@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, 04:45 UTC

main
ts 111 lines 4.4 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Application } from "@alchemy.run/aws/AppIntegrations";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as appintegrations from "@distilled.cloud/aws/appintegrations";
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: prove the distilled error union carries the
12 // not-found tag this provider's read/delete paths depend on.
13 test.provider(
14 "getApplication on a nonexistent id fails with ResourceNotFoundException",
15 () =>
16 Effect.gen(function* () {
17 const error = yield* Effect.flip(
18 appintegrations.getApplication({ Arn: "00000000-0000-0000-0000-000000000000" }),
19 );
20 expect(error._tag).toBe("ResourceNotFoundException");
21 }),
22 { tags: ["provider:aws", "provider:aws:appintegrations", "live"] },
23 );
24
25 const assertGone = (arn: string) =>
26 appintegrations.getApplication({ Arn: arn }).pipe(
27 Effect.flatMap(() => Effect.fail(new Error(`application '${arn}' still exists`))),
28 Effect.catchTag("ResourceNotFoundException", () => Effect.void),
29 Effect.retry({ schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]) }),
30 );
31
32 test.provider(
33 "create, update in place, replace on namespace change, delete an application",
34 (stack) =>
35 Effect.gen(function* () {
36 yield* stack.destroy();
37
38 const { app } = yield* stack.deploy(
39 Effect.gen(function* () {
40 const app = yield* Application("AgentApp", {
41 namespace: "com.alchemy.testapp",
42 accessUrl: "https://example.com",
43 description: "alchemy application",
44 tags: { purpose: "alchemy-test" },
45 });
46 return { app };
47 }),
48 );
49
50 expect(app.applicationId).toBeDefined();
51 expect(app.applicationArn).toContain(":application/");
52 expect(app.applicationName).toBeDefined();
53 expect(app.namespace).toBe("com.alchemy.testapp");
54
55 // Out-of-band verification via distilled.
56 const observed = yield* appintegrations.getApplication({ Arn: app.applicationArn });
57 expect(observed.Name).toBe(app.applicationName);
58 expect(observed.Namespace).toBe("com.alchemy.testapp");
59 expect(observed.Description).toBe("alchemy application");
60 expect(observed.ApplicationSourceConfig?.ExternalUrlConfig?.AccessUrl).toBe(
61 "https://example.com",
62 );
63 expect(observed.Tags?.purpose).toBe("alchemy-test");
64
65 // Update description, access URL, and permissions in place (arn/id
66 // stable).
67 const { app: updated } = yield* stack.deploy(
68 Effect.gen(function* () {
69 const app = yield* Application("AgentApp", {
70 namespace: "com.alchemy.testapp",
71 accessUrl: "https://updated.example.com",
72 description: "alchemy application v2",
73 permissions: ["User.Details.View"],
74 tags: { purpose: "alchemy-test", phase: "two" },
75 });
76 return { app };
77 }),
78 );
79 expect(updated.applicationArn).toBe(app.applicationArn);
80 expect(updated.applicationId).toBe(app.applicationId);
81
82 const reobserved = yield* appintegrations.getApplication({ Arn: app.applicationArn });
83 expect(reobserved.Description).toBe("alchemy application v2");
84 expect(reobserved.ApplicationSourceConfig?.ExternalUrlConfig?.AccessUrl).toBe(
85 "https://updated.example.com",
86 );
87 expect(reobserved.Permissions).toEqual(["User.Details.View"]);
88 expect(reobserved.Tags?.phase).toBe("two");
89
90 // Changing the namespace replaces the application.
91 const { app: replaced } = yield* stack.deploy(
92 Effect.gen(function* () {
93 const app = yield* Application("AgentApp", {
94 namespace: "com.alchemy.testapp.v2",
95 accessUrl: "https://updated.example.com",
96 description: "alchemy application v2",
97 });
98 return { app };
99 }),
100 );
101 expect(replaced.namespace).toBe("com.alchemy.testapp.v2");
102 expect(replaced.applicationArn).not.toBe(app.applicationArn);
103
104 // The replaced (old) application is deleted.
105 yield* assertGone(app.applicationArn);
106
107 yield* stack.destroy();
108 yield* assertGone(replaced.applicationArn);
109 }),
110 { tags: ["provider:aws", "provider:aws:appintegrations", "live"], timeout: 240_000 },
111 );