@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 88 lines 3.46 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { AlternateContact } from "@alchemy.run/aws/Account";
3 import { describe, expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as account from "@distilled.cloud/aws/account";
6 import * as Effect from "effect/Effect";
7 import * as Redacted from "effect/Redacted";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 const unwrap = (value: string | Redacted.Redacted<string> | undefined) =>
12 value === undefined ? undefined : typeof value === "string" ? value : Redacted.value(value);
13
14 const CONTACT_TYPE = "OPERATIONS" as const;
15
16 const captureContact = () =>
17 account.getAlternateContact({ AlternateContactType: CONTACT_TYPE }).pipe(
18 Effect.map((r) => r.AlternateContact),
19 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)),
20 );
21
22 // Account alternate contacts are account-global singletons — one per type. This
23 // test captures whatever OPERATIONS contact the account currently has, sets its
24 // own, verifies, tears down, and restores the original so the account is left
25 // exactly as it was found.
26 describe.sequential(
27 "Account AlternateContact",
28 { tags: ["provider:aws", "provider:aws:account", "live"] },
29 () => {
30 test.provider(
31 "set, read, and reset the OPERATIONS alternate contact",
32 (stack) =>
33 Effect.gen(function* () {
34 yield* stack.destroy();
35
36 const original = yield* captureContact();
37
38 const restore = Effect.gen(function* () {
39 if (original) {
40 yield* account.putAlternateContact({
41 AlternateContactType: CONTACT_TYPE,
42 Name: unwrap(original.Name) ?? "",
43 Title: unwrap(original.Title) ?? "",
44 EmailAddress: unwrap(original.EmailAddress) ?? "",
45 PhoneNumber: unwrap(original.PhoneNumber) ?? "",
46 });
47 } else {
48 yield* account
49 .deleteAlternateContact({ AlternateContactType: CONTACT_TYPE })
50 .pipe(Effect.catchTag("ResourceNotFoundException", () => Effect.void));
51 }
52 });
53
54 yield* Effect.gen(function* () {
55 const contact = yield* stack.deploy(
56 Effect.gen(function* () {
57 return yield* AlternateContact("OpsContact", {
58 alternateContactType: CONTACT_TYPE,
59 name: "Alchemy Test Ops",
60 title: "On-Call",
61 emailAddress: "alchemy-test-ops@example.com",
62 phoneNumber: "+15555550100",
63 });
64 }),
65 );
66
67 expect(contact.alternateContactType).toBe(CONTACT_TYPE);
68 expect(contact.emailAddress).toBe("alchemy-test-ops@example.com");
69
70 // Out-of-band verification.
71 const live = yield* captureContact();
72 expect(unwrap(live?.EmailAddress)).toBe("alchemy-test-ops@example.com");
73 expect(unwrap(live?.Name)).toBe("Alchemy Test Ops");
74
75 // Destroy removes the contact.
76 yield* stack.destroy();
77 const gone = yield* captureContact();
78 expect(gone).toBeUndefined();
79 }).pipe(Effect.ensuring(restore.pipe(Effect.orDie)));
80
81 // Confirm restoration matches the captured original.
82 const restored = yield* captureContact();
83 expect(unwrap(restored?.EmailAddress)).toBe(unwrap(original?.EmailAddress));
84 }),
85 { timeout: 120_000 },
86 );
87 },
88 );