test(mcp): stabilize lazy-loading verification

This commit is contained in:
morluto committed 2026-07-26 15:26:41 +00:00
1 parent fecddc0549
commit 7157ab0b70
5 files changed
+130 -21

No files matched your search

+62 -8
View File
@@ -57,6 +57,7 @@ const auxiliaryProviders = [
identity: provider.identity(),
capabilities: provider.capabilities(),
}));
const payloadJson = JSON.stringify({ catalog, auxiliaryProviders });
const source = await format(
`import type { ToolAnnotations } from "@modelcontextprotocol/server";
import type {
@@ -66,9 +67,7 @@ import type {
import type { ToolKind } from "./contracts/toolContractTypes.js";
import type { ToolEffects } from "./contracts/toolEffects.js";
/** Generated from TOOL_CONTRACTS; do not edit. */
// prettier-ignore
export const GENERATED_MCP_TOOL_CATALOG: readonly {
interface GeneratedTool {
readonly name: string;
readonly analysisOperation: CapabilityDescriptor["operation"] | null;
readonly title: string;
@@ -79,14 +78,69 @@ export const GENERATED_MCP_TOOL_CATALOG: readonly {
readonly outputSchema: Readonly<Record<string, unknown>>;
readonly annotations: ToolAnnotations;
readonly effects: ToolEffects;
}[] = ${JSON.stringify(catalog)};
}
/** Generated lightweight metadata for lazily loaded auxiliary providers. */
// prettier-ignore
export const GENERATED_AUXILIARY_PROVIDERS: readonly {
interface GeneratedProvider {
readonly identity: ProviderIdentity;
readonly capabilities: readonly CapabilityDescriptor[];
}[] = ${JSON.stringify(auxiliaryProviders)};
}
interface GeneratedPayload {
readonly catalog: readonly GeneratedTool[];
readonly auxiliaryProviders: readonly GeneratedProvider[];
}
const GENERATED_PAYLOAD_JSON = ${JSON.stringify(payloadJson)};
const generatedPayload: unknown = JSON.parse(GENERATED_PAYLOAD_JSON);
if (!isGeneratedPayload(generatedPayload))
throw new TypeError("Generated MCP catalog payload is invalid");
/** Generated from TOOL_CONTRACTS; do not edit. */
export const GENERATED_MCP_TOOL_CATALOG = generatedPayload.catalog;
/** Generated lightweight metadata for lazily loaded auxiliary providers. */
export const GENERATED_AUXILIARY_PROVIDERS = generatedPayload.auxiliaryProviders;
function isGeneratedPayload(value: unknown): value is GeneratedPayload {
return (
isRecord(value) &&
Array.isArray(value.catalog) &&
value.catalog.every(isGeneratedTool) &&
Array.isArray(value.auxiliaryProviders) &&
value.auxiliaryProviders.every(isGeneratedProvider)
);
}
function isGeneratedTool(value: unknown): value is GeneratedTool {
return (
isRecord(value) &&
typeof value.name === "string" &&
(typeof value.analysisOperation === "string" ||
value.analysisOperation === null) &&
typeof value.title === "string" &&
typeof value.description === "string" &&
typeof value.kind === "string" &&
typeof value.requiresSession === "boolean" &&
isRecord(value.inputSchema) &&
isRecord(value.outputSchema) &&
isRecord(value.annotations) &&
isRecord(value.effects)
);
}
function isGeneratedProvider(value: unknown): value is GeneratedProvider {
return (
isRecord(value) &&
isRecord(value.identity) &&
Array.isArray(value.capabilities)
);
}
function isRecord(
value: unknown,
): value is Readonly<Record<string, unknown>> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
`,
{ parser: "typescript" },
);
+61 -8
View File
@@ -6,9 +6,7 @@ import type {
import type { ToolKind } from "./contracts/toolContractTypes.js";
import type { ToolEffects } from "./contracts/toolEffects.js";
/** Generated from TOOL_CONTRACTS; do not edit. */
// prettier-ignore
export const GENERATED_MCP_TOOL_CATALOG: readonly {
interface GeneratedTool {
readonly name: string;
readonly analysisOperation: CapabilityDescriptor["operation"] | null;
readonly title: string;
@@ -19,11 +17,66 @@ export const GENERATED_MCP_TOOL_CATALOG: readonly {
readonly outputSchema: Readonly<Record<string, unknown>>;
readonly annotations: ToolAnnotations;
readonly effects: ToolEffects;
}[] = [{"name":"address_name","analysisOperation":"address_name","title":"Address Name","description":"Resolve the primary analyzed name at a code or data address. Headless providers require an explicit address; GUI providers may default to their current cursor. Null means the provider has no primary name at that address.","kind":"official-proxy","requiresSession":false,"inputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"document":{"description":"The document name","type":"string"},"address":{"type":"string","description":"A provider-normalized address; default memory uses 0x-prefixed hexadecimal"},"unknown_registry_approved":{"description":"Explicit approval to record typed capability unavailability as a residual unknown","type":"boolean","const":true}},"additionalProperties":false},"outputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"result":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Primary structured result returned by this operation."},"evidence_id":{"type":"string","pattern":"^ev_[a-f0-9]{64}$","description":"Stable identifier of the recorded Evidence v2 observation."},"evidence_uri":{"type":"string","pattern":"^rea:\\/\\/evidence\\/ev_[a-f0-9]{64}$","description":"Session resource URI for the recorded Evidence v2 observation."}},"required":["result","evidence_id","evidence_uri"],"additionalProperties":false},"annotations":{"readOnlyHint":false,"destructiveHint":false,"idempotentHint":true,"openWorldHint":false},"effects":{"mutatesTarget":false,"mutatesSession":true,"writesFilesystem":false,"launchesProcess":false,"accessesNetwork":false,"changesUiState":false,"mayDiscardData":false,"idempotent":true}},{"name":"comment","analysisOperation":"comment","title":"Comment","description":"Read the regular analysis comment at an address, defaulting to the current cursor. This is read-only and returns null when no comment exists; use set_comment to persist a finding.","kind":"official-proxy","requiresSession":false,"inputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"document":{"description":"The document name","type":"string"},"address":{"type":"string","description":"A provider-normalized address; default memory uses 0x-prefixed hexadecimal"},"unknown_registry_approved":{"description":"Explicit approval to record typed capability unavailability as a residual unknown","type":"boolean","const":true}},"additionalProperties":false},"outputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"result":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Primary structured result returned by this operation."},"evidence_id":{"type":"string","pattern":"^ev_[a-f0-9]{64}$","description":"Stable identifier of the recorded Evidence v2 observation."},"evidence_uri":{"type":"string","pattern":"^rea:\\/\\/evidence\\/ev_[a-f0-9]{64}$","description":"Session resource URI for the recorded Evidence v2 observation."}},"required":["result","evidence_id","evidence_uri"],"additionalProperties":false},"annotations":{"readOnlyHint":false,"destructiveHint":false,"idempotentHint":true,"openWorldHint":false},"effects":{"mutatesTarget":false,"mutatesSession":true,"writesFilesystem":false,"launchesProcess":false,"accessesNetwork":false,"changesUiState":false,"mayDiscardData":false,"idempotent":true}},{"name":"current_address","analysisOperation":"current_address","title":"Current Address","description":"Return Hopper's current cursor address for the selected document. Use only for interactive navigation state; prefer explicit addresses in reproducible investigations.","kind":"official-proxy","requiresSession":false,"inputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"document":{"description":"The document name","type":"string"},"unknown_registry_approved":{"description":"Explicit approval to record typed capability unavailability as a residual unknown","type":"boolean","const":true}},"additionalProperties":false},"outputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"result":{"type":"string","description":"Primary structured result returned by this operation."},"evidence_id":{"type":"string","pattern":"^ev_[a-f0-9]{64}$","description":"Stable identifier of the recorded Evidence v2 observation."},"evidence_uri":{"type":"string","pattern":"^rea:\\/\\/evidence\\/ev_[a-f0-9]{64}$","description":"Session resource URI for the recorded Evidence v2 observation."}},"required":["result","evidence_id","evidence_uri"],"additionalProperties":false},"annotations":{"readOnlyHint":false,"destructiveHint":false,"idempotentHint":true,"openWorldHint":false},"effects":{"mutatesTarget":false,"mutatesSession":true,"writesFilesystem":false,"launchesProcess":false,"accessesNetwork":false,"changesUiState":false,"mayDiscardData":false,"idempotent":truLine truncated
}
/** Generated lightweight metadata for lazily loaded auxiliary providers. */
// prettier-ignore
export const GENERATED_AUXILIARY_PROVIDERS: readonly {
interface GeneratedProvider {
readonly identity: ProviderIdentity;
readonly capabilities: readonly CapabilityDescriptor[];
}[] = [{"identity":{"id":"rea-artifact-graph","name":"REA safe artifact graph provider","version":"1"},"capabilities":[{"provider":{"id":"rea-artifact-graph","name":"REA safe artifact graph provider","version":"1"},"operation":"inventory_artifact","inputContractVersion":1,"outputContractVersion":1,"available":true,"reason":null,"pagination":"offset","exhaustive":false,"effects":{"mutatesArtifact":false,"launchesProcess":true,"mayShowUi":false,"mayAccessNetwork":false,"mayWriteFilesystem":false,"changesPermissions":false,"requiresRoot":false},"limits":{"maxResults":500,"maxPayloadBytes":4194304,"timeoutMs":120000},"limitations":["DMG child inventory is macOS-only and requires per-call approval plus operator policy; PKG remains root-hash-only.","ASAR files discovered in filesystem-backed inventories are expanded without bulk extraction; other nested containers remain recorded only."]},{"provider":{"id":"rea-artifact-graph","name":"REA safe artifact graph provider","version":"1"},"operation":"inspect_artifact","inputContractVersion":1,"outputContractVersion":1,"available":true,"reason":null,"pagination":"none","exhaustive":false,"effects":{"mutatesArtifact":false,"launchesProcess":true,"mayShowUi":false,"mayAccessNetwork":false,"mayWriteFilesystem":false,"changesPermissions":false,"requiresRoot":false},"limits":{"maxResults":500,"maxPayloadBytes":4194304,"timeoutMs":120000},"limitations":["DMG child inventory is macOS-only and requires per-call approval plus operator policy; PKG remains root-hash-only.","ASAR files discovered in filesystem-backed inventories are expanded without bulk extraction; other nested containers remain recorded only."]},{"provider":{"id":"rea-artifact-graph","name":"REA safe artifact graph provider","version":"1"},"operation":"extract_artifact","inputContractVersion":1,"outputContractVersion":1,"available":true,"reason":null,"pagination":"offset","exhaustive":false,"effects":{"mutatesArtifact":false,"launchesProcess":true,"mayShowUi":false,"mayAccessNetwork":false,"mayWriteFilesystem":true,"changesPermissions":false,"requiresRoot":false},"limits":{"maxResults":500,"maxPayloadBytes":4194304,"timeoutMs":120000},"limitations":["DMG child inventory is macOS-only and requires per-call approval plus operator policy; PKG remains root-hash-only.","ASAR files discovered in filesystem-backed inventories are expanded without bulk extraction; other nested containers remain recorded only."]}]},{"identity":{"id":"native-macos","name":"macOS native inspection utilities","version":null},"capabilities":[{"provider":{"id":"native-macos","name":"macOS native inspection utilities","version":null},"operation":"inspect_macho","inputContractVersion":1,"outputContractVersion":1,"available":false,"availabilityCode":"unsupported_host","reason":"Native macOS utilities require macOS.","pagination":"none","exhaustive":false,"effects":{"mutatesArtifact":false,"launchesProcess":true,"mayShowUi":false,"mayAccessNetwork":false,"mayWriteFilesystem":false,"changesPermissions":false,"requiresRoot":false},"limits":{"maxResults":null,"maxPayloadBytes":4194304,"timeoutMs":30000},"limitations":["Availability and textual formats depend on the installed macOS/Xcode toolchain."]},{"provider":{"id":"native-macos","name":"macOS native inspection utilities","version":null},"operation":"inspect_signature","inputContractVersion":1,"outputContractVersion":1,"available":false,"availabilityCode":"unsupported_host","reason":"Native macOS utilities require macOS.","pagination":"none","exhaustive":true,"effects":{"mutatesArtifact":false,"launchesProcess":true,"mayShowUi":false,"mayAccessNetwork":false,"mayWriteFilesystem":false,"changesPermissions":false,"requiresRoot":false},"limits":{"maxResults":null,"maxPayloadBytes":4194304,"timeoutMs":30000},"limitations":["Availability and textual formats depend on the installed macOS/Xcode toolchain."]},{"provider":{"id":"native-macos","name":"macOS native inspection utilities","version":null},"operation":"inspect_plist","inputContractVersion":1,"outputContractVersion":1,"available":false,"availabilityCode":"unsupported_host","reason":"Native macOS utilities require macOS.","pagination":"none","exhaustive":true,"effects":{"mutatesArtifact":false,"launchesProcess":true,"mayShowUi":false,"mayAccessNetwork":false,"mayWriteFilesystem":false,"changesPermissions":false,"requiresRoot":false},"limits":{"maxResults":null,"maxPayloadBytes":4194304,"timeoutMs":30000},"limitations":["Availability and textual formats depend on the installed macOS/Xcode toolchain."]},{"provider":{"id":"native-macos","name":"macOS native inspection utilities","version":null},"operation":"list_architectures","inputContractVersion":1,"outputContractVersion":1,"available":false,"availabilityCode":"unsupported_host","reason":"Native macOS utilities require macOS.","pagination":"none","exhaustive":true,"effects":{"mutatesArtifact":false,"launchesProcess":true,"mayShowUi":false,"mayAccessNetwork":false,"mayWriteFilesystem":false,"chanLine truncated
}
interface GeneratedPayload {
readonly catalog: readonly GeneratedTool[];
readonly auxiliaryProviders: readonly GeneratedProvider[];
}
const GENERATED_PAYLOAD_JSON =
'{"catalog":[{"name":"address_name","analysisOperation":"address_name","title":"Address Name","description":"Resolve the primary analyzed name at a code or data address. Headless providers require an explicit address; GUI providers may default to their current cursor. Null means the provider has no primary name at that address.","kind":"official-proxy","requiresSession":false,"inputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"document":{"description":"The document name","type":"string"},"address":{"type":"string","description":"A provider-normalized address; default memory uses 0x-prefixed hexadecimal"},"unknown_registry_approved":{"description":"Explicit approval to record typed capability unavailability as a residual unknown","type":"boolean","const":true}},"additionalProperties":false},"outputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"result":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Primary structured result returned by this operation."},"evidence_id":{"type":"string","pattern":"^ev_[a-f0-9]{64}$","description":"Stable identifier of the recorded Evidence v2 observation."},"evidence_uri":{"type":"string","pattern":"^rea:\\\\/\\\\/evidence\\\\/ev_[a-f0-9]{64}$","description":"Session resource URI for the recorded Evidence v2 observation."}},"required":["result","evidence_id","evidence_uri"],"additionalProperties":false},"annotations":{"readOnlyHint":false,"destructiveHint":false,"idempotentHint":true,"openWorldHint":false},"effects":{"mutatesTarget":false,"mutatesSession":true,"writesFilesystem":false,"launchesProcess":false,"accessesNetwork":false,"changesUiState":false,"mayDiscardData":false,"idempotent":true}},{"name":"comment","analysisOperation":"comment","title":"Comment","description":"Read the regular analysis comment at an address, defaulting to the current cursor. This is read-only and returns null when no comment exists; use set_comment to persist a finding.","kind":"official-proxy","requiresSession":false,"inputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"document":{"description":"The document name","type":"string"},"address":{"type":"string","description":"A provider-normalized address; default memory uses 0x-prefixed hexadecimal"},"unknown_registry_approved":{"description":"Explicit approval to record typed capability unavailability as a residual unknown","type":"boolean","const":true}},"additionalProperties":false},"outputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"result":{"anyOf":[{"type":"string"},{"type":"null"}],"description":"Primary structured result returned by this operation."},"evidence_id":{"type":"string","pattern":"^ev_[a-f0-9]{64}$","description":"Stable identifier of the recorded Evidence v2 observation."},"evidence_uri":{"type":"string","pattern":"^rea:\\\\/\\\\/evidence\\\\/ev_[a-f0-9]{64}$","description":"Session resource URI for the recorded Evidence v2 observation."}},"required":["result","evidence_id","evidence_uri"],"additionalProperties":false},"annotations":{"readOnlyHint":false,"destructiveHint":false,"idempotentHint":true,"openWorldHint":false},"effects":{"mutatesTarget":false,"mutatesSession":true,"writesFilesystem":false,"launchesProcess":false,"accessesNetwork":false,"changesUiState":false,"mayDiscardData":false,"idempotent":true}},{"name":"current_address","analysisOperation":"current_address","title":"Current Address","description":"Return Hopper\'s current cursor address for the selected document. Use only for interactive navigation state; prefer explicit addresses in reproducible investigations.","kind":"official-proxy","requiresSession":false,"inputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"document":{"description":"The document name","type":"string"},"unknown_registry_approved":{"description":"Explicit approval to record typed capability unavailability as a residual unknown","type":"boolean","const":true}},"additionalProperties":false},"outputSchema":{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"result":{"type":"string","description":"Primary structured result returned by this operation."},"evidence_id":{"type":"string","pattern":"^ev_[a-f0-9]{64}$","description":"Stable identifier of the recorded Evidence v2 observation."},"evidence_uri":{"type":"string","pattern":"^rea:\\\\/\\\\/evidence\\\\/ev_[a-f0-9]{64}$","description":"Session resource URI for the recorded Evidence v2 observation."}},"required":["result","evidence_id","evidence_uri"],"additionalProperties":false},"annotations":{"readOnlyHint":false,"destructiveHint":false,"idempotentHint":true,"openWorldHint":false},"effects":{"mutatesTarget":false,"mutatesSession":true,"writesFilesystem":false,"launchesProcess":false,"accessesNetwork":false,"changesUiState":false,"mayDiscardD Line truncated
const generatedPayload: unknown = JSON.parse(GENERATED_PAYLOAD_JSON);
if (!isGeneratedPayload(generatedPayload))
throw new TypeError("Generated MCP catalog payload is invalid");
/** Generated from TOOL_CONTRACTS; do not edit. */
export const GENERATED_MCP_TOOL_CATALOG = generatedPayload.catalog;
/** Generated lightweight metadata for lazily loaded auxiliary providers. */
export const GENERATED_AUXILIARY_PROVIDERS =
generatedPayload.auxiliaryProviders;
function isGeneratedPayload(value: unknown): value is GeneratedPayload {
return (
isRecord(value) &&
Array.isArray(value.catalog) &&
value.catalog.every(isGeneratedTool) &&
Array.isArray(value.auxiliaryProviders) &&
value.auxiliaryProviders.every(isGeneratedProvider)
);
}
function isGeneratedTool(value: unknown): value is GeneratedTool {
return (
isRecord(value) &&
typeof value.name === "string" &&
(typeof value.analysisOperation === "string" ||
value.analysisOperation === null) &&
typeof value.title === "string" &&
typeof value.description === "string" &&
typeof value.kind === "string" &&
typeof value.requiresSession === "boolean" &&
isRecord(value.inputSchema) &&
isRecord(value.outputSchema) &&
isRecord(value.annotations) &&
isRecord(value.effects)
);
}
function isGeneratedProvider(value: unknown): value is GeneratedProvider {
return (
isRecord(value) &&
isRecord(value.identity) &&
Array.isArray(value.capabilities)
);
}
function isRecord(value: unknown): value is Readonly<Record<string, unknown>> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
+1 -1
View File
@@ -105,7 +105,7 @@ describe("process-capture MCP elicitation", () => {
await Promise.allSettled([client.close(), server.close()]);
await rm(root, { recursive: true, force: true });
}
});
}, 20_000);
it.each(["tampered", "expired"] as const)(
"rejects %s signed state through the modern MCP client and server",
+4 -2
View File
@@ -87,7 +87,9 @@ describe("target-free MCP lifecycle", () => {
expect(closed).toEqual([canonicalTargetPath]);
expect(
z
.object({ result: z.object({ path: z.string(), sha256: z.string() }) })
.object({
result: z.object({ path: z.string(), sha256: z.string() }),
})
.parse(
structured(
await mcp.callTool({
@@ -100,7 +102,7 @@ describe("target-free MCP lifecycle", () => {
path: canonicalTargetPath,
sha256: z.object({ sha256: z.string() }).parse(second).sha256,
});
});
}, 10_000);
it("reports no-target, opens, analyzes, switches, reports status, and closes", async () => {
directory = await createTestTempDirectory("rea-mcp-session-");
+2 -2
View File
@@ -6,9 +6,9 @@ import { defineConfig } from "vitest/config";
export const TEST_FILES = ["tests/**/*.test.ts"];
const IS_CONTINUOUS_INTEGRATION = process.env.CI === "true";
// Subprocess-heavy parallel tests exceed their existing deadlines above two workers.
// Lazy MCP integration tests are memory-bound while Vite transforms tool families.
const MAX_TEST_WORKERS = 2;
const MAX_UNIT_TEST_WORKERS = 4;
const MAX_UNIT_TEST_WORKERS = 1;
const PROCESS_CAPTURE_TEST = "tests/processCapture.test.ts";
const CANONICAL_TEMPORARY_DIRECTORY = realpathSync(tmpdir());
export const SERIAL_INTEGRATION_TESTS = [