The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Cloudflare from "@alchemy.run/cloudflare"; |
| 2 | import { describe, expect, registerFileCleanup } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import { Interaction } from "alchemy/Interaction"; |
| 5 | import { RpcProviderProxy } from "alchemy/Local/RpcProviderProxy"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as Layer from "effect/Layer"; |
| 8 | |
| 9 | /** |
| 10 | * Contract tests for the test harness's sidecar topology (see |
| 11 | * MakeOptions.sidecar in Test/Core.ts): `dev: true` runs local providers |
| 12 | * behind the RPC proxy used by the real `alchemy dev` command BY DEFAULT, |
| 13 | * and `sidecar: false` opts back into the in-process topology. |
| 14 | * |
| 15 | * The dev-mode resource tests (KV/R2/Queue/D1 `*.local.test.ts`) would |
| 16 | * still pass in-process if the default silently stopped installing the |
| 17 | * proxy — the whole point of the topology is that missing main-process |
| 18 | * dependencies only surface under it (#1007). These tests pin the harness |
| 19 | * contract directly so a refactor of Test.make can't quietly demote every |
| 20 | * dev test back to in-process. |
| 21 | */ |
| 22 | |
| 23 | const dev = Test.make({ |
| 24 | providers: Cloudflare.providers(), |
| 25 | dev: true, |
| 26 | }); |
| 27 | |
| 28 | const inProcess = Test.make({ |
| 29 | providers: Cloudflare.providers(), |
| 30 | dev: true, |
| 31 | sidecar: false, |
| 32 | }); |
| 33 | |
| 34 | const live = Test.make({ |
| 35 | providers: Cloudflare.providers(), |
| 36 | }); |
| 37 | |
| 38 | dev.test( |
| 39 | "dev: true installs the RpcProviderProxy by default", |
| 40 | Effect.gen(function* () { |
| 41 | const proxy = yield* Effect.serviceOption(RpcProviderProxy); |
| 42 | expect(proxy._tag).toBe("Some"); |
| 43 | }), |
| 44 | { tags: ["provider:cloudflare", "local"] }, |
| 45 | ); |
| 46 | |
| 47 | inProcess.test( |
| 48 | "sidecar: false opts a dev test out of the RpcProviderProxy", |
| 49 | Effect.gen(function* () { |
| 50 | const proxy = yield* Effect.serviceOption(RpcProviderProxy); |
| 51 | expect(proxy._tag).toBe("None"); |
| 52 | }), |
| 53 | { tags: ["provider:cloudflare", "local"] }, |
| 54 | ); |
| 55 | |
| 56 | live.test( |
| 57 | "non-dev tests do not install the RpcProviderProxy", |
| 58 | Effect.gen(function* () { |
| 59 | const proxy = yield* Effect.serviceOption(RpcProviderProxy); |
| 60 | expect(proxy._tag).toBe("None"); |
| 61 | }), |
| 62 | { tags: ["provider:cloudflare", "local"] }, |
| 63 | ); |
| 64 | |
| 65 | live.test( |
| 66 | "test runtimes provide a non-interactive Interaction", |
| 67 | Effect.gen(function* () { |
| 68 | const interaction = yield* Interaction; |
| 69 | const failure = yield* Effect.flip(interaction.prompt.confirm({ message: "?" })); |
| 70 | expect(failure._tag).toBe("NonInteractiveTerminal"); |
| 71 | }), |
| 72 | { tags: ["provider:cloudflare", "local"] }, |
| 73 | ); |
| 74 | |
| 75 | const cleanupOrder: Array<string> = []; |
| 76 | |
| 77 | describe("file-owned runtime cleanup", () => { |
| 78 | const nested = Test.make({ |
| 79 | providers: Layer.empty, |
| 80 | dev: true, |
| 81 | sidecar: true, |
| 82 | }); |
| 83 | nested.beforeAll( |
| 84 | Effect.addFinalizer(() => |
| 85 | Effect.sync(() => { |
| 86 | cleanupOrder.push("scope"); |
| 87 | }), |
| 88 | ), |
| 89 | ); |
| 90 | nested.test( |
| 91 | "retains the shared runtime until file cleanup", |
| 92 | Effect.sync(() => { |
| 93 | expect(cleanupOrder).toEqual([]); |
| 94 | }), |
| 95 | { tags: ["unit", "local"] }, |
| 96 | ); |
| 97 | nested.afterAll( |
| 98 | Effect.sync(() => { |
| 99 | expect(cleanupOrder).toEqual([]); |
| 100 | cleanupOrder.push("user"); |
| 101 | }), |
| 102 | ); |
| 103 | |
| 104 | const skipped = Test.make({ |
| 105 | providers: Layer.empty, |
| 106 | dev: true, |
| 107 | sidecar: true, |
| 108 | }); |
| 109 | skipped.test.skip("unused handles need no RPC session", Effect.void, { tags: ["unit", "local"] }); |
| 110 | }); |
| 111 | |
| 112 | live.afterAll( |
| 113 | Effect.sync(() => { |
| 114 | expect(cleanupOrder).not.toContain("scope"); |
| 115 | }), |
| 116 | ); |
| 117 | |
| 118 | registerFileCleanup({ |
| 119 | body: () => |
| 120 | Effect.sync(() => { |
| 121 | if (cleanupOrder.length > 0) expect(cleanupOrder).toEqual(["user", "scope"]); |
| 122 | cleanupOrder.length = 0; |
| 123 | }), |
| 124 | }); |