The best way to control Claude Code, Codex and more from any computer or phone

main
ts 120 lines 4.86 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { ComponentVersion, Deployment } from "@alchemy.run/aws/GreengrassV2";
3 import { Thing } from "@alchemy.run/aws/IoT";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as greengrassv2 from "@distilled.cloud/aws/greengrassv2";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: AWS.providers() });
11
12 // Ungated typed-error probe: prove the distilled error union carries the
13 // not-found tag the delete path depends on (deploymentId is a UUID, so a
14 // random-looking constant is safely nonexistent).
15 test.provider(
16 "getDeployment on a nonexistent id fails with ResourceNotFoundException",
17 () =>
18 Effect.gen(function* () {
19 const error = yield* Effect.flip(
20 greengrassv2.getDeployment({ deploymentId: "00000000-dead-beef-0000-000000000000" }),
21 );
22 expect(error._tag).toBe("ResourceNotFoundException");
23 }),
24 { tags: ["provider:aws", "provider:aws:greengrassv2", "live"] },
25 );
26
27 const COMPONENT_NAME = "com.alchemy.test.GgDeploy";
28
29 const recipe = JSON.stringify({
30 RecipeFormatVersion: "2020-01-25",
31 ComponentName: COMPONENT_NAME,
32 ComponentVersion: "1.0.0",
33 ComponentDescription: "Alchemy GreengrassV2 deployment test component",
34 ComponentPublisher: "Alchemy",
35 Manifests: [{ Platform: { os: "linux" }, Lifecycle: { run: "echo deployed by alchemy" } }],
36 });
37
38 const deploymentExists = (deploymentId: string) =>
39 greengrassv2.getDeployment({ deploymentId }).pipe(
40 Effect.map(() => true),
41 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(false)),
42 );
43
44 const waitUntilDeploymentGone = (deploymentId: string) =>
45 deploymentExists(deploymentId).pipe(
46 Effect.repeat({
47 schedule: Schedule.spaced("2 seconds"),
48 until: (exists) => exists === false,
49 times: 10,
50 }),
51 Effect.map((exists) => expect(exists).toBe(false)),
52 );
53
54 // A deployment targets an IoT thing (no live core device required — the
55 // deployment revision is created in the cloud and stays ACTIVE).
56 test.provider(
57 "create deployment for a thing, revise components, destroy",
58 (stack) =>
59 Effect.gen(function* () {
60 yield* stack.destroy();
61
62 const program = (merge?: string) =>
63 Effect.gen(function* () {
64 const core = yield* Thing("GgCore", {});
65 const component = yield* ComponentVersion("DeployHello", { recipe });
66 const deployment = yield* Deployment("Rollout", {
67 targetArn: core.thingArn,
68 components: {
69 [COMPONENT_NAME]: {
70 // Output-valued reference makes the deployment depend on the
71 // component version being registered first.
72 componentVersion: component.componentVersion,
73 ...(merge === undefined ? {} : { configurationUpdate: { merge } }),
74 },
75 },
76 tags: { fixture: "greengrass-deployment" },
77 });
78 return { core, component, deployment };
79 });
80
81 // 1. CREATE.
82 const { core, deployment } = yield* stack.deploy(program());
83 expect(deployment.deploymentId).toBeDefined();
84 expect(deployment.targetArn).toBe(core.thingArn);
85 expect(deployment.deploymentArn).toContain(`:deployments:${deployment.deploymentId}`);
86
87 // Out-of-band verification via distilled.
88 const observed = yield* greengrassv2.getDeployment({ deploymentId: deployment.deploymentId });
89 expect(observed.targetArn).toBe(core.thingArn);
90 expect(observed.isLatestForTarget).toBe(true);
91 expect(observed.components?.[COMPONENT_NAME]?.componentVersion).toBe("1.0.0");
92 expect(observed.tags?.["alchemy::id"]).toBe("Rollout");
93
94 // 2. UPDATE — changing the component spec creates a NEW deployment
95 // revision (fresh deploymentId) and deletes the superseded one.
96 const { deployment: revised } = yield* stack.deploy(
97 program(JSON.stringify({ interval: 30 })),
98 );
99 expect(revised.deploymentId).not.toBe(deployment.deploymentId);
100 const revisedObserved = yield* greengrassv2.getDeployment({
101 deploymentId: revised.deploymentId,
102 });
103 expect(revisedObserved.components?.[COMPONENT_NAME]?.configurationUpdate?.merge).toBe(
104 JSON.stringify({ interval: 30 }),
105 );
106 yield* waitUntilDeploymentGone(deployment.deploymentId);
107
108 // 3. NO-OP — re-deploying the same spec keeps the same revision.
109 const { deployment: stable } = yield* stack.deploy(program(JSON.stringify({ interval: 30 })));
110 expect(stable.deploymentId).toBe(revised.deploymentId);
111
112 // 4. DESTROY — the deployment is canceled and deleted.
113 yield* stack.destroy();
114 yield* waitUntilDeploymentGone(revised.deploymentId);
115 }),
116 {
117 tags: ["provider:aws", "provider:aws:greengrassv2", "provider:aws:iot", "live"],
118 timeout: 300_000,
119 },
120 );