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

main
ts 129 lines 5.25 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { SigningProfile } from "@alchemy.run/aws/Signer";
3 import { describe, expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as signer from "@distilled.cloud/aws/signer";
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 /**
12 * Signing profiles cannot be deleted — destroy cancels them. Wait (bounded)
13 * for the profile to observe as Canceled.
14 */
15 const assertProfileCanceled = (profileName: string) =>
16 signer.getSigningProfile({ profileName }).pipe(
17 Effect.repeat({
18 schedule: Schedule.fixed("2 seconds"),
19 until: (r) => r.status === "Canceled",
20 times: 10,
21 }),
22 Effect.map((r) => {
23 expect(r.status).toBe("Canceled");
24 }),
25 );
26
27 describe(
28 "AWS.Signer.SigningProfile",
29 { tags: ["provider:aws", "provider:aws:signer", "live"] },
30 () => {
31 test.provider(
32 "creates a Lambda code-signing profile, syncs tags, replaces on validity change, cancels on destroy",
33 (stack) =>
34 Effect.gen(function* () {
35 yield* stack.destroy();
36
37 // CREATE
38 const created = yield* stack.deploy(
39 Effect.gen(function* () {
40 const profile = yield* SigningProfile("ReleaseProfile", {
41 platformId: "AWSLambda-SHA384-ECDSA",
42 signatureValidityPeriod: { value: 12, type: "MONTHS" },
43 tags: { purpose: "alchemy-test" },
44 });
45 return {
46 profileName: profile.profileName,
47 arn: profile.arn,
48 profileVersion: profile.profileVersion,
49 profileVersionArn: profile.profileVersionArn,
50 platformId: profile.platformId,
51 status: profile.status,
52 };
53 }),
54 );
55
56 expect(created.platformId).toBe("AWSLambda-SHA384-ECDSA");
57 expect(created.status).toBe("Active");
58 expect(created.profileVersionArn).toContain(created.profileName);
59
60 // Verify out-of-band via distilled
61 const observed = yield* signer.getSigningProfile({ profileName: created.profileName });
62 expect(observed.arn).toEqual(created.arn);
63 expect(observed.profileVersion).toEqual(created.profileVersion);
64 expect(observed.status).toBe("Active");
65 expect(observed.platformId).toBe("AWSLambda-SHA384-ECDSA");
66 expect(observed.signatureValidityPeriod).toEqual({ value: 12, type: "MONTHS" });
67 expect(observed.tags?.purpose).toBe("alchemy-test");
68 // internal alchemy tags are branded on the profile
69 expect(Object.keys(observed.tags ?? {}).some((k) => k.startsWith("alchemy::"))).toBe(
70 true,
71 );
72
73 // UPDATE — tags are the only mutable aspect; the profile (name,
74 // arn, version) must be untouched
75 const updated = yield* stack.deploy(
76 Effect.gen(function* () {
77 const profile = yield* SigningProfile("ReleaseProfile", {
78 platformId: "AWSLambda-SHA384-ECDSA",
79 signatureValidityPeriod: { value: 12, type: "MONTHS" },
80 tags: { purpose: "alchemy-test", stage: "two" },
81 });
82 return {
83 profileName: profile.profileName,
84 arn: profile.arn,
85 profileVersion: profile.profileVersion,
86 };
87 }),
88 );
89
90 expect(updated.profileName).toEqual(created.profileName);
91 expect(updated.arn).toEqual(created.arn);
92 expect(updated.profileVersion).toEqual(created.profileVersion);
93
94 const afterUpdate = yield* signer.getSigningProfile({ profileName: created.profileName });
95 expect(afterUpdate.tags?.stage).toBe("two");
96 expect(afterUpdate.tags?.purpose).toBe("alchemy-test");
97
98 // REPLACE — PutSigningProfile is create-only, so changing the
99 // validity period replaces the profile under a new generated name
100 const replaced = yield* stack.deploy(
101 Effect.gen(function* () {
102 const profile = yield* SigningProfile("ReleaseProfile", {
103 platformId: "AWSLambda-SHA384-ECDSA",
104 signatureValidityPeriod: { value: 24, type: "MONTHS" },
105 tags: { purpose: "alchemy-test", stage: "two" },
106 });
107 return { profileName: profile.profileName, arn: profile.arn, status: profile.status };
108 }),
109 );
110
111 expect(replaced.profileName).not.toEqual(created.profileName);
112 expect(replaced.status).toBe("Active");
113
114 const afterReplace = yield* signer.getSigningProfile({
115 profileName: replaced.profileName,
116 });
117 expect(afterReplace.status).toBe("Active");
118 expect(afterReplace.signatureValidityPeriod).toEqual({ value: 24, type: "MONTHS" });
119 // the replaced (old) profile is canceled by the engine's delete
120 yield* assertProfileCanceled(created.profileName);
121
122 // DESTROY — the profile is canceled (Signer has no hard delete)
123 yield* stack.destroy();
124 yield* assertProfileCanceled(replaced.profileName);
125 }),
126 { timeout: 120_000 },
127 );
128 },
129 );