@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 127 lines 4.84 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Application } from "@alchemy.run/aws/AppRegistry";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as appregistry from "@distilled.cloud/aws/service-catalog-appregistry";
6 import * as Data from "effect/Data";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9 import { makeAppRegistryTestLease } from "./TestLease.ts";
10
11 const { test, beforeAll, afterAll } = Test.make({ providers: AWS.providers() });
12 const serviceLease = makeAppRegistryTestLease();
13
14 beforeAll(serviceLease.acquire, { timeout: 3_600_000 });
15 afterAll(serviceLease.release);
16
17 // AWS Service Catalog AppRegistry entered maintenance mode on July 30, 2026.
18 // Accounts without pre-existing AppRegistry resources are treated as "new
19 // customers" and every create is denied with AccessDeniedException. The full
20 // lifecycle/binding suites are gated behind AWS_TEST_APPREGISTRY=1 for
21 // accounts that retain access; the ungated probe below pins the typed
22 // maintenance-mode rejection on everything else.
23 const gated = !process.env.AWS_TEST_APPREGISTRY;
24
25 // Probe only makes sense on an account WITHOUT AppRegistry access — an
26 // entitled account (AWS_TEST_APPREGISTRY=1) would successfully create the
27 // application instead, so the probe is skipped there and the real lifecycle
28 // tests run in its place.
29 test.provider.skipIf(!gated)(
30 "createApplication is denied with the typed maintenance-mode AccessDeniedException",
31 () =>
32 Effect.gen(function* () {
33 const error = yield* Effect.flip(
34 appregistry.createApplication({
35 name: "alchemy-appregistry-maintenance-probe",
36 clientToken: "alchemy-appregistry-maintenance-probe",
37 }),
38 );
39 expect(error._tag).toBe("AccessDeniedException");
40 if (error._tag === "AccessDeniedException") {
41 expect(error.message).toContain("maintenance mode");
42 }
43 }),
44 { tags: ["provider:aws", "provider:aws:appregistry", "live"] },
45 );
46
47 class ApplicationStillExists extends Data.TaggedError("ApplicationStillExists")<{
48 specifier: string;
49 }> {}
50
51 const assertApplicationGone = (specifier: string) =>
52 appregistry.getApplication({ application: specifier }).pipe(
53 Effect.flatMap(() => Effect.fail(new ApplicationStillExists({ specifier }))),
54 Effect.catchTag("ResourceNotFoundException", () => Effect.void),
55 Effect.retry({
56 while: (e) => e._tag === "ApplicationStillExists",
57 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]),
58 }),
59 );
60
61 test.provider.skipIf(gated)(
62 "creates, updates, replaces, and deletes an application",
63 (stack) =>
64 Effect.gen(function* () {
65 yield* stack.destroy();
66
67 const created = yield* stack.deploy(
68 Effect.gen(function* () {
69 const app = yield* Application("TestApp", {
70 description: "application lifecycle test",
71 tags: { purpose: "lifecycle" },
72 });
73 return {
74 applicationId: app.applicationId,
75 applicationArn: app.applicationArn,
76 applicationName: app.applicationName,
77 };
78 }),
79 );
80 expect(created.applicationArn).toContain(":servicecatalog:");
81
82 // out-of-band verify via distilled
83 const found = yield* appregistry.getApplication({
84 application: created.applicationId,
85 });
86 expect(found.name).toBe(created.applicationName);
87 expect(found.description).toBe("application lifecycle test");
88 expect(found.tags?.purpose).toBe("lifecycle");
89 expect(found.tags?.["alchemy::id"]).toBe("TestApp");
90
91 // in-place update of description + tags
92 yield* stack.deploy(
93 Effect.gen(function* () {
94 yield* Application("TestApp", {
95 description: "updated description",
96 tags: { purpose: "lifecycle-updated" },
97 });
98 }),
99 );
100 const updated = yield* appregistry.getApplication({
101 application: created.applicationId,
102 });
103 expect(updated.id).toBe(created.applicationId);
104 expect(updated.description).toBe("updated description");
105 expect(updated.tags?.purpose).toBe("lifecycle-updated");
106
107 // explicit name change → replacement (new application ID)
108 const replaced = yield* stack.deploy(
109 Effect.gen(function* () {
110 const app = yield* Application("TestApp", {
111 applicationName: `${created.applicationName}-renamed`,
112 description: "updated description",
113 });
114 return { applicationId: app.applicationId };
115 }),
116 );
117 expect(replaced.applicationId).not.toBe(created.applicationId);
118 yield* assertApplicationGone(created.applicationId);
119
120 yield* stack.destroy();
121 yield* assertApplicationGone(replaced.applicationId);
122 }),
123 {
124 tags: ["provider:aws", "provider:aws:appregistry", "live"],
125 timeout: 180_000,
126 },
127 );