Files
my-pi/pi-compaction/test/token-accounting.test.ts
T

20 lines
757 B
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { shouldCompact } from "../src/token-accounting.ts";
test("raw pressure cannot trigger compaction while effective lower-bound stays below 90%", () => {
const config = { hardRatio: 0.9 };
const snapshot = { lowerBound: 231_000, contextWindow: 300_000 };
assert.equal(shouldCompact("threshold", snapshot, config), false);
assert.equal(shouldCompact("manual", snapshot, config), true);
assert.equal(shouldCompact("overflow", snapshot, config), true);
});
test("effective lower-bound at the configured threshold compacts", () => {
assert.equal(shouldCompact(
"threshold",
{ lowerBound: 270_000, contextWindow: 300_000 },
{ hardRatio: 0.9 },
), true);
});