From 3102d18bfc3bb5c9fe6a3d37692a226032bc5d91 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Sat, 21 Nov 2026 20:40:30 -0500 Subject: [PATCH] test(mcp): consolidate artifact verifier catalog and schema checks (#13260) --- .../process/artifactMcpVerifierOutput.test.ts | 99 ++++++++----------- tests/fixtures/artifactMcpVerifierProbe.mjs | 78 ++++++--------- 2 files changed, 68 insertions(+), 109 deletions(-) diff --git a/tests/boundary/process/artifactMcpVerifierOutput.test.ts b/tests/boundary/process/artifactMcpVerifierOutput.test.ts index cb628ab802..d9a8530462 100644 --- a/tests/boundary/process/artifactMcpVerifierOutput.test.ts +++ b/tests/boundary/process/artifactMcpVerifierOutput.test.ts @@ -1,14 +1,13 @@ -import { execFile } from "node:child_process"; import { mkdir, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { fileURLToPath } from "node:url"; -import { promisify } from "node:util"; import { expect, it } from "vitest"; import { z } from "zod"; +import { createVerifierCommands } from "../../../scripts/lib/verify-commands.mjs"; +import { withVerifierCleanup } from "../../../scripts/lib/verifier-cleanup.mjs"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; -const exec = promisify(execFile); const observationSchema = z.strictObject({ accepted: z.boolean(), catalogRequests: z.number().int().nonnegative(), @@ -24,70 +23,59 @@ const observationSchema = z.strictObject({ .nullable(), }); -async function probe(mode: string, name = "Fixture.app") { +async function probe(mode: string) { const root = await createTestTempDirectory("rea-artifact-mcp-schema-"); - const target = join(root, name); + const target = join(root, "Fixture with spaces 雨.app"); await mkdir(join(target, "Contents", "Resources"), { recursive: true }); await writeFile( join(target, "Contents", "Info.plist"), 'CFBundleIdentifierdev.rea.schema-probe', ); - const { stdout } = await exec( - process.execPath, - [ - fileURLToPath( - new URL("../../fixtures/artifactMcpVerifierProbe.mjs", import.meta.url), + const owner = await createVerifierCommands(); + const { stdout } = await withVerifierCleanup( + () => + owner.exec( + process.execPath, + [ + fileURLToPath( + new URL( + "../../fixtures/artifactMcpVerifierProbe.mjs", + import.meta.url, + ), + ), + mode, + target, + ], + { timeout: 25_000 }, ), - mode, - target, - ], - // Retain cleanup time within the existing 30s test budget. - { timeout: 25_000 }, + [() => owner.close()], ); return observationSchema.parse(JSON.parse(stdout)); } -it("validates the real resource admission reply against its canonical output schema", async () => { - expect(await probe("healthy", "Fixture.app")).toEqual({ - accepted: true, - catalogRequests: 1, - corruptedReplies: 0, - toolCalls: 1, - toolTimeouts: [null], - error: null, +it("rejects a corrupted canonical path in a real resource admission reply", async () => { + const result = await probe("corrupt"); + expect(result.accepted).toBe(false); + expect(result.catalogRequests).toBe(1); + expect(result.corruptedReplies).toBe(1); + expect(result.error).toMatchObject({ + name: "ProtocolError", + code: -32602, + message: expect.stringMatching(/output schema.*canonical_path/u), }); }); -it.each(["Fixture.app", "Fixture with spaces 雨.app"])( - "rejects a corrupted canonical path in a real admission reply: %s", - async (name) => { - const result = await probe("corrupt", name); - expect(result.accepted).toBe(false); - expect(result.catalogRequests).toBe(1); - expect(result.corruptedReplies).toBe(1); - expect(result.error).toMatchObject({ - name: "ProtocolError", - code: -32602, - message: expect.stringMatching(/output schema.*canonical_path/u), - }); - }, -); - -it.each(["reuse", "concurrent"])( - "shares one schema discovery within one MCP connection: %s", - async (mode) => { - const result = await probe(mode); - expect(result.accepted).toBe(true); - expect(result.catalogRequests).toBe(1); - expect(result.toolCalls).toBe(mode === "reuse" ? 3 : 2); - }, -); - -it("rebinds the advertised catalog after reconnecting the same client", async () => { +it("shares cold and warm bindings, forwards the timeout and rebinds after reconnect", async () => { const result = await probe("reconnect"); - expect(result.accepted).toBe(true); - expect(result.catalogRequests).toBe(2); - expect(result.toolCalls).toBe(2); + expect(result).toMatchObject({ + accepted: true, + catalogRequests: 2, + toolCalls: 4, + error: null, + }); + expect(result.toolTimeouts.filter((timeout) => timeout !== null)).toEqual([ + 12_345, + ]); }); it("rejects a supplied schema override before dispatching that call", async () => { @@ -97,13 +85,6 @@ it("rejects a supplied schema override before dispatching that call", async () = expect(result.error?.message).toMatch(/owns the advertised schema/u); }); -it("preserves explicit request timeouts on schema-bound calls", async () => { - const result = await probe("request-options"); - expect(result.accepted).toBe(true); - expect(result.catalogRequests).toBe(1); - expect(result.toolTimeouts).toEqual([null, 12_345]); -}); - it.each(["duplicate-first", "duplicate-last"])( "rejects ambiguous named schemas independently of catalog order: %s", async (mode) => { diff --git a/tests/fixtures/artifactMcpVerifierProbe.mjs b/tests/fixtures/artifactMcpVerifierProbe.mjs index af84fcdc72..508cf8e4bd 100644 --- a/tests/fixtures/artifactMcpVerifierProbe.mjs +++ b/tests/fixtures/artifactMcpVerifierProbe.mjs @@ -1,23 +1,19 @@ import assert from "node:assert/strict"; import { fileURLToPath } from "node:url"; import { Client } from "@modelcontextprotocol/client"; -import { StdioClientTransport } from "@modelcontextprotocol/client/stdio"; import * as artifact from "../../scripts/lib/artifact-e2e.mjs"; +import { createOwnedMcpStdioTransport } from "../../scripts/lib/owned-mcp-stdio.mjs"; import { withVerifierCleanup } from "../../scripts/lib/verifier-cleanup.mjs"; const [mode, target] = process.argv.slice(2); assert.ok( [ - "healthy", "corrupt", - "reuse", - "concurrent", "reconnect", "duplicate-first", "duplicate-last", "override", - "request-options", "cancel-finalization", "failure-cancel-finalization", ].includes(mode), @@ -40,7 +36,6 @@ const request = Client.prototype.request; let catalogRequests = 0; let corruptedReplies = 0; let toolCalls = 0; -let connection = 0; const toolTimeouts = []; Client.prototype.request = async function (input, options) { if (input.method === "tools/list") catalogRequests++; @@ -49,14 +44,6 @@ Client.prototype.request = async function (input, options) { toolTimeouts.push(options?.timeout ?? null); } const result = await request.call(this, input, options); - if ( - mode === "override" && - input.method === "tools/call" && - input.params.name === "binary_session" - ) { - corruptedReplies++; - return { ...result, structuredContent: { result: 777 } }; - } if (input.method === "tools/list") { if (mode === "duplicate-first" || mode === "duplicate-last") { const listed = result.tools.find( @@ -97,63 +84,60 @@ Client.prototype.request = async function (input, options) { }; }; -const status = async (client) => { - const result = await artifact.artifactMcpCall(client, { - name: "binary_session", - arguments: {}, - }); +const status = async (client, options) => { + const result = await artifact.artifactMcpCall( + client, + { name: "binary_session", arguments: {} }, + options, + ); assert.notEqual(result.isError, true, JSON.stringify(result)); }; -async function standaloneConnections() { +async function reconnect() { const client = new Client({ name: "artifact-binding-probe", version: "1" }); - let firstVersion; - for ( - connection = 1; - connection <= (mode === "reconnect" ? 2 : 1); - connection++ - ) { - const transport = new StdioClientTransport({ + for (const warmReuse of [true, false]) { + const transport = await createOwnedMcpStdioTransport({ command: process.execPath, - args: [ + arguments: [ fileURLToPath(new URL("../../scripts/rea.mjs", import.meta.url)), "mcp", ], - env: { + hostEnvironment: { PATH: process.env.PATH ?? "/usr/bin:/bin", REA_LOG_LEVEL: "silent", }, - stderr: "pipe", + expectedCommand: null, }); await withVerifierCleanup(async () => { await client.connect(transport); - const version = client.getServerVersion(); - assert.ok(version); - if (firstVersion !== undefined) { - assert.notEqual(version, firstVersion); - assert.equal(version.name, firstVersion.name); - assert.equal(version.version, firstVersion.version); + const before = catalogRequests; + if (warmReuse) { + await Promise.all([ + status(client, { timeout: 12_345 }), + status(client), + ]); + await status(client); + } else { + await status(client); } - firstVersion = version; - if (mode === "concurrent") - await Promise.all([status(client), status(client)]); - else await status(client); + assert.equal( + catalogRequests - before, + 1, + "Expected one catalog read per connection", + ); }, [() => client.close(), () => transport.close()]); } } let error; try { - if (mode === "concurrent" || mode === "reconnect") - await standaloneConnections(); + if (mode === "reconnect") await reconnect(); else await artifact.withBundleResourcesMcp( target, async (client) => { if (mode === "failure-cancel-finalization") throw new Error("work failed before cancellation"); - if (mode === "reuse") - await Promise.all([status(client), status(client)]); if (mode === "override") await artifact.artifactMcpCall( client, @@ -166,12 +150,6 @@ try { }, }, ); - if (mode === "request-options") - await artifact.artifactMcpCall( - client, - { name: "binary_session", arguments: {} }, - { timeout: 12_345 }, - ); }, { signal: controller.signal }, );