perf(tests): remove timed output and synchronize browser fixtures

This commit is contained in:
morluto 2026-10-11 13:20:15 +08:00
parent d3088c3795
commit 693ed332b5
3 changed files with 38 additions and 13 deletions

View File

@ -50,6 +50,33 @@ it("omits trailing blank cells from visible lines without losing rows", async ()
);
});
it("applies rendered retention cumulatively across sparse frames", async () => {
const renderer = new TerminalRenderer({
columns: 10,
rows: 1,
scrollback: 0,
maxBytes: 5,
normalize: (value) => value,
});
try {
renderer.write("a", 0);
renderer.write("b", 1);
const frames = await renderer.frames();
expect(frames.map(({ lines }) => lines)).toEqual([["a"]]);
expect(renderer.retention()).toEqual({
budget_bytes: 5,
observed_bytes: 6,
retained_bytes: 2,
observed_frames: 2,
retained_frames: 1,
});
expect(renderer.truncated()).toBe(true);
} finally {
await renderer.dispose();
}
});
it("trims only after normalization sees the full-width row", async () => {
const { frames } = await renderFrames("pid 4242", (value) =>
value.replace(/4242 +$/u, "<pid>"),

View File

@ -224,6 +224,7 @@ describe("CdpBrowserProvider: explicitly requested text and payload shapes", ()
const browser = await startFakeCdpBrowser({
sensitiveShapes: true,
binaryWebSocketEvent: true,
eventsBeforeReply: ["Network.enable"],
});
trackBrowser(browser);
const result = await new CdpBrowserProvider().inspectPage(

View File

@ -63,30 +63,29 @@ const capture = async (
};
itWithCaptureCapability.each(["cli", "mcp"] as const)(
"localizes sparse rendered-state exhaustion through %s",
"localizes rendered-state expansion exhaustion through %s",
async (adapter) => {
const root = await createTestTempDirectory("rea-rendered-budget-");
// CSI REP expands a small raw burst into a full screen, so rendered
// exhaustion does not depend on how the PTY batches output chunks.
const output = "x\u001b[79b".repeat(24);
const result = await capture(adapter, {
executable: process.execPath,
working_directory: root,
arguments: [
"-e",
"let n=0;const timer=setInterval(()=>{console.log('board '+String(n).padStart(2,'0')+' completed; score '+String(n*10));if(++n===65)clearInterval(timer)},20)",
],
arguments: ["-e", `process.stdout.write(${JSON.stringify(output)})`],
terminal: { columns: 80, rows: 24, scrollback: 0 },
normalization: {
ports: false,
pids: false,
paths: false,
time_bucket_ms: 1,
},
limits: { output_bytes: 30_000 },
limits: { output_bytes: 1_000 },
});
const details = result.truncation_details;
if (details === undefined) throw new Error("Expected producer coverage");
expect(result.frames.map(({ data }) => data).join("")).toContain(
"board 64 completed; score 640",
);
expect(details.raw_terminal.observed_bytes).toBe(2004);
expect(result.frames.map(({ data }) => data).join("")).toBe(output);
expect(details.raw_terminal.observed_bytes).toBe(Buffer.byteLength(output));
expect(details.raw_terminal.retained_bytes).toBe(
details.raw_terminal.observed_bytes,
);
@ -94,9 +93,7 @@ itWithCaptureCapability.each(["cli", "mcp"] as const)(
expect(details.rendered_terminal.observed_frames).toBeGreaterThan(
result.rendered_frames.length,
);
expect(details.rendered_terminal.retained_bytes).toBeLessThanOrEqual(
30_000,
);
expect(details.rendered_terminal.retained_bytes).toBeLessThanOrEqual(1_000);
expect(details.process.coverage).toBe("sampled");
expect(processSourceTruncated(result, "terminal_raw")).toBe(false);
expect(processSourceTruncated(result, "terminal_rendered")).toBe(true);