@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, 06:00 UTC

main
ts 84 lines 3.05 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { JobDefinition } from "@alchemy.run/aws/Batch/JobDefinition";
3 import { Role } from "@alchemy.run/aws/IAM/Role";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as batch from "@distilled.cloud/aws/batch";
7 import * as Effect from "effect/Effect";
8 import * as Stream from "effect/Stream";
9
10 const { test } = Test.make({ providers: AWS.providers() });
11
12 const name = "alchemy-test-batch-jobdef";
13
14 const activeRevisions = batch.describeJobDefinitions
15 .pages({ jobDefinitionName: name, status: "ACTIVE" })
16 .pipe(
17 Stream.runCollect,
18 Effect.map((pages) => Array.from(pages).flatMap((p) => p.jobDefinitions ?? [])),
19 );
20
21 const jobDef = (command: string[]) =>
22 Effect.gen(function* () {
23 const executionRole = yield* Role("JobDefExecutionRole", {
24 assumeRolePolicyDocument: {
25 Version: "2012-10-17",
26 Statement: [
27 {
28 Effect: "Allow",
29 Principal: { Service: "ecs-tasks.amazonaws.com" },
30 Action: ["sts:AssumeRole"],
31 },
32 ],
33 },
34 managedPolicyArns: ["arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"],
35 });
36 return yield* JobDefinition("EchoJobDef", {
37 jobDefinitionName: name,
38 image: "public.ecr.aws/docker/library/busybox:latest",
39 command,
40 executionRoleArn: executionRole.roleArn,
41 });
42 });
43
44 test.provider(
45 "revision semantics: register, no-op redeploy, revise, deregister all",
46 (stack) =>
47 Effect.gen(function* () {
48 yield* stack.destroy();
49
50 // Register revision 1.
51 const created = yield* stack.deploy(jobDef(["echo", "one"]));
52 expect(created.jobDefinitionName).toBe(name);
53 const firstRevision = created.revision;
54 expect(firstRevision).toBeGreaterThanOrEqual(1);
55 expect(created.jobDefinitionArn).toContain(`job-definition/${name}:${firstRevision}`);
56
57 // Identical content — no new revision registered.
58 const unchanged = yield* stack.deploy(jobDef(["echo", "one"]));
59 expect(unchanged.revision).toBe(firstRevision);
60 expect(yield* activeRevisions).toHaveLength(1);
61
62 // Changed command — a new immutable revision under the same family.
63 const revised = yield* stack.deploy(jobDef(["echo", "two"]));
64 expect(revised.revision).toBe(firstRevision + 1);
65 const revisions = yield* activeRevisions;
66 expect(revisions).toHaveLength(2);
67 const latest = revisions.find((d) => d.revision === revised.revision);
68 expect(latest?.containerProperties?.command).toEqual(["echo", "two"]);
69 expect(latest?.containerProperties?.resourceRequirements).toEqual(
70 expect.arrayContaining([
71 { type: "VCPU", value: "0.25" },
72 { type: "MEMORY", value: "512" },
73 ]),
74 );
75
76 // Destroy — EVERY active revision of the family is deregistered.
77 yield* stack.destroy();
78 expect(yield* activeRevisions).toHaveLength(0);
79 }),
80 {
81 tags: ["provider:aws", "provider:aws:batch", "provider:aws:iam", "live"],
82 timeout: 240_000,
83 },
84 );