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

main
ts 87 lines 3.31 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { VpcLink } from "@alchemy.run/aws/ApiGatewayV2";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as agw2 from "@distilled.cloud/aws/apigatewayv2";
6 import * as EC2 from "@distilled.cloud/aws/ec2";
7 import * as Provider from "alchemy/Provider";
8 import * as Effect from "effect/Effect";
9 import { getDefaultVpc } from "../DefaultVpc";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 // Ungated live probe: `list()` enumerates every v2 VPC link and maps each
14 // item to the `read` Attributes shape.
15 test.provider.skipIf(!!process.env.FAST)(
16 "list returns the account/region VPC links",
17 () =>
18 Effect.gen(function* () {
19 const provider = yield* Provider.findProvider(VpcLink);
20 const all = yield* provider.list();
21
22 expect(Array.isArray(all)).toBe(true);
23 for (const link of all) {
24 expect(typeof link.vpcLinkId).toBe("string");
25 expect(Array.isArray(link.subnetIds)).toBe(true);
26 }
27 }),
28 { tags: ["provider:aws", "provider:aws:apigatewayv2", "live"] },
29 );
30
31 // Full lifecycle. SKIPPED by default: a v2 VPC link takes ~1-2 minutes to
32 // reach AVAILABLE (and a comparable window to release its ENIs on delete),
33 // which exceeds the suite's provisioning-wait budget. Set
34 // AWS_TEST_APIGWV2_VPCLINK=1 to run it against the default VPC's subnets.
35 test.provider.skipIf(!!process.env.FAST || !process.env.AWS_TEST_APIGWV2_VPCLINK)(
36 "create, rename, delete VPC link",
37 (stack) =>
38 Effect.gen(function* () {
39 yield* stack.destroy();
40
41 const { vpcId } = yield* getDefaultVpc;
42 const described = yield* EC2.describeSubnets({
43 Filters: [{ Name: "vpc-id", Values: [vpcId] }],
44 });
45 const subnets = (described.Subnets ?? [])
46 .map((subnet) => subnet.SubnetId)
47 .filter((id): id is string => id != null)
48 .slice(0, 2);
49 expect(subnets.length).toBeGreaterThan(0);
50
51 const deployLink = (description: string) =>
52 stack.deploy(
53 Effect.gen(function* () {
54 return yield* AWS.ApiGatewayV2.VpcLink("V2Link", {
55 name: `alchemy-v2link-${description}`,
56 subnetIds: subnets,
57 });
58 }),
59 );
60
61 const link = yield* deployLink("v1");
62 expect(link.vpcLinkId).toBeTruthy();
63
64 const remote = yield* agw2.getVpcLink({ VpcLinkId: link.vpcLinkId });
65 expect(remote.Name).toBe("alchemy-v2link-v1");
66 expect([...(remote.SubnetIds ?? [])].sort()).toEqual([...subnets].sort());
67
68 // Rename in place (name is the only mutable prop).
69 const renamed = yield* deployLink("v2");
70 expect(renamed.vpcLinkId).toBe(link.vpcLinkId);
71 const afterRename = yield* agw2.getVpcLink({ VpcLinkId: link.vpcLinkId });
72 expect(afterRename.Name).toBe("alchemy-v2link-v2");
73
74 yield* stack.destroy();
75
76 const gone = yield* agw2.getVpcLink({ VpcLinkId: link.vpcLinkId }).pipe(
77 // DELETING still resolves; the link is fully gone on NotFound.
78 Effect.map((r) => r.VpcLinkStatus ?? "unknown"),
79 Effect.catchTag("NotFoundException", () => Effect.succeed("deleted" as const)),
80 );
81 expect(["deleted", "DELETING"]).toContain(gone);
82 }),
83 {
84 tags: ["provider:aws", "provider:aws:apigatewayv2", "provider:aws:ec2", "live"],
85 timeout: 480_000,
86 },
87 );