chore: integrate canonical Evidence changes for MCP error delivery
This commit is contained in:
@@ -75,6 +75,9 @@ export async function withArtifactMcp(target, verify) {
|
||||
export async function artifactMcpResult(client, name, arguments_ = {}) {
|
||||
const result = await client.callTool({ name, arguments: arguments_ });
|
||||
assert.notEqual(result.isError, true, JSON.stringify(result));
|
||||
assert.ok(result.structuredContent?.result, "MCP omitted structured result");
|
||||
return result.structuredContent.result;
|
||||
assert.ok(
|
||||
result.structuredContent?.normalized_result,
|
||||
"MCP omitted structured result",
|
||||
);
|
||||
return result.structuredContent.normalized_result;
|
||||
}
|
||||
|
||||
@@ -48,8 +48,7 @@ export async function verifyBrowserDomDestinations(
|
||||
});
|
||||
assert.notEqual(result.isError, true, mcpTextValue(result));
|
||||
assertFormDestinations(
|
||||
parseEvidence(JSON.parse(mcpTextValue(result)).evidence)
|
||||
.normalized_result,
|
||||
parseEvidence(JSON.parse(mcpTextValue(result))).normalized_result,
|
||||
documentUrl,
|
||||
);
|
||||
return { cli: true, stdio_mcp: true, current_document_destinations: 4 };
|
||||
|
||||
@@ -105,9 +105,7 @@ export async function verifyBrowserModules(
|
||||
arguments: input,
|
||||
});
|
||||
assert.notEqual(response.isError, true, mcpTextValue(response));
|
||||
const mcpEvidence = parseEvidence(
|
||||
JSON.parse(mcpTextValue(response)).evidence,
|
||||
);
|
||||
const mcpEvidence = parseEvidence(JSON.parse(mcpTextValue(response)));
|
||||
const mcpResult = assertTrace(mcpEvidence, oracle, site, scriptIndex);
|
||||
assert.deepEqual(mcpResult, cliResult, "CLI and MCP module traces differ");
|
||||
assert.equal(
|
||||
@@ -143,7 +141,7 @@ export async function verifyBrowserModules(
|
||||
},
|
||||
}),
|
||||
),
|
||||
).evidence,
|
||||
),
|
||||
);
|
||||
const result = webModuleTraceResultSchema.parse(
|
||||
withoutMap.normalized_result,
|
||||
@@ -236,7 +234,7 @@ export async function verifyBrowserModules(
|
||||
},
|
||||
});
|
||||
assert.notEqual(response.isError, true, mcpTextValue(response));
|
||||
evidence = parseEvidence(JSON.parse(mcpTextValue(response)).evidence);
|
||||
evidence = parseEvidence(JSON.parse(mcpTextValue(response)));
|
||||
}
|
||||
const result = webModuleTraceResultSchema.parse(
|
||||
evidence.normalized_result,
|
||||
|
||||
@@ -112,10 +112,7 @@ export async function verifyBrowserNetworkEvidence(
|
||||
{ timeout: 60_000 },
|
||||
);
|
||||
assert.notEqual(result.isError, true, JSON.stringify(result));
|
||||
const evidence = parseEvidence({
|
||||
...result.structuredContent?.evidence,
|
||||
normalized_result: result.structuredContent?.result,
|
||||
});
|
||||
const evidence = parseEvidence(result.structuredContent);
|
||||
mcpProof = assertBrowserNetworkEvidence(
|
||||
browserScenarioCaptureSchema.parse(evidence.normalized_result),
|
||||
site.origin,
|
||||
@@ -130,10 +127,7 @@ export async function verifyBrowserNetworkEvidence(
|
||||
{ timeout: 60_000 },
|
||||
);
|
||||
assert.notEqual(connected.isError, true, JSON.stringify(connected));
|
||||
const connectedEvidence = parseEvidence({
|
||||
...connected.structuredContent?.evidence,
|
||||
normalized_result: connected.structuredContent?.result,
|
||||
});
|
||||
const connectedEvidence = parseEvidence(connected.structuredContent);
|
||||
assert.deepEqual(
|
||||
assertBrowserNetworkEvidence(
|
||||
browserScenarioCaptureSchema.parse(
|
||||
|
||||
@@ -8,7 +8,7 @@ import { chromium } from "playwright-core";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
|
||||
import { PlaywrightBrowserScenarioProvider } from "../../dist/browser/PlaywrightBrowserScenarioProvider.js";
|
||||
import { createBrowserScenarioProvider } from "../../dist/composition/browserScenario.js";
|
||||
import { PlaywrightScenarioEvents } from "../../dist/browser/PlaywrightScenarioEvents.js";
|
||||
import { BrowserScenarioSecrets } from "../../dist/browser/BrowserScenarioSecrets.js";
|
||||
import { browserScenarioSchema } from "../../dist/domain/browserScenario.js";
|
||||
@@ -53,9 +53,9 @@ const scenarioFor = (executable, origin, events) =>
|
||||
});
|
||||
|
||||
const capture = async (scenario) => {
|
||||
const result = await new PlaywrightBrowserScenarioProvider().captureScenario(
|
||||
scenario,
|
||||
);
|
||||
const result = await createBrowserScenarioProvider(
|
||||
process.env,
|
||||
).captureScenario(scenario);
|
||||
if (!result.ok) throw result.error;
|
||||
assert.ok(
|
||||
result.value.steps.every((step) => step.status === "completed"),
|
||||
@@ -163,10 +163,7 @@ const verifyTransports = async (executable, origin) => {
|
||||
{ timeout: 60_000 },
|
||||
);
|
||||
assert.notEqual(captured.isError, true, JSON.stringify(captured));
|
||||
const evidence = parseEvidence({
|
||||
...captured.structuredContent?.evidence,
|
||||
normalized_result: captured.structuredContent?.result,
|
||||
});
|
||||
const evidence = parseEvidence(captured.structuredContent);
|
||||
assertNetwork(
|
||||
browserScenarioCaptureSchema.parse(evidence.normalized_result),
|
||||
origin,
|
||||
|
||||
@@ -126,7 +126,7 @@ export async function verifyBrowserRuntime(
|
||||
mcpTextValue(listenerResponse),
|
||||
);
|
||||
const mcpListenerProof = assertListeners(
|
||||
parseEvidence(JSON.parse(mcpTextValue(listenerResponse)).evidence),
|
||||
parseEvidence(JSON.parse(mcpTextValue(listenerResponse))),
|
||||
site,
|
||||
);
|
||||
const mcpProof = await executionMcp(
|
||||
@@ -231,7 +231,7 @@ async function executionMcp(
|
||||
await actionPromise;
|
||||
assert.notEqual(response.isError, true, mcpTextValue(response));
|
||||
return assertExecution(
|
||||
parseEvidence(JSON.parse(mcpTextValue(response)).evidence),
|
||||
parseEvidence(JSON.parse(mcpTextValue(response))),
|
||||
site,
|
||||
requireBlock,
|
||||
);
|
||||
|
||||
@@ -95,10 +95,7 @@ export async function verifyLargeScreenshotE2e(endpoint, origin) {
|
||||
{ timeout: 60000 },
|
||||
);
|
||||
assert.notEqual(captured.isError, true, JSON.stringify(captured));
|
||||
const mcpEvidence = parseEvidence({
|
||||
...captured.structuredContent?.evidence,
|
||||
normalized_result: captured.structuredContent?.result,
|
||||
});
|
||||
const mcpEvidence = parseEvidence(captured.structuredContent);
|
||||
const mcpScreenshot = webScreenshotSchema.parse(
|
||||
mcpEvidence.normalized_result,
|
||||
);
|
||||
|
||||
@@ -69,7 +69,7 @@ export async function verifyBrowserScriptExport(
|
||||
const call = async (name, args) => {
|
||||
const result = await client.callTool({ name, arguments: args });
|
||||
assert.notEqual(result.isError, true, mcpTextValue(result));
|
||||
return parseEvidence(JSON.parse(mcpTextValue(result)).evidence);
|
||||
return parseEvidence(JSON.parse(mcpTextValue(result)));
|
||||
};
|
||||
const mcpCapture = await call("capture_browser_scenario", scenario);
|
||||
const mcpInput = await save("mcp", mcpCapture);
|
||||
|
||||
@@ -184,9 +184,7 @@ async function assertPublicPair(cli, client, oracle) {
|
||||
arguments: input,
|
||||
});
|
||||
assert.notEqual(response.isError, true, mcpTextValue(response));
|
||||
const mcpEvidence = parseEvidence(
|
||||
JSON.parse(mcpTextValue(response)).evidence,
|
||||
);
|
||||
const mcpEvidence = parseEvidence(JSON.parse(mcpTextValue(response)));
|
||||
assert.deepEqual(assertPoint(mcpEvidence, oracle), expected);
|
||||
assert.equal(evidence.parameters.source_map.url, input.source_map.url);
|
||||
return expected;
|
||||
|
||||
@@ -200,7 +200,7 @@ export const providerCatalog = (sources) => {
|
||||
sources.webNetworkCaptureContracts.WEB_NETWORK_CAPTURE_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
identity: sources.browserProvider.CDP_BROWSER_PROVIDER_IDENTITY,
|
||||
identity: sources.browserIdentities.CDP_BROWSER_PROVIDER_IDENTITY,
|
||||
contracts: [
|
||||
...sources.browserContracts.BROWSER_TOOL_CONTRACTS,
|
||||
...sources.webRuntimeContracts.WEB_RUNTIME_TOOL_CONTRACTS,
|
||||
@@ -208,19 +208,17 @@ export const providerCatalog = (sources) => {
|
||||
},
|
||||
{
|
||||
identity:
|
||||
sources.browserScenarioProvider
|
||||
.PLAYWRIGHT_BROWSER_SCENARIO_PROVIDER_IDENTITY,
|
||||
sources.browserIdentities.PLAYWRIGHT_BROWSER_SCENARIO_PROVIDER_IDENTITY,
|
||||
contracts:
|
||||
sources.browserScenarioContracts.BROWSER_SCENARIO_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
identity: sources.electronProvider.CDP_ELECTRON_PROVIDER_IDENTITY,
|
||||
identity: sources.browserIdentities.CDP_ELECTRON_PROVIDER_IDENTITY,
|
||||
contracts: observationContracts,
|
||||
},
|
||||
{
|
||||
identity:
|
||||
sources.electronActiveProvider
|
||||
.PLAYWRIGHT_ELECTRON_ACTIVE_PROVIDER_IDENTITY,
|
||||
sources.browserIdentities.PLAYWRIGHT_ELECTRON_ACTIVE_PROVIDER_IDENTITY,
|
||||
contracts: activeContracts,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -75,10 +75,7 @@ const SOURCE_PATHS = {
|
||||
idaProvider: "dist/ida/IdaProviderCapabilities.js",
|
||||
nativeProvider: "dist/native/NativeMacOSProviderMetadata.js",
|
||||
artifactProviders: "dist/application/InvestigationProviders.js",
|
||||
browserProvider: "dist/browser/CdpBrowserProvider.js",
|
||||
browserScenarioProvider: "dist/browser/PlaywrightBrowserScenarioProvider.js",
|
||||
electronProvider: "dist/browser/CdpElectronProvider.js",
|
||||
electronActiveProvider: "dist/browser/PlaywrightElectronActiveProvider.js",
|
||||
browserIdentities: "dist/browser/providerIdentities.js",
|
||||
v8InspectorProvider: "dist/inspector/V8InspectorProvider.js",
|
||||
evidence: "dist/domain/evidence.js",
|
||||
evidenceBundle: "dist/domain/evidenceBundle.js",
|
||||
|
||||
@@ -11,11 +11,12 @@ export function parseDevelopmentTestRequest(
|
||||
arguments_: readonly string[],
|
||||
): DevelopmentTestRequest;
|
||||
|
||||
/** Plan source feedback or a strict explicit run with its build prerequisite. */
|
||||
/** Plan source feedback or explicit tests with runtime/artifact prerequisites. */
|
||||
export function developmentTestPlan(
|
||||
request: DevelopmentTestRequest,
|
||||
baseCommit?: string,
|
||||
): {
|
||||
readonly needsBuild: boolean;
|
||||
readonly artifactTasks: readonly string[];
|
||||
readonly vitestArguments: readonly string[];
|
||||
};
|
||||
|
||||
@@ -49,7 +49,20 @@ export const parseDevelopmentTestRequest = (mode, arguments_) => {
|
||||
return { mode, paths: [...new Set(paths)], base, dryRun };
|
||||
};
|
||||
|
||||
/** Plan source feedback or a strict explicit run with its build prerequisite. */
|
||||
// Test-only outputs are declared beside the test planner rather than becoming
|
||||
// runtime or typecheck prerequisites. Add a consumer here when it reads one.
|
||||
const artifactConsumers = {
|
||||
"artifacts:mcp-catalog": [
|
||||
"tests/boundary/mcp/contractPresentation.test.ts",
|
||||
"tests/boundary/mcp/toolSchemaValidity.test.ts",
|
||||
],
|
||||
"artifacts:product-catalog": ["tests/boundary/cli/productCatalog.test.ts"],
|
||||
"artifacts:managed-evidence": [
|
||||
"tests/boundary/filesystem/setupSkill.test.ts",
|
||||
],
|
||||
};
|
||||
|
||||
/** Plan source feedback or explicit tests with their runtime/artifact prerequisites. */
|
||||
export const developmentTestPlan = (request, baseCommit) => {
|
||||
const explicit = request.paths.length > 0;
|
||||
if (
|
||||
@@ -60,6 +73,10 @@ export const developmentTestPlan = (request, baseCommit) => {
|
||||
const projects = request.mode === "focused" ? [] : sourceProjects;
|
||||
return {
|
||||
needsBuild: request.paths.some((path) => !sourceTest(path)),
|
||||
artifactTasks: Object.entries(artifactConsumers).flatMap(
|
||||
([task, consumers]) =>
|
||||
request.paths.some((path) => consumers.includes(path)) ? [task] : [],
|
||||
),
|
||||
vitestArguments: [
|
||||
"run",
|
||||
...projects.flatMap((project) => ["--project", project]),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
requireMcpToolError,
|
||||
requireMcpResult,
|
||||
requireMcpLifecycleResult,
|
||||
requireMcpEvidenceResult,
|
||||
} from "./mcp-verifier-results.mjs";
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
@@ -25,7 +26,7 @@ export async function verifyLegacyGhidraReferenceSnapshot(
|
||||
client,
|
||||
{ target, procedure, omittedEdge, entrypoint, env },
|
||||
) {
|
||||
const bundle = requireMcpResult(
|
||||
const bundle = requireMcpLifecycleResult(
|
||||
await client.callTool({
|
||||
name: "get_evidence_bundle",
|
||||
arguments: {},
|
||||
@@ -100,6 +101,7 @@ export async function verifyLegacyGhidraReferenceSnapshot(
|
||||
},
|
||||
}),
|
||||
],
|
||||
workflow_entries: [],
|
||||
evidence_bundle: createEvidenceBundle([evidence]),
|
||||
});
|
||||
assert.equal(
|
||||
@@ -110,7 +112,7 @@ export async function verifyLegacyGhidraReferenceSnapshot(
|
||||
const path = join(env.TMPDIR, `legacy-reference-${randomUUID()}.json`);
|
||||
await writeFile(path, serializeAnalysisSnapshot(snapshot), { flag: "wx" });
|
||||
try {
|
||||
const session = requireMcpResult(
|
||||
const session = requireMcpLifecycleResult(
|
||||
await client.callTool({ name: "binary_session", arguments: {} }),
|
||||
"binary_session",
|
||||
);
|
||||
@@ -131,14 +133,14 @@ export async function verifyLegacyGhidraReferenceSnapshot(
|
||||
/without this snapshot.*fresh snapshot/u,
|
||||
);
|
||||
assert.deepEqual(
|
||||
requireMcpResult(
|
||||
requireMcpLifecycleResult(
|
||||
await client.callTool({ name: "binary_session", arguments: {} }),
|
||||
"binary_session",
|
||||
),
|
||||
session,
|
||||
"A rejected snapshot must preserve the selected session",
|
||||
);
|
||||
const retained = requireMcpResult(
|
||||
const retained = requireMcpEvidenceResult(
|
||||
await client.callTool({
|
||||
name: "analyze_function",
|
||||
arguments: { procedure },
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { analysisErrorProjectionSchema } from "../../dist/contracts/errorSchemas.js";
|
||||
import { toolContract } from "../../dist/contracts/toolContracts.js";
|
||||
|
||||
/** Read the textual JSON projection from one MCP tool call. */
|
||||
export const mcpTextValue = (result) => {
|
||||
@@ -15,25 +16,58 @@ export const requireMcpToolError = (result) => {
|
||||
return analysisErrorProjectionSchema.parse(jsonValue(result).error);
|
||||
};
|
||||
|
||||
/** Return the compact result projection from one successful MCP tool call. */
|
||||
export const requireMcpResult = (result, operation) => {
|
||||
if (result.isError === true) {
|
||||
const requireOutput = (result, operation, contract) => {
|
||||
if (result.isError === true)
|
||||
throw new Error(`${operation} failed: ${mcpTextValue(result)}`);
|
||||
}
|
||||
const value = jsonValue(result);
|
||||
if (value === null || typeof value !== "object" || !("result" in value)) {
|
||||
throw new Error(`${operation} omitted its result projection`);
|
||||
}
|
||||
return value.result;
|
||||
if (contract.name !== operation)
|
||||
throw new Error(`${operation} received the ${contract.name} contract`);
|
||||
return contract.outputSchema.parse(jsonValue(result));
|
||||
};
|
||||
|
||||
const operationResultKey = (contract) => {
|
||||
const shape = contract.outputSchema.shape;
|
||||
if (shape === undefined)
|
||||
throw new Error(`${contract.name} has an unsupported MCP output schema`);
|
||||
const evidence = Object.hasOwn(shape, "normalized_result");
|
||||
const lifecycle = Object.hasOwn(shape, "result");
|
||||
if (evidence === lifecycle)
|
||||
throw new Error(`${contract.name} has an unsupported MCP output schema`);
|
||||
return evidence ? "normalized_result" : "result";
|
||||
};
|
||||
|
||||
/** Validate an Evidence-producing tool output and return its normalized result. */
|
||||
export const requireMcpEvidenceResult = (result, operation) => {
|
||||
const contract = toolContract(operation);
|
||||
if (operationResultKey(contract) !== "normalized_result")
|
||||
throw new Error(`${operation} requires the lifecycle result extractor`);
|
||||
return requireOutput(result, operation, contract).normalized_result;
|
||||
};
|
||||
|
||||
/** Validate a lifecycle tool output and return its operation result. */
|
||||
export const requireMcpLifecycleResult = (result, operation) => {
|
||||
const contract = toolContract(operation);
|
||||
if (operationResultKey(contract) !== "result")
|
||||
throw new Error(`${operation} requires the Evidence result extractor`);
|
||||
return requireOutput(result, operation, contract).result;
|
||||
};
|
||||
|
||||
/** Project a mixed verifier call using its exact named canonical output schema. */
|
||||
export const requireMcpOperationResult = (
|
||||
result,
|
||||
operation,
|
||||
contract = toolContract(operation),
|
||||
) => {
|
||||
const key = operationResultKey(contract);
|
||||
return requireOutput(result, operation, contract)[key];
|
||||
};
|
||||
|
||||
/** Verify provider identity directly from the tool result. */
|
||||
export const requireEvidenceProvider = (result, operation, providerId) => {
|
||||
const evidence = jsonValue(result);
|
||||
if (
|
||||
evidence?.evidence?.provider?.id !== providerId ||
|
||||
evidence?.evidence?.analysis_profile?.provider?.id !== providerId ||
|
||||
typeof evidence.evidence.analysis_profile.provider.version !== "string"
|
||||
evidence?.provider?.id !== providerId ||
|
||||
evidence?.analysis_profile?.provider?.id !== providerId ||
|
||||
typeof evidence.analysis_profile.provider.version !== "string"
|
||||
) {
|
||||
throw new Error(`${operation} omitted its concrete provider provenance`);
|
||||
}
|
||||
@@ -46,10 +80,10 @@ export const requireWorkflowEvidenceProvider = (
|
||||
expected,
|
||||
) => {
|
||||
const evidence = jsonValue(result);
|
||||
const profile = evidence?.evidence?.analysis_profile;
|
||||
const profile = evidence?.analysis_profile;
|
||||
const upstream = profile?.parameters?.upstream_analysis_profile;
|
||||
if (
|
||||
evidence?.evidence?.provider?.id !== expected.workflowProviderId ||
|
||||
evidence?.provider?.id !== expected.workflowProviderId ||
|
||||
profile?.provider?.id !== expected.workflowProviderId ||
|
||||
upstream?.provider?.id !== expected.upstreamProviderId ||
|
||||
typeof upstream.provider.version !== "string"
|
||||
|
||||
@@ -14,14 +14,6 @@ const MIGRATED_PROVIDER_ROOTS = new Set([
|
||||
"inspector",
|
||||
"javascript",
|
||||
]);
|
||||
const PROVIDER_ROOTS = new Set([
|
||||
...MIGRATED_PROVIDER_ROOTS,
|
||||
"artifacts",
|
||||
"browser",
|
||||
"dotnet",
|
||||
"native",
|
||||
]);
|
||||
|
||||
const repositoryPath = (root, path) =>
|
||||
relative(root, path).replaceAll("\\", "/");
|
||||
|
||||
@@ -88,11 +80,6 @@ const failedBoundary = (file, target) => {
|
||||
/^src\/(?:cli|main)\./u.test(target))
|
||||
)
|
||||
return "artifact-acquisition";
|
||||
if (
|
||||
PROVIDER_ROOTS.has(layer) &&
|
||||
/^src\/generatedMcpToolCatalog\.(?:js|ts)$/u.test(target)
|
||||
)
|
||||
return "provider-generated-catalog";
|
||||
if (PURE_LAYERS.has(layer)) {
|
||||
if (
|
||||
(/^src\/[^/]+\//u.test(target) && !PURE_LAYERS.has(targetLayer)) ||
|
||||
|
||||
@@ -179,12 +179,12 @@ async function verifyNativeValueAdapters(
|
||||
{ timeout: 180000 },
|
||||
);
|
||||
assert.notEqual(result.isError, true, JSON.stringify(result));
|
||||
const mcpEvidence = parseEvidence(result.structuredContent?.evidence);
|
||||
const mcpEvidence = parseEvidence(result.structuredContent);
|
||||
assert.equal(mcpEvidence.operation, "trace_native_values");
|
||||
assert.equal(mcpEvidence.provider.id, "rea-workflow");
|
||||
assert.deepEqual(mcpEvidence.analysis_profile, workflowProfile);
|
||||
const mcpGraph = verifyGraph(
|
||||
result.structuredContent?.result,
|
||||
result.structuredContent?.normalized_result,
|
||||
target,
|
||||
procedure,
|
||||
globalAddress,
|
||||
@@ -196,9 +196,7 @@ async function verifyNativeValueAdapters(
|
||||
{ timeout: 180000 },
|
||||
);
|
||||
assert.notEqual(analyzed.isError, true, JSON.stringify(analyzed));
|
||||
const functionEvidence = parseEvidence(
|
||||
analyzed.structuredContent?.evidence,
|
||||
);
|
||||
const functionEvidence = parseEvidence(analyzed.structuredContent);
|
||||
assert.equal(functionEvidence.operation, "analyze_function");
|
||||
assert.equal(functionEvidence.provider.id, "ghidra");
|
||||
const functionProfile = analysisProfileSchema.parse(
|
||||
@@ -207,26 +205,24 @@ async function verifyNativeValueAdapters(
|
||||
assert.deepEqual(functionProfile, upstreamProfile);
|
||||
assert.deepEqual(
|
||||
functionEvidence.normalized_result,
|
||||
analyzed.structuredContent?.result,
|
||||
analyzed.structuredContent?.normalized_result,
|
||||
);
|
||||
const comparison = await client.callTool(
|
||||
{
|
||||
name: "compare_functions",
|
||||
arguments: {
|
||||
left: analyzed.structuredContent.evidence,
|
||||
right: analyzed.structuredContent.evidence,
|
||||
left: analyzed.structuredContent,
|
||||
right: analyzed.structuredContent,
|
||||
},
|
||||
},
|
||||
{ timeout: 180000 },
|
||||
);
|
||||
assert.notEqual(comparison.isError, true, JSON.stringify(comparison));
|
||||
const comparisonEvidence = parseEvidence(
|
||||
comparison.structuredContent?.evidence,
|
||||
);
|
||||
const comparisonEvidence = parseEvidence(comparison.structuredContent);
|
||||
assert.equal(comparisonEvidence.normalized_result.status, "unchanged");
|
||||
assert.deepEqual(
|
||||
comparisonEvidence.normalized_result,
|
||||
comparison.structuredContent?.result,
|
||||
comparison.structuredContent?.normalized_result,
|
||||
);
|
||||
assert.ok(
|
||||
comparisonEvidence.evidence_links.includes(functionEvidence.evidence_id),
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function verifyGhidraAddressBoundaries(client, entry, cli) {
|
||||
{ timeout: 240000 },
|
||||
);
|
||||
assert.notEqual(reply.isError, true, JSON.stringify(reply));
|
||||
return reply.structuredContent.result;
|
||||
return reply.structuredContent.normalized_result;
|
||||
};
|
||||
const before = await query("analyze_function", { procedure: entry });
|
||||
// The segmented parser used to discard the high 32 bits and alias this entry.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
requireMcpToolError,
|
||||
mcpTextValue,
|
||||
requireMcpResult,
|
||||
requireMcpOperationResult,
|
||||
} from "./mcp-verifier-results.mjs";
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
@@ -13,6 +13,8 @@ import { promisify } from "node:util";
|
||||
import Ajv from "ajv/dist/2020.js";
|
||||
import addFormats from "ajv-formats";
|
||||
|
||||
import { analysisErrorProjectionSchema } from "../../dist/contracts/errorSchemas.js";
|
||||
|
||||
import { verifyLegacyGhidraReferenceSnapshot } from "./ghidra-reference-snapshot-e2e.mjs";
|
||||
import { verifyGhidraSnapshotLifecycle } from "./real-ghidra-snapshot-lifecycle.mjs";
|
||||
import { verifyGhidraTargetAdmission } from "./real-ghidra-target-admission.mjs";
|
||||
@@ -44,7 +46,7 @@ export async function verifyGhidraBoundaries(
|
||||
let rejectedCalls = 0;
|
||||
const call = async (name, args = {}) => {
|
||||
const reply = await client.callTool({ name, arguments: args }, options);
|
||||
const result = requireMcpResult(reply, name);
|
||||
const result = requireMcpOperationResult(reply, name);
|
||||
const validate = validators.get(name);
|
||||
assert.ok(validate, `${name} missing from catalog`);
|
||||
assert.ok(
|
||||
|
||||
@@ -161,6 +161,7 @@ export async function verifyGhidraNamespaceAnnotations({
|
||||
|
||||
async function requireNamespaceDemangler(env) {
|
||||
const inspection = inspectGhidraInstallation({
|
||||
environment: process.env,
|
||||
installDir: env.GHIDRA_INSTALL_DIR,
|
||||
...(env.JAVA_HOME === undefined ? {} : { javaHome: env.JAVA_HOME }),
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
requireMcpToolError,
|
||||
requireMcpResult,
|
||||
requireMcpOperationResult,
|
||||
} from "./mcp-verifier-results.mjs";
|
||||
import assert from "node:assert/strict";
|
||||
import { access, mkdtemp, readFile, rm } from "node:fs/promises";
|
||||
@@ -20,7 +20,7 @@ export async function verifyGhidraSnapshotLifecycle(
|
||||
let successfulCalls = 0;
|
||||
let rejectedCalls = 0;
|
||||
const call = async (name, args = {}) => {
|
||||
const result = requireMcpResult(
|
||||
const result = requireMcpOperationResult(
|
||||
await client.callTool({ name, arguments: args }, { timeout: 180000 }),
|
||||
name,
|
||||
);
|
||||
|
||||
@@ -6,7 +6,12 @@ import { basename, join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import Ajv from "ajv/dist/2020.js";
|
||||
import addFormats from "ajv-formats";
|
||||
import { mcpTextValue, requireMcpResult } from "./mcp-verifier-results.mjs";
|
||||
import {
|
||||
mcpTextValue,
|
||||
requireMcpEvidenceResult,
|
||||
requireMcpOperationResult,
|
||||
requireMcpLifecycleResult,
|
||||
} from "./mcp-verifier-results.mjs";
|
||||
import { verifyHopperCliSelectors } from "./real-hopper-cli-selectors.mjs";
|
||||
import { verifyLinuxHopperLaunchIsolation } from "./real-hopper-session-isolation.mjs";
|
||||
import { verifyHopperNavigationAndText } from "./real-hopper-navigation.mjs";
|
||||
@@ -44,7 +49,7 @@ export async function verifyHopperBoundaryContracts(
|
||||
const rejectedOperations = new Set();
|
||||
const call = async (name, args = {}) => {
|
||||
const reply = await client.callTool({ name, arguments: args }, options);
|
||||
const result = requireMcpResult(reply, name);
|
||||
const result = requireMcpOperationResult(reply, name);
|
||||
const validate = validators.get(name);
|
||||
assert.ok(validate, `${name} is missing from tools/list`);
|
||||
assert.ok(
|
||||
@@ -301,7 +306,7 @@ export async function verifyHopperLifecycleAndCli(client, options, targets) {
|
||||
const primary = join(directory, `primary-${suffix}`);
|
||||
const secondary = join(directory, `secondary-${suffix}`);
|
||||
const call = async (name, args = {}) =>
|
||||
requireMcpResult(
|
||||
requireMcpOperationResult(
|
||||
await client.callTool({ name, arguments: args }, options),
|
||||
name,
|
||||
);
|
||||
@@ -508,14 +513,14 @@ const verifyBatchCancellation = async (client, options, procedures) => {
|
||||
/aborted/u,
|
||||
);
|
||||
assert.ok(cancelled, "cancellation did not follow a real Hopper response");
|
||||
const recovered = requireMcpResult(
|
||||
const recovered = requireMcpEvidenceResult(
|
||||
await client.callTool({ name: "list_procedures", arguments: {} }, options),
|
||||
"list_procedures after cancellation",
|
||||
"list_procedures",
|
||||
);
|
||||
assert.deepEqual(recovered, procedures);
|
||||
const status = requireMcpResult(
|
||||
const status = requireMcpLifecycleResult(
|
||||
await client.callTool({ name: "binary_session", arguments: {} }, options),
|
||||
"binary_session after cancellation",
|
||||
"binary_session",
|
||||
);
|
||||
assert.equal(status.provider_operation_health.state, "idle");
|
||||
};
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { requireMcpResult } from "./mcp-verifier-results.mjs";
|
||||
import { requireMcpEvidenceResult } from "./mcp-verifier-results.mjs";
|
||||
|
||||
export const verifyHopperFunctionBasics = async (
|
||||
client,
|
||||
options,
|
||||
procedure,
|
||||
) => {
|
||||
const containment = requireMcpResult(
|
||||
const containment = requireMcpEvidenceResult(
|
||||
await client.callTool(
|
||||
{
|
||||
name: "resolve_containing_procedure",
|
||||
@@ -25,7 +25,7 @@ export const verifyHopperFunctionBasics = async (
|
||||
);
|
||||
}
|
||||
|
||||
const references = requireMcpResult(
|
||||
const references = requireMcpEvidenceResult(
|
||||
await client.callTool(
|
||||
{
|
||||
name: "procedure_references",
|
||||
@@ -42,7 +42,7 @@ export const verifyHopperFunctionBasics = async (
|
||||
throw new Error("procedure_references returned an invalid result");
|
||||
}
|
||||
|
||||
const instructions = requireMcpResult(
|
||||
const instructions = requireMcpEvidenceResult(
|
||||
await client.callTool(
|
||||
{
|
||||
name: "read_function_instructions",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { HOPPER_PROVIDER_IDENTITY } from "../../dist/hopper/HopperProvider.js";
|
||||
import {
|
||||
requireMcpResult,
|
||||
requireMcpEvidenceResult,
|
||||
requireEvidenceProvider,
|
||||
} from "./mcp-verifier-results.mjs";
|
||||
|
||||
@@ -13,7 +13,7 @@ export async function verifyHopperInventories(client, options) {
|
||||
{ name: operation, arguments: {} },
|
||||
options,
|
||||
);
|
||||
const inventory = requireMcpResult(called, operation);
|
||||
const inventory = requireMcpEvidenceResult(called, operation);
|
||||
requireEvidenceProvider(called, operation, HOPPER_PROVIDER_IDENTITY.id);
|
||||
assert.ok(
|
||||
Array.isArray(inventory) && inventory.length > 0,
|
||||
@@ -30,7 +30,7 @@ export async function verifyHopperInventories(client, options) {
|
||||
);
|
||||
previous = address;
|
||||
}
|
||||
const filtered = requireMcpResult(
|
||||
const filtered = requireMcpEvidenceResult(
|
||||
await client.callTool(
|
||||
{
|
||||
name: operation,
|
||||
|
||||
@@ -107,7 +107,7 @@ export async function verifyRealHopperFixture({
|
||||
},
|
||||
options,
|
||||
),
|
||||
"set_comment fixture marker",
|
||||
"set_comment",
|
||||
);
|
||||
if (commentSet !== true)
|
||||
throw new Error("Hopper did not read back the fixture comment marker");
|
||||
@@ -138,7 +138,7 @@ export async function verifyRealHopperFixture({
|
||||
},
|
||||
options,
|
||||
),
|
||||
"procedure_references native calls",
|
||||
"procedure_references",
|
||||
);
|
||||
assert.deepEqual(entryDossier.unresolved_calls, observed.unresolved_calls);
|
||||
for (const call of calls) {
|
||||
@@ -266,7 +266,7 @@ export async function resolveFixtureProcedure(
|
||||
},
|
||||
options,
|
||||
),
|
||||
`search_procedures ${expectedName}`,
|
||||
"search_procedures",
|
||||
);
|
||||
const exactMatches = Array.isArray(matches)
|
||||
? matches.filter(
|
||||
@@ -301,5 +301,5 @@ export const analyzeFixtureProcedure = async (
|
||||
},
|
||||
options,
|
||||
),
|
||||
`analyze_function ${procedure.name}`,
|
||||
"analyze_function",
|
||||
);
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { createHash } from "node:crypto";
|
||||
import { join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { setTimeout as delay } from "node:timers/promises";
|
||||
|
||||
/** Exercise owned Windows stdin through its production Writable and native boundary. */
|
||||
export async function verifyWindowsProtocolInput(packageRoot, workspace) {
|
||||
const { WindowsOwnedProcess } = await import(
|
||||
pathToFileURL(join(packageRoot, "dist/windows/WindowsOwnedProcess.js"))
|
||||
);
|
||||
const { requireWindowsNativeAuthority } = await import(
|
||||
pathToFileURL(join(packageRoot, "dist/windows/WindowsNativeLoader.js"))
|
||||
);
|
||||
const native = requireWindowsNativeAuthority();
|
||||
assert.equal(native.inspection.protocolStdin, true);
|
||||
const launch = (script) => acquire(WindowsOwnedProcess, workspace, script);
|
||||
const echo = await verifyEcho(launch);
|
||||
const cancellation = await verifyBlockedCancellation(launch);
|
||||
await verifyNativePendingWrite(native, workspace);
|
||||
const { JadxMcpTransport } = await import(
|
||||
pathToFileURL(join(packageRoot, "dist/android/JadxMcpTransport.js"))
|
||||
);
|
||||
await verifyTransportPendingWrite(JadxMcpTransport, workspace);
|
||||
return {
|
||||
echo,
|
||||
cancellation,
|
||||
native_pending_write_closed: true,
|
||||
forged_input_handle_rejected: true,
|
||||
malformed_input_rejected: true,
|
||||
provider_transport_pending_write_cancelled: true,
|
||||
};
|
||||
}
|
||||
|
||||
function acquire(Process, workspace, script) {
|
||||
const child = new Process(
|
||||
process.execPath,
|
||||
["-e", script],
|
||||
workspace,
|
||||
process.env,
|
||||
false,
|
||||
true,
|
||||
);
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
child.stdout.on("data", (bytes) => {
|
||||
stdout += bytes.toString();
|
||||
});
|
||||
child.stderr.on("data", (bytes) => {
|
||||
stderr += bytes.toString();
|
||||
});
|
||||
const inputErrors = [];
|
||||
child.stdin.on("error", (cause) => inputErrors.push(cause.message));
|
||||
const closed = new Promise((resolve, reject) => {
|
||||
child.once("error", reject);
|
||||
child.once("close", (code) => resolve({ code, stdout, stderr }));
|
||||
});
|
||||
return { child, closed, inputErrors, stdout: () => stdout };
|
||||
}
|
||||
|
||||
async function verifyEcho(launch) {
|
||||
const acquired = launch(`
|
||||
const {createHash} = require('node:crypto');
|
||||
const hash = createHash('sha256'); let count = 0;
|
||||
process.stdin.on('data', bytes => { hash.update(bytes); count += bytes.length; });
|
||||
process.stdin.pause(); setTimeout(() => process.stdin.resume(), 250);
|
||||
process.stdin.on('end', () => console.log(JSON.stringify({count,sha256:hash.digest('hex')})));
|
||||
`);
|
||||
const bytes = Buffer.from(
|
||||
"caller-selected UTF8: 路径 Ω; binary:\0\n".repeat(60000),
|
||||
);
|
||||
const expected = {
|
||||
count: bytes.length,
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
};
|
||||
let ticks = 0;
|
||||
const timer = setInterval(() => ticks++, 20);
|
||||
try {
|
||||
let writable;
|
||||
await new Promise((resolve, reject) => {
|
||||
writable = acquired.child.stdin.write(bytes, (cause) =>
|
||||
cause ? reject(cause) : resolve(),
|
||||
);
|
||||
// The native worker owns its copy before returning to the caller.
|
||||
bytes.fill(0x5a);
|
||||
});
|
||||
assert.equal(
|
||||
writable,
|
||||
false,
|
||||
"Large protocol input did not expose backpressure",
|
||||
);
|
||||
assert.ok(ticks > 0, "Input write blocked the JS event loop");
|
||||
acquired.child.stdin.end();
|
||||
const result = await deadline(acquired.closed);
|
||||
assert.equal(result.code, 0, result.stderr);
|
||||
assert.deepEqual(JSON.parse(result.stdout), expected);
|
||||
assert.deepEqual(acquired.inputErrors, []);
|
||||
assert.equal((await acquired.child.cleanup()).cleaned, true);
|
||||
return {
|
||||
bytes: expected.count,
|
||||
sha256: expected.sha256,
|
||||
backpressure: true,
|
||||
event_loop_responsive: true,
|
||||
eof_observed: true,
|
||||
};
|
||||
} finally {
|
||||
clearInterval(timer);
|
||||
await acquired.child.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
async function verifyBlockedCancellation(launch) {
|
||||
const acquired = launch(`
|
||||
const {spawn} = require('node:child_process');
|
||||
const child = spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], {stdio:'inherit'});
|
||||
console.log('owned descendant ' + child.pid);
|
||||
setInterval(() => {}, 1000);
|
||||
`);
|
||||
try {
|
||||
for (
|
||||
let attempt = 0;
|
||||
attempt < 100 && !acquired.stdout().includes("owned descendant");
|
||||
attempt++
|
||||
)
|
||||
await delay(25);
|
||||
assert.match(acquired.stdout(), /owned descendant \d+/u);
|
||||
const write = new Promise((resolve) =>
|
||||
acquired.child.stdin.write(Buffer.alloc(2 * 1024 * 1024), (cause) =>
|
||||
resolve(cause),
|
||||
),
|
||||
);
|
||||
await delay(100);
|
||||
const cleanup = await acquired.child.cleanup();
|
||||
assert.equal(cleanup.cleaned, true, cleanup.reason);
|
||||
assert.ok(
|
||||
await deadline(write),
|
||||
"Closing the owned job reported a successful blocked write",
|
||||
);
|
||||
await deadline(acquired.closed);
|
||||
return { blocked_write_cancelled: true, descendant_job_settled: true };
|
||||
} finally {
|
||||
await acquired.child.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
async function verifyNativePendingWrite(native, workspace) {
|
||||
const quote = (value) =>
|
||||
`"${value.replace(/(\\*)"/gu, '$1$1\\"').replace(/(\\+)$/u, "$1$1")}"`;
|
||||
const child = native.call("process_spawn", [
|
||||
process.execPath,
|
||||
[process.execPath, "-e", "setInterval(() => {}, 1000)"]
|
||||
.map(quote)
|
||||
.join(" "),
|
||||
workspace,
|
||||
Object.entries(process.env)
|
||||
.filter(([, value]) => value !== undefined)
|
||||
.map(([key, value]) => `${key}=${value}`),
|
||||
true,
|
||||
]);
|
||||
let rejected;
|
||||
try {
|
||||
assert.throws(
|
||||
() => native.call("process_stdin_write", [child.handle, "not a Buffer"]),
|
||||
/must be a Buffer/u,
|
||||
);
|
||||
const pending = native.call("process_stdin_write", [
|
||||
child.handle,
|
||||
Buffer.alloc(2 * 1024 * 1024),
|
||||
]);
|
||||
rejected = pending.then(
|
||||
() => false,
|
||||
(cause) => cause,
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
native.call("process_stdin_write", [
|
||||
child.handle,
|
||||
Buffer.from("second"),
|
||||
]),
|
||||
/pending write/u,
|
||||
);
|
||||
assert.throws(
|
||||
() => native.call("process_stdin_write", [{}, Buffer.from("forged")]),
|
||||
/does not belong to REA/u,
|
||||
);
|
||||
} finally {
|
||||
// The worker retains its handle/buffer after the JS resource closes.
|
||||
native.call("process_close", [child.handle]);
|
||||
}
|
||||
const failure = await deadline(rejected);
|
||||
assert.ok(failure instanceof Error);
|
||||
assert.match(failure.message, /Write owned process input failed/u);
|
||||
}
|
||||
|
||||
async function verifyTransportPendingWrite(Transport, workspace) {
|
||||
const transport = new Transport({
|
||||
command: process.execPath,
|
||||
arguments: ["-e", "setInterval(() => {}, 1000)"],
|
||||
cwd: workspace,
|
||||
});
|
||||
transport.onerror = () => {};
|
||||
try {
|
||||
await transport.start();
|
||||
const pending = transport
|
||||
.send({
|
||||
jsonrpc: "2.0",
|
||||
id: "blocked",
|
||||
method: "probe",
|
||||
params: { payload: "x".repeat(2 * 1024 * 1024) },
|
||||
})
|
||||
.then(
|
||||
() => false,
|
||||
(cause) => cause,
|
||||
);
|
||||
await delay(100);
|
||||
await transport.close();
|
||||
assert.ok(
|
||||
await deadline(pending),
|
||||
"Transport cancellation accepted a blocked write",
|
||||
);
|
||||
} finally {
|
||||
await transport.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function deadline(promise) {
|
||||
let timer;
|
||||
return Promise.race([
|
||||
promise,
|
||||
new Promise((_, reject) => {
|
||||
timer = setTimeout(
|
||||
() => reject(new Error("Owned input fixture exceeded its deadline")),
|
||||
10000,
|
||||
);
|
||||
}),
|
||||
]).finally(() => clearTimeout(timer));
|
||||
}
|
||||
Reference in New Issue
Block a user