Skip to content

Commit 9ac0d97

Browse files
author
tanshanshan
committed
feat: add compaction percentage threshold standalone proof script
1 parent c00c4d8 commit 9ac0d97

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { resolveTokenThreshold } from "../src/config/token-threshold.js";
2+
3+
function assert(condition, message) {
4+
if (!condition) {
5+
console.error(`✗ FAIL: ${message}`);
6+
process.exitCode = 1;
7+
} else {
8+
console.log(`✓ PASS: ${message}`);
9+
}
10+
}
11+
12+
function main() {
13+
console.log("=== Compaction Percentage Token Threshold Proof ===\n");
14+
15+
// 1. Percentage string resolution
16+
console.log("1. Percentage string resolution against context window");
17+
assert(
18+
resolveTokenThreshold("40%", 1_000_000, 4_000) === 400_000,
19+
'"40%" with 1M context → 400000',
20+
);
21+
assert(
22+
resolveTokenThreshold("40%", 200_000, 4_000) === 80_000,
23+
'"40%" with 200K context → 80000 (correctly scaled)',
24+
);
25+
assert(
26+
resolveTokenThreshold("10%", 128_000, 20_000) === 12_800,
27+
'"10%" with 128K context → 12800',
28+
);
29+
assert(
30+
resolveTokenThreshold("75%", 256_000, 4_000) === 192_000,
31+
'"75%" with 256K context → 192000',
32+
);
33+
34+
// 2. Numeric pass-through (backward compatibility)
35+
console.log("\n2. Numeric pass-through (backward compatible)");
36+
assert(
37+
resolveTokenThreshold(400_000, 1_000_000, 4_000) === 400_000,
38+
"400000 int with 1M context → 400000 (unchanged)",
39+
);
40+
assert(
41+
resolveTokenThreshold(80_000, 200_000, 4_000) === 80_000,
42+
"80000 int with 200K context → 80000 (unchanged)",
43+
);
44+
assert(resolveTokenThreshold(0, 1_000_000, 4_000) === 0, "0 int → 0 (edge case)");
45+
46+
// 3. Undefined falls back to default
47+
console.log("\n3. Undefined falls back to default");
48+
assert(
49+
resolveTokenThreshold(undefined, 1_000_000, 4_000) === 4_000,
50+
"undefined with default 4000 → 4000",
51+
);
52+
assert(
53+
resolveTokenThreshold(undefined, 200_000, 20_000) === 20_000,
54+
"undefined with default 20000 → 20000",
55+
);
56+
57+
// 4. Invalid strings fall back to default
58+
console.log("\n4. Invalid strings fall back to default");
59+
assert(
60+
resolveTokenThreshold("not-a-percent", 1_000_000, 4_000) === 4_000,
61+
"invalid string 'not-a-percent' → default 4000",
62+
);
63+
assert(
64+
resolveTokenThreshold("40.5%", 1_000_000, 4_000) === 4_000,
65+
"invalid string '40.5%' (decimal) → default 4000",
66+
);
67+
assert(
68+
resolveTokenThreshold("abc", 1_000_000, 4_000) === 4_000,
69+
"invalid string 'abc' → default 4000",
70+
);
71+
assert(resolveTokenThreshold("", 1_000_000, 4_000) === 4_000, "empty string → default 4000");
72+
73+
// 5. Model-switch scaling scenario (the core use case)
74+
console.log("\n5. Model-switch scaling scenario");
75+
const softThresholdConfig = "40%";
76+
const deepseekContext = 1_000_000;
77+
const glmContext = 200_000;
78+
79+
const deepseekTokens = resolveTokenThreshold(softThresholdConfig, deepseekContext, 4_000);
80+
const glmTokens = resolveTokenThreshold(softThresholdConfig, glmContext, 4_000);
81+
82+
assert(deepseekTokens === 400_000, `DeepSeek 1M + "40%" → ${deepseekTokens} (40% of 1M)`);
83+
assert(glmTokens === 80_000, `GLM 200K + "40%" → ${glmTokens} (40% of 200K)`);
84+
assert(
85+
deepseekTokens === glmTokens * 5,
86+
"DeepSeek threshold = 5x GLM threshold for same percentage",
87+
);
88+
89+
console.log("\n=== All checks complete ===");
90+
}
91+
92+
main();

0 commit comments

Comments
 (0)