diff --git a/tests/acceptance/tools/protobufCapture.test.ts b/tests/acceptance/tools/protobufCapture.test.ts index c995e690a72..89aecb13d34 100644 --- a/tests/acceptance/tools/protobufCapture.test.ts +++ b/tests/acceptance/tools/protobufCapture.test.ts @@ -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", { diff --git a/tests/acceptance/tools/protobufDescriptorFiles.test.ts b/tests/acceptance/tools/protobufDescriptorFiles.test.ts index d1075aaf818..119ea38d98a 100644 --- a/tests/acceptance/tools/protobufDescriptorFiles.test.ts +++ b/tests/acceptance/tools/protobufDescriptorFiles.test.ts @@ -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, diff --git a/tests/acceptance/tools/protobufDescriptorIdentity.test.ts b/tests/acceptance/tools/protobufDescriptorIdentity.test.ts index 06ad2be1ebb..10c06e891dd 100644 --- a/tests/acceptance/tools/protobufDescriptorIdentity.test.ts +++ b/tests/acceptance/tools/protobufDescriptorIdentity.test.ts @@ -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, diff --git a/tests/acceptance/tools/protobufRegistryIdentity.test.ts b/tests/acceptance/tools/protobufRegistryIdentity.test.ts index c967d8b674c..233435aa6ae 100644 --- a/tests/acceptance/tools/protobufRegistryIdentity.test.ts +++ b/tests/acceptance/tools/protobufRegistryIdentity.test.ts @@ -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, diff --git a/tests/fixtures/protobufCapture.ts b/tests/fixtures/protobufCapture.ts index 375c872e2d4..0a3cb54b8e1 100644 --- a/tests/fixtures/protobufCapture.ts +++ b/tests/fixtures/protobufCapture.ts @@ -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, + }, + }, +});