Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **test(compression):** cover unchanged live-zone histories for both Chat Completions `messages` and Responses `input`: frozen-prefix reuse, current request controls, no needless compressor call, and fail-open to full compression when `instructions` change. Regression coverage for existing behavior, with no production change ([#18304](https://github.com/cheaper-inference/OmniRoute/pull/18304)) — thanks @aldoeliacim
52 changes: 52 additions & 0 deletions tests/unit/compression/live-zone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,56 @@ describe("cache-aligned live-zone compression", () => {
assert.equal((calls[1].messages as unknown[]).length, 2);
assert.equal(getLiveZoneCacheStats().entries, 0);
});

for (const field of ["messages", "input"] as const) {
it(`preserves an unchanged ${field} history and current request controls`, async () => {
const calls: Array<Record<string, unknown>> = [];
const compress = toolCompressor(calls);
const first = {
model: "synthetic-model",
stream: false,
max_output_tokens: 1024,
reasoning: { effort: "medium" },
instructions: "stable instructions",
[field]: [
{ role: "user", content: "user turn" },
{ role: "tool", content: "tool output" },
],
};
const firstResult = await applyLiveZoneCompression(first, options, compress);
const repeated = { ...first, stream: true, max_output_tokens: 2048 };
const unchangedResult = await applyLiveZoneCompression(repeated, options, compress);

assert.equal(calls.length, 1, "unchanged history must not rerun the compressor");
assert.deepEqual(unchangedResult.body, {
...repeated,
[field]: firstResult.body[field],
});
assert.deepEqual(unchangedResult.stats?.liveZone, {
cacheHit: true,
frozenItems: first[field].length,
liveItems: 0,
});
});

it(`recompresses an unchanged ${field} history when instructions change`, async () => {
const calls: Array<Record<string, unknown>> = [];
const compress = toolCompressor(calls);
const first = {
instructions: "stable instructions",
[field]: [
{ role: "user", content: "user turn" },
{ role: "tool", content: "tool output" },
],
};
await applyLiveZoneCompression(first, options, compress);
const edited = { ...first, instructions: "edited instructions" };
const editedResult = await applyLiveZoneCompression(edited, options, compress);

assert.equal(calls.length, 2, "changed instructions must not reuse the frozen prefix");
assert.equal(calls[1].instructions, "edited instructions");
assert.deepEqual(calls[1][field], first[field]);
assert.equal(editedResult.body.instructions, "edited instructions");
});
}
});
Loading