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

main
ts 129 lines 5.07 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import {
3 ResolverEndpoint,
4 ResolverRule,
5 ResolverRuleAssociation,
6 } from "@alchemy.run/aws/Route53Resolver";
7 import { expect } from "@alchemy.run/test";
8 import * as Test from "@alchemy.run/test/Alchemy";
9 import * as r53r from "@distilled.cloud/aws/route53resolver";
10 import * as Effect from "effect/Effect";
11 import * as Schedule from "effect/Schedule";
12 import { assertEndpointDeleting, assertRuleGone, defaultNetwork } from "./helpers.ts";
13
14 const { test } = Test.make({ providers: AWS.providers() });
15
16 // Ungated typed-error probe: association APIs surface the typed
17 // ResourceNotFoundException tag for a nonexistent rule (against a real VPC
18 // — AWS validates the VPC id first with InvalidParameterException).
19 test.provider(
20 "associating a nonexistent rule fails with a typed tag",
21 () =>
22 Effect.gen(function* () {
23 const net = yield* defaultNetwork;
24 const result = yield* r53r
25 .associateResolverRule({ ResolverRuleId: "rslvr-rr-00000000000000000", VPCId: net.vpcId })
26 .pipe(
27 Effect.map(() => "created" as const),
28 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed("not-found" as const)),
29 );
30 expect(result).toBe("not-found");
31 }),
32 { tags: ["provider:aws", "provider:aws:ec2", "provider:aws:route53resolver", "live"] },
33 );
34
35 // The full lifecycle is gated: a VPC rule association takes ~1-2 minutes to
36 // reach COMPLETE and another ~1-2 minutes to drain on disassociation, which
37 // does not fit the ungated 240s budget.
38 test.provider.skipIf(!!process.env.FAST)(
39 "associate a forward rule with the default VPC and tear it down",
40 (stack) =>
41 Effect.gen(function* () {
42 yield* stack.destroy();
43
44 const net = yield* defaultNetwork;
45 const deployed = yield* stack.deploy(
46 Effect.gen(function* () {
47 const endpoint = yield* ResolverEndpoint("Outbound", {
48 direction: "OUTBOUND",
49 securityGroupIds: [net.securityGroupId],
50 ipAddresses: net.subnetIds.map((subnetId) => ({ subnetId })),
51 });
52 const rule = yield* ResolverRule("Forward", {
53 domainName: "assoc.alchemy-r53r-test.internal",
54 resolverEndpointId: endpoint.resolverEndpointId,
55 targetIps: [{ ip: "192.168.20.10" }],
56 });
57 const association = yield* ResolverRuleAssociation("Assoc", {
58 resolverRuleId: rule.resolverRuleId,
59 vpcId: net.vpcId,
60 });
61 return { endpoint, rule, association };
62 }),
63 );
64
65 expect(deployed.association.resolverRuleAssociationId).toContain("rslvr-rrassoc-");
66 expect(deployed.association.resolverRuleId).toBe(deployed.rule.resolverRuleId);
67 expect(deployed.association.vpcId).toBe(net.vpcId);
68
69 // Out-of-band: the association exists and converges to COMPLETE
70 // (VPC associations routinely take 1-2 minutes).
71 const status = yield* r53r
72 .getResolverRuleAssociation({
73 ResolverRuleAssociationId: deployed.association.resolverRuleAssociationId,
74 })
75 .pipe(
76 Effect.map((r) => r.ResolverRuleAssociation?.Status),
77 Effect.repeat({
78 schedule: Schedule.fixed("5 seconds"),
79 until: (s) => s === "COMPLETE" || s === "FAILED",
80 times: 36,
81 }),
82 );
83 expect(status).toBe("COMPLETE");
84
85 // Idempotent redeploy — same association (no replacement).
86 const again = yield* stack.deploy(
87 Effect.gen(function* () {
88 const endpoint = yield* ResolverEndpoint("Outbound", {
89 direction: "OUTBOUND",
90 securityGroupIds: [net.securityGroupId],
91 ipAddresses: net.subnetIds.map((subnetId) => ({ subnetId })),
92 });
93 const rule = yield* ResolverRule("Forward", {
94 domainName: "assoc.alchemy-r53r-test.internal",
95 resolverEndpointId: endpoint.resolverEndpointId,
96 targetIps: [{ ip: "192.168.20.10" }],
97 });
98 const association = yield* ResolverRuleAssociation("Assoc", {
99 resolverRuleId: rule.resolverRuleId,
100 vpcId: net.vpcId,
101 });
102 return { association };
103 }),
104 );
105 expect(again.association.resolverRuleAssociationId).toBe(
106 deployed.association.resolverRuleAssociationId,
107 );
108
109 // Destroy tears down association → rule → endpoint in order; the
110 // association's delete waits for the drain so the rule delete
111 // converges.
112 yield* stack.destroy();
113 const gone = yield* r53r
114 .getResolverRuleAssociation({
115 ResolverRuleAssociationId: deployed.association.resolverRuleAssociationId,
116 })
117 .pipe(
118 Effect.map(() => false),
119 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)),
120 );
121 expect(gone).toBe(true);
122 yield* assertRuleGone(deployed.rule.resolverRuleId);
123 yield* assertEndpointDeleting(deployed.endpoint.resolverEndpointId);
124 }),
125 {
126 tags: ["provider:aws", "provider:aws:ec2", "provider:aws:route53resolver", "live"],
127 timeout: 480_000,
128 },
129 );