Files
OmniRoute/tests/unit/codex-prompt-compression-passthrough.test.ts
tom 92a617c23f fix(sse): re-enable prompt compression for native Codex passthrough (#12834)
Native Codex passthrough (POST /v1/responses, provider=codex) was unconditionally
excluded from prompt compression, writing only skip_reason='excluded' analytics
rows. Prompt compression now depends only on the operator exclusions list;
reactive compaction and combo overflow fail-fast intentionally still bypass
(prompt-only scope).

Closes #12793

Regression guard: tests/unit/codex-prompt-compression-passthrough.test.ts
2026-09-05 23:30:48 -03:00

60 lines
2.2 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import {
isCompressionExcluded,
normalizeCompressionExclusions,
} from "../../open-sse/services/compression/exclusions.ts";
const chatCoreSource = readFileSync(
new URL("../../open-sse/handlers/chatCore.ts", import.meta.url),
"utf8"
);
// Regression guard for https://github.com/diegosouzapw/OmniRoute/issues/12793:
// native Codex passthrough (`POST /v1/responses`, provider `codex`) silently stopped
// producing compression analytics (100% `skip_reason='excluded'`) after #8933 added
// `nativeCodexPassthrough ||` to the prompt-compression exclusion (landed on release
// via #11088). Prompt compression must depend ONLY on the operator exclusions list.
test("codex prompt compression is not gated on native passthrough", () => {
const match = chatCoreSource.match(/const compressionExcluded =([\s\S]*?);/);
assert.ok(match, "compressionExcluded assignment must exist in chatCore.ts");
assert.doesNotMatch(
match[1],
/nativeCodexPassthrough/,
"prompt-compression exclusion must not reference nativeCodexPassthrough"
);
assert.match(match[1], /isCompressionExcluded/);
});
test("codex target is compressible by default; operators can still opt out via exclusions", () => {
assert.equal(
isCompressionExcluded(
{ provider: "codex", model: "gpt-5.6-terra" },
normalizeCompressionExclusions([])
),
false
);
assert.equal(
isCompressionExcluded(
{ provider: "codex", model: "gpt-5.6-terra" },
normalizeCompressionExclusions(["codex/*"])
),
true
);
});
test("prompt-only scope: reactive compaction still bypasses native passthrough", () => {
// Deliberately left for follow-up (overflow fail-fast + history-rewriting safety).
// If these gates are ever lifted, update the PR body notes, not just this test.
assert.match(
chatCoreSource,
/reactiveContextCompactionEnabled\s*&&\s*!nativeCodexPassthrough\s*&&\s*estimatedTokens\s*>\s*threshold/
);
assert.match(
chatCoreSource,
/reactiveContextCompactionEnabled\s*&&\s*!nativeCodexPassthrough\s*&&\s*finalEstimatedInputTokens\s*>=\s*finalContextLimit/
);
});