@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 112 lines 3.58 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Domain } from "@alchemy.run/aws/SimpleDB";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as sdb from "@distilled.cloud/aws/simpledb";
6 import * as Data from "effect/Data";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: AWS.providers() });
11
12 const findDomain = (domainName: string) =>
13 sdb
14 .domainMetadata({ DomainName: domainName })
15 .pipe(Effect.catchTag("NoSuchDomain", () => Effect.succeed(undefined)));
16
17 class DomainStillExists extends Data.TaggedError("DomainStillExists")<{
18 readonly domainName: string;
19 }> {}
20
21 const assertDomainDeleted = (domainName: string) =>
22 findDomain(domainName).pipe(
23 Effect.flatMap((metadata) =>
24 metadata === undefined ? Effect.void : Effect.fail(new DomainStillExists({ domainName })),
25 ),
26 Effect.retry({
27 while: (e) => e._tag === "DomainStillExists",
28 schedule: Schedule.max([Schedule.spaced("2 seconds"), Schedule.recurs(10)]),
29 }),
30 );
31
32 test.provider(
33 "create and delete a domain (generated name)",
34 (stack) =>
35 Effect.gen(function* () {
36 yield* stack.destroy();
37
38 const domain = yield* stack.deploy(
39 Effect.gen(function* () {
40 return yield* Domain("TestSdbDomain", {});
41 }),
42 );
43
44 expect(domain.domainName).toBeDefined();
45 expect(domain.domainArn).toContain(":domain/");
46 expect(domain.domainArn).toContain(domain.domainName);
47
48 // out-of-band verification via distilled
49 const metadata = yield* findDomain(domain.domainName);
50 expect(metadata).toBeDefined();
51 expect(metadata?.ItemCount).toBe(0);
52
53 // idempotent re-deploy: same physical domain
54 const again = yield* stack.deploy(
55 Effect.gen(function* () {
56 return yield* Domain("TestSdbDomain", {});
57 }),
58 );
59 expect(again.domainName).toBe(domain.domainName);
60 expect(again.domainArn).toBe(domain.domainArn);
61
62 yield* stack.destroy();
63 yield* assertDomainDeleted(domain.domainName);
64 }),
65 { tags: ["provider:aws", "provider:aws:simpledb", "live"], timeout: 120_000 },
66 );
67
68 test.provider(
69 "explicit name and replacement on rename",
70 (stack) =>
71 Effect.gen(function* () {
72 yield* stack.destroy();
73
74 const first = yield* stack.deploy(
75 Effect.gen(function* () {
76 return yield* Domain("NamedSdbDomain", {
77 domainName: "alchemy-test-simpledb-a",
78 });
79 }),
80 );
81 expect(first.domainName).toBe("alchemy-test-simpledb-a");
82
83 // renaming triggers a replacement: new physical domain, old gone
84 const second = yield* stack.deploy(
85 Effect.gen(function* () {
86 return yield* Domain("NamedSdbDomain", {
87 domainName: "alchemy-test-simpledb-b",
88 });
89 }),
90 );
91 expect(second.domainName).toBe("alchemy-test-simpledb-b");
92 expect(second.domainArn).not.toBe(first.domainArn);
93
94 yield* assertDomainDeleted(first.domainName);
95
96 yield* stack.destroy();
97 yield* assertDomainDeleted(second.domainName);
98 }),
99 { tags: ["provider:aws", "provider:aws:simpledb", "live"], timeout: 120_000 },
100 );
101
102 test.provider(
103 "domainMetadata on a missing domain fails with typed NoSuchDomain",
104 () =>
105 Effect.gen(function* () {
106 const error = yield* sdb
107 .domainMetadata({ DomainName: "alchemy-test-simpledb-bogus" })
108 .pipe(Effect.flip);
109 expect(error._tag).toBe("NoSuchDomain");
110 }),
111 { tags: ["provider:aws", "provider:aws:simpledb", "live"], timeout: 60_000 },
112 );