@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 63 lines 2.63 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as Lambda from "@distilled.cloud/aws/lambda";
5 import * as Effect from "effect/Effect";
6 import * as HttpClient from "effect/http/HttpClient";
7 import * as Schedule from "effect/Schedule";
8 import { materializeIsolatedProject, removeIsolatedProject } from "../../IsolatedProject.ts";
9 import IsolatedProjectFunctionLive, {
10 BODY,
11 IsolatedProjectFunction,
12 project,
13 } from "./fixtures/isolated-project-handler.ts";
14
15 const { test } = Test.make({ providers: AWS.providers() });
16
17 // Live proof that the Lambda (zip) bootstrap loads when the function's
18 // `main` lives in an isolated project (see test/IsolatedProject.ts) — the
19 // bundle `cwd` resolves none of alchemy's dependencies, so the bootstrap's
20 // `@distilled.cloud/aws/*` / `@effect/platform-node` imports must be bundled
21 // by the virtual-entry plugin rather than found from the project root. With
22 // them left external the runtime fails at init (`Cannot find package`) and
23 // the function URL answers 5xx.
24 test.provider(
25 "function bundled from an isolated project serves its URL",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* materializeIsolatedProject(project);
29 yield* stack.destroy();
30
31 try {
32 const { functionName, functionUrl } = yield* stack.deploy(
33 IsolatedProjectFunction.pipe(Effect.provide(IsolatedProjectFunctionLive)),
34 );
35 expect(functionUrl).toBeTruthy();
36
37 const response = yield* HttpClient.get(functionUrl!).pipe(
38 Effect.flatMap((res) =>
39 res.status === 200
40 ? Effect.succeed(res)
41 : Effect.fail(new Error(`Function URL returned ${res.status}`)),
42 ),
43 // Bounded: a bootstrap that fails at init answers 5xx forever.
44 Effect.retry({ schedule: Schedule.spaced("3 seconds"), times: 40 }),
45 );
46 expect(yield* response.text).toBe(BODY);
47
48 yield* stack.destroy();
49 // Out-of-band proof the destroy removed the function (bounded retry
50 // to ride out delete propagation).
51 yield* Lambda.getFunction({ FunctionName: functionName }).pipe(
52 Effect.flatMap(() => Effect.fail(new Error(`Function ${functionName} still exists`))),
53 Effect.catchTag("ResourceNotFoundException", () => Effect.void),
54 Effect.retry({
55 schedule: Schedule.max([Schedule.exponential(500), Schedule.recurs(8)]),
56 }),
57 );
58 } finally {
59 yield* removeIsolatedProject(project);
60 }
61 }),
62 { tags: ["provider:aws", "provider:aws:lambda", "live"], timeout: 300_000 },
63 );