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
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { VpcConnector } from "@alchemy.run/aws/AppRunner"; |
| 3 | import { SecurityGroup, Subnet, Vpc } from "@alchemy.run/aws/EC2"; |
| 4 | import { expect } from "@alchemy.run/test"; |
| 5 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 6 | import * as apprunner from "@distilled.cloud/aws/apprunner"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import { assertSecurityGroupGone, assertSubnetGone, assertVpcGone } from "../EC2/Gone.ts"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | // VPC connector creation is fast (deletion marks it INACTIVE immediately; |
| 13 | // ENI teardown happens asynchronously server-side), so the lifecycle runs |
| 14 | // ungated on a deterministic, stack-owned network. |
| 15 | test.provider( |
| 16 | "create and destroy a VPC connector on a stack-owned VPC", |
| 17 | (stack) => |
| 18 | Effect.gen(function* () { |
| 19 | // Clean slate in case a previous run died mid-flight. |
| 20 | yield* stack.destroy(); |
| 21 | |
| 22 | const { connector, securityGroup, subnet, vpc } = yield* stack.deploy( |
| 23 | Effect.gen(function* () { |
| 24 | const vpc = yield* Vpc("ConnectorVpc", { |
| 25 | cidrBlock: "10.84.0.0/16", |
| 26 | }); |
| 27 | const subnet = yield* Subnet("ConnectorSubnet", { |
| 28 | vpcId: vpc.vpcId, |
| 29 | cidrBlock: "10.84.1.0/24", |
| 30 | }); |
| 31 | const securityGroup = yield* SecurityGroup("ConnectorSecurityGroup", { |
| 32 | vpcId: vpc.vpcId, |
| 33 | }); |
| 34 | const connector = yield* VpcConnector("Connector", { |
| 35 | subnets: [subnet.subnetId], |
| 36 | securityGroups: [securityGroup.groupId], |
| 37 | }); |
| 38 | return { connector, securityGroup, subnet, vpc }; |
| 39 | }), |
| 40 | ); |
| 41 | expect(connector.vpcConnectorName.length).toBeGreaterThanOrEqual(4); |
| 42 | expect(connector.vpcConnectorArn).toContain(":vpcconnector/"); |
| 43 | // App Runner returns lowercase statuses despite documenting uppercase. |
| 44 | expect(connector.status.toUpperCase()).toBe("ACTIVE"); |
| 45 | expect(connector.vpcConnectorRevision).toBeGreaterThanOrEqual(1); |
| 46 | |
| 47 | // Out-of-band verification via distilled. |
| 48 | const described = yield* apprunner.describeVpcConnector({ |
| 49 | VpcConnectorArn: connector.vpcConnectorArn, |
| 50 | }); |
| 51 | expect(described.VpcConnector.VpcConnectorName).toBe(connector.vpcConnectorName); |
| 52 | expect(described.VpcConnector.Status?.toUpperCase()).toBe("ACTIVE"); |
| 53 | expect(described.VpcConnector.Subnets).toEqual([subnet.subnetId]); |
| 54 | expect(described.VpcConnector.SecurityGroups).toEqual([securityGroup.groupId]); |
| 55 | |
| 56 | // Destroy and verify deletion out-of-band: deleted connectors read |
| 57 | // INACTIVE (or disappear entirely). |
| 58 | yield* stack.destroy(); |
| 59 | const after = yield* apprunner |
| 60 | .describeVpcConnector({ |
| 61 | VpcConnectorArn: connector.vpcConnectorArn, |
| 62 | }) |
| 63 | .pipe( |
| 64 | Effect.map((r) => (r.VpcConnector.Status ?? "INACTIVE").toUpperCase()), |
| 65 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed("GONE" as const)), |
| 66 | ); |
| 67 | expect(["INACTIVE", "GONE"]).toContain(after); |
| 68 | |
| 69 | // The connector must release its managed ENIs before the dependency |
| 70 | // graph is considered destroyed, leaving no App Runner test network |
| 71 | // resources for nuke to discover. |
| 72 | yield* assertSubnetGone(subnet.subnetId); |
| 73 | yield* assertSecurityGroupGone(securityGroup.groupId); |
| 74 | yield* assertVpcGone(vpc.vpcId); |
| 75 | }), |
| 76 | { |
| 77 | tags: ["provider:aws", "provider:aws:apprunner", "provider:aws:ec2", "live"], |
| 78 | timeout: 180_000, |
| 79 | }, |
| 80 | ); |