Files
OmniRoute/tests/unit/ui/live-compression-accumulate.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

77 lines
2.5 KiB
TypeScript

/**
* tests/unit/ui/live-compression-accumulate.test.ts
*
* F5.1 coverage gap (F3.3): the `useLiveCompression` accumulator (`accumulateRun`)
* — which folds incoming `compression.completed` payloads into the run list — was
* exported "for unit tests" but never tested. This pins ordering + the cap.
*/
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { accumulateRun } from "../../../src/hooks/useLiveCompression.ts";
import type { CompressionRunModel } from "../../../src/app/(dashboard)/dashboard/compression/studio/compressionFlowModel.ts";
import type { CompressionCompletedPayload } from "../../../src/lib/events/types.ts";
function payload(requestId: string): CompressionCompletedPayload {
return {
requestId,
comboId: "my-combo",
mode: "stacked",
originalTokens: 1000,
compressedTokens: 600,
savingsPercent: 40,
engineBreakdown: [
{
engine: "rtk",
originalTokens: 1000,
compressedTokens: 600,
savingsPercent: 40,
techniquesUsed: ["tool-output-trim"],
durationMs: 3,
},
],
timestamp: 1718000000000,
};
}
describe("accumulateRun — live compression run accumulator (F3.3)", () => {
it("adds the first run derived from the payload (requestId carried through)", () => {
const runs = accumulateRun([], payload("r1"));
assert.equal(runs.length, 1);
assert.equal(runs[0].requestId, "r1");
assert.equal(runs[0].mode, "stacked");
});
it("prepends so the list is most-recent-first", () => {
let runs: CompressionRunModel[] = [];
runs = accumulateRun(runs, payload("r1"));
runs = accumulateRun(runs, payload("r2"));
runs = accumulateRun(runs, payload("r3"));
assert.deepEqual(
runs.map((r) => r.requestId),
["r3", "r2", "r1"],
);
});
it("caps the list at maxRuns, dropping the oldest", () => {
let runs: CompressionRunModel[] = [];
for (const id of ["a", "b", "c", "d"]) {
runs = accumulateRun(runs, payload(id), /* maxRuns */ 2);
}
assert.equal(runs.length, 2, "never grows beyond maxRuns");
assert.deepEqual(
runs.map((r) => r.requestId),
["d", "c"],
"keeps the 2 newest, newest-first; oldest (a, b) dropped",
);
});
it("does not mutate the previous array (returns a new list)", () => {
const prev = accumulateRun([], payload("r1"));
const next = accumulateRun(prev, payload("r2"));
assert.equal(prev.length, 1, "input array is left untouched");
assert.notEqual(prev, next);
});
});