diff --git a/docs/playwright-traces.md b/docs/playwright-traces.md index 4a5ac6e357..562ad99cbd 100644 --- a/docs/playwright-traces.md +++ b/docs/playwright-traces.md @@ -112,7 +112,9 @@ retryable capacity error. Retained queries do not require another import. Resource policies admit a 256-MiB archive, 32 MiB of decoded streams, a conservative 32-MiB retained-facts representation, 4-MiB metadata reads and 4-MiB physical lines. JSON parsing additionally checks heap headroom, a -131,072-node record allowance and the shared 64-level capture nesting budget. +131,072-node record allowance and a fixed 64-level trace nesting allowance. +JSON parser refusals report the exhausted limit name and maximum in +`details.reported_limits`. These are resource policies, not Playwright format limits. Paging or field selection does not increase parsing allowances; choose a smaller complete recorder chunk when admission fails. diff --git a/scripts/verify/baselines/resource-constraint-constructor.json b/scripts/verify/baselines/resource-constraint-constructor.json index bbc03695ab..9c84c826b1 100644 --- a/scripts/verify/baselines/resource-constraint-constructor.json +++ b/scripts/verify/baselines/resource-constraint-constructor.json @@ -37,7 +37,7 @@ "src/browser/history/playwrightTrace/TraceFailure.ts": 1, "src/browser/history/playwrightTrace/TraceInventory.ts": 1, "src/browser/history/playwrightTrace/TraceLines.ts": 2, - "src/browser/history/playwrightTrace/TraceStream.ts": 2, + "src/browser/history/playwrightTrace/TraceStream.ts": 1, "src/cli/cliJsonInput.ts": 2, "src/cli/cliResultOutput.ts": 2, "src/cli/environmentCommands.ts": 1, diff --git a/src/browser/history/CaptureJson.test.ts b/src/browser/history/CaptureJson.test.ts index a42e494dbb..db62ec1028 100644 --- a/src/browser/history/CaptureJson.test.ts +++ b/src/browser/history/CaptureJson.test.ts @@ -1,6 +1,8 @@ import { expect, it, onTestFinished } from "vitest"; import { createTestProcessRegistry } from "../../../tests/support/process/processFixture.js"; +import { selectedWebNetworkCaptureBudgets } from "../../domain/webNetworkCapture.js"; +import { withCaptureBudgets } from "./CaptureBudgets.js"; import { parseCaptureJson } from "./CaptureJson.js"; it("decodes every JSON string escape as JSON.parse does", () => { @@ -9,6 +11,21 @@ it("decodes every JSON string escape as JSON.parse does", () => { expect(parseCaptureJson(text, "HAR")).toEqual(JSON.parse(text)); }); +it("keeps trace nesting independent of the selected network capture depth", () => { + const text = "[[true]]"; + const budgets = selectedWebNetworkCaptureBudgets({ max_nesting_depth: 1 }); + withCaptureBudgets(budgets, () => { + expect(() => parseCaptureJson(text, "HAR")).toThrow( + expect.objectContaining({ + failure: expect.objectContaining({ + limit: { name: "nesting-depth", maximum: 1 }, + }), + }), + ); + expect(parseCaptureJson(text, "Playwright trace")).toEqual([[true]]); + }); +}); + it("retains escape-heavy strings within a heap near their decoded size", async () => { const processes = createTestProcessRegistry(); onTestFinished(() => processes.shutdown()); diff --git a/src/browser/history/CaptureJson.ts b/src/browser/history/CaptureJson.ts index df58469be5..5fd065c728 100644 --- a/src/browser/history/CaptureJson.ts +++ b/src/browser/history/CaptureJson.ts @@ -4,6 +4,7 @@ import { visit } from "jsonc-parser"; import { LosslessNumber } from "lossless-json"; import { CaptureFormatError } from "./CaptureFormatError.js"; import { decodeStrictUtf8 } from "../../domain/strictUtf8.js"; +import { WEB_NETWORK_CAPTURE_LIMITS } from "../../domain/webNetworkCapture.js"; type Frame = | { @@ -51,6 +52,10 @@ export const parseCaptureJson = ( ): unknown => { const frames: Frame[] = []; const admitNode = captureNodeAdmission(maximumNodes); + const fixedDepth = format === "Playwright trace"; + const maximumDepth = fixedDepth + ? WEB_NETWORK_CAPTURE_LIMITS.depth + : captureBudgets().depth; let result: unknown; const valuePointer = (): string => { const parent = frames.at(-1); @@ -66,10 +71,10 @@ export const parseCaptureJson = ( // container add no level, so empty and scalar-bearing containers agree. const admitContainer = (): void => { admitNode(); - if (frames.length >= captureBudgets().depth) + if (frames.length >= maximumDepth) throw new CaptureFormatError( - { name: "nesting-depth", maximum: captureBudgets().depth }, - `${format} exceeds max_nesting_depth (${String(captureBudgets().depth)} levels).`, + { name: "nesting-depth", maximum: maximumDepth }, + `${format} exceeds ${fixedDepth ? "its fixed JSON nesting allowance" : "max_nesting_depth"} (${String(maximumDepth)} levels).`, valuePointer(), ); }; diff --git a/src/browser/history/playwrightTrace/PlaywrightTraceDecoder.test.ts b/src/browser/history/playwrightTrace/PlaywrightTraceDecoder.test.ts index bab8f91b78..abb70b8323 100644 --- a/src/browser/history/playwrightTrace/PlaywrightTraceDecoder.test.ts +++ b/src/browser/history/playwrightTrace/PlaywrightTraceDecoder.test.ts @@ -391,6 +391,11 @@ it("bounds JSON node expansion even when many tokens fit inside a small physical expect(result.error._tag).toBe("AnalysisResourceConstraintError"); expect(projectAnalysisError(result.error).details).toMatchObject({ refusal: { limit: 131072, unit: "parser nodes" }, + reported_limits: { + boundary: "parser-nodes", + maximum: 131072, + parser_nodes: 131072, + }, }); expect(resources.hasPending).toBe(false); } finally { diff --git a/src/browser/history/playwrightTrace/TraceStream.ts b/src/browser/history/playwrightTrace/TraceStream.ts index 719ec94c27..e9b0421414 100644 --- a/src/browser/history/playwrightTrace/TraceStream.ts +++ b/src/browser/history/playwrightTrace/TraceStream.ts @@ -10,6 +10,10 @@ import { AnalysisResourceConstraintError, AnalysisUnsupportedTargetError, } from "../../../domain/analysisErrorCore.js"; +import { + isParseLimit, + parseLimitConstraint, +} from "../../../domain/parseFailureAnalysisError.js"; import { PLAYWRIGHT_TRACE_OPERATION, PLAYWRIGHT_TRACE_LIMITS, @@ -18,7 +22,11 @@ import { type TraceEvent, } from "../../../domain/playwrightTrace/playwrightTrace.js"; import { captureObject } from "../CaptureRedaction.js"; -import { CAPTURE_LIMITS, CaptureFormatError } from "../CaptureFormatError.js"; +import { + CAPTURE_FORMAT, + CAPTURE_LIMITS, + CaptureFormatError, +} from "../CaptureFormatError.js"; import { parseCaptureJson } from "../CaptureJson.js"; import { TraceInventory, traceIdentity } from "./TraceInventory.js"; import { traceLines, type TraceLineBudget } from "./TraceLines.js"; @@ -142,18 +150,18 @@ class TraceStreamRead { raw = readRecord(line.bytes); } catch (cause) { if (!(cause instanceof CaptureFormatError)) throw cause; - const { limit } = cause; - if (limit !== undefined) { - // The parser names the allowance it exhausted: node count or depth. - const { name, maximum } = limit; + if (isParseLimit(cause, CAPTURE_FORMAT)) { + const { name, maximum } = cause.failure.limit; + if (name !== "nesting-depth" && name !== "parser-nodes") throw cause; const nesting = name === "nesting-depth"; - throw new AnalysisResourceConstraintError( + throw parseLimitConstraint( PLAYWRIGHT_TRACE_OPERATION, "memory", - cause.message, - { [nesting ? "nesting_levels" : "parser_nodes"]: maximum }, + cause, { - cause, + reportedLimitContext: { + [nesting ? "nesting_levels" : "parser_nodes"]: maximum, + }, ...fixedAllowanceOptions( nesting ? "The Playwright trace record nesting allowance" diff --git a/tests/acceptance/applications/playwrightTrace.test.ts b/tests/acceptance/applications/playwrightTrace.test.ts index 4e57e59c37..ba03f91be2 100644 --- a/tests/acceptance/applications/playwrightTrace.test.ts +++ b/tests/acceptance/applications/playwrightTrace.test.ts @@ -17,6 +17,42 @@ import { evidenceBundleSchema } from "../../../src/domain/evidenceBundle.js"; type McpCall = Awaited>["call"]; +cliTest( + "reports the fixed trace nesting limit through CLI and MCP", + async ({ cli }) => { + const trace = + '{"type":"context-options","version":10}\n' + + `{"type":"console","args":${"[".repeat(65)}${"]".repeat(65)}}\n`; + const fixture = await playwrightTraceFixture({ trace, network: "" }); + const expected = { + code: "resource_constraint", + retryable: false, + details: { + reason: expect.stringContaining("fixed JSON nesting allowance"), + reported_limits: { + boundary: "nesting-depth", + maximum: 64, + nesting_levels: 64, + }, + refusal: { kind: "fixed_ceiling", limit: 64, unit: "nesting levels" }, + }, + }; + const result = await cli.run({ + arguments: ["inspect-playwright-trace", fixture.path, "--json"], + }); + expect(result.exitCode, result.stderr).toBe(1); + expect(result.json).toMatchObject(expected); + const { call } = await connectLocalToolsMcp({ + REA_MCP_TOOL_FAMILIES: "application", + }); + const response = await call("inspect_playwright_trace", { + path: fixture.path, + }); + expect(response.isError).toBe(true); + expect(parseMcpToolError(response).error).toMatchObject(expected); + }, +); + cliTest( "preserves original ZIP paths across CLI/MCP, resource lookup and exact member filters", async ({ cli }) => {