@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 107 lines 3.94 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 datasync from "@distilled.cloud/aws/datasync";
5 import * as EC2 from "@distilled.cloud/aws/ec2";
6 import { Region } from "@distilled.cloud/aws/Region";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9 import { getDefaultVpc } from "../DefaultVpc.ts";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 const waitUntilLocationGone = (locationArn: string) =>
14 datasync.describeLocationEfs({ LocationArn: locationArn }).pipe(
15 Effect.as(false),
16 Effect.catchTag("LocationNotFound", () => Effect.succeed(true)),
17 Effect.repeat({
18 schedule: Schedule.fixed("1 seconds"),
19 until: (gone) => gone,
20 times: 20,
21 }),
22 );
23
24 test.provider(
25 "typed LocationNotFound on a nonexistent EFS location",
26 () =>
27 Effect.gen(function* () {
28 const result = yield* datasync
29 .describeLocationEfs({
30 LocationArn: "arn:aws:datasync:us-west-2:391965393224:location/loc-00000000000000000",
31 })
32 .pipe(Effect.result);
33 expect(result._tag).toBe("Failure");
34 if (result._tag === "Failure") {
35 const err = result.failure as { _tag: string };
36 expect(err._tag).toBe("LocationNotFound");
37 }
38 }),
39 { tags: ["provider:aws", "provider:aws:datasync", "live"], timeout: 60_000 },
40 );
41
42 // The live lifecycle requires an EFS file system + mount target; the mount
43 // target's ENI takes 1–3 minutes to become available and again to release on
44 // teardown (~100s observed), so the full cycle is skipped under --fast.
45 test.provider.skipIf(!!process.env.FAST)(
46 "create EFS location from a file system + mount target, delete",
47 (stack) =>
48 Effect.gen(function* () {
49 yield* stack.destroy();
50
51 const region = yield* yield* Region;
52 const vpc = yield* getDefaultVpc;
53 const subnets = yield* EC2.describeSubnets({
54 Filters: [
55 { Name: "vpc-id", Values: [vpc.vpcId] },
56 { Name: "default-for-az", Values: ["true"] },
57 ],
58 });
59 const subnetId = subnets.Subnets![0]!.SubnetId!;
60 const groups = yield* EC2.describeSecurityGroups({
61 Filters: [
62 { Name: "vpc-id", Values: [vpc.vpcId] },
63 { Name: "group-name", Values: ["default"] },
64 ],
65 });
66 const sg = groups.SecurityGroups![0]!;
67 const accountId = sg.OwnerId!;
68 const securityGroupId = sg.GroupId!;
69 const subnetArn = `arn:aws:ec2:${region}:${accountId}:subnet/${subnetId}`;
70 const securityGroupArn = `arn:aws:ec2:${region}:${accountId}:security-group/${securityGroupId}`;
71
72 const created = yield* stack.deploy(
73 Effect.gen(function* () {
74 const files = yield* AWS.EFS.FileSystem("EfsLocFiles");
75 const target = yield* AWS.EFS.MountTarget("EfsLocTarget", {
76 fileSystemId: files.fileSystemId,
77 subnetId,
78 });
79 const location = yield* AWS.DataSync.LocationEfs("EfsLoc", {
80 // depend on the mount target so the location is created only once
81 // the network endpoint is available
82 efsFilesystemArn: files.fileSystemArn,
83 subnetArn,
84 securityGroupArns: [securityGroupArn],
85 tags: { mount: target.mountTargetId },
86 });
87 return { location };
88 }),
89 );
90 expect(created.location.locationArn).toContain(":location/loc-");
91 expect(created.location.locationUri).toContain("efs://");
92 const arn = created.location.locationArn;
93
94 const observed = yield* datasync.describeLocationEfs({
95 LocationArn: arn,
96 });
97 expect(observed.Ec2Config?.SubnetArn).toBe(subnetArn);
98
99 yield* stack.destroy();
100 const gone = yield* waitUntilLocationGone(arn);
101 expect(gone).toBe(true);
102 }),
103 {
104 tags: ["provider:aws", "provider:aws:datasync", "provider:aws:ec2", "provider:aws:efs", "live"],
105 timeout: 600_000,
106 },
107 );