@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 105 lines 3.88 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Profile } from "@alchemy.run/aws/B2BI";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as b2bi from "@distilled.cloud/aws/b2bi";
6 import * as Effect from "effect/Effect";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 // Ungated typed-error probe: proves the distilled error union carries the
12 // not-found tag this provider's read/delete paths depend on.
13 test.provider(
14 "getProfile on a nonexistent id fails with ResourceNotFoundException",
15 () =>
16 Effect.gen(function* () {
17 const error = yield* Effect.flip(b2bi.getProfile({ profileId: "p-00000000000000000" }));
18 expect(["ResourceNotFoundException", "ValidationException"]).toContain(error._tag);
19 }),
20 { tags: ["provider:aws", "provider:aws:b2bi", "live"] },
21 );
22
23 const assertProfileGone = (profileId: string) =>
24 Effect.gen(function* () {
25 const result = yield* b2bi.getProfile({ profileId }).pipe(
26 Effect.map(() => "present" as const),
27 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed("gone" as const)),
28 );
29 if (result === "present") {
30 return yield* Effect.fail(new Error(`Profile '${profileId}' still exists`));
31 }
32 }).pipe(
33 Effect.retry({ schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(8)]) }),
34 );
35
36 // Profiles are credential-free and cheap, so the full lifecycle runs ungated.
37 test.provider(
38 "create, update, and destroy a B2BI profile",
39 (stack) =>
40 Effect.gen(function* () {
41 yield* stack.destroy();
42
43 // Create.
44 const created = yield* stack.deploy(
45 Profile("Acme", {
46 name: "alchemy-b2bi-profile",
47 businessName: "Alchemy Test Corp",
48 phone: "+15555550100",
49 email: "edi@alchemy.example",
50 }),
51 );
52 expect(created.profileId).toMatch(/^p-/);
53 expect(created.name).toBe("alchemy-b2bi-profile");
54 expect(created.businessName).toBe("Alchemy Test Corp");
55 expect(created.profileArn).toContain(":b2bi:");
56
57 // Out-of-band verification.
58 const described = yield* b2bi.getProfile({ profileId: created.profileId });
59 expect(described.businessName).toBe("Alchemy Test Corp");
60
61 // No-op redeploy keeps the same id.
62 const noop = yield* stack.deploy(
63 Profile("Acme", {
64 name: "alchemy-b2bi-profile",
65 businessName: "Alchemy Test Corp",
66 phone: "+15555550100",
67 email: "edi@alchemy.example",
68 }),
69 );
70 expect(noop.profileId).toBe(created.profileId);
71
72 // Update businessName and phone in place.
73 const updated = yield* stack.deploy(
74 Profile("Acme", {
75 name: "alchemy-b2bi-profile",
76 businessName: "Alchemy Renamed Corp",
77 phone: "+15555550199",
78 email: "edi@alchemy.example",
79 }),
80 );
81 expect(updated.profileId).toBe(created.profileId);
82 expect(updated.businessName).toBe("Alchemy Renamed Corp");
83 const reDescribed = yield* b2bi.getProfile({ profileId: created.profileId });
84 expect(reDescribed.businessName).toBe("Alchemy Renamed Corp");
85
86 // Changing logging replaces the profile (no member on updateProfile);
87 // delete-first because profiles are recovered by name and quota-capped.
88 const replaced = yield* stack.deploy(
89 Profile("Acme", {
90 name: "alchemy-b2bi-profile",
91 businessName: "Alchemy Renamed Corp",
92 phone: "+15555550199",
93 email: "edi@alchemy.example",
94 logging: "DISABLED",
95 }),
96 );
97 expect(replaced.profileId).not.toBe(created.profileId);
98 yield* assertProfileGone(created.profileId);
99
100 // Destroy and verify.
101 yield* stack.destroy();
102 yield* assertProfileGone(replaced.profileId);
103 }),
104 { tags: ["provider:aws", "provider:aws:b2bi", "live"], timeout: 120_000 },
105 );