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

main
ts 85 lines 3 KB
Raw
1 import { waitForContainerImage } from "@alchemy.run/cloudflare/Containers/ContainerImagePreparation";
2 import { describe, expect, it } from "@alchemy.run/test";
3 import type { NoteKind } from "alchemy/Events";
4 import * as Effect from "effect/Effect";
5 import * as Fiber from "effect/Fiber";
6 import * as TestClock from "effect/testing/TestClock";
7
8 const image = "registry.cloudflare.com/account/shell@sha256:digest";
9 const fixture = () => {
10 const notes: { message: string; kind?: NoteKind }[] = [];
11 return {
12 notes,
13 session: {
14 note: (message: string, options?: { kind?: NoteKind }) =>
15 Effect.sync(() => {
16 notes.push({ message, kind: options?.kind });
17 }),
18 },
19 };
20 };
21 // A deadline measured in tens of minutes cannot run against the live API;
22 // these pin the deadline and failure semantics of the preparation wait.
23 describe(
24 "container image preparation",
25 { tags: ["unit", "local", "provider:cloudflare:container"] },
26 () => {
27 it.effect("bounds pending preparation at the default thirty-minute deadline", () =>
28 Effect.gen(function* () {
29 const { session } = fixture();
30 const fiber = yield* waitForContainerImage({
31 image,
32 name: "shell",
33 prepare: Effect.succeed({ image, status: "pending" }),
34 session,
35 }).pipe(Effect.flip, Effect.forkChild);
36 yield* TestClock.adjust("30 minutes");
37 const error = yield* Fiber.join(fiber);
38 expect(error._tag).toBe("ContainerImagePreparationError");
39 expect(error.message).toContain("30 minutes");
40 expect(error.message).toContain(image);
41 expect(error.message).toContain("resume from the published image");
42 }),
43 );
44 it.effect("applies a configured deadline to a stalled API call", () =>
45 Effect.gen(function* () {
46 const { session } = fixture();
47 let interrupted = false;
48 const prepare = Effect.never.pipe(
49 Effect.onInterrupt(() =>
50 Effect.sync(() => {
51 interrupted = true;
52 }),
53 ),
54 );
55 const fiber = yield* waitForContainerImage({
56 image,
57 name: "shell",
58 timeout: "10 seconds",
59 prepare,
60 session,
61 }).pipe(Effect.flip, Effect.forkChild);
62 yield* TestClock.adjust("10 seconds");
63 expect((yield* Fiber.join(fiber))._tag).toBe("ContainerImagePreparationError");
64 expect(interrupted).toBe(true);
65 }),
66 );
67 it.effect("fails immediately with Cloudflare's preparation reason", () =>
68 Effect.gen(function* () {
69 const { session } = fixture();
70 let calls = 0;
71 const error = yield* waitForContainerImage({
72 image,
73 name: "shell",
74 session,
75 prepare: Effect.sync(() => {
76 calls++;
77 return { image, status: "error" as const, reason: "unsupported image" };
78 }),
79 }).pipe(Effect.flip);
80 expect(error.message).toBe("unsupported image");
81 expect(calls).toBe(1);
82 }),
83 );
84 },
85 );