@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 142 lines 5.44 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { QApp } from "@alchemy.run/aws/QApps";
3 import { describe, expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as qapps from "@distilled.cloud/aws/qapps";
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 // Amazon Q Apps live inside an Amazon Q Business application environment
12 // (the `instance-id` header), which itself requires IAM Identity Center —
13 // neither is provisioned in the shared testing account. The ungated probe
14 // asserts the distilled wiring surfaces the typed error the provider's
15 // read/observe paths depend on; the full lifecycle is gated behind
16 // AWS_TEST_QAPPS=1 (an account with a Q Business application, passed as
17 // QAPPS_INSTANCE_ID).
18 describe("AWS.QApps.QApp", { tags: ["provider:aws", "provider:aws:qapps", "live"] }, () => {
19 // Without a Q Business instance, the API rejects at the door with a typed
20 // UnauthorizedException ("Unauthorized") — the caller isn't an Identity
21 // Center user of any instance. An entitled account with bogus ids surfaces
22 // ResourceNotFoundException/AccessDeniedException instead; all three are
23 // typed tags in the distilled union.
24 test.provider(
25 "getQApp against a nonexistent Q Business instance yields a typed error",
26 (_stack) =>
27 Effect.gen(function* () {
28 const error = yield* qapps
29 .getQApp({
30 instanceId: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
31 appId: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
32 })
33 .pipe(Effect.flip);
34 expect([
35 "UnauthorizedException",
36 "ResourceNotFoundException",
37 "AccessDeniedException",
38 ]).toContain(error._tag);
39 }),
40 { timeout: 60_000 },
41 );
42
43 test.provider(
44 "deleteQApp against a nonexistent Q Business instance yields a typed error",
45 (_stack) =>
46 Effect.gen(function* () {
47 const error = yield* qapps
48 .deleteQApp({
49 instanceId: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
50 appId: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
51 })
52 .pipe(Effect.flip);
53 expect([
54 "UnauthorizedException",
55 "ResourceNotFoundException",
56 "AccessDeniedException",
57 ]).toContain(error._tag);
58 }),
59 { timeout: 60_000 },
60 );
61
62 test.provider.skipIf(!process.env.AWS_TEST_QAPPS)(
63 "create Q App, update definition, destroy, verify gone",
64 (stack) =>
65 Effect.gen(function* () {
66 yield* stack.destroy();
67
68 const instanceId = process.env.QAPPS_INSTANCE_ID;
69 if (!instanceId) {
70 return yield* Effect.die(new Error("AWS_TEST_QAPPS runs require QAPPS_INSTANCE_ID"));
71 }
72
73 const textCardId = "11111111-1111-4111-8111-111111111111";
74 const queryCardId = "22222222-2222-4222-8222-222222222222";
75
76 const deploy = (props: { description?: string; prompt: string }) =>
77 stack.deploy(
78 Effect.gen(function* () {
79 const app = yield* QApp("Summarizer", {
80 instanceId,
81 description: props.description,
82 appDefinition: {
83 cards: [
84 { textInput: { id: textCardId, title: "Source Text", type: "text-input" } },
85 {
86 qQuery: {
87 id: queryCardId,
88 title: "Summary",
89 type: "q-query",
90 prompt: props.prompt,
91 },
92 },
93 ],
94 },
95 tags: { Environment: "test" },
96 });
97 return { app };
98 }),
99 );
100
101 // Create.
102 const { app } = yield* deploy({ prompt: "Summarize the following text: @Source Text" });
103 expect(app.appId).toBeDefined();
104 expect(app.appArn).toContain(":qapps:");
105 expect(app.status).toBeDefined();
106
107 // Out-of-band verification via distilled.
108 const observed = yield* qapps.getQApp({ instanceId, appId: app.appId });
109 expect(observed.appId).toBe(app.appId);
110 expect(observed.appDefinition.cards).toHaveLength(2);
111
112 // Update in place — description + card prompt flow through UpdateQApp.
113 const updated = yield* deploy({
114 description: "updated by test",
115 prompt: "Summarize the following text in one sentence: @Source Text",
116 });
117 expect(updated.app.appId).toBe(app.appId);
118 const reobserved = yield* qapps.getQApp({ instanceId, appId: app.appId });
119 expect(reobserved.description).toBe("updated by test");
120 expect(reobserved.appVersion).toBeGreaterThan(observed.appVersion);
121
122 yield* stack.destroy();
123
124 // Typed wait-until-gone.
125 yield* Effect.gen(function* () {
126 const gone = yield* qapps.getQApp({ instanceId, appId: app.appId }).pipe(
127 Effect.map((d) => d.status === "DELETED"),
128 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)),
129 );
130 if (!gone) {
131 return yield* Effect.fail({ _tag: "StillExists" as const });
132 }
133 }).pipe(
134 Effect.retry({
135 while: (e: { _tag: string }) => e._tag === "StillExists",
136 schedule: Schedule.max([Schedule.spaced("5 seconds"), Schedule.recurs(10)]),
137 }),
138 );
139 }),
140 { timeout: 600_000 },
141 );
142 });