Files
OmniRoute/tests/unit/compression/rtk-grouping-config.test.ts
Diego Rodrigues de Sa e Souza 3c9883bb73 Release v3.8.29 (#4126)
OmniRoute v3.8.29 — 115 commits since v3.8.28. Full CHANGELOG + 41 i18n mirrors. All content quality gates green (build, unit 8/8, vitest 188/188, PR test policy, quality gates extended, docs sync, quality ratchet). Remaining red CI checks are pre-existing release flakes (coverage-shard/integration/node-compat teardown), a new transitive undici advisory in electron devDeps, and a workflow-level CodeQL fail (0 open alerts). VPS-validated by the operator.
2026-06-19 06:49:01 -03:00

64 lines
2.5 KiB
TypeScript

import { describe, it, beforeEach, afterEach, after } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { rtkConfigSchema } from "../../../src/shared/validation/compressionConfigSchemas.ts";
import { DEFAULT_RTK_CONFIG } from "../../../open-sse/services/compression/types.ts";
// The RTK R5 grouping feature is read by the engine (config.enableGrouping / groupingThreshold)
// but was unreachable in production: the Zod schema (.strict()) rejected the two fields on write
// and normalizeRtkConfig dropped them on read. This proves both gates now let them through.
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-rtk-grouping-"));
const ORIGINAL_DATA_DIR = process.env.DATA_DIR;
process.env.DATA_DIR = TEST_DATA_DIR;
const core = await import("../../../src/lib/db/core.ts");
const { getCompressionSettings, updateCompressionSettings } = await import(
"../../../src/lib/db/compression.ts"
);
describe("RTK grouping config persistence (R5)", () => {
beforeEach(() => {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
});
afterEach(() => {
core.resetDbInstance();
});
after(() => {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
if (ORIGINAL_DATA_DIR === undefined) delete process.env.DATA_DIR;
else process.env.DATA_DIR = ORIGINAL_DATA_DIR;
});
it("accepts enableGrouping / groupingThreshold on the write schema", () => {
assert.equal(
rtkConfigSchema.safeParse({ enableGrouping: true, groupingThreshold: 5 }).success,
true
);
// groupingThreshold below the minimum run length (2) is rejected.
assert.equal(rtkConfigSchema.safeParse({ groupingThreshold: 1 }).success, false);
});
it("preserves enableGrouping / groupingThreshold through a DB round-trip", async () => {
const settings = await updateCompressionSettings({
rtkConfig: { ...DEFAULT_RTK_CONFIG, enableGrouping: true, groupingThreshold: 7 },
});
assert.equal(settings.rtkConfig.enableGrouping, true);
assert.equal(settings.rtkConfig.groupingThreshold, 7);
// Survives a fresh read (not just the write-path return value).
core.resetDbInstance();
const reread = await getCompressionSettings();
assert.equal(reread.rtkConfig.enableGrouping, true);
assert.equal(reread.rtkConfig.groupingThreshold, 7);
});
});