@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, 06:00 UTC

main
ts 88 lines 3.52 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { describe, expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as Core from "@alchemy.run/test/Core";
5 import * as Effect from "effect/Effect";
6 import * as HttpClient from "effect/http/HttpClient";
7 import * as Schedule from "effect/Schedule";
8 import NestedEcsReproFunctionLive, {
9 NestedEcsReproFunction,
10 } from "./fixtures/nested-ecs-lambda.ts";
11
12 // Regression for the "Platform-in-Platform init OOM": a Platform (ECS.Task)
13 // yielded DIRECTLY inside another Platform's (Lambda.Function) init program.
14 // Before the fix, the nested Task's ConfigProvider interceptor recursed back
15 // through the outer Lambda's interceptor at runtime (`ctx.get` → `Config` →
16 // interceptor → `ctx.get` …), growing the heap without bound until the Lambda
17 // sandbox died with `Runtime.OutOfMemory` at init.
18 //
19 // The fixture removes the `Resource.ref` workaround the ECS Bindings handler
20 // uses. If the nested-Platform init still OOMed, the deployed Lambda would
21 // never boot and this fetch would never return 200.
22 const testOptions = { providers: AWS.providers() };
23 const { beforeAll, afterAll, test } = Test.make(testOptions);
24 const sharedStack = Core.scratchStack(testOptions, "NestedPlatformInit");
25
26 let baseUrl: string;
27
28 // Fresh workers/Lambda URLs take a few seconds to start serving 200s; a
29 // sandbox that OOMs at init keeps returning 5xx until the readiness budget is
30 // exhausted, which fails the suite loudly.
31 const readinessPolicy = Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]);
32
33 describe.sequential(
34 "ECS Nested Platform Init",
35 { tags: ["provider:aws", "provider:aws:ecs", "provider:aws:lambda", "live"] },
36 () => {
37 beforeAll(
38 Effect.gen(function* () {
39 yield* Effect.logInfo("nested-platform setup: destroying previous stack");
40 yield* sharedStack.destroy();
41
42 yield* Effect.logInfo("nested-platform setup: deploying nested-Task Lambda");
43 const { functionUrl } = yield* sharedStack.deploy(
44 Effect.gen(function* () {
45 return yield* NestedEcsReproFunction;
46 }).pipe(Effect.provide(NestedEcsReproFunctionLive)),
47 );
48
49 expect(functionUrl).toBeTruthy();
50 baseUrl = functionUrl!.replace(/\/+$/, "");
51
52 yield* Effect.logInfo(`nested-platform setup: probing readiness at ${baseUrl}`);
53 yield* HttpClient.get(baseUrl).pipe(
54 Effect.flatMap((response) =>
55 response.status === 200
56 ? Effect.succeed(response)
57 : Effect.fail(new Error(`Function not ready: ${response.status}`)),
58 ),
59 Effect.tapError((error) =>
60 Effect.logWarning(`nested-platform setup: fixture not ready yet (${String(error)})`),
61 ),
62 Effect.retry({ schedule: readinessPolicy }),
63 );
64 yield* Effect.logInfo("nested-platform setup: fixture ready");
65 }),
66 { timeout: 180_000 },
67 );
68
69 afterAll(sharedStack.destroy(), { timeout: 180_000 });
70
71 test(
72 "nested Platform (ECS.Task in Lambda) init does not OOM the sandbox",
73 Effect.gen(function* () {
74 const response = yield* HttpClient.get(baseUrl);
75 expect(response.status).toBe(200);
76 const body = (yield* response.json) as {
77 ok?: boolean;
78 taskType?: string;
79 containerName?: string;
80 };
81 expect(body.ok).toBe(true);
82 expect(body.taskType).toBe("AWS.ECS.Task");
83 expect(body.containerName).toBeTruthy();
84 }),
85 { timeout: 120_000 },
86 );
87 },
88 );