test(protobuf): share HAR record request fixtures (#15767)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-02 03:41:36 +00:00
1 parent 79855af755
commit 142bc62471
5 files changed
+94 -153

No files matched your search

+9 -20
View File
@@ -14,6 +14,8 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import {
protobufCaptureDescriptor,
protobufHar,
protobufHarRecordCliArguments,
protobufHarRecordMcpArguments,
protobufFrame,
protobufCaptureBody,
} from "../../fixtures/protobufCapture.js";
@@ -66,17 +68,11 @@ async function prepareMcpCapture(
const descriptor = join(root, "capture.pb");
await writeFile(capture, protobufHar());
await writeFile(descriptor, protobufCaptureDescriptor());
const args: CaptureRequest = {
capture_path: capture,
format: "har",
record_ordinals: [0],
protobuf: {
schema: {
descriptor_set_path: descriptor,
message_type: "capture.Message",
},
},
};
const args: CaptureRequest = protobufHarRecordMcpArguments(
capture,
descriptor,
"capture.Message",
);
return { call, args, root, capture, descriptor };
}
@@ -525,18 +521,11 @@ captureTest(
mcp.call,
);
const cliResult = await cli.run({
arguments: [
"inspect-web-network-capture",
arguments: protobufHarRecordCliArguments(
capture,
"har",
"--record",
"0",
"--protobuf-schema",
descriptor,
"--protobuf-message",
"capture.Message",
"--json",
],
),
});
expect(cliResult.exitCode, cliResult.stdout + cliResult.stderr).toBe(0);
const redacted = await call("inspect_web_network_capture", {
@@ -20,6 +20,8 @@ import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
import {
protobufBomDescriptor,
protobufHar,
protobufHarRecordCliArguments,
protobufHarRecordMcpArguments,
} from "../../fixtures/protobufCapture.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
@@ -156,33 +158,19 @@ cliTest(
};
if (change === "declarations" && !reverse) {
const output = await cli.run({
arguments: [
"inspect-web-network-capture",
arguments: protobufHarRecordCliArguments(
capture,
"har",
"--record",
"0",
"--protobuf-schema",
descriptor,
"--protobuf-message",
"entry.Message",
"--json",
],
),
});
expect(output.exitCode).toBe(1);
expect(output.json).toMatchObject(expected);
}
const response = await call("inspect_web_network_capture", {
capture_path: capture,
format: "har",
record_ordinals: [0],
protobuf: {
schema: {
descriptor_set_path: descriptor,
message_type: "entry.Message",
},
},
});
const response = await call(
"inspect_web_network_capture",
protobufHarRecordMcpArguments(capture, descriptor, "entry.Message"),
);
const error = parseMcpToolError(response).error;
expect(error, `${change}-${reverse}`).toMatchObject(expected);
if (change === "declarations") {
@@ -228,18 +216,11 @@ cliTest(
await writeFile(descriptor, bytes);
await writeFile(capture, text);
const output = await cli.run({
arguments: [
"inspect-web-network-capture",
arguments: protobufHarRecordCliArguments(
capture,
"har",
"--record",
"0",
"--protobuf-schema",
descriptor,
"--protobuf-message",
"capture.Root",
"--json",
],
),
});
expect(output.exitCode, output.stdout + output.stderr).toBe(0);
const evidence = parseEvidence(output.json);
@@ -263,17 +244,10 @@ cliTest(
],
});
const call = await cli.sharedMcpCall!();
const response = await call("inspect_web_network_capture", {
capture_path: capture,
format: "har",
record_ordinals: [0],
protobuf: {
schema: {
descriptor_set_path: descriptor,
message_type: "capture.Root",
},
},
});
const response = await call(
"inspect_web_network_capture",
protobufHarRecordMcpArguments(capture, descriptor, "capture.Root"),
);
expect(response.isError, JSON.stringify(response)).not.toBe(true);
expect(parseEvidence(response.structuredContent).evidence_id).toBe(
evidence.evidence_id,
@@ -332,18 +306,11 @@ cliTest(
const descriptor = join(root, `${mode}.pb`);
await writeFile(descriptor, bytes);
const output = await cli.run({
arguments: [
"inspect-web-network-capture",
arguments: protobufHarRecordCliArguments(
capture,
"har",
"--record",
"0",
"--protobuf-schema",
descriptor,
"--protobuf-message",
"entry.Message",
"--json",
],
),
});
expect(output.exitCode, output.stdout + output.stderr).toBe(0);
const evidence = parseEvidence(output.json);
@@ -359,17 +326,10 @@ cliTest(
{ number: 1, schema_name: "payload", schema_type: "capture.Payload" },
{ number: 1, schema_name: "value", schema_value: "1" },
]);
const response = await call("inspect_web_network_capture", {
capture_path: capture,
format: "har",
record_ordinals: [0],
protobuf: {
schema: {
descriptor_set_path: descriptor,
message_type: "entry.Message",
},
},
});
const response = await call(
"inspect_web_network_capture",
protobufHarRecordMcpArguments(capture, descriptor, "entry.Message"),
);
expect(response.isError, JSON.stringify(response)).not.toBe(true);
expect(parseEvidence(response.structuredContent).evidence_id).toBe(
evidence.evidence_id,
@@ -13,7 +13,11 @@ import { z } from "zod";
import { analysisViewResultSchema } from "../../../src/domain/analysisView/analysisViewResult.js";
import { parseEvidence } from "../../../src/domain/evidence.js";
import { webNetworkCaptureSchema } from "../../../src/domain/webNetworkCapture.js";
import { protobufHar } from "../../fixtures/protobufCapture.js";
import {
protobufHar,
protobufHarRecordCliArguments,
protobufHarRecordMcpArguments,
} from "../../fixtures/protobufCapture.js";
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
@@ -158,33 +162,19 @@ cliTest.for([
};
if (index === 0) {
const output = await cli.run({
arguments: [
"inspect-web-network-capture",
arguments: protobufHarRecordCliArguments(
capture,
"har",
"--record",
"0",
"--protobuf-schema",
descriptor,
"--protobuf-message",
"capture.Message",
"--json",
],
),
});
expect(output.exitCode, variant).toBe(1);
expect(output.json, variant).toMatchObject(expected);
}
const response = await call("inspect_web_network_capture", {
capture_path: capture,
format: "har",
record_ordinals: [0],
protobuf: {
schema: {
descriptor_set_path: descriptor,
message_type: "capture.Message",
},
},
});
const response = await call(
"inspect_web_network_capture",
protobufHarRecordMcpArguments(capture, descriptor, "capture.Message"),
);
const error = parseMcpToolError(response).error;
expect(error, variant).toMatchObject(expected);
const source = retainedDetailsSchema.parse(
@@ -239,18 +229,11 @@ cliTest(
await writeFile(capture, protobufHar(body, "application/x-protobuf"));
await writeFile(descriptor, definition);
const output = await cli.run({
arguments: [
"inspect-web-network-capture",
arguments: protobufHarRecordCliArguments(
capture,
"har",
"--record",
"0",
"--protobuf-schema",
descriptor,
"--protobuf-message",
"capture.Message",
"--json",
],
),
});
expect(output.exitCode, output.stdout + output.stderr).toBe(0);
const evidence = parseEvidence(output.json);
@@ -297,17 +280,10 @@ cliTest(
]);
expect(decoded?.fields).toHaveLength(5);
const call = await cli.sharedMcpCall!();
const response = await call("inspect_web_network_capture", {
capture_path: capture,
format: "har",
record_ordinals: [0],
protobuf: {
schema: {
descriptor_set_path: descriptor,
message_type: "capture.Message",
},
},
});
const response = await call(
"inspect_web_network_capture",
protobufHarRecordMcpArguments(capture, descriptor, "capture.Message"),
);
expect(response.isError, JSON.stringify(response)).not.toBe(true);
expect(parseEvidence(response.structuredContent).evidence_id).toBe(
evidence.evidence_id,
@@ -12,7 +12,11 @@ import { expect } from "vitest";
import { parseEvidence } from "../../../src/domain/evidence.js";
import { webNetworkCaptureSchema } from "../../../src/domain/webNetworkCapture.js";
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
import { protobufHar } from "../../fixtures/protobufCapture.js";
import {
protobufHar,
protobufHarRecordCliArguments,
protobufHarRecordMcpArguments,
} from "../../fixtures/protobufCapture.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
@@ -120,33 +124,19 @@ cliTest(
// Keep CLI refusal parity on one collision and both orders in MCP.
if (scope === "same-file" && !reverse) {
const output = await cli.run({
arguments: [
"inspect-web-network-capture",
arguments: protobufHarRecordCliArguments(
capture,
"har",
"--record",
"0",
"--protobuf-schema",
descriptor,
"--protobuf-message",
messageType,
"--json",
],
),
});
expect(output.exitCode).toBe(1);
expect(output.json).toMatchObject(expected);
}
const response = await call("inspect_web_network_capture", {
capture_path: capture,
format: "har",
record_ordinals: [0],
protobuf: {
schema: {
descriptor_set_path: descriptor,
message_type: messageType,
},
},
});
const response = await call(
"inspect_web_network_capture",
protobufHarRecordMcpArguments(capture, descriptor, messageType),
);
expect(
parseMcpToolError(response).error,
`${scope}-${reverse}`,
@@ -200,17 +190,10 @@ cliTest(
["Outer.Message", "nested_value"],
["capture.Message", "package_value"],
] as const) {
const response = await call("inspect_web_network_capture", {
capture_path: capture,
format: "har",
record_ordinals: [0],
protobuf: {
schema: {
descriptor_set_path: descriptor,
message_type: messageType,
},
},
});
const response = await call(
"inspect_web_network_capture",
protobufHarRecordMcpArguments(capture, descriptor, messageType),
);
expect(response.isError, JSON.stringify(response)).not.toBe(true);
const report = webNetworkCaptureSchema.parse(
parseEvidence(response.structuredContent).normalized_result,
+33
View File
@@ -103,3 +103,36 @@ export const protobufHar = (
})),
},
});
export const protobufHarRecordCliArguments = (
capturePath: string,
descriptorSetPath: string,
messageType: string,
): string[] => [
"inspect-web-network-capture",
capturePath,
"har",
"--record",
"0",
"--protobuf-schema",
descriptorSetPath,
"--protobuf-message",
messageType,
"--json",
];
export const protobufHarRecordMcpArguments = (
capturePath: string,
descriptorSetPath: string,
messageType: string,
) => ({
capture_path: capturePath,
format: "har" as const,
record_ordinals: [0],
protobuf: {
schema: {
descriptor_set_path: descriptorSetPath,
message_type: messageType,
},
},
});