mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 20:32:20 +03:00
4 fixes from Gemini Code Assist PR #1689 review: 1. HIGH: Multi-part message content duplication — skip array-content messages instead of joining+replacing all text parts with compressed result, which caused content duplication (e.g., [A,B] → [comp(A+B), comp(A+B)]) 2. HIGH: String.prototype.replace $& vulnerability — use arrow function callback instead of string arg in restorePreservedBlocks() to prevent special replacement patterns ($&, , etc.) from corrupting restored content containing code, URLs, or file paths 3. HIGH: UI/backend rule name mismatch — ALL_CAVEMAN_RULES in CompressionSettingsTab.tsx now uses actual backend rule names (polite_framing, hedging, verbose_instructions, etc.) instead of fabricated names (hedging_disclaimer, redundant_please, etc.) that would break the skip-rules feature 4. MEDIUM: Remove no-op turn_marker rule — pattern /^$/g matches only empty strings and replaces with empty string, achieving nothing. Removed from CAVEMAN_RULES; total count now 29 (was 30). Tests: 72/72 pass, typecheck: 0 errors, lint: 0 errors
91 lines
3.3 KiB
TypeScript
91 lines
3.3 KiB
TypeScript
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { fileURLToPath } from "node:url";
|
|
import { dirname, join } from "node:path";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
|
|
describe("Compression Settings API Schema Validation", () => {
|
|
const compressionModeValues = ["off", "lite", "standard", "aggressive", "ultra"];
|
|
|
|
it("should validate all compression mode values", () => {
|
|
assert.deepStrictEqual(compressionModeValues, [
|
|
"off",
|
|
"lite",
|
|
"standard",
|
|
"aggressive",
|
|
"ultra",
|
|
]);
|
|
});
|
|
|
|
it("should validate caveman config structure", () => {
|
|
const defaultCavemanConfig = {
|
|
enabled: true,
|
|
compressRoles: ["user"],
|
|
skipRules: [],
|
|
minMessageLength: 50,
|
|
preservePatterns: [],
|
|
};
|
|
|
|
assert.equal(defaultCavemanConfig.enabled, true);
|
|
assert.deepStrictEqual(defaultCavemanConfig.compressRoles, ["user"]);
|
|
assert.equal(Array.isArray(defaultCavemanConfig.skipRules), true);
|
|
assert.equal(defaultCavemanConfig.minMessageLength, 50);
|
|
assert.equal(Array.isArray(defaultCavemanConfig.preservePatterns), true);
|
|
});
|
|
|
|
it("should validate full compression config structure", () => {
|
|
const defaultConfig = {
|
|
enabled: false,
|
|
defaultMode: "off",
|
|
autoTriggerTokens: 0,
|
|
cacheMinutes: 5,
|
|
preserveSystemPrompt: true,
|
|
comboOverrides: {},
|
|
cavemanConfig: {
|
|
enabled: true,
|
|
compressRoles: ["user"],
|
|
skipRules: [],
|
|
minMessageLength: 50,
|
|
preservePatterns: [],
|
|
},
|
|
};
|
|
|
|
assert.equal(defaultConfig.enabled, false);
|
|
assert.ok(compressionModeValues.includes(defaultConfig.defaultMode));
|
|
assert.equal(typeof defaultConfig.autoTriggerTokens, "number");
|
|
assert.equal(typeof defaultConfig.cacheMinutes, "number");
|
|
assert.equal(typeof defaultConfig.preserveSystemPrompt, "boolean");
|
|
assert.equal(typeof defaultConfig.comboOverrides, "object");
|
|
assert.equal(typeof defaultConfig.cavemanConfig, "object");
|
|
});
|
|
|
|
it("should validate all caveman compression rules are defined", async () => {
|
|
const { CAVEMAN_RULES } =
|
|
await import("../../../../open-sse/services/compression/cavemanRules.ts");
|
|
assert.ok(Array.isArray(CAVEMAN_RULES));
|
|
assert.ok(CAVEMAN_RULES.length >= 29, `Expected >= 29 rules, got ${CAVEMAN_RULES.length}`);
|
|
for (const rule of CAVEMAN_RULES) {
|
|
assert.ok(rule.name && typeof rule.name === "string", `Rule must have a name`);
|
|
assert.ok(rule.pattern instanceof RegExp, `Rule ${rule.name} must have a RegExp pattern`);
|
|
assert.ok(
|
|
typeof rule.replacement === "string" || typeof rule.replacement === "function",
|
|
`Rule ${rule.name} must have string or function replacement`
|
|
);
|
|
assert.ok(
|
|
rule.pattern.source !== "^$" || rule.replacement !== "",
|
|
`Rule ${rule.name} must not be a no-op (empty pattern + empty replacement)`
|
|
);
|
|
}
|
|
});
|
|
|
|
it("should validate compression modes cover all CavemanConfig roles", () => {
|
|
const validRoles = ["user", "assistant", "system"];
|
|
for (const role of validRoles) {
|
|
assert.ok(validRoles.includes(role), `Role ${role} should be valid`);
|
|
}
|
|
assert.equal(validRoles.length, 3);
|
|
});
|
|
});
|