chore: integrate canonical Evidence changes for MCP error delivery
This commit is contained in:
@@ -4,7 +4,4 @@ import { fileURLToPath } from "node:url";
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
|
||||
await Promise.all([
|
||||
rm(join(root, "dist"), { recursive: true, force: true }),
|
||||
rm(join(root, ".cache", "tsconfig.build.tsbuildinfo"), { force: true }),
|
||||
]);
|
||||
await rm(join(root, "dist"), { recursive: true, force: true });
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { mkdir } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { formatGeneratedFile } from "./lib/format-generated-file.mjs";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { McpServer } from "@modelcontextprotocol/server";
|
||||
|
||||
import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js";
|
||||
import { MANAGED_WORKFLOW_TOOL_CONTRACTS } from "../dist/contracts/managed/managedWorkflowToolContracts.js";
|
||||
import { auxiliaryAnalysisProviderDeclarations } from "../dist/composition/auxiliaryAnalysisProviders.js";
|
||||
import { toolRegistrationOptions } from "../dist/server/toolRegistrationOptions.js";
|
||||
import { ensureGeneratedFile } from "./lib/generated-file.mjs";
|
||||
|
||||
@@ -17,10 +16,9 @@ for (const argument of arguments_)
|
||||
throw new Error(`Unknown MCP tool catalog option: ${argument}`);
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
// This build-generated source supports schema and provider conformance tests;
|
||||
// This generated metadata supports schema conformance tests;
|
||||
// production MCP tools are registered from their canonical contracts directly.
|
||||
// Keep the test metadata portable and regenerate it with `npm run build`.
|
||||
const CATALOG_PLATFORM = "darwin";
|
||||
// Keep the test metadata portable and regenerate it with `npm run mcp-catalog:generate`.
|
||||
const sessionToolNames = new Set([
|
||||
...TOOL_CONTRACTS.filter(({ kind }) => kind === "session").map(
|
||||
({ name }) => name,
|
||||
@@ -87,10 +85,6 @@ async function sdkToolCatalog() {
|
||||
await Promise.allSettled([client.close(), server.close()]);
|
||||
}
|
||||
}
|
||||
const auxiliaryProviders = auxiliaryAnalysisProviderDeclarations(
|
||||
CATALOG_PLATFORM,
|
||||
).map(({ identity, capabilities }) => ({ identity, capabilities }));
|
||||
|
||||
const canonicalizeJson = (value) => {
|
||||
if (Array.isArray(value)) return value.map(canonicalizeJson);
|
||||
if (value === null || typeof value !== "object") return value;
|
||||
@@ -101,101 +95,13 @@ const canonicalizeJson = (value) => {
|
||||
);
|
||||
};
|
||||
|
||||
const payloadJson = JSON.stringify(
|
||||
canonicalizeJson({ catalog, auxiliaryProviders }),
|
||||
null,
|
||||
2,
|
||||
);
|
||||
const source = await formatGeneratedFile(
|
||||
"src/generatedMcpToolCatalog.ts",
|
||||
`import type { ToolAnnotations } from "@modelcontextprotocol/server";
|
||||
import type {
|
||||
CapabilityDescriptor,
|
||||
ProviderIdentity,
|
||||
} from "./application/AnalysisProvider.js";
|
||||
import type { ToolKind } from "./contracts/toolContractTypes.js";
|
||||
import type { ToolEffects } from "./contracts/toolEffects.js";
|
||||
|
||||
interface GeneratedTool {
|
||||
readonly name: string;
|
||||
readonly analysisOperation: CapabilityDescriptor["operation"] | null;
|
||||
readonly title: string;
|
||||
readonly description: string;
|
||||
readonly kind: ToolKind;
|
||||
readonly requiresSession: boolean;
|
||||
readonly inputSchema: Readonly<Record<string, unknown>>;
|
||||
readonly outputSchema: Readonly<Record<string, unknown>>;
|
||||
readonly annotations: ToolAnnotations;
|
||||
readonly effects: ToolEffects;
|
||||
}
|
||||
|
||||
interface GeneratedProvider {
|
||||
readonly identity: ProviderIdentity;
|
||||
readonly capabilities: readonly CapabilityDescriptor[];
|
||||
}
|
||||
|
||||
interface GeneratedPayload {
|
||||
readonly catalog: readonly GeneratedTool[];
|
||||
readonly auxiliaryProviders: readonly GeneratedProvider[];
|
||||
}
|
||||
|
||||
const GENERATED_PAYLOAD_JSON = ${JSON.stringify(payloadJson)};
|
||||
const generatedPayload: unknown = JSON.parse(GENERATED_PAYLOAD_JSON);
|
||||
if (!isGeneratedPayload(generatedPayload))
|
||||
throw new TypeError("Generated MCP catalog payload is invalid");
|
||||
|
||||
/** Generated from TOOL_CONTRACTS; do not edit. */
|
||||
export const GENERATED_MCP_TOOL_CATALOG = generatedPayload.catalog;
|
||||
|
||||
/** Generated lightweight metadata for lazily loaded auxiliary providers. */
|
||||
export const GENERATED_AUXILIARY_PROVIDERS = generatedPayload.auxiliaryProviders;
|
||||
|
||||
function isGeneratedPayload(value: unknown): value is GeneratedPayload {
|
||||
return (
|
||||
isRecord(value) &&
|
||||
Array.isArray(value.catalog) &&
|
||||
value.catalog.every(isGeneratedTool) &&
|
||||
Array.isArray(value.auxiliaryProviders) &&
|
||||
value.auxiliaryProviders.every(isGeneratedProvider)
|
||||
);
|
||||
}
|
||||
|
||||
function isGeneratedTool(value: unknown): value is GeneratedTool {
|
||||
return (
|
||||
isRecord(value) &&
|
||||
typeof value.name === "string" &&
|
||||
(typeof value.analysisOperation === "string" ||
|
||||
value.analysisOperation === null) &&
|
||||
typeof value.title === "string" &&
|
||||
typeof value.description === "string" &&
|
||||
typeof value.kind === "string" &&
|
||||
typeof value.requiresSession === "boolean" &&
|
||||
isRecord(value.inputSchema) &&
|
||||
isRecord(value.outputSchema) &&
|
||||
isRecord(value.annotations) &&
|
||||
isRecord(value.effects)
|
||||
);
|
||||
}
|
||||
|
||||
function isGeneratedProvider(value: unknown): value is GeneratedProvider {
|
||||
return (
|
||||
isRecord(value) &&
|
||||
isRecord(value.identity) &&
|
||||
Array.isArray(value.capabilities)
|
||||
);
|
||||
}
|
||||
|
||||
function isRecord(
|
||||
value: unknown,
|
||||
): value is Readonly<Record<string, unknown>> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
`,
|
||||
);
|
||||
|
||||
const payloadJson = JSON.stringify(canonicalizeJson({ catalog }), null, 2);
|
||||
const outputPath = join(root, ".cache/mcp-tool-catalog.json");
|
||||
if (!arguments_.has("--check"))
|
||||
await mkdir(dirname(outputPath), { recursive: true });
|
||||
await ensureGeneratedFile({
|
||||
path: join(root, "src/generatedMcpToolCatalog.ts"),
|
||||
source,
|
||||
path: outputPath,
|
||||
source: `${payloadJson}\n`,
|
||||
check: arguments_.has("--check"),
|
||||
generateCommand: "npm run mcp-catalog:generate",
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
+3
-6
@@ -44,7 +44,6 @@ if (!(await compiledRuntimeExists(runtimeFiles))) {
|
||||
const {
|
||||
renderCliOutputArgumentError,
|
||||
renderEmptyFilteredCliOutput,
|
||||
sanitizeCliOutput,
|
||||
validateCliOutputArguments,
|
||||
} = await import("../dist/cliOutput.js");
|
||||
const outputArguments = validateCliOutputArguments(args);
|
||||
@@ -57,13 +56,11 @@ if (!(await compiledRuntimeExists(runtimeFiles))) {
|
||||
await createCli(process.env, resultOutput).serve(args, {
|
||||
stdout: (output) => {
|
||||
if (resultOutput?.handled) {
|
||||
if (resultOutput.failed)
|
||||
process.stderr.write(sanitizeCliOutput(output));
|
||||
if (resultOutput.failed) process.stderr.write(output);
|
||||
return;
|
||||
}
|
||||
const sanitized = sanitizeCliOutput(output);
|
||||
if (sanitized.length > 0) wroteOutput = true;
|
||||
process.stdout.write(sanitized);
|
||||
if (output.length > 0) wroteOutput = true;
|
||||
process.stdout.write(output);
|
||||
},
|
||||
});
|
||||
if (!wroteOutput && !resultOutput?.handled)
|
||||
|
||||
@@ -47,15 +47,24 @@ try {
|
||||
? `Focused tests: ${request.paths.join(", ")}`
|
||||
: `Source-test feedback${baseCommit ? ` from merge base ${baseCommit}` : ""}; compiled boundaries and real providers need explicit verification.`,
|
||||
);
|
||||
if (plan.needsBuild) {
|
||||
if (!process.env.npm_execpath)
|
||||
throw new Error("Run compiled tests through npm run test:focused");
|
||||
const built = await run(process.execPath, [
|
||||
process.env.npm_execpath,
|
||||
"run",
|
||||
"build:cached",
|
||||
if (plan.needsBuild || plan.artifactTasks.length > 0) {
|
||||
const dependencies = await run(process.execPath, [
|
||||
"scripts/check-dependency-install.mjs",
|
||||
]);
|
||||
if (built.code !== 0) process.exitCode = built.code;
|
||||
if (dependencies.code !== 0)
|
||||
throw new Error(
|
||||
"Test prerequisites require the locked dependency installation",
|
||||
);
|
||||
const prepared = await run(process.execPath, [
|
||||
"scripts/run-exclusive.mjs",
|
||||
"artifacts",
|
||||
process.execPath,
|
||||
resolve("node_modules/turbo/bin/turbo"),
|
||||
"run",
|
||||
...(plan.needsBuild ? ["artifacts:skills"] : []),
|
||||
...plan.artifactTasks,
|
||||
]);
|
||||
if (prepared.code !== 0) process.exitCode = prepared.code;
|
||||
}
|
||||
if (!process.exitCode && !shutdownSignal) {
|
||||
const tested = await run(process.execPath, [
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { spawn } from "node:child_process";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { DatabaseSync } from "node:sqlite";
|
||||
|
||||
const [, , lockName, ...command] = process.argv;
|
||||
const lockRoot = resolve(process.cwd(), ".cache", "rea-command-locks");
|
||||
const signalExitCodes = { SIGINT: 130, SIGTERM: 143 };
|
||||
|
||||
let database;
|
||||
let child;
|
||||
let forceTimer;
|
||||
let shutdownSignal;
|
||||
|
||||
process.on("SIGINT", () => handleSignal("SIGINT"));
|
||||
process.on("SIGTERM", () => handleSignal("SIGTERM"));
|
||||
process.on("disconnect", handleDisconnect);
|
||||
process.on("message", (message) => {
|
||||
if (message === "SIGINT" || message === "SIGTERM") handleSignal(message);
|
||||
});
|
||||
|
||||
if (!process.connected) {
|
||||
// The public wrapper can disappear before ESM startup installs listeners.
|
||||
// A disconnected supervisor has no authority to start a new command.
|
||||
process.exitCode = signalExitCodes.SIGTERM;
|
||||
} else if (
|
||||
typeof lockName !== "string" ||
|
||||
!/^[a-z][a-z0-9-]*$/u.test(lockName) ||
|
||||
command.length === 0
|
||||
) {
|
||||
console.error("Usage: run-exclusive.mjs <lock-name> <command> [args...]");
|
||||
process.exitCode = 64;
|
||||
disconnectParent();
|
||||
} else {
|
||||
await run();
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
await mkdir(lockRoot, { recursive: true });
|
||||
// SQLite owns acquisition and OS-backed lock release, including process
|
||||
// death. Keep the database pathname stable; deleting it would split owners.
|
||||
database = new DatabaseSync(join(lockRoot, `${lockName}.sqlite`));
|
||||
try {
|
||||
database.exec("BEGIN EXCLUSIVE");
|
||||
} catch (cause) {
|
||||
if (isBusyError(cause))
|
||||
throw new Error(
|
||||
`Another ${lockName} command is already running. Wait for it to finish.`,
|
||||
{ cause },
|
||||
);
|
||||
throw cause;
|
||||
}
|
||||
if (shutdownSignal === undefined) {
|
||||
const result = await runCommand();
|
||||
process.exitCode = result.code ?? 1;
|
||||
}
|
||||
} catch (cause) {
|
||||
console.error(cause instanceof Error ? cause.message : String(cause));
|
||||
process.exitCode = 1;
|
||||
} finally {
|
||||
database?.close();
|
||||
clearTimeout(forceTimer);
|
||||
if (shutdownSignal !== undefined)
|
||||
process.exitCode = signalExitCodes[shutdownSignal];
|
||||
disconnectParent();
|
||||
}
|
||||
}
|
||||
|
||||
function runCommand() {
|
||||
return new Promise((resolveResult, reject) => {
|
||||
child = spawn(command[0], command.slice(1), {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
shell: process.platform === "win32",
|
||||
stdio: "inherit",
|
||||
});
|
||||
child.once("error", reject);
|
||||
child.once("close", (code) => {
|
||||
// During POSIX cancellation the group leader must stay alive, retaining
|
||||
// both its group identity and SQLite ownership until the entire group is
|
||||
// killed. A completed command can still have uncooperative descendants.
|
||||
if (shutdownSignal === undefined || process.platform === "win32")
|
||||
resolveResult({ code });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function disconnectParent() {
|
||||
process.off("disconnect", handleDisconnect);
|
||||
if (process.connected) process.disconnect();
|
||||
}
|
||||
|
||||
function handleDisconnect() {
|
||||
handleSignal("SIGTERM");
|
||||
}
|
||||
|
||||
function handleSignal(signal) {
|
||||
if (shutdownSignal !== undefined) return;
|
||||
shutdownSignal = signal;
|
||||
if (child === undefined || process.platform === "win32") return;
|
||||
// Establish cancellation before signalling the group. This supervisor is
|
||||
// its live leader, so the group identifier cannot be reused during cleanup.
|
||||
process.kill(-process.pid, signal);
|
||||
forceTimer = setTimeout(() => process.kill(-process.pid, "SIGKILL"), 1_000);
|
||||
}
|
||||
|
||||
function isBusyError(cause) {
|
||||
return (
|
||||
typeof cause === "object" &&
|
||||
cause !== null &&
|
||||
"code" in cause &&
|
||||
cause.code === "ERR_SQLITE_ERROR" &&
|
||||
"errcode" in cause &&
|
||||
(cause.errcode === 5 || cause.errcode === 6)
|
||||
);
|
||||
}
|
||||
+31
-146
@@ -1,155 +1,40 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { spawn } from "node:child_process";
|
||||
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const [, , lockName, ...command] = process.argv;
|
||||
const lockRoot = resolve(process.cwd(), ".cache", "rea-command-locks");
|
||||
const lockPath = join(lockRoot, `${lockName ?? "invalid"}.lock`);
|
||||
const ownerPath = join(lockPath, "owner.json");
|
||||
const signalExitCodes = { SIGINT: 130, SIGTERM: 143 };
|
||||
|
||||
let lockHeld = false;
|
||||
let child;
|
||||
let forceTimer;
|
||||
let shutdownSignal;
|
||||
const supervisor = spawn(
|
||||
process.execPath,
|
||||
[
|
||||
fileURLToPath(new URL("./run-exclusive-command.mjs", import.meta.url)),
|
||||
...process.argv.slice(2),
|
||||
],
|
||||
{
|
||||
detached: process.platform !== "win32",
|
||||
stdio: ["inherit", "inherit", "inherit", "ipc"],
|
||||
},
|
||||
);
|
||||
|
||||
process.on("SIGINT", () => handleSignal("SIGINT"));
|
||||
process.on("SIGTERM", () => handleSignal("SIGTERM"));
|
||||
|
||||
if (
|
||||
typeof lockName !== "string" ||
|
||||
!/^[a-z][a-z0-9-]*$/u.test(lockName) ||
|
||||
command.length === 0
|
||||
) {
|
||||
console.error("Usage: run-exclusive.mjs <lock-name> <command> [args...]");
|
||||
process.exitCode = 64;
|
||||
} else {
|
||||
await run();
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
await acquireLock();
|
||||
const result = await runCommand();
|
||||
process.exitCode =
|
||||
shutdownSignal === undefined
|
||||
? (result.code ?? 1)
|
||||
: signalExitCodes[shutdownSignal];
|
||||
} catch (cause) {
|
||||
console.error(cause instanceof Error ? cause.message : String(cause));
|
||||
process.exitCode = 1;
|
||||
} finally {
|
||||
await releaseLock();
|
||||
}
|
||||
}
|
||||
|
||||
async function acquireLock() {
|
||||
await mkdir(lockRoot, { recursive: true });
|
||||
for (let attempt = 0; attempt < 3; attempt += 1) {
|
||||
try {
|
||||
await mkdir(lockPath);
|
||||
await writeFile(
|
||||
ownerPath,
|
||||
JSON.stringify({
|
||||
pid: process.pid,
|
||||
command: command.join(" "),
|
||||
started_at: new Date().toISOString(),
|
||||
}),
|
||||
"utf8",
|
||||
);
|
||||
lockHeld = true;
|
||||
return;
|
||||
} catch (cause) {
|
||||
if (!isAlreadyExistsError(cause)) throw cause;
|
||||
const owner = await readOwner();
|
||||
if (owner === null || isProcessAlive(owner.pid))
|
||||
throw new Error(
|
||||
`Another ${lockName} command is already running (pid ${String(owner?.pid ?? "unknown")}). Wait for it to finish or inspect ${lockPath}.`,
|
||||
);
|
||||
await rm(lockPath, { force: true, recursive: true });
|
||||
}
|
||||
}
|
||||
throw new Error(`Could not acquire the ${lockName} command lock`);
|
||||
}
|
||||
|
||||
async function releaseLock() {
|
||||
if (!lockHeld) return;
|
||||
lockHeld = false;
|
||||
try {
|
||||
const owner = await readOwner();
|
||||
if (owner?.pid === process.pid)
|
||||
await rm(lockPath, { force: true, recursive: true });
|
||||
} catch (cause) {
|
||||
console.error(
|
||||
`Could not remove the ${lockName} command lock: ${cause instanceof Error ? cause.message : String(cause)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function runCommand() {
|
||||
return new Promise((resolveResult, reject) => {
|
||||
child = spawn(command[0], command.slice(1), {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
shell: process.platform === "win32",
|
||||
stdio: "inherit",
|
||||
});
|
||||
child.once("error", reject);
|
||||
child.once("close", (code) => {
|
||||
clearTimeout(forceTimer);
|
||||
resolveResult({ code });
|
||||
});
|
||||
for (const signal of Object.keys(signalExitCodes))
|
||||
process.on(signal, () => {
|
||||
if (shutdownSignal !== undefined) return;
|
||||
shutdownSignal = signal;
|
||||
if (supervisor.connected)
|
||||
supervisor.send(signal, (cause) => {
|
||||
if (cause !== null)
|
||||
console.error(`Could not forward cancellation: ${cause.message}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function handleSignal(signal) {
|
||||
if (shutdownSignal !== undefined) return;
|
||||
shutdownSignal = signal;
|
||||
if (child !== undefined && child.exitCode === null) {
|
||||
child.kill(signal);
|
||||
forceTimer = setTimeout(() => child?.kill("SIGKILL"), 1_000);
|
||||
forceTimer.unref?.();
|
||||
}
|
||||
}
|
||||
|
||||
async function readOwner() {
|
||||
try {
|
||||
const parsed = JSON.parse(await readFile(ownerPath, "utf8"));
|
||||
const pid =
|
||||
typeof parsed === "object" && parsed !== null
|
||||
? Reflect.get(parsed, "pid")
|
||||
: undefined;
|
||||
if (typeof pid !== "number" || !Number.isInteger(pid)) return null;
|
||||
return { pid };
|
||||
} catch (cause) {
|
||||
if (isMissingFileError(cause)) return null;
|
||||
throw cause;
|
||||
}
|
||||
}
|
||||
|
||||
function isProcessAlive(pid) {
|
||||
try {
|
||||
process.kill(pid, 0);
|
||||
return true;
|
||||
} catch (cause) {
|
||||
return !isMissingProcessError(cause);
|
||||
}
|
||||
}
|
||||
|
||||
function isAlreadyExistsError(cause) {
|
||||
return isNodeError(cause) && cause.code === "EEXIST";
|
||||
}
|
||||
|
||||
function isMissingFileError(cause) {
|
||||
return isNodeError(cause) && cause.code === "ENOENT";
|
||||
}
|
||||
|
||||
function isMissingProcessError(cause) {
|
||||
return isNodeError(cause) && cause.code === "ESRCH";
|
||||
}
|
||||
|
||||
function isNodeError(cause) {
|
||||
return typeof cause === "object" && cause !== null && "code" in cause;
|
||||
}
|
||||
supervisor.once("error", (cause) => {
|
||||
console.error(cause.message);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
supervisor.once("close", (code) => {
|
||||
process.exitCode =
|
||||
shutdownSignal === undefined
|
||||
? (code ?? 1)
|
||||
: signalExitCodes[shutdownSignal];
|
||||
});
|
||||
|
||||
@@ -1254,8 +1254,7 @@ async function inspect(
|
||||
return value.error;
|
||||
}
|
||||
assert.notEqual(response.isError, true, mcpTextValue(response));
|
||||
envelope = value.evidence;
|
||||
assert.deepEqual(value.result, envelope.normalized_result);
|
||||
envelope = value;
|
||||
} else {
|
||||
let response;
|
||||
try {
|
||||
|
||||
@@ -118,7 +118,7 @@ try {
|
||||
undefined,
|
||||
`Unexpected public failure: ${JSON.stringify(value)}`,
|
||||
);
|
||||
const evidence = parseEvidence(mode === "cli" ? value : value.evidence);
|
||||
const evidence = parseEvidence(value);
|
||||
const report = evidence.normalized_result;
|
||||
assert.equal(report.diagnostics.truncated, false);
|
||||
assert.equal(evidence.provider.version, "evmole@0.9.3");
|
||||
@@ -157,7 +157,7 @@ try {
|
||||
})),
|
||||
evidence.raw_result.functions ?? [],
|
||||
);
|
||||
if (mode === "mcp") assert.deepEqual(value.result, report);
|
||||
if (mode === "mcp") assert.deepEqual(value.normalized_result, report);
|
||||
return report;
|
||||
};
|
||||
const ownershipProbe = join(root.path, "ownership-prerequisite.hex");
|
||||
|
||||
@@ -118,9 +118,14 @@ try {
|
||||
);
|
||||
const target = await parseBinaryTarget(executable);
|
||||
if (!target.ok) throw target.error;
|
||||
const observation = await observeNativeUi(target.value, "observe_native_ui", {
|
||||
...scope,
|
||||
});
|
||||
const observation = await observeNativeUi(
|
||||
target.value,
|
||||
"observe_native_ui",
|
||||
{
|
||||
...scope,
|
||||
},
|
||||
{ environment: process.env },
|
||||
);
|
||||
if (
|
||||
!observation.ok &&
|
||||
!/accessibility-denied|screen-recording-denied/u.test(
|
||||
@@ -150,6 +155,7 @@ try {
|
||||
{ kind: "wait", milliseconds: 200 },
|
||||
],
|
||||
},
|
||||
{ environment: process.env },
|
||||
);
|
||||
if (!scenario.ok) throw scenario.error;
|
||||
if (
|
||||
@@ -234,6 +240,7 @@ try {
|
||||
{ ...target.value, sha256: "0".repeat(64) },
|
||||
"observe_native_ui",
|
||||
scope,
|
||||
{ environment: process.env },
|
||||
);
|
||||
if (mismatch.ok || !mismatch.error.message.includes("target-mismatch"))
|
||||
throw new Error("Real helper did not reject changed target bytes");
|
||||
|
||||
@@ -8,13 +8,17 @@ export async function verifyPackageCapabilitiesAndSearch({ cli, environment }) {
|
||||
if (!Array.isArray(capabilities.capabilities))
|
||||
throw new Error("packaged capabilities CLI failed");
|
||||
const providers = json(await run(cli, ["providers", "--json"], environment));
|
||||
const candidates = providers.analysis_provider_candidates;
|
||||
if (
|
||||
!Array.isArray(providers.providers) ||
|
||||
providers.providers.some(({ id }) => typeof id !== "string") ||
|
||||
!Array.isArray(candidates) ||
|
||||
candidates.some(
|
||||
(candidate) =>
|
||||
typeof candidate?.provider?.id !== "string" ||
|
||||
candidate.selected !== false,
|
||||
) ||
|
||||
providers.analysis_provider_binding !== null ||
|
||||
providers.analysis_provider_candidates?.find(
|
||||
({ provider }) => provider?.id === "hopper",
|
||||
)?.target_support?.status !== "unknown"
|
||||
candidates.find(({ provider }) => provider?.id === "hopper")?.target_support
|
||||
?.status !== "unknown"
|
||||
)
|
||||
throw new Error("packaged providers CLI failed");
|
||||
if (process.platform !== "linux") {
|
||||
|
||||
@@ -97,7 +97,7 @@ const verifyMcpNonLinuxCurrentDocument = async (
|
||||
mcpOptions,
|
||||
current,
|
||||
) => {
|
||||
if (json(prompts.mcpText(current)).result !== "fixture")
|
||||
if (json(prompts.mcpText(current)).normalized_result !== "fixture")
|
||||
throw new Error("packaged MCP bridge call failed");
|
||||
const batch = await client.callTool(
|
||||
{
|
||||
@@ -106,7 +106,7 @@ const verifyMcpNonLinuxCurrentDocument = async (
|
||||
},
|
||||
mcpOptions,
|
||||
);
|
||||
const batchResult = json(prompts.mcpText(batch)).result;
|
||||
const batchResult = json(prompts.mcpText(batch)).normalized_result;
|
||||
if (
|
||||
batch.isError === true ||
|
||||
batchResult?.total !== 1 ||
|
||||
@@ -176,10 +176,10 @@ const verifyMcpInlineArtifactEvidence = async (
|
||||
mcpOptions,
|
||||
);
|
||||
assert.notEqual(inspected.isError, true, JSON.stringify(inspected));
|
||||
const source = parseEvidence(inspected.structuredContent?.evidence);
|
||||
const source = parseEvidence(inspected.structuredContent);
|
||||
assert.deepEqual(
|
||||
source.normalized_result,
|
||||
inspected.structuredContent?.result,
|
||||
inspected.structuredContent?.normalized_result,
|
||||
);
|
||||
assert.deepEqual(
|
||||
json(prompts.mcpText(inspected)),
|
||||
@@ -189,17 +189,17 @@ const verifyMcpInlineArtifactEvidence = async (
|
||||
{
|
||||
name: "compare_artifacts",
|
||||
arguments: {
|
||||
left: inspected.structuredContent.evidence,
|
||||
right: inspected.structuredContent.evidence,
|
||||
left: inspected.structuredContent,
|
||||
right: inspected.structuredContent,
|
||||
},
|
||||
},
|
||||
mcpOptions,
|
||||
);
|
||||
assert.notEqual(compared.isError, true, JSON.stringify(compared));
|
||||
const comparison = parseEvidence(compared.structuredContent?.evidence);
|
||||
const comparison = parseEvidence(compared.structuredContent);
|
||||
assert.deepEqual(
|
||||
comparison.normalized_result,
|
||||
compared.structuredContent?.result,
|
||||
compared.structuredContent?.normalized_result,
|
||||
);
|
||||
assert.ok(comparison.evidence_links.includes(source.evidence_id));
|
||||
const bundle = await client.callTool(
|
||||
@@ -220,12 +220,12 @@ const verifyMcpInlineArtifactEvidence = async (
|
||||
mcpOptions,
|
||||
);
|
||||
assert.notEqual(extracted.isError, true, JSON.stringify(extracted));
|
||||
const extraction = parseEvidence(extracted.structuredContent?.evidence);
|
||||
const extraction = parseEvidence(extracted.structuredContent);
|
||||
assert.deepEqual(
|
||||
extraction.normalized_result,
|
||||
extracted.structuredContent?.result,
|
||||
extracted.structuredContent?.normalized_result,
|
||||
);
|
||||
const materialized = extracted.structuredContent?.result;
|
||||
const materialized = extracted.structuredContent?.normalized_result;
|
||||
assert.equal(typeof materialized?.output_root, "string");
|
||||
outputRoot = materialized.output_root;
|
||||
assert.equal(materialized.containment_verified, true);
|
||||
|
||||
@@ -42,12 +42,8 @@ export async function verifyPackagePack({ root, workspace }) {
|
||||
throw new Error(
|
||||
"package included authored skill sources instead of only the generated bundle",
|
||||
);
|
||||
if (
|
||||
packedFiles.some((path) =>
|
||||
/^package\/(?:dist|src)\/generatedMcpToolCatalog\./u.test(path),
|
||||
)
|
||||
)
|
||||
throw new Error("package included the test-only generated MCP catalog");
|
||||
if (packedFiles.some((path) => path.startsWith("package/.cache/")))
|
||||
throw new Error("package included development cache or test metadata");
|
||||
const skill = (
|
||||
await exec("tar", [
|
||||
"-xOf",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { requireMcpOperationResult } from "./lib/mcp-verifier-results.mjs";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import {
|
||||
@@ -171,7 +172,14 @@ try {
|
||||
})
|
||||
).stdout,
|
||||
);
|
||||
assert.ok(JSON.stringify(providers).includes("ghidra"));
|
||||
assert.equal(providers.analysis_provider_binding, null);
|
||||
assert.ok(Array.isArray(providers.analysis_provider_candidates));
|
||||
const ghidra = providers.analysis_provider_candidates.find(
|
||||
({ provider }) => provider.id === "ghidra",
|
||||
);
|
||||
assert.ok(ghidra !== undefined);
|
||||
assert.equal(ghidra.selected, false);
|
||||
assert.equal(ghidra.target_support.status, "unknown");
|
||||
report.cli.providers = true;
|
||||
const inspected = await exec(
|
||||
process.execPath,
|
||||
@@ -210,12 +218,9 @@ try {
|
||||
{ timeout: 360_000 },
|
||||
);
|
||||
assert.notEqual(result.isError, true, `Packaged operation failed: ${name}`);
|
||||
const structured =
|
||||
result.structuredContent ??
|
||||
JSON.parse(result.content.find((item) => item.type === "text").text);
|
||||
const parsed = contract.outputSchema.parse(structured);
|
||||
const projected = requireMcpOperationResult(result, name, contract);
|
||||
report.mcpOperations.push(name);
|
||||
return parsed.result;
|
||||
return projected;
|
||||
};
|
||||
try {
|
||||
await client.connect(transport);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { fileURLToPath } from "node:url";
|
||||
|
||||
import { CdpBrowserProvider } from "../dist/browser/CdpBrowserProvider.js";
|
||||
import { waitForBrowserDevtoolsPort } from "../dist/browser/BrowserProcessStartup.js";
|
||||
import { PlaywrightBrowserScenarioProvider } from "../dist/browser/PlaywrightBrowserScenarioProvider.js";
|
||||
import { createBrowserScenarioProvider } from "../dist/composition/browserScenario.js";
|
||||
import {
|
||||
inspectWebPageInputSchema,
|
||||
listBrowserTargetsInputSchema,
|
||||
@@ -240,10 +240,9 @@ try {
|
||||
try {
|
||||
attachedScenario = await runScenarioCli(attachedScenarioInput);
|
||||
} catch (cliError) {
|
||||
const direct =
|
||||
await new PlaywrightBrowserScenarioProvider().captureScenario(
|
||||
attachedScenarioInput,
|
||||
);
|
||||
const direct = await createBrowserScenarioProvider(
|
||||
process.env,
|
||||
).captureScenario(attachedScenarioInput);
|
||||
if (!direct.ok) {
|
||||
const underlying = direct.error.cause;
|
||||
const details =
|
||||
@@ -274,16 +273,17 @@ try {
|
||||
throw new Error("Scenario attachment terminated its external browser");
|
||||
|
||||
const profilesBefore = await scenarioProfiles();
|
||||
const launchedScenario =
|
||||
await new PlaywrightBrowserScenarioProvider().captureScenario(
|
||||
browserScenario(
|
||||
{
|
||||
mode: "launch",
|
||||
executable_path: executable,
|
||||
},
|
||||
site.origin,
|
||||
),
|
||||
);
|
||||
const launchedScenario = await createBrowserScenarioProvider(
|
||||
process.env,
|
||||
).captureScenario(
|
||||
browserScenario(
|
||||
{
|
||||
mode: "launch",
|
||||
executable_path: executable,
|
||||
},
|
||||
site.origin,
|
||||
),
|
||||
);
|
||||
if (!launchedScenario.ok) throw launchedScenario.error;
|
||||
if (
|
||||
launchedScenario.value.browser.cleanup !== "terminated-owned-process" ||
|
||||
|
||||
@@ -50,7 +50,9 @@ const input = electronActiveObservationInputSchema.parse({
|
||||
],
|
||||
});
|
||||
const verifierRun = createVerifierRun();
|
||||
const result = await new PlaywrightElectronActiveProvider().capture(input);
|
||||
const result = await new PlaywrightElectronActiveProvider(process.env).capture(
|
||||
input,
|
||||
);
|
||||
if (!result.ok) throw result.error;
|
||||
|
||||
const output = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
import assert from "node:assert/strict";
|
||||
import { requireMcpOperationResult } from "./lib/mcp-verifier-results.mjs";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
@@ -28,6 +29,7 @@ if (process.env.GHIDRA_INSTALL_DIR === undefined)
|
||||
"verify:ghidra:com prerequisite missing: GHIDRA_INSTALL_DIR (bring your own Ghidra).",
|
||||
);
|
||||
const installation = inspectGhidraInstallation({
|
||||
environment: process.env,
|
||||
installDir: process.env.GHIDRA_INSTALL_DIR,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
@@ -331,12 +333,15 @@ async function call(name, args = {}) {
|
||||
{ timeout: 240000 },
|
||||
);
|
||||
assert.notEqual(value.isError, true, JSON.stringify(value));
|
||||
if (name === "open_binary") return value.structuredContent.result;
|
||||
if (name === "close_binary") return value.structuredContent;
|
||||
const evidence = parseEvidence(value.structuredContent.evidence);
|
||||
const projected = requireMcpOperationResult(value, name);
|
||||
if (name === "open_binary" || name === "close_binary") return projected;
|
||||
const evidence = parseEvidence(value.structuredContent);
|
||||
assert.equal(evidence.subject.digest.sha256, sha256);
|
||||
assert.deepEqual(evidence.normalized_result, value.structuredContent.result);
|
||||
return value.structuredContent.result;
|
||||
assert.deepEqual(
|
||||
evidence.normalized_result,
|
||||
value.structuredContent.normalized_result,
|
||||
);
|
||||
return projected;
|
||||
}
|
||||
async function cli(command, address, options = []) {
|
||||
const { stdout } = await promisify(execFile)(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
import assert from "node:assert/strict";
|
||||
import { requireMcpOperationResult } from "./lib/mcp-verifier-results.mjs";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import {
|
||||
@@ -38,6 +39,7 @@ if (process.env.GHIDRA_INSTALL_DIR === undefined)
|
||||
"verify:ghidra:dos prerequisite missing: GHIDRA_INSTALL_DIR (bring your own Ghidra).",
|
||||
);
|
||||
const installation = inspectGhidraInstallation({
|
||||
environment: process.env,
|
||||
installDir: process.env.GHIDRA_INSTALL_DIR,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
@@ -552,11 +554,8 @@ async function call(name, arguments_ = {}) {
|
||||
{ timeout: 240000 },
|
||||
);
|
||||
assert.notEqual(result.isError, true, JSON.stringify(result));
|
||||
assert.ok(
|
||||
result.structuredContent && "result" in result.structuredContent,
|
||||
`${name} omitted structured result`,
|
||||
);
|
||||
return result.structuredContent.result;
|
||||
assert.ok(result.structuredContent, `${name} omitted structured result`);
|
||||
return requireMcpOperationResult(result, name);
|
||||
}
|
||||
async function evidenceCall(name, arguments_) {
|
||||
const result = await client.callTool(
|
||||
@@ -564,10 +563,7 @@ async function evidenceCall(name, arguments_) {
|
||||
{ timeout: 240000 },
|
||||
);
|
||||
assert.notEqual(result.isError, true, JSON.stringify(result));
|
||||
const evidence = parseEvidence({
|
||||
...result.structuredContent?.evidence,
|
||||
normalized_result: result.structuredContent?.result,
|
||||
});
|
||||
const evidence = parseEvidence(result.structuredContent);
|
||||
assert.equal(evidence.subject.digest.sha256, sha256);
|
||||
assert.equal(evidence.provider.id, "ghidra");
|
||||
assertProfile(evidence.analysis_profile);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
import assert from "node:assert/strict";
|
||||
import { requireMcpOperationResult } from "./lib/mcp-verifier-results.mjs";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import {
|
||||
@@ -392,12 +393,13 @@ async function call(name, args = {}) {
|
||||
{ timeout: 360000 },
|
||||
);
|
||||
assert.notEqual(response.isError, true, JSON.stringify(response));
|
||||
if (name === "close_binary") return response.structuredContent;
|
||||
const evidence = parseEvidence(response.structuredContent.evidence);
|
||||
const projected = requireMcpOperationResult(response, name);
|
||||
if (name === "close_binary") return projected;
|
||||
const evidence = parseEvidence(response.structuredContent);
|
||||
assert.equal(evidence.subject.digest.sha256, sha256);
|
||||
assert.deepEqual(
|
||||
evidence.normalized_result,
|
||||
response.structuredContent.result,
|
||||
response.structuredContent.normalized_result,
|
||||
);
|
||||
return response.structuredContent.result;
|
||||
return projected;
|
||||
}
|
||||
|
||||
@@ -10,12 +10,13 @@ import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { inspectGhidraInstallation } from "../dist/ghidra/GhidraInstallation.js";
|
||||
import { toolContract } from "../dist/contracts/toolContracts.js";
|
||||
import { requireMcpResult } from "./lib/mcp-verifier-results.mjs";
|
||||
import { requireMcpOperationResult } from "./lib/mcp-verifier-results.mjs";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
const run = createVerifierRun();
|
||||
const installation = inspectGhidraInstallation({
|
||||
environment: process.env,
|
||||
installDir: process.env.GHIDRA_INSTALL_DIR,
|
||||
javaHome: process.env.JAVA_HOME,
|
||||
});
|
||||
@@ -156,5 +157,5 @@ async function call(name, arguments_) {
|
||||
);
|
||||
if (name === "analyze_swift_types")
|
||||
toolContract(name).outputSchema.parse(response.structuredContent);
|
||||
return requireMcpResult(response, name);
|
||||
return requireMcpOperationResult(response, name);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
import assert from "node:assert/strict";
|
||||
import { requireMcpOperationResult } from "./lib/mcp-verifier-results.mjs";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import {
|
||||
@@ -74,6 +75,7 @@ if (!compilerOnly) {
|
||||
"Ghidra switch lane prerequisite missing: GHIDRA_INSTALL_DIR (bring your own)",
|
||||
);
|
||||
installation = inspectGhidraInstallation({
|
||||
environment: process.env,
|
||||
installDir: process.env.GHIDRA_INSTALL_DIR,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
@@ -237,15 +239,21 @@ async function verifyTarget(path, sha256, fixtures, variant) {
|
||||
const observed = await toolResult(client, "inspect_native_api", {
|
||||
procedure: procedure.address,
|
||||
});
|
||||
assertWorkflowIdentity(observed.evidence, sha256);
|
||||
assert.equal(observed.result.procedure.address, procedure.address);
|
||||
assertWorkflowIdentity(observed, sha256);
|
||||
assert.equal(
|
||||
observed.normalized_result.procedure.address,
|
||||
procedure.address,
|
||||
);
|
||||
const summary = assertSwitchBoundary(
|
||||
observed.result.boundary,
|
||||
observed.normalized_result.boundary,
|
||||
observationFixture,
|
||||
);
|
||||
assert.deepEqual(
|
||||
[...observed.result.residual_unknowns].sort(),
|
||||
expectedResidualUnknowns(observed.result.boundary, fixture).sort(),
|
||||
[...observed.normalized_result.residual_unknowns].sort(),
|
||||
expectedResidualUnknowns(
|
||||
observed.normalized_result.boundary,
|
||||
fixture,
|
||||
).sort(),
|
||||
"Residual unknowns must preserve unresolved ABI types and exactly the expected switch uncertainty",
|
||||
);
|
||||
const cli = await cliSwitchEvidence(
|
||||
@@ -259,20 +267,20 @@ async function verifyTarget(path, sha256, fixtures, variant) {
|
||||
assertSwitchBoundary(cli.normalized_result.boundary, observationFixture);
|
||||
assert.deepEqual(
|
||||
cli.normalized_result.boundary.jump_tables,
|
||||
observed.result.boundary.jump_tables,
|
||||
observed.normalized_result.boundary.jump_tables,
|
||||
"CLI/MCP switch mappings/defaults/data-source evidence differ",
|
||||
);
|
||||
assert.deepEqual(
|
||||
cli.normalized_result.residual_unknowns,
|
||||
observed.result.residual_unknowns,
|
||||
observed.normalized_result.residual_unknowns,
|
||||
);
|
||||
observations.push({
|
||||
name: fixture.name,
|
||||
...summary,
|
||||
cli_mcp_equal: true,
|
||||
limitations: observed.result.boundary.limitations,
|
||||
residual_unknowns: observed.result.residual_unknowns,
|
||||
jump_tables: observed.result.boundary.jump_tables,
|
||||
limitations: observed.normalized_result.boundary.limitations,
|
||||
residual_unknowns: observed.normalized_result.residual_unknowns,
|
||||
jump_tables: observed.normalized_result.boundary.jump_tables,
|
||||
});
|
||||
}
|
||||
return { observations, stderr };
|
||||
@@ -319,14 +327,15 @@ async function toolResult(client, name, arguments_ = {}) {
|
||||
{ timeout: 240000 },
|
||||
);
|
||||
assert.notEqual(result.isError, true, JSON.stringify(result));
|
||||
assert.ok(
|
||||
result.structuredContent && "result" in result.structuredContent,
|
||||
`${name} omitted structured result`,
|
||||
);
|
||||
assert.ok(result.structuredContent, `${name} omitted structured result`);
|
||||
return result.structuredContent;
|
||||
}
|
||||
async function call(client, name, arguments_ = {}) {
|
||||
return (await toolResult(client, name, arguments_)).result;
|
||||
const result = await client.callTool(
|
||||
{ name, arguments: arguments_ },
|
||||
{ timeout: 240000 },
|
||||
);
|
||||
return requireMcpOperationResult(result, name);
|
||||
}
|
||||
|
||||
async function cliSwitchEvidence(entrypoint, path, procedure, env) {
|
||||
|
||||
@@ -48,6 +48,7 @@ if (installDir === undefined || !isAbsolute(installDir))
|
||||
"Set GHIDRA_INSTALL_DIR to the absolute root of Ghidra 12.1.4.",
|
||||
);
|
||||
const installation = inspectGhidraInstallation({
|
||||
environment: process.env,
|
||||
installDir,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
@@ -94,6 +95,7 @@ if (!profile.ok || profile.value.profile === null)
|
||||
const client = new GhidraClient({
|
||||
platform: installation.platform,
|
||||
launcher: new GhidraHeadlessLauncher({
|
||||
environment: process.env,
|
||||
analyzeHeadlessPath: installation.analyzeHeadlessPath,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
@@ -112,6 +114,7 @@ const client = new GhidraClient({
|
||||
|
||||
let coordinates;
|
||||
let report;
|
||||
let primaryFailure;
|
||||
const observed = new Set();
|
||||
try {
|
||||
const started = await client.start();
|
||||
@@ -257,8 +260,18 @@ try {
|
||||
"no-gui-or-mutation-authority",
|
||||
],
|
||||
};
|
||||
} catch (cause) {
|
||||
primaryFailure = cause;
|
||||
throw cause;
|
||||
} finally {
|
||||
await client.close();
|
||||
const closed = await client.close();
|
||||
if (!closed.ok)
|
||||
throw primaryFailure === undefined
|
||||
? closed.error
|
||||
: new AggregateError(
|
||||
[primaryFailure, closed.error],
|
||||
"Ghidra verification and cleanup failed",
|
||||
);
|
||||
if (coordinates !== undefined) await assertCleanup(coordinates);
|
||||
}
|
||||
if (report === undefined)
|
||||
|
||||
@@ -50,6 +50,7 @@ if (installDir === undefined || !isAbsolute(installDir))
|
||||
"Set GHIDRA_INSTALL_DIR to the absolute root of an extracted Ghidra 12.1.4 release.",
|
||||
);
|
||||
const installation = inspectGhidraInstallation({
|
||||
environment: process.env,
|
||||
installDir,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
@@ -442,6 +443,7 @@ async function verifyTarget(targetPath, variant, expectedTarget = null) {
|
||||
|
||||
const client = new GhidraClient({
|
||||
launcher: new GhidraHeadlessLauncher({
|
||||
environment: process.env,
|
||||
analyzeHeadlessPath: installation.analyzeHeadlessPath,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
@@ -458,6 +460,7 @@ async function verifyTarget(targetPath, variant, expectedTarget = null) {
|
||||
});
|
||||
|
||||
let runtimeCoordinates;
|
||||
let primaryFailure;
|
||||
try {
|
||||
const started = await client.start();
|
||||
if (!started.ok) throw started.error;
|
||||
@@ -539,8 +542,18 @@ async function verifyTarget(targetPath, variant, expectedTarget = null) {
|
||||
native_api_cli: nativeApiCli,
|
||||
native_values: nativeValues,
|
||||
};
|
||||
} catch (cause) {
|
||||
primaryFailure = cause;
|
||||
throw cause;
|
||||
} finally {
|
||||
await client.close();
|
||||
const closed = await client.close();
|
||||
if (!closed.ok)
|
||||
throw primaryFailure === undefined
|
||||
? closed.error
|
||||
: new AggregateError(
|
||||
[primaryFailure, closed.error],
|
||||
"Ghidra verification and cleanup failed",
|
||||
);
|
||||
if (runtimeCoordinates !== undefined)
|
||||
await assertCleanup(runtimeCoordinates);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ const root = await realpath(
|
||||
);
|
||||
const target = join(root, "deadline-fixture");
|
||||
let client;
|
||||
let primaryFailure;
|
||||
try {
|
||||
await copyFile(fixtures.primary.path, target);
|
||||
const parsed = await parseBinaryTarget(target);
|
||||
@@ -40,14 +41,27 @@ try {
|
||||
provider: HOPPER_PROVIDER_IDENTITY,
|
||||
});
|
||||
if (!resolved.ok) throw resolved.error;
|
||||
const image = resolved.value.profile?.parameters.prepared_image;
|
||||
const profile = resolved.value.profile;
|
||||
assert.notEqual(
|
||||
profile,
|
||||
null,
|
||||
"This lane requires a resolved Hopper launcher profile",
|
||||
);
|
||||
const loaderArgs = profile.parameters.loader?.arguments;
|
||||
assert.ok(
|
||||
Array.isArray(loaderArgs) &&
|
||||
loaderArgs.every((argument) => typeof argument === "string"),
|
||||
"The Hopper profile must report its effective loader arguments",
|
||||
);
|
||||
const image = profile.parameters.prepared_image;
|
||||
client = new HopperClient({
|
||||
launcher: new HopperApplicationLauncher({
|
||||
environment: process.env,
|
||||
launcherPath,
|
||||
targetPath: target,
|
||||
targetKind: "executable",
|
||||
launchMode: "native",
|
||||
loaderArgs: resolved.value.compatibility.loaderArgs,
|
||||
loaderArgs,
|
||||
...(image === undefined
|
||||
? {}
|
||||
: {
|
||||
@@ -102,7 +116,7 @@ try {
|
||||
const activityAfterDeadline = client.requestActivity();
|
||||
await call("health");
|
||||
assert.equal(client.requestActivity(), null);
|
||||
const closed = await client.closeWithOutcome();
|
||||
const closed = await client.close();
|
||||
if (!closed.ok) throw closed.error;
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
@@ -120,7 +134,19 @@ try {
|
||||
2,
|
||||
),
|
||||
);
|
||||
} catch (cause) {
|
||||
primaryFailure = cause;
|
||||
throw cause;
|
||||
} finally {
|
||||
if (client !== undefined) await client.close();
|
||||
if (client !== undefined) {
|
||||
const closed = await client.close();
|
||||
if (!closed.ok)
|
||||
throw primaryFailure === undefined
|
||||
? closed.error
|
||||
: new AggregateError(
|
||||
[primaryFailure, closed.error],
|
||||
"Hopper verification and cleanup failed",
|
||||
);
|
||||
}
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
@@ -18,7 +18,10 @@ import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import Ajv from "ajv/dist/2020.js";
|
||||
import addFormats from "ajv-formats";
|
||||
import { mcpTextValue, requireMcpResult } from "./lib/mcp-verifier-results.mjs";
|
||||
import {
|
||||
mcpTextValue,
|
||||
requireMcpOperationResult,
|
||||
} from "./lib/mcp-verifier-results.mjs";
|
||||
import { snapshotHopperRuntime } from "./lib/real-hopper-cleanup.mjs";
|
||||
import { HOPPER_TARGET_LEASE_DIRECTORY } from "../dist/hopper/HopperTargetLease.js";
|
||||
import { parseConfig } from "../dist/config.js";
|
||||
@@ -219,7 +222,7 @@ try {
|
||||
{ name, arguments: args },
|
||||
{ timeout: 180_000 },
|
||||
);
|
||||
const result = requireMcpResult(reply, name);
|
||||
const result = requireMcpOperationResult(reply, name);
|
||||
const schema = catalog.tools.find(
|
||||
(tool) => tool.name === name,
|
||||
)?.outputSchema;
|
||||
|
||||
@@ -27,7 +27,9 @@ import {
|
||||
import {
|
||||
mcpTextValue,
|
||||
requireEvidenceProvider,
|
||||
requireMcpResult,
|
||||
requireMcpOperationResult,
|
||||
requireMcpLifecycleResult,
|
||||
requireMcpEvidenceResult,
|
||||
requireWorkflowEvidenceProvider,
|
||||
} from "./lib/mcp-verifier-results.mjs";
|
||||
import {
|
||||
@@ -64,7 +66,6 @@ const sessionsBefore = await snapshotHopperRuntime(
|
||||
);
|
||||
const ownedProcessIds = new Set();
|
||||
const textValue = mcpTextValue;
|
||||
const requireSuccessfulTool = requireMcpResult;
|
||||
|
||||
const requireOverview = (value, operation) => {
|
||||
if (
|
||||
@@ -87,7 +88,7 @@ const verifyRelationships = async (client, options, procedure) => {
|
||||
const related = {};
|
||||
for (const operation of ["procedure_callers", "procedure_callees"]) {
|
||||
related[operation] = requireAddressArray(
|
||||
requireSuccessfulTool(
|
||||
requireMcpEvidenceResult(
|
||||
await client.callTool(
|
||||
{ name: operation, arguments: { procedure } },
|
||||
options,
|
||||
@@ -98,7 +99,7 @@ const verifyRelationships = async (client, options, procedure) => {
|
||||
);
|
||||
}
|
||||
related.xrefs = requireAddressArray(
|
||||
requireSuccessfulTool(
|
||||
requireMcpEvidenceResult(
|
||||
await client.callTool(
|
||||
{ name: "xrefs", arguments: { address: procedure } },
|
||||
options,
|
||||
@@ -111,7 +112,7 @@ const verifyRelationships = async (client, options, procedure) => {
|
||||
};
|
||||
|
||||
const verifyByteAccess = async (client, options, firstAddress) => {
|
||||
const byteRead = requireSuccessfulTool(
|
||||
const byteRead = requireMcpEvidenceResult(
|
||||
await client.callTool(
|
||||
{ name: "read_bytes", arguments: { address: firstAddress, length: 16 } },
|
||||
options,
|
||||
@@ -127,7 +128,7 @@ const verifyByteAccess = async (client, options, firstAddress) => {
|
||||
) {
|
||||
throw new Error("read_bytes returned an invalid bounded byte window");
|
||||
}
|
||||
const mappedOffset = requireSuccessfulTool(
|
||||
const mappedOffset = requireMcpEvidenceResult(
|
||||
await client.callTool(
|
||||
{
|
||||
name: "address_to_file_offset",
|
||||
@@ -151,7 +152,7 @@ const verifyByteAccess = async (client, options, firstAddress) => {
|
||||
};
|
||||
|
||||
const verifyCurrentTarget = async (client, options) => {
|
||||
const procedures = requireSuccessfulTool(
|
||||
const procedures = requireMcpEvidenceResult(
|
||||
await client.callTool({ name: "list_procedures", arguments: {} }, options),
|
||||
"list_procedures",
|
||||
);
|
||||
@@ -167,7 +168,7 @@ const verifyCurrentTarget = async (client, options) => {
|
||||
options,
|
||||
firstAddress,
|
||||
);
|
||||
const boundedResult = requireSuccessfulTool(
|
||||
const boundedResult = requireMcpEvidenceResult(
|
||||
await client.callTool(
|
||||
{
|
||||
name: "batch_decompile",
|
||||
@@ -196,7 +197,7 @@ const verifyCurrentTarget = async (client, options) => {
|
||||
"batch_decompile",
|
||||
);
|
||||
const dossier = requireFunctionDossier(
|
||||
requireSuccessfulTool(
|
||||
requireMcpEvidenceResult(
|
||||
await client.callTool(
|
||||
{
|
||||
name: "analyze_function",
|
||||
@@ -274,7 +275,10 @@ try {
|
||||
const fullSessionStatus = () =>
|
||||
client.callTool({ name: "binary_session", arguments: {} }, options);
|
||||
const initialSession = await fullSessionStatus();
|
||||
const initialStatus = requireMcpResult(initialSession, "binary_session");
|
||||
const initialStatus = requireMcpLifecycleResult(
|
||||
initialSession,
|
||||
"binary_session",
|
||||
);
|
||||
const listed = await client.listTools();
|
||||
const availableTools = initialStatus.tool_availability;
|
||||
if (!Array.isArray(availableTools))
|
||||
@@ -300,7 +304,7 @@ try {
|
||||
options,
|
||||
);
|
||||
if (opened.isError === true) throw new Error(textValue(opened));
|
||||
const firstStatus = requireMcpResult(
|
||||
const firstStatus = requireMcpLifecycleResult(
|
||||
await fullSessionStatus(),
|
||||
"binary_session",
|
||||
);
|
||||
@@ -312,7 +316,7 @@ try {
|
||||
{ name: "list_documents", arguments: {} },
|
||||
options,
|
||||
);
|
||||
requireSuccessfulTool(documents, "list_documents");
|
||||
requireMcpEvidenceResult(documents, "list_documents");
|
||||
requireBridgeProgress(progressUpdates);
|
||||
const rejectedProcedure = await client.callTool(
|
||||
{
|
||||
@@ -327,7 +331,7 @@ try {
|
||||
{ name: "binary_overview", arguments: {} },
|
||||
options,
|
||||
);
|
||||
requireSuccessfulTool(overview, "binary_overview");
|
||||
requireMcpEvidenceResult(overview, "binary_overview");
|
||||
const inventoryCounts = await verifyHopperInventories(client, options);
|
||||
requireEvidenceProvider(
|
||||
documents,
|
||||
@@ -343,9 +347,9 @@ try {
|
||||
options,
|
||||
);
|
||||
requireTruthfulMemoryRegions(
|
||||
requireSuccessfulTool(segments, "list_segments"),
|
||||
requireMcpEvidenceResult(segments, "list_segments"),
|
||||
);
|
||||
const firstDocuments = requireSuccessfulTool(documents, "list_documents");
|
||||
const firstDocuments = requireMcpEvidenceResult(documents, "list_documents");
|
||||
if (
|
||||
!Array.isArray(firstDocuments) ||
|
||||
firstDocuments.length === 0 ||
|
||||
@@ -356,10 +360,10 @@ try {
|
||||
client,
|
||||
options,
|
||||
firstDocuments,
|
||||
requireSuccessfulTool,
|
||||
requireMcpEvidenceResult,
|
||||
);
|
||||
const firstOverview = requireOverview(
|
||||
requireSuccessfulTool(overview, "binary_overview"),
|
||||
requireMcpEvidenceResult(overview, "binary_overview"),
|
||||
"binary_overview",
|
||||
);
|
||||
if (firstOverview.document !== currentDocument)
|
||||
@@ -372,7 +376,7 @@ try {
|
||||
options,
|
||||
document: currentDocument,
|
||||
oracle: fixtureTargets.oracle,
|
||||
normalizedResult: requireSuccessfulTool,
|
||||
normalizedResult: requireMcpEvidenceResult,
|
||||
});
|
||||
const boundaryContracts = await verifyHopperBoundaryContracts(
|
||||
client,
|
||||
@@ -385,7 +389,7 @@ try {
|
||||
options,
|
||||
);
|
||||
if (switched.isError === true) throw new Error(textValue(switched));
|
||||
const secondSession = requireMcpResult(
|
||||
const secondSession = requireMcpLifecycleResult(
|
||||
await fullSessionStatus(),
|
||||
"binary_session",
|
||||
);
|
||||
@@ -400,19 +404,19 @@ try {
|
||||
options,
|
||||
);
|
||||
const verifiedSecondOverview = requireOverview(
|
||||
requireSuccessfulTool(secondOverview, "binary_overview"),
|
||||
requireMcpEvidenceResult(secondOverview, "binary_overview"),
|
||||
"binary_overview after target switch",
|
||||
);
|
||||
const secondAnalysis = await verifyCurrentTarget(client, options);
|
||||
const documentsAfterTargetSwitch = requireMcpResult(
|
||||
const documentsAfterTargetSwitch = requireMcpEvidenceResult(
|
||||
await client.callTool({ name: "list_documents", arguments: {} }, options),
|
||||
"list_documents after target switch",
|
||||
"list_documents",
|
||||
);
|
||||
const secondDocument = await requireCurrentDocument(
|
||||
client,
|
||||
options,
|
||||
documentsAfterTargetSwitch,
|
||||
requireSuccessfulTool,
|
||||
requireMcpEvidenceResult,
|
||||
);
|
||||
if (verifiedSecondOverview.document !== secondDocument)
|
||||
throw new Error(
|
||||
@@ -432,9 +436,9 @@ try {
|
||||
);
|
||||
if (reopenedTarget.isError === true)
|
||||
throw new Error(textValue(reopenedTarget));
|
||||
const documentsAfterReopen = requireMcpResult(
|
||||
const documentsAfterReopen = requireMcpEvidenceResult(
|
||||
await client.callTool({ name: "list_documents", arguments: {} }, options),
|
||||
"list_documents after reopening target B",
|
||||
"list_documents",
|
||||
);
|
||||
if (
|
||||
!Array.isArray(documentsAfterReopen) ||
|
||||
@@ -446,7 +450,7 @@ try {
|
||||
const largeInventory = await openAndVerifyLargeFixture({
|
||||
client,
|
||||
options,
|
||||
normalizedResult: requireSuccessfulTool,
|
||||
normalizedResult: requireMcpEvidenceResult,
|
||||
path: largeTarget,
|
||||
expectedCount: fixtureTargets.largeOracle.symbolCount,
|
||||
symbolPrefix: fixtureTargets.largeOracle.symbolPrefix,
|
||||
@@ -471,7 +475,7 @@ try {
|
||||
let terminalInstructions = null;
|
||||
if (fixtureTargets.unicode !== undefined) {
|
||||
const call = async (name, args = {}) =>
|
||||
requireSuccessfulTool(
|
||||
requireMcpOperationResult(
|
||||
await client.callTool({ name, arguments: args }, options),
|
||||
name,
|
||||
);
|
||||
@@ -492,7 +496,7 @@ try {
|
||||
: { unicode: fixtureTargets.unicode.path }),
|
||||
ownedProcessIds,
|
||||
});
|
||||
const closedSession = requireMcpResult(
|
||||
const closedSession = requireMcpLifecycleResult(
|
||||
await fullSessionStatus(),
|
||||
"binary_session",
|
||||
);
|
||||
|
||||
@@ -145,11 +145,11 @@ const mcp = async (cliDossier) => {
|
||||
const analyzed = await call("analyze_function", {
|
||||
procedure: values.procedure,
|
||||
});
|
||||
const dossier = functionDossierSchema.parse(observe(analyzed.evidence));
|
||||
const dossier = functionDossierSchema.parse(observe(analyzed));
|
||||
assert.deepEqual(dossier.procedure, cliDossier.procedure);
|
||||
assert.equal(dossier.pseudocode, cliDossier.pseudocode);
|
||||
assert.deepEqual(dossier.assembly, cliDossier.assembly);
|
||||
assert.equal(analyzed.evidence_id, analyzed.evidence.evidence_id);
|
||||
assert.equal(analyzed.operation, "analyze_function");
|
||||
for (const [name, args] of [
|
||||
["list_procedures", {}],
|
||||
["list_strings", {}],
|
||||
@@ -166,7 +166,7 @@ const mcp = async (cliDossier) => {
|
||||
["xrefs", { address: dossier.procedure.address }],
|
||||
]) {
|
||||
const result = await call(name, args);
|
||||
observe(result.evidence);
|
||||
observe(result);
|
||||
}
|
||||
const invalid = await client.callTool({
|
||||
name: "xrefs",
|
||||
@@ -191,7 +191,7 @@ const mcp = async (cliDossier) => {
|
||||
};
|
||||
const cleanup = async () => {
|
||||
phase = "upstream lifecycle verification";
|
||||
const upstream = createIdaMcpConnection(config);
|
||||
const upstream = createIdaMcpConnection(config, process.env);
|
||||
try {
|
||||
await upstream.connect();
|
||||
if (config.mode === "attached") {
|
||||
|
||||
@@ -912,8 +912,8 @@ async function inspect(mode, input, errorCategory) {
|
||||
return value.error;
|
||||
}
|
||||
assert.notEqual(result.isError, true, mcpTextValue(result));
|
||||
assertSensitiveLimitations(value.evidence, input.sensitive_values ?? []);
|
||||
return value.result;
|
||||
assertSensitiveLimitations(value, input.sensitive_values ?? []);
|
||||
return value.normalized_result;
|
||||
}
|
||||
const args = [
|
||||
entrypoint,
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, resolve } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { verifyWindowsProtocolInput } from "./lib/windows-protocol-input.mjs";
|
||||
|
||||
if (process.platform !== "win32")
|
||||
throw new Error(
|
||||
@@ -411,6 +412,10 @@ setInterval(()=>{},1000);\n`,
|
||||
await delay();
|
||||
assert.equal(live(ownerClose.pid), false);
|
||||
report.processes.killOnOwnerClose = true;
|
||||
report.processes.protocolInput = await verifyWindowsProtocolInput(
|
||||
packageRoot,
|
||||
workspace,
|
||||
);
|
||||
const exited = launch([
|
||||
"--max-old-space-size=128",
|
||||
"-e",
|
||||
|
||||
@@ -13,6 +13,8 @@ import fixture from "../../fixtures/android/apidemos.json" with { type: "json" }
|
||||
import { verifyAndroidCliCancellation } from "./cli-cancellation.mjs";
|
||||
import { verifyAndroidMetadata } from "./metadata.mjs";
|
||||
import { verifyAndroidFailureRecovery } from "./failure-recovery.mjs";
|
||||
import { resolveJadxConfiguration } from "../../../dist/android/JadxConfiguration.js";
|
||||
import { verifyWindowsAndroidLifecycle } from "./windows-lifecycle.mjs";
|
||||
|
||||
const repository = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
|
||||
const apk = process.env.REA_ANDROID_TEST_APK;
|
||||
@@ -33,10 +35,10 @@ assert.equal(
|
||||
JADX_RELEASE.sha256,
|
||||
"Real Android lane requires the audited headless JADX release JAR",
|
||||
);
|
||||
const java =
|
||||
process.env.JAVA_HOME === undefined
|
||||
? "java"
|
||||
: resolve(process.env.JAVA_HOME, "bin/java");
|
||||
const { java, jvmArguments } = await resolveJadxConfiguration(
|
||||
process.env,
|
||||
"inspect_android_package",
|
||||
);
|
||||
const execute = promisify(execFile);
|
||||
await execute(java, ["-version"], { timeout: 10_000 });
|
||||
const entrypoint =
|
||||
@@ -49,6 +51,7 @@ await verifyAndroidMetadata({
|
||||
apk: path,
|
||||
repository,
|
||||
execute,
|
||||
jvmArguments,
|
||||
bridge: resolve(dirname(entrypoint), "../bridge/android/ReaJadxBridge.java"),
|
||||
});
|
||||
const tasks = [
|
||||
@@ -136,8 +139,8 @@ try {
|
||||
);
|
||||
assert.notEqual(response.isError, true, JSON.stringify(response));
|
||||
const structured = response.structuredContent;
|
||||
assert.ok(structured !== undefined && structured.evidence !== undefined);
|
||||
const evidence = parseEvidence(structured.evidence);
|
||||
assert.ok(structured !== undefined);
|
||||
const evidence = parseEvidence(structured);
|
||||
assert.deepEqual(
|
||||
evidence.normalized_result,
|
||||
cliResults.get(task.name).normalized_result,
|
||||
@@ -156,7 +159,7 @@ try {
|
||||
cliResults.get(task.name).limitations,
|
||||
);
|
||||
assert.equal(evidence.confidence, cliResults.get(task.name).confidence);
|
||||
assert.deepEqual(structured.result, evidence.normalized_result);
|
||||
assert.deepEqual(structured.normalized_result, evidence.normalized_result);
|
||||
console.log(`PASS MCP/CLI parity ${task.name}`);
|
||||
}
|
||||
} catch (cause) {
|
||||
@@ -200,15 +203,22 @@ assert.ok(
|
||||
reference.dex_offset === null && reference.source_line === null,
|
||||
),
|
||||
);
|
||||
await verifyAndroidCliCancellation({
|
||||
const lifecycleOptions = {
|
||||
entrypoint,
|
||||
environment,
|
||||
path,
|
||||
repository,
|
||||
execute,
|
||||
});
|
||||
};
|
||||
const windowsLifecycle =
|
||||
process.platform === "win32"
|
||||
? await verifyWindowsAndroidLifecycle(lifecycleOptions)
|
||||
: undefined;
|
||||
if (windowsLifecycle === undefined)
|
||||
await verifyAndroidCliCancellation(lifecycleOptions);
|
||||
await verifyAndroidFailureRecovery({
|
||||
java,
|
||||
jvmArguments,
|
||||
entrypoint,
|
||||
environment,
|
||||
path,
|
||||
@@ -230,7 +240,10 @@ const report = {
|
||||
cli_mcp_parity: true,
|
||||
original_apk_unchanged: true,
|
||||
apk_executed: false,
|
||||
cli_sigterm_cleanup: true,
|
||||
cli_sigterm_cleanup: process.platform !== "win32",
|
||||
...(windowsLifecycle === undefined
|
||||
? {}
|
||||
: { windows_lifecycle: windowsLifecycle }),
|
||||
metadata_without_code_generation: true,
|
||||
stable_overload_selection: true,
|
||||
};
|
||||
|
||||
@@ -17,6 +17,7 @@ import { TOOL_CONTRACTS } from "../../../dist/contracts/toolContracts.js";
|
||||
/** Real unusable Java runtimes and selectors must lead to applicable recovery. */
|
||||
export async function verifyAndroidFailureRecovery({
|
||||
java,
|
||||
jvmArguments = [],
|
||||
entrypoint,
|
||||
environment,
|
||||
path,
|
||||
@@ -25,6 +26,8 @@ export async function verifyAndroidFailureRecovery({
|
||||
fixture,
|
||||
}) {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-android-recovery-"));
|
||||
const javaName = process.platform === "win32" ? "java.exe" : "java";
|
||||
const jlinkName = process.platform === "win32" ? "jlink.exe" : "jlink";
|
||||
try {
|
||||
const withoutJar = { ...environment };
|
||||
delete withoutJar.REA_JADX_MCP_JAR;
|
||||
@@ -37,10 +40,10 @@ export async function verifyAndroidFailureRecovery({
|
||||
});
|
||||
let jlink;
|
||||
for (const candidate of isAbsolute(java)
|
||||
? [join(dirname(java), "jlink")]
|
||||
? [join(dirname(java), jlinkName)]
|
||||
: (environment.PATH ?? "")
|
||||
.split(delimiter)
|
||||
.map((directory) => join(directory, "jlink"))) {
|
||||
.map((directory) => join(directory, jlinkName))) {
|
||||
try {
|
||||
await access(candidate);
|
||||
jlink = candidate;
|
||||
@@ -54,10 +57,22 @@ export async function verifyAndroidFailureRecovery({
|
||||
"Android failure-recovery verification requires the full JDK's jlink via JAVA_HOME or PATH.",
|
||||
);
|
||||
const jre = join(root, "jre");
|
||||
await execute(jlink, ["--add-modules", "java.base", "--output", jre], {
|
||||
timeout: 60_000,
|
||||
await execute(
|
||||
jlink,
|
||||
[
|
||||
...jvmArguments.map((argument) => `-J${argument}`),
|
||||
"--add-modules",
|
||||
"java.base",
|
||||
"--output",
|
||||
jre,
|
||||
],
|
||||
{
|
||||
timeout: 60_000,
|
||||
},
|
||||
);
|
||||
await execute(join(jre, "bin", javaName), ["-version"], {
|
||||
timeout: 10_000,
|
||||
});
|
||||
await execute(join(jre, "bin/java"), ["-version"], { timeout: 10_000 });
|
||||
const empty = join(root, "empty-path");
|
||||
await mkdir(empty);
|
||||
if (process.platform === "linux") {
|
||||
@@ -75,6 +90,8 @@ export async function verifyAndroidFailureRecovery({
|
||||
}
|
||||
const withoutJavaHome = { ...environment };
|
||||
delete withoutJavaHome.JAVA_HOME;
|
||||
for (const key of Object.keys(withoutJavaHome))
|
||||
if (key.toLowerCase() === "path") delete withoutJavaHome[key];
|
||||
const invalidJar = join(root, "invalid.jar");
|
||||
await writeFile(invalidJar, "not a Java archive");
|
||||
const environments = [
|
||||
@@ -86,7 +103,8 @@ export async function verifyAndroidFailureRecovery({
|
||||
{
|
||||
label: "missing java",
|
||||
env: { ...withoutJavaHome, PATH: empty },
|
||||
observation: "ENOENT",
|
||||
observation:
|
||||
process.platform === "win32" ? "Cannot find java.exe" : "ENOENT",
|
||||
},
|
||||
{
|
||||
label: "invalid engine archive with a working JDK",
|
||||
@@ -224,7 +242,7 @@ export async function verifyAndroidFailureRecovery({
|
||||
);
|
||||
assert.notEqual(control.isError, true, JSON.stringify(control));
|
||||
assert.equal(
|
||||
control.structuredContent.result.package_name,
|
||||
control.structuredContent.normalized_result.package_name,
|
||||
fixture.package,
|
||||
);
|
||||
console.log("PASS MCP valid package after selector failures");
|
||||
|
||||
@@ -11,11 +11,16 @@ export const verifyAndroidMetadata = async ({
|
||||
bridge,
|
||||
repository,
|
||||
execute,
|
||||
jvmArguments = [],
|
||||
}) => {
|
||||
const javac =
|
||||
process.env.JAVA_HOME === undefined
|
||||
? "javac"
|
||||
: resolve(process.env.JAVA_HOME, "bin/javac");
|
||||
: resolve(
|
||||
process.env.JAVA_HOME,
|
||||
"bin",
|
||||
process.platform === "win32" ? "javac.exe" : "javac",
|
||||
);
|
||||
try {
|
||||
await execute(javac, ["-version"], { timeout: 10_000 });
|
||||
} catch (cause) {
|
||||
@@ -29,6 +34,7 @@ export const verifyAndroidMetadata = async ({
|
||||
await execute(
|
||||
javac,
|
||||
[
|
||||
...jvmArguments.map((argument) => `-J${argument}`),
|
||||
"-classpath",
|
||||
jar,
|
||||
"-d",
|
||||
@@ -44,6 +50,7 @@ export const verifyAndroidMetadata = async ({
|
||||
const result = await execute(
|
||||
java,
|
||||
[
|
||||
...jvmArguments,
|
||||
"-classpath",
|
||||
`${classes}${delimiter}${jar}`,
|
||||
"ReaJadxMetadataRegression",
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { spawn } from "node:child_process";
|
||||
import {
|
||||
mkdtemp,
|
||||
readdir,
|
||||
realpath,
|
||||
rmdir,
|
||||
symlink,
|
||||
unlink,
|
||||
} from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { setTimeout as delay } from "node:timers/promises";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { resolveJadxConfiguration } from "../../../dist/android/JadxConfiguration.js";
|
||||
|
||||
/** Verify real Windows cancellation, disconnect and abrupt CLI owner exit. */
|
||||
export async function verifyWindowsAndroidLifecycle(options) {
|
||||
assert.equal(process.platform, "win32");
|
||||
await verifyJavaSelection(options.environment);
|
||||
const cancellation = await verifyMcp(options, "cancel");
|
||||
await verifyMcp(options, "disconnect");
|
||||
await verifyCliOwnerExit(options);
|
||||
return {
|
||||
mcp_cancelled_engine_exited: true,
|
||||
mcp_cancelled_workspace_removed: true,
|
||||
mcp_ping_and_next_call: true,
|
||||
mcp_disconnect_engine_exited: true,
|
||||
cli_abrupt_owner_exit_engine_exited: true,
|
||||
// A forced Windows process exit cannot execute JavaScript workspace cleanup.
|
||||
cli_abrupt_owner_exit_workspace_cleanup: false,
|
||||
observed_resources: cancellation,
|
||||
java_home_and_quoted_case_insensitive_path: true,
|
||||
};
|
||||
}
|
||||
|
||||
async function verifyJavaSelection(environment) {
|
||||
const selected = await resolveJadxConfiguration(
|
||||
environment,
|
||||
"inspect_android_package",
|
||||
);
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-windows-java-selection-"));
|
||||
const alias = join(root, "JDK 路径 with spaces");
|
||||
const pathEnvironment = Object.fromEntries(
|
||||
Object.entries(environment).filter(
|
||||
([key]) => !["path", "java_home"].includes(key.toLowerCase()),
|
||||
),
|
||||
);
|
||||
try {
|
||||
// The owned junction borrows the selected JDK directory without copying it.
|
||||
await symlink(dirname(selected.java), alias, "junction");
|
||||
pathEnvironment.Path = `"${alias}"`;
|
||||
const onPath = await resolveJadxConfiguration(
|
||||
pathEnvironment,
|
||||
"inspect_android_package",
|
||||
);
|
||||
assert.equal(onPath.java, await realpath(selected.java));
|
||||
console.log(
|
||||
"PASS Windows JAVA_HOME and quoted Unicode/space Path selection",
|
||||
);
|
||||
} finally {
|
||||
await unlink(alias).catch((cause) => {
|
||||
if (cause.code !== "ENOENT") throw cause;
|
||||
});
|
||||
await rmdir(root);
|
||||
}
|
||||
}
|
||||
|
||||
async function verifyMcp({ entrypoint, environment, path, repository }, mode) {
|
||||
const baseline = await runtimeRoots();
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
cwd: repository,
|
||||
env: environment,
|
||||
stderr: "pipe",
|
||||
});
|
||||
let stderr = "";
|
||||
transport.stderr?.on("data", (chunk) => {
|
||||
stderr = (stderr + chunk.toString()).slice(-65536);
|
||||
});
|
||||
const client = new Client({
|
||||
name: `rea-windows-android-${mode}`,
|
||||
version: "1",
|
||||
});
|
||||
let observer;
|
||||
try {
|
||||
await client.connect(transport);
|
||||
assert.ok(transport.pid !== null);
|
||||
observer = observeJava(transport.pid);
|
||||
const controller = new AbortController();
|
||||
const pending = client
|
||||
.callTool(
|
||||
{ name: "inspect_android_package", arguments: { path } },
|
||||
{ timeout: 150000, signal: controller.signal },
|
||||
)
|
||||
.then(
|
||||
(response) => ({ response }),
|
||||
(error) => ({ error }),
|
||||
);
|
||||
const resources = await observer.acquired;
|
||||
if (mode === "cancel") controller.abort();
|
||||
else await client.close();
|
||||
const outcome = await deadline(pending, 15000);
|
||||
assert.ok("error" in outcome, "Cancelled request published a success");
|
||||
await observer.verifyExit();
|
||||
await waitFor(
|
||||
async () => {
|
||||
const remaining = await runtimeRoots();
|
||||
return remaining.every((root) => baseline.includes(root));
|
||||
},
|
||||
15000,
|
||||
"Owned Android workspace remained after cleanup",
|
||||
);
|
||||
if (mode === "cancel") {
|
||||
await waitFor(
|
||||
() => stderr.includes('"status":"error"'),
|
||||
15000,
|
||||
`Server did not finish the cancelled request: ${stderr}`,
|
||||
);
|
||||
assert.ok(
|
||||
!stderr.includes('"status":"ok"'),
|
||||
"Cancelled operation was logged successful",
|
||||
);
|
||||
await client.ping();
|
||||
const next = await client.callTool(
|
||||
{ name: "inspect_android_package", arguments: { path } },
|
||||
{ timeout: 150000 },
|
||||
);
|
||||
assert.notEqual(next.isError, true, JSON.stringify(next));
|
||||
assert.ok(next.structuredContent?.evidence_id);
|
||||
}
|
||||
console.log(
|
||||
`PASS Windows MCP ${mode}: real Java exit and workspace cleanup`,
|
||||
);
|
||||
return resources;
|
||||
} finally {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
await observer?.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function verifyCliOwnerExit({
|
||||
entrypoint,
|
||||
environment,
|
||||
path,
|
||||
repository,
|
||||
}) {
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
[entrypoint, "inspect-android-package", path, "--format", "json"],
|
||||
{ cwd: repository, env: environment, stdio: ["ignore", "pipe", "pipe"] },
|
||||
);
|
||||
let output = "";
|
||||
child.stdout.on("data", (chunk) => {
|
||||
output = (output + chunk.toString()).slice(-65536);
|
||||
});
|
||||
child.stderr.resume();
|
||||
const exited = new Promise((resolve, reject) => {
|
||||
child.once("error", reject);
|
||||
child.once("close", resolve);
|
||||
});
|
||||
assert.ok(child.pid !== undefined);
|
||||
const observer = observeJava(child.pid);
|
||||
try {
|
||||
await observer.acquired;
|
||||
// Node's Windows SIGTERM terminates the retained child handle abruptly.
|
||||
// The Java job must settle through kill-on-owner-close without JS cleanup.
|
||||
assert.equal(child.kill(), true);
|
||||
await deadline(exited, 15000);
|
||||
await observer.verifyExit();
|
||||
assert.equal(output, "", "Aborted CLI published successful Evidence");
|
||||
console.log("PASS Windows CLI abrupt owner exit: real Java job cleanup");
|
||||
} finally {
|
||||
if (child.exitCode === null && child.signalCode === null) child.kill();
|
||||
await deadline(exited, 15000);
|
||||
await observer.close();
|
||||
}
|
||||
}
|
||||
|
||||
function observeJava(ownerPid) {
|
||||
assert.ok(Number.isSafeInteger(ownerPid) && ownerPid > 0);
|
||||
// Retain actual process handles and creation times. The process table only
|
||||
// discovers the child; no PID or executable path grants termination authority.
|
||||
const source = `
|
||||
$ErrorActionPreference='Stop'
|
||||
$owner=Get-Process -Id ${ownerPid}
|
||||
$null=$owner.Handle; $ownerStart=$owner.StartTime
|
||||
$java=$null; $deadline=[DateTime]::UtcNow.AddSeconds(45)
|
||||
try {
|
||||
while ([DateTime]::UtcNow -lt $deadline) {
|
||||
if ($owner.HasExited) { throw 'REA owner exited before Java acquisition' }
|
||||
$rows=Get-CimInstance Win32_Process -Filter 'ParentProcessId = ${ownerPid}'
|
||||
foreach ($row in $rows) {
|
||||
if ($row.Name -eq 'java.exe' -and $row.CommandLine -like '*ReaJadxBridge.java*') {
|
||||
$candidate=Get-Process -Id $row.ProcessId
|
||||
$null=$candidate.Handle
|
||||
$sameCreation=$candidate.StartTime.ToUniversalTime().ToString('yyyyMMddHHmmssffffff') -eq $row.CreationDate.ToUniversalTime().ToString('yyyyMMddHHmmssffffff')
|
||||
if ($sameCreation -and $candidate.StartTime -ge $ownerStart -and !$candidate.HasExited) {
|
||||
$java=$candidate
|
||||
$resourceArgs=@([regex]::Matches($row.CommandLine,'-Xmx[0-9]+m|-XX:ActiveProcessorCount=[0-9]+') | ForEach-Object {$_.Value})
|
||||
@{affinity=[int64]$java.ProcessorAffinity; priority=[string]$java.PriorityClass; jvm_arguments=$resourceArgs} | ConvertTo-Json -Compress
|
||||
break
|
||||
}
|
||||
$candidate.Dispose()
|
||||
}
|
||||
}
|
||||
if ($null -ne $java) { break }
|
||||
Start-Sleep -Milliseconds 100
|
||||
}
|
||||
if ($null -eq $java) { throw 'No real owned Java engine was acquired' }
|
||||
$null=[Console]::ReadLine()
|
||||
if (!$java.WaitForExit(15000)) { throw 'Retained Java process did not exit' }
|
||||
@{exited=$java.HasExited} | ConvertTo-Json -Compress
|
||||
} finally { if ($null -ne $java) {$java.Dispose()}; $owner.Dispose() }
|
||||
`;
|
||||
const observer = spawn(
|
||||
join(
|
||||
process.env.SystemRoot ?? "C:\\Windows",
|
||||
"System32",
|
||||
"WindowsPowerShell",
|
||||
"v1.0",
|
||||
"powershell.exe",
|
||||
),
|
||||
[
|
||||
"-NoProfile",
|
||||
"-NonInteractive",
|
||||
"-EncodedCommand",
|
||||
Buffer.from(source, "utf16le").toString("base64"),
|
||||
],
|
||||
{ stdio: ["pipe", "pipe", "pipe"], windowsHide: true },
|
||||
);
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
observer.stdout.on("data", (chunk) => {
|
||||
stdout = (stdout + chunk.toString()).slice(-65536);
|
||||
});
|
||||
observer.stderr.on("data", (chunk) => {
|
||||
stderr = (stderr + chunk.toString()).slice(-65536);
|
||||
});
|
||||
const exited = new Promise((resolve, reject) => {
|
||||
observer.once("error", reject);
|
||||
observer.once("close", resolve);
|
||||
});
|
||||
const acquired = waitFor(
|
||||
() => stdout.includes("\n") || observer.exitCode !== null,
|
||||
50000,
|
||||
"Java process observer did not acquire a handle",
|
||||
).then(() => {
|
||||
assert.ok(stdout.includes("\n"), stderr);
|
||||
return JSON.parse(stdout.split(/\r?\n/u)[0]);
|
||||
});
|
||||
return {
|
||||
acquired,
|
||||
async verifyExit() {
|
||||
observer.stdin.end("verify\n");
|
||||
assert.equal(await deadline(exited, 20000), 0, stderr);
|
||||
assert.equal(
|
||||
JSON.parse(stdout.trim().split(/\r?\n/u).at(-1)).exited,
|
||||
true,
|
||||
);
|
||||
},
|
||||
async close() {
|
||||
if (observer.exitCode === null && observer.signalCode === null) {
|
||||
observer.stdin.end();
|
||||
observer.kill();
|
||||
}
|
||||
await deadline(exited, 20000);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function runtimeRoots() {
|
||||
return (await readdir(tmpdir())).filter((name) =>
|
||||
name.startsWith("rea-android-"),
|
||||
);
|
||||
}
|
||||
|
||||
async function waitFor(predicate, milliseconds, message) {
|
||||
const until = Date.now() + milliseconds;
|
||||
while (Date.now() < until) {
|
||||
if (await predicate()) return;
|
||||
await delay(50);
|
||||
}
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
async function deadline(promise, milliseconds) {
|
||||
let timer;
|
||||
return Promise.race([
|
||||
promise,
|
||||
new Promise((_, reject) => {
|
||||
timer = setTimeout(
|
||||
() => reject(new Error("Windows lifecycle deadline exceeded")),
|
||||
milliseconds,
|
||||
);
|
||||
}),
|
||||
]).finally(() => clearTimeout(timer));
|
||||
}
|
||||
@@ -109,10 +109,10 @@ window.loadFile("renderer.html");require("node:fs").writeFileSync(${JSON.stringi
|
||||
let targets;
|
||||
for (let attempt = 0; attempt < 30; attempt++) {
|
||||
targets = await call("list_electron_targets", { cdp_endpoint: endpoint });
|
||||
if (targets.result.targets.length > 0) break;
|
||||
if (targets.normalized_result.targets.length > 0) break;
|
||||
await pause(100);
|
||||
}
|
||||
const target = targets.result.targets.find(
|
||||
const target = targets.normalized_result.targets.find(
|
||||
(item) => item.file_path === join(root, "renderer.html"),
|
||||
);
|
||||
assert.ok(target, JSON.stringify(targets));
|
||||
@@ -123,7 +123,7 @@ window.loadFile("renderer.html");require("node:fs").writeFileSync(${JSON.stringi
|
||||
observation_ms: 50,
|
||||
});
|
||||
assert.ok(
|
||||
page.result.scripts.items.some(
|
||||
page.normalized_result.scripts.items.some(
|
||||
(script) =>
|
||||
script.file_path === join(root, "renderer.js") &&
|
||||
script.source.included,
|
||||
@@ -135,13 +135,13 @@ window.loadFile("renderer.html");require("node:fs").writeFileSync(${JSON.stringi
|
||||
const reconciled = await call("reconcile_javascript_runtime", {
|
||||
static_layers: [
|
||||
{
|
||||
analysis: staticAnalysis.evidence,
|
||||
analysis: staticAnalysis,
|
||||
runtime_mappings: [{ kind: "file-root", root }],
|
||||
},
|
||||
],
|
||||
runtime_observations: [page.evidence],
|
||||
runtime_observations: [page],
|
||||
});
|
||||
assert.ok(reconciled.result.runtime_captures.length > 0);
|
||||
assert.ok(reconciled.normalized_result.runtime_captures.length > 0);
|
||||
const cli = await execute(
|
||||
process.execPath,
|
||||
[
|
||||
@@ -174,7 +174,7 @@ window.loadFile("renderer.html");require("node:fs").writeFileSync(${JSON.stringi
|
||||
);
|
||||
const capture = active.isError
|
||||
? requireMcpToolError(active).details.partial_observation.capture
|
||||
: active.structuredContent.result;
|
||||
: active.structuredContent.normalized_result;
|
||||
if (active.isError) {
|
||||
assert.equal(
|
||||
requireMcpToolError(active).code,
|
||||
|
||||
@@ -149,13 +149,13 @@ try {
|
||||
{ timeout: 30_000 },
|
||||
);
|
||||
const inspectedMcp = await call("inspect_firmware_regions", { path });
|
||||
const mcpEvidence = parseEvidence(inspectedMcp.evidence);
|
||||
const mcpEvidence = parseEvidence(inspectedMcp);
|
||||
assert.deepEqual(verifyRegions(mcpEvidence), cliRegions);
|
||||
const extractedMcp = await call("extract_firmware", {
|
||||
path,
|
||||
output_directory: join(root, "mcp-output"),
|
||||
});
|
||||
const mcpFiles = await verifyFiles(parseEvidence(extractedMcp.evidence));
|
||||
const mcpFiles = await verifyFiles(parseEvidence(extractedMcp));
|
||||
const contentIdentity = (result) =>
|
||||
result.files.map(({ relative_path, sha256, size }) => ({
|
||||
relative_path,
|
||||
@@ -168,7 +168,7 @@ try {
|
||||
output_directory: join(root, "selected-output"),
|
||||
range: { offset: oracle.offset, length: oracle.length },
|
||||
});
|
||||
const selectedFiles = await verifyFiles(parseEvidence(selected.evidence));
|
||||
const selectedFiles = await verifyFiles(parseEvidence(selected));
|
||||
assert.equal(selectedFiles.selection.offset, oracle.offset);
|
||||
assert.equal(selectedFiles.selection.length, oracle.length);
|
||||
const depth = await call("extract_firmware", {
|
||||
@@ -177,7 +177,7 @@ try {
|
||||
max_depth: 1,
|
||||
});
|
||||
const depthResult = firmwareResultSchemas.extract_firmware.parse(
|
||||
depth.result,
|
||||
depth.normalized_result,
|
||||
);
|
||||
assert.equal(depthResult.coverage, "partial");
|
||||
assert.ok(depthResult.depth_limited_paths.length > 0);
|
||||
@@ -192,7 +192,7 @@ try {
|
||||
output_directory: join(root, "ext4-output"),
|
||||
});
|
||||
const result = firmwareResultSchemas.extract_firmware.parse(
|
||||
response.result,
|
||||
response.normalized_result,
|
||||
);
|
||||
assert.ok(result.chunks.some((chunk) => chunk.handler === "extfs"));
|
||||
assert.equal(result.coverage, "complete");
|
||||
@@ -234,7 +234,7 @@ try {
|
||||
const dossier = await call("analyze_function", {
|
||||
procedure: "firmware_probe",
|
||||
});
|
||||
const evidence = parseEvidence(dossier.evidence);
|
||||
const evidence = parseEvidence(dossier);
|
||||
assert.equal(
|
||||
evidence.subject.digest.sha256,
|
||||
oracle.files["usr/bin/probe"].sha256,
|
||||
@@ -242,7 +242,7 @@ try {
|
||||
const pseudocode = await call("procedure_pseudo_code", {
|
||||
procedure: "firmware_probe",
|
||||
});
|
||||
assert.equal(parseEvidence(pseudocode.evidence).provider.id, "ghidra");
|
||||
assert.equal(parseEvidence(pseudocode).provider.id, "ghidra");
|
||||
assert.ok(
|
||||
JSON.stringify(evidence.normalized_result).includes("firmware_probe"),
|
||||
);
|
||||
|
||||
@@ -170,8 +170,8 @@ async function runMcp(name, arguments_) {
|
||||
true,
|
||||
JSON.stringify(response.structuredContent),
|
||||
);
|
||||
assert.ok(response.structuredContent?.result);
|
||||
return response.structuredContent.result;
|
||||
assert.ok(response.structuredContent?.normalized_result);
|
||||
return response.structuredContent.normalized_result;
|
||||
}
|
||||
|
||||
async function inspectorUrl(process_) {
|
||||
|
||||
@@ -45,7 +45,7 @@ const call = async (name, args) => {
|
||||
timeout: 150000,
|
||||
});
|
||||
assert.notEqual(result.isError, true, mcpTextValue(result));
|
||||
return parseEvidence(JSON.parse(mcpTextValue(result)).evidence);
|
||||
return parseEvidence(JSON.parse(mcpTextValue(result)));
|
||||
};
|
||||
const fingerprint = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
||||
const counts = [];
|
||||
|
||||
@@ -47,8 +47,8 @@ export async function connectRecordedCrash({ entrypoint, environment }) {
|
||||
return value.error;
|
||||
}
|
||||
assert.notEqual(response.isError, true, JSON.stringify(value));
|
||||
evidence = parseEvidence(value.evidence);
|
||||
assert.deepEqual(value.result, evidence.normalized_result);
|
||||
evidence = parseEvidence(value);
|
||||
assert.deepEqual(value.normalized_result, evidence.normalized_result);
|
||||
} else {
|
||||
assert.equal(mode, "cli");
|
||||
let response;
|
||||
|
||||
Reference in New Issue
Block a user