Files
OmniRoute/tests/unit/compression/outputMode.test.ts
Diego Rodrigues de Sa e Souza abbbca216d feat(sse): full language parity for output styles (es/de/fr/it/ru/zh + autoDetect) (#12289)
* feat(sse): add it/ru/zh caveman output instructions

* fix(sse): expose the dormant terse-prose translations through the catalog

* feat(sse): translate less-code to es/de/fr/it/ru/zh

* feat(sse): translate ponytail to es/de/fr/it/ru/zh

* feat(sse): translate i-have-adhd to es/de/fr/it/ru/zh

* test(sse): anchor wave-2 output-style translations to their own language

* feat(dashboard): offer every output-style language in the default-language selector

* feat(sse): let autoDetect pick the output-style instruction language

* docs(compression): consolidate the output-style tables and record full language parity
2026-09-01 11:13:26 -03:00

126 lines
4.4 KiB
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
import {
applyCavemanOutputMode,
buildCavemanOutputInstruction,
CAVEMAN_INSTRUCTION_BY_LANGUAGE,
shouldBypassCavemanOutputMode,
} from "../../../open-sse/services/compression/outputMode.ts";
describe("Caveman output mode", () => {
it("injects a system instruction without post-processing output", () => {
const result = applyCavemanOutputMode(
{ messages: [{ role: "user", content: "Summarize this API response." }] },
{ enabled: true, intensity: "full", autoClarity: true }
);
assert.equal(result.applied, true);
assert.equal(result.body.messages?.[0]?.role, "system");
assert.match(String(result.body.messages?.[0]?.content), /Caveman Output Mode/);
});
it("appends to an existing system prompt", () => {
const result = applyCavemanOutputMode(
{
messages: [
{ role: "system", content: "Follow tenant policy." },
{ role: "user", content: "Summarize logs." },
],
},
{ enabled: true, intensity: "lite", autoClarity: true }
);
assert.equal(result.applied, true);
assert.match(String(result.body.messages?.[0]?.content), /Follow tenant policy/);
assert.match(String(result.body.messages?.[0]?.content), /Drop filler/);
});
it("does not inject the Caveman instruction twice", () => {
const body = {
messages: [
{ role: "system", content: "Follow tenant policy." },
{ role: "user", content: "Summarize logs." },
],
};
const once = applyCavemanOutputMode(body, {
enabled: true,
intensity: "full",
autoClarity: true,
}).body;
const twice = applyCavemanOutputMode(once, {
enabled: true,
intensity: "full",
autoClarity: true,
});
assert.equal(twice.applied, false);
assert.equal(twice.skippedReason, "already_applied");
const markerCount = String(twice.body.messages?.[0]?.content).match(
/OmniRoute Caveman Output Mode/g
)?.length;
assert.equal(markerCount, 1);
});
it("does not modify user content", () => {
const body = { messages: [{ role: "user", content: "Please explain this response." }] };
const result = applyCavemanOutputMode(body, {
enabled: true,
intensity: "full",
autoClarity: true,
});
assert.equal(result.body.messages?.at(-1)?.content, body.messages[0].content);
});
it("uses Responses instructions when input has no messages", () => {
const result = applyCavemanOutputMode(
{ input: [{ type: "message", role: "user", content: "Summarize logs." }] },
{ enabled: true, intensity: "full", autoClarity: true }
);
assert.equal(result.applied, true);
assert.match(String(result.body.instructions), /Caveman Output Mode/);
assert.ok(!("messages" in result.body));
});
it("bypasses security, destructive, clarification, and order-sensitive prompts", () => {
const cases = [
"Explain this security vulnerability in detail.",
"Delete all rows after backup confirmation.",
"Can you clarify what this means?",
"First backup then drop table during migration.",
];
for (const content of cases) {
assert.ok(shouldBypassCavemanOutputMode([{ role: "user", content }]), content);
}
});
it("skips injection when disabled", () => {
const result = applyCavemanOutputMode(
{ messages: [{ role: "user", content: "Tell me a joke." }] },
{ enabled: false, intensity: "full", autoClarity: true }
);
assert.equal(result.applied, false);
assert.equal(result.skippedReason, "disabled");
assert.equal(result.body.messages?.[0]?.role, "user");
assert.equal(result.body.messages?.[0]?.content, "Tell me a joke.");
});
it("builds intensity-specific instructions", () => {
assert.match(
buildCavemanOutputInstruction({ enabled: true, intensity: "ultra", autoClarity: true }),
/ultra terse/i
);
});
});
describe("caveman instruction language map", () => {
it("covers it/ru/zh with three bounded levels", () => {
for (const lang of ["it", "ru", "zh"] as const) {
const entry = CAVEMAN_INSTRUCTION_BY_LANGUAGE[lang];
assert.ok(entry, `missing ${lang}`);
for (const level of ["lite", "full", "ultra"] as const) {
assert.ok(entry[level].length > 0, `${lang}.${level} empty`);
assert.ok(entry[level].includes("Code blocks"), `${lang}.${level} missing boundaries`);
}
}
});
});