Files
OmniRoute/tests/unit/claude-web-executor-split.test.ts
Diego Rodrigues de Sa e Souza 1a73dd2936 refactor(executors): extract pure payload construction from claude-web (#6006)
Extract the pure Claude-web payload types + transforms + default tools/style
(ClaudeWebRequestPayload, ClaudeWebStreamChunk, DEFAULT_CLAUDE_MODEL,
generateMessageUUIDs, getDefaultTools, getDefaultPersonalizedStyle, transformToClaude,
transformFromClaude) verbatim into the leaf claude-web/payload.ts. Host imports the 3
it uses back (ClaudeWebRequestPayload type + the two transforms).

Host 1056 -> 835 LOC. Byte-identical bodies (verbatim 149/149), leaf imports only
randomUUID (no host import, no cycle), all module-private (no re-export). Cookie/auth/
Turnstile/TLS/HTTP dispatch untouched. Adds a split-guard; consumer tests stay green
(claude-web 13, claude-web-auto-refresh 6).
2026-07-02 20:59:33 -03:00

39 lines
1.6 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
// Split-guard for the claude-web executor payload extraction.
// The pure payload types + transforms + default tools/style live in the leaf
// claude-web/payload.ts (no host state, no fetch/auth). Host imports back the
// symbols it uses (ClaudeWebRequestPayload, transformToClaude, transformFromClaude).
const HERE = dirname(fileURLToPath(import.meta.url));
const EXE = join(HERE, "../../open-sse/executors");
const HOST = join(EXE, "claude-web.ts");
const LEAF = join(EXE, "claude-web/payload.ts");
test("leaf hosts the payload builders/transforms and does not import the host", () => {
const src = readFileSync(LEAF, "utf8");
for (const sym of ["transformToClaude", "transformFromClaude", "getDefaultTools"]) {
assert.match(src, new RegExp(`export function ${sym}\\b`));
}
assert.match(src, /export interface ClaudeWebRequestPayload\b/);
assert.doesNotMatch(src, /from "\.\.\/claude-web\.ts"/);
});
test("host imports the transforms back from the leaf", () => {
const host = readFileSync(HOST, "utf8");
assert.match(host, /from "\.\/claude-web\/payload\.ts"/);
});
test("transformToClaude builds a Claude-web payload with model + tools", async () => {
const { transformToClaude } = await import("../../open-sse/executors/claude-web/payload.ts");
const payload = transformToClaude(
{ messages: [{ role: "user", content: "hi" }] },
"claude-sonnet-4-6"
);
assert.equal(typeof payload, "object");
assert.ok(Array.isArray(payload.tools));
});