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

main
ts 122 lines 4.89 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { AutoScalingConfiguration } from "@alchemy.run/aws/AppRunner";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as apprunner from "@distilled.cloud/aws/apprunner";
6 import * as sts from "@distilled.cloud/aws/sts";
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: proves the distilled error union carries the
13 // not-found tag this provider's read/delete paths depend on.
14 test.provider(
15 "describeAutoScalingConfiguration on a nonexistent ARN fails with ResourceNotFoundException",
16 () =>
17 Effect.gen(function* () {
18 const { Account } = yield* sts.getCallerIdentity({});
19 const error = yield* Effect.flip(
20 apprunner.describeAutoScalingConfiguration({
21 AutoScalingConfigurationArn: `arn:aws:apprunner:us-west-2:${Account}:autoscalingconfiguration/alchemy-nonexistent-probe/1/00000000000000000000000000000000`,
22 }),
23 );
24 expect(error._tag).toBe("ResourceNotFoundException");
25 }),
26 { tags: ["provider:aws", "provider:aws:apprunner", "live"] },
27 );
28
29 // No ACTIVE revision of the named configuration remains (deleted configs
30 // linger as INACTIVE for observability).
31 const assertConfigGone = (name: string) =>
32 Effect.gen(function* () {
33 const page = yield* apprunner.listAutoScalingConfigurations({
34 AutoScalingConfigurationName: name,
35 });
36 // App Runner returns lowercase statuses ("active") despite documenting
37 // uppercase — compare case-insensitively.
38 const active = (page.AutoScalingConfigurationSummaryList ?? []).filter(
39 (s) => s.AutoScalingConfigurationName === name && s.Status?.toUpperCase() === "ACTIVE",
40 );
41 if (active.length > 0) {
42 return yield* Effect.fail(
43 new Error(
44 `Auto scaling configuration '${name}' still has ${active.length} ACTIVE revision(s)`,
45 ),
46 );
47 }
48 }).pipe(
49 Effect.retry({
50 schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(8)]),
51 }),
52 );
53
54 // Auto scaling configurations are immutable revisions — fast and free, so
55 // the full lifecycle (create, no-op, revise, replace-by-name, destroy)
56 // runs ungated.
57 test.provider(
58 "create, revise, replace, and destroy an auto scaling configuration",
59 (stack) =>
60 Effect.gen(function* () {
61 // Clean slate in case a previous run died mid-flight.
62 yield* stack.destroy();
63
64 const props = {
65 autoScalingConfigurationName: "alchemy-test-asc",
66 maxConcurrency: 50,
67 minSize: 1,
68 maxSize: 3,
69 };
70
71 // Create.
72 const created = yield* stack.deploy(AutoScalingConfiguration("Asc", props));
73 expect(created.autoScalingConfigurationName).toBe("alchemy-test-asc");
74 expect(created.autoScalingConfigurationArn).toContain(
75 ":autoscalingconfiguration/alchemy-test-asc/",
76 );
77 expect(created.maxConcurrency).toBe(50);
78 expect(created.maxSize).toBe(3);
79
80 // Out-of-band verification via distilled.
81 const described = yield* apprunner.describeAutoScalingConfiguration({
82 AutoScalingConfigurationArn: created.autoScalingConfigurationArn,
83 });
84 expect(described.AutoScalingConfiguration.Status?.toUpperCase()).toBe("ACTIVE");
85 expect(described.AutoScalingConfiguration.MaxConcurrency).toBe(50);
86 expect(described.AutoScalingConfiguration.MinSize).toBe(1);
87 expect(described.AutoScalingConfiguration.MaxSize).toBe(3);
88
89 // No-op redeploy must not create a new revision.
90 const noop = yield* stack.deploy(AutoScalingConfiguration("Asc", props));
91 expect(noop.autoScalingConfigurationRevision).toBe(created.autoScalingConfigurationRevision);
92
93 // Settings change → new revision under the same name.
94 const revised = yield* stack.deploy(
95 AutoScalingConfiguration("Asc", { ...props, maxConcurrency: 80 }),
96 );
97 expect(revised.autoScalingConfigurationName).toBe("alchemy-test-asc");
98 expect(revised.autoScalingConfigurationRevision).toBe(
99 created.autoScalingConfigurationRevision + 1,
100 );
101 expect(revised.autoScalingConfigurationArn).not.toBe(created.autoScalingConfigurationArn);
102 expect(revised.maxConcurrency).toBe(80);
103
104 // Name change → replace; every revision of the old name is deleted.
105 const replaced = yield* stack.deploy(
106 AutoScalingConfiguration("Asc", {
107 ...props,
108 autoScalingConfigurationName: "alchemy-test-asc-b",
109 }),
110 );
111 expect(replaced.autoScalingConfigurationName).toBe("alchemy-test-asc-b");
112 yield* assertConfigGone("alchemy-test-asc");
113
114 // Destroy and verify deletion out-of-band.
115 yield* stack.destroy();
116 yield* assertConfigGone("alchemy-test-asc-b");
117 }),
118 {
119 tags: ["provider:aws", "provider:aws:apprunner", "live"],
120 timeout: 120_000,
121 },
122 );