test(mcp): stabilize lazy-loading verification

This commit is contained in:
morluto
2026-07-26 15:26:41 +00:00
parent fecddc0549
commit 7157ab0b70
5 changed files with 130 additions and 21 deletions
+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" },
);
File diff suppressed because one or more lines are too long
+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 = [