mirror of
https://github.com/morluto/rea.git
synced 2026-12-01 11:01:11 +00:00
test: fail loudly on setup refusals and assert exact MCP refusal and linkage facts (#15368)
* test(mcp): assert exact refusal, identity and Evidence linkage facts Replace isError-only, expect.any and oracle-mirror checks in MCP and CLI workflow tests with the exact code, reason, subject identity and Evidence links the producers report. The capability-unavailable unknowns test now opens its target, so it exercises the path it names instead of NoBinaryOpenError. * test: fail loudly on setup refusals, unrecorded paths and zombie liveness Three shared helpers remove weakness classes from the suite: - callOk (tests/support/mcp/toolResult.ts) fails at the setup step when a tool used as fixture setup refuses. It replaces the build-computer copy and the unchecked open_binary calls. serverUnknownsMcp's capability-unavailable test passed only because open_binary failed: its fixture refused health, and NoBinaryOpenError has the same "unavailable" category. The fixture now answers health, and the test asserts capability_unavailable for procedure_pseudo_code. - expectRemoved (tests/support/expectRemoved.ts) throws when no path was recorded; access(list[0] ?? "") passed because "" is also ENOENT. - expectProcessRunning checks ps state instead of signal 0, which still reaches a zombie that REA wrongly signalled. Also asserts the open target before and after an ordinary close, the written overwrite snapshot, and the comparison's links, status and supporting unknown. * test(mcp): compare delivered recovery with its owning projection
This commit is contained in:
1 parent
18f3ea0bc2
commit
c7fa6af8a3
48 files changed
+420
-227
No files matched your search
@@ -777,7 +777,10 @@ an external oracle; comparing two paths through the same replacement algorithm
|
||||
does not preserve the old oracle. A negative probe inside a conditional or loop
|
||||
must assert that it ran. Check that the facts compared actually exist: `every`
|
||||
on an empty list, optional chaining, or comparing two missing values can pass
|
||||
without exercising the behavior. For a suspicious assertion, use an isolated
|
||||
without exercising the behavior. Call an MCP tool that the test uses as setup,
|
||||
such as `open_binary`, through `callOk` from `tests/support/mcp/toolResult.ts`:
|
||||
a refusal such as "nothing is open" also satisfies a later expected error,
|
||||
empty list, or null result. For a suspicious assertion, use an isolated
|
||||
controlled change that removes or alters the relevant fact; confirm the test
|
||||
fails at the intended assertion, then restore the change and rerun it.
|
||||
|
||||
@@ -977,7 +980,11 @@ To assert that a POSIX process or process group has stopped, use
|
||||
`processHasStopped` or `processGroupHasStopped` from
|
||||
`tests/support/process/observePosixProcess.ts`, not signal 0. Signal 0 still
|
||||
reaches a zombie, and an orphan stays one wherever PID 1 does not reap it, as in
|
||||
a container started without an init process.
|
||||
a container started without an init process. For the opposite claim, that a
|
||||
process REA must not signal is still running, use `expectProcessRunning` from
|
||||
the same module. Assert a removed path with `expectRemoved` from
|
||||
`tests/support/expectRemoved.ts`, which fails when no path was recorded;
|
||||
`access(list[0] ?? "")` passes then, because an empty path is also ENOENT.
|
||||
|
||||
| Scenario | Assertion and control |
|
||||
| --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
|
||||
@@ -42,6 +42,7 @@ import {
|
||||
javaScriptMemberMutationRefusal,
|
||||
} from "../domain/javascript/javascriptSemanticWorkAllowance.js";
|
||||
import { releaseOwnedCleanup } from "../../tests/support/cleanupRelease.js";
|
||||
import { expectRemoved } from "../../tests/support/expectRemoved.js";
|
||||
|
||||
const sourceWorkerProgram = (
|
||||
hangMarker?: string,
|
||||
@@ -1172,7 +1173,7 @@ it("cancels during the late ready handshake and retains failed cleanup until exa
|
||||
await worker.close();
|
||||
expect(error.cleanupIncomplete).toBe(false);
|
||||
expect(resolvedAnalysisError(error).cause).toBe(reason);
|
||||
await expect(access(children[0]?.root ?? "")).rejects.toThrow();
|
||||
await expectRemoved(children[0]?.root);
|
||||
await waitForExit(children[0]!.process);
|
||||
} finally {
|
||||
if (
|
||||
|
||||
@@ -89,6 +89,7 @@ import {
|
||||
import { OwnedWorkerRuntime } from "../process/OwnedWorkerRuntime.js";
|
||||
import { WebBundleAnalysisWorker } from "./WebBundleAnalysisWorker.js";
|
||||
import { WEB_BUNDLE_WORKER_LIMITS } from "./WebBundleAnalysisWorkerProtocol.js";
|
||||
import { expectRemoved } from "../../tests/support/expectRemoved.js";
|
||||
|
||||
const ownedSourceLauncher = (
|
||||
failCleanupOnce = false,
|
||||
@@ -177,7 +178,7 @@ it("retains completed facts and resolves a result-file lease through another cle
|
||||
expect(result.error.error.cleanupIncomplete).toBe(false);
|
||||
expect(closeFailure.resultCloseAttempts).toBeGreaterThanOrEqual(2);
|
||||
expect(closeFailure.rootRemovedBeforeResultClose).toBe(false);
|
||||
await expect(access(closeFailure.root ?? "")).rejects.toThrow();
|
||||
await expectRemoved(closeFailure.root);
|
||||
} finally {
|
||||
await worker.close().catch(() => undefined);
|
||||
await OwnedWorkerRuntime.retryPending().catch(() => undefined);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { existsSync } from "node:fs";
|
||||
import {
|
||||
access,
|
||||
chmod,
|
||||
mkdir,
|
||||
readFile,
|
||||
@@ -35,6 +34,7 @@ import {
|
||||
type QueryRunner,
|
||||
} from "./HostQuery.js";
|
||||
import { inspectLinuxApplication } from "./LinuxApplicationInventory.js";
|
||||
import { expectRemoved } from "../../tests/support/expectRemoved.js";
|
||||
|
||||
const NOBLE = "http://ports.ubuntu.com/ubuntu-ports noble/main arm64 Packages";
|
||||
const PPA =
|
||||
@@ -472,7 +472,7 @@ describe.skipIf(process.platform === "win32")("vendor repositories", () => {
|
||||
);
|
||||
// The candidate keyrings were private copies, removed afterwards.
|
||||
expect(keyrings.every((keyring) => !keyring.startsWith(root))).toBe(true);
|
||||
await expect(access(keyrings[0] ?? "")).rejects.toThrow();
|
||||
await expectRemoved(keyrings[0]);
|
||||
});
|
||||
|
||||
it("retains only the verifying key of a keyring that holds several", async () => {
|
||||
@@ -632,7 +632,7 @@ describe.skipIf(process.platform === "win32")(
|
||||
expect(signingKeys.get(sha256(armored))?.equals(armored)).toBe(true);
|
||||
expect(keyrings).toHaveLength(1);
|
||||
expect(keyrings[0]?.startsWith(root)).toBe(false);
|
||||
await expect(access(keyrings[0] ?? "")).rejects.toThrow();
|
||||
await expectRemoved(keyrings[0]);
|
||||
const install = exportInstall(installed, "typora", "arm64");
|
||||
expect(install.ok && install.value.sources).toEqual([
|
||||
{
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
import { PrivateRuntimeRoot } from "../process/PrivateRuntimeRoot.js";
|
||||
import { withGpgvKeyCheck } from "./GpgvKeyCheck.js";
|
||||
import { runHostQuery, type QueryRunner } from "./HostQuery.js";
|
||||
import { expectRemoved } from "../../tests/support/expectRemoved.js";
|
||||
|
||||
const hasGpgv =
|
||||
typeof (await runHostQuery("gpgv", ["--version"], undefined)) === "object";
|
||||
@@ -234,9 +235,7 @@ describe("withGpgvKeyCheck cleanup", () => {
|
||||
expect(failure.cause).toBe(reason);
|
||||
}
|
||||
expect(path).toBeDefined();
|
||||
await expect(access(path ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(path);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -290,8 +289,6 @@ describe("withGpgvKeyCheck cleanup", () => {
|
||||
expect(verified.reason).toContain(release);
|
||||
expect(verified.reason).not.toMatch(/[a-z][a-z0-9+.-]*:\/\//iu);
|
||||
expect(keyrings).toHaveLength(1);
|
||||
await expect(access(keyrings[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(keyrings[0]);
|
||||
});
|
||||
});
|
||||
@@ -43,8 +43,12 @@ cliTest.skipIf(process.platform === "win32")(
|
||||
expect(response.exitCode, response.stdout + response.stderr).toBe(1);
|
||||
expect(response.stdout).not.toContain(secret);
|
||||
expect(response.json).toMatchObject({
|
||||
code: expect.any(String),
|
||||
code: "execution_failure",
|
||||
category: "execution_failure",
|
||||
retryable: false,
|
||||
details: {
|
||||
provider_id: "rea-playwright-browser-scenario",
|
||||
operation: "capture_browser_scenario",
|
||||
diagnostics: {
|
||||
executable_path: path,
|
||||
startup_error: expect.stringContaining(marker),
|
||||
|
||||
@@ -156,8 +156,11 @@ processTest(
|
||||
result.updates.map(({ message: _message, ...facts }) => facts),
|
||||
).toEqual([]);
|
||||
expect(JSON.parse(result.stdout)).toMatchObject({
|
||||
code: expect.any(String),
|
||||
category: expect.any(String),
|
||||
code: "unreadable_output",
|
||||
category: "execution_failure",
|
||||
message:
|
||||
"CDP Performance.enable failed (-32000): authored preparation failure",
|
||||
details: { operation: "observe_web_session", reason: "protocol_error" },
|
||||
});
|
||||
expect(browser.commands).toContainEqual(
|
||||
expect.objectContaining({ method: "Target.detachFromTarget" }),
|
||||
@@ -178,9 +181,11 @@ processTest(
|
||||
expect(result.updates.every(({ terminal }) => terminal !== true)).toBe(
|
||||
true,
|
||||
);
|
||||
// A malformed CDP frame after arming is a protocol failure, not an end.
|
||||
expect(JSON.parse(result.stdout)).toMatchObject({
|
||||
code: expect.any(String),
|
||||
category: expect.any(String),
|
||||
code: "unreadable_output",
|
||||
category: "execution_failure",
|
||||
details: { operation: "observe_web_session", reason: "protocol_error" },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
@@ -10,7 +10,8 @@ import {
|
||||
BUILD_TASK as TASK,
|
||||
buildCaptureFakes,
|
||||
} from "../../fixtures/buildCaptureFakes.js";
|
||||
import { callOk, startBuildComputer } from "../../fixtures/buildComputerMcp.js";
|
||||
import { startBuildComputer } from "../../fixtures/buildComputerMcp.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ import { waitForProviderProcessReady } from "../../fixtures/providerProcess.js";
|
||||
import { EvmInterfaceService } from "../../../src/application/evm/EvmInterfaceService.js";
|
||||
import { AnalysisCancelledError } from "../../../src/domain/analysisErrorCore.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { expectProcessRunning } from "../../support/process/observePosixProcess.js";
|
||||
|
||||
let limitsWorkspace = "";
|
||||
beforeAll(async () => {
|
||||
@@ -644,7 +645,7 @@ it("preserves an active cancellation through denied owned-group cleanup and late
|
||||
expect(original.cleanupPrimary?.cause).toBe(abortReason);
|
||||
if (pid === undefined) throw new Error("Owned worker pid was not captured");
|
||||
const ownedPid = pid;
|
||||
expect(() => process.kill(ownedPid, 0)).not.toThrow();
|
||||
await expectProcessRunning(ownedPid);
|
||||
|
||||
const firstClose = await provider.close().then(
|
||||
() => undefined,
|
||||
|
||||
@@ -56,6 +56,7 @@ import { createArtifactBinarySession } from "../../../src/composition/artifactSe
|
||||
import { observed } from "../../fixtures/analysisExecution.js";
|
||||
import { cArchiveExecutable } from "../../../src/artifacts/pyinstaller/CArchive.fixture.js";
|
||||
import { compareUnicodeCodePoints } from "../../../src/domain/unicodeCodePointOrder.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
|
||||
it("refuses an artifact parent and summary when its actual inventory source cannot be recorded", async ({
|
||||
mcp,
|
||||
@@ -392,10 +393,7 @@ it("records an explicitly continued mismatch, preserves verified siblings, and n
|
||||
version: "1",
|
||||
});
|
||||
try {
|
||||
await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: archive },
|
||||
});
|
||||
await callOk(client, "open_binary", { path: archive });
|
||||
const result = await client.callTool({
|
||||
name: "inspect_artifact",
|
||||
arguments: {
|
||||
|
||||
@@ -399,7 +399,12 @@ it("counts both forms of an unavailable entry label", async () => {
|
||||
expect(items).toMatchObject([
|
||||
{ procedure: { name: "main" } },
|
||||
{ procedure: { name: null } },
|
||||
{ procedure: { name: null, name_error: { code: expect.any(String) } } },
|
||||
{
|
||||
procedure: {
|
||||
name: null,
|
||||
name_error: { code: "execution_failure", retryable: false },
|
||||
},
|
||||
},
|
||||
]);
|
||||
expect(JSON.stringify(z.array(z.unknown()).parse(items)[1])).not.toContain(
|
||||
"name_error",
|
||||
|
||||
@@ -16,7 +16,8 @@ import {
|
||||
BUILD_REQUEST as REQUEST,
|
||||
buildCaptureFakes,
|
||||
} from "../../fixtures/buildCaptureFakes.js";
|
||||
import { callOk, startBuildComputer } from "../../fixtures/buildComputerMcp.js";
|
||||
import { startBuildComputer } from "../../fixtures/buildComputerMcp.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
|
||||
const LIST = "Documents/list.xml";
|
||||
const SEED = `<list><cat key="1" name="Dairy"/><cat key="2" name="Bakery"/><item name="milk" cat="1" qty="1"/><item name="bread" cat="2" qty="2"/></list>`;
|
||||
|
||||
@@ -23,10 +23,10 @@ import {
|
||||
buildCaptureFakes as fakes,
|
||||
} from "../../fixtures/buildCaptureFakes.js";
|
||||
import {
|
||||
callOk,
|
||||
expectNoToken,
|
||||
startBuildComputer,
|
||||
} from "../../fixtures/buildComputerMcp.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
|
||||
@@ -20,15 +20,16 @@ import {
|
||||
} from "../../fixtures/buildCaptureFakes.js";
|
||||
import {
|
||||
bundleFolder,
|
||||
callOk,
|
||||
expectNoToken,
|
||||
startBuildComputer,
|
||||
} from "../../fixtures/buildComputerMcp.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
import {
|
||||
INVALID_BUILD_SCREENSHOTS,
|
||||
VALID_BUILD_SCREENSHOT,
|
||||
} from "../../fixtures/buildScreenshotData.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { z } from "zod";
|
||||
import { hasReadableProcDescriptor } from "../../fixtures/desktopDconfHost.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
@@ -477,14 +478,27 @@ it("exports a task larger than the old 96 KiB refusal and keeps its prompt", asy
|
||||
});
|
||||
expect(parseMcpToolError(refused).error).toMatchObject({
|
||||
code: "resource_constraint",
|
||||
retryable: false,
|
||||
details: {
|
||||
resource: "transport",
|
||||
reported_limits: {
|
||||
actual_bytes: expect.any(Number),
|
||||
max_bytes: LINUX_ARGUMENT_VECTOR_BYTES,
|
||||
},
|
||||
},
|
||||
remediation: { action: expect.any(String) },
|
||||
remediation: { action: expect.stringMatching(/\S/u) },
|
||||
});
|
||||
// The measured argument vector is what exceeded the transport limit.
|
||||
expect(
|
||||
z
|
||||
.object({
|
||||
details: z.object({
|
||||
reported_limits: z.object({ actual_bytes: z.number() }),
|
||||
}),
|
||||
})
|
||||
.parse(parseMcpToolError(refused).error).details.reported_limits
|
||||
.actual_bytes,
|
||||
).toBeGreaterThan(LINUX_ARGUMENT_VECTOR_BYTES);
|
||||
});
|
||||
|
||||
it("refuses capture steps out of order and a capture of a bundle's computer", async () => {
|
||||
|
||||
@@ -20,7 +20,8 @@ import {
|
||||
BUILD_TASK,
|
||||
buildCaptureFakes as fakes,
|
||||
} from "../../fixtures/buildCaptureFakes.js";
|
||||
import { callOk, startBuildComputer } from "../../fixtures/buildComputerMcp.js";
|
||||
import { startBuildComputer } from "../../fixtures/buildComputerMcp.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { cancelDuringCommit } from "../../fixtures/outputTreeCommit.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
@@ -15,7 +15,8 @@ import {
|
||||
BUILD_TASK as TASK,
|
||||
buildCaptureFakes,
|
||||
} from "../../fixtures/buildCaptureFakes.js";
|
||||
import { callOk, startBuildComputer } from "../../fixtures/buildComputerMcp.js";
|
||||
import { startBuildComputer } from "../../fixtures/buildComputerMcp.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ import { createDeferred } from "../../fixtures/binarySession.js";
|
||||
import {
|
||||
buildComputerFakes as fakes,
|
||||
bundleFolder,
|
||||
callOk,
|
||||
connectBuildServer as connect,
|
||||
expectNoToken,
|
||||
startBuildComputer,
|
||||
} from "../../fixtures/buildComputerMcp.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
import { COMPUTER_START_TIMING } from "../../../src/desktop/AgentEnvComputer.js";
|
||||
import {
|
||||
awaitFakeDeployWait,
|
||||
|
||||
@@ -11,7 +11,8 @@ import {
|
||||
renderTaskVerifier,
|
||||
taskVerifierArtifact,
|
||||
} from "../../../src/domain/desktop/appTaskPython.js";
|
||||
import { callOk, connectBuildServer } from "../../fixtures/buildComputerMcp.js";
|
||||
import { connectBuildServer } from "../../fixtures/buildComputerMcp.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
import { fakeAgentEnvSolves } from "../../fixtures/fakeAgentEnvSolves.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
@@ -27,10 +27,10 @@ import {
|
||||
import {
|
||||
buildComputerFakes,
|
||||
bundleFolder,
|
||||
callOk,
|
||||
connectBuildServer,
|
||||
startBuildComputer,
|
||||
} from "../../fixtures/buildComputerMcp.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
import type { FakeApp } from "../../fixtures/fakeAgentEnvComputer.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
@@ -13,7 +13,8 @@ import {
|
||||
BUILD_TASK as ADD_EGGS,
|
||||
buildCaptureFakes as fakes,
|
||||
} from "../../fixtures/buildCaptureFakes.js";
|
||||
import { callOk, startBuildComputer } from "../../fixtures/buildComputerMcp.js";
|
||||
import { startBuildComputer } from "../../fixtures/buildComputerMcp.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@ import {
|
||||
import {
|
||||
buildComputerFakes,
|
||||
bundleFolder,
|
||||
callOk,
|
||||
connectBuildServer,
|
||||
startBuildComputer,
|
||||
} from "../../fixtures/buildComputerMcp.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import {
|
||||
buildComputerFakes,
|
||||
bundleFolder,
|
||||
callOk,
|
||||
connectBuildServer,
|
||||
expectNoToken,
|
||||
startBuildComputer,
|
||||
} from "../../fixtures/buildComputerMcp.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
import {
|
||||
FAKE_SEGMENTS,
|
||||
type FakeApp,
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
} from "../../fixtures/binarySession.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
import { ProcessCaptureResourceScope } from "../../../src/process/capture/ProcessCaptureLifecycle.js";
|
||||
|
||||
const discarded: EngineCloseReport = {
|
||||
@@ -62,11 +63,8 @@ it("reports a close that released refused checkpoint edits, with and without a s
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
const call = async (name: string, arguments_: Record<string, unknown>) => {
|
||||
const result = await client.callTool({ name, arguments: arguments_ });
|
||||
expect(result.isError, JSON.stringify(result.content)).not.toBe(true);
|
||||
return result.structuredContent;
|
||||
};
|
||||
const call = async (name: string, arguments_: Record<string, unknown>) =>
|
||||
(await callOk(client, name, arguments_)).structuredContent;
|
||||
const closeResult = (value: unknown) =>
|
||||
toolContract("close_binary").outputSchema.parse(value).result;
|
||||
try {
|
||||
@@ -102,12 +100,19 @@ it("keeps an ordinary close result null", async () => {
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
await client.callTool({ name: "open_binary", arguments: { path: target } });
|
||||
// Closing with nothing open also returns null, so the open must succeed.
|
||||
await callOk(client, "open_binary", { path: target });
|
||||
expect(
|
||||
(await callOk(client, "binary_session")).structuredContent,
|
||||
).toMatchObject({ result: { open: true } });
|
||||
const closed = await client.callTool({
|
||||
name: "close_binary",
|
||||
arguments: {},
|
||||
});
|
||||
expect(closed.structuredContent).toEqual({ result: null });
|
||||
expect(
|
||||
(await callOk(client, "binary_session")).structuredContent,
|
||||
).toMatchObject({ result: { open: false } });
|
||||
} finally {
|
||||
await Promise.allSettled([client.close(), server.close(), session.close()]);
|
||||
}
|
||||
|
||||
@@ -357,10 +357,25 @@ describe("function comparison MCP integration", () => {
|
||||
},
|
||||
});
|
||||
expect(result.isError).not.toBe(true);
|
||||
const leftId = FUNCTION_COMPARISON_EXAMPLE.left.evidence_id;
|
||||
const rightId = FUNCTION_COMPARISON_EXAMPLE.right.evidence_id;
|
||||
expect(result.structuredContent).toMatchObject({
|
||||
normalized_result: { status: expect.any(String) },
|
||||
parameters: { left_evidence_id: leftId, right_evidence_id: rightId },
|
||||
normalized_result: {
|
||||
status: "changed",
|
||||
summary: { unchanged: 7, changed: 1, unknown: 0 },
|
||||
},
|
||||
evidence_id: expect.stringMatching(/^ev_[a-f0-9]{64}$/u),
|
||||
});
|
||||
// Every compared dimension links both input dossiers.
|
||||
expect(result.structuredContent).toMatchObject({
|
||||
normalized_result: {
|
||||
dimensions: Array.from({ length: 8 }, () =>
|
||||
expect.objectContaining({ evidence_links: [leftId, rightId] }),
|
||||
),
|
||||
},
|
||||
});
|
||||
const comparison = parseEvidence(result.structuredContent);
|
||||
const unknowns = await client.callTool({
|
||||
name: "list_unknowns",
|
||||
arguments: { domain: "function-comparison" },
|
||||
@@ -370,6 +385,13 @@ describe("function comparison MCP integration", () => {
|
||||
items: [
|
||||
expect.objectContaining({
|
||||
domain: "function-comparison",
|
||||
status: "contradicted",
|
||||
comparison_conclusion_scope: {
|
||||
comparison_evidence_id: comparison.evidence_id,
|
||||
dimensions: ["calls", "pseudocode"],
|
||||
},
|
||||
supporting_evidence_ids: [leftId, comparison.evidence_id],
|
||||
contradicting_evidence_ids: [rightId],
|
||||
recommended_probes: [
|
||||
expect.objectContaining({
|
||||
rationale:
|
||||
|
||||
@@ -24,6 +24,7 @@ import { buildManagedPeFixture } from "../../../src/dotnet/ManagedPe.fixture.js"
|
||||
import { elf } from "../../../src/domain/binaryTarget.fixture.js";
|
||||
import { managedMemberInspectionSchema } from "../../../src/domain/managed/managedArtifact.js";
|
||||
import { managedMemberComparisonResultSchema } from "../../../src/domain/managed/managedMemberComparison.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
|
||||
type ManagedOutputAssertion = Awaited<ReturnType<typeof createOutputAssertion>>;
|
||||
|
||||
@@ -476,10 +477,7 @@ const verifyManagedComparisonAndReconstruction = async (
|
||||
rightPath: string,
|
||||
outputAssertion: ManagedOutputAssertion,
|
||||
): Promise<void> => {
|
||||
await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: rightPath },
|
||||
});
|
||||
await callOk(client, "open_binary", { path: rightPath });
|
||||
const right = inlineEvidence(
|
||||
structured(
|
||||
await client.callTool({
|
||||
@@ -488,6 +486,10 @@ const verifyManagedComparisonAndReconstruction = async (
|
||||
}),
|
||||
),
|
||||
);
|
||||
expect(right).toMatchObject({
|
||||
subject: { local_path: rightPath, identity: { format: "pe" } },
|
||||
});
|
||||
expect(right.subject).not.toEqual(members.subject);
|
||||
const compared = inlineEvidence(
|
||||
structured(
|
||||
await client.callTool({
|
||||
|
||||
@@ -8,6 +8,7 @@ import { observed } from "../../fixtures/analysisExecution.js";
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
||||
import { callOk } from "../../support/mcp/toolResult.js";
|
||||
|
||||
const navigate = async (
|
||||
selection: Readonly<Record<string, unknown>>,
|
||||
@@ -27,10 +28,7 @@ const navigate = async (
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: process.execPath },
|
||||
});
|
||||
await callOk(client, "open_binary", { path: process.execPath });
|
||||
return (await client.callTool({
|
||||
name: "get_navigation_context",
|
||||
arguments: {},
|
||||
|
||||
@@ -241,6 +241,7 @@ const exerciseDeliveryFailure = async (
|
||||
type: "text",
|
||||
text: "still connected",
|
||||
});
|
||||
return reportedLimits;
|
||||
} finally {
|
||||
await Promise.all([client.close(), server.close()]);
|
||||
}
|
||||
@@ -261,11 +262,16 @@ it("keeps the SDK connection usable when oversized-error retention is unavailabl
|
||||
|
||||
it("retains the complete oversized diagnostic before removing its private structured carrier", async () => {
|
||||
const retained: Evidence[] = [];
|
||||
await exerciseDeliveryFailure((evidence) => {
|
||||
const reportedLimits = await exerciseDeliveryFailure((evidence) => {
|
||||
retained.push(evidence);
|
||||
return ok("added");
|
||||
}, "retained");
|
||||
expect(retained).toHaveLength(1);
|
||||
// The delivered reference names the record that was actually retained.
|
||||
expect(reportedLimits.evidence_reference).toEqual({
|
||||
kind: "retained-evidence",
|
||||
evidence_id: retained[0]?.evidence_id,
|
||||
});
|
||||
expect(retained[0]?.normalized_result).toEqual(
|
||||
oversizedFailure().structuredContent,
|
||||
);
|
||||
|
||||
@@ -193,12 +193,24 @@ it("delivers an over-budget partial observation as its summary with a cursor on
|
||||
expect(fitting.details).not.toHaveProperty(PARTIAL_OBSERVATION_DELIVERY);
|
||||
|
||||
// The failure's own facts are delivered whole, whatever the budget did.
|
||||
expect(failureFacts(budgeted)).toEqual(failureFacts(fitting));
|
||||
expect(budgeted).toMatchObject({
|
||||
const facts = {
|
||||
code: "resource_constraint",
|
||||
retryable: expect.any(Boolean),
|
||||
remediation: { action: expect.any(String) },
|
||||
});
|
||||
category: "resource_constraint",
|
||||
message: "The fixture stopped after completing its observation.",
|
||||
retryable: true,
|
||||
// Guidance is delivered as its owning projection words it.
|
||||
remediation: projectAnalysisError(
|
||||
stoppedWith(undefined, "inspect_binary_layout"),
|
||||
).remediation,
|
||||
details: {
|
||||
operation: "inspect_binary_layout",
|
||||
resource: "capacity",
|
||||
reason: "The fixture stopped after completing its observation.",
|
||||
reported_limits: { fixture_rows: 1 },
|
||||
},
|
||||
};
|
||||
expect(failureFacts(budgeted)).toEqual(facts);
|
||||
expect(failureFacts(fitting)).toEqual(facts);
|
||||
});
|
||||
|
||||
/** Complete entropy Evidence far over the default agent budget, and a small one. */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { structured } from "../../support/mcp/toolResult.js";
|
||||
import { callOk, structured } from "../../support/mcp/toolResult.js";
|
||||
import { connectFixtureClient } from "../../support/mcp/mcpFixture.js";
|
||||
import { unknownTarget } from "../../../src/domain/targetIdentity.js";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
@@ -76,6 +76,7 @@ const providerWithCapabilities = (
|
||||
capabilities: () => capabilities,
|
||||
createClient: () => ({
|
||||
execute: (operation) => {
|
||||
if (operation === "health") return Promise.resolve(ok(null));
|
||||
return Promise.resolve(
|
||||
err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
@@ -204,10 +205,8 @@ it("does not record capability unavailability without supporting Evidence", asyn
|
||||
{ name: "unavailable-unknown", version: "1" },
|
||||
resources,
|
||||
);
|
||||
await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: process.execPath },
|
||||
});
|
||||
// With nothing open the call below fails for another reason.
|
||||
await callOk(client, "open_binary", { path: process.execPath });
|
||||
|
||||
const unavailable = await client.callTool({
|
||||
name: "procedure_pseudo_code",
|
||||
@@ -218,7 +217,13 @@ it("does not record capability unavailability without supporting Evidence", asyn
|
||||
expect(unavailable.isError).toBe(true);
|
||||
expect(structured(unavailable)).toMatchObject({
|
||||
error: {
|
||||
category: "unavailable",
|
||||
code: "capability_unavailable",
|
||||
category: "unsupported_provider",
|
||||
details: {
|
||||
provider_id: "fixture",
|
||||
operation: "procedure_pseudo_code",
|
||||
reason: "Decompiler is not installed.",
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { text } from "../../support/mcp/toolResult.js";
|
||||
import type { RequestAnalysisPort } from "../../../src/ports/AnalysisProvider.js";
|
||||
import { callOk, text } from "../../support/mcp/toolResult.js";
|
||||
import type {
|
||||
RequestAnalysisPort,
|
||||
AnalysisClient,
|
||||
AnalysisProvider,
|
||||
CapabilityDescriptor,
|
||||
ProviderAvailability,
|
||||
} from "../../../src/ports/AnalysisProvider.js";
|
||||
import type { ApktoolRequest } from "../../../src/domain/apktool/apktoolResourceAnalysis.js";
|
||||
import type { AdbRequest } from "../../../src/domain/adb/adbDeviceAnalysis.js";
|
||||
import { unknownTarget } from "../../../src/domain/targetIdentity.js";
|
||||
@@ -7,6 +13,7 @@ import { ProviderCleanupError } from "../../../src/domain/providerCleanupError.j
|
||||
import { createEvidence } from "../../../src/domain/evidence.js";
|
||||
import { ProcessCaptureResourceScope } from "../../../src/process/capture/ProcessCaptureLifecycle.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFile, realpath, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
@@ -18,12 +25,6 @@ import { z } from "zod";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import type {
|
||||
AnalysisClient,
|
||||
AnalysisProvider,
|
||||
CapabilityDescriptor,
|
||||
ProviderAvailability,
|
||||
} from "../../../src/ports/AnalysisProvider.js";
|
||||
import type { AndroidAnalysisPort } from "../../../src/ports/android/AndroidAnalysisPort.js";
|
||||
import {
|
||||
createFixtureProviderIdentity,
|
||||
@@ -121,7 +122,10 @@ describe("MCP snapshot lifecycle ordering", () => {
|
||||
sessionObservation.release(ok(first));
|
||||
expect((await observation).isError).not.toBe(true);
|
||||
expect((await closing).isError).not.toBe(true);
|
||||
expect((await later).isError).toBe(true);
|
||||
// The later call waits behind the close and then finds no open target.
|
||||
expect(parseMcpToolError(await later)).toMatchObject({
|
||||
error: { code: "target_unavailable" },
|
||||
});
|
||||
const snapshot = parseAnalysisSnapshot(
|
||||
JSON.parse(await readFile(snapshotPath, "utf8")),
|
||||
);
|
||||
@@ -141,13 +145,18 @@ describe("MCP snapshot lifecycle ordering", () => {
|
||||
).not.toBe(true);
|
||||
const bytes = await readFile(snapshotPath);
|
||||
expect(
|
||||
(
|
||||
parseMcpToolError(
|
||||
await mcp.callTool({
|
||||
name: "close_binary",
|
||||
arguments: { snapshot_path: snapshotPath },
|
||||
})
|
||||
).isError,
|
||||
).toBe(true);
|
||||
}),
|
||||
),
|
||||
).toMatchObject({
|
||||
error: {
|
||||
code: "invalid_request",
|
||||
details: { operation: "write", reason: "exists", path: snapshotPath },
|
||||
},
|
||||
});
|
||||
expect(Buffer.compare(await readFile(snapshotPath), bytes)).toBe(0);
|
||||
expect(
|
||||
(
|
||||
@@ -161,14 +170,30 @@ describe("MCP snapshot lifecycle ordering", () => {
|
||||
structured(await mcp.callTool({ name: "binary_session", arguments: {} }))
|
||||
.result,
|
||||
).toMatchObject({ open: true });
|
||||
// The reopened session saves the same bytes, so a marker shows the write.
|
||||
await writeFile(snapshotPath, "stale snapshot");
|
||||
const overwritten = await mcp.callTool({
|
||||
name: "close_binary",
|
||||
arguments: { snapshot_path: snapshotPath, overwrite: true },
|
||||
});
|
||||
const written = await readFile(snapshotPath);
|
||||
expect(Buffer.compare(written, bytes)).toBe(0);
|
||||
expect(structured(overwritten).result).toEqual({
|
||||
path: snapshotPath,
|
||||
bytes: written.byteLength,
|
||||
primitive_entries: 1,
|
||||
workflow_entries: 0,
|
||||
evidence_records: 1,
|
||||
});
|
||||
const rewritten = parseAnalysisSnapshot(
|
||||
JSON.parse(written.toString("utf8")),
|
||||
);
|
||||
expect(
|
||||
(
|
||||
await mcp.callTool({
|
||||
name: "close_binary",
|
||||
arguments: { snapshot_path: snapshotPath, overwrite: true },
|
||||
})
|
||||
).isError,
|
||||
).not.toBe(true);
|
||||
rewritten.entries.map((entry) => [
|
||||
entry.operation,
|
||||
entry.execution.result,
|
||||
]),
|
||||
).toEqual([["address_name", first]]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -616,7 +641,7 @@ describe("target-free MCP workflow", () => {
|
||||
}),
|
||||
).result,
|
||||
).toMatchObject({ valid: true, truthVerified: false });
|
||||
await mcp.callTool({ name: "open_binary", arguments: { path: second } });
|
||||
await callOk(mcp, "open_binary", { path: second });
|
||||
expect(closed.some((path) => path.endsWith("first.hop"))).toBe(true);
|
||||
expect(
|
||||
text(await mcp.callTool({ name: "binary_session", arguments: {} })),
|
||||
@@ -641,14 +666,34 @@ describe("target-free MCP workflow", () => {
|
||||
expect(
|
||||
text(await mcp.callTool({ name: "binary_session", arguments: {} })),
|
||||
).toContain('"open":false');
|
||||
const sha256 = async (path: string) =>
|
||||
createHash("sha256")
|
||||
.update(await readFile(path))
|
||||
.digest("hex");
|
||||
const [firstSha256, secondSha256] = await Promise.all([
|
||||
sha256(first),
|
||||
sha256(second),
|
||||
]);
|
||||
expect(
|
||||
(
|
||||
parseMcpToolError(
|
||||
await mcp.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: first, snapshot_path: snapshotPath },
|
||||
})
|
||||
).isError,
|
||||
).toBe(true);
|
||||
}),
|
||||
),
|
||||
).toMatchObject({
|
||||
error: {
|
||||
code: "evidence_integrity_mismatch",
|
||||
details: {
|
||||
binding_mismatch: {
|
||||
target: {
|
||||
snapshot: { identity: { sha256: secondSha256 } },
|
||||
selected: { identity: { sha256: firstSha256 } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(
|
||||
structured(await mcp.callTool({ name: "list_unknowns", arguments: {} }))
|
||||
.result,
|
||||
@@ -682,7 +727,7 @@ describe("MCP snapshot open ordering", () => {
|
||||
resources,
|
||||
);
|
||||
const snapshotPath = join(directory, "analysis.json");
|
||||
await mcp.callTool({ name: "open_binary", arguments: { path: second } });
|
||||
await callOk(mcp, "open_binary", { path: second });
|
||||
expect(
|
||||
(
|
||||
await mcp.callTool({
|
||||
@@ -691,7 +736,7 @@ describe("MCP snapshot open ordering", () => {
|
||||
})
|
||||
).isError,
|
||||
).not.toBe(true);
|
||||
await mcp.callTool({ name: "open_binary", arguments: { path: first } });
|
||||
await callOk(mcp, "open_binary", { path: first });
|
||||
|
||||
// Dispatched without awaiting, like a client issuing one turn's calls.
|
||||
const opening = mcp.callTool({
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { canonicalOutputSchema } from "../../fixtures/canonicalOutputSchema.js";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
@@ -121,35 +122,14 @@ it.each(["compact"] as const)(
|
||||
path,
|
||||
JSON.stringify({ ...reference.value, root_sha256: "0".repeat(64) }),
|
||||
);
|
||||
expect(
|
||||
(
|
||||
await client.callTool({
|
||||
name: "compare_source_to_bundle",
|
||||
arguments: { ...inputs, reference: { kind: "file", path } },
|
||||
})
|
||||
).isError,
|
||||
).toBe(true);
|
||||
for (const value of [
|
||||
{ kind: "file", path: "relative.json" },
|
||||
{ kind: "file", path: root },
|
||||
{ kind: "file", path: join(root, "missing.json") },
|
||||
])
|
||||
expect(
|
||||
(
|
||||
await client.callTool({
|
||||
name: "compare_source_to_bundle",
|
||||
arguments: { ...inputs, reference: value },
|
||||
})
|
||||
).isError,
|
||||
).toBe(true);
|
||||
expect(
|
||||
(
|
||||
await client.callTool({
|
||||
name: "inspect_analysis_view",
|
||||
arguments: { source, view: { ...request, fields: ["not_a_field"] } },
|
||||
})
|
||||
).isError,
|
||||
).toBe(true);
|
||||
await expectReferenceRefusals({
|
||||
client,
|
||||
inputs,
|
||||
root,
|
||||
path,
|
||||
source,
|
||||
request,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
@@ -385,3 +365,74 @@ const assertCandidateBoundaryPages = async (
|
||||
coverage: { total: 3, next_offset: null, exhausted: true },
|
||||
});
|
||||
};
|
||||
|
||||
/** Each refused reference names its own field or file fact. */
|
||||
const expectReferenceRefusals = async ({
|
||||
client,
|
||||
inputs,
|
||||
root,
|
||||
path,
|
||||
source,
|
||||
request,
|
||||
}: Pick<
|
||||
Awaited<ReturnType<typeof comparisonFixture>>,
|
||||
"client" | "inputs" | "root" | "path"
|
||||
> & {
|
||||
readonly source: Readonly<Record<string, unknown>>;
|
||||
readonly request: Readonly<Record<string, unknown>>;
|
||||
}) => {
|
||||
const refusal = async (name: string, arguments_: Record<string, unknown>) =>
|
||||
parseMcpToolError(await client.callTool({ name, arguments: arguments_ }))
|
||||
.error;
|
||||
expect(
|
||||
await refusal("compare_source_to_bundle", {
|
||||
...inputs,
|
||||
reference: { kind: "file", path },
|
||||
}),
|
||||
).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: [
|
||||
{
|
||||
path: ["reference", "root_sha256"],
|
||||
reason: "invalid_value",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(
|
||||
await refusal("compare_source_to_bundle", {
|
||||
...inputs,
|
||||
reference: { kind: "file", path: "relative.json" },
|
||||
}),
|
||||
).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: [{ path: ["reference", "path"], reason: "invalid_format" }],
|
||||
},
|
||||
});
|
||||
for (const [selected, reason] of [
|
||||
[root, "not-file"],
|
||||
[join(root, "missing.json"), "missing"],
|
||||
] as const)
|
||||
expect(
|
||||
await refusal("compare_source_to_bundle", {
|
||||
...inputs,
|
||||
reference: { kind: "file", path: selected },
|
||||
}),
|
||||
).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: { operation: "read", reason, path: selected },
|
||||
});
|
||||
expect(
|
||||
await refusal("inspect_analysis_view", {
|
||||
source,
|
||||
view: { ...request, fields: ["not_a_field"] },
|
||||
}),
|
||||
).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: [{ path: ["view", "fields", 0], reason: "invalid_value" }],
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -3,7 +3,6 @@ import { join } from "node:path";
|
||||
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
@@ -14,7 +13,6 @@ it("delivers typed tool failures without violating the advertised success schema
|
||||
const missing = join(root, "not-present.bin");
|
||||
const { client, call } = await connectLocalToolsMcp();
|
||||
const tools = (await client.listTools()).tools;
|
||||
const failures: string[] = [];
|
||||
const requests = [
|
||||
{ name: "list_documents", arguments: {} },
|
||||
{ name: "open_binary", arguments: { path: missing } },
|
||||
@@ -35,17 +33,20 @@ it("delivers typed tool failures without violating the advertised success schema
|
||||
expect(JSON.stringify(diagnostic), request.name).toContain(
|
||||
JSON.stringify(missing).slice(1, -1),
|
||||
);
|
||||
if (reply.structuredContent !== undefined) {
|
||||
const validate = new Ajv2020({
|
||||
strict: false,
|
||||
validateFormats: false,
|
||||
}).compile(canonicalOutputSchema(tool.name));
|
||||
if (!validate(reply.structuredContent)) failures.push(request.name);
|
||||
}
|
||||
// The diagnostic travels once, as text, so the advertised success schema
|
||||
// never sees it.
|
||||
expect(reply.isError, request.name).toBe(true);
|
||||
expect(reply.structuredContent, request.name).toBeUndefined();
|
||||
}
|
||||
expect(failures).toEqual([]);
|
||||
const successful = await call("get_evidence_bundle", {});
|
||||
expect(successful.isError).not.toBe(true);
|
||||
expect(successful.structuredContent).toBeDefined();
|
||||
const validate = new Ajv2020({
|
||||
strict: false,
|
||||
validateFormats: false,
|
||||
}).compile(canonicalOutputSchema("get_evidence_bundle"));
|
||||
expect(
|
||||
validate(successful.structuredContent),
|
||||
JSON.stringify(validate.errors),
|
||||
).toBe(true);
|
||||
await client.ping();
|
||||
});
|
||||
@@ -30,6 +30,7 @@ import { liveProcesses } from "../../../src/process/ProcessOwnershipProcessTree.
|
||||
import { waitForProviderProcessReady } from "../../fixtures/providerProcess.js";
|
||||
import { createDeferred } from "../../fixtures/binarySession.js";
|
||||
import { phaseArrival, phaseGate } from "../../support/lifecycleHarness.js";
|
||||
import { expectProcessRunning } from "../../support/process/observePosixProcess.js";
|
||||
|
||||
const command = (script: string) => ({
|
||||
command: process.execPath,
|
||||
@@ -614,7 +615,7 @@ it.skipIf(process.platform === "win32")(
|
||||
if (remainsLive) await delay(25);
|
||||
}
|
||||
expect(remainsLive).toBe(false);
|
||||
expect(() => process.kill(unrelated.process.pid!, 0)).not.toThrow();
|
||||
await expectProcessRunning(unrelated.process.pid);
|
||||
} finally {
|
||||
const descendant = descendantOwner;
|
||||
const results = await Promise.allSettled([
|
||||
@@ -783,10 +784,10 @@ it.skipIf(process.platform === "win32").each(["cancelled", "timeout"] as const)(
|
||||
]);
|
||||
// An unresolved member does not grant authority to signal the shared group.
|
||||
const acquiredPid = launched.ownership.leaderPid;
|
||||
expect(() => process.kill(acquiredPid, 0)).not.toThrow();
|
||||
await expectProcessRunning(acquiredPid);
|
||||
if (cleanup?.cleaned === false) {
|
||||
for (const member of cleanup.failures ?? []) {
|
||||
expect(() => process.kill(member.pid, 0)).not.toThrow();
|
||||
await expectProcessRunning(member.pid);
|
||||
expect(failure.cleanupFailure).toContain(String(member.pid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ import {
|
||||
ghidraFixturePath as fixturePath,
|
||||
} from "./ghidraClient.fixture.js";
|
||||
import { waitFor } from "../../../support/testWait.js";
|
||||
import { expectRemoved } from "../../../support/expectRemoved.js";
|
||||
|
||||
const PROFILE_DIGEST = "a".repeat(64);
|
||||
const PROVIDER_VERSION = "12.2";
|
||||
@@ -224,9 +225,7 @@ it("reports unknown startup work and stops notifications when cancellation relea
|
||||
]);
|
||||
await client.close();
|
||||
await expect(waitForChildExit(child, 5_000)).resolves.toBe(true);
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
await vi.advanceTimersByTimeAsync(30_000);
|
||||
expect(updates).toHaveLength(1);
|
||||
});
|
||||
@@ -1068,9 +1067,7 @@ it.each(
|
||||
expect(client.isReady()).toBe(false);
|
||||
await expect(waitForExit(launcher.processes[0])).resolves.toBe(true);
|
||||
expect(launcher.requests).toEqual(["ping", "shutdown"]);
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1343,9 +1340,7 @@ it.skipIf(process.platform === "win32")(
|
||||
);
|
||||
if (socketRoot === undefined)
|
||||
throw new Error("Expected a separate socket root");
|
||||
await expect(
|
||||
access(launcher.runtimeRoots[0] ?? ""),
|
||||
).rejects.toMatchObject({ code: "ENOENT" });
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
await expect(access(socketRoot.path)).resolves.toBeUndefined();
|
||||
const retry = await client.start();
|
||||
if (retry.ok) throw new Error("Restart lost the retained socket root");
|
||||
@@ -1439,9 +1434,7 @@ it("retains startup failure and cleans up when lineage observation rejects", asy
|
||||
const child = launcher.processes[0];
|
||||
if (child === undefined) throw new Error("fixture child was not launched");
|
||||
await expect(waitForChildExit(child, 5_000)).resolves.toBe(true);
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
expect(client.isReady()).toBe(false);
|
||||
await expect(client.start()).resolves.toMatchObject({ ok: true });
|
||||
expect(launcher.processes).toHaveLength(2);
|
||||
@@ -1476,9 +1469,7 @@ it("cleans up when the final waiter cancels during lineage observation", async (
|
||||
error: { kind: "cancelled" },
|
||||
});
|
||||
await expect(waitForChildExit(child, 5_000)).resolves.toBe(true);
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
await expect(client.callToolIfReady("list_strings", {})).resolves.toBe(
|
||||
undefined,
|
||||
);
|
||||
@@ -1531,9 +1522,7 @@ it("cancels a retry waiter without taking ownership of startup cleanup", async (
|
||||
const child = launcher.processes[0];
|
||||
if (child === undefined) throw new Error("fixture child was not launched");
|
||||
await expect(waitForChildExit(child, 5_000)).resolves.toBe(true);
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
});
|
||||
|
||||
it("applies one startup deadline and removes the private runtime", async () => {
|
||||
@@ -1551,9 +1540,7 @@ it("applies one startup deadline and removes the private runtime", async () => {
|
||||
ok: false,
|
||||
error: { kind: "timeout", timeoutMs: 30 },
|
||||
});
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
await client.close();
|
||||
await expect(waitForExit(child)).resolves.toBe(true);
|
||||
});
|
||||
@@ -1660,9 +1647,7 @@ it("cancels startup promptly and leaves no project or process", async () => {
|
||||
const result = await pending;
|
||||
|
||||
expect(result).toMatchObject({ ok: false, error: { kind: "cancelled" } });
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
await client.close();
|
||||
await expect(waitForExit(process_)).resolves.toBe(true);
|
||||
});
|
||||
@@ -1772,9 +1757,7 @@ describe("GhidraClient cleanup and diagnostics", () => {
|
||||
await Promise.all([client.close(), client.close()]);
|
||||
await client.close();
|
||||
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
const process_ = launcher.processes[0];
|
||||
expect(exited(process_)).toBe(true);
|
||||
if (process_ === undefined)
|
||||
@@ -1803,9 +1786,7 @@ describe("GhidraClient cleanup and diagnostics", () => {
|
||||
exit_code: child.exitCode,
|
||||
run_id: "11111111-1111-4111-8111-111111111111",
|
||||
});
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
});
|
||||
|
||||
it("bounds long-lived launcher diagnostics without interrupting the session", async () => {
|
||||
@@ -1850,9 +1831,7 @@ describe("GhidraClient cleanup and diagnostics", () => {
|
||||
|
||||
await client.close();
|
||||
expect(exited(launcher.processes[0])).toBe(true);
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
});
|
||||
|
||||
it("retains actionable diagnostics without retaining its token", async () => {
|
||||
@@ -2171,9 +2150,7 @@ describe("GhidraClient shutdown diagnostics", () => {
|
||||
}),
|
||||
);
|
||||
expect(logs.join("")).not.toContain(launcher.tokens[0]);
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
await expect(waitForExit(launcher.processes[0])).resolves.toBe(true);
|
||||
});
|
||||
|
||||
@@ -2214,9 +2191,7 @@ describe("GhidraClient shutdown diagnostics", () => {
|
||||
);
|
||||
}
|
||||
expect(logs.join("")).not.toContain(launcher.tokens[0]);
|
||||
await expect(
|
||||
access(launcher.runtimeRoots[0] ?? ""),
|
||||
).rejects.toMatchObject({ code: "ENOENT" });
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
await expect(waitForExit(launcher.processes[0])).resolves.toBe(true);
|
||||
},
|
||||
);
|
||||
@@ -2309,9 +2284,7 @@ it("retains the identity refusal when cancellation arrives during final startup
|
||||
code: "import_identity_mismatch",
|
||||
});
|
||||
expect(client.isReady()).toBe(false);
|
||||
await expect(access(fixture.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(fixture.runtimeRoots[0]);
|
||||
}, [
|
||||
() => identityRefusalCleanup.release(),
|
||||
async () => {
|
||||
@@ -2522,9 +2495,7 @@ it.each([null, "caller stopped", new Error("caller stopped")])(
|
||||
// session closed once the grace period elapsed.
|
||||
expect(launcher.requests).toContain("cancel");
|
||||
expect(await waitForExit(launcher.processes[0])).toBe(true);
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -2571,9 +2542,7 @@ it("preserves the observed protocol failure when cancellation interrupts request
|
||||
failure_output: { complete: false },
|
||||
});
|
||||
expect(await waitForExit(launcher.processes[0])).toBe(true);
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
});
|
||||
|
||||
it.each([null, "caller stopped", new Error("caller stopped")])(
|
||||
@@ -2607,9 +2576,7 @@ it.each([null, "caller stopped", new Error("caller stopped")])(
|
||||
expect(result.error.kind).toBe("cancelled");
|
||||
expect(result.error.cancellation?.reason).toBe(reason);
|
||||
expect(await waitForExit(launcher.processes[0])).toBe(true);
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -2652,9 +2619,7 @@ it.each([
|
||||
if (mode === "import_identity_unavailable")
|
||||
expect(result.error.cause).toMatchObject({ code: mode });
|
||||
expect(await waitForExit(launcher.processes[0])).toBe(true);
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
startHopperFixtureClient as startClient,
|
||||
} from "./hopperClient.fixture.js";
|
||||
import { stopProviderProcessFixture } from "../../../fixtures/providerProcess.js";
|
||||
import { expectProcessRunning } from "../../../support/process/observePosixProcess.js";
|
||||
|
||||
class OwnedFixtureLauncher implements BridgeLauncher {
|
||||
ownership:
|
||||
@@ -141,7 +142,7 @@ describe("HopperClient cleanup", () => {
|
||||
const unrelatedPid = unrelated.pid;
|
||||
if (unrelatedPid === undefined)
|
||||
throw new Error("Unrelated Hopper fixture has no PID");
|
||||
expect(() => process.kill(unrelatedPid, 0)).not.toThrow();
|
||||
await expectProcessRunning(unrelatedPid);
|
||||
expect(diagnostics).toContainEqual({
|
||||
type: "owned-shutdown",
|
||||
status: "verified-cleanup",
|
||||
|
||||
@@ -18,6 +18,7 @@ import type {
|
||||
} from "../../../../src/hopper/BridgeLauncher.js";
|
||||
import { HopperClient } from "../../../../src/hopper/HopperClient.js";
|
||||
import { LINUX_PRIVATE_DISPLAY_DIAGNOSTIC_PREFIX } from "../../../../src/hopper/LinuxPrivateDisplayDiagnostic.js";
|
||||
import { expectRemoved } from "../../../support/expectRemoved.js";
|
||||
|
||||
class SilentLauncher implements BridgeLauncher {
|
||||
launch() {
|
||||
@@ -227,9 +228,7 @@ describe("HopperClient startup deadline", () => {
|
||||
stage: "startup",
|
||||
});
|
||||
expect(launcher.directories).toHaveLength(1);
|
||||
await expect(access(launcher.directories[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.directories[0]);
|
||||
const process = launcher.processes[0];
|
||||
expect(
|
||||
process !== undefined &&
|
||||
|
||||
@@ -17,6 +17,7 @@ import { ok } from "../../../../src/domain/result.js";
|
||||
import { ProviderRunLineage } from "../../../../src/process/ProviderRunLineage.js";
|
||||
import { waitForExit } from "../../../support/process/processFixture.js";
|
||||
import { waitFor } from "../../../support/testWait.js";
|
||||
import { expectRemoved } from "../../../support/expectRemoved.js";
|
||||
|
||||
it("preserves a warm provider when an already cancelled caller joins", async () => {
|
||||
const launcher = new HopperFixtureLauncher();
|
||||
@@ -107,9 +108,7 @@ it("retains the final caller's cleanup failure and blocks replacement until clos
|
||||
await expect(access(fixture.directories[0] ?? "")).resolves.toBeUndefined();
|
||||
allowCleanup = true;
|
||||
await expect(client.close()).resolves.toEqual({ ok: true, value: null });
|
||||
await expect(access(fixture.directories[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(fixture.directories[0]);
|
||||
await expect(client.start()).resolves.toMatchObject({ ok: true });
|
||||
expect(fixture.processes).toHaveLength(2);
|
||||
} finally {
|
||||
@@ -232,9 +231,7 @@ it.each(["cancelled", "rejected"] as const)(
|
||||
const child = launcher.processes[0];
|
||||
if (child === undefined) throw new Error("Missing fixture process");
|
||||
expect(await waitForExit(child, 5_000)).toBe(true);
|
||||
await expect(access(launcher.directories[0] ?? "")).rejects.toMatchObject(
|
||||
{ code: "ENOENT" },
|
||||
);
|
||||
await expectRemoved(launcher.directories[0]);
|
||||
expect(client.isReady()).toBe(false);
|
||||
await expect(client.start()).resolves.toMatchObject({ ok: true });
|
||||
expect(launcher.processes).toHaveLength(2);
|
||||
|
||||
@@ -20,6 +20,7 @@ import { OwnedFileHandle } from "../../../../src/filesystem/OwnedFileHandle.js";
|
||||
import { RegularFileCleanupFailure } from "../../../../src/filesystem/OwnedRegularFile.js";
|
||||
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
||||
import { makeLauncher, ownedGroupCleanup } from "./kunaVersionProbeProcess.js";
|
||||
import { expectProcessRunning } from "../../../support/process/observePosixProcess.js";
|
||||
|
||||
const writeProbe = async (
|
||||
root: string,
|
||||
@@ -347,7 +348,7 @@ it.skipIf(process.platform === "win32")(
|
||||
expect(launcher.launches).toBe(2);
|
||||
expect(scope.hasPending).toBe(false);
|
||||
expect(primary.cleanupIncomplete).toBe(false);
|
||||
expect(() => process.kill(unrelated.pid!, 0)).not.toThrow();
|
||||
await expectProcessRunning(unrelated.pid);
|
||||
} finally {
|
||||
allowCleanup = true;
|
||||
await scope.close();
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
NativeFixtureRunner,
|
||||
nativeMachoTarget,
|
||||
} from "../../../fixtures/nativeCommands.js";
|
||||
import { expectProcessRunning } from "../../../support/process/observePosixProcess.js";
|
||||
|
||||
const request: Parameters<NativeCallTracer["trace"]>[0] = {
|
||||
executable: "/fixture/target",
|
||||
@@ -152,9 +153,9 @@ it.skipIf(process.platform === "win32")(
|
||||
coverage: { status: "partial", reason: "cleanup-failure" },
|
||||
});
|
||||
const pid = ownedPid;
|
||||
expect(() => process.kill(pid, 0)).not.toThrow();
|
||||
await expectProcessRunning(pid);
|
||||
expect((await client.close()).ok).toBe(false);
|
||||
expect(() => process.kill(pid, 0)).not.toThrow();
|
||||
await expectProcessRunning(pid);
|
||||
await expect(access(root)).resolves.toBeUndefined();
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
expect(() => process.kill(pid, 0)).toThrow();
|
||||
@@ -210,9 +211,9 @@ it.skipIf(process.platform === "win32")(
|
||||
expect(trace.error.cleanupResources).toContain(`native-target:${pid}`);
|
||||
const root = runtimeRoot(trace.error);
|
||||
await expect(access(root)).resolves.toBeUndefined();
|
||||
expect(() => process.kill(pid, 0)).not.toThrow();
|
||||
await expectProcessRunning(pid);
|
||||
expect((await client.close()).ok).toBe(false);
|
||||
expect(() => process.kill(pid, 0)).not.toThrow();
|
||||
await expectProcessRunning(pid);
|
||||
await expect(access(root)).resolves.toBeUndefined();
|
||||
await stopChild(child);
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
@@ -250,7 +251,7 @@ it.skipIf(process.platform === "win32")(
|
||||
expect(trace.error).toBeInstanceOf(ProviderCleanupError);
|
||||
if (!(trace.error instanceof ProviderCleanupError)) return;
|
||||
expect(trace.error.cleanupResources).toContain("native-target:unknown");
|
||||
expect(() => process.kill(pid, 0)).not.toThrow();
|
||||
await expectProcessRunning(pid);
|
||||
const root = runtimeRoot(trace.error);
|
||||
await stopChild(child);
|
||||
await writeFile(join(root, "pid"), String(pid));
|
||||
|
||||
@@ -46,6 +46,7 @@ import {
|
||||
nativeMachoTarget,
|
||||
nativeResolvedToolFixture,
|
||||
} from "../../../fixtures/nativeCommands.js";
|
||||
import { expectRemoved } from "../../../support/expectRemoved.js";
|
||||
|
||||
const EVENT = {
|
||||
sequence: 0,
|
||||
@@ -1185,7 +1186,7 @@ describe("LLDB target proof read by cleanup retry", () => {
|
||||
if (published === "no target created") {
|
||||
expect(close.ok).toBe(true);
|
||||
expect(result.error.cleanupIncomplete).toBe(false);
|
||||
await expect(access(retainedRoot ?? "")).rejects.toThrow();
|
||||
await expectRemoved(retainedRoot);
|
||||
return;
|
||||
}
|
||||
expect(close.ok).toBe(false);
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
} from "./ghidra/ghidraClient.fixture.js";
|
||||
import { HopperFixtureLauncher } from "./hopper/hopperClient.fixture.js";
|
||||
import { waitFor } from "../../support/testWait.js";
|
||||
import { expectRemoved } from "../../support/expectRemoved.js";
|
||||
|
||||
const providers = [
|
||||
{
|
||||
@@ -95,9 +96,7 @@ it.each(providers)(
|
||||
providerClose.release();
|
||||
await expect(closing).resolves.toMatchObject({ ok: true });
|
||||
await retry;
|
||||
await expect(access(roots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(roots[0]);
|
||||
await expect(client.start()).resolves.toMatchObject({ ok: true });
|
||||
expect(children).toHaveLength(2);
|
||||
}, [
|
||||
|
||||
Vendored
+1
-12
@@ -5,7 +5,7 @@ import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import type { CallToolResult } from "@modelcontextprotocol/server";
|
||||
import { callOk } from "../support/mcp/toolResult.js";
|
||||
import { expect, onTestFinished } from "vitest";
|
||||
|
||||
import type { BuildSettle } from "../../src/application/desktop/DesktopBuildSettle.js";
|
||||
@@ -110,17 +110,6 @@ export const bundleFolder = async (
|
||||
return bundle;
|
||||
};
|
||||
|
||||
/** Call a tool and fail the test with its result when it is an error. */
|
||||
export const callOk = async (
|
||||
client: Client,
|
||||
name: string,
|
||||
args: Record<string, unknown>,
|
||||
): Promise<CallToolResult> => {
|
||||
const result = await client.callTool({ name, arguments: args });
|
||||
expect(result.isError, JSON.stringify(result)).not.toBe(true);
|
||||
return result as CallToolResult;
|
||||
};
|
||||
|
||||
/** Start a build computer and return its id. */
|
||||
export const startBuildComputer = async (
|
||||
client: Client,
|
||||
|
||||
@@ -76,6 +76,7 @@ import {
|
||||
} from "../boundary/providers/ghidra/ghidraClient.fixture.js";
|
||||
import { waitForExit } from "../support/process/processFixture.js";
|
||||
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||
import { expectRemoved } from "../support/expectRemoved.js";
|
||||
|
||||
const clients: GhidraClient[] = [];
|
||||
beforeEach(() => {
|
||||
@@ -298,9 +299,7 @@ it
|
||||
if (child === undefined)
|
||||
throw new Error("Expected admitted fixture process");
|
||||
expect(await waitForExit(child, 5000)).toBe(true);
|
||||
await expect(access(launcher.runtimeRoots[0] ?? "")).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
await expectRemoved(launcher.runtimeRoots[0]);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
createTestWorkspace,
|
||||
removeTestWorkspace,
|
||||
} from "../support/workspace/workspaceFixture.js";
|
||||
import { expectProcessRunning } from "../support/process/observePosixProcess.js";
|
||||
|
||||
const supportedHost = process.platform !== "win32";
|
||||
|
||||
@@ -120,7 +121,7 @@ it.runIf(supportedHost)(
|
||||
if (pid === undefined)
|
||||
throw new Error("The fixture did not acquire a process");
|
||||
const workerPid = pid;
|
||||
expect(() => process.kill(workerPid, 0)).not.toThrow();
|
||||
await expectProcessRunning(workerPid);
|
||||
expect(await readFile(join(ownedPath, "object.snapshot"), "utf8")).toBe(
|
||||
"source-owned-seam-bytes",
|
||||
);
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
createTestWorkspace,
|
||||
removeTestWorkspace,
|
||||
} from "../support/workspace/workspaceFixture.js";
|
||||
import { expectProcessRunning } from "../support/process/observePosixProcess.js";
|
||||
|
||||
const supportedHost = process.platform !== "win32";
|
||||
const worker = fileURLToPath(
|
||||
@@ -123,7 +124,7 @@ const changingWorker = async (
|
||||
reason: "fixture inspection unavailable",
|
||||
};
|
||||
const descendant = Number(await readFile(ready, "utf8"));
|
||||
expect(() => process.kill(descendant, 0)).not.toThrow();
|
||||
await expectProcessRunning(descendant);
|
||||
await writeFile(trigger, "change now");
|
||||
await expect
|
||||
.poll(() =>
|
||||
@@ -298,7 +299,7 @@ it.runIf(supportedHost).each([
|
||||
const descendant = Number(
|
||||
await readFile(join(stagePath, "descendant.ready"), "utf8"),
|
||||
);
|
||||
expect(() => process.kill(descendant, 0)).not.toThrow();
|
||||
await expectProcessRunning(descendant);
|
||||
await expect(access(root.path)).resolves.toBeUndefined();
|
||||
},
|
||||
);
|
||||
@@ -360,7 +361,7 @@ it.runIf(supportedHost)(
|
||||
});
|
||||
if (pid === undefined) throw new Error("Expected a live owned debugger");
|
||||
const debuggerPid = pid;
|
||||
expect(() => process.kill(debuggerPid, 0)).not.toThrow();
|
||||
await expectProcessRunning(debuggerPid);
|
||||
cleanupAllowed = true;
|
||||
await provider.close();
|
||||
expect(() => process.kill(debuggerPid, 0)).toThrow();
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { lstat } from "node:fs/promises";
|
||||
import { expect } from "vitest";
|
||||
|
||||
/**
|
||||
* Expect a recorded path to be gone. A missing record fails instead of
|
||||
* passing: `access("")` also rejects with ENOENT, so a `list[0] ?? ""` check
|
||||
* passes when the fixture never recorded the resource. `lstat` keeps a
|
||||
* dangling symbolic link from reading as removed.
|
||||
*/
|
||||
export const expectRemoved = async (
|
||||
path: string | undefined,
|
||||
): Promise<void> => {
|
||||
if (path === undefined || path === "")
|
||||
throw new Error("expectRemoved needs a recorded path; none was recorded");
|
||||
await expect(lstat(path)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Client } from "@modelcontextprotocol/client";
|
||||
import type { CallToolResult } from "@modelcontextprotocol/server";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
|
||||
@@ -17,3 +18,25 @@ export const structured = (result: CallToolResult): Record<string, unknown> => {
|
||||
throw new Error("missing structured result");
|
||||
return Object.fromEntries(Object.entries(result.structuredContent));
|
||||
};
|
||||
|
||||
/**
|
||||
* Call a tool whose success the rest of the test depends on, such as
|
||||
* `open_binary` or a `start_*` tool used as fixture setup, and fail at that
|
||||
* step when it refuses. Refusals such as "nothing is open" otherwise satisfy
|
||||
* later assertions that expect an error, an empty list or a null result.
|
||||
*/
|
||||
export const callOk = async (
|
||||
client: Pick<Client, "callTool">,
|
||||
name: string,
|
||||
args: Record<string, unknown> = {},
|
||||
): Promise<CallToolResult> => {
|
||||
const result = (await client.callTool({
|
||||
name,
|
||||
arguments: args,
|
||||
})) as CallToolResult;
|
||||
if (result.isError === true)
|
||||
throw new Error(
|
||||
`Setup step ${name} failed: ${JSON.stringify(result.content)}`,
|
||||
);
|
||||
return result;
|
||||
};
|
||||
@@ -74,6 +74,19 @@ export const processHasStopped = async (pid: number): Promise<boolean> => {
|
||||
return observation.kind !== "running";
|
||||
};
|
||||
|
||||
/**
|
||||
* Expect a recorded process to still be running. Use this instead of
|
||||
* `process.kill(pid, 0)`: a test-owned child that REA wrongly signalled stays
|
||||
* a zombie until it is reaped, and signal 0 still reaches it.
|
||||
*/
|
||||
export const expectProcessRunning = async (
|
||||
pid: number | undefined,
|
||||
): Promise<void> => {
|
||||
if (pid === undefined)
|
||||
throw new Error("expectProcessRunning needs a recorded PID");
|
||||
expect(await processHasStopped(pid), `process ${pid} is running`).toBe(false);
|
||||
};
|
||||
|
||||
/**
|
||||
* True when no member of the process group is still running. Lists all
|
||||
* processes with `ps -A -o pgid= -o stat=`; the output carries no command
|
||||
|
||||
Reference in new issue
Block a user