fix(analysis-view): fit Playwright trace row pages to byte budget (#15231)

Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
ShuaixinHuang
2026-11-30 23:55:16 +08:00
committed by GitHub
co-authored by ShuaixinHuang
parent 181bbb2f89
commit 5367fe5a5f
3 changed files with 101 additions and 4 deletions
+4 -1
View File
@@ -48,7 +48,10 @@ The `playwright-trace` view offers:
An omitted filter selects all retained rows; an explicit empty filter selects
none. Minimal event rows keep event/stream IDs, source member/line, producer
ordinal, kind and credential-redaction status. Page exhaustion describes only
ordinal, kind and credential-redaction status. The 1 MiB projection budget
can shorten a row page. Continue at `coverage.next_offset` with the same
filters and fields. If one row cannot fit, select fewer fields or read its
text through `event-text`. Page exhaustion describes only
the selected facts and never establishes complete recording coverage.
Default event pages return at most 256 UTF-16 code units in `text_preview`,
+32 -3
View File
@@ -16,6 +16,7 @@ import {
} from "../playwrightTrace/playwrightTrace.js";
import { playwrightTraceViewRequestSchema } from "../playwrightTrace/playwrightTraceQuery.js";
import { ok } from "../result.js";
import type { JsonValue } from "../jsonValue.js";
import {
createAnalysisViewResultReader,
type AnalysisViewParent,
@@ -29,11 +30,15 @@ import {
analysisViewCoverageSchema,
boundedViewLimitations,
completeWithinViewCoverage,
selectedViewPage,
pageViewCoverage,
} from "./analysisViewCoverage.js";
import { isImmutableJsonSnapshot } from "../immutableJson.js";
import { pickFields, selectViewRows, filterSet } from "./selectViewRows.js";
import { invalidAnalysisView } from "./analysisViewErrors.js";
import {
PLACEHOLDER_COVERAGE,
selectByteBoundedViewRows,
} from "./byteBoundedViewRows.js";
export const playwrightTraceViewContextSchema = playwrightTraceSchema
.omit({
@@ -468,11 +473,35 @@ export const projectPlaywrightTraceView = (
: text;
}
const selected = selectRows(parsed.value, view);
return ok({
const page = {
...shared,
...context,
kind: "playwright-trace" as const,
view,
...selectedViewPage(view.offset, selected),
};
type Row = (typeof selected.rows)[number];
const fitted = selectByteBoundedViewRows<Row, Row>(
selected.rows,
{ offset: 0, limit: selected.rows.length },
{ matches: undefined, project: (row) => row },
{
parentEvidenceId: parent.evidenceId,
envelope: {
...page,
coverage: PLACEHOLDER_COVERAGE,
items: [],
} as JsonValue,
facet: `Playwright trace ${view.collection}`,
},
);
if (!fitted.ok) return fitted;
return ok({
...page,
items: selected.rows.slice(0, fitted.value.rows.length),
coverage: pageViewCoverage(
view.offset,
fitted.value.rows.length,
selected.total,
),
});
};
@@ -693,3 +693,68 @@ cliTest(
}
},
);
cliTest("continues filtered trace pages at the view byte budget", async () => {
const texts = Array.from({ length: 16 }, (_, index) =>
String.fromCharCode(97 + index).repeat(400_000),
);
const trace = [
JSON.stringify({ type: "context-options", version: 10 }),
...texts.map((text, time) =>
JSON.stringify({ type: "console", messageType: "log", text, time }),
),
"",
].join("\n");
const fixture = await playwrightTraceFixture({ trace, network: "" });
const { call } = await traceMcp();
const view = {
kind: "playwright-trace",
collection: "events",
kinds: ["console"],
fields: ["text"],
limit: texts.length,
};
const first = await call("inspect_playwright_trace", {
path: fixture.path,
trace_limits: { facts_bytes: 96 * 1024 * 1024 },
view,
});
if (first.isError) throw new Error(JSON.stringify(parseMcpToolError(first)));
const page = analysisViewResultSchema.parse(
parseEvidence(first.structuredContent).normalized_result,
);
expect(page.coverage).toEqual({
status: "page",
examined: 2,
total: texts.length,
next_offset: 2,
exhausted: false,
});
if (page.kind !== "playwright-trace") throw new Error("Expected trace page");
expect(page.items.map((item) => "text" in item && item.text?.[0])).toEqual([
"a",
"b",
]);
const second = await call("inspect_analysis_view", {
source: { kind: "retained-evidence", evidence_id: page.parent_evidence_id },
view: { ...view, offset: 2 },
});
if (second.isError)
throw new Error(JSON.stringify(parseMcpToolError(second)));
const next = analysisViewResultSchema.parse(
parseEvidence(second.structuredContent).normalized_result,
);
expect(next.coverage).toEqual({
status: "page",
examined: 2,
total: texts.length,
next_offset: 4,
exhausted: false,
});
if (next.kind !== "playwright-trace")
throw new Error("Expected trace continuation");
expect(next.items.map((item) => "text" in item && item.text?.[0])).toEqual([
"c",
"d",
]);
});