mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
Extract the pure upstream-header helpers (mergeUpstreamExtraHeaders, getCustomUserAgent, setUserAgentHeader, applyConfiguredUserAgent, isOpenAICompatibleEndpoint, stripStainlessHeadersForOpenAICompat) verbatim into the leaf base/headers.ts. base.ts is imported by ~18 executors, so the host re-exports all 6 to keep those import paths intact; it also imports the 4 it uses internally in the BaseExecutor class. The trivial JsonRecord type alias is redefined locally in the leaf to avoid a base<->leaf cycle. Host 1539 -> 1451 LOC. Byte-identical bodies (verbatim 78/78), leaf does not import the host (no cycle). typecheck:core validates all base importers still resolve via the re-export. Adds a split-guard; consumer tests stay green (executor-base-utils 22, executor-default-base 49, executor-strip-stainless-openai-compat 6, plus executor sanity via typecheck).
56 lines
2.1 KiB
TypeScript
56 lines
2.1 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 base executor header-helper extraction.
|
|
// The pure upstream-header helpers live in base/headers.ts (no host state, no fetch).
|
|
// base.ts re-exports all 6 so the ~18 executors + tests that import them from "./base.ts"
|
|
// keep resolving unchanged.
|
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
const EXE = join(HERE, "../../open-sse/executors");
|
|
const HOST = join(EXE, "base.ts");
|
|
const LEAF = join(EXE, "base/headers.ts");
|
|
|
|
test("leaf hosts the header helpers and does not import the host", () => {
|
|
const src = readFileSync(LEAF, "utf8");
|
|
for (const sym of [
|
|
"mergeUpstreamExtraHeaders",
|
|
"setUserAgentHeader",
|
|
"isOpenAICompatibleEndpoint",
|
|
"stripStainlessHeadersForOpenAICompat",
|
|
]) {
|
|
assert.match(src, new RegExp(`export function ${sym}\\b`));
|
|
}
|
|
assert.doesNotMatch(src, /from "\.\.\/base\.ts"/);
|
|
});
|
|
|
|
test("host re-exports all 6 header helpers for external importers", () => {
|
|
const host = readFileSync(HOST, "utf8");
|
|
for (const sym of [
|
|
"mergeUpstreamExtraHeaders",
|
|
"getCustomUserAgent",
|
|
"setUserAgentHeader",
|
|
"applyConfiguredUserAgent",
|
|
"isOpenAICompatibleEndpoint",
|
|
"stripStainlessHeadersForOpenAICompat",
|
|
]) {
|
|
assert.match(host, new RegExp(`\\b${sym}\\b`));
|
|
}
|
|
assert.match(host, /from "\.\/base\/headers\.ts"/);
|
|
});
|
|
|
|
test("header helpers behave via base.ts (the public import path)", async () => {
|
|
const mod = await import("../../open-sse/executors/base.ts");
|
|
assert.equal(mod.isOpenAICompatibleEndpoint("openai-compatible-x", "https://x/y"), true);
|
|
const headers: Record<string, string> = { "x-stainless-lang": "js", "User-Agent": "openai-node" };
|
|
const stripped = mod.stripStainlessHeadersForOpenAICompat(
|
|
headers,
|
|
"openai-compatible-x",
|
|
"https://x/v1/chat/completions"
|
|
);
|
|
assert.ok(stripped.includes("x-stainless-lang"));
|
|
assert.equal(headers["x-stainless-lang"], undefined);
|
|
});
|