test: cover inferred-window hook output

This commit is contained in:
haelyra
2026-08-29 14:55:13 -04:00
parent ecdd517765
commit 2f8a5a271d
2 changed files with 6 additions and 7 deletions
+4 -5
View File
@@ -34,12 +34,11 @@ const {
} = require('../lib/utils');
const {
readLatestContextTokens,
resolveContextWindowTokens,
resolveContextWindow,
resolveContextThreshold,
resolveContextInterval,
computeContextBucket,
formatWindowLabel,
isContextWindowInferred
formatWindowLabel
} = require('../lib/transcript-context');
const COUNTER_FILE_PREFIX = 'claude-tool-count-';
@@ -172,7 +171,7 @@ function buildContextSuggestion(transcriptPath, bucketFile, env) {
const usage = readLatestContextTokens(transcriptPath);
if (!usage) return null;
const windowTokens = resolveContextWindowTokens(usage.tokens, usage.model);
const { windowTokens, inferred } = resolveContextWindow(usage.tokens, usage.model);
const threshold = resolveContextThreshold(env, windowTokens);
if (threshold <= 0) return null; // COMPACT_CONTEXT_THRESHOLD=0 disables
@@ -189,7 +188,7 @@ function buildContextSuggestion(transcriptPath, bucketFile, env) {
// Only quote a percentage when the window size was actually detected.
// Against an assumed 200k default the denominator is a guess, and a
// "97% of 200k window" line on a 1M session triggers needless compaction.
const scale = isContextWindowInferred(usage.tokens, usage.model)
const scale = inferred
? ''
: ` (${Math.round((usage.tokens / windowTokens) * 100)}% of ${formatWindowLabel(windowTokens)} window)`;
return `[StrategicCompact] Context ~${approxTokens} tokens${scale} - consider /compact at the next logical boundary`;
+2 -2
View File
@@ -694,7 +694,7 @@ function runTests() {
};
}
if (test('suggests compact when context exceeds the 200k-window threshold', () => {
if (test('omits the percentage when the context window is assumed', () => {
const ctx = createContextContext();
const transcript = writeTranscriptFixture(170000);
try {
@@ -704,7 +704,7 @@ function runTests() {
const parsed = JSON.parse(result.stdout);
const context = parsed.hookSpecificOutput.additionalContext;
assert.ok(context.includes('Context ~170k tokens'), `Expected token estimate. Got: ${context}`);
assert.ok(context.includes('85% of 200k window'), `Expected window percentage. Got: ${context}`);
assert.ok(!context.includes('% of'), `Expected no percentage for an assumed window. Got: ${context}`);
} finally {
try { fs.unlinkSync(transcript); } catch (_err) { /* ignore */ }
ctx.cleanup();