From 858ff73880f25fb55b1d6c077f1487a4aea5ff8d Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:53:53 +0800 Subject: [PATCH] perf(tests): give MCP test clients the shared lazy schema validation (#10960) * perf(tests): give MCP test clients the shared lazy schema validation The MCP SDK client compiles every listed tool's output schema on its first tool call. With the SDK's default Ajv options, REA's catalog costs gigabytes of allocation per client (inspect_analysis_view alone: 1.7 s and ~500 MiB retained), so native MCP files peaked at 1-2 GiB per worker. tests/fixtures/mcpSchemaValidation already owns lazy, reference-preserving validation. Route the native MCP, process-boundary and shared harness clients through it, share compiled validators across clients in a worker (bounded LRU keyed by schema text), and add a counted architecture guard so default-validation test clients cannot spread; the remaining copies are the baseline. * fix(guards): read call arguments past parentheses inside string literals * perf(tests): give MCP boundary test clients the shared schema validation (#11022) * perf(tests): give MCP boundary test clients the shared schema validation * perf(tests): give the remaining MCP test clients the shared schema validation (#11025) * fix(guards): read an MCP client's validator option from parsed code The default-validation counter searched each new Client(...) call's text for jsonSchemaValidator, so an inline comment, a string literal or a client name naming the option hid a default client. Parse the source with @babel/parser and count NewExpressions of Client whose object-literal arguments have no jsonSchemaValidator property; a source that does not parse counts every textual call. The guard reads raw test sources, and the generated-child-script allowlist entry, which no longer counts as a call, is removed. * fix(guards): read an MCP client's options only from a whole object-literal argument The default-validation counter skipped files without the text 'new Client(', so a comment between the tokens hid a client, and it took any depth-two key as an option, so 'enabled ? { jsonSchemaValidator } : {}' passed while its false branch uses the SDK default. The skip now only requires the name Client, and the validator counts only when it is a key of an object literal that is a whole argument; anything else counts as the default. --- docs/development/testing.md | 13 +- scripts/verify/architecture-guards.mjs | 24 ++ scripts/verify/keyed-first-match.d.mts | 2 + scripts/verify/keyed-first-match.mjs | 22 +- scripts/verify/mcp-client-validation.d.mts | 2 + scripts/verify/mcp-client-validation.mjs | 109 ++++++ .../applicationWorkflowCli.test.ts | 12 +- .../exportedFunctionBindingsCli.test.ts | 12 +- .../interfaceBuilderClassNameIdentity.test.ts | 6 +- .../applications/nibFieldIdentity.test.ts | 6 +- .../artifactExtractionSelection.test.ts | 12 +- ...rowserScenarioReferenceDiagnostics.test.ts | 12 +- .../byteEntropyWindowsIdentity.test.ts | 6 +- .../acceptance/darwinAvailabilityMcp.test.ts | 6 +- .../environmentSparseClockWritesMcp.test.ts | 6 +- .../acceptance/harmonyArtifactJourney.test.ts | 6 +- .../acceptance/managedMemberRecovery.test.ts | 6 +- tests/acceptance/nonBinaryComposition.test.ts | 6 +- .../providers/hopperStartupRecovery.test.ts | 16 +- tests/acceptance/setup/dshClientSetup.test.ts | 6 +- .../setup/launcherAliasesCli.test.ts | 6 +- tests/acceptance/setup/piClientSetup.test.ts | 6 +- .../wasmInterfaceComparison.test.ts | 6 +- tests/acceptance/webModuleCli.test.ts | 6 +- tests/acceptance/webSourceLocationCli.test.ts | 12 +- .../boundary/cli/bundleComparisonCli.test.ts | 12 +- tests/boundary/cli/cliStartupImports.test.ts | 6 +- .../packageRunnerBoundInstallation.test.ts | 12 +- .../ghidraLanguageCatalogRecovery.test.ts | 6 +- .../mcpClientValidationGuard.test.ts | 44 +++ .../filesystem/windowsNpxRegistration.test.ts | 12 +- .../firmware/firmwarePublicationPaths.test.ts | 6 +- .../mcp/absoluteLocalPathSchema.test.ts | 6 +- .../mcp/absoluteLocalPathTools.test.ts | 6 +- .../boundary/mcp/adbDeviceProperties.test.ts | 6 +- tests/boundary/mcp/adbInputFileMcp.test.ts | 6 +- tests/boundary/mcp/adbMcp.test.ts | 10 +- .../mcp/adbOutputDirectoryMcp.test.ts | 6 +- tests/boundary/mcp/adbStartMcp.test.ts | 19 +- .../mcp/addressContextBookmarks.test.ts | 11 +- .../mcp/addressContextCapacity.test.ts | 6 +- .../mcp/addressContextInputErrors.test.ts | 17 +- tests/boundary/mcp/advertisedDialect.test.ts | 6 +- .../mcp/advertisedPatternsVMode.test.ts | 6 +- .../boundary/mcp/analysisSettingsMcp.test.ts | 6 +- .../mcp/analysisSummaryDetailMcp.test.ts | 6 +- .../mcp/analyzeFunctionDetail.test.ts | 6 +- .../mcp/androidLateCompletionMcp.test.ts | 6 +- .../mcp/androidPackageSummaryMcp.test.ts | 6 +- tests/boundary/mcp/apktoolMcp.test.ts | 6 +- .../artifactComparisonSourceSchema.test.ts | 6 +- .../mcp/asarListingAdmissionMcp.test.ts | 6 +- .../mcp/asarUnpackedExtractionMcp.test.ts | 6 +- .../mcp/batchDecompileViewsMcp.test.ts | 11 +- .../mcp/batchSourcePublicationCleanup.test.ts | 6 +- .../batchSourcePublicationRecovery.test.ts | 6 +- .../boundary/mcp/binaryDiagnosticsMcp.test.ts | 37 +- .../mcp/browserComparisonInput.test.ts | 6 +- tests/boundary/mcp/bunStandaloneMcp.test.ts | 6 +- .../mcp/bundleComparisonCancellation.test.ts | 12 +- .../boundary/mcp/bundleComparisonMcp.test.ts | 6 +- .../mcp/callGraphCleanupIncomplete.test.ts | 6 +- .../mcp/callPathSearchExtentMcp.test.ts | 22 +- .../mcp/capabilityRemediationMcp.test.ts | 5 +- tests/boundary/mcp/clientCapabilities.test.ts | 8 +- .../mcp/commandObservationViews.test.ts | 6 +- .../mcp/completionInventoryAliasMcp.test.ts | 17 +- .../composedWorkflowEvidenceLinksMcp.test.ts | 12 +- .../mcp/contextEvidenceOverflow.test.ts | 17 +- .../mcp/cutterCancellationMcp.test.ts | 27 +- tests/boundary/mcp/cutterMcp.test.ts | 6 +- ...buggerExternalMutationLifecycleMcp.test.ts | 6 +- tests/boundary/mcp/denoStandaloneMcp.test.ts | 6 +- tests/boundary/mcp/dylibResolutionMcp.test.ts | 6 +- tests/boundary/mcp/electronMcp.test.ts | 52 ++- ....01-lists-the-complete-target-open.test.ts | 6 +- tests/boundary/mcp/enhancedToolsHarness.ts | 6 +- .../boundary/mcp/environmentBundleMcp.test.ts | 6 +- .../boundary/mcp/environmentServeMcp.test.ts | 6 +- .../mcp/environmentServeWritesMcp.test.ts | 54 ++- .../boundary/mcp/evidenceBundleInline.test.ts | 11 +- .../mcp/evidenceExportCancellation.test.ts | 12 +- .../mcp/evidenceImportCancellation.test.ts | 34 +- .../mcp/evidenceImportLifecycle.test.ts | 17 +- .../mcp/evidenceRetentionRecovery.test.ts | 22 +- .../mcp/exclusiveBoundIssuesMcp.test.ts | 6 +- .../boundary/mcp/featureTraceViewsMcp.test.ts | 5 +- tests/boundary/mcp/firmwareMcp.test.ts | 6 +- .../mcp/fixedEvidenceConsumersMcp.test.ts | 6 +- tests/boundary/mcp/fridaLifecycleMcp.test.ts | 17 +- ...unctionComparisonReferenceFactsMcp.test.ts | 6 +- tests/boundary/mcp/gdbCancellationMcp.test.ts | 42 ++- .../boundary/mcp/gdbCloseDisposition.test.ts | 6 +- .../boundary/mcp/generatedToolCatalog.test.ts | 6 +- tests/boundary/mcp/ghidraInventoryMcp.test.ts | 6 +- .../mcp/ghidraProfileRefusalMcp.test.ts | 6 +- tests/boundary/mcp/ghidraReopen.test.ts | 6 +- .../mcp/ghidraStartupCancellationMcp.test.ts | 6 +- tests/boundary/mcp/guidanceMcp.test.ts | 6 +- .../mcp/hostRestrictedAvailabilityMcp.test.ts | 12 +- .../mcp/investigationAnalysisMcp.test.ts | 11 +- ...investigationEvidenceReferencesMcp.test.ts | 12 +- .../mcp/javascriptRecoveryMcp.test.ts | 11 +- .../javascriptRuntimeObservationMcp.test.ts | 11 +- tests/boundary/mcp/kunaCloseRetryMcp.test.ts | 6 +- tests/boundary/mcp/largeToolResult.test.ts | 6 +- .../lateAbortApplicationEvidenceMcp.test.ts | 16 +- .../boundary/mcp/mcpSchemaValidation.test.ts | 53 ++- .../mcp/nativeCallObservationMcp.test.ts | 17 +- .../mcp/nativeDispatchAvailability.test.ts | 6 +- .../mcp/nativeDispatchBoundTarget.test.ts | 6 +- .../boundary/mcp/nativeInputContracts.test.ts | 6 +- .../nativeInstructionReferencesView.test.ts | 11 +- .../mcp/nativeInventoryViewsMcp.test.ts | 17 +- .../mcp/nativeLoadImageViewsMcp.test.ts | 6 +- .../mcp/nativeObservationViewsMcp.test.ts | 11 +- .../nativeSignatureTargetBindingMcp.test.ts | 11 +- tests/boundary/mcp/nativeUiFactsMcp.test.ts | 6 +- .../mcp/nativeUiFinalizationMcp.test.ts | 6 +- .../mcp/nativeUiPartialCallRoutesMcp.test.ts | 6 +- .../nativeValueTraceCleanupIncomplete.test.ts | 6 +- .../mcp/nativeValueTraceCompleteness.test.ts | 6 +- .../mcp/nativeViewPredicateMcp.test.ts | 5 +- .../boundary/mcp/navigationContextMcp.test.ts | 6 +- ...observationPartialEvidenceDelivery.test.ts | 12 +- tests/boundary/mcp/officialArguments.test.ts | 6 +- tests/boundary/mcp/officialTools.test.ts | 6 +- .../boundary/mcp/outputSchemaProfile.test.ts | 26 +- .../outputSchemaSemanticConstraints.test.ts | 6 +- .../mcp/oversizedErrorDeliveryMcp.test.ts | 26 +- tests/boundary/mcp/pcapMcp.test.ts | 6 +- .../boundary/mcp/pcapParentIssuePath.test.ts | 6 +- .../mcp/pcapWorkspaceAllocation.test.ts | 6 +- .../mcp/processCleanupRetryMcp.test.ts | 6 +- .../processComparisonDiagnosticsMcp.test.ts | 6 +- .../mcp/processEvidenceIdentityMcp.test.ts | 12 +- .../mcp/processTraceAdaptersParity.test.ts | 6 +- tests/boundary/mcp/progressMcp.test.ts | 13 +- tests/boundary/mcp/promptMcp.test.ts | 27 +- .../boundary/mcp/providerSelectionMcp.test.ts | 344 ++++++++++-------- .../mcp/pseudocodeDeliveryMcp.test.ts | 6 +- tests/boundary/mcp/rawBinaryMcp.test.ts | 6 +- .../mcp/reconstructionCoverageMcp.test.ts | 6 +- .../reconstructionObligationLedgerMcp.test.ts | 16 +- tests/boundary/mcp/recordedCrashMcp.test.ts | 6 +- ...eEngineeringProviderEnvironmentMcp.test.ts | 6 +- .../mcp/rizinDebuggerCancellationMcp.test.ts | 22 +- .../mcp/rizinOutputPreservation.test.ts | 6 +- tests/boundary/mcp/rizinPendingOutput.test.ts | 6 +- .../mcp/rizinStoppedSessionMcp.test.ts | 6 +- .../mcp/sdkInputIssueAttribution.test.ts | 22 +- tests/boundary/mcp/serverIdentity.test.ts | 12 +- tests/boundary/mcp/serverLifecycleMcp.test.ts | 33 +- tests/boundary/mcp/serverUnknownsMcp.test.ts | 41 ++- tests/boundary/mcp/serverWorkflowMcp.test.ts | 23 +- .../mcp/sessionEvidenceRecovery.test.ts | 12 +- .../mcp/sessionEvidenceReuseMcp.test.ts | 11 +- tests/boundary/mcp/sessionMcp.test.ts | 27 +- tests/boundary/mcp/sessionMcpHarness.ts | 6 +- .../mcp/sourcePublicationContext.test.ts | 21 +- .../mcp/sourcePublicationRecovery.test.ts | 32 +- tests/boundary/mcp/streamableHttpMcp.test.ts | 6 +- .../mcp/targetContentFramingMcp.test.ts | 22 +- .../mcp/toolInputCapacityHttp.test.ts | 6 +- .../mcp/toolInputCapacityStdio.test.ts | 6 +- tests/boundary/mcp/toolResult.test.ts | 23 +- tests/boundary/mcp/toolSchemaValidity.test.ts | 32 +- tests/boundary/mcp/wasmArtifactMcp.test.ts | 15 +- .../mcp/webBundleContainmentMcp.test.ts | 12 +- tests/boundary/mcp/webModuleTraceMcp.test.ts | 11 +- .../boundary/mcp/webNetworkCaptureMcp.test.ts | 12 +- tests/boundary/mcp/webRuntimeMcp.test.ts | 5 +- .../boundary/mcp/webSourceLocationMcp.test.ts | 6 +- .../mcp/workflowSnapshotReplayMcp.test.ts | 6 +- .../process/androidMappingMcp.test.ts | 18 +- .../androidSearchEvidenceBudget.test.ts | 12 +- tests/boundary/process/jadxStartup.test.ts | 12 +- ...processCaptureCancellationAdapters.test.ts | 12 +- .../processDescendantPidAdapters.test.ts | 12 +- .../process/processSessionMcp.test.ts | 32 +- .../process/processTruncationAdapters.test.ts | 6 +- .../boundary/process/verifierMcpOwner.test.ts | 6 +- .../RizinDebugSessionInferiorStdin.test.ts | 6 +- .../providers/jeb/failureEnvelopes.test.ts | 6 +- tests/fixtures/buildComputerMcp.ts | 6 +- tests/fixtures/mcpSchemaValidation.ts | 79 ++-- tests/fixtures/promptOccurrenceCompletion.ts | 12 +- tests/process-global/adbStartMcp.test.ts | 6 +- .../bundleComparisonFailures.test.ts | 6 +- .../derivedOperationFailures.test.ts | 12 +- .../javascriptAnalysisCancellation.test.ts | 12 +- .../javascriptFilesystemErrors.test.ts | 6 +- .../managedBundleReadGuards.test.ts | 12 +- .../mcpDeliveryEnvironment.test.ts | 6 +- .../processCaptureFilenameBytes.test.ts | 6 +- .../processCaptureServerEnvironment.test.ts | 6 +- .../processSnapshotCleanupMcp.test.ts | 6 +- .../sourceToBundleReferenceGuards.test.ts | 6 +- .../windowsNativeControlCapability.test.ts | 6 +- 199 files changed, 2071 insertions(+), 683 deletions(-) create mode 100644 scripts/verify/mcp-client-validation.d.mts create mode 100644 scripts/verify/mcp-client-validation.mjs create mode 100644 tests/boundary/filesystem/mcpClientValidationGuard.test.ts diff --git a/docs/development/testing.md b/docs/development/testing.md index 308012aba0..5876c82855 100644 --- a/docs/development/testing.md +++ b/docs/development/testing.md @@ -799,11 +799,14 @@ should assert canonical failure categories and provider-call controls where rejection before provider work matters. Do not make today's omission of a constraint a compact-profile invariant. -When a file repeatedly validates the same MCP schemas, use -`createMcpSchemaValidation` for file-owned preparation and clear it in -`afterAll`. Its content keys include the complete schema, and the SDK provider -keeps dialect and format validation. Keep sessions and connections scoped to -each test; share immutable schema preparation through the fixture's validator +Give every MCP SDK test client the validator from +`createMcpSchemaValidation` (or use `mcpTest`); the architecture guards count +clients that keep the SDK default. Compiled validators are shared across the +worker in a bounded cache keyed by the complete schema, and the SDK provider +keeps dialect and format validation. A fixture created inline for one client +is released with that client. When a file holds one fixture for several +clients, clear it in `afterAll`. Keep sessions and connections scoped to each +test; share immutable schema preparation through the fixture's validator dependency. Artifact verification uses `artifactMcpCall` for both lifecycle and analysis diff --git a/scripts/verify/architecture-guards.mjs b/scripts/verify/architecture-guards.mjs index 9aac2630dd..cbbf5ce810 100644 --- a/scripts/verify/architecture-guards.mjs +++ b/scripts/verify/architecture-guards.mjs @@ -12,6 +12,7 @@ import { countKeyedFirstMatches } from "./keyed-first-match.mjs"; import { incurZodImportCount } from "./incur-import-guard.mjs"; import { budgetArithmeticCount } from "./budget-arithmetic-guard.mjs"; import { localLimitErrorClassCount } from "./limit-class-guard.mjs"; +import { countDefaultValidationClients } from "./mcp-client-validation.mjs"; import { isComparisonOrCountFile, optionalFactDefaultCount, @@ -990,6 +991,29 @@ checkCounted( [], ); +// The MCP SDK client compiles every listed tool's output schema on its first +// tool call. With the default Ajv options, REA's catalog costs gigabytes of +// allocation per client, so test clients take the lazy, reference-preserving +// validation from tests/fixtures/mcpSchemaValidation (directly, or through +// tests/support/mcp/mcpFixture). Tests of the SDK default itself stay listed. +// The counter parses each source, so comments need no stripping here. A +// client built inside a generated child script is string data, not a call, so +// it is not read (such scripts run over compiled dist/ modules, which cannot +// load the TypeScript fixture). +const mcpClientTestFiles = testFiles.filter((file) => + file.path.startsWith("tests/"), +); +checkCounted( + "MCP SDK client without shared schema validation in tests (pass createMcpSchemaValidation from tests/fixtures/mcpSchemaValidation or use mcpTest)", + "test-mcp-client-default-validation", + mcpClientTestFiles, + countDefaultValidationClients, + [ + // Checks the SDK default validator itself across catalog refreshes. + "tests/boundary/mcp/outputValidatorReuse.test.ts", + ], +); + for (const key of baselineTexts.keys()) if (!checkedBaselineKeys.has(key)) failures.push( diff --git a/scripts/verify/keyed-first-match.d.mts b/scripts/verify/keyed-first-match.d.mts index 3ed4584836..43e74301e7 100644 --- a/scripts/verify/keyed-first-match.d.mts +++ b/scripts/verify/keyed-first-match.d.mts @@ -1,2 +1,4 @@ /** Number of first-match lookups by key field in `content`. */ export function countKeyedFirstMatches(content: string): number; +/** Index just past the parenthesis that closes the one at `open`, or -1. */ +export function closingParen(content: string, open: number): number; diff --git a/scripts/verify/keyed-first-match.mjs b/scripts/verify/keyed-first-match.mjs index eddc2b60b9..6f11bc13c5 100644 --- a/scripts/verify/keyed-first-match.mjs +++ b/scripts/verify/keyed-first-match.mjs @@ -22,12 +22,28 @@ const FILTER_PATTERNS = [ new RegExp(FILTER + DESTRUCTURED, "gu"), ]; -/** Index just past the parenthesis that closes the one at `open`, or -1. */ -const closingParen = (content, open) => { +/** Index of the quote that closes the literal opening at `start`, or -1. */ +const literalEnd = (content, start) => { + const quote = content[start]; + for (let index = start + 1; index < content.length; index += 1) { + if (content[index] === "\\") index += 1; + else if (content[index] === quote) return index; + } + return -1; +}; + +/** + * Index just past the parenthesis that closes the one at `open`, or -1. + * Parentheses inside string and template literals do not count. + */ +export const closingParen = (content, open) => { let depth = 0; for (let index = open; index < content.length; index += 1) { const character = content[index]; - if (character === "(") depth += 1; + if (character === '"' || character === "'" || character === "`") { + index = literalEnd(content, index); + if (index < 0) return -1; + } else if (character === "(") depth += 1; else if (character === ")") { depth -= 1; if (depth === 0) return index + 1; diff --git a/scripts/verify/mcp-client-validation.d.mts b/scripts/verify/mcp-client-validation.d.mts new file mode 100644 index 0000000000..b809bbb9a4 --- /dev/null +++ b/scripts/verify/mcp-client-validation.d.mts @@ -0,0 +1,2 @@ +/** Number of `new Client(...)` calls without their own `jsonSchemaValidator`. */ +export function countDefaultValidationClients(content: string): number; diff --git a/scripts/verify/mcp-client-validation.mjs b/scripts/verify/mcp-client-validation.mjs new file mode 100644 index 0000000000..483e590cbd --- /dev/null +++ b/scripts/verify/mcp-client-validation.mjs @@ -0,0 +1,109 @@ +import { tokenize } from "./source-tokens.mjs"; + +// CI runs the architecture guards before installing dependencies, so this +// reads the call from scripts/verify/source-tokens.mjs tokens rather than a +// parser package. + +// Skips files that never name Client. Comments between `new`, `Client` and +// `(` are read from the tokens, so this test must not require them adjacent. +const MENTIONS_CLIENT = /\bClient\b/u; +const OPENERS = new Map([ + ["(", ")"], + ["[", "]"], + ["{", "}"], +]); + +/** The text of a quoted string token, or undefined for a template. */ +const quotedText = (source, token) => { + const quote = source[token.start]; + if (quote !== '"' && quote !== "'") return undefined; + let text = ""; + for (let at = token.start + 1; at < source.length; at += 1) { + if (source[at] === quote) return text; + if (source[at] === "\\") at += 1; + text += source[at]; + } + return undefined; +}; + +/** The property name a token spells when it is an object key position. */ +const keyName = (source, token) => + token.kind === "id" ? token.text : quotedText(source, token); + +const isPunct = (token, text) => token?.kind === "punct" && token.text === text; + +/** + * Whether the arguments of the call whose `(` is at `open` include an object + * literal that is itself a whole argument (it starts after the call's `(` or + * a top-level `,` and ends before `,` or `)`) and names `jsonSchemaValidator` + * as one of its own keys (`jsonSchemaValidator: …` or shorthand). An option + * object inside parentheses, a conditional or any other expression is not + * read, so the client counts as using the default. + */ +const callNamesValidator = (source, tokens, open) => { + const closers = []; + // Whether the open top-level object is a whole argument, and whether it + // has named the validator so far. + let argumentObject = false; + let named = false; + for (let index = open; index < tokens.length; index += 1) { + const token = tokens[index]; + if (token.kind === "punct" && OPENERS.has(token.text)) { + if (closers.length === 1 && token.text === "{") { + const before = tokens[index - 1]; + argumentObject = index - 1 === open || isPunct(before, ","); + named = false; + } + closers.push(OPENERS.get(token.text)); + continue; + } + if (token.kind === "punct" && token.text === closers.at(-1)) { + closers.pop(); + if (closers.length === 0) return false; + if ( + closers.length === 1 && + token.text === "}" && + argumentObject && + named && + (isPunct(tokens[index + 1], ",") || isPunct(tokens[index + 1], ")")) + ) + return true; + continue; + } + if (closers.length !== 2 || closers[1] !== "}" || !argumentObject) continue; + const before = tokens[index - 1]; + const after = tokens[index + 1]; + if ( + (isPunct(before, "{") || isPunct(before, ",")) && + (isPunct(after, ":") || isPunct(after, ",") || isPunct(after, "}")) && + keyName(source, token) === "jsonSchemaValidator" + ) + named = true; + } + return false; +}; + +/** + * Number of `new Client(...)` calls in `content` whose own arguments do not + * pass a `jsonSchemaValidator` property. The source is tokenized, so the + * option is read from the call's object-literal arguments: comments, string + * literals, client names and neighbouring calls do not stand in for it. + */ +export const countDefaultValidationClients = (content) => { + if (!MENTIONS_CLIENT.test(content)) return 0; + const { tokens } = tokenize(content); + let count = 0; + for (let index = 0; index + 2 < tokens.length; index += 1) { + if ( + tokens[index].kind === "id" && + tokens[index].text === "new" && + tokens[index + 1].kind === "id" && + tokens[index + 1].text === "Client" && + tokens[index + 2].kind === "punct" && + tokens[index + 2].text === "(" && + !callNamesValidator(content, tokens, index + 2) + ) + count += 1; + } + return count; +}; diff --git a/tests/acceptance/applications/applicationWorkflowCli.test.ts b/tests/acceptance/applications/applicationWorkflowCli.test.ts index 9c1b5bdc01..49188d0150 100644 --- a/tests/acceptance/applications/applicationWorkflowCli.test.ts +++ b/tests/acceptance/applications/applicationWorkflowCli.test.ts @@ -40,6 +40,7 @@ import { z } from "zod"; import { ELECTRON_IDENTITY_LIMITATION } from "../../../src/domain/javascript/javascriptElectronMemberWrites.js"; import { javaScriptSemanticTraceResultSchema } from "../../../src/domain/javascript/javascriptSemanticTraceSchemas.js"; import type { JavaScriptSemanticQueryInput } from "../../../src/domain/javascript/javascriptSemanticQuerySchemas.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const execute = promisify(execFile); let cliSession: CliCommandSession | undefined; @@ -58,10 +59,13 @@ const mcpTransport = new StdioClientTransport({ stderr: "pipe", }); mcpTransport.stderr?.on("data", () => undefined); -const mcpClient = new Client({ - name: "application-workflow-parity", - version: "1", -}); +const mcpClient = new Client( + { + name: "application-workflow-parity", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, +); let mcpConnection: Promise | undefined; const connectedMcpClient = async (): Promise => { await (mcpConnection ??= mcpClient.connect(mcpTransport)); diff --git a/tests/acceptance/applications/exportedFunctionBindingsCli.test.ts b/tests/acceptance/applications/exportedFunctionBindingsCli.test.ts index 65fdfeeffb..9c7b010972 100644 --- a/tests/acceptance/applications/exportedFunctionBindingsCli.test.ts +++ b/tests/acceptance/applications/exportedFunctionBindingsCli.test.ts @@ -19,6 +19,7 @@ import { createCliCommandSession, type CliCommandSession, } from "../../support/cli/cliCommandSession.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const execute = promisify(execFile); const requireFixture = createRequire(import.meta.url); @@ -1330,10 +1331,13 @@ const getMcpClient = async (): Promise => { stderr: "pipe", }); transport.stderr?.on("data", () => undefined); - const client = new Client({ - name: "exported-function-bindings", - version: "1", - }); + const client = new Client( + { + name: "exported-function-bindings", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); mcpConnection = { client, transport, diff --git a/tests/acceptance/applications/interfaceBuilderClassNameIdentity.test.ts b/tests/acceptance/applications/interfaceBuilderClassNameIdentity.test.ts index 76f7271eba..971e9a29ea 100644 --- a/tests/acceptance/applications/interfaceBuilderClassNameIdentity.test.ts +++ b/tests/acceptance/applications/interfaceBuilderClassNameIdentity.test.ts @@ -12,6 +12,7 @@ import { parseEvidence } from "../../../src/domain/evidence.js"; import { thinMach } from "../../../src/domain/binaryTarget.fixture.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { cliTest } from "../../support/cli/cliFixture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const appWithClassNameArchive = async (): Promise => { const app = join( @@ -80,7 +81,10 @@ cliTest( }, stderr: "pipe", }); - const client = new Client({ name: "ib-class-name-identity", version: "1" }); + const client = new Client( + { name: "ib-class-name-identity", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { await client.connect(transport); const opened = await client.callTool({ diff --git a/tests/acceptance/applications/nibFieldIdentity.test.ts b/tests/acceptance/applications/nibFieldIdentity.test.ts index b752c65f17..0bf19bfe7d 100644 --- a/tests/acceptance/applications/nibFieldIdentity.test.ts +++ b/tests/acceptance/applications/nibFieldIdentity.test.ts @@ -11,6 +11,7 @@ import { interfaceBuilderAnalysisSchema } from "../../../src/domain/apple/interf import { thinMach } from "../../../src/domain/binaryTarget.fixture.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { cliTest } from "../../support/cli/cliFixture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const createIdentityArchive = () => encodeNibArchiveFixture({ @@ -104,7 +105,10 @@ cliTest( }, stderr: "pipe", }); - const client = new Client({ name: "nib-field-identity", version: "1" }); + const client = new Client( + { name: "nib-field-identity", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { await client.connect(transport); const opened = await client.callTool({ diff --git a/tests/acceptance/artifactExtractionSelection.test.ts b/tests/acceptance/artifactExtractionSelection.test.ts index 365e3c3c76..672940c3a9 100644 --- a/tests/acceptance/artifactExtractionSelection.test.ts +++ b/tests/acceptance/artifactExtractionSelection.test.ts @@ -20,6 +20,7 @@ import { artifactInspectionResultSchema } from "../../src/domain/artifactInspect import { parseEvidence } from "../../src/domain/evidence.js"; import { advertisedMcpToolSchemas } from "../fixtures/advertisedMcpTool.js"; import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; const execute = promisify(execFile); const cli = fileURLToPath(new URL("../../scripts/rea.mjs", import.meta.url)); @@ -128,10 +129,13 @@ it("keeps CLI/MCP selection identity, invalid-input refusals and committed outpu }, stderr: "pipe", }); - const client = new Client({ - name: "extraction-selection-test", - version: "1", - }); + const client = new Client( + { + name: "extraction-selection-test", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const output = join(data.root, "mcp-output"); await withVerifierCleanup(async () => { await client.connect(transport); diff --git a/tests/acceptance/browserScenarioReferenceDiagnostics.test.ts b/tests/acceptance/browserScenarioReferenceDiagnostics.test.ts index 8b97ba0cbf..859dc347ad 100644 --- a/tests/acceptance/browserScenarioReferenceDiagnostics.test.ts +++ b/tests/acceptance/browserScenarioReferenceDiagnostics.test.ts @@ -7,6 +7,7 @@ import { browserScenarioReferences } from "../fixtures/browserScenarioReferences import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; import { parseMcpToolError } from "../fixtures/mcpToolError.js"; import { cliTest } from "../support/cli/cliFixture.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; cliTest.for([ ["CLI", "query"], @@ -51,10 +52,13 @@ cliTest.for([ expect(result.json).toMatchObject(expected); return; } - const client = new Client({ - name: "scenario-reference-diagnostics", - version: "1", - }); + const client = new Client( + { + name: "scenario-reference-diagnostics", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const transport = new StdioClientTransport({ command: process.execPath, args: [resolve("scripts/rea.mjs"), "mcp"], diff --git a/tests/acceptance/byteEntropyWindowsIdentity.test.ts b/tests/acceptance/byteEntropyWindowsIdentity.test.ts index c0f979a8d3..26d7024515 100644 --- a/tests/acceptance/byteEntropyWindowsIdentity.test.ts +++ b/tests/acceptance/byteEntropyWindowsIdentity.test.ts @@ -8,6 +8,7 @@ import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; import { cliTest } from "../support/cli/cliFixture.js"; import { ByteEntropyService } from "../../src/application/binaryDiagnostics/ByteEntropyService.js"; import { parseEvidence } from "../../src/domain/evidence.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; describe.skipIf(process.platform !== "win32")( "Windows selected-file spelling", @@ -25,7 +26,10 @@ describe.skipIf(process.platform !== "win32")( throw new Error("No analysis provider should start"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "entropy-case", version: "1" }); + const client = new Client( + { name: "entropy-case", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); diff --git a/tests/acceptance/darwinAvailabilityMcp.test.ts b/tests/acceptance/darwinAvailabilityMcp.test.ts index 7dc4880295..a1ffea9244 100644 --- a/tests/acceptance/darwinAvailabilityMcp.test.ts +++ b/tests/acceptance/darwinAvailabilityMcp.test.ts @@ -7,6 +7,7 @@ import { z } from "zod"; import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; import { parseMcpToolError } from "../fixtures/mcpToolError.js"; import { cliTest } from "../support/cli/cliFixture.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; cliTest.skipIf(process.platform !== "darwin")( "target-free MCP discovery survives an unavailable macOS compiler", @@ -31,7 +32,10 @@ cliTest.skipIf(process.platform !== "darwin")( stderr: "pipe", }); transport.stderr?.on("data", () => undefined); - const client = new Client({ name: "darwin-availability", version: "1" }); + const client = new Client( + { name: "darwin-availability", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { await client.connect(transport); const result = await client.callTool({ diff --git a/tests/acceptance/environmentSparseClockWritesMcp.test.ts b/tests/acceptance/environmentSparseClockWritesMcp.test.ts index f24a5e5330..e00b179335 100644 --- a/tests/acceptance/environmentSparseClockWritesMcp.test.ts +++ b/tests/acceptance/environmentSparseClockWritesMcp.test.ts @@ -16,6 +16,7 @@ import { import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; import { startListeningProcess } from "../support/mcp/streamableHttpProcess.js"; import { processTest } from "../support/process/processFixture.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; const rowsWithClocks = ( mode: @@ -133,7 +134,10 @@ for (const [mode, appended] of [ "--port", "0", ]); - const client = new Client({ name: "sparse-clock-writes", version: "1" }); + const client = new Client( + { name: "sparse-clock-writes", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { await client.connect(new StreamableHTTPClientTransport(started.url)); await checkCreatedItems(client, appended); diff --git a/tests/acceptance/harmonyArtifactJourney.test.ts b/tests/acceptance/harmonyArtifactJourney.test.ts index 571e2cd27c..9f4563e4c4 100644 --- a/tests/acceptance/harmonyArtifactJourney.test.ts +++ b/tests/acceptance/harmonyArtifactJourney.test.ts @@ -16,6 +16,7 @@ import { type HarmonyApplicationProjectionResult, } from "../../src/domain/harmony/harmonyApplication.js"; import { workspaceCliTest as test } from "../support/cli/workspaceCliFixture.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; const expectProjectionParity = ( graph: HarmonyApplicationProjectionResult, @@ -121,7 +122,10 @@ test("preserves Harmony archive formats through the public CLI/MCP lifecycle", a NODE_OPTIONS: "--max-old-space-size=512", REA_LOG_LEVEL: "silent", }; - const client = new Client({ name: "rea-harmony-acceptance", version: "1" }); + const client = new Client( + { name: "rea-harmony-acceptance", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const transport = new StdioClientTransport({ command: process.execPath, args: [resolve("scripts/rea.mjs"), "mcp"], diff --git a/tests/acceptance/managedMemberRecovery.test.ts b/tests/acceptance/managedMemberRecovery.test.ts index 97a536747d..df16029dd5 100644 --- a/tests/acceptance/managedMemberRecovery.test.ts +++ b/tests/acceptance/managedMemberRecovery.test.ts @@ -19,6 +19,7 @@ import { import { buildManagedMemberCapacityFixture } from "../fixtures/managedMemberCapacity.js"; import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; import { cliTest } from "../support/cli/cliFixture.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; const createTransport = () => new StdioClientTransport({ @@ -49,7 +50,10 @@ cliTest( const sha256 = createHash("sha256").update(bytes).digest("hex"); const transport = createTransport(); transport.stderr?.on("data", () => undefined); - const client = new Client({ name: "managed-type-recovery", version: "1" }); + const client = new Client( + { name: "managed-type-recovery", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { await client.connect(transport); const definition = (await client.listTools()).tools.find( diff --git a/tests/acceptance/nonBinaryComposition.test.ts b/tests/acceptance/nonBinaryComposition.test.ts index dbbbd22746..a50bc58338 100644 --- a/tests/acceptance/nonBinaryComposition.test.ts +++ b/tests/acceptance/nonBinaryComposition.test.ts @@ -12,6 +12,7 @@ import { createTestBinarySession } from "../fixtures/binarySession.js"; import { writeOrderedZip } from "../fixtures/artifactEntryOrder.js"; import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; import { cliTest } from "../support/cli/cliFixture.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; const connect = async (environment: NodeJS.ProcessEnv) => { const session = createTestBinarySession(() => { @@ -25,7 +26,10 @@ const connect = async (environment: NodeJS.ProcessEnv) => { javascriptRecovery: createJavaScriptRecoveryProvider(environment), }, ); - const client = new Client({ name: "composition-parity", version: "1" }); + const client = new Client( + { name: "composition-parity", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await closeVerifierResources([ () => client.close(), diff --git a/tests/acceptance/providers/hopperStartupRecovery.test.ts b/tests/acceptance/providers/hopperStartupRecovery.test.ts index 0c4337c3dd..a8251652e3 100644 --- a/tests/acceptance/providers/hopperStartupRecovery.test.ts +++ b/tests/acceptance/providers/hopperStartupRecovery.test.ts @@ -16,6 +16,7 @@ import { awaitAcknowledgement } from "../../fixtures/lifecycleAcknowledgement.js import { workspaceCliTest } from "../../support/cli/workspaceCliFixture.js"; import { acquireHopperTargetLease } from "../../../src/process/HopperLease.js"; import { waitFor } from "../../support/testWait.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const statusSchema = z.object({ result: z.object({ open: z.boolean() }) }); const test = workspaceCliTest.skipIf(process.platform !== "darwin"); @@ -92,7 +93,10 @@ test.for(["target", "loader"] as const)( stderr: "pipe", env: environment, }); - const mcp = new Client({ name: "hopper-literal-boundary", version: "1" }); + const mcp = new Client( + { name: "hopper-literal-boundary", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await closeVerifierResources([ () => mcp.close(), @@ -183,7 +187,10 @@ test("recovers a denied Hopper launch through the same stdio MCP session and CLI env: environment, stderr: "pipe", }); - const mcp = new Client({ name: "hopper-startup-recovery", version: "1" }); + const mcp = new Client( + { name: "hopper-startup-recovery", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); let stderr = ""; transport.stderr?.on("data", (chunk: Buffer) => { stderr += chunk.toString(); @@ -289,7 +296,10 @@ test.for(["handoff", "not-found"] as const)( REA_LOG_LEVEL: "silent", }, }); - const mcp = new Client({ name: "hopper-late-readiness", version: "1" }); + const mcp = new Client( + { name: "hopper-late-readiness", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const children: ChildProcess[] = []; let runtime: string | undefined; onTestFinished(async () => { diff --git a/tests/acceptance/setup/dshClientSetup.test.ts b/tests/acceptance/setup/dshClientSetup.test.ts index e8cd54e0fc..7d43e5b78e 100644 --- a/tests/acceptance/setup/dshClientSetup.test.ts +++ b/tests/acceptance/setup/dshClientSetup.test.ts @@ -8,6 +8,7 @@ import { parse } from "yaml"; import { z } from "zod"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { cliTest } from "../../support/cli/cliFixture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; cliTest.for(["setup", "uninstall"] as const)( "DSH CLI %s refuses a multi-document patch without losing caller content", @@ -314,7 +315,10 @@ async function verifyGeneratedLauncher( }, stderr: "pipe", }); - const client = new Client({ name: "dsh-setup-lifecycle", version: "1" }); + const client = new Client( + { name: "dsh-setup-lifecycle", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { await client.connect(transport); expect((await client.listTools()).tools.map(({ name }) => name)).toContain( diff --git a/tests/acceptance/setup/launcherAliasesCli.test.ts b/tests/acceptance/setup/launcherAliasesCli.test.ts index 8864b3923f..5a03aaecf9 100644 --- a/tests/acceptance/setup/launcherAliasesCli.test.ts +++ b/tests/acceptance/setup/launcherAliasesCli.test.ts @@ -9,6 +9,7 @@ import { z } from "zod"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { cliTest } from "../../support/cli/cliFixture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; cliTest.skipIf(process.platform === "win32")( "migrates an owned shebang registration and starts its generated MCP command without a runtime on PATH", @@ -108,7 +109,10 @@ cliTest.skipIf(process.platform === "win32")( env: { ...environment, ...registration.env }, stderr: "pipe", }); - const client = new Client({ name: "setup-interpreter", version: "1" }); + const client = new Client( + { name: "setup-interpreter", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { await client.connect(transport); expect( diff --git a/tests/acceptance/setup/piClientSetup.test.ts b/tests/acceptance/setup/piClientSetup.test.ts index 906c2a9560..cb9cb7a6a4 100644 --- a/tests/acceptance/setup/piClientSetup.test.ts +++ b/tests/acceptance/setup/piClientSetup.test.ts @@ -9,6 +9,7 @@ import { z } from "zod"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { cliTest } from "../../support/cli/cliFixture.js"; import { COMPACT_INPUT_SCHEMA_BUDGET_BYTES } from "../../../src/contracts/mcpSchemaPresentation.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; for (const [setting, profile] of [ ["REA_MCP_INPUT_SCHEMA_PROFILE", ""], @@ -166,7 +167,10 @@ cliTest( }, stderr: "pipe", }); - const client = new Client({ name: "setup-environment", version: "1" }); + const client = new Client( + { name: "setup-environment", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { await client.connect(transport); const { tools } = await client.listTools(); diff --git a/tests/acceptance/wasmInterfaceComparison.test.ts b/tests/acceptance/wasmInterfaceComparison.test.ts index 8ed4f7dfa9..571ab8f663 100644 --- a/tests/acceptance/wasmInterfaceComparison.test.ts +++ b/tests/acceptance/wasmInterfaceComparison.test.ts @@ -16,6 +16,7 @@ import { createServer } from "../../src/server/createServer.js"; import { wasmArtifactFixture } from "../fixtures/wasm/artifact.js"; import { cliTest } from "../support/cli/cliFixture.js"; import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; cliTest( "compares portable Evidence identically through CLI and retained MCP with schema/provenance", @@ -94,7 +95,10 @@ cliTest( }); const session = composeBinarySession(new AnalysisProviderRegistry([])); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "wasm-interface-parity", version: "1" }); + const client = new Client( + { name: "wasm-interface-parity", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); diff --git a/tests/acceptance/webModuleCli.test.ts b/tests/acceptance/webModuleCli.test.ts index 23d8a32900..c601376bcd 100644 --- a/tests/acceptance/webModuleCli.test.ts +++ b/tests/acceptance/webModuleCli.test.ts @@ -8,6 +8,7 @@ import { createTestBinarySession } from "../fixtures/binarySession.js"; import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; import { webModuleArtifactsFixture } from "../fixtures/webModuleTrace.js"; import { cliTest } from "../support/cli/cliFixture.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; cliTest( "accepts zero-based numeric source indices and returns the same engine-free CLI/MCP trace", @@ -77,7 +78,10 @@ cliTest( webModuleTrace: createWebModuleTraceService(environment), }, ); - const client = new Client({ name: "module-cli-parity", version: "1" }); + const client = new Client( + { name: "module-cli-parity", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/acceptance/webSourceLocationCli.test.ts b/tests/acceptance/webSourceLocationCli.test.ts index 06ecadb1df..75b1553b12 100644 --- a/tests/acceptance/webSourceLocationCli.test.ts +++ b/tests/acceptance/webSourceLocationCli.test.ts @@ -13,6 +13,7 @@ import { join } from "node:path"; import { webSourceLocationFixture } from "../fixtures/webSourceLocation.js"; import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; import { cliTest, type TestCli } from "../support/cli/cliFixture.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; const expectRetainedSourceMap = async ( path: string, @@ -287,10 +288,13 @@ cliTest( }, stderr: "pipe", }); - const client = new Client({ - name: "source-location-cli-parity", - version: "1", - }); + const client = new Client( + { + name: "source-location-cli-parity", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { try { await client.close(); diff --git a/tests/boundary/cli/bundleComparisonCli.test.ts b/tests/boundary/cli/bundleComparisonCli.test.ts index accfc78e6c..88c793e451 100644 --- a/tests/boundary/cli/bundleComparisonCli.test.ts +++ b/tests/boundary/cli/bundleComparisonCli.test.ts @@ -16,6 +16,7 @@ import { import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { cliTest } from "../../support/cli/cliFixture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; cliTest("rejects the removed compare-bundles command", async ({ cli }) => { const result = await cli.run({ @@ -189,10 +190,13 @@ cliTest( writeFile(rightPath, encoded), ]); - const client = new Client({ - name: "bundle-path-contract-test", - version: "1", - }); + const client = new Client( + { + name: "bundle-path-contract-test", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const transport = new StdioClientTransport({ command: process.execPath, args: [ diff --git a/tests/boundary/cli/cliStartupImports.test.ts b/tests/boundary/cli/cliStartupImports.test.ts index d34d46df16..911969d9b7 100644 --- a/tests/boundary/cli/cliStartupImports.test.ts +++ b/tests/boundary/cli/cliStartupImports.test.ts @@ -7,6 +7,7 @@ import { join } from "node:path"; import { describe, expect, it, onTestFinished } from "vitest"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; const MARKER = "REA_TEST_RESOLVED "; @@ -305,7 +306,10 @@ describe("MCP startup imports", () => { transport.stderr?.on("data", (chunk: Buffer) => { stderr += chunk.toString("utf8"); }); - const client = new Client({ name: "rea-startup-imports", version: "1" }); + const client = new Client( + { name: "rea-startup-imports", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { await client.connect(transport); const { tools } = await client.listTools(); diff --git a/tests/boundary/cli/packageRunnerBoundInstallation.test.ts b/tests/boundary/cli/packageRunnerBoundInstallation.test.ts index 28ec890050..ffe01fddb4 100644 --- a/tests/boundary/cli/packageRunnerBoundInstallation.test.ts +++ b/tests/boundary/cli/packageRunnerBoundInstallation.test.ts @@ -18,6 +18,7 @@ import { npmInvocation } from "../../../scripts/lib/npm-invocation.mjs"; import { PRODUCT_IDENTITY } from "../../../src/identity.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { cliTest } from "../../support/cli/cliFixture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const registrationSchema = z.object({ mcpServers: z.object({ @@ -131,10 +132,13 @@ cliTest.skipIf(process.platform === "win32")( env: clientEnvironment, stderr: "pipe", }); - const client = new Client({ - name: "real-npm-registration", - version: "1", - }); + const client = new Client( + { + name: "real-npm-registration", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { await client.connect(transport); expect(client.getServerVersion()?.version).toBe( diff --git a/tests/boundary/filesystem/ghidraLanguageCatalogRecovery.test.ts b/tests/boundary/filesystem/ghidraLanguageCatalogRecovery.test.ts index df95be4893..46e0182ccb 100644 --- a/tests/boundary/filesystem/ghidraLanguageCatalogRecovery.test.ts +++ b/tests/boundary/filesystem/ghidraLanguageCatalogRecovery.test.ts @@ -14,6 +14,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { nativeAotPeFixture } from "../../fixtures/nativeaotPe.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; // Fault only the installed x86 language definition; its real descriptor stays // open while close is refused, and closes for real once the fault clears. @@ -116,7 +117,10 @@ it("retries the retained catalog close on later MCP admission and reopens the sa logger: silentLogger, }, ); - const client = new Client({ name: "catalog-close-recovery", version: "1" }); + const client = new Client( + { name: "catalog-close-recovery", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const call = (name: "open_binary" | "close_binary") => diff --git a/tests/boundary/filesystem/mcpClientValidationGuard.test.ts b/tests/boundary/filesystem/mcpClientValidationGuard.test.ts new file mode 100644 index 0000000000..5460eeabc3 --- /dev/null +++ b/tests/boundary/filesystem/mcpClientValidationGuard.test.ts @@ -0,0 +1,44 @@ +import { expect, it } from "vitest"; + +import { countDefaultValidationClients } from "../../../scripts/verify/mcp-client-validation.mjs"; + +// Sources spell the constructor as `NEW(` so this file is not itself counted. +const source = (text: string) => text.replaceAll("NEW(", "new " + "Client("); + +it.each([ + ["NEW(info)", 1], + ["NEW(info, { jsonSchemaValidator: validation })", 0], + ["NEW(info, {\n capabilities: {},\n jsonSchemaValidator,\n})", 0], + // A later client's validator does not hide an earlier default client. + ["[NEW(a), NEW(b, { jsonSchemaValidator })]", 1], + ["const a = NEW(a);\nconst b = NEW(b, { jsonSchemaValidator });", 1], + ["NEW(a, { jsonSchemaValidator }); NEW(b)", 1], + ["NEW(make(a), options(b))", 1], + ["NEW(a); NEW(b);", 2], + // Parentheses inside literals do not end the call. + ['NEW({ name: "fixture )" }, { jsonSchemaValidator })', 0], + ["NEW({ name: 'a)' }, { jsonSchemaValidator })", 0], + ["NEW({ name: `a)` }, { jsonSchemaValidator })", 0], + ['NEW({ name: "\\")" }, { jsonSchemaValidator })', 0], + ['NEW({ name: "(" })', 1], + // Comments, string literals and names do not stand in for the option. + ["NEW(info, {\n capabilities: {}, // TODO: add jsonSchemaValidator\n})", 1], + ["NEW(info /* jsonSchemaValidator */)", 1], + ['NEW({ name: "jsonSchemaValidator-client" })', 1], + ["NEW(info, { note: `jsonSchemaValidator` })", 1], + ["NEW(jsonSchemaValidator)", 1], + ['NEW(info, { "jsonSchemaValidator": validation })', 0], + // A commented-out call is not a client. + ["// NEW(info)\nNEW(info, { jsonSchemaValidator })", 0], + // Comments between the tokens do not hide the call. + ["new /* fixture */ Client(info)", 1], + ["new Client /* fixture */ (info)", 1], + ["new /* a */ Client /* b */ (info, { jsonSchemaValidator })", 0], + // Only an object literal that is a whole argument counts as the options. + ["NEW(info, ({ jsonSchemaValidator }))", 1], + ["NEW(info, enabled ? { jsonSchemaValidator } : {})", 1], + ["NEW(info, { ...{ jsonSchemaValidator } })", 1], + ["NEW(info, { capabilities: { jsonSchemaValidator } })", 1], +] as const)("counts default-validation clients in %j", (text, expected) => { + expect(countDefaultValidationClients(source(text))).toBe(expected); +}); diff --git a/tests/boundary/filesystem/windowsNpxRegistration.test.ts b/tests/boundary/filesystem/windowsNpxRegistration.test.ts index ae67a8af3b..cb344b06d5 100644 --- a/tests/boundary/filesystem/windowsNpxRegistration.test.ts +++ b/tests/boundary/filesystem/windowsNpxRegistration.test.ts @@ -14,6 +14,7 @@ import { systemUninstallHost } from "../../../src/application/Uninstall.js"; import { PRODUCT_IDENTITY } from "../../../src/identity.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { supportedClientRegistrationProfile } from "../../../src/application/SupportedClients.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; // These writer tests model setup running from REA's actual entrypoint, not Vitest's worker. vi.mock( @@ -211,10 +212,13 @@ it.skipIf(process.platform !== "win32")( env: getDefaultEnvironment(), stderr: "pipe", }); - const client = new Client({ - name: "windows-direct-registration", - version: "1", - }); + const client = new Client( + { + name: "windows-direct-registration", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { await client.connect(transport); expect(client.getServerVersion()?.version).toBe( diff --git a/tests/boundary/firmware/firmwarePublicationPaths.test.ts b/tests/boundary/firmware/firmwarePublicationPaths.test.ts index 171eb00e26..3d5573f6c8 100644 --- a/tests/boundary/firmware/firmwarePublicationPaths.test.ts +++ b/tests/boundary/firmware/firmwarePublicationPaths.test.ts @@ -29,6 +29,7 @@ import { normalizeUnblobReport } from "../../../src/firmware/FirmwareReports.js" import { startFirmwareDeadline } from "../../../src/firmware/FirmwareDeadline.js"; import { SafeOutputTree } from "../../../src/resources/SafeOutputTree.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const validateAdvertisedFirmwareOutput = async ( result: Awaited>, @@ -42,7 +43,10 @@ const validateAdvertisedFirmwareOutput = async ( name: "schema", version: "1", }); - const client = new Client({ name: "schema-client", version: "1" }); + const client = new Client( + { name: "schema-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); server.registerTool( contract.name, { outputSchema: toolOutputSchemaWithMetadata(contract) }, diff --git a/tests/boundary/mcp/absoluteLocalPathSchema.test.ts b/tests/boundary/mcp/absoluteLocalPathSchema.test.ts index 8f29a3ea3f..da85c40d08 100644 --- a/tests/boundary/mcp/absoluteLocalPathSchema.test.ts +++ b/tests/boundary/mcp/absoluteLocalPathSchema.test.ts @@ -8,6 +8,7 @@ import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createServer } from "../../../src/server/createServer.js"; import { silentLogger } from "../../../src/logger.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; interface PathInputCase { readonly name: string; @@ -35,7 +36,10 @@ const createMcp = async (firmwareCalls: string[], profile?: "compact") => { }, }, ); - const client = new Client({ name: "absolute-path-schema", version: "1" }); + const client = new Client( + { name: "absolute-path-schema", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); diff --git a/tests/boundary/mcp/absoluteLocalPathTools.test.ts b/tests/boundary/mcp/absoluteLocalPathTools.test.ts index 350eb3b6b9..3532e6ae6a 100644 --- a/tests/boundary/mcp/absoluteLocalPathTools.test.ts +++ b/tests/boundary/mcp/absoluteLocalPathTools.test.ts @@ -12,6 +12,7 @@ import { PLAYWRIGHT_TRACE_TOOL_CONTRACTS } from "../../../src/contracts/playwrig import { PYTHON_PYC_TOOL_CONTRACTS } from "../../../src/contracts/python/pythonPycToolContracts.js"; import { RequestTrackingMcpServer } from "../../../src/server/RequestTrackingMcpServer.js"; import { toolRegistrationOptions } from "../../../src/server/toolRegistrationOptions.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const CONTRACTS = [ ...BINARY_DIAGNOSTICS_TOOL_CONTRACTS, @@ -92,7 +93,10 @@ it("rejects one relative path field at a time on tools/list", async () => { () => ({ content: [] }), ); } - const client = new Client({ name: "absolute-path-client", version: "1" }); + const client = new Client( + { name: "absolute-path-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const ajv = new Ajv2020({ strict: false, validateFormats: false }); diff --git a/tests/boundary/mcp/adbDeviceProperties.test.ts b/tests/boundary/mcp/adbDeviceProperties.test.ts index 3e31f1f0af..d20f82cb7b 100644 --- a/tests/boundary/mcp/adbDeviceProperties.test.ts +++ b/tests/boundary/mcp/adbDeviceProperties.test.ts @@ -14,6 +14,7 @@ import { createTestWorkspace, removeTestWorkspace, } from "../../support/workspace/workspaceFixture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const scenarios = [ { @@ -102,7 +103,10 @@ exit 1 }, ); onTestFinished(() => server.close()); - const client = new Client({ name: "adb-properties", version: "1" }); + const client = new Client( + { name: "adb-properties", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); diff --git a/tests/boundary/mcp/adbInputFileMcp.test.ts b/tests/boundary/mcp/adbInputFileMcp.test.ts index 19d5362580..1993eb37b8 100644 --- a/tests/boundary/mcp/adbInputFileMcp.test.ts +++ b/tests/boundary/mcp/adbInputFileMcp.test.ts @@ -8,6 +8,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.skipIf(process.platform === "win32")( "reports each refused local file before device commands", @@ -39,7 +40,10 @@ it.skipIf(process.platform === "win32")( const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); - const client = new Client({ name: "adb-input-refusal", version: "1" }); + const client = new Client( + { name: "adb-input-refusal", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); await client.connect(clientTransport); for (const { selected, hostCode } of [ diff --git a/tests/boundary/mcp/adbMcp.test.ts b/tests/boundary/mcp/adbMcp.test.ts index f626808cab..0f31943fc7 100644 --- a/tests/boundary/mcp/adbMcp.test.ts +++ b/tests/boundary/mcp/adbMcp.test.ts @@ -332,7 +332,10 @@ it("advertises exact valid ADB schemas and records inline evidence through MCP", const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); - const client = new Client({ name: "adb-boundary", version: "0.0.0" }); + const client = new Client( + { name: "adb-boundary", version: "0.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); await client.connect(clientTransport); @@ -424,7 +427,10 @@ it("rejects invalid tool input before reaching the provider", async () => { const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); - const client = new Client({ name: "adb-boundary-invalid", version: "0.0.0" }); + const client = new Client( + { name: "adb-boundary-invalid", version: "0.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); await client.connect(clientTransport); diff --git a/tests/boundary/mcp/adbOutputDirectoryMcp.test.ts b/tests/boundary/mcp/adbOutputDirectoryMcp.test.ts index c2b8131d89..f9f0b170de 100644 --- a/tests/boundary/mcp/adbOutputDirectoryMcp.test.ts +++ b/tests/boundary/mcp/adbOutputDirectoryMcp.test.ts @@ -8,6 +8,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.skipIf(process.platform === "win32")( "classifies output paths blocked by a file before device commands", @@ -39,7 +40,10 @@ it.skipIf(process.platform === "win32")( const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); - const client = new Client({ name: "adb-output-refusal", version: "1" }); + const client = new Client( + { name: "adb-output-refusal", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); await client.connect(clientTransport); for (const { output, hostCode } of [ diff --git a/tests/boundary/mcp/adbStartMcp.test.ts b/tests/boundary/mcp/adbStartMcp.test.ts index 2bbd6e46fc..ab6037653f 100644 --- a/tests/boundary/mcp/adbStartMcp.test.ts +++ b/tests/boundary/mcp/adbStartMcp.test.ts @@ -14,6 +14,7 @@ import { parseEvidence } from "../../../src/domain/evidence.js"; import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.skipIf(process.platform === "win32")( "preserves caller destination and reports the effective pushed file path through MCP", @@ -61,7 +62,10 @@ else if (args[0] === "-s" && args[2] === "shell" && args[3] === "test") { const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); - const client = new Client({ name: "adb-push-boundary", version: "0.0.0" }); + const client = new Client( + { name: "adb-push-boundary", version: "0.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); await client.connect(clientTransport); const response = await artifactMcpCall(client, { @@ -203,7 +207,10 @@ it const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); - const client = new Client({ name: "adb-start-boundary", version: "0.0.0" }); + const client = new Client( + { name: "adb-start-boundary", version: "0.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); await client.connect(clientTransport); @@ -342,10 +349,10 @@ it.skipIf(process.platform === "win32")( const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); - const client = new Client({ - name: "adb-start-refusal-mcp", - version: "0.0.0", - }); + const client = new Client( + { name: "adb-start-refusal-mcp", version: "0.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); await client.connect(clientTransport); diff --git a/tests/boundary/mcp/addressContextBookmarks.test.ts b/tests/boundary/mcp/addressContextBookmarks.test.ts index 40963f16e3..c4e0ce386d 100644 --- a/tests/boundary/mcp/addressContextBookmarks.test.ts +++ b/tests/boundary/mcp/addressContextBookmarks.test.ts @@ -13,6 +13,7 @@ import { import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { err, ok } from "../../../src/domain/result.js"; import { createServer } from "../../../src/server/createServer.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.each([ ["resolved padded", true, "0x00401000", "0x401000", "available"], @@ -62,7 +63,10 @@ it.each([ close: async () => ok(null), })); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "bookmark-verifier", version: "1" }); + const client = new Client( + { name: "bookmark-verifier", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -121,7 +125,10 @@ it.each([false, true])( close: async () => ok(null), })); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "context-cleanup", version: "1" }); + const client = new Client( + { name: "context-cleanup", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/addressContextCapacity.test.ts b/tests/boundary/mcp/addressContextCapacity.test.ts index 3af9b9f9da..48e25d7342 100644 --- a/tests/boundary/mcp/addressContextCapacity.test.ts +++ b/tests/boundary/mcp/addressContextCapacity.test.ts @@ -14,6 +14,7 @@ import { AnalysisCapabilityUnavailableError } from "../../../src/domain/analysis import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { SESSION_TOOL_CONTRACTS } from "../../../src/contracts/sessionToolContracts.js"; import { createServer } from "../../../src/server/createServer.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.each(["compact"] as const)( "preserves retained siblings and capacity recovery (%s schema)", @@ -72,7 +73,10 @@ it.each(["compact"] as const)( environment: { ...process.env, REA_MCP_OUTPUT_SCHEMA_PROFILE: profile }, }, ); - const client = new Client({ name: "context-capacity", version: "1" }); + const client = new Client( + { name: "context-capacity", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/addressContextInputErrors.test.ts b/tests/boundary/mcp/addressContextInputErrors.test.ts index d78a467309..c682f82d5b 100644 --- a/tests/boundary/mcp/addressContextInputErrors.test.ts +++ b/tests/boundary/mcp/addressContextInputErrors.test.ts @@ -16,6 +16,7 @@ import { projectAnalysisError } from "../../../src/domain/analysisErrorProjectio import { err, ok } from "../../../src/domain/result.js"; import { SESSION_TOOL_CONTRACTS } from "../../../src/contracts/sessionToolContracts.js"; import { createServer } from "../../../src/server/createServer.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const createContextRecoverySession = () => { const identity = { id: "fixture", name: "Fixture", version: "1" }; @@ -119,10 +120,13 @@ it.each(["compact"] as const)( }, }, ); - const client = new Client({ - name: "context-comment-recovery", - version: "1", - }); + const client = new Client( + { + name: "context-comment-recovery", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -298,7 +302,10 @@ it.each([ }, }, ); - const client = new Client({ name: "context-input-error", version: "1" }); + const client = new Client( + { name: "context-input-error", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/advertisedDialect.test.ts b/tests/boundary/mcp/advertisedDialect.test.ts index 93f9235ad6..a14f58197c 100644 --- a/tests/boundary/mcp/advertisedDialect.test.ts +++ b/tests/boundary/mcp/advertisedDialect.test.ts @@ -15,6 +15,7 @@ import { mcpToolCatalogProfileSchema } from "../../../src/config/mcpToolCatalogP import { createServer } from "../../../src/server/createServer.js"; import { silentLogger } from "../../../src/logger.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; describe("portable regex grammar", () => { // Each refused construct failed to compile in at least one of V8 (plain, @@ -159,7 +160,10 @@ const listTools = async (environment: Readonly) => { { kind: "session", session }, { environment, logger: silentLogger }, ); - const client = new Client({ name: "advertised-dialect", version: "1" }); + const client = new Client( + { name: "advertised-dialect", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/advertisedPatternsVMode.test.ts b/tests/boundary/mcp/advertisedPatternsVMode.test.ts index 90ea46a524..c00f219152 100644 --- a/tests/boundary/mcp/advertisedPatternsVMode.test.ts +++ b/tests/boundary/mcp/advertisedPatternsVMode.test.ts @@ -13,6 +13,7 @@ import { } from "../../../src/domain/stringPatterns.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { canonicalOutputSchema } from "../../fixtures/canonicalOutputSchema.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; // Pattern portability across every profile is owned by // advertisedDialect.test.ts. This file keeps the composed canonical base64 @@ -57,7 +58,10 @@ const listAdvertisedTools = async () => { throw new Error("No deep provider may start for a schema projection"); }); const server = createServer({ kind: "session", session }, {}); - const client = new Client({ name: "advertised-patterns", version: "1" }); + const client = new Client( + { name: "advertised-patterns", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/analysisSettingsMcp.test.ts b/tests/boundary/mcp/analysisSettingsMcp.test.ts index 0a092be613..c89398c2a2 100644 --- a/tests/boundary/mcp/analysisSettingsMcp.test.ts +++ b/tests/boundary/mcp/analysisSettingsMcp.test.ts @@ -5,6 +5,7 @@ import { EvidenceMcpServer } from "../../../src/server/EvidenceMcpServer.js"; import { registerServiceTools } from "../../../src/server/serviceToolBindings.js"; import { ToolResultDelivery } from "../../../src/server/ToolResultDelivery.js"; import { silentLogger } from "../../../src/logger.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const open: { client: Client; server: EvidenceMcpServer }[] = []; afterEach(async () => { @@ -36,7 +37,10 @@ it("binds runtime settings through the shared table, outside analysis admission" }, }, ); - const client = new Client({ name: "settings-client", version: "1" }); + const client = new Client( + { name: "settings-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); diff --git a/tests/boundary/mcp/analysisSummaryDetailMcp.test.ts b/tests/boundary/mcp/analysisSummaryDetailMcp.test.ts index 273163d6dd..24bd573b01 100644 --- a/tests/boundary/mcp/analysisSummaryDetailMcp.test.ts +++ b/tests/boundary/mcp/analysisSummaryDetailMcp.test.ts @@ -15,6 +15,7 @@ import { BINARY_LAYOUT_TEST_PROVIDER } from "../../fixtures/binaryDiagnostics/la import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const contract = toolContract("analyze_javascript_application"); @@ -38,7 +39,10 @@ const connect = async ( }, binaryLayout === undefined ? {} : { binaryLayout }, ); - const client = new Client({ name: "analysis-summary-detail", version: "1" }); + const client = new Client( + { name: "analysis-summary-detail", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/analyzeFunctionDetail.test.ts b/tests/boundary/mcp/analyzeFunctionDetail.test.ts index 4c08fd008e..5d3bb32e0d 100644 --- a/tests/boundary/mcp/analyzeFunctionDetail.test.ts +++ b/tests/boundary/mcp/analyzeFunctionDetail.test.ts @@ -22,6 +22,7 @@ import { parseGhidraFunctionInput } from "../../../src/ghidra/GhidraFunctionValu import { InvestigationRecords } from "../../../src/application/investigation/InvestigationRecords.js"; import { registerServiceTools } from "../../../src/server/serviceToolBindings.js"; import { recordsWorkflowSession } from "../../fixtures/workflowSession.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const dossier = functionDossierSchema.parse(ghidraFunctionDossier()); const partialCallees = { @@ -93,7 +94,10 @@ const connect = async ( withAdmittedAnalysis: withAdmittedAnalysis({ kind: "fixed", analysis }), }, ); - const client = new Client({ name: "fn-detail-client", version: "1" }); + const client = new Client( + { name: "fn-detail-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/androidLateCompletionMcp.test.ts b/tests/boundary/mcp/androidLateCompletionMcp.test.ts index eba19c814b..c8135c2a61 100644 --- a/tests/boundary/mcp/androidLateCompletionMcp.test.ts +++ b/tests/boundary/mcp/androidLateCompletionMcp.test.ts @@ -13,6 +13,7 @@ import { createTestBinarySession, } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("retains completed Android Evidence through the MCP cancellation delivery path", async () => { const fixture = await createJadxProtocolFixture(); @@ -53,7 +54,10 @@ it("retains completed Android Evidence through the MCP cancellation delivery pat }, }, ); - const client = new Client({ name: "android-late-completion", version: "1" }); + const client = new Client( + { name: "android-late-completion", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); onTestFinished(async () => { diff --git a/tests/boundary/mcp/androidPackageSummaryMcp.test.ts b/tests/boundary/mcp/androidPackageSummaryMcp.test.ts index fa0bf5c094..b472cbe51c 100644 --- a/tests/boundary/mcp/androidPackageSummaryMcp.test.ts +++ b/tests/boundary/mcp/androidPackageSummaryMcp.test.ts @@ -45,6 +45,7 @@ import { createJadxProtocolFixture, verifyJadxFixtureCleanup, } from "../../fixtures/android/jadx.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; async function assertAndroidPackageSelectedFacetContract(options: { client: Pick; @@ -567,7 +568,10 @@ it("rejects unavailable retention, invalid selectors and cancellation before pro { kind: "fixed", analysis: session }, { androidAnalysis: provider }, ); - const client = new Client({ name: "android-fixed-summary", version: "1" }); + const client = new Client( + { name: "android-fixed-summary", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/apktoolMcp.test.ts b/tests/boundary/mcp/apktoolMcp.test.ts index 42e08a1616..432e0fb56b 100644 --- a/tests/boundary/mcp/apktoolMcp.test.ts +++ b/tests/boundary/mcp/apktoolMcp.test.ts @@ -9,6 +9,7 @@ import { ok } from "../../../src/domain/result.js"; import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { assertAdvertisedMcpContracts } from "./mcpContractHarness.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const identity = { id: "apktool", name: "Apktool", version: "2.7.0-dirty" }; @@ -93,7 +94,10 @@ it("advertises exact valid Apktool schemas and records inline evidence through M const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); - const client = new Client({ name: "apktool-boundary", version: "0.0.0" }); + const client = new Client( + { name: "apktool-boundary", version: "0.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); await client.connect(clientTransport); diff --git a/tests/boundary/mcp/artifactComparisonSourceSchema.test.ts b/tests/boundary/mcp/artifactComparisonSourceSchema.test.ts index 47dee0928b..2ac43b9bc1 100644 --- a/tests/boundary/mcp/artifactComparisonSourceSchema.test.ts +++ b/tests/boundary/mcp/artifactComparisonSourceSchema.test.ts @@ -10,6 +10,7 @@ import { ARTIFACT_COMPARISON_EXAMPLE } from "../../../src/contracts/artifactComp import { toolContract } from "../../../src/contracts/toolContracts.js"; import { toolRegistrationOptions } from "../../../src/server/toolRegistrationOptions.js"; import { advertisedSchemaErrors } from "../../fixtures/mcpAdvertisedSchemaValidity.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const evidence = ARTIFACT_COMPARISON_EXAMPLE.left; const retained = { @@ -24,7 +25,10 @@ const file = { it("advertises one spelling per compare_artifacts source and rejects the same sides the parser rejects", async () => { const contract = toolContract("compare_artifacts"); const server = new McpServer({ name: "artifact-sources", version: "0" }); - const client = new Client({ name: "artifact-sources", version: "0" }); + const client = new Client( + { name: "artifact-sources", version: "0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); server.registerTool( diff --git a/tests/boundary/mcp/asarListingAdmissionMcp.test.ts b/tests/boundary/mcp/asarListingAdmissionMcp.test.ts index 19a5b07aab..15dca9bf8b 100644 --- a/tests/boundary/mcp/asarListingAdmissionMcp.test.ts +++ b/tests/boundary/mcp/asarListingAdmissionMcp.test.ts @@ -9,6 +9,7 @@ import { nestedAsarHeader } from "../../fixtures/asarHeader.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("reports expanded ASAR admission failure through MCP and permits a valid retry", async () => { const root = await createTestTempDirectory("rea-asar-listing-mcp-"); @@ -17,7 +18,10 @@ it("reports expanded ASAR admission failure through MCP and permits a valid retr await writeFile(path, bytes); const session = createTestBinarySession(new ArtifactProvider(process.env)); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "asar-listing-test", version: "1" }); + const client = new Client( + { name: "asar-listing-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/asarUnpackedExtractionMcp.test.ts b/tests/boundary/mcp/asarUnpackedExtractionMcp.test.ts index a671bc783f..20ffb7ccb2 100644 --- a/tests/boundary/mcp/asarUnpackedExtractionMcp.test.ts +++ b/tests/boundary/mcp/asarUnpackedExtractionMcp.test.ts @@ -11,11 +11,15 @@ import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createStrippedAsarAddon } from "../../fixtures/strippedAsarAddon.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const openArchive = async (archive: string): Promise => { const session = createTestBinarySession(new ArtifactProvider(process.env)); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "asar-unpacked-extraction", version: "1" }); + const client = new Client( + { name: "asar-unpacked-extraction", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); diff --git a/tests/boundary/mcp/batchDecompileViewsMcp.test.ts b/tests/boundary/mcp/batchDecompileViewsMcp.test.ts index fca88f6285..4d00344924 100644 --- a/tests/boundary/mcp/batchDecompileViewsMcp.test.ts +++ b/tests/boundary/mcp/batchDecompileViewsMcp.test.ts @@ -729,10 +729,13 @@ it("keeps the caller's own source when a page cannot fit, without retaining its }, { delivery: createToolResultDelivery(budget) }, ); - const fixedClient = new Client({ - name: "batch-unretained", - version: "1.0.0", - }); + const fixedClient = new Client( + { + name: "batch-unretained", + version: "1.0.0", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); onTestFinished(async () => { diff --git a/tests/boundary/mcp/batchSourcePublicationCleanup.test.ts b/tests/boundary/mcp/batchSourcePublicationCleanup.test.ts index 0fdcba46ce..6a6e3916c3 100644 --- a/tests/boundary/mcp/batchSourcePublicationCleanup.test.ts +++ b/tests/boundary/mcp/batchSourcePublicationCleanup.test.ts @@ -16,6 +16,7 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { phaseGate } from "../../support/lifecycleHarness.js"; import { releaseOwnedCleanup } from "../../support/cleanupRelease.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const expectRecoveredBatch = (response: CallToolResult, owned: string) => { expect(parseMcpToolError(response).error).toMatchObject({ @@ -116,7 +117,10 @@ it("keeps a batch cleanup owner and its completed prefix after source retention ), ); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "batch-owned-cleanup", version: "1" }); + const client = new Client( + { name: "batch-owned-cleanup", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); diff --git a/tests/boundary/mcp/batchSourcePublicationRecovery.test.ts b/tests/boundary/mcp/batchSourcePublicationRecovery.test.ts index ab6005eb25..ed7e6d4245 100644 --- a/tests/boundary/mcp/batchSourcePublicationRecovery.test.ts +++ b/tests/boundary/mcp/batchSourcePublicationRecovery.test.ts @@ -17,6 +17,7 @@ import { createToolResultDelivery } from "../../../src/server/toolResult.js"; import { registerServiceTools } from "../../../src/server/serviceToolBindings.js"; import { recordsWorkflowSession } from "../../fixtures/workflowSession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const provider = { id: "fixture", name: "Fixture", version: "1" }; const source = createEvidence(unknownTarget("not-observed"), provider, { operation: "health", @@ -84,7 +85,10 @@ it.each([ withAdmittedAnalysis: withAdmittedAnalysis({ kind: "fixed", analysis }), }, ); - const client = new Client({ name: "batch-overflow-test", version: "1" }); + const client = new Client( + { name: "batch-overflow-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/binaryDiagnosticsMcp.test.ts b/tests/boundary/mcp/binaryDiagnosticsMcp.test.ts index 8d8546fcee..144bc10785 100644 --- a/tests/boundary/mcp/binaryDiagnosticsMcp.test.ts +++ b/tests/boundary/mcp/binaryDiagnosticsMcp.test.ts @@ -33,6 +33,7 @@ import { } from "../../fixtures/binaryDiagnostics/nativeExports.js"; import { parseNativeExports } from "../../../src/domain/native/nativeExportParser.js"; import { createNativeExportsService } from "../../../src/composition/binaryDiagnostics.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("reports the exhausted native export allowance through MCP", async () => { const root = await createTestTempDirectory("rea-native-export-mcp-limits-"); @@ -40,7 +41,10 @@ it("reports the exhausted native export allowance through MCP", async () => { throw new Error("deep provider must not start"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "native-export-limits", version: "1" }); + const client = new Client( + { name: "native-export-limits", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); @@ -107,10 +111,13 @@ it.each(["inspect_native_exports", "inspect_byte_entropy"] as const)( : { nativeExports: service }, { logger: silentLogger }, ); - const client = new Client({ - name: "exports-preflight-client", - version: "1", - }); + const client = new Client( + { + name: "exports-preflight-client", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); @@ -198,7 +205,10 @@ it.each([false, true])( withAdmittedAnalysis: admission, }, ); - const client = new Client({ name: "entropy-cleanup-client", version: "1" }); + const client = new Client( + { name: "entropy-cleanup-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { failClose = false; try { @@ -294,7 +304,10 @@ it("records inline layout with compact schemas and canonical path checks", async { kind: "session", session }, { binaryLayout: service }, ); - const client = new Client({ name: "binary-layout-contract", version: "1" }); + const client = new Client( + { name: "binary-layout-contract", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); @@ -371,7 +384,10 @@ it("profiles real bytes with exact offsets, valid advertised schemas and read-on throw new Error("No provider needed"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "entropy-contract", version: "1" }); + const client = new Client( + { name: "entropy-contract", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); @@ -438,7 +454,10 @@ it("records a portable export inventory through MCP without a binary target", as throw new Error("deep provider must not start"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "native-exports-contract", version: "1" }); + const client = new Client( + { name: "native-exports-contract", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/browserComparisonInput.test.ts b/tests/boundary/mcp/browserComparisonInput.test.ts index a3c20725f9..bb7c77316e 100644 --- a/tests/boundary/mcp/browserComparisonInput.test.ts +++ b/tests/boundary/mcp/browserComparisonInput.test.ts @@ -18,6 +18,7 @@ import { browserScenarioCaptureSchema } from "../../../src/domain/browserScenari import { createToolResultDelivery } from "../../../src/server/toolResult.js"; import { toolRegistrationOptions } from "../../../src/server/toolRegistrationOptions.js"; import { startFakeCdpBrowser } from "../../fixtures/fakeCdpBrowser.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const delivery = createToolResultDelivery(STDIO_DEFAULT_MAX_BUFFER_SIZE); @@ -95,7 +96,10 @@ describe("browser comparison input boundary", () => { it("advertises producer captures and agrees with SDK validation on both comparison families", async () => { const browser = await startFakeCdpBrowser({ sensitiveShapes: true }); const server = new McpServer({ name: "capture-input", version: "0" }); - const client = new Client({ name: "capture-input", version: "0" }); + const client = new Client( + { name: "capture-input", version: "0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); let calls = 0; diff --git a/tests/boundary/mcp/bunStandaloneMcp.test.ts b/tests/boundary/mcp/bunStandaloneMcp.test.ts index a2201897c2..9802e13ec8 100644 --- a/tests/boundary/mcp/bunStandaloneMcp.test.ts +++ b/tests/boundary/mcp/bunStandaloneMcp.test.ts @@ -12,6 +12,7 @@ import { bunModuleGraphPayload, elfAppendedBunPayload, } from "../../../src/artifacts/bun/BunStandalone.fixture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("exposes Bun graph metadata through the existing MCP artifact tool", async () => { const root = await createTestTempDirectory("rea-bun-mcp-"); @@ -28,7 +29,10 @@ it("exposes Bun graph metadata through the existing MCP artifact tool", async () ); const session = createTestBinarySession(new ArtifactProvider({})); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "bun-contract-test", version: "1" }); + const client = new Client( + { name: "bun-contract-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/bundleComparisonCancellation.test.ts b/tests/boundary/mcp/bundleComparisonCancellation.test.ts index c7069c96d7..b21f79494a 100644 --- a/tests/boundary/mcp/bundleComparisonCancellation.test.ts +++ b/tests/boundary/mcp/bundleComparisonCancellation.test.ts @@ -16,6 +16,7 @@ import { ToolResultDelivery } from "../../../src/server/ToolResultDelivery.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { holdFirstFileRead } from "../../support/holdFirstFileRead.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("leaves the session unchanged after bundle comparison cancellation and permits a retry", async () => { const root = await createTestTempDirectory("rea-mcp-compare-cancel-"); @@ -56,10 +57,13 @@ it("leaves the session unchanged after bundle comparison cancellation and permit if (!recorded.ok) throw recorded.error; const before = session.exportEvidenceBundle(); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "bundle-comparison-cancellation", - version: "1", - }); + const client = new Client( + { + name: "bundle-comparison-cancellation", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const controller = new AbortController(); let releaseRead: (() => void) | undefined; onTestFinished(async () => { diff --git a/tests/boundary/mcp/bundleComparisonMcp.test.ts b/tests/boundary/mcp/bundleComparisonMcp.test.ts index 932a60e12b..ad22a898f3 100644 --- a/tests/boundary/mcp/bundleComparisonMcp.test.ts +++ b/tests/boundary/mcp/bundleComparisonMcp.test.ts @@ -24,6 +24,7 @@ import { } from "../../../src/domain/evidenceBundle.js"; import { createServer } from "../../../src/server/createServer.js"; import { observed } from "../../fixtures/analysisExecution.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const sourceEvidence = (label: string) => createEvidence( @@ -449,7 +450,10 @@ const connect = async () => { close: () => Promise.resolve(resultOk(null)), })); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "bundle-comparison-test", version: "1" }); + const client = new Client( + { name: "bundle-comparison-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); diff --git a/tests/boundary/mcp/callGraphCleanupIncomplete.test.ts b/tests/boundary/mcp/callGraphCleanupIncomplete.test.ts index 35104d148a..7ce4d5b507 100644 --- a/tests/boundary/mcp/callGraphCleanupIncomplete.test.ts +++ b/tests/boundary/mcp/callGraphCleanupIncomplete.test.ts @@ -27,6 +27,7 @@ import { jsonResult, resources, } from "./enhancedToolsHarness.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; afterEach(closeEnhancedToolResources); @@ -319,7 +320,10 @@ const openSession = async (port: AnalysisOperationPort) => { }, ); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "call-graph-cleanup", version: "1" }); + const client = new Client( + { name: "call-graph-cleanup", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); diff --git a/tests/boundary/mcp/callPathSearchExtentMcp.test.ts b/tests/boundary/mcp/callPathSearchExtentMcp.test.ts index c57b33f76d..e293474566 100644 --- a/tests/boundary/mcp/callPathSearchExtentMcp.test.ts +++ b/tests/boundary/mcp/callPathSearchExtentMcp.test.ts @@ -17,6 +17,7 @@ import { createFunctionCoordinateContext } from "../../../src/domain/native/func import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const observe = ( address: string, @@ -67,10 +68,13 @@ it.each([ throw new Error("Offline call paths must not launch a provider"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "call-path-coordinate-identity", - version: "1", - }); + const client = new Client( + { + name: "call-path-coordinate-identity", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const provider = FUNCTION_COMPARISON_EXAMPLE.left.provider; @@ -157,7 +161,10 @@ it("publishes explored extent without the terminal goal's callees", async () => throw new Error("Offline call paths must not launch a provider"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "call-path-search-extent", version: "1" }); + const client = new Client( + { name: "call-path-search-extent", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -217,7 +224,10 @@ it("preserves unresolved outgoing call caveats and bounds search completeness at throw new Error("Offline call paths must not launch a provider"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "unresolved-call-path", version: "1" }); + const client = new Client( + { name: "unresolved-call-path", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/capabilityRemediationMcp.test.ts b/tests/boundary/mcp/capabilityRemediationMcp.test.ts index 1eafe3c01a..0c86383f60 100644 --- a/tests/boundary/mcp/capabilityRemediationMcp.test.ts +++ b/tests/boundary/mcp/capabilityRemediationMcp.test.ts @@ -156,7 +156,10 @@ it("returns an unready IDA registration's repair from an explicit open_binary se { kind: "session", session }, { logger: silentLogger }, ); - const client = new Client({ name: "selection-remediation", version: "1" }); + const client = new Client( + { name: "selection-remediation", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); onTestFinished(async () => { diff --git a/tests/boundary/mcp/clientCapabilities.test.ts b/tests/boundary/mcp/clientCapabilities.test.ts index c741045b23..0ec3b6627b 100644 --- a/tests/boundary/mcp/clientCapabilities.test.ts +++ b/tests/boundary/mcp/clientCapabilities.test.ts @@ -16,6 +16,7 @@ import { createCacheProvider, createTestBinarySession, } from "../../fixtures/binarySession.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const assertCompleteToolAvailability = (structuredContent: unknown): void => { const status = @@ -38,7 +39,10 @@ describe("per-request client capability reporting", () => { async (capabilities, form, url) => { const session = createTestBinarySession(createCacheProvider([])); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "capabilities-test", version: "1" }); + const client = new Client( + { name: "capabilities-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -79,7 +83,7 @@ describe("initialize-scoped client metadata", () => { const server = createServer({ kind: "session", session }); const client = new Client( { name: "initialize-test", version: "2" }, - { capabilities }, + { jsonSchemaValidator: createMcpSchemaValidation(), capabilities }, ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); diff --git a/tests/boundary/mcp/commandObservationViews.test.ts b/tests/boundary/mcp/commandObservationViews.test.ts index 5d0ff03d5f..bb821d7304 100644 --- a/tests/boundary/mcp/commandObservationViews.test.ts +++ b/tests/boundary/mcp/commandObservationViews.test.ts @@ -18,6 +18,7 @@ import { inspectAnalysisView } from "../../../src/application/analysisView/Analy import { TestReverseEngineeringService } from "../../support/reverseEngineeringService.js"; import { ownedOutput } from "../../support/reverseEngineeringCompositionFixtures.js"; import { advertisedMcpToolSchemas } from "../../fixtures/advertisedMcpTool.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const sessionId = "00000000-0000-4000-8000-000000000001"; const capture = { @@ -97,7 +98,10 @@ const connect = async (retain = true) => { recordEvidence: retain ? record : undefined, }, ); - const client = new Client({ name: "command-view-client", version: "1" }); + const client = new Client( + { name: "command-view-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/completionInventoryAliasMcp.test.ts b/tests/boundary/mcp/completionInventoryAliasMcp.test.ts index 759b6054bf..324a2cad7c 100644 --- a/tests/boundary/mcp/completionInventoryAliasMcp.test.ts +++ b/tests/boundary/mcp/completionInventoryAliasMcp.test.ts @@ -4,6 +4,7 @@ import { expect, it } from "vitest"; import { createAnalysisExecution } from "../../../src/ports/AnalysisProvider.js"; import { ok } from "../../../src/domain/result.js"; import { createServer } from "../../../src/server/createServer.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const provider = { id: "fixed-fixture", name: "Fixed fixture", version: "1" }; @@ -43,7 +44,10 @@ it.each([false, true])( ), }, }); - const client = new Client({ name: "procedure-completion", version: "1" }); + const client = new Client( + { name: "procedure-completion", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); @@ -106,10 +110,13 @@ it("evaluates later alias rows before the MCP completion limit is applied", asyn execute: async () => ok(createAnalysisExecution(rows, provider)), }, }); - const client = new Client({ - name: "large-completion-inventory", - version: "1", - }); + const client = new Client( + { + name: "large-completion-inventory", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/composedWorkflowEvidenceLinksMcp.test.ts b/tests/boundary/mcp/composedWorkflowEvidenceLinksMcp.test.ts index 88fd62affb..566e354a75 100644 --- a/tests/boundary/mcp/composedWorkflowEvidenceLinksMcp.test.ts +++ b/tests/boundary/mcp/composedWorkflowEvidenceLinksMcp.test.ts @@ -6,6 +6,7 @@ import { silentLogger } from "../../../src/logger.js"; import { parseEvidence } from "../../../src/domain/evidence.js"; import { runDirectAnalysis } from "../../../src/application/DirectAnalysis.js"; import { composedWorkflowFixture } from "../../fixtures/composedWorkflowEvidence.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("returns the same consumed atomic provenance through CLI application and MCP boundaries", async () => { const cli = await composedWorkflowFixture(); @@ -22,10 +23,13 @@ it("returns the same consumed atomic provenance through CLI application and MCP { kind: "session", session: fixture.session }, { logger: silentLogger }, ); - const client = new Client({ - name: "workflow-evidence-links", - version: "1.0.0", - }); + const client = new Client( + { + name: "workflow-evidence-links", + version: "1.0.0", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/contextEvidenceOverflow.test.ts b/tests/boundary/mcp/contextEvidenceOverflow.test.ts index 994cd8f329..2a20d068d5 100644 --- a/tests/boundary/mcp/contextEvidenceOverflow.test.ts +++ b/tests/boundary/mcp/contextEvidenceOverflow.test.ts @@ -13,6 +13,7 @@ import { createAnalysisProfile } from "../../../src/domain/analysisProfile.js"; import { err, ok } from "../../../src/domain/result.js"; import { AnalysisCapabilityUnavailableError } from "../../../src/domain/analysisErrorCore.js"; import { createServer } from "../../../src/server/createServer.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const verifyContext = ( content: unknown, @@ -168,7 +169,10 @@ it.each([ }, }, ); - const client = new Client({ name: "context-capacity", version: "1" }); + const client = new Client( + { name: "context-capacity", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -264,10 +268,13 @@ it.each([true, false])( { kind: "session", session }, { environment: { ...process.env, REA_MCP_TOOL_FAMILIES: "session" } }, ); - const client = new Client({ - name: "context-oversize-success", - version: "1", - }); + const client = new Client( + { + name: "context-oversize-success", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); diff --git a/tests/boundary/mcp/cutterCancellationMcp.test.ts b/tests/boundary/mcp/cutterCancellationMcp.test.ts index f4fcea0098..8391a1e76c 100644 --- a/tests/boundary/mcp/cutterCancellationMcp.test.ts +++ b/tests/boundary/mcp/cutterCancellationMcp.test.ts @@ -15,6 +15,7 @@ import { CutterBridgeService } from "../../../src/cutter/CutterBridgeService.js" import { toolContract } from "../../../src/contracts/toolContracts.js"; import { cutterMcpServer } from "../../fixtures/debuggerMcp.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; // CutterBridgeClient's per-probe request deadline. const CUTTER_REQUEST_DEADLINE_MS = 25_000; @@ -56,7 +57,10 @@ it("propagates MCP cancellation into an active Cutter command", async () => { }, }); const server = cutterMcpServer("cutter-cancellation", service); - const client = new Client({ name: "cutter-cancellation", version: "1" }); + const client = new Client( + { name: "cutter-cancellation", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const controller = new AbortController(); @@ -123,7 +127,10 @@ it("shares one cleanup proof across concurrent Cutter MCP commands without Binar }, }); const server = cutterMcpServer("cutter-cleanup-race", service); - const client = new Client({ name: "cutter-cleanup-race", version: "1" }); + const client = new Client( + { name: "cutter-cleanup-race", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const call = (command: string) => @@ -211,7 +218,10 @@ it("cancels active discovery sockets, stops queued probes and recovers on the sa } }; const server = cutterMcpServer("cutter-discovery-cancel", service); - const client = new Client({ name: "cutter-discovery-cancel", version: "1" }); + const client = new Client( + { name: "cutter-discovery-cancel", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const controller = new AbortController(); @@ -319,10 +329,13 @@ it.skipIf(process.platform === "win32")( new CutterBridgeClient({ REA_CUTTER_BRIDGE_DIR: directory }), ); const server = cutterMcpServer("cutter-generation-proof", service); - const client = new Client({ - name: "cutter-generation-proof", - version: "1", - }); + const client = new Client( + { + name: "cutter-generation-proof", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); diff --git a/tests/boundary/mcp/cutterMcp.test.ts b/tests/boundary/mcp/cutterMcp.test.ts index 76e7c46d05..7b16e99abd 100644 --- a/tests/boundary/mcp/cutterMcp.test.ts +++ b/tests/boundary/mcp/cutterMcp.test.ts @@ -13,6 +13,7 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { parseEvidence } from "../../../src/domain/evidence.js"; import { createServer } from "../../../src/server/createServer.js"; import { silentLogger } from "../../../src/logger.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const assertUncertainEvidence = async ( client: Client, @@ -222,7 +223,10 @@ it("preserves live Cutter command Evidence and parity through the MCP boundary", providerEnvironment: { ...process.env, REA_CUTTER_BRIDGE_DIR: directory }, }, ); - const client = new Client({ name: "cutter-mcp-boundary", version: "1" }); + const client = new Client( + { name: "cutter-mcp-boundary", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/debuggerExternalMutationLifecycleMcp.test.ts b/tests/boundary/mcp/debuggerExternalMutationLifecycleMcp.test.ts index d03d7518a0..a42f2f7cd0 100644 --- a/tests/boundary/mcp/debuggerExternalMutationLifecycleMcp.test.ts +++ b/tests/boundary/mcp/debuggerExternalMutationLifecycleMcp.test.ts @@ -20,6 +20,7 @@ import { } from "../../fixtures/debuggerMcp.js"; import { phaseGate } from "../../support/lifecycleHarness.js"; import { waitFor } from "../../support/testWait.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const SESSION_ID = "00000000-0000-4000-8000-000000000001"; @@ -278,7 +279,10 @@ describe.each([RIZIN, GDB, CUTTER])( recorded.push(evidence); return ok("added" as const); }); - const client = new Client({ name: "debugger-lifecycle", version: "1" }); + const client = new Client( + { name: "debugger-lifecycle", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/denoStandaloneMcp.test.ts b/tests/boundary/mcp/denoStandaloneMcp.test.ts index 73d7af8e57..ec6f087199 100644 --- a/tests/boundary/mcp/denoStandaloneMcp.test.ts +++ b/tests/boundary/mcp/denoStandaloneMcp.test.ts @@ -12,6 +12,7 @@ import { parseEvidence } from "../../../src/domain/evidence.js"; import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("exposes Deno compile metadata through the existing MCP artifact tool", async () => { const root = await createTestTempDirectory("rea-deno-mcp-"); @@ -19,7 +20,10 @@ it("exposes Deno compile metadata through the existing MCP artifact tool", async await writeFile(path, denoElf()); const session = createTestBinarySession(new ArtifactProvider({})); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "deno-contract-test", version: "1" }); + const client = new Client( + { name: "deno-contract-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/dylibResolutionMcp.test.ts b/tests/boundary/mcp/dylibResolutionMcp.test.ts index db6f9378dd..b102711431 100644 --- a/tests/boundary/mcp/dylibResolutionMcp.test.ts +++ b/tests/boundary/mcp/dylibResolutionMcp.test.ts @@ -23,13 +23,17 @@ import { dylibResolutionResultSchema } from "../../../src/domain/apple/dylibReso import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const withClient = async ( verify: (client: Client) => Promise, ): Promise => { const session = createTestBinarySession(new ArtifactProvider(process.env)); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "dylib-mcp-test", version: "1" }); + const client = new Client( + { name: "dylib-mcp-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/electronMcp.test.ts b/tests/boundary/mcp/electronMcp.test.ts index f8b6c15b7f..7045d9cb38 100644 --- a/tests/boundary/mcp/electronMcp.test.ts +++ b/tests/boundary/mcp/electronMcp.test.ts @@ -36,6 +36,13 @@ import { toolAvailabilityInventory } from "../../../src/contracts/toolOutputSche import { AnalysisCancelledError } from "../../../src/domain/analysisErrorCore.js"; import { emptyElectronPageCoverage } from "../../../src/domain/javascript/electronPageInspection.fixture.js"; import type { ElectronPageInspection } from "../../../src/domain/javascript/electronObservation.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; + +const testClient = (name: string) => + new Client( + { name, version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const browsers: FakeCdpBrowser[] = []; const resources: Array<{ close(): Promise }> = []; @@ -48,7 +55,7 @@ it("retains failed JavaScript inventory cleanup through server shutdown retries" close: () => Promise.resolve(resultOk(null)), })); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "javascript-cleanup-owner", version: "1" }); + const client = testClient("javascript-cleanup-owner"); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const originalClose = AsarArtifactReader.prototype.close; @@ -151,7 +158,7 @@ it("records completed Electron facts after final detach as server Evidence", asy electronObservation: provider, }, ); - const client = new Client({ name: "electron-final-detach", version: "1" }); + const client = testClient("electron-final-detach"); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server, session); @@ -196,7 +203,7 @@ it("lets MCP JavaScript analysis continue only with recorded untrusted ASAR byte close: () => Promise.resolve(resultOk(null)), })); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "asar-integrity-policy", version: "1" }); + const client = testClient("asar-integrity-policy"); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server, session); @@ -241,10 +248,13 @@ it("advertises owned JavaScript analysis effects without foreign target executio close: () => Promise.resolve(resultOk(null)), })); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "javascript-analysis-effects", - version: "1", - }); + const client = new Client( + { + name: "javascript-analysis-effects", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server, session); @@ -322,7 +332,7 @@ it("exposes endpoint-scoped Electron discovery and inspection as Evidence", asyn }), }, ); - const client = new Client({ name: "electron-mcp-test", version: "1" }); + const client = testClient("electron-mcp-test"); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server, session); @@ -500,7 +510,7 @@ it("runs active Electron scenarios with selected paths and inferred working dire }), }, ); - const client = new Client({ name: "electron-active-mcp-test", version: "1" }); + const client = testClient("electron-active-mcp-test"); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server, session); @@ -634,10 +644,13 @@ it("exposes the target-free static JavaScript application workflow", async () => }), }, ); - const client = new Client({ - name: "electron-static-mcp-test", - version: "1", - }); + const client = new Client( + { + name: "electron-static-mcp-test", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server, session); @@ -736,10 +749,13 @@ it.skipIf(process.platform === "win32")( ); }); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "application-source-admission", - version: "1", - }); + const client = new Client( + { + name: "application-source-admission", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server, session); @@ -800,7 +816,7 @@ const activePathAdmissionClient = async ( }, }, ); - const client = new Client({ name: "electron-path-test", version: "1" }); + const client = testClient("electron-path-test"); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server, session); diff --git a/tests/boundary/mcp/enhancedTools.01-lists-the-complete-target-open.test.ts b/tests/boundary/mcp/enhancedTools.01-lists-the-complete-target-open.test.ts index 1a0bbdc4d6..9976ef91a7 100644 --- a/tests/boundary/mcp/enhancedTools.01-lists-the-complete-target-open.test.ts +++ b/tests/boundary/mcp/enhancedTools.01-lists-the-complete-target-open.test.ts @@ -17,6 +17,7 @@ import { createAnalysisExecution } from "../../../src/ports/AnalysisProvider.js" import { ok as resultOk, err } from "../../../src/domain/result.js"; import { AnalysisCapabilityUnavailableError } from "../../../src/domain/analysisErrorCore.js"; import { nativeDispatchMetadataResultSchema } from "../../../src/domain/native/objcSwiftMetadata.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const targetObservation = (value: unknown) => resultOk( @@ -231,7 +232,10 @@ afterEach(async () => { const connect = async (analysis: AnalysisOperationPort = fixturePort()) => { const server = createServer({ kind: "fixed", analysis }); - const client = new Client({ name: "enhanced-test", version: "1.0.0" }); + const client = new Client( + { name: "enhanced-test", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); diff --git a/tests/boundary/mcp/enhancedToolsHarness.ts b/tests/boundary/mcp/enhancedToolsHarness.ts index 18547618e9..624af9766f 100644 --- a/tests/boundary/mcp/enhancedToolsHarness.ts +++ b/tests/boundary/mcp/enhancedToolsHarness.ts @@ -8,6 +8,7 @@ import { import { Client, InMemoryTransport } from "@modelcontextprotocol/client"; import type { AnalysisOperationPort } from "../../../src/ports/AnalysisProvider.js"; import { createServer } from "../../../src/server/createServer.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; export const PROCEDURES = { "0x1": "_TtC7Fixture5Class", @@ -28,7 +29,10 @@ export const connect = async ( environment: Readonly = process.env, ) => { const server = createServer({ kind: "fixed", analysis }, { environment }); - const client = new Client({ name: "enhanced-test", version: "1.0.0" }); + const client = new Client( + { name: "enhanced-test", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); diff --git a/tests/boundary/mcp/environmentBundleMcp.test.ts b/tests/boundary/mcp/environmentBundleMcp.test.ts index 53e0e57062..75002440ad 100644 --- a/tests/boundary/mcp/environmentBundleMcp.test.ts +++ b/tests/boundary/mcp/environmentBundleMcp.test.ts @@ -22,6 +22,7 @@ import { import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const TOOL = "export_environment_bundle"; @@ -35,7 +36,10 @@ const connect = async () => { environment: { ...process.env }, }, ); - const client = new Client({ name: "environment-bundle-mcp", version: "1" }); + const client = new Client( + { name: "environment-bundle-mcp", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/environmentServeMcp.test.ts b/tests/boundary/mcp/environmentServeMcp.test.ts index 236da92164..b27bda88ef 100644 --- a/tests/boundary/mcp/environmentServeMcp.test.ts +++ b/tests/boundary/mcp/environmentServeMcp.test.ts @@ -22,6 +22,7 @@ import { processTest, type TestProcesses, } from "../../support/process/processFixture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const CARD_PATH = "/.well-known/agent-env.json"; /** SHA-256 of the card served for the fixture named "renamed", its descriptions naming each tool's recorded responses; pure replay must serve these bytes. */ @@ -54,7 +55,10 @@ const serveReplayOnly = async ( const connect = async (url: URL) => { const transport = new StreamableHTTPClientTransport(url); - const client = new Client({ name: "environment-boundary", version: "1" }); + const client = new Client( + { name: "environment-boundary", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); await client.connect(transport); return client; }; diff --git a/tests/boundary/mcp/environmentServeWritesMcp.test.ts b/tests/boundary/mcp/environmentServeWritesMcp.test.ts index 019eacc08d..102fb62459 100644 --- a/tests/boundary/mcp/environmentServeWritesMcp.test.ts +++ b/tests/boundary/mcp/environmentServeWritesMcp.test.ts @@ -36,6 +36,7 @@ import { jsonObjectSchema, type JsonValue, } from "../../../src/domain/jsonValue.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; /** The book the first served create of "Boundary Book" makes: one second past the served clock's start. */ const BOUNDARY_BOOK = book(3, "Boundary Book", bookClock(13)); @@ -123,7 +124,10 @@ processTest( await expect( rpc("data/add", { parts: [{ kind: "data", data: document }] }), ).resolves.toMatchObject({ result: {} }); - const client = new Client({ name: "own-keys-writes", version: "1" }); + const client = new Client( + { name: "own-keys-writes", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); await client.connect(new StreamableHTTPClientTransport(started.url)); try { for (const [tool, args, name, id] of [ @@ -177,7 +181,10 @@ processTest( "--port", "0", ]); - const client = new Client({ name: "write-views", version: "1" }); + const client = new Client( + { name: "write-views", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); await client.connect(new StreamableHTTPClientTransport(started.url)); try { const { tools } = await client.listTools(); @@ -262,10 +269,13 @@ processTest( "--port", "0", ]); - const client = new Client({ - name: "write-schema-defaults", - version: "1", - }); + const client = new Client( + { + name: "write-schema-defaults", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); await client.connect(new StreamableHTTPClientTransport(started.url)); try { const { tools } = await client.listTools(); @@ -372,7 +382,10 @@ describe("rea environment-serve write tools", () => { "--port", "0", ]); - const client = new Client({ name: "environment-writes", version: "1" }); + const client = new Client( + { name: "environment-writes", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); await client.connect(new StreamableHTTPClientTransport(started.url)); try { const { tools } = await client.listTools(); @@ -460,7 +473,10 @@ describe("rea environment-serve write tools", () => { "--port", "0", ]); - const client = new Client({ name: "raw-utf16-writes", version: "1" }); + const client = new Client( + { name: "raw-utf16-writes", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); await client.connect(new StreamableHTTPClientTransport(started.url)); try { for (const id of [3, 4]) { @@ -525,10 +541,13 @@ processTest( "--port", "0", ]); - const client = new Client({ - name: "bulk-response-verification", - version: "1", - }); + const client = new Client( + { + name: "bulk-response-verification", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); await client.connect(new StreamableHTTPClientTransport(started.url)); try { const { tools } = await client.listTools(); @@ -626,10 +645,13 @@ processTest.for([ "--port", "0", ]); - const client = new Client({ - name: "contradictory-reference", - version: "1", - }); + const client = new Client( + { + name: "contradictory-reference", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); await client.connect(new StreamableHTTPClientTransport(started.url)); try { const { tools } = await client.listTools(); diff --git a/tests/boundary/mcp/evidenceBundleInline.test.ts b/tests/boundary/mcp/evidenceBundleInline.test.ts index 517661a28f..b4ec6cf398 100644 --- a/tests/boundary/mcp/evidenceBundleInline.test.ts +++ b/tests/boundary/mcp/evidenceBundleInline.test.ts @@ -17,6 +17,7 @@ import { ANALYSIS_SNAPSHOT_TARGET } from "../../../src/domain/analysisSnapshot.f import { EMPTY_PROCESS_CAPTURE_EXAMPLE } from "../../../src/domain/process/processCaptureExample.js"; import { PROCESS_PROVIDER } from "../../../src/domain/process/processEvidenceProvider.js"; import { createServer } from "../../../src/server/createServer.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("exports and imports GameCube DOL Evidence without losing its subject identity", async () => { const root = await createTestTempDirectory("rea-dol-bundle-mcp-"); @@ -125,7 +126,10 @@ it("returns the complete session Evidence bundle in the tool result", async () = })); expect(session.recordEvidence(evidence).ok).toBe(true); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "inline-evidence-bundle", version: "1" }); + const client = new Client( + { name: "inline-evidence-bundle", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); @@ -350,7 +354,10 @@ const connectEvidenceMcp = async ( session: ReturnType, ) => { const server = createServer({ kind: "session", session }); - const client = new Client({ name, version: "1" }); + const client = new Client( + { name, version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); diff --git a/tests/boundary/mcp/evidenceExportCancellation.test.ts b/tests/boundary/mcp/evidenceExportCancellation.test.ts index 6f14d9c142..326f28f775 100644 --- a/tests/boundary/mcp/evidenceExportCancellation.test.ts +++ b/tests/boundary/mcp/evidenceExportCancellation.test.ts @@ -9,6 +9,7 @@ import { createEvidence } from "../../../src/domain/evidence.js"; import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.each([false, true])( "stops an SDK export cancellation before publication and keeps the same session usable (overwrite: %s)", @@ -30,10 +31,13 @@ it.each([false, true])( ); expect(session.recordEvidence(evidence).ok).toBe(true); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "evidence-export-cancellation", - version: "1", - }); + const client = new Client( + { + name: "evidence-export-cancellation", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const controller = new AbortController(); onTestFinished(async () => { controller.abort(); diff --git a/tests/boundary/mcp/evidenceImportCancellation.test.ts b/tests/boundary/mcp/evidenceImportCancellation.test.ts index 490739de60..8de89375bd 100644 --- a/tests/boundary/mcp/evidenceImportCancellation.test.ts +++ b/tests/boundary/mcp/evidenceImportCancellation.test.ts @@ -16,6 +16,7 @@ import * as evidenceBundleFiles from "../../../src/application/EvidenceBundleFil import { OwnedFileHandle } from "../../../src/filesystem/OwnedFileHandle.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("preserves the exact reason when import is cancelled after reading the bundle", async () => { const root = await createTestTempDirectory( @@ -105,10 +106,13 @@ it("keeps the complete session unchanged after SDK import cancellation and permi // Valid whitespace crosses the streaming threshold without a large JSON tree. await writeFile(path, " ".repeat(9 * 1024 * 1024) + JSON.stringify(bundle)); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "evidence-import-cancellation", - version: "1", - }); + const client = new Client( + { + name: "evidence-import-cancellation", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const controller = new AbortController(); onTestFinished(async () => { controller.abort(); @@ -242,10 +246,13 @@ it("retains a failed import close in the server scope through SDK error projecti }); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "evidence-import-close-failure", - version: "1", - }); + const client = new Client( + { + name: "evidence-import-close-failure", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { allowClose = true; close.mockRestore(); @@ -301,10 +308,13 @@ it("retries a transient import close failure before admitting the bundle", async throw new Error("one transient file close failure"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "evidence-import-close-retry", - version: "1", - }); + const client = new Client( + { + name: "evidence-import-close-retry", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { close.mockRestore(); await client.close(); diff --git a/tests/boundary/mcp/evidenceImportLifecycle.test.ts b/tests/boundary/mcp/evidenceImportLifecycle.test.ts index 0669e7b79c..3ddb1692b4 100644 --- a/tests/boundary/mcp/evidenceImportLifecycle.test.ts +++ b/tests/boundary/mcp/evidenceImportLifecycle.test.ts @@ -11,6 +11,7 @@ import { OwnedFileHandle } from "../../../src/filesystem/OwnedFileHandle.js"; import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const connectImportSession = async () => { const root = await createTestTempDirectory("rea-mcp-import-lifecycle-"); @@ -18,10 +19,13 @@ const connectImportSession = async () => { throw new Error("Evidence import must not start a binary provider"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "evidence-import-lifecycle", - version: "1", - }); + const client = new Client( + { + name: "evidence-import-lifecycle", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const importRead = phaseGate(); const originalFileClose = OwnedFileHandle.prototype.close; vi.spyOn(OwnedFileHandle.prototype, "close").mockImplementationOnce( @@ -181,7 +185,10 @@ it("reports newly committed Unknown revisions and counts a repeated import once" throw new Error("Evidence import must not start a binary provider"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "import-counts", version: "1" }); + const client = new Client( + { name: "import-counts", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); onTestFinished(async () => { diff --git a/tests/boundary/mcp/evidenceRetentionRecovery.test.ts b/tests/boundary/mcp/evidenceRetentionRecovery.test.ts index c166abe475..850f5b475d 100644 --- a/tests/boundary/mcp/evidenceRetentionRecovery.test.ts +++ b/tests/boundary/mcp/evidenceRetentionRecovery.test.ts @@ -20,6 +20,7 @@ import { ok } from "../../../src/domain/result.js"; import { createServer } from "../../../src/server/createServer.js"; import { EvidenceMcpServer } from "../../../src/server/EvidenceMcpServer.js"; import { createToolResultDelivery } from "../../../src/server/toolResult.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.each(["compact"] as const)( "delivers authenticated but unretained provider Evidence inline (%s schema)", @@ -51,7 +52,10 @@ it.each(["compact"] as const)( environment: { ...process.env, REA_MCP_OUTPUT_SCHEMA_PROFILE: profile }, }, ); - const client = new Client({ name: "unretained-evidence", version: "1" }); + const client = new Client( + { name: "unretained-evidence", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); @@ -140,10 +144,13 @@ it("keeps an oversized unretained observation failure bounded and the connection const records = new InvestigationRecords({ maximumRepresentationBytes: 0 }); const session = new BinarySession(router, records); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "unretained-evidence-overflow", - version: "1", - }); + const client = new Client( + { + name: "unretained-evidence-overflow", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); @@ -230,7 +237,10 @@ it("bounds fallback when the retention error itself has oversized diagnostics", { inputSchema: z.object({}) }, async () => delivery.toErrorToolResult(refused.error, true), ); - const client = new Client({ name: "retention-overflow", version: "1" }); + const client = new Client( + { name: "retention-overflow", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); diff --git a/tests/boundary/mcp/exclusiveBoundIssuesMcp.test.ts b/tests/boundary/mcp/exclusiveBoundIssuesMcp.test.ts index af9294d8bb..b2f15125bf 100644 --- a/tests/boundary/mcp/exclusiveBoundIssuesMcp.test.ts +++ b/tests/boundary/mcp/exclusiveBoundIssuesMcp.test.ts @@ -5,13 +5,17 @@ import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { analysisViewLayoutEvidence } from "../../fixtures/analysisView.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const pageViewError = async (page: { offset: number; limit: number }) => { const session = createTestBinarySession(() => { throw new Error("inspect_analysis_view must not launch a provider"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "exclusive-bound-issues", version: "1" }); + const client = new Client( + { name: "exclusive-bound-issues", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/featureTraceViewsMcp.test.ts b/tests/boundary/mcp/featureTraceViewsMcp.test.ts index e176996729..54e76f01f3 100644 --- a/tests/boundary/mcp/featureTraceViewsMcp.test.ts +++ b/tests/boundary/mcp/featureTraceViewsMcp.test.ts @@ -371,7 +371,10 @@ it("refuses a selected view before tracing when the server retains no Evidence", throw new Error("No deep provider"); }); const server = createServer({ kind: "fixed", analysis: session }); - const client = new Client({ name: "feature-trace-fixed", version: "1" }); + const client = new Client( + { name: "feature-trace-fixed", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); onTestFinished(async () => { diff --git a/tests/boundary/mcp/firmwareMcp.test.ts b/tests/boundary/mcp/firmwareMcp.test.ts index 4e3b7761ab..c19404115a 100644 --- a/tests/boundary/mcp/firmwareMcp.test.ts +++ b/tests/boundary/mcp/firmwareMcp.test.ts @@ -8,6 +8,7 @@ import { firmwareFixture, assertFirmwareCleanup, } from "../../fixtures/firmware/provider.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const it = test.skipIf(process.platform !== "linux"); @@ -22,7 +23,10 @@ it("executes named firmware contracts with inline Evidence and no native binary firmwareAnalysis: fixture.provider, }, ); - const client = new Client({ name: "firmware-regression", version: "1" }); + const client = new Client( + { name: "firmware-regression", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/fixedEvidenceConsumersMcp.test.ts b/tests/boundary/mcp/fixedEvidenceConsumersMcp.test.ts index 7312a3fa99..44b5cf4057 100644 --- a/tests/boundary/mcp/fixedEvidenceConsumersMcp.test.ts +++ b/tests/boundary/mcp/fixedEvidenceConsumersMcp.test.ts @@ -18,6 +18,7 @@ import { toolContract } from "../../../src/contracts/toolContracts.js"; import { parseEvidence } from "../../../src/domain/evidence.js"; import { createServer } from "../../../src/server/createServer.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; // These authenticated catalog examples are authored fixtures, not real-provider // verification. Their complete requests fit the default 1,024-element policy; @@ -151,7 +152,10 @@ const server = createServer( }, }, ); -const client = new Client({ name: "fixed-evidence-fixtures", version: "1" }); +const client = new Client( + { name: "fixed-evidence-fixtures", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, +); beforeAll(async () => { const [clientTransport, serverTransport] = diff --git a/tests/boundary/mcp/fridaLifecycleMcp.test.ts b/tests/boundary/mcp/fridaLifecycleMcp.test.ts index 0f8f5a8ab6..2586468272 100644 --- a/tests/boundary/mcp/fridaLifecycleMcp.test.ts +++ b/tests/boundary/mcp/fridaLifecycleMcp.test.ts @@ -46,6 +46,7 @@ import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { phaseGate } from "../../support/lifecycleHarness.js"; import { waitFor } from "../../support/testWait.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const nativeFixture = () => { const created: string[] = []; @@ -204,7 +205,10 @@ const connectedFixture = async () => { { kind: "session", session }, { fridaInstrumentation: manager }, ); - const client = new Client({ name: "frida-lifecycle", version: "1" }); + const client = new Client( + { name: "frida-lifecycle", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { native.controls.detachFailures = 0; native.controls.removalFailures = 0; @@ -793,10 +797,13 @@ const callPartialFridaLoadError = async ( { frida: new FridaInstrumentationService(provider) }, { logger: silentLogger, recordEvidence }, ); - const client = new Client({ - name: "frida-partial-probe-client", - version: "1", - }); + const client = new Client( + { + name: "frida-partial-probe-client", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); diff --git a/tests/boundary/mcp/functionComparisonReferenceFactsMcp.test.ts b/tests/boundary/mcp/functionComparisonReferenceFactsMcp.test.ts index da12bbdb86..4aaf3e3b35 100644 --- a/tests/boundary/mcp/functionComparisonReferenceFactsMcp.test.ts +++ b/tests/boundary/mcp/functionComparisonReferenceFactsMcp.test.ts @@ -21,6 +21,7 @@ import { functionDossierSchema } from "../../../src/domain/native/functionDossie import { reconstructionVerificationResultSchema } from "../../../src/domain/reconstructionVerificationSchemas.js"; import { createApplicationMcpHarness } from "../../fixtures/applicationMcpHarness.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const example = FUNCTION_COMPARISON_EXAMPLE.left; const dossier = functionDossierSchema.parse(example.normalized_result); @@ -1034,7 +1035,10 @@ it("distinguishes same-entry renames from different entries through retained MCP name: "comparison-schema", version: "1", }); - const schemaClient = new Client({ name: "comparison-schema", version: "1" }); + const schemaClient = new Client( + { name: "comparison-schema", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); onTestFinished(async () => { diff --git a/tests/boundary/mcp/gdbCancellationMcp.test.ts b/tests/boundary/mcp/gdbCancellationMcp.test.ts index c263b09193..c7e72aa719 100644 --- a/tests/boundary/mcp/gdbCancellationMcp.test.ts +++ b/tests/boundary/mcp/gdbCancellationMcp.test.ts @@ -39,6 +39,7 @@ import { fakeGdbModeledReplies, fakeGdbStartupPreamble, } from "../providers/gdbTestHelpers.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.skipIf(process.platform === "win32")( "keeps a failed GDB startup closed through MCP and retries its retained owner before console admission", @@ -83,7 +84,10 @@ process.stdin.on("data", (chunk) => { }, }); const server = gdbMcpServer("gdb-startup-readiness", manager); - const client = new Client({ name: "gdb-startup-readiness", version: "1" }); + const client = new Client( + { name: "gdb-startup-readiness", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -192,7 +196,10 @@ process.stdin.on("data", async (chunk) => { }, }); const server = gdbMcpServer("gdb-cancellation", manager); - const client = new Client({ name: "gdb-cancellation", version: "1" }); + const client = new Client( + { name: "gdb-cancellation", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -291,7 +298,10 @@ process.stdin.on("data", (chunk) => { environment: { REA_GDB_COMMAND: provider }, }); const server = gdbMcpServer("gdb-inferior-tty", manager); - const client = new Client({ name: "gdb-inferior-tty", version: "1" }); + const client = new Client( + { name: "gdb-inferior-tty", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -378,7 +388,10 @@ process.stdin.on("data", (chunk) => { environment: { REA_GDB_COMMAND: provider }, }); const server = gdbMcpServer("gdb-mi-utf8", manager); - const client = new Client({ name: "gdb-mi-utf8", version: "1" }); + const client = new Client( + { name: "gdb-mi-utf8", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -497,7 +510,10 @@ it("records partial GDB Evidence from an MCP command error", async () => { return ok("added"); }, }); - const client = new Client({ name: "gdb-partial-evidence", version: "1" }); + const client = new Client( + { name: "gdb-partial-evidence", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -550,7 +566,10 @@ it("recovers only the owning debugger cleanup and reopens admitted analysis", as retryCleanupFailures: async () => ok(null), } satisfies GdbToolOptions["manager"]; const server = gdbMcpServer("gdb-owned-cleanup", manager, analysisSession); - const client = new Client({ name: "gdb-owned-cleanup", version: "1" }); + const client = new Client( + { name: "gdb-owned-cleanup", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -660,10 +679,13 @@ it("records partial GDB startup Evidence from an MCP start error", async () => { }, }, ); - const client = new Client({ - name: "gdb-startup-partial-evidence", - version: "1", - }); + const client = new Client( + { + name: "gdb-startup-partial-evidence", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/gdbCloseDisposition.test.ts b/tests/boundary/mcp/gdbCloseDisposition.test.ts index c15ef2ae4f..2cd4da7e7f 100644 --- a/tests/boundary/mcp/gdbCloseDisposition.test.ts +++ b/tests/boundary/mcp/gdbCloseDisposition.test.ts @@ -11,6 +11,7 @@ import { toolContract } from "../../../src/contracts/toolContracts.js"; import { GdbSessionManager } from "../../../src/gdb/GdbSessionManager.js"; import { gdbMcpServer } from "../../fixtures/debuggerMcp.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.skipIf(process.platform === "win32").each(["kill", "detach"])( "retains a valid GDB session through disposition refusal and explicit %s recovery", @@ -57,7 +58,10 @@ createInterface({ input: process.stdin }).on('line', line => { onTestFinished(() => manager.closeAll()); const server = gdbMcpServer("gdb-disposition-test", manager); onTestFinished(() => server.close()); - const client = new Client({ name: "gdb-disposition-test", version: "1" }); + const client = new Client( + { name: "gdb-disposition-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); diff --git a/tests/boundary/mcp/generatedToolCatalog.test.ts b/tests/boundary/mcp/generatedToolCatalog.test.ts index 7e05f238e5..cb5eec620d 100644 --- a/tests/boundary/mcp/generatedToolCatalog.test.ts +++ b/tests/boundary/mcp/generatedToolCatalog.test.ts @@ -9,6 +9,7 @@ import { localInputReferences, recursiveReferences, } from "../../fixtures/mcpAdvertisedSchemaValidity.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; import { GENERATED_MCP_TOOL_CATALOG } from "../../fixtures/mcpToolCatalog.js"; // The generated catalog is built on the POSIX build host; live advertisement @@ -25,7 +26,10 @@ it("ships input schemas without local references in the generated catalog", () = it("generates the catalog the MCP server advertises", async () => { const server = new McpServer({ name: "generated-catalog", version: "0" }); - const client = new Client({ name: "generated-catalog", version: "0" }); + const client = new Client( + { name: "generated-catalog", version: "0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); for (const contract of TOOL_CONTRACTS) diff --git a/tests/boundary/mcp/ghidraInventoryMcp.test.ts b/tests/boundary/mcp/ghidraInventoryMcp.test.ts index 60f12c5751..626ec374bb 100644 --- a/tests/boundary/mcp/ghidraInventoryMcp.test.ts +++ b/tests/boundary/mcp/ghidraInventoryMcp.test.ts @@ -25,6 +25,7 @@ import { AnalysisProviderRegistry } from "../../../src/application/binary/Analys import { createServer } from "../../../src/server/createServer.js"; import { waitForExit } from "../../support/process/processFixture.js"; import { GhidraSessionError } from "../../../src/ghidra/GhidraSessionError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("delivers a complete Ghidra inventory within the existing MCP response budget", async () => { const items = Array.from({ length: 30_000 }, (_, index) => ({ @@ -293,7 +294,10 @@ it("searches bytes through MCP and the socket bridge with pagination and skipped { kind: "session", session }, { logger: silentLogger }, ); - const client = new Client({ name: "byte-search", version: "1" }); + const client = new Client( + { name: "byte-search", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/ghidraProfileRefusalMcp.test.ts b/tests/boundary/mcp/ghidraProfileRefusalMcp.test.ts index cda019642c..eb926566c8 100644 --- a/tests/boundary/mcp/ghidraProfileRefusalMcp.test.ts +++ b/tests/boundary/mcp/ghidraProfileRefusalMcp.test.ts @@ -12,6 +12,7 @@ import { silentLogger } from "../../../src/logger.js"; import { createServer } from "../../../src/server/createServer.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { ghidraInstallationHost } from "./ghidraMcpHarness.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const REFUSAL = "Processor or compiler specification overrides cannot replace the admitted raw-binary import."; @@ -43,7 +44,10 @@ const openRawArm = async (languageId: string | undefined) => { { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "profile-refusal", version: "1.0.0" }); + const mcp = new Client( + { name: "profile-refusal", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/ghidraReopen.test.ts b/tests/boundary/mcp/ghidraReopen.test.ts index 2690a795d6..17e396e18f 100644 --- a/tests/boundary/mcp/ghidraReopen.test.ts +++ b/tests/boundary/mcp/ghidraReopen.test.ts @@ -25,6 +25,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { waitForExit } from "../../support/process/processFixture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const fixturePath = fileURLToPath( new URL("../../fixtures/fakeGhidra.mjs", import.meta.url), @@ -169,7 +170,10 @@ const connectGhidra = async () => { { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "ghidra-reopen", version: "1.0.0" }); + const mcp = new Client( + { name: "ghidra-reopen", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const close = async () => { diff --git a/tests/boundary/mcp/ghidraStartupCancellationMcp.test.ts b/tests/boundary/mcp/ghidraStartupCancellationMcp.test.ts index b8560a2454..4e28424879 100644 --- a/tests/boundary/mcp/ghidraStartupCancellationMcp.test.ts +++ b/tests/boundary/mcp/ghidraStartupCancellationMcp.test.ts @@ -16,6 +16,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { GhidraFixtureLauncher } from "../providers/ghidra/ghidraClient.fixture.js"; import { waitFor } from "../../support/testWait.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.each([0, 1])( "releases cancelled MCP startup caller %s while its peer completes and stays warm", @@ -80,7 +81,10 @@ it.each([0, 1])( { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "ghidra-shared-startup", version: "1.0.0" }); + const mcp = new Client( + { name: "ghidra-shared-startup", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const controllers = [new AbortController(), new AbortController()]; diff --git a/tests/boundary/mcp/guidanceMcp.test.ts b/tests/boundary/mcp/guidanceMcp.test.ts index 9fed9df778..cad41d83b9 100644 --- a/tests/boundary/mcp/guidanceMcp.test.ts +++ b/tests/boundary/mcp/guidanceMcp.test.ts @@ -10,6 +10,7 @@ import { EvidenceMcpServer } from "../../../src/server/EvidenceMcpServer.js"; import { registerServiceTools } from "../../../src/server/serviceToolBindings.js"; import { silentLogger } from "../../../src/logger.js"; import { ToolResultDelivery } from "../../../src/server/ToolResultDelivery.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const open: { client: Client; @@ -60,7 +61,10 @@ it("advertises strict provider-free contracts and returns packaged guide results }, }, ); - const client = new Client({ name: "guidance-client", version: "1" }); + const client = new Client( + { name: "guidance-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); diff --git a/tests/boundary/mcp/hostRestrictedAvailabilityMcp.test.ts b/tests/boundary/mcp/hostRestrictedAvailabilityMcp.test.ts index 6c46077885..d1f5e82d62 100644 --- a/tests/boundary/mcp/hostRestrictedAvailabilityMcp.test.ts +++ b/tests/boundary/mcp/hostRestrictedAvailabilityMcp.test.ts @@ -9,6 +9,7 @@ import { sessionOutputSchemas } from "../../../src/contracts/toolOutputSchemaGro import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; /** Each tool with the host its execution check admits. */ const HOST_RESTRICTED_TOOLS = [ @@ -63,10 +64,13 @@ const connect = async ( ...options, }, ); - const client = new Client({ - name: "host-restricted-availability", - version: "1", - }); + const client = new Client( + { + name: "host-restricted-availability", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); diff --git a/tests/boundary/mcp/investigationAnalysisMcp.test.ts b/tests/boundary/mcp/investigationAnalysisMcp.test.ts index fe68cacac1..9b8a289509 100644 --- a/tests/boundary/mcp/investigationAnalysisMcp.test.ts +++ b/tests/boundary/mcp/investigationAnalysisMcp.test.ts @@ -27,6 +27,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { observed } from "../../fixtures/analysisExecution.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import type { RelationshipCoverage } from "../../../src/domain/relationshipCoverage.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("aggregates comparison Evidence and records an approved runtime gap", async () => { const { session, server, client } = await connected(); @@ -134,7 +135,10 @@ it("keeps call-path publication ahead of close_binary record draining", async () close: () => Promise.resolve(resultOk(null)), })); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "investigation-close-race", version: "1" }); + const client = new Client( + { name: "investigation-close-race", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const callPathPreparation = phaseGate(); @@ -616,7 +620,10 @@ const connected = async (analysis?: AnalysisOperationPort) => { close: () => Promise.resolve(resultOk(null)), })); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "investigation-test", version: "1" }); + const client = new Client( + { name: "investigation-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); diff --git a/tests/boundary/mcp/investigationEvidenceReferencesMcp.test.ts b/tests/boundary/mcp/investigationEvidenceReferencesMcp.test.ts index ad66987649..1eb845a519 100644 --- a/tests/boundary/mcp/investigationEvidenceReferencesMcp.test.ts +++ b/tests/boundary/mcp/investigationEvidenceReferencesMcp.test.ts @@ -27,6 +27,7 @@ import { functionDossierSchema } from "../../../src/domain/native/functionDossie import { createApplicationMcpHarness } from "../../fixtures/applicationMcpHarness.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const reference = (source: Evidence) => ({ kind: "retained-evidence" as const, @@ -205,10 +206,13 @@ it("reports missing or wrong-kind records without recording a successful workflo }); it("reports missing sources for a retained dossier with a large link set", async () => { - const client = new Client({ - name: "large-evidence-links-test", - version: "1", - }); + const client = new Client( + { + name: "large-evidence-links-test", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); await client.connect( new StdioClientTransport({ diff --git a/tests/boundary/mcp/javascriptRecoveryMcp.test.ts b/tests/boundary/mcp/javascriptRecoveryMcp.test.ts index 60817a2c05..6f1b4386be 100644 --- a/tests/boundary/mcp/javascriptRecoveryMcp.test.ts +++ b/tests/boundary/mcp/javascriptRecoveryMcp.test.ts @@ -16,6 +16,7 @@ import { assertRecoveryCleanup, recoveryFixture, } from "../../fixtures/javascript-recovery/provider.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it .skipIf(process.platform !== "linux" || process.arch !== "x64") @@ -32,7 +33,10 @@ it javascriptRecovery: fixture.provider, }, ); - const client = new Client({ name: "recovery-contract", version: "1" }); + const client = new Client( + { name: "recovery-contract", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); @@ -111,7 +115,10 @@ it.skipIf(process.platform !== "linux" || process.arch !== "x64")( javascriptRecovery: fixture.provider, }, ); - const client = new Client({ name: "recovery-denied", version: "1" }); + const client = new Client( + { name: "recovery-denied", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/javascriptRuntimeObservationMcp.test.ts b/tests/boundary/mcp/javascriptRuntimeObservationMcp.test.ts index 3be527c855..bed493de9c 100644 --- a/tests/boundary/mcp/javascriptRuntimeObservationMcp.test.ts +++ b/tests/boundary/mcp/javascriptRuntimeObservationMcp.test.ts @@ -25,6 +25,7 @@ import { parseMcpEvidenceBundle } from "../../fixtures/mcpEvidenceBundle.js"; import { observed } from "../../fixtures/analysisExecution.js"; import { startFakeV8Inspector } from "../../fixtures/inspector/fakeV8Inspector.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; describe("JavaScript runtime observation MCP tools", () => { const resources: Array<{ close(): Promise }> = []; @@ -46,7 +47,10 @@ function registerRuntimeParameterContract( throw new Error("No provider expected"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "runtime-parameter-test", version: "1" }); + const client = new Client( + { name: "runtime-parameter-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); resources.push(client, server, session); await server.connect(st); @@ -332,7 +336,10 @@ const createObservationClient = async ( }), }, ); - const client = new Client({ name: "v8-mcp-test", version: "1" }); + const client = new Client( + { name: "v8-mcp-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server, session); diff --git a/tests/boundary/mcp/kunaCloseRetryMcp.test.ts b/tests/boundary/mcp/kunaCloseRetryMcp.test.ts index 3e4e00f809..5ba8d2804b 100644 --- a/tests/boundary/mcp/kunaCloseRetryMcp.test.ts +++ b/tests/boundary/mcp/kunaCloseRetryMcp.test.ts @@ -17,6 +17,7 @@ import { session as kunaSession, unprovenCleanupLauncher, } from "../providers/kuna/kunaSessionFixture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const it = test.skipIf(process.platform === "win32"); @@ -50,7 +51,10 @@ it("names the same-connection close_binary retry for an unproven Kuna export sto { kind: "session", session }, { logger: silentLogger }, ); - const client = new Client({ name: "kuna-close-retry", version: "1" }); + const client = new Client( + { name: "kuna-close-retry", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); diff --git a/tests/boundary/mcp/largeToolResult.test.ts b/tests/boundary/mcp/largeToolResult.test.ts index 1bc9343187..4580ac97a5 100644 --- a/tests/boundary/mcp/largeToolResult.test.ts +++ b/tests/boundary/mcp/largeToolResult.test.ts @@ -40,6 +40,7 @@ import { } from "../../../src/server/toolResultEncoding.js"; import { EvidenceMcpServer } from "../../../src/server/EvidenceMcpServer.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const delivery = createToolResultDelivery(STDIO_DEFAULT_MAX_BUFFER_SIZE); @@ -86,7 +87,10 @@ const callPseudoCode = async ( }, { logger: silentLogger, recordEvidence, withAdmittedAnalysis }, ); - const client = new Client({ name: "complete-evidence-client", version: "1" }); + const client = new Client( + { name: "complete-evidence-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const send = serverTransport.send.bind(serverTransport); diff --git a/tests/boundary/mcp/lateAbortApplicationEvidenceMcp.test.ts b/tests/boundary/mcp/lateAbortApplicationEvidenceMcp.test.ts index 8cf954be2d..5baab6b9de 100644 --- a/tests/boundary/mcp/lateAbortApplicationEvidenceMcp.test.ts +++ b/tests/boundary/mcp/lateAbortApplicationEvidenceMcp.test.ts @@ -12,6 +12,7 @@ import type { BrowserObservationPort } from "../../../src/ports/BrowserObservati import type { BrowserTargetList } from "../../../src/domain/browserObservationSchemas.js"; import type { JavaScriptRuntimeTargetList } from "../../../src/domain/javascript/javascriptRuntimeObservation.js"; import { waitFor } from "../../support/testWait.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("retains late-cancelled Go artifact Evidence through MCP and keeps the server usable", async () => { const goInspection = phaseGate(); @@ -41,7 +42,10 @@ it("retains late-cancelled Go artifact Evidence through MCP and keeps the server { kind: "session", session }, { logger: silentLogger, goBinary: service }, ); - const client = new Client({ name: "late-abort-artifact", version: "1" }); + const client = new Client( + { name: "late-abort-artifact", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); onTestFinished(async () => { @@ -103,7 +107,10 @@ it("retains late-cancelled Inspector target Evidence through MCP and keeps the s { kind: "session", session }, { logger: silentLogger, javascriptRuntimeObservation: provider }, ); - const client = new Client({ name: "late-abort-inspector", version: "1" }); + const client = new Client( + { name: "late-abort-inspector", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); onTestFinished(async () => { @@ -188,7 +195,10 @@ it("records late-cancelled Browser target Evidence and keeps the server usable", { kind: "session", session }, { logger: silentLogger, browserObservation: browser }, ); - const client = new Client({ name: "late-abort-browser", version: "1" }); + const client = new Client( + { name: "late-abort-browser", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); onTestFinished(async () => { diff --git a/tests/boundary/mcp/mcpSchemaValidation.test.ts b/tests/boundary/mcp/mcpSchemaValidation.test.ts index 02935a6cf1..45f3a4866f 100644 --- a/tests/boundary/mcp/mcpSchemaValidation.test.ts +++ b/tests/boundary/mcp/mcpSchemaValidation.test.ts @@ -1,6 +1,9 @@ import { AjvJsonSchemaValidator } from "@modelcontextprotocol/client/validators/ajv"; import { expect, it, vi } from "vitest"; -import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; +import { + createMcpSchemaValidation, + SHARED_COMPILED_VALIDATORS, +} from "../../fixtures/mcpSchemaValidation.js"; it("compiles a listed tool's validator only when it first validates", () => { // The SDK requests a validator for every listed tool before its first call. @@ -23,6 +26,54 @@ it("compiles a listed tool's validator only when it first validates", () => { } }); +it("shares compiled validators across fixtures and evicts the least recently used", () => { + const compile = vi.spyOn(AjvJsonSchemaValidator.prototype, "getValidator"); + const first = createMcpSchemaValidation(); + const second = createMcpSchemaValidation(); + // A per-test title keeps schemas compiled by other tests in this worker + // out of the shared cache counts. + const nonce = crypto.randomUUID(); + const schema = (index: number) => ({ + title: `${nonce}-${index}`, + type: "integer", + }); + try { + expect(first.getValidator(schema(0))(1).valid).toBe(true); + expect(compile).toHaveBeenCalledTimes(1); + // Another fixture, and the same fixture after clear(), reuse the result. + expect(second.getValidator(schema(0))("one").valid).toBe(false); + first.clear(); + expect(first.getValidator(schema(0))(2).valid).toBe(true); + expect(compile).toHaveBeenCalledTimes(1); + + // Fill the remaining capacity, touch the oldest entry, then overflow: + // the least recently used entry (schema 1) goes, schema 0 stays. + for (let index = 1; index < SHARED_COMPILED_VALIDATORS; index += 1) { + expect(first.getValidator(schema(index))(index).valid).toBe(true); + } + expect(compile).toHaveBeenCalledTimes(SHARED_COMPILED_VALIDATORS); + // A fixture's own validator keeps its compiled function, so a new fixture + // is what reaches the shared cache again. + const touch = createMcpSchemaValidation(); + expect(touch.getValidator(schema(0))(3).valid).toBe(true); + touch.clear(); + expect( + second.getValidator(schema(SHARED_COMPILED_VALIDATORS))(4).valid, + ).toBe(true); + expect(compile).toHaveBeenCalledTimes(SHARED_COMPILED_VALIDATORS + 1); + const fresh = createMcpSchemaValidation(); + expect(fresh.getValidator(schema(0))(5).valid).toBe(true); + expect(compile).toHaveBeenCalledTimes(SHARED_COMPILED_VALIDATORS + 1); + expect(fresh.getValidator(schema(1))(6).valid).toBe(true); + expect(compile).toHaveBeenCalledTimes(SHARED_COMPILED_VALIDATORS + 2); + fresh.clear(); + } finally { + compile.mockRestore(); + first.clear(); + second.clear(); + } +}); + it("reuses equal schemas and recompiles changed schemas sharing an id", () => { const validation = createMcpSchemaValidation(); try { diff --git a/tests/boundary/mcp/nativeCallObservationMcp.test.ts b/tests/boundary/mcp/nativeCallObservationMcp.test.ts index ca1b6dc091..4a70c057a2 100644 --- a/tests/boundary/mcp/nativeCallObservationMcp.test.ts +++ b/tests/boundary/mcp/nativeCallObservationMcp.test.ts @@ -18,6 +18,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { NativeFixtureRunner } from "../../fixtures/nativeCommands.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; /** A thin little-endian arm64 MH_EXECUTE header with no load commands. */ const machoHeader = (): Buffer => { @@ -113,7 +114,10 @@ it("routes observe_native_calls through MCP with schema-checked input and output ), ); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "native-calls-mcp-test", version: "1" }); + const client = new Client( + { name: "native-calls-mcp-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -310,10 +314,13 @@ it.each([ ), ); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "native-calls-partial-mcp-test", - version: "1", - }); + const client = new Client( + { + name: "native-calls-partial-mcp-test", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/nativeDispatchAvailability.test.ts b/tests/boundary/mcp/nativeDispatchAvailability.test.ts index de2d2026c5..a8458b6959 100644 --- a/tests/boundary/mcp/nativeDispatchAvailability.test.ts +++ b/tests/boundary/mcp/nativeDispatchAvailability.test.ts @@ -29,6 +29,7 @@ import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { NativeFixtureRunner } from "../../fixtures/nativeCommands.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { createSessionMcpHarness } from "./sessionMcpHarness.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const resources: Array<{ close(): Promise }> = []; @@ -312,7 +313,10 @@ const connectUnconfiguredSymbolFallback = async ( { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "native-dispatch-fallback", version: "1" }); + const mcp = new Client( + { name: "native-dispatch-fallback", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, { close: () => session.close() }); diff --git a/tests/boundary/mcp/nativeDispatchBoundTarget.test.ts b/tests/boundary/mcp/nativeDispatchBoundTarget.test.ts index 163de3508b..054803adae 100644 --- a/tests/boundary/mcp/nativeDispatchBoundTarget.test.ts +++ b/tests/boundary/mcp/nativeDispatchBoundTarget.test.ts @@ -10,6 +10,7 @@ import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { localToolsMcpEnvironment } from "../../fixtures/localToolsMcp.js"; import { objcRecordBudgetMacho } from "../../fixtures/objcRecordBudgetMacho.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; type Replacement = "missing" | "directory" | "loop" | "unreadable"; @@ -36,7 +37,10 @@ const inspectReplacements = async (replacements: readonly Replacement[]) => { env[key] = directory; await mkdir(directory); } - const client = new Client({ name: "dispatch-bound-target", version: "1" }); + const client = new Client( + { name: "dispatch-bound-target", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const transport = new StdioClientTransport({ command: process.execPath, args: [resolve("scripts/rea.mjs"), "mcp"], diff --git a/tests/boundary/mcp/nativeInputContracts.test.ts b/tests/boundary/mcp/nativeInputContracts.test.ts index b5eb717b65..4246c47383 100644 --- a/tests/boundary/mcp/nativeInputContracts.test.ts +++ b/tests/boundary/mcp/nativeInputContracts.test.ts @@ -8,6 +8,7 @@ import type { JsonValue } from "../../../src/domain/jsonValue.js"; import { ok } from "../../../src/domain/result.js"; import { createAnalysisExecution } from "../../../src/ports/AnalysisProvider.js"; import { createServer } from "../../../src/server/createServer.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const provider = { id: "fixture-native", @@ -36,7 +37,10 @@ const connect = async ( execute: AnalysisOperationPort["execute"], ): Promise => { const server = createServer({ kind: "fixed", analysis: { execute } }); - const client = new Client({ name: "native-contract-test", version: "1" }); + const client = new Client( + { name: "native-contract-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); diff --git a/tests/boundary/mcp/nativeInstructionReferencesView.test.ts b/tests/boundary/mcp/nativeInstructionReferencesView.test.ts index 64a6864898..71f919a637 100644 --- a/tests/boundary/mcp/nativeInstructionReferencesView.test.ts +++ b/tests/boundary/mcp/nativeInstructionReferencesView.test.ts @@ -298,10 +298,13 @@ it("recovers the complete parent when a single reference exceeds the page budget const retained = session.recordEvidence(parent); if (!retained.ok) throw retained.error; const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "oversized-instruction-reference", - version: "1", - }); + const client = new Client( + { + name: "oversized-instruction-reference", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/nativeInventoryViewsMcp.test.ts b/tests/boundary/mcp/nativeInventoryViewsMcp.test.ts index 0b1b6eb8f8..2591bdba1d 100644 --- a/tests/boundary/mcp/nativeInventoryViewsMcp.test.ts +++ b/tests/boundary/mcp/nativeInventoryViewsMcp.test.ts @@ -17,6 +17,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { connectGhidraMcp } from "./ghidraMcpHarness.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const procedureRows = [ { @@ -277,10 +278,13 @@ it("refuses summary before provider work when no retaining session is configured }, }, }); - const client = new Client({ - name: "unretained-native-summary", - version: "1", - }); + const client = new Client( + { + name: "unretained-native-summary", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); @@ -327,7 +331,10 @@ it("projects imported inventories with an unknown artifact without inventing a p const recorded = session.recordEvidence(source); if (!recorded.ok) throw recorded.error; const server = createServer({ kind: "session", session }); - const client = new Client({ name: "unbound-native-views", version: "1" }); + const client = new Client( + { name: "unbound-native-views", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/nativeLoadImageViewsMcp.test.ts b/tests/boundary/mcp/nativeLoadImageViewsMcp.test.ts index 65d8de4b3f..9124d41eb9 100644 --- a/tests/boundary/mcp/nativeLoadImageViewsMcp.test.ts +++ b/tests/boundary/mcp/nativeLoadImageViewsMcp.test.ts @@ -12,6 +12,7 @@ import { nativeRawLoadImageFixture, } from "../../fixtures/nativeLoadImage.js"; import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("preserves raw and DOL verification facts and selected DOL sections through the advertised SDK output", async () => { const { call } = await connectLocalToolsMcp(); @@ -118,7 +119,10 @@ it("delivers load-image summaries from the complete retained public-tool observa close: async () => ok(null), })); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "load-image-summary", version: "1" }); + const client = new Client( + { name: "load-image-summary", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/nativeObservationViewsMcp.test.ts b/tests/boundary/mcp/nativeObservationViewsMcp.test.ts index 78d2493b5b..aa4de32d8e 100644 --- a/tests/boundary/mcp/nativeObservationViewsMcp.test.ts +++ b/tests/boundary/mcp/nativeObservationViewsMcp.test.ts @@ -194,10 +194,13 @@ it("follows native overflow continuations through MCP without repeating provider { kind: "session", session }, { delivery: createToolResultDelivery(32 * 1024) }, ); - const client = new Client({ - name: "native-observation-capacity", - version: "1", - }); + const client = new Client( + { + name: "native-observation-capacity", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/nativeSignatureTargetBindingMcp.test.ts b/tests/boundary/mcp/nativeSignatureTargetBindingMcp.test.ts index 8d1b137a98..8c2b47dd77 100644 --- a/tests/boundary/mcp/nativeSignatureTargetBindingMcp.test.ts +++ b/tests/boundary/mcp/nativeSignatureTargetBindingMcp.test.ts @@ -16,6 +16,7 @@ import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { NativeFixtureRunner } from "../../fixtures/nativeCommands.js"; import { toolContract } from "../../../src/contracts/toolContracts.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("keeps a failed snapshot descriptor and root together through MCP close and recovery", async () => { const root = await createTestTempDirectory("rea-signature-order-mcp-"); @@ -46,7 +47,10 @@ it("keeps a failed snapshot descriptor and root together through MCP close and r kind: "session", session: createTestBinarySession(provider), }); - const client = new Client({ name: "signature-order-test", version: "1" }); + const client = new Client( + { name: "signature-order-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const original = OwnedFileHandle.prototype.close; @@ -144,7 +148,10 @@ it.each(["mach-o", "mach-o-universal"] as const)( new NativeMacOSProvider({}, new NativeFixtureRunner(), "darwin"), ); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "signature-binding-test", version: "1" }); + const client = new Client( + { name: "signature-binding-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/nativeUiFactsMcp.test.ts b/tests/boundary/mcp/nativeUiFactsMcp.test.ts index 343fb7e1e7..bbe1e0c497 100644 --- a/tests/boundary/mcp/nativeUiFactsMcp.test.ts +++ b/tests/boundary/mcp/nativeUiFactsMcp.test.ts @@ -14,6 +14,7 @@ import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { NativeFixtureRunner } from "../../fixtures/nativeCommands.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const scope = { pid: 123, @@ -51,7 +52,10 @@ const connectNativeUi = async () => { new NativeMacOSProvider({}, new NativeFixtureRunner(), "darwin"), ); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "native-ui-facts", version: "1" }); + const client = new Client( + { name: "native-ui-facts", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); onTestFinished(async () => { factory.mockRestore(); diff --git a/tests/boundary/mcp/nativeUiFinalizationMcp.test.ts b/tests/boundary/mcp/nativeUiFinalizationMcp.test.ts index 62a60a022a..266d46e078 100644 --- a/tests/boundary/mcp/nativeUiFinalizationMcp.test.ts +++ b/tests/boundary/mcp/nativeUiFinalizationMcp.test.ts @@ -10,6 +10,7 @@ import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { NativeFixtureRunner } from "../../fixtures/nativeCommands.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.each([false, true])( "retains native UI reports over MCP when its deadline expires during close (cleanup fails: %s)", @@ -55,7 +56,10 @@ it.each([false, true])( new NativeMacOSProvider({}, new NativeFixtureRunner(), "darwin"), ); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "native-ui-finalization", version: "1" }); + const client = new Client( + { name: "native-ui-finalization", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/nativeUiPartialCallRoutesMcp.test.ts b/tests/boundary/mcp/nativeUiPartialCallRoutesMcp.test.ts index e72aede1d7..e116246288 100644 --- a/tests/boundary/mcp/nativeUiPartialCallRoutesMcp.test.ts +++ b/tests/boundary/mcp/nativeUiPartialCallRoutesMcp.test.ts @@ -22,6 +22,7 @@ import { jsonValueSchema } from "../../../src/domain/jsonValue.js"; import { err, ok, type Result } from "../../../src/domain/result.js"; import { createServer } from "../../../src/server/createServer.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const identity = { id: "typed", name: "Typed provider", version: "1" }; const fallback = { id: "fallback", name: "Fallback provider", version: "1" }; @@ -227,7 +228,10 @@ function publicTrace(plan: Plan, maxNodes = 12, maxEdges = 500) { }, }; const server = createServer({ kind: "fixed", analysis }); - const client = new Client({ name: "native-ui-partial-routes", version: "1" }); + const client = new Client( + { name: "native-ui-partial-routes", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push({ diff --git a/tests/boundary/mcp/nativeValueTraceCleanupIncomplete.test.ts b/tests/boundary/mcp/nativeValueTraceCleanupIncomplete.test.ts index 63e97cf73d..aefc48ecce 100644 --- a/tests/boundary/mcp/nativeValueTraceCleanupIncomplete.test.ts +++ b/tests/boundary/mcp/nativeValueTraceCleanupIncomplete.test.ts @@ -32,6 +32,7 @@ import { jsonResult, resources, } from "./enhancedToolsHarness.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; afterEach(closeEnhancedToolResources); @@ -274,7 +275,10 @@ const openSession = async (port: AnalysisOperationPort) => { }), }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "value-trace-cleanup", version: "1" }); + const client = new Client( + { name: "value-trace-cleanup", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); diff --git a/tests/boundary/mcp/nativeValueTraceCompleteness.test.ts b/tests/boundary/mcp/nativeValueTraceCompleteness.test.ts index 0bcbe06ae9..e79072688f 100644 --- a/tests/boundary/mcp/nativeValueTraceCompleteness.test.ts +++ b/tests/boundary/mcp/nativeValueTraceCompleteness.test.ts @@ -22,6 +22,7 @@ import { closeEnhancedToolResources, resources, } from "./enhancedToolsHarness.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; afterEach(closeEnhancedToolResources); @@ -43,7 +44,10 @@ const connectTraceSession = async ( { kind: "session", session }, { environment: { REA_MCP_OUTPUT_SCHEMA_PROFILE: profile } }, ); - const client = new Client({ name: "value-trace-test", version: "1.0.0" }); + const client = new Client( + { name: "value-trace-test", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); diff --git a/tests/boundary/mcp/nativeViewPredicateMcp.test.ts b/tests/boundary/mcp/nativeViewPredicateMcp.test.ts index 257592187a..8a640f1c8a 100644 --- a/tests/boundary/mcp/nativeViewPredicateMcp.test.ts +++ b/tests/boundary/mcp/nativeViewPredicateMcp.test.ts @@ -60,7 +60,10 @@ it.each(["compact"] as const)( environment: { ...process.env, REA_MCP_OUTPUT_SCHEMA_PROFILE: profile }, }, ); - const client = new Client({ name: "native-view-identity", version: "1" }); + const client = new Client( + { name: "native-view-identity", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const validation = createMcpSchemaValidation(); const [ct, st] = InMemoryTransport.createLinkedPair(); const root = await createTestTempDirectory("rea-native-view-identity-"); diff --git a/tests/boundary/mcp/navigationContextMcp.test.ts b/tests/boundary/mcp/navigationContextMcp.test.ts index 1af2bd1626..14f4ecbcf2 100644 --- a/tests/boundary/mcp/navigationContextMcp.test.ts +++ b/tests/boundary/mcp/navigationContextMcp.test.ts @@ -7,6 +7,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { observed } from "../../fixtures/analysisExecution.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const navigate = async ( selection: Readonly>, @@ -17,7 +18,10 @@ const navigate = async ( close: () => Promise.resolve(ok(null)), })); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "navigation-test", version: "1" }); + const client = new Client( + { name: "navigation-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/observationPartialEvidenceDelivery.test.ts b/tests/boundary/mcp/observationPartialEvidenceDelivery.test.ts index d6aaceb44c..e80ced4066 100644 --- a/tests/boundary/mcp/observationPartialEvidenceDelivery.test.ts +++ b/tests/boundary/mcp/observationPartialEvidenceDelivery.test.ts @@ -10,6 +10,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { observed } from "../../fixtures/analysisExecution.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const resources: Array<{ close(): Promise }> = []; const operations = [ @@ -111,10 +112,13 @@ it.each(operations)( }, }, ); - const client = new Client({ - name: "partial-observation-delivery", - version: "1", - }); + const client = new Client( + { + name: "partial-observation-delivery", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server, session); diff --git a/tests/boundary/mcp/officialArguments.test.ts b/tests/boundary/mcp/officialArguments.test.ts index 398dbf0b9d..2a2b5186e0 100644 --- a/tests/boundary/mcp/officialArguments.test.ts +++ b/tests/boundary/mcp/officialArguments.test.ts @@ -20,10 +20,14 @@ import { createBinarySessionTargets, createTestBinarySession, } from "../../fixtures/binarySession.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const connect = async (analysis: AnalysisOperationPort) => { const server = createServer({ kind: "fixed", analysis }); - const client = new Client({ name: "argument-parity", version: "1.0.0" }); + const client = new Client( + { name: "argument-parity", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/officialTools.test.ts b/tests/boundary/mcp/officialTools.test.ts index f1c86e38ff..d915ecb308 100644 --- a/tests/boundary/mcp/officialTools.test.ts +++ b/tests/boundary/mcp/officialTools.test.ts @@ -19,6 +19,7 @@ import { composeBinarySession } from "../../../src/application/binary/BinarySess import { AnalysisProviderRegistry } from "../../../src/application/binary/AnalysisProviderRegistry.js"; import { createBinarySessionTargets } from "../../fixtures/binarySession.js"; import { createApplicationMcpHarness } from "../../fixtures/applicationMcpHarness.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; interface Invocation { readonly name: string; @@ -129,7 +130,10 @@ afterEach(async () => { const connect = async (analysis: AnalysisOperationPort) => { const server = createServer({ kind: "fixed", analysis }); - const client = new Client({ name: "contract-test", version: "1.0.0" }); + const client = new Client( + { name: "contract-test", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); diff --git a/tests/boundary/mcp/outputSchemaProfile.test.ts b/tests/boundary/mcp/outputSchemaProfile.test.ts index cd770f6698..a94f2d65f4 100644 --- a/tests/boundary/mcp/outputSchemaProfile.test.ts +++ b/tests/boundary/mcp/outputSchemaProfile.test.ts @@ -21,6 +21,7 @@ import { resolveMcpOutputSchemaProfile, type McpOutputSchemaProfile, } from "../../../src/contracts/mcpSchemaPresentation.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const createServer = (outputSchemaProfile: McpOutputSchemaProfile) => new EvidenceMcpServer( @@ -39,7 +40,10 @@ it("omits only output schema advertisements and keeps canonical MCP output valid ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); - const client = new Client({ name: "schema-profile-test", version: "1" }); + const client = new Client( + { name: "schema-profile-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const contract = { ...toolContract("comment"), name: "output_schema_fixture", @@ -103,7 +107,10 @@ it("bounds output schema advertisements and keeps canonical MCP output validatio ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); - const client = new Client({ name: "compact-output-test", version: "1" }); + const client = new Client( + { name: "compact-output-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const contract = { ...toolContract("comment"), name: "compact_output_schema_fixture", @@ -184,7 +191,10 @@ it("keeps both output profiles below a measured one-megabyte frame", async () => const server = createServer(profile); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); - const client = new Client({ name: "catalog-size-test", version: "1" }); + const client = new Client( + { name: "catalog-size-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); for (const contract of TOOL_CONTRACTS) server.registerTool( contract.name, @@ -258,7 +268,10 @@ it("rejects canonical-invalid output that the reduced advertisement accepts", as const server = createServer("compact"); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); - const client = new Client({ name: "reduced-output-test", version: "1" }); + const client = new Client( + { name: "reduced-output-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const contract = { ...toolContract("comment"), name: "reduced_output_schema_fixture", @@ -353,7 +366,10 @@ it("omits output schemas by default and still delivers validated structured resu { kind: "session", session }, { environment: { HOME: process.env.HOME }, logger: silentLogger }, ); - const client = new Client({ name: "default-output-profile", version: "1" }); + const client = new Client( + { name: "default-output-profile", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/outputSchemaSemanticConstraints.test.ts b/tests/boundary/mcp/outputSchemaSemanticConstraints.test.ts index 3909537c1c..c5b7b360cd 100644 --- a/tests/boundary/mcp/outputSchemaSemanticConstraints.test.ts +++ b/tests/boundary/mcp/outputSchemaSemanticConstraints.test.ts @@ -22,6 +22,7 @@ import { toolRegistrationOptions } from "../../../src/server/toolRegistrationOpt import { verifyManagedNativeVerificationSource } from "../../../src/domain/managed/managedNativeVerification.js"; import { readManagedNativeVerificationSource } from "../../../src/domain/managed/managedNativeVerificationSource.js"; import { processCaptureSchema } from "../../../src/domain/process/processCapture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const record = (value: unknown): Record => { if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("Expected a schema object"); @@ -57,7 +58,10 @@ it("advertises semantic output invariants and keeps producers aligned with Zod", name: "output-schema-semantics", version: "1", }); - const client = new Client({ name: "output-schema-semantics", version: "1" }); + const client = new Client( + { name: "output-schema-semantics", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); for (const contract of contracts) diff --git a/tests/boundary/mcp/oversizedErrorDeliveryMcp.test.ts b/tests/boundary/mcp/oversizedErrorDeliveryMcp.test.ts index e660fe74db..905e49e332 100644 --- a/tests/boundary/mcp/oversizedErrorDeliveryMcp.test.ts +++ b/tests/boundary/mcp/oversizedErrorDeliveryMcp.test.ts @@ -14,6 +14,7 @@ import type { Evidence } from "../../../src/domain/evidence.js"; import { err, ok } from "../../../src/domain/result.js"; import { EvidenceMcpServer } from "../../../src/server/EvidenceMcpServer.js"; import { createToolResultDelivery } from "../../../src/server/toolResult.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const delivery = createToolResultDelivery(STDIO_DEFAULT_MAX_BUFFER_SIZE); const UNTRUSTED_TARGET_CONTENT = { @@ -63,7 +64,10 @@ const exerciseDeliveryFailure = async ( content: [{ type: "text", text: "still connected" }], }), ); - const client = new Client({ name: "oversized-error-client", version: "1" }); + const client = new Client( + { name: "oversized-error-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -199,7 +203,10 @@ it("retains an oversized failed-open receipt with its original error", async () false, ), ); - const client = new Client({ name: "oversized-open-client", version: "1" }); + const client = new Client( + { name: "oversized-open-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -253,7 +260,10 @@ it("delivers an error whose text fits although structured and text copies would server.registerTool("mid_failure", { inputSchema: z.object({}) }, async () => failureWithName(nameBytes), ); - const client = new Client({ name: "mid-sized-error-client", version: "1" }); + const client = new Client( + { name: "mid-sized-error-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -304,7 +314,10 @@ it("keeps the untrusted target-content marker on an oversized error's replacemen { inputSchema: z.object({ required: z.string() }) }, async (): Promise => ({ content: [] }), ); - const client = new Client({ name: "oversized-target-client", version: "1" }); + const client = new Client( + { name: "oversized-target-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -382,7 +395,10 @@ it.each([false, true])( async () => failureWithName(fittingName + 1, targetContent, boundaryDelivery), ); - const client = new Client({ name: "error-budget-client", version: "1" }); + const client = new Client( + { name: "error-budget-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/pcapMcp.test.ts b/tests/boundary/mcp/pcapMcp.test.ts index 0bd7c85264..ba3e1fa285 100644 --- a/tests/boundary/mcp/pcapMcp.test.ts +++ b/tests/boundary/mcp/pcapMcp.test.ts @@ -9,6 +9,7 @@ import { ok } from "../../../src/domain/result.js"; import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpEvidenceBundle } from "../../fixtures/mcpEvidenceBundle.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const identity = { id: "pcap", name: "Packet capture analysis", version: null }; @@ -99,7 +100,10 @@ it("advertises exact valid pcap schemas and records inline evidence through MCP" const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); - const client = new Client({ name: "pcap-boundary", version: "0.0.0" }); + const client = new Client( + { name: "pcap-boundary", version: "0.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); await client.connect(clientTransport); diff --git a/tests/boundary/mcp/pcapParentIssuePath.test.ts b/tests/boundary/mcp/pcapParentIssuePath.test.ts index cd294e844b..0f23afea83 100644 --- a/tests/boundary/mcp/pcapParentIssuePath.test.ts +++ b/tests/boundary/mcp/pcapParentIssuePath.test.ts @@ -6,6 +6,7 @@ import { createEvidence } from "../../../src/domain/evidence.js"; import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("locates malformed pcap parent fields beneath the analysis-view source", async () => { const target = { path: "example.pcap", sha256: "a".repeat(64), bytes: 24 }; @@ -69,7 +70,10 @@ it("locates malformed pcap parent fields beneath the analysis-view source", asyn throw new Error("provider must not run"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "pcap-parent-path-repro", version: "1" }); + const client = new Client( + { name: "pcap-parent-path-repro", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); await withVerifierCleanup(async () => { const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); diff --git a/tests/boundary/mcp/pcapWorkspaceAllocation.test.ts b/tests/boundary/mcp/pcapWorkspaceAllocation.test.ts index 8af2694036..9abe9f2545 100644 --- a/tests/boundary/mcp/pcapWorkspaceAllocation.test.ts +++ b/tests/boundary/mcp/pcapWorkspaceAllocation.test.ts @@ -14,6 +14,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; // POSIX fixtures use real mkdtemp under caller-controlled temporary parents. const it = test.skipIf(process.platform === "win32"); @@ -54,7 +55,10 @@ const inspectWith = async (allocate: Allocate, path: string) => { { kind: "session", session }, { pcapAnalysis: provider }, ); - const client = new Client({ name: "pcap-workspace-test", version: "1" }); + const client = new Client( + { name: "pcap-workspace-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); onTestFinished(() => diff --git a/tests/boundary/mcp/processCleanupRetryMcp.test.ts b/tests/boundary/mcp/processCleanupRetryMcp.test.ts index e024c7179e..7f28f3694d 100644 --- a/tests/boundary/mcp/processCleanupRetryMcp.test.ts +++ b/tests/boundary/mcp/processCleanupRetryMcp.test.ts @@ -23,6 +23,7 @@ import { import { silentLogger } from "../../../src/logger.js"; import { createServer } from "../../../src/server/createServer.js"; import { ToolResultDelivery } from "../../../src/server/ToolResultDelivery.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const createTemporaryRoot = (): Promise => mkdtemp(join(tmpdir(), "rea-mcp-process-cleanup-retry-")); @@ -54,7 +55,10 @@ const connectSession = async () => { { kind: "session", session }, { logger: silentLogger }, ); - const client = new Client({ name: "process-cleanup-retry", version: "1" }); + const client = new Client( + { name: "process-cleanup-retry", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); onTestFinished(() => closeSession({ client, server, session })); diff --git a/tests/boundary/mcp/processComparisonDiagnosticsMcp.test.ts b/tests/boundary/mcp/processComparisonDiagnosticsMcp.test.ts index 5bbdb20c78..62745f842b 100644 --- a/tests/boundary/mcp/processComparisonDiagnosticsMcp.test.ts +++ b/tests/boundary/mcp/processComparisonDiagnosticsMcp.test.ts @@ -31,6 +31,7 @@ import { digestProcessCommitment } from "../../../src/domain/process/processScen import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const captureEvidence = ( side: "left" | "right", @@ -78,7 +79,10 @@ const connect = async ( }, }, ); - const client = new Client({ name: "process-comparison-test", version: "1" }); + const client = new Client( + { name: "process-comparison-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await Promise.allSettled([client.close(), server.close(), session.close()]); }); diff --git a/tests/boundary/mcp/processEvidenceIdentityMcp.test.ts b/tests/boundary/mcp/processEvidenceIdentityMcp.test.ts index 8f8d2989c8..037619213a 100644 --- a/tests/boundary/mcp/processEvidenceIdentityMcp.test.ts +++ b/tests/boundary/mcp/processEvidenceIdentityMcp.test.ts @@ -29,6 +29,7 @@ import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { verifyReconstruction } from "../../../src/domain/reconstructionVerification.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const providerNames = [ "REA process capture", "REA deterministic process harness", @@ -61,10 +62,13 @@ const connectedComparison = async () => { throw new Error("Process comparison must not launch a provider"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "process-evidence-identity", - version: "1", - }); + const client = new Client( + { + name: "process-evidence-identity", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await Promise.allSettled([client.close(), server.close(), session.close()]); }); diff --git a/tests/boundary/mcp/processTraceAdaptersParity.test.ts b/tests/boundary/mcp/processTraceAdaptersParity.test.ts index ab407c2b54..549856f329 100644 --- a/tests/boundary/mcp/processTraceAdaptersParity.test.ts +++ b/tests/boundary/mcp/processTraceAdaptersParity.test.ts @@ -17,6 +17,7 @@ import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js"; import { createServer } from "../../../src/server/createServer.js"; import { observed as ok } from "../../fixtures/analysisExecution.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const resources: Array<{ close(): Promise }> = []; const temporaryRoots: string[] = []; @@ -50,7 +51,10 @@ const comparisonClient = async ( { kind: "session", session }, { environment: { ...process.env, ...INLINE_EVIDENCE_MCP_ENVIRONMENT } }, ); - const client = new Client({ name: "trace-parity", version: "1" }); + const client = new Client( + { name: "trace-parity", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); diff --git a/tests/boundary/mcp/progressMcp.test.ts b/tests/boundary/mcp/progressMcp.test.ts index 8aa5516514..1ab47898a1 100644 --- a/tests/boundary/mcp/progressMcp.test.ts +++ b/tests/boundary/mcp/progressMcp.test.ts @@ -14,6 +14,13 @@ import { err, ok } from "../../../src/domain/result.js"; import { createServer } from "../../../src/server/createServer.js"; import { observed } from "../../fixtures/analysisExecution.js"; import { phaseGate } from "../../support/lifecycleHarness.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; + +const testClient = (name: string) => + new Client( + { name, version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); describe("ordinary MCP progress and cancellation", () => { it("advances MCP progress when provider waiting does not advance completed work", async () => { @@ -32,7 +39,7 @@ describe("ordinary MCP progress and cancellation", () => { }, }; const server = createServer({ kind: "fixed", analysis }); - const client = new Client({ name: "progress-test", version: "1" }); + const client = testClient("progress-test"); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const progress: { @@ -81,7 +88,7 @@ describe("ordinary MCP progress and cancellation", () => { ), }; const server = createServer({ kind: "fixed", analysis }); - const client = new Client({ name: "function-progress-test", version: "1" }); + const client = testClient("function-progress-test"); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const progress: number[] = []; @@ -130,7 +137,7 @@ describe("ordinary MCP progress and cancellation", () => { }, }; const server = createServer({ kind: "fixed", analysis }); - const client = new Client({ name: "cancellation-test", version: "1" }); + const client = testClient("cancellation-test"); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const controller = new AbortController(); diff --git a/tests/boundary/mcp/promptMcp.test.ts b/tests/boundary/mcp/promptMcp.test.ts index 6a4e9a4f8c..4d8b601084 100644 --- a/tests/boundary/mcp/promptMcp.test.ts +++ b/tests/boundary/mcp/promptMcp.test.ts @@ -59,6 +59,7 @@ import { EvidenceMcpServer } from "../../../src/server/EvidenceMcpServer.js"; import { createToolResultDelivery } from "../../../src/server/toolResult.js"; import { observed } from "../../fixtures/analysisExecution.js"; import { serveStreamableHttp } from "../../../src/server/http/serveStreamableHttp.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; type PromptResource = { close(): Promise>>; @@ -561,10 +562,13 @@ describe("guided prompt completion registry", () => { { execute: async () => observed(["fixture-document"]) }, session, ); - const client = new Client({ - name: "prompt-registry-client", - version: "1", - }); + const client = new Client( + { + name: "prompt-registry-client", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const changed = new Promise((resolve) => { client.setNotificationHandler("notifications/prompts/list_changed", () => resolve(), @@ -730,7 +734,10 @@ it.each(["replacement", "shutdown"])( }); retainPromptResources(served); const connectHttp = async () => { - const client = new Client({ name: "completion-http", version: "1" }); + const client = new Client( + { name: "completion-http", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); retainPromptResources(client); await client.connect( new StreamableHTTPClientTransport(new URL(served.url)), @@ -804,7 +811,10 @@ describe("guided prompt completion lifecycle", () => { return observed(["fresh-document"]); }, }); - const client = new Client({ name: "prompt-cancel-client", version: "1" }); + const client = new Client( + { name: "prompt-cancel-client", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); await connectPair(server, client); const controller = new AbortController(); const pending = client.complete( @@ -1139,7 +1149,10 @@ const complete = async ( const connect = async ( server: Awaited>, ): Promise => { - const client = new Client({ name: "prompt-test", version: "1" }); + const client = new Client( + { name: "prompt-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); await connectPair(server, client); return client; }; diff --git a/tests/boundary/mcp/providerSelectionMcp.test.ts b/tests/boundary/mcp/providerSelectionMcp.test.ts index 183160567a..142a4e2348 100644 --- a/tests/boundary/mcp/providerSelectionMcp.test.ts +++ b/tests/boundary/mcp/providerSelectionMcp.test.ts @@ -3,7 +3,6 @@ import { withCanonicalOutputSchema, } from "../../fixtures/canonicalOutputSchema.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; -import { createHash } from "node:crypto"; import { writeFile } from "node:fs/promises"; import { join } from "node:path"; @@ -13,6 +12,7 @@ import type { CallToolResult } from "@modelcontextprotocol/server"; import { afterEach, describe, expect, it, vi } from "vitest"; import { z } from "zod"; import { jsonObjectSchema } from "../../../src/domain/jsonValue.js"; +import { sha256Hex } from "../../../src/kernel/sha256Hex.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { phaseGate } from "../../support/lifecycleHarness.js"; @@ -50,6 +50,7 @@ import { toolAvailabilitySummaryInventory, } from "../../../src/contracts/toolOutputSchemaPrimitives.js"; import { releaseOwnedCleanup } from "../../support/cleanupRelease.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const resources: Array<{ close(): Promise }> = []; afterEach(async () => { @@ -80,7 +81,10 @@ it("delivers provider-owned diagnostic keys without narrowing their JSON facts", { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "provider-diagnostics", version: "1" }); + const mcp = new Client( + { name: "provider-diagnostics", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, { close: () => session.close() }); @@ -191,7 +195,10 @@ describe("provider selection over MCP", () => { { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "provider-selection", version: "1.0.0" }); + const mcp = new Client( + { name: "provider-selection", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server); @@ -344,7 +351,10 @@ it("offers admitted providers and retains unconfigured rejections", async () => { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "provider-selection", version: "1.0.0" }); + const mcp = new Client( + { name: "provider-selection", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server); @@ -538,7 +548,10 @@ const connectDetailFixture = async (starts: string[]) => { { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "session-detail", version: "1.0.0" }); + const mcp = new Client( + { name: "session-detail", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, { close: () => session.close() }); @@ -658,6 +671,9 @@ const expectedOpenSelection = (path: string, sha256: string) => ({ sha256, }); +const firstSha = sha256Hex("first fixture"); +const secondSha = sha256Hex("second fixture"); + const expectQueuedOpenReceipt = async ( mcp: Client, session: BinarySession, @@ -691,16 +707,14 @@ const expectQueuedOpenReceipt = async ( provider_id: "beta", }); expect(nextReply.isError).not.toBe(true); - const sha = (value: string) => - createHash("sha256").update(value).digest("hex"); expect((await call("binary_session", {})).structuredContent).toMatchObject({ - result: { path: second, sha256: sha("second fixture") }, + result: { path: second, sha256: secondSha }, }); failedSnapshotOpen.release(); const failedReply = await failedSwitch; expect( parseMcpToolError(failedReply).error.details?.selection_at_failure, - ).toEqual(expectedOpenSelection(first, sha("first fixture"))); + ).toEqual(expectedOpenSelection(first, firstSha)); } finally { failedSnapshotOpen.release(); await failedSwitch.catch(() => undefined); @@ -720,127 +734,14 @@ const writeSnapshotMismatchTargets = async () => { return { testDirectory, first, second, snapshotPath }; }; -it("reports confirmed snapshot binding differences and keeps the active session", async () => { - const { testDirectory, first, second, snapshotPath } = - await writeSnapshotMismatchTargets(); - const sha = (value: string) => - createHash("sha256").update(value).digest("hex"); - let revision = 1; - const alphaProfile = createAnalysisProfile( - { id: "alpha", name: "alpha provider", version: "1" }, - { revision: 1 }, - ); - const betaProfile = createAnalysisProfile( - { id: "beta", name: "beta provider", version: "1" }, - { fixture: "beta" }, - ); - const alpha = candidate("alpha", []); - const session = composeBinarySession( - new AnalysisProviderRegistry([ - { - ...alpha, - resolveAnalysisProfile: () => - Promise.resolve( - ok({ - profile: createAnalysisProfile( - { id: "alpha", name: "alpha provider", version: "1" }, - { revision }, - ), - }), - ), - }, - candidate("beta", []), - ]), - ); - const server = createServer({ kind: "session", session }); - const mcp = new Client({ name: "snapshot-mismatch", version: "1" }); - const [clientTransport, serverTransport] = - InMemoryTransport.createLinkedPair(); - resources.push(mcp, server, { close: () => session.close() }); - await server.connect(serverTransport); - await mcp.connect(clientTransport); - const call = (name: string, args: Record) => - mcp.callTool({ name, arguments: args }); - expect( - (await call("open_binary", { path: first, provider_id: "alpha" })).isError, - ).not.toBe(true); - expect( - (await call("close_binary", { snapshot_path: snapshotPath })).isError, - ).not.toBe(true); - expect( - (await call("open_binary", { path: first, provider_id: "alpha" })).isError, - ).not.toBe(true); - const mismatch = async (path: string, provider: string) => { - const result = await call("open_binary", { - path, - provider_id: provider, - snapshot_path: snapshotPath, - }); - const error = parseMcpToolError(result).error; - expect(error.code).toBe("evidence_integrity_mismatch"); - expect(error.details).toMatchObject({ - target_at_open_completion: { sha256: sha("first fixture") }, - selection_at_failure: expectedOpenSelection(first, sha("first fixture")), - }); - expect(error.remediation.action).toBe( - analysisErrorRemediationAction(new AnalysisSnapshotMismatchError("")), - ); - expect((await call("binary_session", {})).structuredContent).toMatchObject({ - result: { - open: true, - path: first, - analysis_provider_binding: { - analysis_profile: { digest: alphaProfile.digest }, - }, - }, - }); - return error.details?.binding_mismatch; - }; - // A snapshot names its target by the target identity it persisted. - expect(await mismatch(second, "alpha")).toEqual({ - target: { - snapshot: expect.objectContaining({ - identity: expect.objectContaining({ sha256: sha("first fixture") }), - }), - selected: expect.objectContaining({ - identity: expect.objectContaining({ sha256: sha("second fixture") }), - }), - }, - }); - const otherProvider = await mismatch(first, "beta"); - expect(otherProvider).toMatchObject({ - provider: { snapshot: { id: "alpha" }, selected: { id: "beta" } }, - profile_digest: { - snapshot: alphaProfile.digest, - selected: betaProfile.digest, - }, - }); - expect(otherProvider).not.toHaveProperty("target"); - revision = 2; - const otherProfile = await mismatch(first, "alpha"); - expect(otherProfile).toMatchObject({ - profile_digest: { - snapshot: expect.any(String), - selected: expect.any(String), - }, - }); - expect(otherProfile).not.toHaveProperty("provider"); - expect(otherProfile).not.toHaveProperty("target"); - const combined = await mismatch(second, "beta"); - expect(combined).toMatchObject({ - target: { - snapshot: { identity: { sha256: sha("first fixture") } }, - selected: { identity: { sha256: sha("second fixture") } }, - }, - provider: { snapshot: { id: "alpha" }, selected: { id: "beta" } }, - }); - expect((await call("address_name", { address: "0x10" })).isError).not.toBe( - true, - ); - - await expectQueuedOpenReceipt(mcp, session, first, second, snapshotPath); - - revision = 1; +/** A raw-binary snapshot names the entry point its target was opened with. */ +const expectRawEntryPointMismatch = async ( + call: ( + name: string, + args: Record, + ) => ReturnType, + testDirectory: string, +) => { const raw = join(testDirectory, "raw.bin"); const rawSnapshot = join(testDirectory, "raw-snapshot.json"); await writeFile(raw, Buffer.from([0, 1, 2, 3])); @@ -871,6 +772,135 @@ it("reports confirmed snapshot binding differences and keeps the active session" }, }, }); +}; + +it("reports confirmed snapshot binding differences and keeps the active session", async () => { + const { testDirectory, first, second, snapshotPath } = + await writeSnapshotMismatchTargets(); + let revision = 1; + const alphaProfile = createAnalysisProfile( + { id: "alpha", name: "alpha provider", version: "1" }, + { revision: 1 }, + ); + const betaProfile = createAnalysisProfile( + { id: "beta", name: "beta provider", version: "1" }, + { fixture: "beta" }, + ); + const alpha = candidate("alpha", []); + const session = composeBinarySession( + new AnalysisProviderRegistry([ + { + ...alpha, + resolveAnalysisProfile: () => + Promise.resolve( + ok({ + profile: createAnalysisProfile( + { id: "alpha", name: "alpha provider", version: "1" }, + { revision }, + ), + }), + ), + }, + candidate("beta", []), + ]), + ); + const server = createServer({ kind: "session", session }); + const mcp = new Client( + { name: "snapshot-mismatch", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); + const [clientTransport, serverTransport] = + InMemoryTransport.createLinkedPair(); + resources.push(mcp, server, { close: () => session.close() }); + await server.connect(serverTransport); + await mcp.connect(clientTransport); + const call = (name: string, args: Record) => + mcp.callTool({ name, arguments: args }); + expect( + (await call("open_binary", { path: first, provider_id: "alpha" })).isError, + ).not.toBe(true); + expect( + (await call("close_binary", { snapshot_path: snapshotPath })).isError, + ).not.toBe(true); + expect( + (await call("open_binary", { path: first, provider_id: "alpha" })).isError, + ).not.toBe(true); + const mismatch = async (path: string, provider: string) => { + const result = await call("open_binary", { + path, + provider_id: provider, + snapshot_path: snapshotPath, + }); + const error = parseMcpToolError(result).error; + expect(error.code).toBe("evidence_integrity_mismatch"); + expect(error.details).toMatchObject({ + target_at_open_completion: { sha256: firstSha }, + selection_at_failure: expectedOpenSelection(first, firstSha), + }); + expect(error.remediation.action).toBe( + analysisErrorRemediationAction(new AnalysisSnapshotMismatchError("")), + ); + expect((await call("binary_session", {})).structuredContent).toMatchObject({ + result: { + open: true, + path: first, + analysis_provider_binding: { + analysis_profile: { digest: alphaProfile.digest }, + }, + }, + }); + return error.details?.binding_mismatch; + }; + // A snapshot names its target by the target identity it persisted. + expect(await mismatch(second, "alpha")).toEqual({ + target: { + snapshot: expect.objectContaining({ + identity: expect.objectContaining({ + sha256: firstSha, + }), + }), + selected: expect.objectContaining({ + identity: expect.objectContaining({ + sha256: secondSha, + }), + }), + }, + }); + const otherProvider = await mismatch(first, "beta"); + expect(otherProvider).toMatchObject({ + provider: { snapshot: { id: "alpha" }, selected: { id: "beta" } }, + profile_digest: { + snapshot: alphaProfile.digest, + selected: betaProfile.digest, + }, + }); + expect(otherProvider).not.toHaveProperty("target"); + revision = 2; + const otherProfile = await mismatch(first, "alpha"); + expect(otherProfile).toMatchObject({ + profile_digest: { + snapshot: expect.any(String), + selected: expect.any(String), + }, + }); + expect(otherProfile).not.toHaveProperty("provider"); + expect(otherProfile).not.toHaveProperty("target"); + const combined = await mismatch(second, "beta"); + expect(combined).toMatchObject({ + target: { + snapshot: { identity: { sha256: firstSha } }, + selected: { identity: { sha256: secondSha } }, + }, + provider: { snapshot: { id: "alpha" }, selected: { id: "beta" } }, + }); + expect((await call("address_name", { address: "0x10" })).isError).not.toBe( + true, + ); + + await expectQueuedOpenReceipt(mcp, session, first, second, snapshotPath); + + revision = 1; + await expectRawEntryPointMismatch(call, testDirectory); }); it.each([true, false])( @@ -906,7 +936,10 @@ it.each([true, false])( { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "comment-recovery", version: "1" }); + const mcp = new Client( + { name: "comment-recovery", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, { close: () => session.close() }); @@ -1001,7 +1034,10 @@ it("keeps containing-function recovery for undeclared comment facets", async () { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "undeclared-comment-facet", version: "1" }); + const mcp = new Client( + { name: "undeclared-comment-facet", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, { close: () => session.close() }); @@ -1247,9 +1283,7 @@ const checkQueuedSwitchReceipt = async ( arguments: { path: other, provider_id: "alpha" }, }); expect(switched.isError).not.toBe(true); - expect(session.activeTarget()?.sha256).toBe( - createHash("sha256").update("other fixture").digest("hex"), - ); + expect(session.activeTarget()?.sha256).toBe(sha256Hex("other fixture")); failedOpenReceipt.release(); const queuedRefusal = await pending; for (const result of [structured(queuedRefusal), refusal]) @@ -1297,7 +1331,10 @@ it("preserves a selected Ghidra project's read-only guidance when an edit is req { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "project-refusal", version: "1" }); + const mcp = new Client( + { name: "project-refusal", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, { close: () => session.close() }); @@ -1351,7 +1388,10 @@ it("labels unbound provider observations as selection-time after a repair", asyn { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "candidate-scope", version: "1" }); + const mcp = new Client( + { name: "candidate-scope", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, { close: () => session.close() }); @@ -1461,7 +1501,10 @@ it("preserves the bound client when a candidate refresh is cancelled during fina { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "candidate-refresh-cancel", version: "1" }); + const mcp = new Client( + { name: "candidate-refresh-cancel", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, { close: () => session.close() }); @@ -1540,7 +1583,10 @@ it("orders a provider switch after an in-flight candidate refresh", async () => { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "refresh-switch-race", version: "1" }); + const mcp = new Client( + { name: "refresh-switch-race", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, { close: () => session.close() }); @@ -1625,7 +1671,10 @@ it("does not cancel an already admitted prompt lookup for a candidate refresh", { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "refresh-prompt", version: "1" }); + const mcp = new Client( + { name: "refresh-prompt", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, { close: () => session.close() }); @@ -1697,7 +1746,10 @@ it("retains failed candidate-refresh cleanup while preserving the selected bindi { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "candidate-refresh-cleanup", version: "1" }); + const mcp = new Client( + { name: "candidate-refresh-cleanup", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, { close: () => session.close() }); @@ -1772,7 +1824,10 @@ it("retains attributed mixed profile cleanup through registered MCP calls and pa { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "profile-completion", version: "1.0.0" }); + const mcp = new Client( + { name: "profile-completion", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, { close: () => session.close() }); @@ -1856,7 +1911,10 @@ it.each(["ready", "cancelled", "physical"] as const)( { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "async-readiness", version: "1.0.0" }); + const mcp = new Client( + { name: "async-readiness", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, { close: () => session.close() }); diff --git a/tests/boundary/mcp/pseudocodeDeliveryMcp.test.ts b/tests/boundary/mcp/pseudocodeDeliveryMcp.test.ts index 3732b6d4bf..d7d0217170 100644 --- a/tests/boundary/mcp/pseudocodeDeliveryMcp.test.ts +++ b/tests/boundary/mcp/pseudocodeDeliveryMcp.test.ts @@ -11,6 +11,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { advertisedMcpToolSchemas } from "../../fixtures/advertisedMcpTool.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { connectGhidraMcp } from "./ghidraMcpHarness.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const connectPseudocode = async (text: string | null) => { const harness = await connectGhidraMcp( @@ -267,7 +268,10 @@ it("refuses summary delivery before calling a fixed provider without retention", }, { environment: {} }, ); - const client = new Client({ name: "pseudocode-no-retention", version: "1" }); + const client = new Client( + { name: "pseudocode-no-retention", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => closeVerifierResources([() => client.close(), () => server.close()]), ); diff --git a/tests/boundary/mcp/rawBinaryMcp.test.ts b/tests/boundary/mcp/rawBinaryMcp.test.ts index 795c281b46..446ba469dc 100644 --- a/tests/boundary/mcp/rawBinaryMcp.test.ts +++ b/tests/boundary/mcp/rawBinaryMcp.test.ts @@ -23,6 +23,7 @@ import { silentLogger } from "../../../src/logger.js"; import { GHIDRA_PROVIDER_IDENTITY } from "../../../src/ghidra/GhidraProviderMetadata.js"; import { RAW_ONLY_ARCHITECTURES } from "../../../src/domain/binaryTargetTypes.js"; import type { CallToolResult } from "@modelcontextprotocol/server"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const connect = async ( provider: AnalysisProvider = createCacheProvider([]), @@ -32,7 +33,10 @@ const connect = async ( { kind: "session", session }, { logger: silentLogger }, ); - const client = new Client({ name: "raw-binary-mcp", version: "1" }); + const client = new Client( + { name: "raw-binary-mcp", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/reconstructionCoverageMcp.test.ts b/tests/boundary/mcp/reconstructionCoverageMcp.test.ts index 30a91218a6..7b210776da 100644 --- a/tests/boundary/mcp/reconstructionCoverageMcp.test.ts +++ b/tests/boundary/mcp/reconstructionCoverageMcp.test.ts @@ -20,6 +20,7 @@ import { RECREATE_EVIDENCE_GUIDANCE } from "../../../src/domain/evidenceFormat.j import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createServer } from "../../../src/server/createServer.js"; import { observed } from "../../fixtures/analysisExecution.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("rejects malformed boundary identifiers at the MCP request boundary", async () => { await withCoverageMcp(async ({ client }) => { @@ -421,7 +422,10 @@ const withCoverageMcp = async ( close: () => Promise.resolve(resultOk(null)), })); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "coverage-mcp-test", version: "1" }); + const client = new Client( + { name: "coverage-mcp-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/reconstructionObligationLedgerMcp.test.ts b/tests/boundary/mcp/reconstructionObligationLedgerMcp.test.ts index 5b60763918..5979333098 100644 --- a/tests/boundary/mcp/reconstructionObligationLedgerMcp.test.ts +++ b/tests/boundary/mcp/reconstructionObligationLedgerMcp.test.ts @@ -32,6 +32,7 @@ import { reviewedObligation, } from "../../../src/application/ReconstructionObligationLedger.fixture.js"; import { observed } from "../../fixtures/analysisExecution.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; type LedgerRequest = ( evidenceBundle: unknown, @@ -47,7 +48,10 @@ const withLedgerClient = async ( close: () => Promise.resolve(resultOk(null)), })); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "obligation-ledger-test", version: "1" }); + const client = new Client( + { name: "obligation-ledger-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -297,7 +301,10 @@ describe("reconstruction obligation ledger MCP parity", () => { close: () => Promise.resolve(resultOk(null)), })); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "obligation-ledger-test", version: "1" }); + const client = new Client( + { name: "obligation-ledger-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -389,7 +396,10 @@ describe("reconstruction obligation ledger MCP parity", () => { close: () => Promise.resolve(resultOk(null)), })); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "obligation-ledger-test", version: "1" }); + const client = new Client( + { name: "obligation-ledger-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/recordedCrashMcp.test.ts b/tests/boundary/mcp/recordedCrashMcp.test.ts index 7b86e187a5..3f00c4be71 100644 --- a/tests/boundary/mcp/recordedCrashMcp.test.ts +++ b/tests/boundary/mcp/recordedCrashMcp.test.ts @@ -17,6 +17,7 @@ import { recordedCrashFixture, RECORDED_CRASH_TEST_PROVIDER, } from "../../fixtures/binaryDiagnostics/recordedCrash.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("records inline recorded-core evidence with compact schemas and canonical path checks", async () => { const value = recordedCrashFixture(); @@ -42,7 +43,10 @@ it("records inline recorded-core evidence with compact schemas and canonical pat { kind: "session", session }, { recordedCrash: service }, ); - const client = new Client({ name: "recorded-crash-contract", version: "1" }); + const client = new Client( + { name: "recorded-crash-contract", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/reverseEngineeringProviderEnvironmentMcp.test.ts b/tests/boundary/mcp/reverseEngineeringProviderEnvironmentMcp.test.ts index 882c1d4640..4819f4d1ab 100644 --- a/tests/boundary/mcp/reverseEngineeringProviderEnvironmentMcp.test.ts +++ b/tests/boundary/mcp/reverseEngineeringProviderEnvironmentMcp.test.ts @@ -8,6 +8,7 @@ import { expect, it } from "vitest"; import { createServer } from "../../../src/server/createServer.js"; import { createAnalysisExecution } from "../../../src/ports/AnalysisProvider.js"; import { ok } from "../../../src/domain/result.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const analysis = { execute: async () => @@ -60,7 +61,10 @@ it("uses the server-selected environment unless a provider environment overrides }), }, ); - const client = new Client({ name: "reverse-env-test", version: "1" }); + const client = new Client( + { name: "reverse-env-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/rizinDebuggerCancellationMcp.test.ts b/tests/boundary/mcp/rizinDebuggerCancellationMcp.test.ts index 7b4c96c789..2166cdfd79 100644 --- a/tests/boundary/mcp/rizinDebuggerCancellationMcp.test.ts +++ b/tests/boundary/mcp/rizinDebuggerCancellationMcp.test.ts @@ -29,6 +29,7 @@ import { validateDebuggerStatusResponse, waitForStartedFile, } from "../../support/reverseDebuggerMcpTestHelpers.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.skipIf(process.platform === "win32")( "reports Rizin launch provenance and lossy frame decoding through MCP", @@ -56,10 +57,13 @@ process.stdin.on("data", (chunk) => { await chmod(provider, 0o700); const manager = createRizinTestManager({ REA_RIZIN_COMMAND: provider }); const server = rizinDebugMcpServer("rizin-evidence-provenance", manager); - const client = new Client({ - name: "rizin-evidence-provenance", - version: "1", - }); + const client = new Client( + { + name: "rizin-evidence-provenance", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); // An absolute spelling that resolution changes: interior "." is removed. @@ -144,7 +148,10 @@ it("admits Rizin startup across a bound analysis session", async () => { manager, analysisSession, ); - const client = new Client({ name: "rizin-start-admission", version: "1" }); + const client = new Client( + { name: "rizin-start-admission", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -204,7 +211,10 @@ process.stdin.on("data", async (chunk) => { REA_RIZIN_COMMAND: provider, }); const server = rizinDebugMcpServer("rizin-cancellation", manager); - const client = new Client({ name: "rizin-cancellation", version: "1" }); + const client = new Client( + { name: "rizin-cancellation", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/rizinOutputPreservation.test.ts b/tests/boundary/mcp/rizinOutputPreservation.test.ts index fea53e1439..cb013596b0 100644 --- a/tests/boundary/mcp/rizinOutputPreservation.test.ts +++ b/tests/boundary/mcp/rizinOutputPreservation.test.ts @@ -10,6 +10,7 @@ import { createRizinTestManager, rizinTestInferiorTty, } from "../providers/RizinTestInferiorTty.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const test = it.skipIf(process.platform === "win32"); @@ -45,7 +46,10 @@ const observe = async ( }, ); const server = rizinDebugMcpServer("rizin-output-test", manager); - const client = new Client({ name: "rizin-output-test", version: "1" }); + const client = new Client( + { name: "rizin-output-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/rizinPendingOutput.test.ts b/tests/boundary/mcp/rizinPendingOutput.test.ts index abc80b70ac..04e36d05ae 100644 --- a/tests/boundary/mcp/rizinPendingOutput.test.ts +++ b/tests/boundary/mcp/rizinPendingOutput.test.ts @@ -10,6 +10,7 @@ import { createRizinTestManager, rizinTestInferiorTty, } from "../providers/RizinTestInferiorTty.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const test = it.skipIf(process.platform === "win32"); @@ -49,7 +50,10 @@ test.each([ }, ); const server = rizinDebugMcpServer("rizin-partial-test", manager); - const client = new Client({ name: "rizin-partial-test", version: "1" }); + const client = new Client( + { name: "rizin-partial-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/rizinStoppedSessionMcp.test.ts b/tests/boundary/mcp/rizinStoppedSessionMcp.test.ts index df92783b0c..2d48b86982 100644 --- a/tests/boundary/mcp/rizinStoppedSessionMcp.test.ts +++ b/tests/boundary/mcp/rizinStoppedSessionMcp.test.ts @@ -14,6 +14,7 @@ import { createRizinTestManager, rizinTestInferiorTty, } from "../providers/RizinTestInferiorTty.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const test = it.skipIf(process.platform === "win32"); @@ -65,7 +66,10 @@ test.each([ }, ); const server = rizinDebugMcpServer("rizin-stopped", manager); - const client = new Client({ name: "rizin-stopped", version: "1" }); + const client = new Client( + { name: "rizin-stopped", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const call = (name: string, arguments_: Record) => diff --git a/tests/boundary/mcp/sdkInputIssueAttribution.test.ts b/tests/boundary/mcp/sdkInputIssueAttribution.test.ts index e554827518..64b9a728cd 100644 --- a/tests/boundary/mcp/sdkInputIssueAttribution.test.ts +++ b/tests/boundary/mcp/sdkInputIssueAttribution.test.ts @@ -8,6 +8,7 @@ import { createToolResultDelivery } from "../../../src/server/toolResult.js"; import { observed } from "../../fixtures/analysisExecution.js"; import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("keeps concurrent SDK validation issues attached to their own tool call", async () => { let calls = 0; @@ -20,7 +21,10 @@ it("keeps concurrent SDK validation issues attached to their own tool call", asy }, }, }); - const client = new Client({ name: "input-issue-attribution", version: "1" }); + const client = new Client( + { name: "input-issue-attribution", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -134,7 +138,9 @@ it("retains mixed SDK field diagnostics without repeating custom guidance", asyn server.registerTool("custom_issues", { inputSchema }, async () => ({ content: [{ type: "text", text: "unexpected dispatch" }], })); - const client = new Client(info); + const client = new Client(info, { + jsonSchemaValidator: createMcpSchemaValidation(), + }); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -210,7 +216,9 @@ it("keeps same-path union and independent issues attributed to their producers", server.registerTool("overlapping_issues", { inputSchema }, async () => ({ content: [{ type: "text", text: "unexpected dispatch" }], })); - const client = new Client(info); + const client = new Client(info, { + jsonSchemaValidator: createMcpSchemaValidation(), + }); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -297,8 +305,12 @@ it("discloses when bounded projection cannot retain union branch details", async }); server.registerTool("long_key", { inputSchema: keySchema }, unreachable); sdkServer.registerTool("long_key", { inputSchema: keySchema }, unreachable); - const client = new Client(info); - const sdkClient = new Client(info); + const client = new Client(info, { + jsonSchemaValidator: createMcpSchemaValidation(), + }); + const sdkClient = new Client(info, { + jsonSchemaValidator: createMcpSchemaValidation(), + }); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const [sdkClientTransport, sdkServerTransport] = diff --git a/tests/boundary/mcp/serverIdentity.test.ts b/tests/boundary/mcp/serverIdentity.test.ts index 0ddc93e0fd..236d1abff9 100644 --- a/tests/boundary/mcp/serverIdentity.test.ts +++ b/tests/boundary/mcp/serverIdentity.test.ts @@ -38,6 +38,7 @@ import type { CapabilityDescriptor, } from "../../../src/ports/AnalysisProvider.js"; import { COMPACT_INPUT_SCHEMA_BUDGET_BYTES } from "../../../src/contracts/mcpSchemaPresentation.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const availabilityProvider = ( operations: readonly CapabilityDescriptor["operation"][] = [ @@ -382,6 +383,7 @@ describe("live server identity over MCP", () => { const client = new Client( { name: "identity-test", version: "9" }, { + jsonSchemaValidator: createMcpSchemaValidation(), capabilities: { elicitation: { form: {} }, }, @@ -424,7 +426,10 @@ describe("live server identity over MCP", () => { { kind: "session", session }, { environment: { REA_MCP_INPUT_SCHEMA_PROFILE: "compact" } }, ); - const client = new Client({ name: "compact-identity-test", version: "1" }); + const client = new Client( + { name: "compact-identity-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -475,7 +480,10 @@ describe("active-target availability over MCP", () => { { kind: "session", session }, { environment: { REA_MCP_OUTPUT_SCHEMA_PROFILE: "off" } }, ); - const client = new Client({ name: "availability-test", version: "1" }); + const client = new Client( + { name: "availability-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const directory = await createTestTempDirectory("rea-target-availability-"); diff --git a/tests/boundary/mcp/serverLifecycleMcp.test.ts b/tests/boundary/mcp/serverLifecycleMcp.test.ts index df11130a19..d367059d2a 100644 --- a/tests/boundary/mcp/serverLifecycleMcp.test.ts +++ b/tests/boundary/mcp/serverLifecycleMcp.test.ts @@ -41,6 +41,7 @@ import { WebNetworkCaptureService } from "../../../src/application/WebNetworkCap import { AnalysisUnsupportedTargetError } from "../../../src/domain/analysisErrorCore.js"; import { ProviderCleanupError } from "../../../src/domain/providerCleanupError.js"; import type { JavaScriptRuntimeObservationPort } from "../../../src/ports/javascript/JavaScriptRuntimeObservationPort.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const resources: Array<{ close(): Promise }> = []; @@ -80,7 +81,10 @@ it.runIf(SQLITE_NATIVE_LIMITS_AVAILABLE)( { kind: "session", session }, { sqliteDatabase: new SqliteDatabaseService(provider) }, ); - const client = new Client({ name: "sqlite-admission", version: "1" }); + const client = new Client( + { name: "sqlite-admission", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -165,10 +169,13 @@ it.runIf(SQLITE_NATIVE_LIMITS_AVAILABLE)( { kind: "session", session }, { sqliteDatabase: new SqliteDatabaseService(provider) }, ); - const client = new Client({ - name: "sqlite-retained-observation", - version: "1", - }); + const client = new Client( + { + name: "sqlite-retained-observation", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -402,7 +409,10 @@ it("closes the bound Go, IL2CPP and web-capture services and retries failed shut }, }, ); - const client = new Client({ name: "bound-service-lifecycle", version: "1" }); + const client = new Client( + { name: "bound-service-lifecycle", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); @@ -534,10 +544,13 @@ afterEach(async () => { const connect = async (analysis: AnalysisOperationPort) => { const server = createServer({ kind: "fixed", analysis }); - const client = new Client({ - name: "integration-test", - version: "1.0.0", - }); + const client = new Client( + { + name: "integration-test", + version: "1.0.0", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); diff --git a/tests/boundary/mcp/serverUnknownsMcp.test.ts b/tests/boundary/mcp/serverUnknownsMcp.test.ts index 08fcf2797b..3615c2913f 100644 --- a/tests/boundary/mcp/serverUnknownsMcp.test.ts +++ b/tests/boundary/mcp/serverUnknownsMcp.test.ts @@ -33,6 +33,7 @@ import { EMPTY_PROCESS_CAPTURE_EXAMPLE } from "../../../src/domain/process/proce import { PROCESS_PROVIDER } from "../../../src/domain/process/processEvidenceProvider.js"; import { processCaptureSchema } from "../../../src/domain/process/processCapture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const resources: Array<{ close(): Promise }> = []; afterEach(async () => { @@ -154,7 +155,10 @@ it("rejects divergent imported histories without suggesting an unchanged retry", throw new Error("no target"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "conflicting-history", version: "1" }); + const client = new Client( + { name: "conflicting-history", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); @@ -209,7 +213,10 @@ it("does not record capability unavailability without supporting Evidence", asyn providerWithCapabilities(["procedure_pseudo_code"]), ); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "unavailable-unknown", version: "1" }); + const client = new Client( + { name: "unavailable-unknown", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); @@ -277,7 +284,10 @@ it("records capture disagreement as a contradicted unknown", async () => { expect(session.recordEvidence(leftEvidence).ok).toBe(true); expect(session.recordEvidence(rightEvidence).ok).toBe(true); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "comparison-unknown", version: "1" }); + const client = new Client( + { name: "comparison-unknown", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); @@ -370,7 +380,10 @@ it("records capture disagreement as a contradicted unknown", async () => { it("pages filtered unknown heads through the public MCP contract", async () => { const session = createTestBinarySession(providerWithCapabilities([])); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "unknown-pagination", version: "1" }); + const client = new Client( + { name: "unknown-pagination", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); @@ -524,7 +537,10 @@ it("pages filtered unknown heads through the public MCP contract", async () => { it("reports contradictory unknown input as a correctable request", async () => { const session = createTestBinarySession(providerWithCapabilities([])); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "unknown-input", version: "1" }); + const client = new Client( + { name: "unknown-input", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); @@ -638,7 +654,10 @@ it("returns exact committed unknown receipts when creation and update replies ov { kind: "session", session }, { delivery: createToolResultDelivery(8 * 1024) }, ); - const client = new Client({ name: "unknown-overflow-receipt", version: "1" }); + const client = new Client( + { name: "unknown-overflow-receipt", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); resources.push(client, server); await server.connect(st); @@ -722,7 +741,10 @@ it("returns exact committed unknown receipts when creation and update replies ov it("preserves graph constraint facts and rejects atomically until input is corrected", async () => { const session = createTestBinarySession(providerWithCapabilities([])); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "unknown-constraint", version: "1" }); + const client = new Client( + { name: "unknown-constraint", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); @@ -840,7 +862,10 @@ it("recovers an oversized list with same-session paging or export", async () => { kind: "session", session }, { delivery: createToolResultDelivery(8 * 1024) }, ); - const client = new Client({ name: "unknown-list-recovery", version: "1" }); + const client = new Client( + { name: "unknown-list-recovery", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); resources.push(client, server); await server.connect(st); diff --git a/tests/boundary/mcp/serverWorkflowMcp.test.ts b/tests/boundary/mcp/serverWorkflowMcp.test.ts index bd885d6993..7a9e90ebc4 100644 --- a/tests/boundary/mcp/serverWorkflowMcp.test.ts +++ b/tests/boundary/mcp/serverWorkflowMcp.test.ts @@ -23,6 +23,7 @@ import { } from "../../../src/contracts/toolContracts.js"; import { expandToolAvailability } from "../../../src/contracts/toolOutputSchemaPrimitives.js"; import { advertisedToolPresentation } from "../../../src/contracts/mcpSchemaPresentation.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const resources: Array<{ close(): Promise }> = []; @@ -34,10 +35,13 @@ afterEach(async () => { const connect = async (analysis: AnalysisOperationPort) => { const server = createServer({ kind: "fixed", analysis }); - const client = new Client({ - name: "integration-test", - version: "1.0.0", - }); + const client = new Client( + { + name: "integration-test", + version: "1.0.0", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); @@ -117,10 +121,13 @@ it("advertises the complete currently available inventory with a session", async }) satisfies AnalysisClient, ); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "integration-test", - version: "1.0.0", - }); + const client = new Client( + { + name: "integration-test", + version: "1.0.0", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); diff --git a/tests/boundary/mcp/sessionEvidenceRecovery.test.ts b/tests/boundary/mcp/sessionEvidenceRecovery.test.ts index 84cfaa2068..4d3b58cdc9 100644 --- a/tests/boundary/mcp/sessionEvidenceRecovery.test.ts +++ b/tests/boundary/mcp/sessionEvidenceRecovery.test.ts @@ -15,6 +15,7 @@ import { } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const bundleResult = (reply: CallToolResult) => z.object({ result: evidenceBundleSchema }).parse(reply.structuredContent) @@ -108,10 +109,13 @@ it.each(["switch", "restart"] as const)( { kind: "session", session }, { environment: {} }, ); - const client = new Client({ - name: "switch-evidence-recovery", - version: "1", - }); + const client = new Client( + { + name: "switch-evidence-recovery", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); const call = (name: string, arguments_: Record = {}) => diff --git a/tests/boundary/mcp/sessionEvidenceReuseMcp.test.ts b/tests/boundary/mcp/sessionEvidenceReuseMcp.test.ts index b0f5bb4902..b67e16ff91 100644 --- a/tests/boundary/mcp/sessionEvidenceReuseMcp.test.ts +++ b/tests/boundary/mcp/sessionEvidenceReuseMcp.test.ts @@ -25,6 +25,7 @@ import { registerServiceTools } from "../../../src/server/serviceToolBindings.js import { createToolResultDelivery } from "../../../src/server/toolResult.js"; import { createTestProviderRouter } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.each(["normal", "copied", "parameters", "forged", "source"] as const)( "preserves direct observation identity across the %s session boundary", @@ -130,7 +131,10 @@ it.each(["normal", "copied", "parameters", "forged", "source"] as const)( withAdmittedAnalysis: admitted, }, ); - const client = new Client({ name: "reuse-control", version: "1" }); + const client = new Client( + { name: "reuse-control", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); @@ -186,7 +190,10 @@ it("preserves the selected path when reusing an identical observation for a diff ); const session = new BinarySession(router); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "reused-subject", version: "1" }); + const client = new Client( + { name: "reused-subject", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); diff --git a/tests/boundary/mcp/sessionMcp.test.ts b/tests/boundary/mcp/sessionMcp.test.ts index 437e56804f..6aabb3d63d 100644 --- a/tests/boundary/mcp/sessionMcp.test.ts +++ b/tests/boundary/mcp/sessionMcp.test.ts @@ -46,6 +46,7 @@ import { createSessionMcpHarness, snapshotAndRecordUnknown, } from "./sessionMcpHarness.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const SNAPSHOT_PROFILE = createAnalysisProfile( { id: "fixture", name: "Fixture analysis provider", version: "1" }, @@ -197,10 +198,13 @@ describe("public provider availability", () => { { kind: "session", session }, { adbDeviceAnalysis, apktoolAnalysis, logger: silentLogger }, ); - const mcp = new Client({ - name: "provider-host-readiness", - version: "1.0.0", - }); + const mcp = new Client( + { + name: "provider-host-readiness", + version: "1.0.0", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server); @@ -265,7 +269,10 @@ describe("owned-process prerequisite during status discovery", () => { { kind: "session", session }, { adbDeviceAnalysis, apktoolAnalysis, logger: silentLogger }, ); - const mcp = new Client({ name: "ps-prerequisite", version: "1.0.0" }); + const mcp = new Client( + { name: "ps-prerequisite", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server, apktoolAnalysis); @@ -348,7 +355,10 @@ describe("target-free MCP lifecycle", () => { logger: silentLogger, }, ); - const mcp = new Client({ name: "status-readiness", version: "1.0.0" }); + const mcp = new Client( + { name: "status-readiness", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server); @@ -392,7 +402,10 @@ describe("target-free MCP lifecycle", () => { { kind: "session", session }, { logger: silentLogger }, ); - const mcp = new Client({ name: "replaced-target", version: "1.0.0" }); + const mcp = new Client( + { name: "replaced-target", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server); diff --git a/tests/boundary/mcp/sessionMcpHarness.ts b/tests/boundary/mcp/sessionMcpHarness.ts index e7c70ac6d7..6bd77b79c5 100644 --- a/tests/boundary/mcp/sessionMcpHarness.ts +++ b/tests/boundary/mcp/sessionMcpHarness.ts @@ -25,6 +25,7 @@ import { import { ok } from "../../../src/domain/result.js"; import { silentLogger } from "../../../src/logger.js"; import { createServer } from "../../../src/server/createServer.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const SNAPSHOT_PROFILE = createAnalysisProfile( { id: "fixture", name: "Fixture analysis provider", version: "1" }, @@ -109,7 +110,10 @@ export const createSessionMcpHarness = async ( }), }, ); - const mcp = new Client({ name: "session-test", version: "1.0.0" }); + const mcp = new Client( + { name: "session-test", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server); diff --git a/tests/boundary/mcp/sourcePublicationContext.test.ts b/tests/boundary/mcp/sourcePublicationContext.test.ts index b60a8a871e..7ecec78048 100644 --- a/tests/boundary/mcp/sourcePublicationContext.test.ts +++ b/tests/boundary/mcp/sourcePublicationContext.test.ts @@ -105,7 +105,10 @@ it.each( }, }, ); - const client = new Client({ name: "source-context", version: "1" }); + const client = new Client( + { name: "source-context", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); @@ -222,7 +225,10 @@ it.each([false, true])( new InvestigationRecords({ maximumRepresentationBytes: 0 }), ); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "source-cleanup-context", version: "1" }); + const client = new Client( + { name: "source-cleanup-context", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); @@ -334,10 +340,13 @@ it("keeps a smaller sibling recovery when a later completed observation exceeds new InvestigationRecords({ maximumRepresentationBytes: 0 }), ); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "multiple-recovery-context", - version: "1", - }); + const client = new Client( + { + name: "multiple-recovery-context", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); diff --git a/tests/boundary/mcp/sourcePublicationRecovery.test.ts b/tests/boundary/mcp/sourcePublicationRecovery.test.ts index e8ae8da73d..72de1a7ac1 100644 --- a/tests/boundary/mcp/sourcePublicationRecovery.test.ts +++ b/tests/boundary/mcp/sourcePublicationRecovery.test.ts @@ -16,6 +16,7 @@ import { createEvidence, type Evidence } from "../../../src/domain/evidence.js"; import { safeParseEvidence } from "../../../src/domain/evidenceValidation.js"; import { ok } from "../../../src/domain/result.js"; import { createServer } from "../../../src/server/createServer.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const assertPublication = ({ error, @@ -259,7 +260,10 @@ it.each([ }); const session = new BinarySession(router, records); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "source-publication", version: "1" }); + const client = new Client( + { name: "source-publication", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); @@ -356,7 +360,10 @@ it("reports omission when the primary cannot be safely authenticated", async () }); const session = new BinarySession(router, records); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "recovery-headroom", version: "1" }); + const client = new Client( + { name: "recovery-headroom", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); @@ -424,7 +431,10 @@ it("accounts for a wide source ID list before constructing recovery Evidence", a }); const session = new BinarySession(router, records); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "wide-recovery", version: "1" }); + const client = new Client( + { name: "wide-recovery", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); @@ -494,10 +504,13 @@ it.each(["compact"] as const)( environment: { ...process.env, REA_MCP_OUTPUT_SCHEMA_PROFILE: profile }, }, ); - const client = new Client({ - name: "source-primary-headroom", - version: "1", - }); + const client = new Client( + { + name: "source-primary-headroom", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); @@ -562,7 +575,10 @@ it("accounts for source links before admitting a completed direct observation", }); const session = new BinarySession(router, records); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "wide-primary-admission", version: "1" }); + const client = new Client( + { name: "wide-primary-admission", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [ct, st] = InMemoryTransport.createLinkedPair(); try { await server.connect(st); diff --git a/tests/boundary/mcp/streamableHttpMcp.test.ts b/tests/boundary/mcp/streamableHttpMcp.test.ts index a0c25e20d4..b3f274788f 100644 --- a/tests/boundary/mcp/streamableHttpMcp.test.ts +++ b/tests/boundary/mcp/streamableHttpMcp.test.ts @@ -12,10 +12,14 @@ import { } from "../../support/mcp/streamableHttpProcess.js"; import { processTest } from "../../support/process/processFixture.js"; import { assertAdvertisedMcpContracts } from "./mcpContractHarness.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const openSession = async (url: URL, name: string) => { const transport = new StreamableHTTPClientTransport(url); - const client = new Client({ name, version: "1" }); + const client = new Client( + { name, version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); await client.connect(transport); expect(transport.sessionId).toEqual(expect.any(String)); diff --git a/tests/boundary/mcp/targetContentFramingMcp.test.ts b/tests/boundary/mcp/targetContentFramingMcp.test.ts index 0b8fc18d5f..ff7aa3cf46 100644 --- a/tests/boundary/mcp/targetContentFramingMcp.test.ts +++ b/tests/boundary/mcp/targetContentFramingMcp.test.ts @@ -28,6 +28,7 @@ import { createToolResultDelivery } from "../../../src/server/toolResult.js"; import { toolRegistrationOptions } from "../../../src/server/toolRegistrationOptions.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createServer } from "../../../src/server/createServer.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const resources: Array<() => Promise> = []; afterEach(async () => { @@ -43,7 +44,10 @@ const connect = async (environment?: NodeJS.ProcessEnv) => { { kind: "session", session }, environment === undefined ? {} : { environment }, ); - const client = new Client({ name: "target-content-test", version: "1" }); + const client = new Client( + { name: "target-content-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(() => @@ -137,7 +141,10 @@ describe("MCP fixed-target scope guidance", () => { }, { environment: { ...process.env, REA_MCP_TOOL_FAMILIES: scope } }, ); - const client = new Client({ name: "fixed-target-scope", version: "1" }); + const client = new Client( + { name: "fixed-target-scope", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(() => Promise.all([client.close(), server.close()])); @@ -226,10 +233,13 @@ describe.each([ return result; }, ); - const client = new Client({ - name: "partial-provenance-client", - version: "1", - }); + const client = new Client( + { + name: "partial-provenance-client", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/toolInputCapacityHttp.test.ts b/tests/boundary/mcp/toolInputCapacityHttp.test.ts index 3fd14b5598..1fa34ad946 100644 --- a/tests/boundary/mcp/toolInputCapacityHttp.test.ts +++ b/tests/boundary/mcp/toolInputCapacityHttp.test.ts @@ -12,6 +12,7 @@ import { processTest, type TestProcesses, } from "../../support/process/processFixture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const openHttp = async ( processes: TestProcesses, @@ -33,7 +34,10 @@ const openHttp = async ( ...(maximum === undefined ? {} : { REA_MCP_MAX_INPUT_ELEMENTS: maximum }), }, ); - const client = new Client({ name: "input-capacity-http", version: "1" }); + const client = new Client( + { name: "input-capacity-http", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const transport = new StreamableHTTPClientTransport(url, { // SDK output-schema compilation can outlive an idle pooled socket on two // CPUs. Keep this admission test independent of that client-side race. diff --git a/tests/boundary/mcp/toolInputCapacityStdio.test.ts b/tests/boundary/mcp/toolInputCapacityStdio.test.ts index b4b5d3cc60..5e666f8f8e 100644 --- a/tests/boundary/mcp/toolInputCapacityStdio.test.ts +++ b/tests/boundary/mcp/toolInputCapacityStdio.test.ts @@ -4,6 +4,7 @@ import { join, resolve } from "node:path"; import { expect, it, onTestFinished } from "vitest"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("applies the selected input allowance through the public deferred stdio entry point", async () => { const root = await createTestTempDirectory("rea-input-capacity-stdio-"); @@ -25,7 +26,10 @@ it("applies the selected input allowance through the public deferred stdio entry stderr: "pipe", }); transport.stderr?.on("data", () => undefined); - const client = new Client({ name: "input-capacity-stdio", version: "1" }); + const client = new Client( + { name: "input-capacity-stdio", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { try { await client.close(); diff --git a/tests/boundary/mcp/toolResult.test.ts b/tests/boundary/mcp/toolResult.test.ts index 527e7f8c58..c37597260f 100644 --- a/tests/boundary/mcp/toolResult.test.ts +++ b/tests/boundary/mcp/toolResult.test.ts @@ -37,6 +37,7 @@ import type { IncompleteProcessCaptureObservations, ProcessCaptureCleanupReport, } from "../../../src/domain/process/processCapture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const delivery = createToolResultDelivery(STDIO_DEFAULT_MAX_BUFFER_SIZE); const UNTRUSTED_TARGET_CONTENT = { provenance: { untrusted_content: true, source: "analysis_target" }, @@ -152,10 +153,13 @@ describe("completed partial process capture MCP projection", () => { toolRegistrationOptions(captureContract), async () => delivery.toCallToolResult(err(failure), captureContract), ); - const client = new Client({ - name: "process-partial-error-client", - version: "1", - }); + const client = new Client( + { + name: "process-partial-error-client", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -292,10 +296,13 @@ describe("incomplete partial process observations MCP projection", () => { toolRegistrationOptions(captureContract), async () => delivery.toCallToolResult(err(failure), captureContract), ); - const client = new Client({ - name: "process-partial-observations-client", - version: "1", - }); + const client = new Client( + { + name: "process-partial-observations-client", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/boundary/mcp/toolSchemaValidity.test.ts b/tests/boundary/mcp/toolSchemaValidity.test.ts index 00c6df22ef..976824652d 100644 --- a/tests/boundary/mcp/toolSchemaValidity.test.ts +++ b/tests/boundary/mcp/toolSchemaValidity.test.ts @@ -30,6 +30,7 @@ import { THIRD_BOOK, } from "../../fixtures/environmentStateWrites.js"; import { advertisedToolPresentation } from "../../../src/contracts/mcpSchemaPresentation.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; interface ToolSchemas { readonly name: string; @@ -344,7 +345,10 @@ const advertiseAndEnforceProcessEnvironmentKeyConstraint = }; }, ); - const client = new Client({ name: "process-schema", version: "0" }); + const client = new Client( + { name: "process-schema", version: "0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -464,7 +468,10 @@ describe("MCP JSON Schema validity", () => { it("advertises valid input and output schemas for every canonical tool", async () => { const server = new McpServer({ name: "schema-validation", version: "0" }); - const client = new Client({ name: "schema-validation", version: "0" }); + const client = new Client( + { name: "schema-validation", version: "0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); for (const contract of TOOL_CONTRACTS) @@ -523,7 +530,10 @@ describe("MCP JSON Schema validity", () => { describe("MCP root input schemas", () => { it("advertises object roots while enforcing union requirements at runtime", async () => { const server = new McpServer({ name: "schema-constraints", version: "0" }); - const client = new Client({ name: "schema-constraints", version: "0" }); + const client = new Client( + { name: "schema-constraints", version: "0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); for (const contract of TOOL_CONTRACTS) @@ -666,7 +676,10 @@ const advertiseAndEnforceItemSelectorCollectionConstraints = content: [], }), ); - const client = new Client({ name: "item-selector-schema", version: "0" }); + const client = new Client( + { name: "item-selector-schema", version: "0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -742,10 +755,13 @@ describe("MCP process input JSON Schema", () => { name: "process-schema-validation", version: "0", }); - const client = new Client({ - name: "process-schema-validation", - version: "0", - }); + const client = new Client( + { + name: "process-schema-validation", + version: "0", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); for (const contract of TOOL_CONTRACTS) diff --git a/tests/boundary/mcp/wasmArtifactMcp.test.ts b/tests/boundary/mcp/wasmArtifactMcp.test.ts index d6e0c6b485..d6ec7fd9cb 100644 --- a/tests/boundary/mcp/wasmArtifactMcp.test.ts +++ b/tests/boundary/mcp/wasmArtifactMcp.test.ts @@ -733,7 +733,10 @@ it("rejects malformed paths, refuses WASM summary delivery before provider work { kind: "fixed", analysis: session }, { wasmArtifact: service }, ); - const client = new Client({ name: "wasm-fixed-delivery", version: "1" }); + const client = new Client( + { name: "wasm-fixed-delivery", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [a, b] = InMemoryTransport.createLinkedPair(); try { await server.connect(b); @@ -861,7 +864,10 @@ it("compares caller-owned complete inline WASM sources on a fixed server without { kind: "fixed", analysis: session }, { wasmArtifact: service }, ); - const client = new Client({ name: "wasm-fixed-comparison", version: "1" }); + const client = new Client( + { name: "wasm-fixed-comparison", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { @@ -910,7 +916,10 @@ it("retries cleanup of the injected WASM module after server shutdown fails", as { kind: "session", session }, { wasmArtifact: service }, ); - const client = new Client({ name: "wasm-cleanup-retry", version: "1" }); + const client = new Client( + { name: "wasm-cleanup-retry", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [a, b] = InMemoryTransport.createLinkedPair(); try { await server.connect(b); diff --git a/tests/boundary/mcp/webBundleContainmentMcp.test.ts b/tests/boundary/mcp/webBundleContainmentMcp.test.ts index e4bb56bfd7..a5db7937f9 100644 --- a/tests/boundary/mcp/webBundleContainmentMcp.test.ts +++ b/tests/boundary/mcp/webBundleContainmentMcp.test.ts @@ -11,6 +11,7 @@ import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { observed } from "../../fixtures/analysisExecution.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { startFakeCdpBrowser } from "../../fixtures/fakeCdpBrowser.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const capturedSource = ` fetch("/api/orders"); @@ -54,10 +55,13 @@ it("retains timeout Evidence and recovers on the same MCP server", async () => { }), }, ); - const client = new Client({ - name: "web-bundle-containment-test", - version: "1", - }); + const client = new Client( + { + name: "web-bundle-containment-test", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server, session); diff --git a/tests/boundary/mcp/webModuleTraceMcp.test.ts b/tests/boundary/mcp/webModuleTraceMcp.test.ts index cc1cc1835d..c378d79027 100644 --- a/tests/boundary/mcp/webModuleTraceMcp.test.ts +++ b/tests/boundary/mcp/webModuleTraceMcp.test.ts @@ -23,6 +23,7 @@ import { webModuleResolverFixture, } from "../../fixtures/webModuleTrace.js"; import { releaseOwnedCleanup } from "../../support/cleanupRelease.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("publishes valid SDK schemas and records the named module trace without a binary target", async () => { const artifacts = webModuleArtifactsFixture(); @@ -37,7 +38,10 @@ it("publishes valid SDK schemas and records the named module trace without a bin { kind: "session", session }, { webModuleTrace: service }, ); - const client = new Client({ name: "module-contract", version: "1" }); + const client = new Client( + { name: "module-contract", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); @@ -405,7 +409,10 @@ const createModuleFinalizationHarness = async ( { kind: "session", session }, { webModuleTrace: service }, ); - const client = new Client({ name: "module-finalization", version: "1" }); + const client = new Client( + { name: "module-finalization", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { allowClose = true; allowArtifactClose = true; diff --git a/tests/boundary/mcp/webNetworkCaptureMcp.test.ts b/tests/boundary/mcp/webNetworkCaptureMcp.test.ts index e4860c4fe4..8bc8d095c7 100644 --- a/tests/boundary/mcp/webNetworkCaptureMcp.test.ts +++ b/tests/boundary/mcp/webNetworkCaptureMcp.test.ts @@ -16,6 +16,7 @@ import { webNetworkCaptureSchema } from "../../../src/domain/webNetworkCapture.j import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestMcp } from "../../support/mcp/mcpFixture.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const syntheticCaptureService = () => new WebNetworkCaptureService({ @@ -48,10 +49,13 @@ it("publishes valid SDK schemas and retains historical inline Evidence with the { kind: "session", session }, { webNetworkCapture: service }, ); - const client = new Client({ - name: "historical-capture-contract", - version: "1", - }); + const client = new Client( + { + name: "historical-capture-contract", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/webRuntimeMcp.test.ts b/tests/boundary/mcp/webRuntimeMcp.test.ts index fe50080e8e..3787b2c8a1 100644 --- a/tests/boundary/mcp/webRuntimeMcp.test.ts +++ b/tests/boundary/mcp/webRuntimeMcp.test.ts @@ -125,7 +125,10 @@ it("reports provider progress for observe_web_execution to the MCP caller", asyn }), }, ); - const client = new Client({ name: "web-runtime-progress", version: "1" }); + const client = new Client( + { name: "web-runtime-progress", version: "1" }, + { jsonSchemaValidator: schemaValidation }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/webSourceLocationMcp.test.ts b/tests/boundary/mcp/webSourceLocationMcp.test.ts index ec490a5c64..8d5dcd56ae 100644 --- a/tests/boundary/mcp/webSourceLocationMcp.test.ts +++ b/tests/boundary/mcp/webSourceLocationMcp.test.ts @@ -18,6 +18,7 @@ import { SourceMapDecoder } from "../../../src/javascript/sourceMaps/SourceMapDe import { createSystemProcessOwnershipHost } from "../../../src/process/ProcessOwnershipObservation.js"; import { createApplicationMcpHarness } from "../../fixtures/applicationMcpHarness.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it("publishes valid SDK schemas and records the named module trace without a binary target", async () => { const service = new WebSourceLocationService( @@ -38,7 +39,10 @@ it("publishes valid SDK schemas and records the named module trace without a bin { kind: "session", session }, { webSourceLocation: service }, ); - const client = new Client({ name: "module-contract", version: "1" }); + const client = new Client( + { name: "module-contract", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/mcp/workflowSnapshotReplayMcp.test.ts b/tests/boundary/mcp/workflowSnapshotReplayMcp.test.ts index f0a069d556..fbf9a454b0 100644 --- a/tests/boundary/mcp/workflowSnapshotReplayMcp.test.ts +++ b/tests/boundary/mcp/workflowSnapshotReplayMcp.test.ts @@ -34,6 +34,7 @@ import { silentLogger } from "../../../src/logger.js"; import { createServer } from "../../../src/server/createServer.js"; import { toolContract } from "../../../src/contracts/toolContracts.js"; import { recordUnknownInputSchema } from "../../../src/domain/residualUnknown.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const identity = { id: "fixture", name: "Fixture", version: "1" } as const; const profile = createAnalysisProfile(identity, { fixture: true }); @@ -892,7 +893,10 @@ const connectWorkflowMcp = async ( ...(providerEnvironment === undefined ? {} : { providerEnvironment }), }, ); - const mcp = new Client({ name: clientName, version: "1.0.0" }); + const mcp = new Client( + { name: clientName, version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server); diff --git a/tests/boundary/process/androidMappingMcp.test.ts b/tests/boundary/process/androidMappingMcp.test.ts index 61302b3243..eeabf88816 100644 --- a/tests/boundary/process/androidMappingMcp.test.ts +++ b/tests/boundary/process/androidMappingMcp.test.ts @@ -1,6 +1,5 @@ import { fileIdentity } from "../../fixtures/evidenceSubject.js"; import { canonicalOutputSchema } from "../../fixtures/canonicalOutputSchema.js"; -import { Client, InMemoryTransport } from "@modelcontextprotocol/client"; import { Ajv2020 } from "ajv/dist/2020.js"; import { createHash } from "node:crypto"; import { readFile, truncate, unlink, writeFile } from "node:fs/promises"; @@ -20,6 +19,7 @@ import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createJadxProtocolFixture } from "../../fixtures/android/jadx.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createTestMcp } from "../../support/mcp/mcpFixture.js"; const it = test.skipIf(process.platform === "win32"); @@ -38,19 +38,15 @@ const connect = async () => { }, }, ); - const client = new Client({ + const mcp = createTestMcp(); + onTestFinished(async () => { + await mcp.close(); + await session.close(); + }); + const client = await mcp.connect(server, { name: "android-mapping-regression", version: "1", }); - onTestFinished(async () => { - await client.close(); - await server.close(); - await session.close(); - }); - const [clientTransport, serverTransport] = - InMemoryTransport.createLinkedPair(); - await server.connect(serverTransport); - await client.connect(clientTransport); const inspect = (mapping_path: string) => client.callTool({ name: "inspect_android_class", diff --git a/tests/boundary/process/androidSearchEvidenceBudget.test.ts b/tests/boundary/process/androidSearchEvidenceBudget.test.ts index 4011e02c8d..4b572f7ed5 100644 --- a/tests/boundary/process/androidSearchEvidenceBudget.test.ts +++ b/tests/boundary/process/androidSearchEvidenceBudget.test.ts @@ -11,6 +11,7 @@ import { createJadxProtocolFixture, verifyJadxFixtureCleanup, } from "../../fixtures/android/jadx.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const INVENTORY_CLASS_COUNT = 7096; @@ -72,10 +73,13 @@ test("delivers bounded search_android_classes Evidence while retaining the compl { kind: "session", session }, { androidAnalysis: provider }, ); - const client = new Client({ - name: "android-search-inventory-budget", - version: "1", - }); + const client = new Client( + { + name: "android-search-inventory-budget", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/process/jadxStartup.test.ts b/tests/boundary/process/jadxStartup.test.ts index c53b38e4f7..44b9c972d0 100644 --- a/tests/boundary/process/jadxStartup.test.ts +++ b/tests/boundary/process/jadxStartup.test.ts @@ -15,6 +15,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { parseMcpToolError } from "../../fixtures/mcpToolError.js"; import { createJadxStartupFixture as setup } from "../../fixtures/android/jadxStartup.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const it = test.skipIf(process.platform === "win32"); @@ -286,10 +287,13 @@ it("returns terminal startup diagnostics and partial identity through the MCP co { kind: "session", session }, { androidAnalysis: f.provider }, ); - const client = new Client({ - name: "jadx-startup-finalization", - version: "1", - }); + const client = new Client( + { + name: "jadx-startup-finalization", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { const [local, remote] = InMemoryTransport.createLinkedPair(); await server.connect(remote); diff --git a/tests/boundary/process/processCaptureCancellationAdapters.test.ts b/tests/boundary/process/processCaptureCancellationAdapters.test.ts index 17bbba3760..aa3fd0177d 100644 --- a/tests/boundary/process/processCaptureCancellationAdapters.test.ts +++ b/tests/boundary/process/processCaptureCancellationAdapters.test.ts @@ -17,6 +17,7 @@ import { } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { itWithCaptureCapability } from "./processCaptureCapability.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const fixture = fileURLToPath( new URL("../../fixtures/processCaptureCancellation.mjs", import.meta.url), @@ -268,10 +269,13 @@ itWithCaptureCapability( }, ); const server = createServer({ kind: "session", session }, { logger }); - const client = new Client({ - name: "process-settlement-cancellation", - version: "1", - }); + const client = new Client( + { + name: "process-settlement-cancellation", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); let marker: Marker | undefined; onTestFinished(async () => { await finishCleanup([ diff --git a/tests/boundary/process/processDescendantPidAdapters.test.ts b/tests/boundary/process/processDescendantPidAdapters.test.ts index 07abe48b41..8cb4bd38b0 100644 --- a/tests/boundary/process/processDescendantPidAdapters.test.ts +++ b/tests/boundary/process/processDescendantPidAdapters.test.ts @@ -14,6 +14,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { itWithCaptureCapability } from "./processCaptureCapability.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const exec = promisify(execFile); const fixture = fileURLToPath( @@ -56,10 +57,13 @@ itWithCaptureCapability.each([ throw new Error("Process capture must not launch a binary provider"); }); const server = createServer({ kind: "session", session }); - client = new Client({ - name: "descendant-pid-normalization", - version: "1", - }); + client = new Client( + { + name: "descendant-pid-normalization", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const connected = client; onTestFinished(async () => { await connected.close(); diff --git a/tests/boundary/process/processSessionMcp.test.ts b/tests/boundary/process/processSessionMcp.test.ts index f828477c79..05a2f84fb5 100644 --- a/tests/boundary/process/processSessionMcp.test.ts +++ b/tests/boundary/process/processSessionMcp.test.ts @@ -18,6 +18,7 @@ import { silentLogger } from "../../../src/logger.js"; import type { ProcessCapture } from "../../../src/domain/process/processCaptureParsing.js"; import { itWithCaptureCapability } from "./processCaptureCapability.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const processFixture = fileURLToPath( new URL("../../fixtures/processFidelity.mjs", import.meta.url), @@ -47,7 +48,10 @@ it("rejects oversized initial and resize terminal buffers through MCP before lau { kind: "session", session }, { logger: silentLogger }, ); - const client = new Client({ name: "terminal-admission", version: "1" }); + const client = new Client( + { name: "terminal-admission", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); resources.push(client, server, session); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); @@ -93,7 +97,10 @@ itWithCaptureCapability( { kind: "session", session }, { logger: silentLogger }, ); - const client = new Client({ name: "process-plan", version: "1" }); + const client = new Client( + { name: "process-plan", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); resources.push(client, server, session); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); @@ -139,10 +146,13 @@ itWithCaptureCapability( { kind: "session", session }, { logger: silentLogger }, ); - const client = new Client({ - name: "process-normalized-budget", - version: "1", - }); + const client = new Client( + { + name: "process-normalized-budget", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); resources.push(client, server, session); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); @@ -242,7 +252,10 @@ itWithCaptureCapability( logger: silentLogger, }, ); - const mcp = new Client({ name: "process-unknown", version: "1.0.0" }); + const mcp = new Client( + { name: "process-unknown", version: "1.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(mcp, server); @@ -326,7 +339,10 @@ itWithCaptureCapability( }, }, ); - const client = new Client({ name: "process-mcp-env", version: "1" }); + const client = new Client( + { name: "process-mcp-env", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); resources.push(client, server, session); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); diff --git a/tests/boundary/process/processTruncationAdapters.test.ts b/tests/boundary/process/processTruncationAdapters.test.ts index a44005378c..f31d8abb66 100644 --- a/tests/boundary/process/processTruncationAdapters.test.ts +++ b/tests/boundary/process/processTruncationAdapters.test.ts @@ -14,6 +14,7 @@ import { createServer } from "../../../src/server/createServer.js"; import { createTestBinarySession } from "../../fixtures/binarySession.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { itWithCaptureCapability } from "./processCaptureCapability.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; const exec = promisify(execFile); const capture = async ( @@ -41,7 +42,10 @@ const capture = async ( throw new Error("Capture must not launch a binary provider"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "truncation-coverage", version: "1" }); + const client = new Client( + { name: "truncation-coverage", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/boundary/process/verifierMcpOwner.test.ts b/tests/boundary/process/verifierMcpOwner.test.ts index d44c752744..5b834c9b5c 100644 --- a/tests/boundary/process/verifierMcpOwner.test.ts +++ b/tests/boundary/process/verifierMcpOwner.test.ts @@ -8,13 +8,17 @@ import { VerifierStdioTransport, } from "../../../scripts/lib/verifier-mcp-owner.mjs"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; it.each(["initialize", "discovery"])( "closes the real MCP child when %s fails before ownership transfers", async (mode) => { const workspace = await createTestTempDirectory("rea-verifier-mcp-owner-"); const marker = join(workspace, "exit.txt"); - const client = new Client({ name: "verifier-owner-test", version: "1" }); + const client = new Client( + { name: "verifier-owner-test", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const transport = new VerifierStdioTransport({ command: process.execPath, args: [ diff --git a/tests/boundary/providers/RizinDebugSessionInferiorStdin.test.ts b/tests/boundary/providers/RizinDebugSessionInferiorStdin.test.ts index 3b77361917..72220187cd 100644 --- a/tests/boundary/providers/RizinDebugSessionInferiorStdin.test.ts +++ b/tests/boundary/providers/RizinDebugSessionInferiorStdin.test.ts @@ -21,6 +21,7 @@ import { RizinDebugSessionManager } from "../../../src/rizin/RizinDebugSessionMa import { createToolResultDelivery } from "../../../src/server/toolResult.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { rizinTestTtyPathPattern } from "./RizinTestInferiorTty.js"; +import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js"; // Real Rizin is not exercised here. These launchers apply `-R` keys the way the // #8642 report observed on Rizin 0.9.1, and the target is a real process, so the @@ -348,7 +349,10 @@ linuxIt.each([ const current = await createFixture({ target, reportsInferior: true }); const manager = createManager(current); const server = rizinDebugMcpServer("rizin-stdin", manager); - const client = new Client({ name: "rizin-stdin", version: "1" }); + const client = new Client( + { name: "rizin-stdin", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); diff --git a/tests/boundary/providers/jeb/failureEnvelopes.test.ts b/tests/boundary/providers/jeb/failureEnvelopes.test.ts index 7eed72335f..9b028df6ef 100644 --- a/tests/boundary/providers/jeb/failureEnvelopes.test.ts +++ b/tests/boundary/providers/jeb/failureEnvelopes.test.ts @@ -7,6 +7,7 @@ import { JEB_ENGINE_TOOLS } from "../../../../src/jeb/JebMcpConnection.js"; import type { JsonValue } from "../../../../src/domain/jsonValue.js"; import { createServer } from "../../../../src/server/createServer.js"; import { createTestBinarySession } from "../../../fixtures/binarySession.js"; +import { createMcpSchemaValidation } from "../../../fixtures/mcpSchemaValidation.js"; const requestSchema = z.object({ id: z.union([z.string(), z.number()]).optional(), @@ -139,7 +140,10 @@ const refuseOpenProject = async ( { kind: "session", session }, { jebAnalysis: provider, environment: {} }, ); - const client = new Client({ name: "jeb-failure-contract", version: "1" }); + const client = new Client( + { name: "jeb-failure-contract", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); diff --git a/tests/fixtures/buildComputerMcp.ts b/tests/fixtures/buildComputerMcp.ts index 2cdcfeb2aa..42558a95f8 100644 --- a/tests/fixtures/buildComputerMcp.ts +++ b/tests/fixtures/buildComputerMcp.ts @@ -22,6 +22,7 @@ import { type FakeComputerOptions, } from "./fakeAgentEnvComputer.js"; import { createTestTempDirectory } from "./temporaryDirectory.js"; +import { createMcpSchemaValidation } from "./mcpSchemaValidation.js"; /** The host's environment without the settings the opt-in real test exports, which would reach past the fakes. */ const hostEnvironment = Object.fromEntries( @@ -66,7 +67,10 @@ export const connectBuildServer = async ( : { desktopBuildStartTiming: startTiming }), }, ); - const client = new Client({ name: "build-computer-mcp", version: "1" }); + const client = new Client( + { name: "build-computer-mcp", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await closeVerifierResources([ () => client.close(), diff --git a/tests/fixtures/mcpSchemaValidation.ts b/tests/fixtures/mcpSchemaValidation.ts index 0add64e973..2b2ada1080 100644 --- a/tests/fixtures/mcpSchemaValidation.ts +++ b/tests/fixtures/mcpSchemaValidation.ts @@ -9,36 +9,64 @@ import { import { Ajv2020 } from "ajv/dist/2020.js"; import type { ValidateFunction } from "ajv"; +/** + * Compiled SDK validators keyed by full schema text, shared by every client in + * the worker. A validator call is synchronous and keeps no state between + * calls, so clients can share it. Compiling REA's largest advertised schema + * allocates hundreds of MiB and takes most of a second, while the result + * retains about 16 MiB; recompiling it for each connection dominated MCP test + * memory. The count bound keeps workers that share a module graph across + * files from retaining every catalog schema; least recently used goes first. + */ +export const SHARED_COMPILED_VALIDATORS = 32; +const sharedCompiledValidators = new Map< + string, + JsonSchemaValidator +>(); +const sharedCompiledValidator = (key: string): JsonSchemaValidator => { + let validator = sharedCompiledValidators.get(key); + if (validator === undefined) { + validator = compiledValidator(key); + if (sharedCompiledValidators.size >= SHARED_COMPILED_VALIDATORS) { + const oldest = sharedCompiledValidators.keys().next(); + if (oldest.done !== true) sharedCompiledValidators.delete(oldest.value); + } + } else sharedCompiledValidators.delete(key); + sharedCompiledValidators.set(key, validator); + return validator; +}; + +const compiledValidator = (key: string): JsonSchemaValidator => { + const schema = JSON.parse(key) as Record; + // Keep shared definitions as compiled functions instead of expanding them + // at every reference. Other dialects retain SDK dispatch. + const provider = + schema.$schema === undefined || + schema.$schema === "https://json-schema.org/draft/2020-12/schema" + ? new AjvJsonSchemaValidator( + addFormats( + new Ajv2020({ + strict: false, + validateFormats: true, + validateSchema: false, + allErrors: true, + inlineRefs: false, + code: { optimize: false }, + }), + ), + ) + : new AjvJsonSchemaValidator(); + // Each full schema owns its provider, including dialect dispatch. + // Distinct schemas may legally reuse the same $id in separate servers. + return provider.getValidator(schema as JsonSchemaType); +}; + /** Share immutable schema preparation within one test file, never its sessions. */ export const createMcpSchemaValidation = () => { const sdkValidators = new Map>(); const assertionValidators = new Map(); const meta = new Ajv2020({ strict: false, validateFormats: false }); let errors: unknown = null; - const compiledValidator = (key: string): JsonSchemaValidator => { - const schema = JSON.parse(key) as Record; - // Keep shared definitions as compiled functions instead of expanding them - // at every reference. Other dialects retain SDK dispatch. - const provider = - schema.$schema === undefined || - schema.$schema === "https://json-schema.org/draft/2020-12/schema" - ? new AjvJsonSchemaValidator( - addFormats( - new Ajv2020({ - strict: false, - validateFormats: true, - validateSchema: false, - allErrors: true, - inlineRefs: false, - code: { optimize: false }, - }), - ), - ) - : new AjvJsonSchemaValidator(); - // Each full schema owns its provider, including dialect dispatch. - // Distinct schemas may legally reuse the same $id in separate servers. - return provider.getValidator(schema as JsonSchemaType); - }; return { getValidator( schema: JsonSchemaType | Readonly>, @@ -51,7 +79,8 @@ export const createMcpSchemaValidation = () => { // call. Compile on first use, so a session pays only for the tools it // calls; REA's full catalog otherwise costs seconds of compilation. let compiled: JsonSchemaValidator | undefined; - validator = (input) => (compiled ??= compiledValidator(key))(input); + validator = (input) => + (compiled ??= sharedCompiledValidator(key))(input); sdkValidators.set(key, validator); } return validator as JsonSchemaValidator; diff --git a/tests/fixtures/promptOccurrenceCompletion.ts b/tests/fixtures/promptOccurrenceCompletion.ts index 8bcd536d65..78bfa554c5 100644 --- a/tests/fixtures/promptOccurrenceCompletion.ts +++ b/tests/fixtures/promptOccurrenceCompletion.ts @@ -17,6 +17,7 @@ import { parseArtifactInventoryEvidence } from "../../src/domain/artifactInvento import { compareUnicodeCodePoints } from "../../src/domain/unicodeCodePointOrder.js"; import { createEvidence } from "../../src/domain/evidence.js"; import { createServer } from "../../src/server/createServer.js"; +import { createMcpSchemaValidation } from "./mcpSchemaValidation.js"; // Run on Node's main-thread stack, like the stdio MCP server. No real ZIP or // provider is involved: these are authenticated, synthetic inventory facts. @@ -127,10 +128,13 @@ const session = new BinarySession( const retained = session.recordEvidence(evidence); if (!retained.ok) throw retained.error; const server = createServer({ kind: "session", session }, { environment: {} }); -const client = new Client({ - name: "occurrence-completion-control", - version: "1", -}); +const client = new Client( + { + name: "occurrence-completion-control", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, +); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { await server.connect(serverTransport); diff --git a/tests/process-global/adbStartMcp.test.ts b/tests/process-global/adbStartMcp.test.ts index f1d069671c..260a4e85b6 100644 --- a/tests/process-global/adbStartMcp.test.ts +++ b/tests/process-global/adbStartMcp.test.ts @@ -10,6 +10,7 @@ import { execFileOutput, } from "../../src/process/ExecFileOutput.js"; import { toolContract } from "../../src/contracts/toolContracts.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; vi.mock("../../src/process/ExecFileOutput.js", async (importOriginal) => ({ ...(await importOriginal< @@ -60,7 +61,10 @@ it.each(["start_adb_app", "start_adb_activity"] as const)( const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); - const client = new Client({ name: "adb-start-boundary", version: "0.0.0" }); + const client = new Client( + { name: "adb-start-boundary", version: "0.0.0" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(() => client.close()); await client.connect(clientTransport); const input = diff --git a/tests/process-global/bundleComparisonFailures.test.ts b/tests/process-global/bundleComparisonFailures.test.ts index 8423e4368c..6938b6f128 100644 --- a/tests/process-global/bundleComparisonFailures.test.ts +++ b/tests/process-global/bundleComparisonFailures.test.ts @@ -27,6 +27,7 @@ import * as evidenceDomain from "../../src/domain/evidence.js"; import { createServer } from "../../src/server/createServer.js"; import { createTestBinarySession } from "../fixtures/binarySession.js"; import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; const unexpectedBundleFailures = [ new TypeError("bundle authentication TypeError"), @@ -187,7 +188,10 @@ it.each(unexpectedBundleFailures)( throw new Error("Evidence import must not launch a provider"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "bundle-import-failure", version: "1" }); + const client = new Client( + { name: "bundle-import-failure", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); spyOnBundleParse(failure); diff --git a/tests/process-global/derivedOperationFailures.test.ts b/tests/process-global/derivedOperationFailures.test.ts index da043c2f4f..2934c99d65 100644 --- a/tests/process-global/derivedOperationFailures.test.ts +++ b/tests/process-global/derivedOperationFailures.test.ts @@ -75,6 +75,7 @@ import { nativeMatchingInventory, nativeMatchingDetails, } from "../fixtures/nativeFunctionMatching.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; /** Unexpected implementation failures retain the SDK text surface, without a typed caller error. */ const expectUnexpectedToolFailure = ( @@ -201,10 +202,13 @@ const withSdk = async ( ); }); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "derived-operation-failures", - version: "1", - }); + const client = new Client( + { + name: "derived-operation-failures", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/process-global/javascriptAnalysisCancellation.test.ts b/tests/process-global/javascriptAnalysisCancellation.test.ts index 3acd89bf01..5025c83dff 100644 --- a/tests/process-global/javascriptAnalysisCancellation.test.ts +++ b/tests/process-global/javascriptAnalysisCancellation.test.ts @@ -13,6 +13,7 @@ import { } from "../fixtures/binarySession.js"; import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; import type { ProgressUpdate } from "../../src/ports/ProgressReporter.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; const progressBoundary = vi.hoisted(() => ({ observe: undefined as ((update: ProgressUpdate) => Promise) | undefined, @@ -129,10 +130,13 @@ it.each([ }, ); const server = createServer({ kind: "session", session }, { logger }); - const client = new Client({ - name: "javascript-cancellation", - version: "1", - }); + const client = new Client( + { + name: "javascript-cancellation", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { boundary.release(); progressBoundary.observe = undefined; diff --git a/tests/process-global/javascriptFilesystemErrors.test.ts b/tests/process-global/javascriptFilesystemErrors.test.ts index d19db6265b..9b41239159 100644 --- a/tests/process-global/javascriptFilesystemErrors.test.ts +++ b/tests/process-global/javascriptFilesystemErrors.test.ts @@ -33,6 +33,7 @@ vi.mock("node:fs/promises", async (importOriginal) => { }); import { createServer } from "../../src/server/createServer.js"; import { createTestBinarySession } from "../fixtures/binarySession.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; it.each([ { method: "lstat", code: "EACCES" }, @@ -48,7 +49,10 @@ it.each([ ); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "javascript-filesystem", version: "1" }); + const client = new Client( + { name: "javascript-filesystem", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/process-global/managedBundleReadGuards.test.ts b/tests/process-global/managedBundleReadGuards.test.ts index cba048975d..54c8d59dfd 100644 --- a/tests/process-global/managedBundleReadGuards.test.ts +++ b/tests/process-global/managedBundleReadGuards.test.ts @@ -27,6 +27,7 @@ import { requireAuthenticationHeadroom } from "../../src/application/JsonAuthent import { SOURCE_TO_BUNDLE_COMPARISON_EXAMPLE } from "../../src/contracts/javascript/javascriptApplicationWorkflowExamples.js"; import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; import { holdFirstFileRead } from "../support/holdFirstFileRead.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; vi.mock("../../src/application/JsonAuthenticationHeadroom.js", { spy: true }); vi.mock("node:v8", { spy: true }); @@ -73,10 +74,13 @@ it.each(["compare_bundles", "match_native_functions"])( throw new Error("Comparison must not open a target"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ - name: "bundle-operation-refusal", - version: "1", - }); + const client = new Client( + { + name: "bundle-operation-refusal", + version: "1", + }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); try { diff --git a/tests/process-global/mcpDeliveryEnvironment.test.ts b/tests/process-global/mcpDeliveryEnvironment.test.ts index ad8b494945..23b0a80544 100644 --- a/tests/process-global/mcpDeliveryEnvironment.test.ts +++ b/tests/process-global/mcpDeliveryEnvironment.test.ts @@ -11,6 +11,7 @@ import { run } from "../../src/main.js"; import { createServer } from "../../src/server/createServer.js"; import type { EvidenceMcpServer } from "../../src/server/EvidenceMcpServer.js"; import { parseMcpToolError } from "../fixtures/mcpToolError.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; const resources: Array<{ close(): Promise }> = []; afterEach(async () => { @@ -19,7 +20,10 @@ afterEach(async () => { }); const connect = async (server: EvidenceMcpServer) => { - const client = new Client({ name: "selected-delivery", version: "1" }); + const client = new Client( + { name: "selected-delivery", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); resources.push(client, server); diff --git a/tests/process-global/processCaptureFilenameBytes.test.ts b/tests/process-global/processCaptureFilenameBytes.test.ts index 425289c9cc..ea5a8e976f 100644 --- a/tests/process-global/processCaptureFilenameBytes.test.ts +++ b/tests/process-global/processCaptureFilenameBytes.test.ts @@ -12,6 +12,7 @@ import { createServer } from "../../src/server/createServer.js"; import { createTestBinarySession } from "../fixtures/binarySession.js"; import { advertisedSchemaErrors } from "../fixtures/mcpAdvertisedSchemaValidity.js"; import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; vi.mock("node:fs/promises", async (importOriginal) => { const actual = await importOriginal(); @@ -138,7 +139,10 @@ it("advertises byte-preserving omissions in valid SDK-converted MCP schemas", as throw new Error("Schema discovery must not launch a provider"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "capture-name-bytes", version: "1" }); + const client = new Client( + { name: "capture-name-bytes", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); try { const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); diff --git a/tests/process-global/processCaptureServerEnvironment.test.ts b/tests/process-global/processCaptureServerEnvironment.test.ts index d80ccae67d..6c3e70dbbf 100644 --- a/tests/process-global/processCaptureServerEnvironment.test.ts +++ b/tests/process-global/processCaptureServerEnvironment.test.ts @@ -6,6 +6,7 @@ import { err } from "../../src/domain/result.js"; import { captureProcessScenario } from "../../src/process/capture/ProcessHarness.js"; import { createServer } from "../../src/server/createServer.js"; import { createTestBinarySession } from "../fixtures/binarySession.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; // Windows rejects capture before it reads the environment, so record the // environment the MCP adapter hands to the capture owner on every host. @@ -43,7 +44,10 @@ it("captures MCP process scenarios with the server's selected environment", asyn { kind: "session", session }, { environment: { REA_CAPTURE_SELECTION_MARKER: "selected" } }, ); - const client = new Client({ name: "capture-environment", version: "1" }); + const client = new Client( + { name: "capture-environment", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); resources.push(client, server, session); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); diff --git a/tests/process-global/processSnapshotCleanupMcp.test.ts b/tests/process-global/processSnapshotCleanupMcp.test.ts index da818eb0f4..d6a259ff84 100644 --- a/tests/process-global/processSnapshotCleanupMcp.test.ts +++ b/tests/process-global/processSnapshotCleanupMcp.test.ts @@ -40,6 +40,7 @@ import { createServer } from "../../src/server/createServer.js"; import { silentLogger } from "../../src/logger.js"; import { ToolResultDelivery } from "../../src/server/ToolResultDelivery.js"; import { ok } from "../../src/domain/result.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; const connectSession = async () => { const session = createTestBinarySession( @@ -53,7 +54,10 @@ const connectSession = async () => { { kind: "session", session }, { logger: silentLogger }, ); - const client = new Client({ name: "process-snapshot-cleanup", version: "1" }); + const client = new Client( + { name: "process-snapshot-cleanup", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport); diff --git a/tests/process-global/sourceToBundleReferenceGuards.test.ts b/tests/process-global/sourceToBundleReferenceGuards.test.ts index fe8aec4e3b..22839fe68d 100644 --- a/tests/process-global/sourceToBundleReferenceGuards.test.ts +++ b/tests/process-global/sourceToBundleReferenceGuards.test.ts @@ -15,6 +15,7 @@ import { createServer } from "../../src/server/createServer.js"; import { ToolResultDelivery } from "../../src/server/ToolResultDelivery.js"; import { createTestBinarySession } from "../fixtures/binarySession.js"; import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; vi.mock("../../src/application/JsonAuthenticationHeadroom.js", { spy: true }); vi.mock( @@ -196,7 +197,10 @@ const connectedComparison = async () => { throw new Error("Comparison must not start a native provider"); }); const server = createServer({ kind: "session", session }); - const client = new Client({ name: "source-cancel", version: "1" }); + const client = new Client( + { name: "source-cancel", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); onTestFinished(async () => { await client.close(); await server.close(); diff --git a/tests/process-global/windowsNativeControlCapability.test.ts b/tests/process-global/windowsNativeControlCapability.test.ts index dc51612e33..2f2f5f3682 100644 --- a/tests/process-global/windowsNativeControlCapability.test.ts +++ b/tests/process-global/windowsNativeControlCapability.test.ts @@ -15,6 +15,7 @@ import { webSourceLocationArgs, webSourceLocationFixture, } from "../fixtures/webSourceLocation.js"; +import { createMcpSchemaValidation } from "../fixtures/mcpSchemaValidation.js"; // The owned launcher selects the Windows native path from HOST_PLATFORM. vi.mock("../../src/platform/HostPlatform.js", () => ({ @@ -108,7 +109,10 @@ it("reports a missing Windows native control as an unavailable capability", asyn ), }, ); - client = new Client({ name: "native-control-capability", version: "1" }); + client = new Client( + { name: "native-control-capability", version: "1" }, + { jsonSchemaValidator: createMcpSchemaValidation() }, + ); const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); await server.connect(serverTransport);