mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-01 04:42:10 +03:00
Add caveman intensity levels, output mode instructions, validation, and preview diffs across the compression pipeline. Extend MCP and dashboard settings to support auto-trigger mode, system prompt preservation, MCP description compression, and caveman rule metadata. Record richer compression analytics with receipt fields, validation fallbacks, output mode data, and add the related database migration. Improve preservation handling for code, URLs, markdown, math, and other protected content while adding broad unit, integration, and golden-set coverage for caveman parity and compression behavior.
90 lines
3.0 KiB
TypeScript
90 lines
3.0 KiB
TypeScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
applyCavemanOutputMode,
|
|
buildCavemanOutputInstruction,
|
|
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("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("builds intensity-specific instructions", () => {
|
|
assert.match(
|
|
buildCavemanOutputInstruction({ enabled: true, intensity: "ultra", autoClarity: true }),
|
|
/ultra terse/i
|
|
);
|
|
});
|
|
});
|