test(capture): prove retained summaries survive source deletion (#13206)

This commit is contained in:
morluto authored and GitHub committed 2026-11-21 20:48:19 +00:00
1 parent 088bc68b1c
commit a2faf4cc34
3 files changed
+283 -305

No files matched your search

+143 -172
View File
@@ -91,7 +91,7 @@ it("derives interval unions per trace/direction while retaining event source ord
expect(Reflect.get(Object.prototype, "ordinary")).toBeUndefined();
});
it("keeps exact 62-bit integers and numeric lexemes without allocating exponent expansion", () => {
it("keeps exact 62-bit integers and source numeric lexemes", () => {
const text = capture([event([frame(0, 0, true)])])
.replace('"stream_id":0', '"stream_id":4611686018427387903')
.replace('"offset":0', '"offset":9007199254740993')
@@ -112,26 +112,60 @@ it("keeps exact 62-bit integers and numeric lexemes without allocating exponent
});
});
it("keeps incomplete fields unknown and FIN without bytes as metadata", () => {
const { traces } = facts(
it("keeps incomplete STREAM facts, distinct FIN values and zero-byte final sizes", () => {
const { decoded, traces } = facts(
capture([
event([{ ...frame(8, 3), fin: undefined }]),
event([{ ...frame(8, 3), fin: null }]),
event([frame(8, 3, false)]),
event([{ ...frame(12, 0, true), stream_id: 6 }]),
event([{ frame_type: "stream", stream_id: 0, length: 5 }]),
event([frame(10, 0, true)]),
{ name: "recovery:packet_lost", time: 1, data: {} },
{
name: "extension:custom",
time: 0,
data: { body: "ordinary evidence" },
},
]),
);
expect(traces[0]?.incomplete_fact_records).toEqual([0]);
expect(traces[0]?.streams[0]).toMatchObject({
unique_bytes: "0",
covered_ranges: [],
reported_final_sizes: ["10"],
expect(traces[0]).toMatchObject({
incomplete_fact_records: [0, 1, 4],
streams: [
{
stream_id: "0",
unique_bytes: "3",
covered_ranges: [{ start: "8", end: "11" }],
reported_final_sizes: [],
},
{
stream_id: "6",
unique_bytes: "0",
covered_ranges: [],
reported_final_sizes: ["12"],
},
],
loss_declarations: [
{ record_ordinal: 5, packet_number: { state: "unknown" } },
],
});
expect(traces[0]?.loss_declarations[0]?.packet_number.state).toBe("unknown");
expect(
traces[0]?.streams.flatMap(({ contributions }) =>
contributions.map(
({ record_ordinal, frame_index, offset, length, fin }) => [
record_ordinal,
frame_index,
offset,
length,
fin,
],
),
),
).toEqual([
[0, 0, "8", "3", null],
[1, 0, "8", "3", null],
[2, 0, "8", "3", false],
[3, 0, "12", "0", true],
]);
expect(decoded.records[0]?.reported).not.toHaveProperty("data.frames.0.fin");
expect(decoded.records[1]?.reported).toHaveProperty(
"data.frames.0.fin",
null,
);
});
it("marks non-string frame types incomplete without hiding their recorded values", () => {
@@ -149,54 +183,8 @@ it("marks non-string frame types incomplete without hiding their recorded values
});
});
it.each([
{ fin: undefined, incomplete: [0] },
{ fin: null, incomplete: [0] },
{ fin: false, incomplete: [] },
{ fin: true, incomplete: [] },
])(
"retains STREAM ranges and marks unknown FIN records incomplete: $fin",
({ fin, incomplete }) => {
const streamFrame: Record<string, unknown> = {
frame_type: "stream",
stream_id: 4,
offset: 8,
length: 3,
};
if (fin !== undefined) streamFrame.fin = fin;
const { traces } = facts(capture([event([streamFrame])]));
expect(traces[0]?.incomplete_fact_records).toEqual(incomplete);
expect(traces[0]?.streams[0]?.contributions).toEqual([
{
record_ordinal: 0,
frame_index: 0,
offset: "8",
length: "3",
fin: typeof fin === "boolean" ? fin : null,
},
]);
expect(traces[0]?.streams[0]?.covered_ranges).toEqual([
{ start: "8", end: "11" },
]);
},
);
it("excludes structural auth material and explicit normalized values without guessing extension secrecy", () => {
it("excludes structural QUIC credentials and marked normalized stream values", () => {
const text = capture([
{
name: "http:frame_parsed",
time: 1,
data: {
frame: {
frame_type: "headers",
headers: [
{ name: "authorization", value: "Bearer credential" },
{ name: ":path", value: "/?token=ordinary" },
{ name: "location", value: "https://user:pass@example.test/a" },
],
},
},
},
{
name: "transport:parameters_set",
time: 2,
@@ -210,74 +198,73 @@ it("excludes structural auth material and explicit normalized values without gue
{
name: "extension:custom",
time: 3,
data: {
secret: "caller-selected ordinary value",
reset_token: "extension ordinary",
},
data: { reset_token: "ordinary extension value" },
},
]).replace('"length":100', '"length":1e2');
const { decoded, traces } = facts(text, ["100"]);
const serialized = JSON.stringify(decoded);
for (const hidden of [
"Bearer credential",
for (const excluded of [
"reset-credential",
"reset-frame",
"new-token",
"100",
"user:pass",
])
expect(serialized).not.toContain(hidden);
expect(serialized).toContain("token=ordinary");
expect(serialized).toContain("caller-selected ordinary value");
expect(JSON.stringify(decoded)).not.toContain(excluded);
expect(decoded.records[0]?.reported).toHaveProperty(
"data.stateless_reset_token",
null,
);
expect(decoded.records[1]?.reported).toMatchObject({
data: {
frames: [
{ frame_type: "new_connection_id", reset_token: null },
{ frame_type: "new_token", token: null },
{ frame_type: "stream", length: null },
],
},
});
expect(decoded.records[2]?.reported).toHaveProperty(
"data.reset_token",
"ordinary extension value",
);
expect(traces[0]?.streams).toEqual([]);
expect(traces[0]?.incomplete_fact_records).toContain(2);
expect(traces[0]?.incomplete_fact_records).toEqual([1]);
});
it.each(["http:frame_created", "http:frame_parsed", "extension:custom"])(
"applies HTTP credential and transport URL rules only to HTTP header events: %s",
(name) => {
const headers = [
{ name: "Authorization", value: "authorization credential" },
{ name: "Proxy-AUTHORIZATION", value: "proxy credential" },
{ name: "CoOkIe", value: "cookie credential" },
{ name: "Set-Cookie", value: "response cookie credential" },
{ name: "Location", value: "https://user:pass@example.test/path" },
{ name: "authorization-extra", value: "ordinary extension" },
];
const { decoded } = facts(
capture([{ name, time: 1, data: { frame: { headers } } }]),
);
const http = name.startsWith("http:");
const expectedValues = http
? [
null,
null,
null,
null,
"https://example.test/path",
"ordinary extension",
]
: headers.map(({ value }) => value);
expect(decoded.records[0]?.reported).toMatchObject({
data: {
frame: {
headers: headers.map((header, index) => ({
...header,
value: expectedValues[index],
})),
},
},
});
expect(decoded.records[0]?.redactions).toEqual(
http
? Array.from({ length: 5 }, (_, index) => ({
pointer: `/data/frame/headers/${index}/value`,
reason: "transport-credential",
}))
: [],
);
},
);
it("applies transport redaction only to actual HTTP header events", () => {
const headers = [
{ name: "Authorization", value: "authorization credential" },
{ name: "Proxy-AUTHORIZATION", value: "proxy credential" },
{ name: "CoOkIe", value: "cookie credential" },
{ name: "Set-Cookie", value: "response cookie credential" },
{ name: "Location", value: "https://user:pass@example.test/path" },
{ name: ":path", value: "/?token=ordinary" },
{ name: "authorization-extra", value: "ordinary extension" },
];
const names = ["http:frame_created", "extension:custom", "http:frame_parsed"];
const { decoded } = facts(
capture(
names.map((name) => ({ name, time: 1, data: { frame: { headers } } })),
),
);
const redactedHeaders = headers.map((header, index) => ({
...header,
value:
index < 4
? null
: index === 4
? "https://example.test/path"
: header.value,
}));
const redactions = Array.from({ length: 5 }, (_, index) => ({
pointer: `/data/frame/headers/${index}/value`,
reason: "transport-credential",
}));
expect(decoded.records).toMatchObject([
{ reported: { data: { frame: { headers: redactedHeaders } } }, redactions },
{ reported: { data: { frame: { headers } } }, redactions: [] },
{ reported: { data: { frame: { headers: redactedHeaders } } }, redactions },
]);
});
it.each([
{ literal: "1e2", sensitive: "100", reported: null, retained: false },
@@ -365,12 +352,8 @@ it("counts hidden payloads only for events interpreted as transport facts", () =
});
it("omits a hidden derived total for a stream with more contributions than call arguments allow", () => {
const events = Array.from({ length: 130 }, (_, index) =>
event(
Array.from({ length: 1_000 }, (_, offset) =>
frame(index * 1_000 + offset, 1),
),
),
const events = Array.from({ length: 130 }, () =>
event(Array.from({ length: 1_000 }, () => frame(0, 1))),
);
const { traces } = facts(capture(events), ["130000"]);
expect(traces[0]?.streams).toEqual([]);
@@ -408,17 +391,33 @@ it.each([
`"length":${literal}`,
),
),
).toThrow(CaptureFormatError);
).toThrow(
expect.objectContaining({
pointer: "/traces/0/events/0/data/frames/0/length",
failure: expect.objectContaining({ kind: "malformed" }),
}),
);
});
it("rejects a STREAM whose valid offset and length exceed the range when added", () => {
const text = capture([event([frame(0, 1)])]).replace(
'"offset":0',
'"offset":4611686018427387903',
);
expect(() => facts(text)).toThrow(
expect.objectContaining({
pointer: "/traces/0/events/0/data/frames/0",
failure: expect.objectContaining({ kind: "malformed" }),
}),
);
});
it.each([
'{"qlog_format":"JSON","qlog_format":"JSON","qlog_version":"0.3","traces":[]}',
capture([]).slice(0, -1),
capture([]) + " {}",
capture([{ name: "invalid", time: "1", data: {} }]),
capture([[1, "transport", "packet_sent", {}]]),
capture([event([{ ...frame(0, 1), fin: "true" }])]),
capture([event([{ ...frame(0, 1), offset: 4611686018427388000 }])]),
])(
"rejects malformed JSON/profile events with no partial success: %s",
(text) => {
@@ -426,53 +425,25 @@ it.each([
},
);
it.each([
{ depth: 64, innermost: "[]", accepted: true },
{ depth: 64, innermost: "{}", accepted: true },
{ depth: 64, innermost: "[0]", accepted: true },
{ depth: 65, innermost: "[]", accepted: false },
{ depth: 65, innermost: "{}", accepted: false },
{ depth: 65, innermost: "[0]", accepted: false },
{ depth: 66, innermost: "[]", accepted: false },
])(
"bounds a $innermost extension at container level $depth",
({ depth, innermost, accepted }) => {
// The root, traces array and trace object are the first three levels.
const enclosing = depth - 4;
const text = `{"qlog_format":"JSON","qlog_version":"0.3","traces":[{"events":[],"ext":${"[".repeat(enclosing)}${innermost}${"]".repeat(enclosing)}}]}`;
if (accepted) expect(facts(text).decoded.total_records).toBe(0);
else
expect(() => facts(text)).toThrow(
expect.objectContaining({
limit: { name: "nesting-depth", maximum: 64 },
}),
);
},
);
it("retains an extension at the last admitted qlog container level", () => {
// The root, traces array and trace object consume the first three levels.
const nested = "[".repeat(61) + '"last-level"' + "]".repeat(61);
const text = `{"qlog_format":"JSON","qlog_version":"0.3","traces":[{"events":[],"ext":${nested}}]}`;
const bytes = Buffer.from("\ufeff" + text);
const { decoded } = facts(decodeCaptureText(bytes, "qlog"));
expect(decoded.container.reported).toHaveProperty(
"traces.0.ext",
JSON.parse(nested),
);
});
it("rejects other qlog containers/versions and excessive nesting, accepts empty profiles and UTF-8 BOM", () => {
for (const extra of [{ qlog_format: "JSON-SEQ" }, { qlog_version: "0.4" }])
expect(() => facts(capture([], extra))).toThrow("Only the aioquic");
expect(() =>
facts(
capture([], {
extension: JSON.parse("[".repeat(65) + "0" + "]".repeat(65)),
}),
),
).toThrow(
expect.objectContaining({ limit: { name: "nesting-depth", maximum: 64 } }),
it("distinguishes unsupported qlog sequences from an empty supported profile", () => {
expect(() => facts(capture([], { qlog_format: "JSON-SEQ" }))).toThrow(
expect.objectContaining({
failure: expect.objectContaining({ kind: "unsupported" }),
}),
);
expect(
facts('{"qlog_format":"JSON","qlog_version":"0.3","traces":[]}').traces,
).toEqual([]);
const raw = Buffer.from(capture([]));
expect(
facts(
decodeCaptureText(
Buffer.concat([Buffer.from([0xef, 0xbb, 0xbf]), raw]),
"qlog",
),
).decoded.total_records,
).toBe(0);
expect(() => decodeCaptureText(Buffer.from([0xff]), "qlog")).toThrow("UTF-8");
});
+112 -119
View File
@@ -11,6 +11,8 @@ import {
} from "../../fixtures/captureDecoderLimits.js";
import { webNetworkCaptureSummaryViewResultSchema } from "../../../src/domain/analysisView/analysisViewResult.js";
import { parseEvidence } from "../../../src/domain/evidence.js";
import { evidenceRecordSelectionSchema } from "../../../src/domain/evidenceRecordSummary.js";
import { lifecycleResultOf } from "../../../src/contracts/toolOutputSchemaPrimitives.js";
import {
webNetworkCaptureSchema,
WEB_NETWORK_CAPTURE_LIMITS,
@@ -119,6 +121,19 @@ const event = {
frames: [{ frame_type: "stream", stream_id: 0, offset: 10, length: 5 }],
},
};
const packetWithStream = (
offset: number,
length: number,
fin: boolean,
name = event.name,
) => ({
...event,
name,
data: {
...event.data,
frames: [{ ...event.data.frames[0], offset, length, fin }],
},
});
const qlog = (events: unknown[]) =>
JSON.stringify({
qlog_format: "JSON",
@@ -150,89 +165,45 @@ const expectRecoveredCapture = async (
});
};
it("does not classify hidden custom event data as incomplete transport facts", async () => {
const root = await createTestTempDirectory("rea-qlog-hidden-extension-");
const path = join(root, "input.qlog");
await writeFile(
path,
qlog([
{ name: "extension:custom", time: 1, data: { body: "ordinary" } },
{
...event,
data: {
...event.data,
frames: [{ ...event.data.frames[0], fin: false }],
},
},
]),
);
const { call } = await sharedMcp();
for (const sensitive of [[], ["data"]]) {
const response = await call("inspect_web_network_capture", {
capture_path: path,
format: "qlog",
sensitive_values: sensitive,
});
expect(response.isError, JSON.stringify(response)).not.toBe(true);
const mcp = parseEvidence(response.structuredContent);
const cliResult = await runSharedCli([
"inspect-web-network-capture",
path,
"qlog",
...sensitive.flatMap((value) => ["--sensitive-value", value]),
"--json",
]);
expect(cliResult.exitCode, cliResult.stderr).toBe(0);
const cliEvidence = parseEvidence(cliResult.json);
expect(cliEvidence.normalized_result).toEqual(mcp.normalized_result);
const capture = webNetworkCaptureSchema.parse(mcp.normalized_result);
if (capture.format !== "qlog") throw new Error("qlog format required");
expect(capture.qlog.traces[0]?.incomplete_fact_records).toEqual(
sensitive.length === 0 ? [] : [1],
);
if (sensitive.length > 0)
expect(capture.records[0]?.reported).toEqual({
name: "extension:custom",
time: 1,
});
}
});
const assertAdditionalQlogFacets = async (
call: Awaited<ReturnType<typeof connectLocalToolsMcp>>["call"],
retained: { kind: string; evidence_id: string },
): Promise<void> => {
for (const [view, expected] of [
for (const [view, expected, total] of [
[
{ kind: "qlog", facet: "traces", offset: 1, limit: 1 },
[{ trace_index: 1, event_count: 1, stream_count: 1 }],
2,
],
[
{ kind: "qlog", facet: "loss-declarations", trace_index: 0 },
[{ record_ordinal: 1, packet_number: { state: "reported", value: "5" } }],
1,
],
[{ kind: "qlog", facet: "incomplete-records", trace_index: 0 }, [0]],
[{ kind: "qlog", facet: "incomplete-records", trace_index: 0 }, [0], 1],
[
{
kind: "qlog",
facet: "ranges",
trace_index: 0,
stream_id: "0",
direction: "sent",
direction: "received",
},
[{ start: "10", end: "15" }],
[{ start: "50", end: "52" }],
1,
],
[
{
kind: "qlog",
facet: "final-sizes",
trace_index: 0,
trace_index: 1,
stream_id: "0",
direction: "sent",
},
[],
["103"],
1,
],
[{ kind: "qlog", facet: "traces", offset: 99 }, []],
[{ kind: "qlog", facet: "traces", offset: 99 }, [], 2],
] as const) {
const response = await call("inspect_analysis_view", {
source: retained,
@@ -242,8 +213,8 @@ const assertAdditionalQlogFacets = async (
expect(
parseEvidence(response.structuredContent).normalized_result,
).toMatchObject({
page: { items: expected },
coverage: { exhausted: true },
page: { facet: view.facet, items: expected },
coverage: { total, exhausted: true },
});
}
};
@@ -259,26 +230,12 @@ it("pages original trace-scoped facts after source deletion without conflating s
time: 1791819895001,
data: { packet_number: 5, type: "1RTT" },
},
packetWithStream(50, 2, false, "transport:packet_received"),
]),
);
source.traces.push({
...source.traces[0],
events: [
{
...event,
data: {
frames: [
{
frame_type: "stream",
stream_id: 0,
offset: 100,
length: 3,
fin: true,
},
],
},
},
],
events: [packetWithStream(100, 3, true)],
});
await writeFile(path, JSON.stringify(source));
const { call } = await sharedMcp();
@@ -286,7 +243,7 @@ it("pages original trace-scoped facts after source deletion without conflating s
capture_path: path,
format: "qlog",
detail: "summary",
record_ordinals: [2],
record_ordinals: [3],
});
expect(response.isError, JSON.stringify(response)).not.toBe(true);
const summary = webNetworkCaptureSummaryViewResultSchema.parse(
@@ -294,37 +251,34 @@ it("pages original trace-scoped facts after source deletion without conflating s
);
expect(summary).toMatchObject({
summary: {
total_records: 3,
total_records: 4,
retained_records: 1,
qlog: {
trace_count: 2,
retained_stream_count: 2,
retained_stream_count: 3,
loss_declaration_count: 1,
},
},
});
expect(JSON.stringify(summary)).not.toContain('"contributions"');
if (
!("parent_evidence_id" in summary) ||
typeof summary.parent_evidence_id !== "string"
)
throw new Error("Missing retained parent");
const retained = {
kind: "retained-evidence",
evidence_id: summary.parent_evidence_id,
};
const parent = parseEvidence(
(
await call("inspect_web_network_capture", {
capture_path: path,
format: "qlog",
record_ordinals: [2],
})
).structuredContent,
);
expect(parent.evidence_id).toBe(summary.parent_evidence_id);
const portablePath = join(root, "parent.json");
await rm(path);
const bundle = await call("get_evidence_bundle", {
detail: "records",
filters: { evidence_id: retained.evidence_id },
});
const { records } = lifecycleResultOf(evidenceRecordSelectionSchema).parse(
bundle.structuredContent,
).result;
expect(records.map(({ evidence_id }) => evidence_id)).toEqual([
retained.evidence_id,
]);
const parent = parseEvidence(records[0]);
expect(parent.normalized_result).toMatchObject({ records: [{ ordinal: 3 }] });
const portablePath = join(root, "parent.json");
const pages = [];
for (const trace_index of [0, 1]) {
const page = await call("inspect_analysis_view", {
@@ -337,6 +291,7 @@ it("pages original trace-scoped facts after source deletion without conflating s
expect(pages[0]).toMatchObject({
page: { items: [{ stream_id: "0", unique_bytes: "5" }] },
context: { scope: "all-recorded-events-before-selection" },
coverage: { total: 2, next_offset: 1, exhausted: false },
});
expect(pages[1]).toMatchObject({
page: { items: [{ stream_id: "0", unique_bytes: "3" }] },
@@ -422,12 +377,13 @@ it("runs built CLI and real stdio SDK with exact evidence parity, selection, ret
await writeFile(
path,
qlog([
event,
packetWithStream(10, 5, false),
{
name: "recovery:packet_lost",
time: 1791819895001.125,
data: { packet_number: 5, type: "1RTT" },
},
{ name: "extension:custom", time: 1, data: { body: "ordinary" } },
]),
);
const { call, client } = await sharedMcp();
@@ -460,6 +416,7 @@ it("runs built CLI and real stdio SDK with exact evidence parity, selection, ret
unique_bytes: "5",
covered_ranges: [{ start: "10", end: "15" }],
});
expect(decoded.qlog.traces[0]?.incomplete_fact_records).toEqual([]);
// An unsupported view over an existing retained parent proves lookup without pretending qlog is HAR.
for (const kind of [
"api-surface",
@@ -475,7 +432,7 @@ it("runs built CLI and real stdio SDK with exact evidence parity, selection, ret
});
}
await client.ping();
for (const record_ordinals of [[2], [0, 0]]) {
for (const record_ordinals of [[3], [0, 0]]) {
expect(
parseMcpToolError(
await call("inspect_web_network_capture", {
@@ -485,19 +442,36 @@ it("runs built CLI and real stdio SDK with exact evidence parity, selection, ret
),
).toMatchObject({ error: { code: "invalid_request" } });
}
const sensitive = ["trace-local", "/traces/0", "input.qlog", "data"];
const hidden = await call("inspect_web_network_capture", {
capture_path: path,
format: "qlog",
sensitive_values: ["trace-local", "/traces/0", "input.qlog"],
sensitive_values: sensitive,
});
expect(JSON.stringify(hidden)).not.toContain("trace-local");
expect(JSON.stringify(hidden)).not.toContain("/traces/0");
expect(JSON.stringify(hidden)).not.toContain("input.qlog");
const hiddenCli = await runSharedCli([
"inspect-web-network-capture",
path,
"qlog",
...sensitive.flatMap((value) => ["--sensitive-value", value]),
"--json",
]);
expect(hiddenCli.exitCode, hiddenCli.stderr).toBe(0);
const hiddenEvidence = parseEvidence(hidden.structuredContent);
expect(
webNetworkCaptureSchema.parse(hiddenEvidence.normalized_result).artifact
.path,
).toBe("");
expect(parseEvidence(hiddenCli.json).normalized_result).toEqual(
hiddenEvidence.normalized_result,
);
for (const excluded of ["trace-local", "/traces/0", "input.qlog"])
expect(JSON.stringify(hidden)).not.toContain(excluded);
const redacted = webNetworkCaptureSchema.parse(
hiddenEvidence.normalized_result,
);
if (redacted.format !== "qlog") throw new Error("qlog format required");
expect(redacted.artifact.path).toBe("");
expect(redacted.qlog.traces[0]?.incomplete_fact_records).toEqual([0, 1]);
expect(redacted.records[2]?.reported).toEqual({
name: "extension:custom",
time: 1,
});
const invalid = await call("inspect_web_network_capture", {
...input,
mysecret: true,
@@ -513,7 +487,7 @@ it("fails whole-capture validation before selection and survives malformed, unsu
const root = await createTestTempDirectory("rea-qlog-errors-");
const path = join(root, "input.qlog");
const { call, client } = await sharedMcp();
for (const [text, expected] of [
const cases = [
[
qlog([event, { ...event, time: "invalid" }]),
{
@@ -553,7 +527,7 @@ it("fails whole-capture validation before selection and survives malformed, unsu
qlog([
{
...event,
extension: JSON.parse("[".repeat(65) + "0" + "]".repeat(65)),
extension: JSON.parse("[".repeat(60) + "0" + "]".repeat(60)),
},
]),
{
@@ -571,7 +545,24 @@ it("fails whole-capture validation before selection and survives malformed, unsu
},
},
],
] as const) {
] as const;
const [outsideSelection, selectionError] = cases[0];
await writeFile(path, outsideSelection);
const failed = await runSharedCli([
"inspect-web-network-capture",
path,
"qlog",
"--record",
"0",
"--json",
]);
expect(failed.exitCode, failed.stdout + failed.stderr).toBe(1);
expect(
issuesByContractField(JSON.parse(failed.stdout), {
capturePath: "capture_path",
}),
).toMatchObject(selectionError);
for (const [text, expected] of cases) {
await writeFile(path, text);
expect(
parseMcpToolError(
@@ -582,19 +573,6 @@ it("fails whole-capture validation before selection and survives malformed, unsu
}),
),
).toMatchObject({ error: expected });
const failed = await runSharedCli([
"inspect-web-network-capture",
path,
"qlog",
"--json",
]);
expect(failed.exitCode, failed.stdout + failed.stderr).toBe(1);
// The CLI names the capture by its argument, otherwise as MCP does.
expect(
issuesByContractField(JSON.parse(failed.stdout), {
capturePath: "capture_path",
}),
).toMatchObject(expected);
}
await truncate(path, WEB_NETWORK_CAPTURE_LIMITS.inputBytes + 1);
expect(
@@ -604,7 +582,22 @@ it("fails whole-capture validation before selection and survives malformed, unsu
format: "qlog",
}),
),
).toMatchObject({ error: { code: "invalid_request" } });
).toMatchObject({
error: {
code: "invalid_request",
details: {
issues: [
{
path: ["capture_path"],
reason: "out_of_range",
expected: {
maximum_capture_bytes: WEB_NETWORK_CAPTURE_LIMITS.inputBytes,
},
},
],
},
},
});
await writeFile(path, qlog([event]));
await client.ping();
await expectRecoveredCapture(call, path);
+28 -14
View File
@@ -17,6 +17,9 @@ import {
} from "vitest";
import { z } from "zod";
import { parseEvidence } from "../../../src/domain/evidence.js";
import { webNetworkCaptureSummaryViewResultSchema } from "../../../src/domain/analysisView/analysisViewResult.js";
import { evidenceRecordSelectionSchema } from "../../../src/domain/evidenceRecordSummary.js";
import { lifecycleResultOf } from "../../../src/contracts/toolOutputSchemaPrimitives.js";
import {
WEB_NETWORK_CAPTURE_LIMITS,
webNetworkCaptureSchema,
@@ -552,33 +555,44 @@ it("pages retained SAZ Evidence through public MCP and portable CLI after source
const path = await fixture(await archive());
const { call } = await connectSazMcp();
const args = { capture_path: path, format: "saz", record_ordinals: [1, 0] };
const full = await call("inspect_web_network_capture", args);
const fromMcp = parseEvidence(full.structuredContent);
const capture = webNetworkCaptureSchema.parse(fromMcp.normalized_result);
const summaryArgs = { ...args, detail: "summary" };
const summaryResponse = await call(
"inspect_web_network_capture",
summaryArgs,
);
const summaryResponse = await call("inspect_web_network_capture", {
...args,
detail: "summary",
});
expect(summaryResponse.isError, JSON.stringify(summaryResponse)).not.toBe(
true,
);
const summary = parseEvidence(summaryResponse.structuredContent);
expect(summary.normalized_result).toMatchObject({
kind: "summary",
parent_evidence_id: fromMcp.evidence_id,
summary: { format: "saz", total_records: 2, retained_records: 2 },
const view = webNetworkCaptureSummaryViewResultSchema.parse(
summary.normalized_result,
);
expect(view.summary).toMatchObject({
format: "saz",
total_records: 2,
retained_records: 2,
});
expect(JSON.stringify(summary)).not.toContain(
compressedBody.toString("base64"),
);
// Retained pages must keep their snapshot semantics after the input disappears.
await unlink(path);
const source = {
kind: "retained-evidence",
evidence_id: fromMcp.evidence_id,
evidence_id: view.parent_evidence_id,
};
const bundle = await call("get_evidence_bundle", {
detail: "records",
filters: { evidence_id: source.evidence_id },
});
const { records } = lifecycleResultOf(evidenceRecordSelectionSchema).parse(
bundle.structuredContent,
).result;
expect(records.map(({ evidence_id }) => evidence_id)).toEqual([
source.evidence_id,
]);
const fromMcp = parseEvidence(records[0]);
const capture = webNetworkCaptureSchema.parse(fromMcp.normalized_result);
expect(capture.records.map(({ ordinal }) => ordinal)).toEqual([1, 0]);
const previewArgs = {
source,
view: { kind: "capture", offset: 0, limit: 1 },