feat: unify context compaction

This commit is contained in:
云服务部-叶林立
2026-09-01 14:52:43 +08:00
parent 44f27f7585
commit a4807dde67
114 changed files with 2681 additions and 21336 deletions
@@ -0,0 +1,19 @@
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);
});