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

main
ts 76 lines 2.84 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { CapacityProvider } from "@alchemy.run/aws/ECS";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as ecs from "@distilled.cloud/aws/ecs";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 // Skipped by default: requires a pre-provisioned EC2 Auto Scaling Group ARN
14 // (set via TEST_ASG_ARN) because AutoScalingGroup/LaunchTemplate currently
15 // have no test infrastructure in this repo. Run locally with:
16 // TEST_ASG_ARN=arn:aws:autoscaling:... bun vitest CapacityProvider
17 test.provider.skipIf(!process.env.TEST_ASG_ARN)(
18 "create, update, delete ECS capacity provider",
19 (stack) =>
20 Effect.gen(function* () {
21 const autoScalingGroupArn = process.env.TEST_ASG_ARN!;
22 yield* stack.destroy();
23
24 const provider = yield* stack.deploy(
25 CapacityProvider("TestCapacityProvider", {
26 autoScalingGroupArn,
27 managedScaling: {
28 status: "ENABLED",
29 targetCapacity: 80,
30 minimumScalingStepSize: 1,
31 maximumScalingStepSize: 10,
32 },
33 managedTerminationProtection: "DISABLED",
34 tags: { env: "test" },
35 }),
36 );
37
38 expect(provider.capacityProviderArn).toMatch(/^arn:aws:ecs:[^:]+:\d+:capacity-provider\//);
39 expect(provider.status).toEqual("ACTIVE");
40 expect(provider.managedScaling?.targetCapacity).toEqual(80);
41 expect(provider.tags.env).toEqual("test");
42
43 const described = yield* ecs.describeCapacityProviders({
44 capacityProviders: [provider.name],
45 include: ["TAGS"],
46 });
47 const found = described.capacityProviders?.[0];
48 expect(found?.name).toEqual(provider.name);
49 expect(found?.autoScalingGroupProvider?.managedScaling?.targetCapacity).toEqual(80);
50
51 const updated = yield* stack.deploy(
52 CapacityProvider("TestCapacityProvider", {
53 autoScalingGroupArn,
54 managedScaling: {
55 status: "ENABLED",
56 targetCapacity: 60,
57 minimumScalingStepSize: 1,
58 maximumScalingStepSize: 5,
59 },
60 managedTerminationProtection: "DISABLED",
61 tags: { env: "test", owner: "alchemy" },
62 }),
63 );
64
65 expect(updated.managedScaling?.targetCapacity).toEqual(60);
66 expect(updated.tags.owner).toEqual("alchemy");
67
68 yield* stack.destroy();
69
70 const afterDestroy = yield* ecs.describeCapacityProviders({
71 capacityProviders: [provider.name],
72 });
73 expect(afterDestroy.capacityProviders ?? []).toHaveLength(0);
74 }).pipe(logLevel),
75 { tags: ["provider:aws", "provider:aws:ecs", "live"], timeout: 600_000 },
76 );