fix(process): validate terminal byte totals against retained frames

parseProcessCapture accepted terminal retention accounting that its
retained frames contradict: any retained_bytes within budget, and
observed_bytes above retained_bytes with no omitted frame. A malformed
capture could therefore report truncated: false while its terminal
evidence was incomplete. Recompute retained raw and rendered bytes from
the frames, and require equal observed and retained bytes when no frame
was omitted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kaoru0822
2026-10-09 14:12:05 +00:00
co-authored by Claude Opus 5.5
parent 33bf585185
commit 39eb0587c9
2 changed files with 48 additions and 2 deletions
@@ -133,6 +133,30 @@ itWithCaptureCapability.each(["cli", "mcp"] as const)(
expect(
processCaptureSchema.safeParse({ ...result, truncated: false }).success,
).toBe(false);
const withTerminal = (
name: "raw_terminal" | "rendered_terminal",
change: Partial<typeof details.raw_terminal>,
) =>
processCaptureSchema.safeParse({
...result,
truncation_details: {
...details,
[name]: { ...details[name], ...change },
},
}).success;
// Byte totals must match the retained frames, and with no omitted frame
// nothing observed can be missing from retention.
expect(withTerminal("raw_terminal", { retained_bytes: 0 })).toBe(false);
expect(
withTerminal("raw_terminal", {
observed_bytes: details.raw_terminal.observed_bytes + 1,
}),
).toBe(false);
expect(
withTerminal("rendered_terminal", {
retained_bytes: details.rendered_terminal.retained_bytes - 1,
}),
).toBe(false);
},
20_000,
);