The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as FileSystem from "effect/FileSystem"; |
| 4 | import * as Path from "effect/Path"; |
| 5 | import type * as Scope from "effect/Scope"; |
| 6 | import { describe, expect, it } from "vitest"; |
| 7 | import { ADAPTER_NAME, ADAPTER_PACKAGE, makeCloudflareTarget } from "../cloudflare.ts"; |
| 8 | import { fromHarnessOptions } from "../index.ts"; |
| 9 | import { readOctaneOutput } from "../Octane.ts"; |
| 10 | |
| 11 | const runWithNode = <A, E>( |
| 12 | effect: Effect.Effect<A, E, FileSystem.FileSystem | Path.Path | Scope.Scope>, |
| 13 | ): Promise<A> => |
| 14 | Effect.runPromise( |
| 15 | Effect.scoped(effect).pipe(Effect.provide(NodeServices.layer)) as Effect.Effect<A, E>, |
| 16 | ); |
| 17 | |
| 18 | describe("readOctaneOutput", () => { |
| 19 | it("maps an octane dist tree onto the BuildOutput contract, entry first", async () => { |
| 20 | const output = await runWithNode( |
| 21 | Effect.gen(function* () { |
| 22 | const fs = yield* FileSystem.FileSystem; |
| 23 | const path = yield* Path.Path; |
| 24 | const dir = yield* fs.makeTempDirectoryScoped({ |
| 25 | prefix: "octane-output-", |
| 26 | }); |
| 27 | const serverDir = path.join(dir, "server"); |
| 28 | const clientDir = path.join(dir, "client"); |
| 29 | yield* fs.makeDirectory(path.join(serverDir, "chunks"), { |
| 30 | recursive: true, |
| 31 | }); |
| 32 | yield* fs.makeDirectory(clientDir, { recursive: true }); |
| 33 | // alphabetically before worker.js, to prove entry-first sorting |
| 34 | yield* fs.writeFileString(path.join(serverDir, "chunks", "a.js"), "export const a = 1;"); |
| 35 | yield* fs.writeFileString(path.join(serverDir, "entry.js"), "export const e = 1;"); |
| 36 | yield* fs.writeFileString(path.join(serverDir, "worker.js"), "export default {};"); |
| 37 | // adapt() inputs embedded into worker.js — must NOT surface as modules |
| 38 | yield* fs.writeFileString(path.join(serverDir, "index.html"), "<!doctype html>"); |
| 39 | yield* fs.writeFileString(path.join(serverDir, "octane-client-assets.json"), "{}"); |
| 40 | yield* fs.writeFileString(path.join(clientDir, "robots.txt"), "User-agent: *\n"); |
| 41 | return yield* readOctaneOutput({ dir, serverDir, clientDir }); |
| 42 | }), |
| 43 | ); |
| 44 | expect(output.serverModules?.map((module) => module.name)).toEqual([ |
| 45 | "server/worker.js", |
| 46 | "server/chunks/a.js", |
| 47 | "server/entry.js", |
| 48 | ]); |
| 49 | expect(output.clientDirectory?.endsWith("client")).toBe(true); |
| 50 | expect(output.externalWorkspaces.size).toBe(0); |
| 51 | }); |
| 52 | |
| 53 | it("fails actionably when the adapter entry is missing", async () => { |
| 54 | const error = await runWithNode( |
| 55 | Effect.gen(function* () { |
| 56 | const fs = yield* FileSystem.FileSystem; |
| 57 | const path = yield* Path.Path; |
| 58 | const dir = yield* fs.makeTempDirectoryScoped({ |
| 59 | prefix: "octane-output-", |
| 60 | }); |
| 61 | const serverDir = path.join(dir, "server"); |
| 62 | const clientDir = path.join(dir, "client"); |
| 63 | yield* fs.makeDirectory(serverDir, { recursive: true }); |
| 64 | yield* fs.makeDirectory(clientDir, { recursive: true }); |
| 65 | yield* fs.writeFileString(path.join(serverDir, "entry.js"), "export const e = 1;"); |
| 66 | return yield* readOctaneOutput({ dir, serverDir, clientDir }).pipe(Effect.flip); |
| 67 | }), |
| 68 | ); |
| 69 | expect(error.message).toContain('no "server/worker.js" entry'); |
| 70 | expect(error.message).toContain("adapt()"); |
| 71 | }); |
| 72 | }); |
| 73 | |
| 74 | describe("makeCloudflareTarget", () => { |
| 75 | it("owns the Cloudflare build and accepts the optional legacy adapter", () => { |
| 76 | const target = makeCloudflareTarget({ compatibilityDate: "2026-03-10" }); |
| 77 | expect(target.platform).toBe("cloudflare"); |
| 78 | expect(target.requiresAdapter).toBeUndefined(); |
| 79 | expect(target.build).toBeTypeOf("function"); |
| 80 | expect(target.adapterName).toBe(ADAPTER_NAME); |
| 81 | expect(target.adapterPackage).toBe(ADAPTER_PACKAGE); |
| 82 | expect(target.serverEntryFileName).toBe("worker.js"); |
| 83 | expect(target.config.compatibilityDate).toBe("2026-03-10"); |
| 84 | }); |
| 85 | }); |
| 86 | |
| 87 | describe("fromHarnessOptions", () => { |
| 88 | it("prefers the target-scoped carriage over the deprecated vite alias", () => { |
| 89 | const options = fromHarnessOptions({ |
| 90 | target: { |
| 91 | cloudflare: { |
| 92 | worker: { |
| 93 | compatibilityDate: "2026-03-10", |
| 94 | compatibilityFlags: ["nodejs_compat"], |
| 95 | }, |
| 96 | }, |
| 97 | }, |
| 98 | vite: { compatibilityDate: "2020-01-01" }, |
| 99 | }); |
| 100 | expect(options.compatibilityDate).toBe("2026-03-10"); |
| 101 | expect(options.compatibilityFlags).toEqual(["nodejs_compat"]); |
| 102 | }); |
| 103 | }); |