Files
rea/tests/process-global/windowsNativeControlCapability.test.ts
morluto 88fd8a9df0 test: drop detail requests the budget seed made redundant (#14615)
PR #14252 added explicit complete-detail requests across tests before the
vitest REA_AGENT_RESULT_BUDGET_BYTES seed and the complete-Evidence harness
existed. Restore the pre-#14252 form where the seed or the harness already
delivers complete Evidence.

Keep the requests that are load-bearing: delivery, summary and budget tests,
tools whose omitted detail is summary, and callers that neither the seed nor
the harness reaches (unwrapped SDK clients on servers with an explicit
environment, and in-process CLIs). Those were found by running the touched
files with the shipped budget lowered to its 4 KiB minimum.
2026-11-25 21:08:12 +00:00

154 lines
5.1 KiB
TypeScript

import { mkdir, rm } from "node:fs/promises";
import { join } from "node:path";
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
import type { CallToolResult } from "@modelcontextprotocol/server";
import { expect, it, vi } from "vitest";
import { WebSourceLocationService } from "../../src/application/WebSourceLocationService.js";
import { ok } from "../../src/domain/result.js";
import { systemProcessOwnershipHost } from "../../src/process/ProcessOwnershipObservation.js";
import { createServer } from "../../src/server/createServer.js";
import * as nativeLoader from "../../src/windows/WindowsNativeLoader.js";
import { createTestBinarySession } from "../fixtures/binarySession.js";
import { parseMcpToolError } from "../fixtures/mcpToolError.js";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
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", () => ({
HOST_PLATFORM: Object.freeze({ platform: "win32", architecture: "x64" }),
}));
// Bun on Windows is the runtime whose codec launch requests a Job Object limit.
vi.mock(
"../../src/process/JavaScriptWorkerMemoryLimit.js",
async (original) => {
const actual =
await original<
typeof import("../../src/process/JavaScriptWorkerMemoryLimit.js")
>();
return {
...actual,
javaScriptWorkerMemoryLimitBytes: (heapBudgetMiB: number) =>
actual.javaScriptWorkerMemoryLimitBytes(heapBudgetMiB, {
platform: "win32",
versions: { node: "24.18.0", bun: "1.4.2" },
}),
};
},
);
/** An admitted artifact that predates the optional Job Object limit control. */
const earlierArtifact = (
spawns: string[],
): nativeLoader.WindowsNativeAuthority => ({
inspection: {
abiVersion: 1,
nodeApiVersion: 8,
architecture: "x64",
filesystem: {
requestedPath: "C:\\probe",
finalPath: "C:\\probe",
filesystem: "NTFS",
volumeSerial: "0".repeat(16),
fileId: "0".repeat(32),
size: 0,
directory: true,
},
privateDacl: true,
privateBridgeDescriptorAccess: true,
atomicJobAssignment: true,
killOnOwnerClose: true,
protocolStdin: true,
},
call: (operation) => {
spawns.push(operation);
throw new Error(`Unexpected native ${operation}`);
},
});
it("reports a missing Windows native control as an unavailable capability", async () => {
const spawns: string[] = [];
const parent = await createTestTempDirectory("rea-native-control-");
const root = join(parent, "runtime");
await mkdir(root);
let rootClosed = false;
const session = createTestBinarySession(() => {
throw new Error("binary provider must not start");
});
let client: Client | undefined;
let server: ReturnType<typeof createServer> | undefined;
try {
vi.spyOn(nativeLoader, "requireWindowsNativeAuthority").mockReturnValue(
earlierArtifact(spawns),
);
vi.spyOn(systemProcessOwnershipHost, "prepare").mockResolvedValue(
undefined,
);
const { SourceMapDecoder } =
await import("../../src/javascript/sourceMaps/SourceMapDecoder.js");
const decoder = new SourceMapDecoder({
prepareOwnership: async () => {},
createRuntime: async () => ({
path: root,
close: async () => {
await rm(root, { recursive: true, force: true });
rootClosed = true;
},
}),
});
server = createServer(
{ kind: "session", session },
{
webSourceLocation: new WebSourceLocationService(
{ load: async () => ok(webSourceLocationFixture()) },
decoder,
),
},
);
client = new Client(
{ name: "native-control-capability", version: "1" },
{ jsonSchemaValidator: createMcpSchemaValidation() },
);
const [clientTransport, serverTransport] =
InMemoryTransport.createLinkedPair();
await server.connect(serverTransport);
await client.connect(clientTransport);
const response = await client.callTool({
name: "trace_web_source_location",
arguments: webSourceLocationArgs,
});
const { error } = parseMcpToolError(response as CallToolResult);
expect(error).toMatchObject({
code: "capability_unavailable",
retryable: false,
message: expect.stringContaining(
"does not support Job Object memory limits",
),
remediation: {
action: expect.stringContaining(
"matching current Windows x64 REA package",
),
},
details: {
provider_id: "source-map-decoder",
operation: "trace_web_source_location",
},
});
// The refusal still precedes any native launch and releases the runtime.
expect(spawns).toEqual([]);
expect(rootClosed).toBe(true);
await decoder.close();
} finally {
vi.restoreAllMocks();
await client?.close();
await server?.close();
await session.close();
}
});