From 95582ceaa1dccc05233670bbb81cfd4759e7a8cf Mon Sep 17 00:00:00 2001 From: Vendex Date: Wed, 1 Jul 2026 19:37:08 +0800 Subject: [PATCH] fix: correct stripBulkToolOutputs JSDoc to match AND conditions, fix test data to satisfy both thresholds --- extensions/engine.ts | 3 ++- tests/engine-coverage.test.ts | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/extensions/engine.ts b/extensions/engine.ts index 5feaf78..e22916d 100644 --- a/extensions/engine.ts +++ b/extensions/engine.ts @@ -982,7 +982,8 @@ export class UltraCompactEngine { /** * Strip bulk tool outputs (large file reads, directory listings). - * Only targets outputs > 100 lines or > 5000 characters of plain text. + * Only targets outputs with > 100 lines AND > 5000 characters of plain text. + * Both conditions must be met to avoid truncating compact single-line results. */ private stripBulkToolOutputs(messages: Message[]): Message[] { return messages.map((msg) => { diff --git a/tests/engine-coverage.test.ts b/tests/engine-coverage.test.ts index 666a234..a243fbd 100644 --- a/tests/engine-coverage.test.ts +++ b/tests/engine-coverage.test.ts @@ -115,7 +115,10 @@ describe("microCompact", () => { it("truncates bulk tool outputs when over budget", () => { const engine = new UltraCompactEngine({ modelName: "gpt-4o" }); - const bulkOutput = Array(150).fill("LongLineForTestingPadding ").join(String.fromCharCode(10)); + // Must exceed both thresholds: content.length >= 5000 AND lines > 100 + const longLine = "LongLineForTestingPaddingAndTruncationCheck "; // 47 chars + const bulkOutput = Array(150).fill(longLine).join(String.fromCharCode(10)); + // 150 * 47 = 7050 chars + 149 newlines ≈ 7199 chars (>= 5000 ✓, > 100 lines ✓) const hugeText = "TextContentForTokenBudget".repeat(25000); const msgs: Message[] = [ makeMsg("1", "tool", bulkOutput), @@ -163,7 +166,10 @@ describe("microCompact", () => { it("saves tokens when stripping bulk tool output", () => { const engine = new UltraCompactEngine({ modelName: "gpt-4o" }); - const bigTool = "A".repeat(7000); + // Must exceed both thresholds: content.length >= 5000 AND lines > 100 + const longLine = "LineContentForTruncationCheckAndTokenSavingTest "; // 51 chars + const bigTool = Array(110).fill(longLine).join(String.fromCharCode(10)); + // 110 * 51 = 5610 chars + 109 newlines ≈ 5719 chars (>= 5000 ✓, > 100 lines ✓) const hugeText = "TextContentForTokenBudget".repeat(25000); const msgs: Message[] = [ makeMsg("1", "tool", bigTool),