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

main
ts 96 lines 4.01 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as batch from "@distilled.cloud/aws/batch";
5 import * as logs from "@distilled.cloud/aws/cloudwatch-logs";
6 import * as Effect from "effect/Effect";
7 import * as Schedule from "effect/Schedule";
8 import { materializeIsolatedProject, removeIsolatedProject } from "../../IsolatedProject.ts";
9 import IsolatedProjectJob, { MARKER, project } from "./fixtures/isolated-project-job.ts";
10 import { BatchTestNetwork } from "./TestNetwork.ts";
11
12 const { test } = Test.make({ providers: AWS.providers() });
13
14 // Live proof that the Batch bun bootstrap boots when the job's `main` lives
15 // in an isolated project (see test/IsolatedProject.ts) — the bundle `cwd`
16 // resolves none of alchemy's dependencies, so the bootstrap's
17 // `@distilled.cloud/aws/*` / `@effect/platform-bun` imports must be bundled
18 // by the virtual-entry plugin rather than found from the project root. With
19 // them left external bun dies at module load and the job FAILS.
20 //
21 // Heavy (Docker build + ECR push + compute environment + Fargate job run,
22 // ~2.5 minutes), so skipped under --fast like the platform e2e.
23 test.provider.skipIf(!!process.env.FAST)(
24 "job bundled from an isolated project runs to SUCCEEDED",
25 (stack) =>
26 Effect.gen(function* () {
27 yield* materializeIsolatedProject(project);
28 yield* stack.destroy();
29
30 try {
31 const outputs = yield* stack.deploy(
32 Effect.gen(function* () {
33 const network = yield* BatchTestNetwork;
34 const computeEnvironment = yield* AWS.Batch.ComputeEnvironment("IsolatedProjectCE", {
35 subnets: network.subnetIds,
36 securityGroupIds: network.securityGroupIds,
37 });
38 const queue = yield* AWS.Batch.JobQueue("IsolatedProjectQueue", {
39 computeEnvironments: [computeEnvironment.computeEnvironmentArn],
40 });
41 const job = yield* IsolatedProjectJob;
42 return {
43 jobQueueArn: queue.jobQueueArn,
44 jobDefinitionArn: job.jobDefinitionArn,
45 };
46 }),
47 );
48
49 const submitted = yield* batch.submitJob({
50 jobName: "alchemy-isolated-project-run",
51 jobQueue: outputs.jobQueueArn,
52 jobDefinition: outputs.jobDefinitionArn!,
53 });
54 const job = yield* batch.describeJobs({ jobs: [submitted.jobId] }).pipe(
55 Effect.map((result) => result.jobs?.[0]),
56 Effect.repeat({
57 schedule: Schedule.spaced("10 seconds"),
58 until: (j): boolean => j?.status === "SUCCEEDED" || j?.status === "FAILED",
59 times: 60,
60 }),
61 );
62 // SUCCEEDED = container exit 0 = the bootstrap booted and ran `run`
63 // (the reason is included so a FAILED run shows why).
64 expect(`${job?.status}: ${job?.statusReason ?? ""}`).toMatch(/^SUCCEEDED:/);
65
66 // The bundled program actually executed: its marker is in the job's
67 // log stream (log delivery can lag the state change slightly).
68 const logStreamName = job?.container?.logStreamName;
69 expect(logStreamName).toBeTruthy();
70 const seen = yield* logs
71 .getLogEvents({
72 logGroupName: "/aws/batch/job",
73 logStreamName: logStreamName!,
74 })
75 .pipe(
76 Effect.flatMap((result) =>
77 (result.events ?? []).some((e) => e.message?.includes(MARKER))
78 ? Effect.succeed(true)
79 : Effect.fail(new Error("marker not in log stream yet")),
80 ),
81 Effect.retry({ schedule: Schedule.spaced("5 seconds"), times: 12 }),
82 );
83 expect(seen).toBe(true);
84
85 yield* stack.destroy();
86 } finally {
87 yield* removeIsolatedProject(project);
88 }
89 }),
90 // Docker build + push (~2-4 min) + CE/queue (~1-2 min) + Fargate job run
91 // (~2-4 min) + destroy (~2-3 min).
92 {
93 tags: ["provider:aws", "provider:aws:batch", "provider:aws:ec2", "live"],
94 timeout: 1_200_000,
95 },
96 );