@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 96 lines 3.49 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { DhcpOptions, Vpc } from "@alchemy.run/aws/EC2";
3 import { expect } from "@alchemy.run/test";
4 import * as EC2 from "@distilled.cloud/aws/ec2";
5 import * as Provider from "alchemy/Provider";
6 import * as Data from "effect/Data";
7 import * as Effect from "effect/Effect";
8 import { MinimumLogLevel } from "effect/References";
9 import * as Schedule from "effect/Schedule";
10 import * as Test from "./VpcTest.ts";
11
12 const { test } = Test.make({ providers: AWS.providers() });
13
14 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
15
16 class DhcpOptionsStillExists extends Data.TaggedError("DhcpOptionsStillExists") {}
17
18 const assertDeleted = Effect.fn(function* (dhcpOptionsId: string) {
19 yield* EC2.describeDhcpOptions({ DhcpOptionsIds: [dhcpOptionsId] }).pipe(
20 Effect.flatMap((r) =>
21 (r.DhcpOptions?.length ?? 0) === 0 ? Effect.void : Effect.fail(new DhcpOptionsStillExists()),
22 ),
23 Effect.retry({
24 while: (e) => e instanceof DhcpOptionsStillExists,
25 schedule: Schedule.max([Schedule.exponential(300), Schedule.recurs(8)]),
26 }),
27 Effect.catchTag("InvalidDhcpOptionID.NotFound", () => Effect.void),
28 Effect.catchTag("InvalidDhcpOptionsID.NotFound", () => Effect.void),
29 );
30 });
31
32 test.provider(
33 "create DHCP options set, associate to VPC, delete",
34 (stack) =>
35 Effect.gen(function* () {
36 yield* stack.destroy();
37
38 const { vpc, dhcp } = yield* stack.deploy(
39 Effect.gen(function* () {
40 const vpc = yield* Vpc("DhcpVpc", { cidrBlock: "10.60.0.0/16" });
41 const dhcp = yield* DhcpOptions("Dhcp", {
42 domainName: "corp.internal",
43 domainNameServers: ["AmazonProvidedDNS"],
44 netbiosNodeType: "2",
45 vpcId: vpc.vpcId,
46 });
47 return { vpc, dhcp };
48 }),
49 );
50
51 expect(dhcp.dhcpOptionsId).toMatch(/^dopt-/);
52 expect(dhcp.vpcId).toEqual(vpc.vpcId);
53
54 // Verify out-of-band: the options set exists with the domain config.
55 const described = yield* EC2.describeDhcpOptions({
56 DhcpOptionsIds: [dhcp.dhcpOptionsId],
57 });
58 const opts = described.DhcpOptions?.[0];
59 expect(opts?.DhcpOptionsId).toEqual(dhcp.dhcpOptionsId);
60 const domainNameConfig = opts?.DhcpConfigurations?.find((c) => c.Key === "domain-name");
61 expect(domainNameConfig?.Values?.[0]?.Value).toEqual("corp.internal");
62
63 // Verify the VPC points at the options set.
64 const vpcs = yield* EC2.describeVpcs({ VpcIds: [vpc.vpcId] });
65 expect(vpcs.Vpcs?.[0]?.DhcpOptionsId).toEqual(dhcp.dhcpOptionsId);
66
67 yield* stack.destroy();
68 yield* assertDeleted(dhcp.dhcpOptionsId);
69 }).pipe(logLevel),
70 { tags: ["provider:aws", "provider:aws:ec2", "live"], timeout: 240_000 },
71 );
72
73 test.provider(
74 "list enumerates the deployed DHCP options set",
75 (stack) =>
76 Effect.gen(function* () {
77 yield* stack.destroy();
78
79 const { dhcp } = yield* stack.deploy(
80 Effect.gen(function* () {
81 const dhcp = yield* DhcpOptions("ListDhcp", {
82 domainNameServers: ["AmazonProvidedDNS"],
83 });
84 return { dhcp };
85 }),
86 );
87
88 const provider = yield* Provider.findProvider(DhcpOptions);
89 const all = yield* provider.list();
90 expect(all.some((x) => x.dhcpOptionsId === dhcp.dhcpOptionsId)).toBe(true);
91
92 yield* stack.destroy();
93 yield* assertDeleted(dhcp.dhcpOptionsId);
94 }).pipe(logLevel),
95 { tags: ["provider:aws", "provider:aws:ec2", "live"], timeout: 240_000 },
96 );