Files
OmniRoute/tests/unit/grok-web-executor-split.test.ts
Diego Rodrigues de Sa e Souza cc570cbc6b refactor(executors): decompose grok-web into pure tool/markup leaves (#5994)
Extract the pure OpenAI<->Grok tool-translation, native-tool mapping, markup cleanup,
and NDJSON stream types out of the 1872-line grok-web executor into 4 sibling leaves:
- grok-web/types.ts: GrokStreamResponse/GrokStreamEvent (stream types)
- grok-web/tool-bridge.ts: OpenAI<->Grok tool translation + registry + classifiers
- grok-web/native-tools.ts: native-tool selection/scoring + native->OpenAI mapping
- grok-web/text-cleanup.ts: Grok markup stripping + GrokMarkupFilter

Layered, acyclic: types <- tool-bridge <- native-tools; text-cleanup <- types; host
imports the leaves. All symbols module-private (no host re-export). Host 1872 -> 887 LOC.
Byte-identical bodies (verbatim per-leaf), no cycle, all new leaves <= 800 cap
(tool-bridge split at line 753 to stay under). Auth/cookie/TLS/HTTP dispatch untouched.
Adds a split-guard; consumer tests stay green (grok-web 62, grok-cli-oauth 15,
grok-cli-strip-params 2).
2026-07-02 20:04:05 -03:00

37 lines
1.8 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 grok-web executor extraction.
// Pure clusters live in 4 leaves: types.ts (stream types), tool-bridge.ts (OpenAI<->Grok
// tool translation), native-tools.ts (native-tool selection + mapping), text-cleanup.ts
// (markup cleanup). All are module-private (no host re-export). No leaf imports the host.
const HERE = dirname(fileURLToPath(import.meta.url));
const DIR = join(HERE, "../../open-sse/executors/grok-web");
const HOST = join(HERE, "../../open-sse/executors/grok-web.ts");
test("leaves are acyclic: none imports the host, layered types<-tool-bridge<-native-tools", () => {
for (const f of ["types", "tool-bridge", "native-tools", "text-cleanup"]) {
const src = readFileSync(join(DIR, `${f}.ts`), "utf8");
assert.doesNotMatch(src, /from "\.\.\/grok-web\.ts"/, `${f} must not import the host`);
}
assert.doesNotMatch(readFileSync(join(DIR, "types.ts"), "utf8"), /^import /m);
assert.match(readFileSync(join(DIR, "native-tools.ts"), "utf8"), /from "\.\/tool-bridge\.ts"/);
});
test("host imports the tool-bridge + native-tools + text-cleanup helpers", () => {
const host = readFileSync(HOST, "utf8");
assert.match(host, /from "\.\/grok-web\/tool-bridge\.ts"/);
assert.match(host, /from "\.\/grok-web\/native-tools\.ts"/);
assert.match(host, /from "\.\/grok-web\/text-cleanup\.ts"/);
});
test("text-cleanup strips Grok markup", async () => {
const { cleanGrokContentText } =
await import("../../open-sse/executors/grok-web/text-cleanup.ts");
assert.equal(typeof cleanGrokContentText, "function");
assert.equal(typeof cleanGrokContentText("plain text"), "string");
});