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

main
ts 75 lines 2.79 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { describe, expect } from "@alchemy.run/test";
3 import * as Core from "@alchemy.run/test/Core";
4 import * as Effect from "effect/Effect";
5 import * as HttpClient from "effect/http/HttpClient";
6 import * as Schedule from "effect/Schedule";
7 import NetworkTestFunctionLive, { NetworkTestFunction } from "./fixtures/network-function";
8 import * as Test from "./VpcTest.ts";
9
10 const testOptions = { providers: AWS.providers() };
11 const { test, beforeAll, afterAll } = Test.make(testOptions);
12 const sharedStack = Core.scratchStack(testOptions, "EC2NetworkFunction");
13
14 // Lambda function URL cold-start (DNS, IAM propagation, init) can take
15 // well over 60s on a fresh deploy — budget ~150s of readiness polling.
16 const readinessPolicy = Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(75)]);
17
18 let baseUrl: string;
19
20 describe(
21 "EC2.Network composed in a Lambda layer",
22 { tags: ["provider:aws", "provider:aws:ec2", "provider:aws:lambda", "live"] },
23 () => {
24 beforeAll(
25 Effect.gen(function* () {
26 yield* sharedStack.destroy();
27
28 const { functionUrl } = yield* sharedStack.deploy(
29 Effect.gen(function* () {
30 return yield* NetworkTestFunction;
31 }).pipe(Effect.provide(NetworkTestFunctionLive)),
32 );
33
34 expect(functionUrl).toBeTruthy();
35 baseUrl = functionUrl!.replace(/\/+$/, "");
36
37 // The function role has NO ec2:Describe* permissions and the runtime
38 // does not provide `AWSEnvironment` — a 200 here proves the `Network`
39 // composition re-executes cleanly at Lambda init.
40 yield* HttpClient.get(`${baseUrl}/network`).pipe(
41 Effect.timeout("4 seconds"),
42 Effect.flatMap((response) =>
43 response.status === 200
44 ? Effect.succeed(response)
45 : Effect.fail(new Error(`Function not ready: ${response.status}`)),
46 ),
47 Effect.retry({ schedule: readinessPolicy }),
48 );
49 }),
50 // This nested setup hook is scheduled while the file may still be queued
51 // on the shared VPC-capacity lease. Give coordination the suite wall;
52 // every cloud/HTTP wait inside remains independently bounded.
53 { timeout: 3_600_000 },
54 );
55
56 afterAll(sharedStack.destroy(), { timeout: 240_000 });
57
58 test.provider(
59 "Lambda INITs cleanly and resolves Network outputs at runtime",
60 (_stack) =>
61 Effect.gen(function* () {
62 const response = yield* HttpClient.get(`${baseUrl}/network`);
63 expect(response.status).toBe(200);
64
65 const body = (yield* response.json) as {
66 vpcId: string;
67 subnetId: string;
68 };
69 expect(body.vpcId).toMatch(/^vpc-/);
70 expect(body.subnetId).toMatch(/^subnet-/);
71 }),
72 { timeout: 60_000 },
73 );
74 },
75 );