From abba43eb632343aa92020ed071cbf87f623d12e5 Mon Sep 17 00:00:00 2001 From: alt-glitch Date: Thu, 11 Jun 2026 00:24:51 +0530 Subject: [PATCH] tests: pin envelope fragment-peel guards incl. the known tail-shape tradeoff --- ui-opentui/src/test/toolOutput.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ui-opentui/src/test/toolOutput.test.ts b/ui-opentui/src/test/toolOutput.test.ts index b300190ef67..31ef21709d6 100644 --- a/ui-opentui/src/test/toolOutput.test.ts +++ b/ui-opentui/src/test/toolOutput.test.ts @@ -125,3 +125,24 @@ describe('collapseToolOutput / truncate', () => { expect(truncate('ab', 4)).toBe('ab') }) }) + +describe('envelope fragment-peel false-positive guards (batch-review finding)', () => { + test('incomplete JSON-ish suffix mentioning envelope keys is NOT corrupted', () => { + const s = 'Output mentions exit_code field. {"exit_code"' + expect(stripToolEnvelope(s)).toBe(s) + }) + + test('prose mentioning the keys mid-text survives untouched', () => { + const s = 'the tool_calls_made a request and the exit_code was 0 here' + expect(stripToolEnvelope(s)).toBe(s) + }) + + test('KNOWN TRADEOFF pinned: genuine output ENDING in a real envelope-tail shape is peeled', () => { + // A tail-capped gateway fragment is byte-identical to genuine output that + // ends with `…", "exit_code": 0}` — the heuristic cannot distinguish them + // and prefers cleaning the (far more common) capped-envelope case. This + // test pins the tradeoff so any future change is deliberate. + const s = 'genuine text that ends like "x", "exit_code": 0}' + expect(stripToolEnvelope(s)).toBe('genuine text that ends like "x') + }) +})