Files
OmniRoute/tests/unit/perplexity-web-executor-split.test.ts
Diego Rodrigues de Sa e Souza 7bcd750d72 refactor(executors): extract pure wire protocol from perplexity-web (#6014)
Extract the pure Perplexity wire protocol (consts, SSE stream types, SSE parsing,
OpenAI<->Perplexity message translation, request/query builders, content extraction,
sseChunk) verbatim into the leaf perplexity-web/protocol.ts. Host imports back the 10
symbols it uses; everything module-private (no re-export). Session cache, TLS fetch,
auth, and the executor class stay in the host.

Host 1028 -> 534 LOC. Byte-identical bodies (verbatim), leaf imports only randomUUID
(no host import, no cycle). Adds a split-guard; consumer tests stay green
(perplexity-web 26, streaming-tools-5927 2, tls-client 6, key-validation-models 2).
2026-07-02 21:53:19 -03:00

35 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 perplexity-web executor protocol extraction.
// The pure wire protocol (consts, types, SSE parsing, request/query building, content
// extraction) lives in perplexity-web/protocol.ts (no host state/fetch/auth). Host imports
// back the symbols it uses; everything is module-private (no re-export).
const HERE = dirname(fileURLToPath(import.meta.url));
const EXE = join(HERE, "../../open-sse/executors");
const HOST = join(EXE, "perplexity-web.ts");
const LEAF = join(EXE, "perplexity-web/protocol.ts");
test("leaf hosts the protocol helpers and does not import the host", () => {
const src = readFileSync(LEAF, "utf8");
for (const sym of ["cleanResponse", "buildPplxRequestBody", "extractContent", "sseChunk"]) {
assert.match(src, new RegExp(`export (async function\\*?|function\\*?|const) ${sym}\\b`));
}
assert.doesNotMatch(src, /from "\.\.\/perplexity-web\.ts"/);
});
test("host imports the protocol helpers back from the leaf", () => {
const host = readFileSync(HOST, "utf8");
assert.match(host, /from "\.\/perplexity-web\/protocol\.ts"/);
});
test("cleanResponse strips citations and sseChunk formats a chunk", async () => {
const { cleanResponse, sseChunk } =
await import("../../open-sse/executors/perplexity-web/protocol.ts");
assert.equal(typeof cleanResponse("hello", true), "string");
assert.match(sseChunk({ a: 1 }), /^data: \{"a":1\}\n\n$/);
});