@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 210 lines 8.54 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import * as AppConfig from "@alchemy.run/aws/AppConfig";
3 import { AWSEnvironment } from "@alchemy.run/aws/Environment";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as appconfig from "@distilled.cloud/aws/appconfig";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9 import * as Stream from "effect/Stream";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 const getApp = (applicationId: string) =>
14 appconfig
15 .getApplication({ ApplicationId: applicationId })
16 .pipe(Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)));
17
18 const waitUntilAppGone = (applicationId: string) =>
19 getApp(applicationId).pipe(
20 Effect.repeat({
21 schedule: Schedule.spaced("2 seconds"),
22 until: (a) => a === undefined,
23 times: 10,
24 }),
25 );
26
27 // Full AppConfig control-plane lifecycle in one stack: application ->
28 // environment -> hosted configuration profile -> hosted version, plus a
29 // standalone deployment strategy. Everything is fast and free. Update the
30 // application description in place, then destroy and verify out-of-band.
31 test.provider(
32 "appconfig control plane: create the full chain, update, and destroy",
33 (stack) =>
34 Effect.gen(function* () {
35 yield* stack.destroy();
36
37 const deploy = (description: string) =>
38 stack.deploy(
39 Effect.gen(function* () {
40 const app = yield* AppConfig.Application("App", {
41 description,
42 tags: { team: "platform" },
43 });
44 const env = yield* AppConfig.Environment("Env", {
45 applicationId: app.applicationId,
46 });
47 const profile = yield* AppConfig.ConfigurationProfile("Profile", {
48 applicationId: app.applicationId,
49 locationUri: "hosted",
50 });
51 const version = yield* AppConfig.HostedConfigurationVersion("V1", {
52 applicationId: app.applicationId,
53 configurationProfileId: profile.configurationProfileId,
54 content: JSON.stringify({ featureX: true }),
55 contentType: "application/json",
56 });
57 const strategy = yield* AppConfig.DeploymentStrategy("Strategy", {
58 deploymentDuration: 0,
59 growthFactor: 100,
60 finalBakeTime: 0,
61 replicateTo: "NONE",
62 });
63 return {
64 applicationId: app.applicationId.as<string>(),
65 applicationArn: app.applicationArn.as<string>(),
66 environmentId: env.environmentId.as<string>(),
67 configurationProfileId: profile.configurationProfileId.as<string>(),
68 versionNumber: version.versionNumber.as<number>(),
69 strategyId: strategy.deploymentStrategyId.as<string>(),
70 };
71 }),
72 );
73
74 const created = yield* deploy("v1 description");
75 expect(created.applicationId).toBeTruthy();
76 expect(created.environmentId).toBeTruthy();
77 expect(created.configurationProfileId).toBeTruthy();
78 expect(created.versionNumber).toBe(1);
79 expect(created.strategyId).toBeTruthy();
80
81 // Out-of-band: the application exists and carries alchemy + user tags.
82 const app = yield* getApp(created.applicationId);
83 expect(app?.Description).toBe("v1 description");
84 const tags = yield* appconfig.listTagsForResource({
85 ResourceArn: created.applicationArn,
86 });
87 expect(tags.Tags?.["alchemy::id"]).toBe("App");
88 expect(tags.Tags?.team).toBe("platform");
89
90 // Out-of-band: the hosted version content round-trips.
91 const version = yield* appconfig.getHostedConfigurationVersion({
92 ApplicationId: created.applicationId,
93 ConfigurationProfileId: created.configurationProfileId,
94 VersionNumber: created.versionNumber,
95 });
96 const content = yield* Stream.mkString(Stream.decodeText(version.Content!));
97 expect(JSON.parse(content)).toEqual({ featureX: true });
98
99 // Update the description in place — the application id is stable.
100 const updated = yield* deploy("v2 description");
101 expect(updated.applicationId).toBe(created.applicationId);
102 const appAfter = yield* getApp(created.applicationId);
103 expect(appAfter?.Description).toBe("v2 description");
104
105 // Destroy — the application (and its children) are gone.
106 yield* stack.destroy();
107 const gone = yield* waitUntilAppGone(created.applicationId);
108 expect(gone).toBeUndefined();
109 }),
110 {
111 tags: ["provider:aws", "provider:aws:appconfig", "live"],
112 timeout: 240_000,
113 },
114 );
115
116 // Extension + association lifecycle: an extension whose action emits
117 // deployment events to the default EventBridge bus (AppConfig EventBridge
118 // extension actions only support the default bus; no invoke role required),
119 // associated with the application. Update the extension description in
120 // place, then destroy and verify out-of-band.
121 test.provider(
122 "appconfig extension: create, associate, update, and destroy",
123 (stack) =>
124 Effect.gen(function* () {
125 yield* stack.destroy();
126
127 const { accountId, region } = yield* AWSEnvironment.current;
128 const defaultBusArn = `arn:aws:events:${region}:${accountId}:event-bus/default`;
129
130 const deploy = (description: string) =>
131 stack.deploy(
132 Effect.gen(function* () {
133 const app = yield* AppConfig.Application("ExtApp", {});
134 const extension = yield* AppConfig.Extension("Ext", {
135 description,
136 actions: {
137 ON_DEPLOYMENT_COMPLETE: [{ name: "notify-bus", uri: defaultBusArn }],
138 },
139 tags: { team: "platform" },
140 });
141 const association = yield* AppConfig.ExtensionAssociation("ExtAssoc", {
142 extensionIdentifier: extension.extensionId,
143 resourceIdentifier: app.applicationArn,
144 });
145 return {
146 extensionId: extension.extensionId.as<string>(),
147 extensionArn: extension.extensionArn.as<string>(),
148 versionNumber: extension.versionNumber.as<number>(),
149 associationId: association.extensionAssociationId.as<string>(),
150 };
151 }),
152 );
153
154 const created = yield* deploy("v1 hook");
155 expect(created.extensionId).toBeTruthy();
156 expect(created.versionNumber).toBeGreaterThan(0);
157 expect(created.associationId).toBeTruthy();
158
159 // Out-of-band: the extension exists with the action and alchemy tags.
160 const extension = yield* appconfig.getExtension({
161 ExtensionIdentifier: created.extensionId,
162 });
163 expect(extension.Description).toBe("v1 hook");
164 expect(extension.Actions?.ON_DEPLOYMENT_COMPLETE?.[0]?.Name).toBe("notify-bus");
165 const tags = yield* appconfig.listTagsForResource({
166 ResourceArn: created.extensionArn,
167 });
168 expect(tags.Tags?.["alchemy::id"]).toBe("Ext");
169
170 // Out-of-band: the association binds the extension to the application.
171 const association = yield* appconfig.getExtensionAssociation({
172 ExtensionAssociationId: created.associationId,
173 });
174 expect(association.ExtensionArn).toBeTruthy();
175 expect(association.ResourceArn).toContain(":application/");
176
177 // Update the description in place — id and association are stable.
178 const updated = yield* deploy("v2 hook");
179 expect(updated.extensionId).toBe(created.extensionId);
180 expect(updated.associationId).toBe(created.associationId);
181 const after = yield* appconfig.getExtension({
182 ExtensionIdentifier: created.extensionId,
183 });
184 expect(after.Description).toBe("v2 hook");
185
186 // Destroy — association first, then the extension.
187 yield* stack.destroy();
188 const goneExtension = yield* appconfig
189 .getExtension({ ExtensionIdentifier: created.extensionId })
190 .pipe(
191 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)),
192 Effect.repeat({
193 schedule: Schedule.spaced("2 seconds"),
194 until: (e): boolean => e === undefined,
195 times: 10,
196 }),
197 );
198 expect(goneExtension).toBeUndefined();
199 const goneAssociation = yield* appconfig
200 .getExtensionAssociation({
201 ExtensionAssociationId: created.associationId,
202 })
203 .pipe(Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)));
204 expect(goneAssociation).toBeUndefined();
205 }),
206 {
207 tags: ["provider:aws", "provider:aws:appconfig", "live"],
208 timeout: 240_000,
209 },
210 );