fix(verification): integrate Linux Hopper lane with current contracts
Integrate mainae8051302while retaining the Linux setup, orphan detection, launcher restoration and explicit string-recognition coverage corrections. Move verification guidance to its current owner and use the test-scoped temporary-directory helper. The checkout matches all 3,175 exported source-file digests of the tested candidate. Git stores the Windows captureGhidraLaunch.cmd fixture with LF; its exported checkout uses CRLF per .gitattributes. It is outside Linux Hopper execution. No native run is attributed to different runtime bytes. Real Hopper conformance: 9e7de373-4686-4820-ae48-801e536589b7. Uninterrupted Linux setup: 93584b53-944b-47cf-a6a4-b0d4ff8a4961. The exact97b76aa2run remains separate: ae4de7ff-dd2a-4c73-88dc-6dbf1ad7c537. 21 focused tests, check, docs:check, four fixtures, discovery, package verification and pack dry-run passed. Linux native decoded omissions, macOS/other builds and installed npm artifacts with Hopper remain unverified. Refs #339, #340
This commit is contained in:
@@ -1 +0,0 @@
|
||||
export const bundleMcpRuntime: (root: string) => Promise<void>;
|
||||
@@ -1,104 +0,0 @@
|
||||
import { parse } from "@babel/parser";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
|
||||
/**
|
||||
* Reduce filesystem resolution during MCP startup. Keep dependencies external,
|
||||
* dynamic imports lazy, and the original compiled files for CLI/worker entrypoints.
|
||||
*/
|
||||
export const bundleMcpRuntime = async (root) => {
|
||||
const compiledRoot = join(root, "dist");
|
||||
const { rolldown, RUNTIME_MODULE_ID } = await import("rolldown");
|
||||
const { imports = {} } = JSON.parse(
|
||||
await readFile(join(root, "package.json"), "utf8"),
|
||||
);
|
||||
const bundle = await rolldown({
|
||||
input: { main: join(compiledRoot, "main.js") },
|
||||
platform: "node",
|
||||
treeshake: false,
|
||||
external: (source) => !source.startsWith(".") && !isAbsolute(source),
|
||||
plugins: [
|
||||
{
|
||||
name: "preserve-compiled-module-locations",
|
||||
transform(code, id) {
|
||||
if (id === RUNTIME_MODULE_ID) return null;
|
||||
if (!code.includes("import.meta")) return null;
|
||||
const sourcePath = relative(compiledRoot, id);
|
||||
if (
|
||||
isAbsolute(sourcePath) ||
|
||||
sourcePath === ".." ||
|
||||
sourcePath.startsWith(`..${sep}`)
|
||||
)
|
||||
throw new Error(`MCP bundle input is outside dist: ${id}`);
|
||||
// All chunks are directly under dist/mcp. Preserve the original
|
||||
// module URL, including URL escaping, for bridges and createRequire.
|
||||
const moduleUrl = `new URL(${JSON.stringify(`../${sourcePath.split(sep).map(encodeURIComponent).join("/")}`)}, import.meta.url).href`;
|
||||
const edits = [];
|
||||
const visit = (node) => {
|
||||
if (node === null || typeof node !== "object") return;
|
||||
const isMeta = (value) =>
|
||||
value?.type === "MetaProperty" &&
|
||||
value.meta.name === "import" &&
|
||||
value.property.name === "meta";
|
||||
if (
|
||||
node.type === "CallExpression" &&
|
||||
node.callee.type === "MemberExpression" &&
|
||||
!node.callee.computed &&
|
||||
isMeta(node.callee.object) &&
|
||||
node.callee.property.name === "resolve" &&
|
||||
node.arguments.length === 1 &&
|
||||
node.arguments[0].type === "StringLiteral" &&
|
||||
Object.hasOwn(imports, node.arguments[0].value)
|
||||
)
|
||||
// Package imports resolve in the same package scope after bundling.
|
||||
return;
|
||||
if (
|
||||
node.type === "MemberExpression" &&
|
||||
!node.computed &&
|
||||
isMeta(node.object) &&
|
||||
node.property.name === "url"
|
||||
) {
|
||||
edits.push({ start: node.start, end: node.end });
|
||||
return;
|
||||
}
|
||||
if (isMeta(node))
|
||||
throw new Error(
|
||||
`Unsupported import.meta use in MCP bundle: ${id}`,
|
||||
);
|
||||
for (const value of Object.values(node)) {
|
||||
if (Array.isArray(value)) value.forEach(visit);
|
||||
else visit(value);
|
||||
}
|
||||
};
|
||||
visit(parse(code, { sourceType: "module" }).program);
|
||||
for (const { start, end } of edits.sort((a, b) => b.start - a.start))
|
||||
code = code.slice(0, start) + moduleUrl + code.slice(end);
|
||||
return { code, map: null };
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
try {
|
||||
await bundle.write({
|
||||
dir: join(compiledRoot, "mcp"),
|
||||
format: "esm",
|
||||
entryFileNames: "[name].js",
|
||||
chunkFileNames: "[name]-[hash].js",
|
||||
codeSplitting: true,
|
||||
strictExecutionOrder: true,
|
||||
minify: false,
|
||||
sourcemap: false,
|
||||
});
|
||||
} finally {
|
||||
await bundle.close();
|
||||
}
|
||||
};
|
||||
|
||||
if (
|
||||
process.argv[1] !== undefined &&
|
||||
pathToFileURL(resolve(process.argv[1])).href === import.meta.url
|
||||
)
|
||||
await bundleMcpRuntime(
|
||||
resolve(dirname(fileURLToPath(import.meta.url)), ".."),
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
export const bundleRuntime: (root: string) => Promise<void>;
|
||||
@@ -0,0 +1,140 @@
|
||||
import { parse } from "@babel/parser";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
|
||||
/**
|
||||
* Reduce filesystem resolution during CLI and MCP startup. Keep dependencies
|
||||
* external, dynamic imports lazy, and original compiled worker entrypoints.
|
||||
*/
|
||||
export const bundleRuntime = async (root) => {
|
||||
const compiledRoot = resolve(root, "dist");
|
||||
// CLI, MCP, workers and updater fixtures share one release-identity owner.
|
||||
const metadataModule = join(compiledRoot, "generatedPackageMetadata.js");
|
||||
const isMetadataModule = (id) =>
|
||||
isAbsolute(id) && resolve(id) === metadataModule;
|
||||
const { rolldown, RUNTIME_MODULE_ID } = await import("rolldown");
|
||||
const { imports = {} } = JSON.parse(
|
||||
await readFile(join(root, "package.json"), "utf8"),
|
||||
);
|
||||
for (const [directory, entries] of [
|
||||
["mcp", { main: "main.js" }],
|
||||
[
|
||||
"cli-runtime",
|
||||
{
|
||||
cli: "cli.js",
|
||||
cliOutput: "cliOutput.js",
|
||||
cliResultOutput: "cli/cliResultOutput.js",
|
||||
mcpDoctor: "mcpDoctor.js",
|
||||
},
|
||||
],
|
||||
]) {
|
||||
const bundle = await rolldown({
|
||||
input: Object.fromEntries(
|
||||
Object.entries(entries).map(([name, path]) => [
|
||||
name,
|
||||
join(compiledRoot, path),
|
||||
]),
|
||||
),
|
||||
platform: "node",
|
||||
treeshake: false,
|
||||
external: (source) =>
|
||||
isMetadataModule(source) ||
|
||||
(!source.startsWith(".") && !isAbsolute(source)),
|
||||
plugins: [
|
||||
{
|
||||
name: "preserve-compiled-module-locations",
|
||||
transform(code, id) {
|
||||
if (id === RUNTIME_MODULE_ID) return null;
|
||||
if (!code.includes("import.meta")) return null;
|
||||
const sourcePath = relative(compiledRoot, id);
|
||||
if (
|
||||
isAbsolute(sourcePath) ||
|
||||
sourcePath === ".." ||
|
||||
sourcePath.startsWith(`..${sep}`)
|
||||
)
|
||||
throw new Error(`Runtime bundle input is outside dist: ${id}`);
|
||||
// Each output directory is directly under dist. Preserve the original
|
||||
// module URL, including URL escaping, for bridges and createRequire.
|
||||
const moduleUrl = `new URL(${JSON.stringify(`../${sourcePath.split(sep).map(encodeURIComponent).join("/")}`)}, import.meta.url).href`;
|
||||
const edits = [];
|
||||
const visit = (node) => {
|
||||
if (node === null || typeof node !== "object") return;
|
||||
const isMeta = (value) =>
|
||||
value?.type === "MetaProperty" &&
|
||||
value.meta.name === "import" &&
|
||||
value.property.name === "meta";
|
||||
if (
|
||||
node.type === "CallExpression" &&
|
||||
node.callee.type === "MemberExpression" &&
|
||||
!node.callee.computed &&
|
||||
isMeta(node.callee.object) &&
|
||||
node.callee.property.name === "resolve" &&
|
||||
node.arguments.length === 1 &&
|
||||
node.arguments[0].type === "StringLiteral" &&
|
||||
Object.hasOwn(imports, node.arguments[0].value)
|
||||
)
|
||||
// Package imports resolve in the same package scope after bundling.
|
||||
return;
|
||||
if (
|
||||
node.type === "MemberExpression" &&
|
||||
!node.computed &&
|
||||
isMeta(node.object) &&
|
||||
node.property.name === "url"
|
||||
) {
|
||||
edits.push({ start: node.start, end: node.end });
|
||||
return;
|
||||
}
|
||||
if (isMeta(node))
|
||||
throw new Error(
|
||||
`Unsupported import.meta use in runtime bundle: ${id}`,
|
||||
);
|
||||
for (const value of Object.values(node)) {
|
||||
if (Array.isArray(value)) value.forEach(visit);
|
||||
else visit(value);
|
||||
}
|
||||
};
|
||||
visit(parse(code, { sourceType: "module" }).program);
|
||||
for (const { start, end } of edits.sort(
|
||||
(a, b) => b.start - a.start,
|
||||
))
|
||||
code = code.slice(0, start) + moduleUrl + code.slice(end);
|
||||
return { code, map: null };
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
try {
|
||||
await bundle.write({
|
||||
dir: join(compiledRoot, directory),
|
||||
format: "esm",
|
||||
entryFileNames: "[name].js",
|
||||
chunkFileNames:
|
||||
directory === "mcp"
|
||||
? "[name]-[hash].js"
|
||||
: (chunk) => {
|
||||
// Keep lazy facades distinguishable when source basenames repeat.
|
||||
if (typeof chunk.facadeModuleId !== "string")
|
||||
return "[name]-[hash].js";
|
||||
const path = relative(compiledRoot, chunk.facadeModuleId);
|
||||
return `${path.replace(/\.js$/u, "").split(sep).join("__")}-[hash].js`;
|
||||
},
|
||||
paths: (id) =>
|
||||
isMetadataModule(id) ? "../generatedPackageMetadata.js" : id,
|
||||
minifyInternalExports: directory === "mcp",
|
||||
codeSplitting: true,
|
||||
strictExecutionOrder: true,
|
||||
minify: false,
|
||||
sourcemap: false,
|
||||
});
|
||||
} finally {
|
||||
await bundle.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (
|
||||
process.argv[1] !== undefined &&
|
||||
pathToFileURL(resolve(process.argv[1])).href === import.meta.url
|
||||
)
|
||||
await bundleRuntime(resolve(dirname(fileURLToPath(import.meta.url)), ".."));
|
||||
+44
-15
@@ -1,24 +1,30 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { appendFileSync } from "node:fs";
|
||||
import { matchesGlob } from "node:path";
|
||||
import { SCOPES } from "./scopes.mjs";
|
||||
import { MANUAL_VERIFIERS, SCOPES } from "./scopes.mjs";
|
||||
|
||||
const flags = [
|
||||
"code",
|
||||
"runtime",
|
||||
"package",
|
||||
"apple",
|
||||
"fixtures",
|
||||
"readiness",
|
||||
"docs",
|
||||
"workflows",
|
||||
...Object.keys(SCOPES),
|
||||
...new Set([
|
||||
"code",
|
||||
"runtime",
|
||||
"package",
|
||||
"apple",
|
||||
"fixtures",
|
||||
"readiness",
|
||||
"docs",
|
||||
"workflows",
|
||||
...Object.keys(SCOPES),
|
||||
]),
|
||||
];
|
||||
// Test files select the native-host lanes that run them explicitly. Provider
|
||||
// scopes remain implementation-owned, so test-only edits stay off those lanes.
|
||||
const NATIVE_TEST_OWNERS = ["apple", "package"];
|
||||
// Actionlint validates workflow syntax only. The semantic suite asserts these
|
||||
// workflows' release, publication and self-hosted runner safeguards.
|
||||
const GUARDED_WORKFLOWS = new Set([
|
||||
".github/workflows/release.yml",
|
||||
".github/workflows/real-ghidra-windows.yml",
|
||||
".github/workflows/sqlite-runtime.yml",
|
||||
]);
|
||||
// Sources compiled by build-conformance-fixtures.mjs. The readiness journey
|
||||
// analyzes the built C fixture as well as its own applications.
|
||||
@@ -87,11 +93,11 @@ function classifyPackage(base, head) {
|
||||
const scriptOwners =
|
||||
simple &&
|
||||
entries.every((entry) =>
|
||||
Object.values(SCOPES).some((patterns) => patterns.includes(entry)),
|
||||
Object.values(SCOPES).some((patterns) => matchesAny(entry, patterns)),
|
||||
)
|
||||
? Object.entries(SCOPES)
|
||||
.filter(([, patterns]) =>
|
||||
entries.some((entry) => patterns.includes(entry)),
|
||||
entries.some((entry) => matchesAny(entry, patterns)),
|
||||
)
|
||||
.map(([owner]) => owner)
|
||||
: [];
|
||||
@@ -119,14 +125,23 @@ if (
|
||||
.filter(Boolean);
|
||||
for (const file of files) {
|
||||
if (
|
||||
/^(README(?:_[^/]+)?\.md|AGENTS\.md|CONTRIBUTING\.md)$/.test(file) ||
|
||||
file.startsWith("docs/")
|
||||
/^(README(?:_[^/]+)?\.md|AGENTS\.md|CONTRIBUTING\.md|CHANGELOG\.md|SECURITY\.md|native\/windows\/README\.md|\.github\/pull_request_template\.md)$/.test(
|
||||
file,
|
||||
) ||
|
||||
file.startsWith("docs/") ||
|
||||
file.startsWith(".github/ISSUE_TEMPLATE/")
|
||||
) {
|
||||
selected.docs = true;
|
||||
selected.website ||= matchesAny(file, SCOPES.website);
|
||||
continue;
|
||||
}
|
||||
if (/^(src|tests)\/.*\.(?:test|spec)\.[cm]?[jt]sx?$/.test(file)) {
|
||||
selected.code = true;
|
||||
for (const owner of NATIVE_TEST_OWNERS)
|
||||
selected[owner] ||= matchesAny(file, SCOPES[owner]);
|
||||
continue;
|
||||
}
|
||||
if (matchesAny(file, MANUAL_VERIFIERS)) {
|
||||
selected.code = true;
|
||||
continue;
|
||||
}
|
||||
@@ -166,6 +181,14 @@ if (
|
||||
} else if (owners.length) {
|
||||
if (file.startsWith("src/") || file.startsWith("bridge/"))
|
||||
selected.runtime = true;
|
||||
} else if (/^(src|bridge)\//.test(file)) {
|
||||
// Unowned runtime sources keep the Linux x64 installed-package baseline;
|
||||
// ci:full, main pushes and manual dispatch retain every native host.
|
||||
selected.runtime = true;
|
||||
reasons.push(`Unowned runtime source: ${file}`);
|
||||
} else if (file.startsWith(".agents/skills/")) {
|
||||
selected.runtime = true;
|
||||
selected.docs = true;
|
||||
} else {
|
||||
full(`Unclassified input: ${file}`);
|
||||
}
|
||||
@@ -173,13 +196,19 @@ if (
|
||||
} else throw new Error(`Unsupported CI event: ${event}`);
|
||||
selected.runtime ||= selected.package;
|
||||
const linux = { os: "ubuntu-latest", platform: "linux", architecture: "x64" };
|
||||
// macOS x64 is the slowest package host. Pull requests run it only with ci:full;
|
||||
// main pushes, schedules and manual dispatch always include it.
|
||||
const intel =
|
||||
event !== "pull_request" || process.env.CI_FULL === "true"
|
||||
? [{ os: "macos-15-intel", platform: "darwin", architecture: "x64" }]
|
||||
: [];
|
||||
const matrix = {
|
||||
include: selected.package
|
||||
? [
|
||||
linux,
|
||||
{ os: "ubuntu-24.04-arm", platform: "linux", architecture: "arm64" },
|
||||
{ os: "macos-15", platform: "darwin", architecture: "arm64" },
|
||||
{ os: "macos-15-intel", platform: "darwin", architecture: "x64" },
|
||||
...intel,
|
||||
]
|
||||
: [linux],
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ const jobs = JSON.parse(process.env.CI_JOBS);
|
||||
const outputs = jobs.changes.outputs;
|
||||
const required = ["changes", "static", "test"];
|
||||
const lanes = {
|
||||
code: ["build", "test-shard"],
|
||||
code: ["build", "test-shard", "sqlite-runtime"],
|
||||
runtime: ["windows-native-build", "package-e2e"],
|
||||
package: ["windows-curated"],
|
||||
apple: ["apple-artifacts"],
|
||||
|
||||
+105
-2
@@ -1,6 +1,89 @@
|
||||
// Ownership of the real-provider and website verification lanes. Shared build
|
||||
// inputs are classified once in plan.mjs rather than repeated in every workflow.
|
||||
// Ownership of the native-host, real-provider and website verification lanes.
|
||||
// Shared build inputs are classified once in plan.mjs rather than repeated in
|
||||
// every workflow.
|
||||
export const SCOPES = {
|
||||
// Apple artifact CLI/MCP lane on macOS, including its focused regressions.
|
||||
apple: [
|
||||
"src/native/Apple*",
|
||||
"src/native/NativeMacOS*",
|
||||
"src/native/NativeUi*",
|
||||
"src/native/Lldb*",
|
||||
"bridge/native/**",
|
||||
"bridge/process/**",
|
||||
"scripts/verify/apple/**",
|
||||
"tests/boundary/filesystem/installScript.test.ts",
|
||||
"tests/boundary/filesystem/nibNativeHierarchy.test.ts",
|
||||
"tests/boundary/filesystem/interfaceBuilderBundle.test.ts",
|
||||
"tests/boundary/cli/nativePlistCli.test.ts",
|
||||
"tests/boundary/cli/nativePlistPrototypeKeyCli.test.ts",
|
||||
"tests/boundary/cli/nativePlistSelectionFailureCli.test.ts",
|
||||
"tests/boundary/cli/nativeDemangleCli.test.ts",
|
||||
"tests/boundary/mcp/nativeDemangleMcp.test.ts",
|
||||
"tests/boundary/providers/native/nativeSignatureTargetBinding.test.ts",
|
||||
"tests/boundary/cli/nativeSignatureCli.test.ts",
|
||||
"tests/boundary/mcp/nativeSignatureTargetBindingMcp.test.ts",
|
||||
"src/process/capture/FilesystemSnapshot.test.ts",
|
||||
"tests/boundary/process/darwinProcessRunTokenReader.test.ts",
|
||||
"tests/boundary/process/directAnalysisSignals.test.ts",
|
||||
"tests/boundary/process/processCaptureLifecycle.test.ts",
|
||||
"tests/boundary/process/processCli.test.ts",
|
||||
"tests/boundary/mcp/sessionMcp.test.ts",
|
||||
],
|
||||
// Four-host installed-package matrix and the Windows curated lane.
|
||||
package: [
|
||||
"src/windows/**",
|
||||
"native/windows/**",
|
||||
"src/inspector/**",
|
||||
"scripts/verify/inspector/**",
|
||||
"scripts/verify-package.mjs",
|
||||
"scripts/verify-package-*",
|
||||
"scripts/verify-windows-*.mjs",
|
||||
"scripts/build-windows-native.mjs",
|
||||
"scripts/windows-capabilities.mjs",
|
||||
"scripts/prepack.mjs",
|
||||
"scripts/prepare.mjs",
|
||||
"scripts/rea.mjs",
|
||||
"install.sh",
|
||||
"src/config/**",
|
||||
"src/application/Setup*.ts",
|
||||
"src/application/Uninstall*.ts",
|
||||
"src/cli/interactiveSetup.ts",
|
||||
"src/cli/setupCommands.ts",
|
||||
"tests/boundary/filesystem/binaryTarget.test.ts",
|
||||
"tests/boundary/filesystem/safeOutputTree.test.ts",
|
||||
"tests/boundary/providers/native/artifactProvider.archiveSafety.test.ts",
|
||||
"tests/boundary/providers/native/artifactProvider.extractionCompleteness.test.ts",
|
||||
"tests/boundary/filesystem/setupUnavailableProvider.test.ts",
|
||||
"tests/boundary/filesystem/windowsNpxRegistration.test.ts",
|
||||
"tests/boundary/filesystem/webScriptManifestPaths.test.ts",
|
||||
"tests/boundary/process/ProcessEvidence.host.test.ts",
|
||||
"tests/acceptance/webModuleCli.test.ts",
|
||||
"tests/acceptance/webSourceLocationCli.test.ts",
|
||||
"tests/boundary/cli/referenceSourceImportStatus.test.ts",
|
||||
"tests/boundary/filesystem/asarInventoryFreshness.test.ts",
|
||||
"tests/boundary/filesystem/javascript-applications/javascriptArtifactReconstruction.test.ts",
|
||||
"tests/conformance/providers/ghidra/windowsCapabilities.test.ts",
|
||||
"src/ghidra/GhidraInstallation.test.ts",
|
||||
"tests/boundary/filesystem/ghidraJavaProbe.test.ts",
|
||||
"tests/boundary/providers/ghidra/ghidraTransport.test.ts",
|
||||
"tests/boundary/providers/ghidra/ghidraTargetSnapshot.test.ts",
|
||||
"tests/boundary/providers/ghidra/ghidraLauncher.test.ts",
|
||||
"tests/boundary/providers/hopper/hopperClient.cleanupRetry.test.ts",
|
||||
"src/windows/WindowsNativeLoader.test.ts",
|
||||
"src/windows/WindowsOwnedProcess.test.ts",
|
||||
"src/ghidra/GhidraLauncherEnvironment.test.ts",
|
||||
"src/process/ProcessOwnership.test.ts",
|
||||
"src/process/ProcessOwnership.part2.test.ts",
|
||||
"src/process/ProcessOwnership.part3.test.ts",
|
||||
"src/process/ProcessOwnership.validation.test.ts",
|
||||
"src/application/Update.test.ts",
|
||||
"tests/process-global/updateMaintenance.test.ts",
|
||||
"tests/conformance/providers/ghidra/realGhidraWindowsWorkflow.test.ts",
|
||||
"tests/boundary/filesystem/directoryArtifactReaderOpen.test.ts",
|
||||
"tests/boundary/filesystem/javascriptPackagePrecedence.test.ts",
|
||||
"tests/boundary/filesystem/javascriptArtifactContentIdentity.test.ts",
|
||||
"tests/boundary/process/sourceMapUncHosts.test.ts",
|
||||
],
|
||||
browser: [
|
||||
".github/workflows/real-browser.yml",
|
||||
"scripts/verify-real-browser.mjs",
|
||||
@@ -227,3 +310,23 @@ export const SCOPES = {
|
||||
".github/workflows/website-pages.yml",
|
||||
],
|
||||
};
|
||||
|
||||
// Verifier entrypoints that only manual, licensed, or self-hosted workflows
|
||||
// run. No selected CI lane executes them, so their edits need only the static
|
||||
// checks and the source-test suite. Shared helpers under scripts/lib remain
|
||||
// broad inputs.
|
||||
export const MANUAL_VERIFIERS = [
|
||||
"scripts/verify-real-electron.mjs",
|
||||
"scripts/verify-real-ghidra*.mjs",
|
||||
"scripts/verify-real-hopper*.mjs",
|
||||
"scripts/verify-real-ida.mjs",
|
||||
"scripts/verify-*-client.mjs",
|
||||
"scripts/verify-native-agent-client.mjs",
|
||||
"scripts/verify-jeb.mjs",
|
||||
"scripts/verify-apktool.mjs",
|
||||
"scripts/verify-adb.mjs",
|
||||
"scripts/verify-agent-experience.mjs",
|
||||
"scripts/verify-packaged-ghidra-windows.mjs",
|
||||
"scripts/verify-wasm-artifact.mjs",
|
||||
"scripts/verify-packaged-wasm-artifact.mjs",
|
||||
];
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { createRequire } from "node:module";
|
||||
import { dirname, join, relative, sep } from "node:path";
|
||||
import { z } from "zod";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const mode = process.argv[2];
|
||||
const reportRoot = join(".cache", "static-checks");
|
||||
const extraArguments = process.argv.slice(3);
|
||||
const lintReport = z.object({
|
||||
number_of_files: z.number(),
|
||||
diagnostics: z.array(
|
||||
z.object({
|
||||
message: z.string(),
|
||||
code: z.string().optional(),
|
||||
severity: z.enum(["error", "warning", "advice"]),
|
||||
filename: z.string(),
|
||||
labels: z.array(
|
||||
z.object({
|
||||
span: z.object({ line: z.number(), column: z.number() }),
|
||||
}),
|
||||
),
|
||||
}),
|
||||
),
|
||||
});
|
||||
const duplicateReport = z
|
||||
.object({
|
||||
duplicates: z.array(
|
||||
z
|
||||
.object({
|
||||
firstFile: z.object({ name: z.string() }).passthrough(),
|
||||
secondFile: z.object({ name: z.string() }).passthrough(),
|
||||
})
|
||||
.passthrough(),
|
||||
),
|
||||
statistics: z
|
||||
.object({
|
||||
total: z
|
||||
.object({
|
||||
sources: z.number(),
|
||||
clones: z.number(),
|
||||
percentage: z.number(),
|
||||
})
|
||||
.passthrough(),
|
||||
})
|
||||
.passthrough(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
const run = (packageName, entrypoint, arguments_) => {
|
||||
const executable = join(
|
||||
dirname(require.resolve(`${packageName}/package.json`)),
|
||||
entrypoint,
|
||||
);
|
||||
const result = spawnSync(process.execPath, [executable, ...arguments_], {
|
||||
encoding: "utf8",
|
||||
maxBuffer: 32 * 1024 * 1024,
|
||||
});
|
||||
if (result.stderr) process.stderr.write(result.stderr);
|
||||
if (result.error !== undefined) throw result.error;
|
||||
if (result.status === null)
|
||||
throw new Error(`${packageName} terminated by ${result.signal}`);
|
||||
return result;
|
||||
};
|
||||
|
||||
try {
|
||||
await mkdir(reportRoot, { recursive: true });
|
||||
if (mode === "lint") {
|
||||
const reportPath = join(reportRoot, "oxlint.json");
|
||||
await rm(reportPath, { force: true });
|
||||
const result = run("oxlint", "bin/oxlint", [
|
||||
...extraArguments,
|
||||
"--format",
|
||||
"json",
|
||||
]);
|
||||
let report;
|
||||
try {
|
||||
report = lintReport.parse(JSON.parse(result.stdout));
|
||||
} catch (cause) {
|
||||
process.stderr.write(result.stdout);
|
||||
throw cause;
|
||||
}
|
||||
await writeFile(reportPath, result.stdout);
|
||||
const warnings = report.diagnostics.filter(
|
||||
({ severity }) => severity === "warning",
|
||||
);
|
||||
const errors = report.diagnostics.filter(
|
||||
({ severity }) => severity === "error",
|
||||
);
|
||||
console.log(
|
||||
`Lint: ${report.number_of_files} files, ${errors.length} errors, ${warnings.length} warnings.`,
|
||||
);
|
||||
for (const diagnostic of errors) {
|
||||
const location = diagnostic.labels[0]?.span;
|
||||
console.error(
|
||||
`${diagnostic.filename}:${location?.line ?? 1}:${location?.column ?? 1}: ${diagnostic.code ?? "lint"}: ${diagnostic.message}`,
|
||||
);
|
||||
}
|
||||
const counts = new Map();
|
||||
for (const { code } of warnings)
|
||||
counts.set(code ?? "warning", (counts.get(code ?? "warning") ?? 0) + 1);
|
||||
for (const [rule, count] of [...counts]
|
||||
.sort(
|
||||
(left, right) => right[1] - left[1] || left[0].localeCompare(right[0]),
|
||||
)
|
||||
.slice(0, 8))
|
||||
console.log(` ${rule}: ${count} warnings`);
|
||||
console.log(`Full diagnostics: ${reportPath}; npm run lint:details`);
|
||||
process.exitCode = result.status;
|
||||
} else if (mode === "duplicates") {
|
||||
const output = join(reportRoot, "jscpd");
|
||||
const reportPath = join(output, "jscpd-report.json");
|
||||
await rm(reportPath, { force: true });
|
||||
const result = run("jscpd", "run-jscpd.js", [
|
||||
"src/",
|
||||
"tests/",
|
||||
...extraArguments,
|
||||
"--reporters",
|
||||
"json",
|
||||
"--output",
|
||||
output,
|
||||
"--no-colors",
|
||||
"--no-tips",
|
||||
"--absolute",
|
||||
]);
|
||||
if (result.stdout) process.stdout.write(result.stdout);
|
||||
const report = duplicateReport.parse(
|
||||
JSON.parse(await readFile(reportPath, "utf8")),
|
||||
);
|
||||
// jscpd otherwise strips each scan root, making src/ and tests/ names
|
||||
// ambiguous. Normalize absolute producer paths once for portable reports.
|
||||
for (const clone of report.duplicates)
|
||||
for (const file of [clone.firstFile, clone.secondFile])
|
||||
file.name = relative(process.cwd(), file.name).split(sep).join("/");
|
||||
await writeFile(reportPath, JSON.stringify(report, null, 2));
|
||||
const { sources, clones, percentage } = report.statistics.total;
|
||||
console.log(
|
||||
`Duplication: ${sources} files, ${clones} clones, ${percentage.toFixed(2)}% duplicated lines.`,
|
||||
);
|
||||
console.log(`Full diagnostics: ${reportPath}; npm run jscpd:details`);
|
||||
process.exitCode = result.status;
|
||||
} else {
|
||||
throw new Error("Expected lint or duplicates");
|
||||
}
|
||||
} catch (cause) {
|
||||
console.error(cause instanceof Error ? cause.message : String(cause));
|
||||
process.exitCode = 1;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { appendFile, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
const root = process.cwd();
|
||||
const historyDirectory = join(root, ".cache/ci-test-history");
|
||||
const historyPath = join(historyDirectory, "test-results.json");
|
||||
// Never let a failed or partial rerun leave a previous successful history file.
|
||||
await rm(historyPath, { force: true });
|
||||
const report = z
|
||||
.object({
|
||||
success: z.boolean(),
|
||||
numFailedTests: z.number().int().nonnegative(),
|
||||
testResults: z.array(
|
||||
z.object({
|
||||
name: z.string().min(1),
|
||||
startTime: z.number().finite(),
|
||||
endTime: z.number().finite(),
|
||||
}),
|
||||
),
|
||||
})
|
||||
.parse(JSON.parse(await readFile("test-results.json", "utf8")));
|
||||
|
||||
const files = report.testResults.map(({ name, startTime, endTime }) => {
|
||||
const path = relative(root, resolve(root, name));
|
||||
if (
|
||||
path === "" ||
|
||||
path === ".." ||
|
||||
path.startsWith(".." + sep) ||
|
||||
isAbsolute(path)
|
||||
)
|
||||
throw new Error(`Test report path is outside the checkout: ${name}`);
|
||||
const duration = endTime - startTime;
|
||||
if (!Number.isFinite(duration) || duration < 0)
|
||||
throw new Error(`Test report has an invalid duration: ${name}`);
|
||||
return { name: path.split(sep).join("/"), startTime: 0, endTime: duration };
|
||||
});
|
||||
const complete = process.env.SHARD_RESULT === "success";
|
||||
const passed =
|
||||
complete &&
|
||||
process.env.MERGE_RESULT === "success" &&
|
||||
report.success &&
|
||||
report.numFailedTests === 0;
|
||||
const summary = [
|
||||
complete ? "## Merged test diagnostics" : "## Partial test diagnostics",
|
||||
"",
|
||||
`Shard result: ${process.env.SHARD_RESULT ?? "unknown"}; merge result: ${process.env.MERGE_RESULT ?? "unknown"}.`,
|
||||
passed
|
||||
? "Successful timing history is available."
|
||||
: "This report is diagnostic only and is not a successful timing baseline.",
|
||||
"",
|
||||
"| Slowest file | Duration (ms) |",
|
||||
"| --- | ---: |",
|
||||
...files
|
||||
.toSorted((left, right) => right.endTime - left.endTime)
|
||||
.slice(0, 20)
|
||||
.map(
|
||||
({ name, endTime }) => `| ${name.replaceAll("|", "\\|")} | ${endTime} |`,
|
||||
),
|
||||
"",
|
||||
].join("\n");
|
||||
if (process.env.GITHUB_STEP_SUMMARY)
|
||||
await appendFile(process.env.GITHUB_STEP_SUMMARY, summary);
|
||||
else console.log(summary);
|
||||
|
||||
if (passed) {
|
||||
await mkdir(historyDirectory, { recursive: true });
|
||||
await writeFile(
|
||||
historyPath,
|
||||
JSON.stringify({ success: true, numFailedTests: 0, testResults: files }),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"target_sha256": "659b5fc6a4319dfe4f117d00ad4e7ec004915ebcadcb96628797fb3544040e29",
|
||||
"snapshot_hash": "65817c30a78bb44c3dc3771876b6010a",
|
||||
"engines": {
|
||||
"x86_64": {
|
||||
"dart_version": null,
|
||||
"toolchain_lines": [
|
||||
"Android (5900059 based on r365631c) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 207d7abc1a2abf3ef8d4301736d6a7ebc224a290) (based on LLVM 9.0.8svn)"
|
||||
]
|
||||
},
|
||||
"armeabi-v7a": {
|
||||
"dart_version": null,
|
||||
"toolchain_lines": [
|
||||
"Android (5900059 based on r365631c) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 207d7abc1a2abf3ef8d4301736d6a7ebc224a290) (based on LLVM 9.0.8svn)"
|
||||
]
|
||||
},
|
||||
"arm64-v8a": {
|
||||
"dart_version": null,
|
||||
"toolchain_lines": [
|
||||
"Android (5900059 based on r365631c) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 207d7abc1a2abf3ef8d4301736d6a7ebc224a290) (based on LLVM 9.0.8svn)"
|
||||
]
|
||||
}
|
||||
},
|
||||
"string_pools": {
|
||||
"x86_64": {
|
||||
"package_uri_count_at_least": 756,
|
||||
"dart_uri_count_at_least": 201
|
||||
},
|
||||
"armeabi-v7a": {
|
||||
"package_uri_count_at_least": 212,
|
||||
"dart_uri_count_at_least": 48
|
||||
},
|
||||
"arm64-v8a": {
|
||||
"package_uri_count_at_least": 756,
|
||||
"dart_uri_count_at_least": 201
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { TraceMap, eachMapping } from "@jridgewell/trace-mapping";
|
||||
import { CdpBrowserProvider } from "../../dist/browser/CdpBrowserProvider.js";
|
||||
import { CdpConnection } from "../../dist/browser/CdpConnection.js";
|
||||
import { waitForBrowserDevtoolsPort } from "../../dist/browser/BrowserProcessStartup.js";
|
||||
import { parseEvidence } from "../../dist/domain/evidence.js";
|
||||
import { traceSourceMap } from "../../dist/javascript/sourceMaps/TraceSourceMap.js";
|
||||
import { startBrowserSourceMapSite } from "../fixtures/browser-source-map-site.mjs";
|
||||
@@ -63,7 +61,6 @@ async function verifyCase(executable, entrypoint, scenario) {
|
||||
let fixture;
|
||||
let connection;
|
||||
let primaryError;
|
||||
let stderr = "";
|
||||
let phase = "native-map-admission";
|
||||
let browserVersion;
|
||||
let expected;
|
||||
@@ -90,17 +87,7 @@ async function verifyCase(executable, entrypoint, scenario) {
|
||||
|
||||
phase = "owned-browser-startup";
|
||||
fixture = await startRuntimeFixtureBrowser(executable, site.origin);
|
||||
fixture.browser.stderr.on("data", (chunk) => {
|
||||
if (stderr.length < 65536) stderr += chunk;
|
||||
});
|
||||
const port = await waitForBrowserDevtoolsPort({
|
||||
child: fixture.browser,
|
||||
executable,
|
||||
activePortPath: join(fixture.profile, "DevToolsActivePort"),
|
||||
stderr: () => stderr,
|
||||
timeoutMs: 20_000,
|
||||
});
|
||||
const endpoint = `http://127.0.0.1:${port}`;
|
||||
const endpoint = `http://127.0.0.1:${fixture.port}`;
|
||||
const provider = new CdpBrowserProvider();
|
||||
const targets = await provider.listTargets({
|
||||
cdp_endpoint: endpoint,
|
||||
@@ -150,7 +137,16 @@ async function verifyCase(executable, entrypoint, scenario) {
|
||||
phase = "public-map-assertions";
|
||||
observed = item?.mappings;
|
||||
assert.equal(item.status, "included");
|
||||
assert.deepEqual(item.mappings, expected);
|
||||
assert.equal(item.mappings.length, expected.length);
|
||||
for (const [index, coordinates] of expected.entries()) {
|
||||
const mapping = item.mappings[index];
|
||||
for (const [key, value] of Object.entries(coordinates))
|
||||
assert.deepEqual(mapping[key], value);
|
||||
// This compiler fixture has one source declaration in one wrapped leaf.
|
||||
assert.equal(mapping.source_index, 0);
|
||||
assert.equal(mapping.declaration_index, 0);
|
||||
}
|
||||
assert.equal(item.original_sources.length, 1);
|
||||
assert.equal(item.artifact.sha256, sha(site.map));
|
||||
assert.equal(item.artifact.bytes, Buffer.byteLength(site.map));
|
||||
assert.equal(item.original_sources[0].artifact.sha256, sha(site.original));
|
||||
|
||||
@@ -117,7 +117,7 @@ export function assertBrowserNetworkEvidence(
|
||||
assert.deepEqual(retained(responseFor("/compressed")), networkFixtureDecoded);
|
||||
assert.equal(
|
||||
responseFor("/compressed").body.representation,
|
||||
"browser-decoded-response-bytes",
|
||||
"playwright-response-body-bytes",
|
||||
);
|
||||
const formRequest = requestEvents.find(
|
||||
(event) => event.url.url === `${origin}/form`,
|
||||
@@ -149,7 +149,7 @@ export function assertBrowserNetworkEvidence(
|
||||
return {
|
||||
same_url_markers: markers,
|
||||
binary_bytes: networkFixtureBinary.length,
|
||||
compressed_representation: "browser-decoded-response-bytes",
|
||||
compressed_representation: "playwright-response-body-bytes",
|
||||
unfinished_stream: "response-unfinished",
|
||||
empty_response_state: responseFor("/empty").body.state,
|
||||
};
|
||||
|
||||
@@ -3,14 +3,12 @@ import { spawn, execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { once } from "node:events";
|
||||
import { access } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { CdpBrowserProvider } from "../../dist/browser/CdpBrowserProvider.js";
|
||||
import { CdpConnection } from "../../dist/browser/CdpConnection.js";
|
||||
import { waitForBrowserDevtoolsPort } from "../../dist/browser/BrowserProcessStartup.js";
|
||||
import { parseEvidence } from "../../dist/domain/evidence.js";
|
||||
import { webExecutionSchema } from "../../dist/domain/webExecution.js";
|
||||
import { webEventListenersSchema } from "../../dist/domain/webEventListeners.js";
|
||||
@@ -42,23 +40,11 @@ export async function verifyBrowserRuntime(
|
||||
const site = await startBrowserRuntimeSite();
|
||||
let fixture;
|
||||
let primaryError;
|
||||
let stderr = "";
|
||||
let action;
|
||||
let client;
|
||||
try {
|
||||
fixture = await startRuntimeFixtureBrowser(executable, site.origin);
|
||||
const { browser, profile } = fixture;
|
||||
browser.stderr.on("data", (chunk) => {
|
||||
if (stderr.length < 65536) stderr += chunk;
|
||||
});
|
||||
const port = await waitForBrowserDevtoolsPort({
|
||||
child: browser,
|
||||
executable,
|
||||
activePortPath: join(profile, "DevToolsActivePort"),
|
||||
stderr: () => stderr,
|
||||
timeoutMs: 20_000,
|
||||
});
|
||||
const endpoint = `http://127.0.0.1:${port}`;
|
||||
const endpoint = `http://127.0.0.1:${fixture.port}`;
|
||||
const targets = await new CdpBrowserProvider().listTargets({
|
||||
cdp_endpoint: endpoint,
|
||||
allowed_origins: [site.origin],
|
||||
|
||||
@@ -8,8 +8,9 @@ import { spawnOwnedProviderProcess } from "../../dist/process/ProviderProcess.js
|
||||
import { createSystemProcessOwnershipHost } from "../../dist/process/ProcessOwnershipObservation.js";
|
||||
import { liveProcesses } from "../../dist/process/ProcessOwnershipProcessTree.js";
|
||||
import { CdpConnection } from "../../dist/browser/CdpConnection.js";
|
||||
import { waitForBrowserDevtoolsPort } from "../../dist/browser/BrowserProcessStartup.js";
|
||||
|
||||
/** Launch only the synthetic fixture browser in its own verified process group. */
|
||||
/** Launch the synthetic fixture browser and await CDP in its own verified process group. */
|
||||
export async function startRuntimeFixtureBrowser(executable, origin) {
|
||||
const profile = await mkdtemp(join(tmpdir(), "rea-real-web-runtime-"));
|
||||
let owned;
|
||||
@@ -38,9 +39,21 @@ export async function startRuntimeFixtureBrowser(executable, origin) {
|
||||
expectedCommand: null,
|
||||
});
|
||||
owned.process.stdout?.resume();
|
||||
let stderr = "";
|
||||
owned.process.stderr?.on("data", (chunk) => {
|
||||
if (stderr.length < 65536) stderr += chunk;
|
||||
});
|
||||
const port = await waitForBrowserDevtoolsPort({
|
||||
child: owned.process,
|
||||
executable,
|
||||
activePortPath: join(profile, "DevToolsActivePort"),
|
||||
stderr: () => stderr,
|
||||
// Match the broader real-browser verifier's allowance for cold Chrome
|
||||
// startup on shared runners; early process failures still reject at once.
|
||||
timeoutMs: 60_000,
|
||||
});
|
||||
return {
|
||||
browser: owned.process,
|
||||
profile,
|
||||
port,
|
||||
close: async () => {
|
||||
await stopOwnedBrowser(owned, profile);
|
||||
await rm(profile, {
|
||||
|
||||
@@ -27,7 +27,11 @@ export const toolFamilyCatalog = (sources) => {
|
||||
contracts: [
|
||||
...sources.artifactContracts.ARTIFACT_TOOL_CONTRACTS,
|
||||
...sources.evmContracts.EVM_TOOL_CONTRACTS,
|
||||
...sources.goContracts.GO_TOOL_CONTRACTS,
|
||||
...sources.wasmContracts.WASM_TOOL_CONTRACTS,
|
||||
...sources.sqliteContracts.SQLITE_TOOL_CONTRACTS,
|
||||
...sources.captureContracts.CAPTURE_TOOL_CONTRACTS,
|
||||
...sources.signalContracts.SIGNAL_TOOL_CONTRACTS,
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -48,6 +52,16 @@ export const toolFamilyCatalog = (sources) => {
|
||||
surface: "android-provider",
|
||||
contracts: sources.androidContracts.ANDROID_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
id: "flutter",
|
||||
surface: "flutter-provider",
|
||||
contracts: sources.flutterContracts.FLUTTER_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
id: "frida",
|
||||
surface: "instrumentation-provider",
|
||||
contracts: sources.fridaContracts.FRIDA_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
id: "apktool",
|
||||
surface: "apktool-provider",
|
||||
@@ -144,6 +158,10 @@ export const providerCatalog = (sources) => {
|
||||
activeContracts,
|
||||
} = electronContractSlices(sources);
|
||||
return [
|
||||
{
|
||||
identity: sources.fridaProvider.FRIDA_PROVIDER_IDENTITY,
|
||||
contracts: sources.fridaContracts.FRIDA_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
identity: sources.hopperProvider.HOPPER_PROVIDER_IDENTITY,
|
||||
contracts: declaredContracts(
|
||||
@@ -180,6 +198,14 @@ export const providerCatalog = (sources) => {
|
||||
({ name }) => name === "inspect_pe_resources",
|
||||
),
|
||||
},
|
||||
{
|
||||
identity: sources.captureProvider.TSHARK_PROVIDER_IDENTITY,
|
||||
contracts: sources.captureContracts.CAPTURE_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
identity: sources.signalProvider.SIGROK_PROVIDER_IDENTITY,
|
||||
contracts: sources.signalContracts.SIGNAL_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
identity: sources.wasmProvider.WABT_PROVIDER_IDENTITY,
|
||||
contracts: sources.wasmContracts.WASM_TOOL_CONTRACTS,
|
||||
@@ -188,6 +214,14 @@ export const providerCatalog = (sources) => {
|
||||
identity: sources.evmProvider.EVMOLE_PROVIDER_IDENTITY,
|
||||
contracts: sources.evmContracts.EVM_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
identity: sources.goProvider.GO_BINARY_PROVIDER_IDENTITY,
|
||||
contracts: sources.goContracts.GO_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
identity: sources.sqliteDomain.SQLITE_PROVIDER_IDENTITY,
|
||||
contracts: sources.sqliteContracts.SQLITE_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
identity: sources.artifactProviders.ARTIFACT_GRAPH_PROVIDER,
|
||||
contracts: sources.artifactContracts.ARTIFACT_TOOL_CONTRACTS,
|
||||
@@ -217,6 +251,10 @@ export const providerCatalog = (sources) => {
|
||||
identity: sources.androidProvider.JADX_PROVIDER_IDENTITY,
|
||||
contracts: sources.androidContracts.ANDROID_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
identity: sources.flutterProvider.FLUTTER_PROVIDER_IDENTITY,
|
||||
contracts: sources.flutterContracts.FLUTTER_TOOL_CONTRACTS,
|
||||
},
|
||||
{
|
||||
identity: sources.apktoolProvider.APKTOOL_PROVIDER_IDENTITY,
|
||||
contracts: sources.apktoolContracts.APKTOOL_TOOL_CONTRACTS,
|
||||
|
||||
@@ -43,19 +43,33 @@ const SOURCE_PATHS = {
|
||||
sessionContracts: "dist/contracts/sessionToolContracts.js",
|
||||
binaryDiagnosticsContracts:
|
||||
"dist/contracts/native/binaryDiagnosticsToolContracts.js",
|
||||
fridaContracts: "dist/contracts/fridaToolContracts.js",
|
||||
fridaProvider: "dist/frida/FridaInstrumentationManager.js",
|
||||
pwntoolsProvider: "dist/native/pwntools/PwntoolsRelease.js",
|
||||
nativeContracts: "dist/contracts/native/nativeToolContracts.js",
|
||||
captureContracts: "dist/contracts/captures/captureToolContracts.js",
|
||||
captureProvider: "dist/captures/TsharkCaptureProvider.js",
|
||||
signalContracts: "dist/contracts/signals/signalToolContracts.js",
|
||||
signalProvider: "dist/signals/SigrokRecordingProvider.js",
|
||||
wasmContracts: "dist/contracts/wasm/wasmToolContracts.js",
|
||||
wasmProvider: "dist/wasm/WabtRelease.js",
|
||||
evmContracts: "dist/contracts/evm/evmToolContracts.js",
|
||||
sqliteContracts: "dist/contracts/sqlite/sqliteToolContracts.js",
|
||||
sqliteDomain: "dist/domain/sqlite/sqliteDatabase.js",
|
||||
evmProvider: "dist/evm/EvmoleRelease.js",
|
||||
goContracts: "dist/contracts/go/goToolContracts.js",
|
||||
goProvider: "dist/go/GoBinaryProvider.js",
|
||||
artifactContracts: "dist/contracts/artifactToolContracts.js",
|
||||
managedContracts: "dist/contracts/managed/managedToolContracts.js",
|
||||
firmwareContracts: "dist/contracts/firmware/firmwareToolContracts.js",
|
||||
firmwareProvider: "dist/firmware/FirmwareRelease.js",
|
||||
androidContracts: "dist/contracts/android/androidToolContracts.js",
|
||||
flutterContracts: "dist/contracts/flutter/flutterToolContracts.js",
|
||||
flutterProvider: "dist/flutter/FlutterBuildProvider.js",
|
||||
androidProvider: "dist/android/JadxRelease.js",
|
||||
apktoolContracts: "dist/contracts/apktool/apktoolToolContracts.js",
|
||||
flutterContracts: "dist/contracts/flutter/flutterToolContracts.js",
|
||||
flutterProvider: "dist/flutter/FlutterBuildProvider.js",
|
||||
apktoolProvider: "dist/apktool/ApktoolProvider.js",
|
||||
jebContracts: "dist/contracts/jeb/jebToolContracts.js",
|
||||
jebProvider: "dist/jeb/JebProvider.js",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { analysisErrorProjectionSchema } from "../../dist/contracts/errorSchemas.js";
|
||||
import { toolContract } from "../../dist/contracts/toolContracts.js";
|
||||
import {
|
||||
expandProviderCapabilities,
|
||||
expandToolAvailability,
|
||||
providerCapabilitySet,
|
||||
} from "../../dist/contracts/toolOutputSchemaPrimitives.js";
|
||||
import { compareUnicodeCodePoints } from "../../dist/domain/unicodeCodePointOrder.js";
|
||||
|
||||
/** Read the textual JSON projection from one MCP tool call. */
|
||||
export const mcpTextValue = (result) => {
|
||||
@@ -10,6 +16,10 @@ export const mcpTextValue = (result) => {
|
||||
|
||||
const jsonValue = (result) => JSON.parse(mcpTextValue(result));
|
||||
|
||||
/** Sort canonical contract names using REA's code-point ordering. */
|
||||
export const sortVerifierNames = (names) =>
|
||||
[...names].sort(compareUnicodeCodePoints);
|
||||
|
||||
/** Read the complete canonical diagnostic from an MCP tool failure. */
|
||||
export const requireMcpToolError = (result) => {
|
||||
if (result.isError !== true) throw new Error("Expected an MCP tool failure");
|
||||
@@ -35,6 +45,44 @@ const operationResultKey = (contract) => {
|
||||
return evidence ? "normalized_result" : "result";
|
||||
};
|
||||
|
||||
/** Expand compact session metadata once at the verifier boundary. */
|
||||
export const expandMcpSessionStatus = (status) => ({
|
||||
...status,
|
||||
capabilities: expandProviderCapabilities(status.capabilities),
|
||||
analysis_provider_candidates: expandProviderCandidates(
|
||||
status.analysis_provider_candidates,
|
||||
),
|
||||
tool_availability: expandToolAvailability(status.tool_availability),
|
||||
});
|
||||
|
||||
/** Expand provider capability groups while retaining candidate identity/state. */
|
||||
export const expandProviderCandidates = (candidates) =>
|
||||
candidates.map((candidate) => ({
|
||||
...candidate,
|
||||
capabilities: expandProviderCapabilities(
|
||||
providerCapabilitySet.array().parse(candidate.capabilities),
|
||||
),
|
||||
}));
|
||||
|
||||
/** Expand CLI provider capability groups at the same owning boundary. */
|
||||
export const expandProviderOutput = (providers) => ({
|
||||
...providers,
|
||||
capabilities: expandProviderCapabilities(
|
||||
providerCapabilitySet.array().parse(providers.capabilities),
|
||||
),
|
||||
analysis_provider_candidates: expandProviderCandidates(
|
||||
providers.analysis_provider_candidates,
|
||||
),
|
||||
});
|
||||
|
||||
/** Expand the CLI capabilities command's compact provider descriptor groups. */
|
||||
export const expandCapabilitiesOutput = (capabilities) => ({
|
||||
...capabilities,
|
||||
capabilities: expandProviderCapabilities(
|
||||
providerCapabilitySet.array().parse(capabilities.capabilities),
|
||||
),
|
||||
});
|
||||
|
||||
/** Validate an Evidence-producing tool output and return its normalized result. */
|
||||
export const requireMcpEvidenceResult = (result, operation) => {
|
||||
const contract = toolContract(operation);
|
||||
@@ -48,7 +96,10 @@ 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;
|
||||
const projected = requireOutput(result, operation, contract).result;
|
||||
return operation === "binary_session"
|
||||
? expandMcpSessionStatus(projected)
|
||||
: projected;
|
||||
};
|
||||
|
||||
/** Project a mixed verifier call using its exact named canonical output schema. */
|
||||
@@ -58,7 +109,10 @@ export const requireMcpOperationResult = (
|
||||
contract = toolContract(operation),
|
||||
) => {
|
||||
const key = operationResultKey(contract);
|
||||
return requireOutput(result, operation, contract)[key];
|
||||
const projected = requireOutput(result, operation, contract)[key];
|
||||
return operation === "binary_session"
|
||||
? expandMcpSessionStatus(projected)
|
||||
: projected;
|
||||
};
|
||||
|
||||
/** Verify provider identity directly from the tool result. */
|
||||
|
||||
@@ -5,8 +5,12 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
|
||||
const PURE_LAYERS = new Set(["domain", "contracts"]);
|
||||
const MIGRATED_PROVIDER_ROOTS = new Set([
|
||||
"sqlite",
|
||||
"evm",
|
||||
"go",
|
||||
"wasm",
|
||||
"captures",
|
||||
"signals",
|
||||
"android",
|
||||
"firmware",
|
||||
"ghidra",
|
||||
|
||||
@@ -11,6 +11,7 @@ import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { parseEvidence } from "../../dist/domain/evidence.js";
|
||||
import { analysisProfileSchema } from "../../dist/domain/analysisProfile.js";
|
||||
import { nativeValueTraceSchema } from "../../dist/domain/native/nativeValueTrace.js";
|
||||
import { requireMcpLifecycleResult } from "./mcp-verifier-results.mjs";
|
||||
import { verifyGhidraBoundaries } from "./real-ghidra-boundaries.mjs";
|
||||
|
||||
const defaultEntrypoint = fileURLToPath(new URL("../rea.mjs", import.meta.url));
|
||||
@@ -172,13 +173,16 @@ async function verifyNativeValueAdapters(
|
||||
{ timeout: 180000 },
|
||||
);
|
||||
assert.notEqual(opened.isError, true, JSON.stringify(opened));
|
||||
const inventory = await client.callTool({
|
||||
const inventoryReply = await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: {},
|
||||
});
|
||||
assert.notEqual(inventory.isError, true, JSON.stringify(inventory));
|
||||
const inventory = requireMcpLifecycleResult(
|
||||
inventoryReply,
|
||||
"binary_session",
|
||||
);
|
||||
assert.ok(
|
||||
inventory.structuredContent?.result?.tool_availability.some(
|
||||
inventory.tool_availability.some(
|
||||
(tool) => tool.name === "trace_native_values" && tool.available,
|
||||
),
|
||||
"Native value tracing is unavailable in real provider discovery",
|
||||
@@ -267,11 +271,14 @@ async function verifyNativeValueAdapters(
|
||||
arguments: {},
|
||||
});
|
||||
assert.notEqual(closed.isError, true, JSON.stringify(closed));
|
||||
const status = await client.callTool({
|
||||
const statusReply = await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: {},
|
||||
});
|
||||
assert.equal(status.structuredContent?.result?.open, false);
|
||||
assert.equal(
|
||||
requireMcpLifecycleResult(statusReply, "binary_session").open,
|
||||
false,
|
||||
);
|
||||
assert.deepEqual(
|
||||
(await readdir(env.TMPDIR)).filter((name) =>
|
||||
name.startsWith("rea-ghidra-"),
|
||||
|
||||
@@ -13,8 +13,6 @@ 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";
|
||||
|
||||
@@ -36,16 +36,11 @@ export async function verifyGhidraSnapshotLifecycle(
|
||||
);
|
||||
const error = requireMcpToolError(reply);
|
||||
assert.equal(
|
||||
error?.code,
|
||||
error.code,
|
||||
"evidence_integrity_mismatch",
|
||||
JSON.stringify(reply),
|
||||
);
|
||||
assert.match(error.message, /after analysis metadata mutations/u);
|
||||
assert.match(
|
||||
error.remediation.action,
|
||||
/close.*without saving a snapshot/iu,
|
||||
);
|
||||
assert.match(error.remediation.action, /export_evidence_bundle/u);
|
||||
assert.equal(error.retryable, false);
|
||||
rejectedCalls++;
|
||||
};
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { requireFunctionDossierOracle } from "../../dist/application/RealHopperAssertions.js";
|
||||
|
||||
/**
|
||||
* `requireFunctionDossierOracle` is only used inside `verifyRealHopperFixture`,
|
||||
* which runs against the real Hopper bridge after `build:cached`. Loading it
|
||||
* lazily keeps this module importable from `test:fast` (which docs promise to
|
||||
* run "without build" — see docs/testing.md § test scripts) so that mock-only
|
||||
* callers such as `requireCurrentDocument` and `resolveFixtureProcedure` do
|
||||
* not require `dist/`.
|
||||
*/
|
||||
const loadFunctionDossierOracle = () =>
|
||||
import("../../dist/application/RealHopperAssertions.js").then(
|
||||
(module) => module.requireFunctionDossierOracle,
|
||||
);
|
||||
|
||||
/** Require truthful tri-state permissions from real Hopper memory regions. */
|
||||
export const requireTruthfulMemoryRegions = (segments) => {
|
||||
@@ -87,6 +99,7 @@ export async function verifyRealHopperFixture({
|
||||
oracle,
|
||||
normalizedResult,
|
||||
}) {
|
||||
const requireFunctionDossierOracle = await loadFunctionDossierOracle();
|
||||
const main = await resolveFixtureProcedure(
|
||||
client,
|
||||
options,
|
||||
|
||||
@@ -37,7 +37,7 @@ export async function verifyHopperWorkflows(call, invalid, procedure) {
|
||||
);
|
||||
assert.equal(cycle.length, 2, "fixture omitted its source-owned call cycle");
|
||||
const cycleGraph = await call("get_call_graph", { address: cycle[0].value });
|
||||
const cycleNodes = Object.values(cycleGraph).flat();
|
||||
const cycleNodes = Object.values(cycleGraph.graph).flat();
|
||||
assert.equal(cycleNodes.length, 2);
|
||||
assert.deepEqual(
|
||||
cycleNodes.map((node) => node.address).sort(),
|
||||
|
||||
@@ -3,6 +3,17 @@ import { lstat } from "node:fs/promises";
|
||||
import { promisify } from "node:util";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
|
||||
/**
|
||||
* `mcp-verifier-results.mjs` reaches into `dist/` at module load, so eager
|
||||
* importing it propagates that build dependency to every consumer in this
|
||||
* file. `verifyCompleteToolCatalog` is the only consumer, so we lazy-load
|
||||
* the module there and keep the other helpers (`exec`, `run`, `json`,
|
||||
* `pathExists`) usable from `test:fast` callers that only need `dist/`-free
|
||||
* utilities — see docs/testing.md § test scripts, which promises `test:fast`
|
||||
* runs "without build".
|
||||
*/
|
||||
const loadMcpVerifierResults = () => import("./mcp-verifier-results.mjs");
|
||||
|
||||
/** Promisified child_process execution helper. */
|
||||
export const exec = promisify(execFile);
|
||||
|
||||
@@ -31,6 +42,8 @@ export const json = (text) => JSON.parse(text);
|
||||
|
||||
/** Verify schema validity and that the MCP catalog matches session metadata. */
|
||||
export const verifyCompleteToolCatalog = async (client, options) => {
|
||||
const { requireMcpLifecycleResult, sortVerifierNames } =
|
||||
await loadMcpVerifierResults();
|
||||
const listed = await client.listTools(undefined, options);
|
||||
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
||||
for (const tool of listed.tools) {
|
||||
@@ -46,11 +59,10 @@ export const verifyCompleteToolCatalog = async (client, options) => {
|
||||
{ name: "binary_session", arguments: {} },
|
||||
options,
|
||||
);
|
||||
const availability = status.structuredContent?.result?.tool_availability;
|
||||
if (!Array.isArray(availability))
|
||||
throw new Error("packaged MCP omitted tool availability");
|
||||
const expected = availability.map(({ name }) => name).sort();
|
||||
const observed = listed.tools.map(({ name }) => name).sort();
|
||||
const expanded = requireMcpLifecycleResult(status, "binary_session");
|
||||
const availability = expanded.tool_availability;
|
||||
const expected = sortVerifierNames(availability.map(({ name }) => name));
|
||||
const observed = sortVerifierNames(listed.tools.map(({ name }) => name));
|
||||
if (JSON.stringify(observed) !== JSON.stringify(expected))
|
||||
throw new Error(
|
||||
"packaged MCP tool inventory diverged from session metadata",
|
||||
|
||||
@@ -47,6 +47,10 @@ if (await pathExists(join(root, "src"))) {
|
||||
for (const path of [
|
||||
"dist/main.js",
|
||||
"dist/mcp/main.js",
|
||||
"dist/cli-runtime/cli.js",
|
||||
"dist/cli-runtime/cliOutput.js",
|
||||
"dist/cli-runtime/cliResultOutput.js",
|
||||
"dist/cli-runtime/mcpDoctor.js",
|
||||
"dist/mcpDoctor.js",
|
||||
"dist/cli.js",
|
||||
"dist/cliOutput.js",
|
||||
|
||||
+19
-9
@@ -33,8 +33,12 @@ if (
|
||||
const runtimeFiles = isMcpMode
|
||||
? ["dist/mcp/main.js"]
|
||||
: isMcpDoctorMode
|
||||
? ["dist/mcp/main.js", "dist/mcpDoctor.js"]
|
||||
: ["dist/cli.js", "dist/cliOutput.js", "dist/cli/streamedJsonOutput.js"];
|
||||
? ["dist/mcp/main.js", "dist/cli-runtime/mcpDoctor.js"]
|
||||
: [
|
||||
"dist/cli-runtime/cli.js",
|
||||
"dist/cli-runtime/cliOutput.js",
|
||||
"dist/cli-runtime/cliResultOutput.js",
|
||||
];
|
||||
|
||||
if (!(await compiledRuntimeExists(runtimeFiles))) {
|
||||
process.stderr.write(
|
||||
@@ -45,7 +49,8 @@ if (!(await compiledRuntimeExists(runtimeFiles))) {
|
||||
const { runEntrypoint } = await import("../dist/mcp/main.js");
|
||||
await runEntrypoint();
|
||||
} else if (isMcpDoctorMode) {
|
||||
const { runProductionMcpDoctorCli } = await import("../dist/mcpDoctor.js");
|
||||
const { runProductionMcpDoctorCli } =
|
||||
await import("../dist/cli-runtime/mcpDoctor.js");
|
||||
const result = await runProductionMcpDoctorCli(args.slice(2), {
|
||||
dispatcherPath: fileURLToPath(import.meta.url),
|
||||
packageRoot,
|
||||
@@ -53,21 +58,26 @@ if (!(await compiledRuntimeExists(runtimeFiles))) {
|
||||
process.stdout.write(result.output);
|
||||
process.exitCode = result.exitCode;
|
||||
} else {
|
||||
const { createCli } = await import("../dist/cli.js");
|
||||
const { createStreamedCliJsonOutput } =
|
||||
await import("../dist/cli/streamedJsonOutput.js");
|
||||
const { cliConfigurationError, createCli } =
|
||||
await import("../dist/cli-runtime/cli.js");
|
||||
const { createCliResultOutput } =
|
||||
await import("../dist/cli-runtime/cliResultOutput.js");
|
||||
const {
|
||||
renderCliOutputArgumentError,
|
||||
renderEmptyFilteredCliOutput,
|
||||
validateCliOutputArguments,
|
||||
} = await import("../dist/cliOutput.js");
|
||||
} = await import("../dist/cli-runtime/cliOutput.js");
|
||||
const outputArguments = validateCliOutputArguments(args);
|
||||
if (!outputArguments.ok) {
|
||||
const configurationError = cliConfigurationError(process.env);
|
||||
if (configurationError !== undefined) {
|
||||
process.stderr.write(`${configurationError}\n`);
|
||||
process.exitCode = 1;
|
||||
} else if (!outputArguments.ok) {
|
||||
process.stdout.write(renderCliOutputArgumentError(outputArguments));
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
let wroteOutput = false;
|
||||
const resultOutput = createStreamedCliJsonOutput(args, process.stdout);
|
||||
const resultOutput = createCliResultOutput(args, process.stdout);
|
||||
await createCli(process.env, resultOutput).serve(args, {
|
||||
stdout: (output) => {
|
||||
if (resultOutput?.handled) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { spawn } from "node:child_process";
|
||||
import spawn from "cross-spawn";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { DatabaseSync } from "node:sqlite";
|
||||
@@ -74,7 +74,6 @@ function runCommand() {
|
||||
child = spawn(command[0], command.slice(1), {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
shell: process.platform === "win32",
|
||||
stdio: "inherit",
|
||||
});
|
||||
child.once("error", reject);
|
||||
|
||||
@@ -401,6 +401,22 @@ class WebsiteTranslationChecks(unittest.TestCase):
|
||||
server.shutdown()
|
||||
worker.join()
|
||||
|
||||
def test_every_reading_page_offers_light_and_dark_theme_colors(self):
|
||||
site = ROOT / "website/_site"
|
||||
english_pages = reading_pages(ROOT / "website/public")
|
||||
self.assertTrue(english_pages)
|
||||
for language in languages(ROOT):
|
||||
code = language["code"]
|
||||
for original in english_pages:
|
||||
relative = original.relative_to(ROOT / "website/public")
|
||||
for path in {original, site / relative if code == "en" else site / code / relative}:
|
||||
with self.subTest(language=code, page=str(path.relative_to(ROOT))):
|
||||
doc = Document(path.read_text())
|
||||
media = sorted(node.attrs.get("media") for node in doc.nodes if node.tag == "meta" and node.attrs.get("name") == "theme-color")
|
||||
self.assertEqual(media, ["(prefers-color-scheme: dark)", "(prefers-color-scheme: light)"])
|
||||
styles = (ROOT / "website/public/assets/styles.css").read_text()
|
||||
self.assertTrue("@media (prefers-color-scheme: dark)" in styles, "styles.css has no dark color scheme block")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
+80
-67
@@ -1,7 +1,5 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, readFile, rm, stat } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { readFile, stat } from "node:fs/promises";
|
||||
|
||||
import { ApktoolResourceAnalysisService } from "../dist/application/apktool/ApktoolResourceAnalysisService.js";
|
||||
import { createApktoolResourceAnalysisProvider } from "../dist/composition/apktool.js";
|
||||
@@ -11,8 +9,8 @@ if (options.help) {
|
||||
process.stdout.write(
|
||||
"Usage: npm run verify:apktool [-- --apk PATH]\n" +
|
||||
"Requires a caller-selected apktool launcher (REA_APKTOOL_COMMAND or\n" +
|
||||
"PATH) and a Java runtime. Without --apk, a small signed probe APK is\n" +
|
||||
"expected at the path given by --apk; nothing is downloaded or built.\n",
|
||||
"PATH) and a Java runtime. Without --apk, only client availability is\n" +
|
||||
"checked. Supply a local APK to verify decoding; nothing is downloaded or built.\n",
|
||||
);
|
||||
process.exit(0);
|
||||
}
|
||||
@@ -38,70 +36,80 @@ const run = async (operation, input) => {
|
||||
return result.value.normalized_result;
|
||||
};
|
||||
|
||||
const client = await run("inspect_apktool_client", {});
|
||||
if (client !== null) {
|
||||
check(
|
||||
"apktool launcher reports a version",
|
||||
typeof client.client.apktool_version === "string" &&
|
||||
client.client.apktool_version !== "",
|
||||
`command=${client.client.command} version=${client.client.apktool_version}`,
|
||||
);
|
||||
}
|
||||
try {
|
||||
const client = await run("inspect_apktool_client", {});
|
||||
if (client !== null) {
|
||||
check(
|
||||
"apktool launcher reports a version",
|
||||
typeof client.client.apktool_version === "string" &&
|
||||
client.client.apktool_version !== "",
|
||||
`command=${client.client.command} version=${client.client.apktool_version}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (options.apk !== null) {
|
||||
const decoded = await run("decode_android_resources", {
|
||||
path: options.apk,
|
||||
include_strings: true,
|
||||
});
|
||||
if (decoded !== null) {
|
||||
const bytes = await stat(options.apk).then((info) => info.size);
|
||||
const digest = createHash("sha256")
|
||||
.update(await readFile(options.apk))
|
||||
.digest("hex");
|
||||
check(
|
||||
"decoded target identity matches the file on disk",
|
||||
decoded.target.bytes === bytes && decoded.target.sha256 === digest,
|
||||
`${bytes} bytes`,
|
||||
);
|
||||
check(
|
||||
"metadata carries version and SDK facts",
|
||||
typeof decoded.metadata.version_name === "string" &&
|
||||
decoded.metadata.min_sdk_version !== null &&
|
||||
decoded.metadata.target_sdk_version !== null,
|
||||
`version=${String(decoded.metadata.version_name)} sdk=${String(decoded.metadata.min_sdk_version)}..${String(decoded.metadata.target_sdk_version)}`,
|
||||
);
|
||||
check(
|
||||
"decoded manifest names the package",
|
||||
typeof decoded.metadata.package_name === "string" &&
|
||||
decoded.manifest !== null &&
|
||||
decoded.manifest.includes(decoded.metadata.package_name),
|
||||
String(decoded.metadata.package_name),
|
||||
);
|
||||
check(
|
||||
"string resources projected",
|
||||
decoded.strings.length > 0,
|
||||
`${decoded.strings.length} string(s)`,
|
||||
);
|
||||
if (decoded.locales.length > 0) {
|
||||
const locale = await run("decode_android_resources", {
|
||||
path: options.apk,
|
||||
include_strings: true,
|
||||
locale: decoded.locales[0],
|
||||
});
|
||||
if (locale !== null)
|
||||
check(
|
||||
`locale table projected for ${String(decoded.locales[0])}`,
|
||||
Array.isArray(locale.strings),
|
||||
`${locale.strings.length} string(s)`,
|
||||
);
|
||||
if (options.apk !== null) {
|
||||
const decoded = await run("decode_android_resources", {
|
||||
path: options.apk,
|
||||
include_strings: true,
|
||||
});
|
||||
if (decoded !== null) {
|
||||
const bytes = await stat(options.apk).then((info) => info.size);
|
||||
const digest = createHash("sha256")
|
||||
.update(await readFile(options.apk))
|
||||
.digest("hex");
|
||||
check(
|
||||
"decoded target identity matches the file on disk",
|
||||
decoded.target.bytes === bytes && decoded.target.sha256 === digest,
|
||||
`${bytes} bytes`,
|
||||
);
|
||||
check(
|
||||
"metadata carries version and SDK facts",
|
||||
typeof decoded.metadata.version_name === "string" &&
|
||||
decoded.metadata.min_sdk_version !== null &&
|
||||
decoded.metadata.target_sdk_version !== null,
|
||||
`version=${String(decoded.metadata.version_name)} sdk=${String(decoded.metadata.min_sdk_version)}..${String(decoded.metadata.target_sdk_version)}`,
|
||||
);
|
||||
check(
|
||||
"decoded manifest names the package",
|
||||
typeof decoded.metadata.package_name === "string" &&
|
||||
decoded.manifest !== null &&
|
||||
decoded.manifest.includes(decoded.metadata.package_name),
|
||||
String(decoded.metadata.package_name),
|
||||
);
|
||||
check(
|
||||
"string resources projected",
|
||||
decoded.strings.length > 0,
|
||||
`${decoded.strings.length} string(s)`,
|
||||
);
|
||||
if (decoded.locales.length > 0) {
|
||||
const locale = await run("decode_android_resources", {
|
||||
path: options.apk,
|
||||
include_strings: true,
|
||||
locale: decoded.locales[0],
|
||||
});
|
||||
if (locale !== null)
|
||||
check(
|
||||
`locale table projected for ${String(decoded.locales[0])}`,
|
||||
Array.isArray(locale.strings),
|
||||
`${locale.strings.length} string(s)`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await provider.close();
|
||||
} catch {
|
||||
// The provider owns per-call workspaces only; closing is best-effort.
|
||||
} catch (cause) {
|
||||
failures += 1;
|
||||
process.stdout.write(
|
||||
`[FAIL] verifier execution — ${cause instanceof Error ? cause.message : String(cause)}\n`,
|
||||
);
|
||||
} finally {
|
||||
try {
|
||||
await provider.close();
|
||||
} catch (cause) {
|
||||
failures += 1;
|
||||
process.stdout.write(
|
||||
`[FAIL] provider cleanup — ${cause instanceof Error ? cause.message : String(cause)}\n`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (failures > 0) {
|
||||
@@ -116,7 +124,12 @@ function parseArguments(argv) {
|
||||
const argument = argv[index];
|
||||
if (argument === "--help" || argument === "-h") parsed.help = true;
|
||||
else if (argument === "--apk") {
|
||||
parsed.apk = argv[index + 1] ?? null;
|
||||
const path = argv[index + 1];
|
||||
if (path === undefined) {
|
||||
process.stderr.write("--apk requires a local APK path\n");
|
||||
process.exit(2);
|
||||
}
|
||||
parsed.apk = path;
|
||||
index += 1;
|
||||
} else {
|
||||
process.stderr.write(`unknown argument: ${argument}\n`);
|
||||
|
||||
@@ -662,6 +662,16 @@ try {
|
||||
bytes.writeBigUInt64LE(8n, header + 56);
|
||||
return [`undersized-entry-${type}`, bytes, "invalid_input"];
|
||||
});
|
||||
const nonintegralSymbolEntries = ["SHT_SYMTAB", "SHT_DYNSYM"].map((type) => {
|
||||
const section = protectedReport.sections.find((item) => item.type === type);
|
||||
assert.notEqual(section, undefined);
|
||||
const bytes = Buffer.from(sectionBearingBytes);
|
||||
const header = Number(BigInt(section.header_location.offset));
|
||||
const size = bytes.readBigUInt64LE(header + 32);
|
||||
assert.ok(size + 1n <= BigInt(bytes.length) - BigInt(section.offset));
|
||||
bytes.writeBigUInt64LE(size + 1n, header + 32);
|
||||
return [`nonintegral-entry-count-${type}`, bytes, "invalid_input"];
|
||||
});
|
||||
const relocationSection = relocatable.sections.find(
|
||||
(item) => item.type === "SHT_RELA",
|
||||
);
|
||||
@@ -677,6 +687,17 @@ try {
|
||||
bytes.writeBigUInt64LE(8n, header + 56);
|
||||
return [`undersized-entry-${type}`, bytes, "invalid_input"];
|
||||
});
|
||||
const nonintegralRelocationEntries = [
|
||||
["RELA", 4, 24],
|
||||
["REL", 9, 16],
|
||||
].map(([type, sectionType, entrySize]) => {
|
||||
const bytes = Buffer.from(object);
|
||||
const header = Number(BigInt(relocationSection.header_location.offset));
|
||||
bytes.writeUInt32LE(sectionType, header + 4);
|
||||
bytes.writeBigUInt64LE(BigInt(entrySize + 1), header + 32);
|
||||
bytes.writeBigUInt64LE(BigInt(entrySize), header + 56);
|
||||
return [`nonintegral-entry-count-${type}`, bytes, "invalid_input"];
|
||||
});
|
||||
const invalidRelocationReferences = [
|
||||
["missing-symbol-table", relocatable.sections.length + 100],
|
||||
["wrong-symbol-table-kind", 1],
|
||||
@@ -1066,7 +1087,9 @@ try {
|
||||
],
|
||||
...zeroSymbolEntries,
|
||||
...undersizedSymbolEntries,
|
||||
...nonintegralSymbolEntries,
|
||||
...undersizedRelocationEntries,
|
||||
...nonintegralRelocationEntries,
|
||||
...invalidRelocationReferences,
|
||||
["unterminated-dynamic-segment", shortDynamic, "invalid_input"],
|
||||
["unterminated-interpreter", unterminatedInterpreter, "invalid_input"],
|
||||
|
||||
@@ -5,11 +5,16 @@ import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import Ajv2020 from "ajv/dist/2020.js";
|
||||
import { CATALOG_IDENTITY } from "../dist/catalogIdentity.js";
|
||||
import {
|
||||
TOOL_CONTRACTS,
|
||||
toolContract,
|
||||
} from "../dist/contracts/toolContracts.js";
|
||||
import { exec } from "./lib/verify-package-core.mjs";
|
||||
import {
|
||||
expandMcpSessionStatus,
|
||||
sortVerifierNames,
|
||||
} from "./lib/mcp-verifier-results.mjs";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
import { createAnthropicModelFixture } from "./verify/clients/anthropic-model-fixture.mjs";
|
||||
|
||||
@@ -58,6 +63,8 @@ await writeFile(
|
||||
'export function result() { return { clientCompatibility: "REA_CLIENT_FIXTURE", count: 7 }; }\n',
|
||||
);
|
||||
let skillRequested = false;
|
||||
let sessionRequested = false;
|
||||
let sessionStatusSeen = false;
|
||||
let skillLoaded = false;
|
||||
let expectedSkillBody;
|
||||
let evidenceSeen = false;
|
||||
@@ -73,7 +80,7 @@ const containsText = (value, text) => {
|
||||
return Object.values(value).some((nested) => containsText(nested, text));
|
||||
return false;
|
||||
};
|
||||
const extractEvidence = (value) => {
|
||||
const extractInlineResult = (value, matches) => {
|
||||
if (typeof value === "string") {
|
||||
try {
|
||||
// Native Claude appends this resource hint to tool results. Original bodies remain intact in request artifacts.
|
||||
@@ -81,20 +88,16 @@ const extractEvidence = (value) => {
|
||||
/\n\n<system-reminder>\n<total_tokens>\d+ tokens left<\/total_tokens>\n<\/system-reminder>$/u,
|
||||
"",
|
||||
);
|
||||
return extractEvidence(JSON.parse(json));
|
||||
return extractInlineResult(JSON.parse(json), matches);
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
if (value && typeof value === "object") {
|
||||
if (
|
||||
typeof value.evidence_id === "string" &&
|
||||
value.normalized_result?.graph?.nodes?.length > 0
|
||||
)
|
||||
return value;
|
||||
if (matches(value)) return value;
|
||||
for (const nested of Object.values(value)) {
|
||||
const evidence = extractEvidence(nested);
|
||||
if (evidence) return evidence;
|
||||
const result = extractInlineResult(nested, matches);
|
||||
if (result) return result;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
@@ -125,10 +128,12 @@ const fixture = await createAnthropicModelFixture({
|
||||
0,
|
||||
-"analyze_javascript_application".length,
|
||||
);
|
||||
const expected = TOOL_CONTRACTS.map((t) => prefix + t.name).sort();
|
||||
const expected = sortVerifierNames(
|
||||
TOOL_CONTRACTS.map((t) => prefix + t.name),
|
||||
);
|
||||
const reaTools = tools.filter((t) => t.name.startsWith(prefix));
|
||||
assert.deepEqual(
|
||||
reaTools.map((t) => t.name).sort(),
|
||||
sortVerifierNames(reaTools.map((t) => t.name)),
|
||||
expected,
|
||||
"Claude must forward the complete REA catalog after connection",
|
||||
);
|
||||
@@ -146,11 +151,61 @@ const fixture = await createAnthropicModelFixture({
|
||||
schemasChecked++;
|
||||
}
|
||||
}
|
||||
if (mode === "call" && !sessionStatusSeen) {
|
||||
const observedStatus = extractInlineResult(
|
||||
body.messages,
|
||||
(value) =>
|
||||
Boolean(value.result?.server_identity) &&
|
||||
Array.isArray(value.result?.tool_availability?.groups),
|
||||
);
|
||||
if (observedStatus) {
|
||||
const parsedStatus =
|
||||
toolContract("binary_session").outputSchema.parse(observedStatus);
|
||||
const status = {
|
||||
...parsedStatus,
|
||||
result: expandMcpSessionStatus(parsedStatus.result),
|
||||
};
|
||||
assert.deepEqual(
|
||||
status.result.server_identity.catalog,
|
||||
CATALOG_IDENTITY,
|
||||
"binary_session must return the exact compact catalog counts and digests",
|
||||
);
|
||||
assert.equal(
|
||||
Object.hasOwn(status.result.server_identity.catalog, "tools"),
|
||||
false,
|
||||
"binary_session must not inline the duplicated canonical tool catalog",
|
||||
);
|
||||
assert.deepEqual(
|
||||
sortVerifierNames(
|
||||
status.result.tool_availability.map((entry) => entry.name),
|
||||
),
|
||||
sortVerifierNames(TOOL_CONTRACTS.map((contract) => contract.name)),
|
||||
"binary_session must retain complete canonical tool availability",
|
||||
);
|
||||
sessionStatusSeen = true;
|
||||
} else {
|
||||
assert(
|
||||
!sessionRequested,
|
||||
"Claude must return the inline binary_session result before continuing",
|
||||
);
|
||||
const session = tools.find(
|
||||
(tool) => tool.name === `${prefix}binary_session`,
|
||||
);
|
||||
assert(session, "Claude must expose the REA binary_session tool");
|
||||
sessionRequested = true;
|
||||
return call(session.name, {});
|
||||
}
|
||||
}
|
||||
skillLoaded ||=
|
||||
expectedSkillBody !== undefined &&
|
||||
containsText(body.messages, expectedSkillBody) &&
|
||||
containsText(body.messages, skillDirectory);
|
||||
const observed = extractEvidence(body.messages);
|
||||
const observed = extractInlineResult(
|
||||
body.messages,
|
||||
(value) =>
|
||||
typeof value.evidence_id === "string" &&
|
||||
value.normalized_result?.graph?.nodes?.length > 0,
|
||||
);
|
||||
if (observed) {
|
||||
const evidence = toolContract(
|
||||
"analyze_javascript_application",
|
||||
@@ -184,7 +239,7 @@ const fixture = await createAnthropicModelFixture({
|
||||
await writeFile(join(lab, "claude-evidence.json"), bytes);
|
||||
evidenceSeen = true;
|
||||
}
|
||||
if (mode === "chat" || evidenceSeen) {
|
||||
if (mode === "chat" || (sessionStatusSeen && evidenceSeen)) {
|
||||
finalSeen = true;
|
||||
return [{ type: "text", text: "REA_CLIENT_COMPATIBILITY_OK" }];
|
||||
}
|
||||
@@ -294,6 +349,7 @@ try {
|
||||
"Skill",
|
||||
"WaitForMcpServers",
|
||||
"mcp__rea__analyze_javascript_application",
|
||||
...(mode === "call" ? ["mcp__rea__binary_session"] : []),
|
||||
],
|
||||
},
|
||||
}),
|
||||
@@ -324,7 +380,7 @@ try {
|
||||
assert.equal(parsed.result, "REA_CLIENT_COMPATIBILITY_OK");
|
||||
assert.deepEqual(parsed.permission_denials, []);
|
||||
assert(finalSeen);
|
||||
if (mode === "call") assert(evidenceSeen && skillLoaded);
|
||||
if (mode === "call") assert(evidenceSeen && skillLoaded && sessionStatusSeen);
|
||||
} catch (cause) {
|
||||
failure = cause;
|
||||
if (typeof cause?.stdout === "string")
|
||||
@@ -355,6 +411,7 @@ try {
|
||||
schemasChecked,
|
||||
pendingServerWaits,
|
||||
evidenceSeen,
|
||||
sessionStatusSeen,
|
||||
skillLoaded,
|
||||
artifactDigest,
|
||||
finalSeen,
|
||||
|
||||
@@ -5,11 +5,12 @@ import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { parse as parseYaml } from "yaml";
|
||||
import {
|
||||
TOOL_CONTRACTS,
|
||||
toolContract,
|
||||
} from "../dist/contracts/toolContracts.js";
|
||||
import { exec } from "./lib/verify-package-core.mjs";
|
||||
import { exec, pathExists } from "./lib/verify-package-core.mjs";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
import { createOpenAiModelFixture } from "./verify/clients/model-fixture.mjs";
|
||||
|
||||
@@ -32,6 +33,7 @@ const skillPath = join(
|
||||
"SKILL.md",
|
||||
);
|
||||
const cli = join(runtimeRoot, "scripts", "rea.mjs");
|
||||
const configPath = join(profile, "cordis.patch.yml");
|
||||
const verifier = createVerifierRun();
|
||||
await Promise.all([
|
||||
mkdir(account),
|
||||
@@ -66,32 +68,32 @@ const clientVersion = (
|
||||
timeout: 30_000,
|
||||
})
|
||||
).stdout.trim();
|
||||
for (const args of [
|
||||
["setup", "--skill", "--dry-run"],
|
||||
["setup", "--skill", "--yes"],
|
||||
]) {
|
||||
const lifecycle = [];
|
||||
const runRea = async (args, artifact) => {
|
||||
const result = await exec(process.execPath, [cli, ...args, "--json"], {
|
||||
env: environment,
|
||||
cwd: workspace,
|
||||
timeout: 60_000,
|
||||
});
|
||||
const parsed = JSON.parse(result.stdout);
|
||||
assert.equal(parsed.status, args.includes("--dry-run") ? "planned" : "ready");
|
||||
if (args.includes("--dry-run")) {
|
||||
assert.equal(parsed.plannedActions.length, 1);
|
||||
assert.equal(parsed.plannedActions[0].kind, "install_skill");
|
||||
assert.equal(parsed.plannedActions[0].target, dirname(skillPath));
|
||||
}
|
||||
await writeFile(
|
||||
join(lab, args.includes("--dry-run") ? "setup-plan.json" : "setup.json"),
|
||||
result.stdout,
|
||||
);
|
||||
}
|
||||
assert(
|
||||
(await readFile(skillPath, "utf8")).includes(
|
||||
"name: reverse-engineer-anything",
|
||||
),
|
||||
);
|
||||
await writeFile(join(lab, `${artifact}.json`), result.stdout);
|
||||
return JSON.parse(result.stdout);
|
||||
};
|
||||
const patches = (text) =>
|
||||
parseYaml(text, {
|
||||
customTags: [
|
||||
{
|
||||
tag: "tag:yaml.org,2002:js",
|
||||
resolve: (source) => ({ __jsExpr: source }),
|
||||
},
|
||||
],
|
||||
});
|
||||
const withoutRea = (text) =>
|
||||
patches(text).flatMap((op) => {
|
||||
if (op.id === "rea-mcp") return [];
|
||||
if (!Array.isArray(op.insert)) return [op];
|
||||
const insert = op.insert.filter((entry) => entry.id !== "rea-mcp");
|
||||
return insert.length === 0 ? [] : [{ ...op, insert }];
|
||||
});
|
||||
|
||||
let catalog;
|
||||
let patternCount = 0;
|
||||
@@ -247,10 +249,9 @@ const fixture = await createOpenAiModelFixture({
|
||||
});
|
||||
let failure;
|
||||
try {
|
||||
// Use the client's native Cordis patch DSL; generic `rea setup --client` does not edit it.
|
||||
await writeFile(
|
||||
join(profile, "cordis.patch.yml"),
|
||||
`
|
||||
// Seed model settings and a stale registration; the public setup workflow
|
||||
// must produce the registration this native client actually boots.
|
||||
const original = `
|
||||
- id: llm-pi-ai
|
||||
config:
|
||||
providers:
|
||||
@@ -275,13 +276,59 @@ try {
|
||||
config:
|
||||
serverName: rea
|
||||
transport: stdio
|
||||
command: ${JSON.stringify(process.execPath)}
|
||||
args: ${JSON.stringify([cli, "mcp"])}
|
||||
command: stale-launcher
|
||||
args: [mcp]
|
||||
cwd: !!js process.cwd()
|
||||
env:
|
||||
REA_PROCESS_RUN_ID: ${JSON.stringify(verifier.run_id)}
|
||||
`,
|
||||
`;
|
||||
await writeFile(configPath, original);
|
||||
const planned = await runRea(
|
||||
["setup", "--client", "dsh", "--dry-run"],
|
||||
"setup-plan",
|
||||
);
|
||||
assert.equal(planned.status, "planned");
|
||||
assert(planned.plannedActions.some((action) => action.target === configPath));
|
||||
assert(
|
||||
planned.plannedActions.some(
|
||||
(action) => action.target === dirname(skillPath),
|
||||
),
|
||||
);
|
||||
assert(
|
||||
planned.plannedActions.every(
|
||||
(action) =>
|
||||
action.target === configPath || action.target === dirname(skillPath),
|
||||
),
|
||||
);
|
||||
assert.equal(await readFile(configPath, "utf8"), original);
|
||||
assert.equal(await pathExists(`${configPath}.rea.backup`), false);
|
||||
lifecycle.push("dry-run");
|
||||
const setup = await runRea(["setup", "--client", "dsh", "--yes"], "setup");
|
||||
assert.equal(setup.status, "ready");
|
||||
assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original);
|
||||
const configured = await readFile(configPath, "utf8");
|
||||
assert.deepEqual(withoutRea(configured), withoutRea(original));
|
||||
assert(configured.includes("!!js process.cwd()"));
|
||||
assert(
|
||||
(await readFile(skillPath, "utf8")).includes(
|
||||
"name: reverse-engineer-anything",
|
||||
),
|
||||
);
|
||||
lifecycle.push("setup");
|
||||
const repeated = await runRea(
|
||||
["setup", "--client", "dsh", "--yes"],
|
||||
"setup-repeat",
|
||||
);
|
||||
assert.deepEqual(repeated.appliedActions, []);
|
||||
assert.equal(await readFile(configPath, "utf8"), configured);
|
||||
assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original);
|
||||
lifecycle.push("idempotent-setup");
|
||||
const doctor = await runRea(
|
||||
["doctor", "--client", "dsh", "--skill"],
|
||||
"doctor",
|
||||
);
|
||||
assert.equal(doctor.healthy, true);
|
||||
lifecycle.push("doctor");
|
||||
const execution = exec(
|
||||
command,
|
||||
[
|
||||
@@ -304,6 +351,20 @@ try {
|
||||
assert.equal(fixture.failure, undefined);
|
||||
assert(finalSeen && result.stdout.includes("REA_CLIENT_COMPATIBILITY_OK"));
|
||||
if (mode === "call") assert(evidenceSeen && skillLoaded);
|
||||
lifecycle.push(mode === "call" ? "native-tool-invocation" : "native-chat");
|
||||
const uninstall = await runRea(["uninstall"], "uninstall");
|
||||
assert.equal(uninstall.status, "complete");
|
||||
assert(
|
||||
uninstall.items.some(
|
||||
(item) => item.name === "dsh" && item.status === "removed",
|
||||
),
|
||||
);
|
||||
assert.deepEqual(
|
||||
patches(await readFile(configPath, "utf8")),
|
||||
withoutRea(original),
|
||||
);
|
||||
assert.equal(await pathExists(skillPath), false);
|
||||
lifecycle.push("uninstall");
|
||||
} catch (cause) {
|
||||
failure = cause;
|
||||
if (typeof cause?.stdout === "string")
|
||||
@@ -316,6 +377,7 @@ try {
|
||||
client: "deepseek-harness",
|
||||
clientVersion,
|
||||
mode,
|
||||
lifecycle,
|
||||
passed: failure === undefined,
|
||||
artifacts: lab,
|
||||
runtimeRoot,
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { readdir, readFile } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { toolContract } from "../dist/contracts/toolContracts.js";
|
||||
import { PrivateRuntimeRoot } from "../dist/process/PrivateRuntimeRoot.js";
|
||||
import { hashStableFile } from "../dist/filesystem/StableFileHash.js";
|
||||
import { mcpTextValue } from "./lib/mcp-verifier-results.mjs";
|
||||
|
||||
const options = parseArguments(process.argv.slice(2));
|
||||
if (options.help) {
|
||||
process.stdout.write(
|
||||
"Usage: npm run verify:flutter -- --apk PATH [--plain-apk PATH] [--expectations JSON]\n" +
|
||||
"Checks real APK parsing through compiled CLI and stdio MCP. Optional\n" +
|
||||
"expectations bind exact engine labels, URI counts and snapshot hash to an APK digest.\n",
|
||||
);
|
||||
process.exit(0);
|
||||
}
|
||||
if (options.apk === null) {
|
||||
process.stderr.write("No Flutter APK was provided; pass --apk PATH.\n");
|
||||
process.exit(2);
|
||||
}
|
||||
const expectations =
|
||||
options.expectations === null
|
||||
? null
|
||||
: JSON.parse(await readFile(options.expectations, "utf8"));
|
||||
const root = await PrivateRuntimeRoot.create({
|
||||
prefix: "rea-flutter-verifier-",
|
||||
});
|
||||
const entrypoint = resolve("scripts/rea.mjs");
|
||||
const environment = Object.fromEntries(
|
||||
Object.entries(process.env).filter(([, value]) => typeof value === "string"),
|
||||
);
|
||||
Object.assign(environment, {
|
||||
TMPDIR: root.path,
|
||||
TMP: root.path,
|
||||
TEMP: root.path,
|
||||
});
|
||||
const client = new Client({ name: "flutter-verifier", version: "1" });
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
env: environment,
|
||||
stderr: "pipe",
|
||||
});
|
||||
const execute = promisify(execFile);
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const apk = resolve(options.apk);
|
||||
const identity = await hashStableFile(apk);
|
||||
const identified = await run("identify_flutter_build", { path: apk });
|
||||
assert.deepEqual(identified.target, { path: apk, ...identity });
|
||||
assert.equal(identified.flutter_detected, true);
|
||||
assert.equal(identified.coverage, "complete");
|
||||
const abis = identified.abis.filter((abi) => abi.libapp.present);
|
||||
assert.ok(abis.length > 0);
|
||||
const hashes = new Set();
|
||||
for (const abi of abis) {
|
||||
assert.equal(abi.libapp.elf_header_valid, true);
|
||||
assert.equal(abi.libapp.snapshot_hash_sources, 2);
|
||||
assert.ok(abi.libapp.snapshot_hash);
|
||||
hashes.add(abi.libapp.snapshot_hash);
|
||||
assert.equal(abi.libflutter.present, true);
|
||||
assert.match(abi.libflutter.build_id ?? "", /^(?:[0-9a-f]{2}){4,64}$/u);
|
||||
assert.deepEqual(abi.libflutter.build_id_candidates, [
|
||||
abi.libflutter.build_id,
|
||||
]);
|
||||
}
|
||||
assert.equal(hashes.size, 1, "Every ABI must agree on the snapshot hash");
|
||||
if (expectations !== null) {
|
||||
assert.equal(identity.sha256, expectations.target_sha256);
|
||||
assert.deepEqual([...hashes], [expectations.snapshot_hash]);
|
||||
assert.deepEqual(
|
||||
abis.map((abi) => abi.abi).sort(),
|
||||
Object.keys(expectations.engines).sort(),
|
||||
);
|
||||
for (const abi of abis) {
|
||||
assert.deepEqual(
|
||||
{
|
||||
dart_version: abi.libflutter.dart_version,
|
||||
toolchain_lines: abi.libflutter.toolchain_lines,
|
||||
},
|
||||
expectations.engines[abi.abi],
|
||||
);
|
||||
assert.equal(abi.libflutter.dart_version_capped, false);
|
||||
assert.equal(abi.libflutter.toolchain_capped, false);
|
||||
}
|
||||
process.stdout.write(
|
||||
"[ok] Exact per-ABI engine labels match digest-bound expectations\n",
|
||||
);
|
||||
} else {
|
||||
process.stdout.write(
|
||||
"[unverified] Exact engine labels and their absence need --expectations JSON\n",
|
||||
);
|
||||
}
|
||||
// The same checks apply to the default selection and each remaining ABI.
|
||||
const preferred = await run("inspect_dart_aot", { path: apk });
|
||||
for (const abi of abis) {
|
||||
const aot =
|
||||
abi.abi === preferred.abi
|
||||
? preferred
|
||||
: await run("inspect_dart_aot", { path: apk, abi: abi.abi });
|
||||
assert.equal(aot.abi, abi.abi);
|
||||
assert.equal(
|
||||
aot.libapp.coverage,
|
||||
"complete",
|
||||
`Snapshot decoding must be complete on ${abi.abi}`,
|
||||
);
|
||||
assert.equal(aot.coverage, aot.string_pool.coverage);
|
||||
if (aot.coverage !== "complete") {
|
||||
process.stdout.write(
|
||||
`[unverified] ${abi.abi}: full string-pool projection (returned pool is bounded and partial)\n`,
|
||||
);
|
||||
}
|
||||
assert.deepEqual(aot.target, identified.target);
|
||||
assert.equal(aot.libapp.sha256, abi.libapp.sha256);
|
||||
assert.equal(aot.libapp.bytes, abi.libapp.bytes);
|
||||
assert.equal(aot.libapp.snapshot_hash_sources, 2);
|
||||
assert.equal(aot.libapp.snapshot_hash, abi.libapp.snapshot_hash);
|
||||
assert.deepEqual(
|
||||
aot.libapp.sections.map((section) => section.name).sort(),
|
||||
[
|
||||
"_kDartVmSnapshotData",
|
||||
"_kDartVmSnapshotInstructions",
|
||||
"_kDartIsolateSnapshotData",
|
||||
"_kDartIsolateSnapshotInstructions",
|
||||
].sort(),
|
||||
);
|
||||
for (const section of aot.libapp.sections) {
|
||||
assert.ok(section.offset + section.size <= aot.libapp.bytes);
|
||||
if (!section.name.endsWith("Data")) continue;
|
||||
assert.equal(section.magic_valid, true);
|
||||
assert.equal(
|
||||
section.kind,
|
||||
3,
|
||||
"This verifier requires an AOT app snapshot",
|
||||
);
|
||||
assert.ok(
|
||||
section.header_length >= 48 &&
|
||||
section.header_length + 4 <= section.size,
|
||||
`Snapshot extent must fit ${section.name} on ${abi.abi}`,
|
||||
);
|
||||
}
|
||||
assert.ok(aot.string_pool.package_uri_count_at_least > 0);
|
||||
assert.ok(aot.string_pool.dart_uri_count_at_least > 0);
|
||||
if (expectations?.string_pools !== undefined) {
|
||||
const expected = expectations.string_pools[abi.abi];
|
||||
assert.ok(
|
||||
expected,
|
||||
`Pinned string-pool counts are required on ${abi.abi}`,
|
||||
);
|
||||
assert.equal(
|
||||
aot.string_pool.package_uri_count_at_least,
|
||||
expected.package_uri_count_at_least,
|
||||
);
|
||||
assert.equal(
|
||||
aot.string_pool.dart_uri_count_at_least,
|
||||
expected.dart_uri_count_at_least,
|
||||
);
|
||||
process.stdout.write(
|
||||
`[ok] ${abi.abi}: exact pinned package and Dart URI counts\n`,
|
||||
);
|
||||
} else {
|
||||
process.stdout.write(
|
||||
`[unverified] ${abi.abi}: exact string-pool counts need --expectations JSON\n`,
|
||||
);
|
||||
}
|
||||
process.stdout.write(
|
||||
`[ok] ${abi.abi}: four symbols, bounded AOT headers, agreeing hashes and string pool\n`,
|
||||
);
|
||||
}
|
||||
if (options.plainApk !== null) {
|
||||
const plain = resolve(options.plainApk);
|
||||
const negative = await run("identify_flutter_build", { path: plain });
|
||||
assert.deepEqual(negative.target, {
|
||||
path: plain,
|
||||
...(await hashStableFile(plain)),
|
||||
});
|
||||
assert.equal(negative.flutter_detected, false);
|
||||
assert.equal(negative.coverage, "complete");
|
||||
}
|
||||
assert.deepEqual(
|
||||
await hashStableFile(apk),
|
||||
identity,
|
||||
"Verification must preserve its input",
|
||||
);
|
||||
} finally {
|
||||
// Server shutdown retries retained provider cleanup and must settle before success.
|
||||
try {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
assert.deepEqual(
|
||||
await readdir(root.path),
|
||||
[],
|
||||
"Provider snapshots must be released before verification succeeds",
|
||||
);
|
||||
} finally {
|
||||
await root.close();
|
||||
}
|
||||
}
|
||||
process.stdout.write(
|
||||
"all asserted Flutter CLI/MCP checks passed; unverified facets are reported above\n",
|
||||
);
|
||||
|
||||
async function run(operation, input) {
|
||||
const contract = toolContract(operation);
|
||||
const args = [
|
||||
entrypoint,
|
||||
operation.replaceAll("_", "-"),
|
||||
input.path,
|
||||
"--json",
|
||||
];
|
||||
if (input.abi !== undefined) args.push("--abi", input.abi);
|
||||
const { stdout } = await execute(process.execPath, args, {
|
||||
env: environment,
|
||||
timeout: 60_000,
|
||||
maxBuffer: 8 * 1024 * 1024,
|
||||
});
|
||||
const cli = contract.outputSchema.parse(JSON.parse(stdout));
|
||||
const response = await client.callTool(
|
||||
{ name: operation, arguments: input },
|
||||
{ timeout: 60_000 },
|
||||
);
|
||||
assert.notEqual(response.isError, true, mcpTextValue(response));
|
||||
const mcp = contract.outputSchema.parse(JSON.parse(mcpTextValue(response)));
|
||||
assert.deepEqual(cli.normalized_result, mcp.normalized_result);
|
||||
assert.deepEqual(cli.subject, mcp.subject);
|
||||
assert.equal(cli.subject.local_path, input.path);
|
||||
assert.equal(cli.subject.digest.sha256, cli.normalized_result.target.sha256);
|
||||
assert.deepEqual(cli.limitations, mcp.limitations);
|
||||
process.stdout.write(
|
||||
`[ok] ${operation}${input.abi === undefined ? "" : ` ${input.abi}`}: CLI/MCP Evidence parity\n`,
|
||||
);
|
||||
return cli.normalized_result;
|
||||
}
|
||||
|
||||
function parseArguments(argv) {
|
||||
const parsed = { help: false, apk: null, plainApk: null, expectations: null };
|
||||
const names = {
|
||||
"--apk": "apk",
|
||||
"--plain-apk": "plainApk",
|
||||
"--expectations": "expectations",
|
||||
};
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const argument = argv[index];
|
||||
if (argument === "--help" || argument === "-h") parsed.help = true;
|
||||
else if (
|
||||
Object.hasOwn(names, argument) &&
|
||||
typeof argv[index + 1] === "string" &&
|
||||
!argv[index + 1].startsWith("--")
|
||||
) {
|
||||
parsed[names[argument]] = argv[++index];
|
||||
} else throw new Error(`Unknown argument or missing value: ${argument}`);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
import { basename } from "node:path";
|
||||
|
||||
import { FridaInstrumentationService } from "../dist/application/frida/FridaInstrumentationService.js";
|
||||
import { FridaInstrumentationManager } from "../dist/frida/FridaInstrumentationManager.js";
|
||||
import { isValidFridaRemoteAddress } from "../dist/contracts/fridaRemoteAddress.js";
|
||||
|
||||
const options = parseArguments(process.argv.slice(2));
|
||||
if (options.help) {
|
||||
process.stdout.write(
|
||||
"Usage: npm run verify:frida [-- --address HOST:PORT --pid PID [remote auth flags]]\n" +
|
||||
"Without flags, verifies a local Node.js process created by this script.\n",
|
||||
);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const manager = new FridaInstrumentationManager();
|
||||
const service = new FridaInstrumentationService(manager);
|
||||
const remote =
|
||||
options.address === undefined
|
||||
? undefined
|
||||
: {
|
||||
address: options.address,
|
||||
...(options.token === undefined ? {} : { token: options.token }),
|
||||
...(options.certificate === undefined
|
||||
? {}
|
||||
: { certificate: options.certificate }),
|
||||
...(options.origin === undefined ? {} : { origin: options.origin }),
|
||||
...(options.keepaliveInterval === undefined
|
||||
? {}
|
||||
: { keepaliveInterval: options.keepaliveInterval }),
|
||||
};
|
||||
|
||||
try {
|
||||
let targetProcess;
|
||||
let input;
|
||||
if (remote === undefined) {
|
||||
input = {
|
||||
mode: "spawn",
|
||||
deviceId: "local",
|
||||
program: process.execPath,
|
||||
argv: ["-e", "setTimeout(() => {}, 1500)"],
|
||||
source: {
|
||||
sourceKind: "inline",
|
||||
source: "send({ rea_frida_verification: 'ok', pid: Process.id });",
|
||||
},
|
||||
durationMs: 500,
|
||||
};
|
||||
targetProcess = { pid: undefined, name: basename(process.execPath) };
|
||||
} else {
|
||||
const inventory = await service.listProcesses({ remote });
|
||||
if (!inventory.ok) throw new Error(inventory.error.message);
|
||||
targetProcess = inventory.value.processes.find(
|
||||
({ pid }) => pid === options.pid,
|
||||
);
|
||||
if (targetProcess === undefined)
|
||||
throw new Error(
|
||||
`Selected PID ${String(options.pid)} was not observed remotely`,
|
||||
);
|
||||
input = {
|
||||
mode: "attach",
|
||||
remote,
|
||||
pid: options.pid,
|
||||
source: {
|
||||
sourceKind: "inline",
|
||||
source: "send({ rea_frida_verification: 'ok', pid: Process.id });",
|
||||
},
|
||||
durationMs: 500,
|
||||
};
|
||||
}
|
||||
|
||||
const result = await service.instrument(input);
|
||||
if (!result.ok) throw new Error(result.error.message);
|
||||
const observed = result.value.evidence.normalized_result;
|
||||
if (
|
||||
typeof observed !== "object" ||
|
||||
observed === null ||
|
||||
Array.isArray(observed) ||
|
||||
!Array.isArray(observed.messages)
|
||||
)
|
||||
throw new Error("Frida returned no message observation");
|
||||
const messageObserved = observed.messages.some(
|
||||
(message) =>
|
||||
typeof message === "object" &&
|
||||
message !== null &&
|
||||
!Array.isArray(message) &&
|
||||
message.type === "send" &&
|
||||
typeof message.payload === "object" &&
|
||||
message.payload !== null &&
|
||||
!Array.isArray(message.payload) &&
|
||||
message.payload.rea_frida_verification === "ok" &&
|
||||
message.payload.pid === observed.pid,
|
||||
);
|
||||
if (!messageObserved)
|
||||
throw new Error("Selected target did not return the Frida marker");
|
||||
const report = {
|
||||
ok: result.value.cleanupError === null,
|
||||
provider: "frida",
|
||||
host_platform: process.platform,
|
||||
target_mode: remote === undefined ? "local_spawn" : "remote_attach",
|
||||
target_pid: observed.pid,
|
||||
target_name: targetProcess.name,
|
||||
...(remote === undefined ? {} : { remote_target_observed: true }),
|
||||
script_message_observed: true,
|
||||
cleanup_error: result.value.cleanupError,
|
||||
};
|
||||
process.stdout.write(`${JSON.stringify(report)}\n`);
|
||||
if (!report.ok) process.exitCode = 1;
|
||||
} catch (cause) {
|
||||
process.stderr.write(
|
||||
`Frida real-provider verification failed: ${cause instanceof Error ? cause.message : String(cause)}\n`,
|
||||
);
|
||||
process.exitCode = 1;
|
||||
} finally {
|
||||
await manager.closeAll().catch(() => undefined);
|
||||
}
|
||||
|
||||
function parseArguments(args) {
|
||||
if (args.length === 1 && args[0] === "--help") return { help: true };
|
||||
const values = parseOptionValues(args);
|
||||
const address = values.get("--address");
|
||||
const pidValue = values.get("--pid");
|
||||
const pid = parseRemotePid(address, pidValue);
|
||||
if (address === undefined) assertNoRemoteOptions(values);
|
||||
const keepaliveInterval = parseKeepalive(values.get("--keepalive-interval"));
|
||||
return {
|
||||
help: false,
|
||||
...(address === undefined ? {} : { address }),
|
||||
...(pid === undefined ? {} : { pid }),
|
||||
...(values.has("--token") ? { token: values.get("--token") } : {}),
|
||||
...(values.has("--certificate")
|
||||
? { certificate: values.get("--certificate") }
|
||||
: {}),
|
||||
...(values.has("--origin") ? { origin: values.get("--origin") } : {}),
|
||||
...(keepaliveInterval === undefined ? {} : { keepaliveInterval }),
|
||||
};
|
||||
}
|
||||
|
||||
function parseOptionValues(args) {
|
||||
const values = new Map();
|
||||
const valueFlags = new Set([
|
||||
"--address",
|
||||
"--pid",
|
||||
"--token",
|
||||
"--certificate",
|
||||
"--origin",
|
||||
"--keepalive-interval",
|
||||
]);
|
||||
for (let index = 0; index < args.length; index += 1) {
|
||||
const flag = args[index];
|
||||
const value = args[index + 1];
|
||||
if (
|
||||
typeof flag !== "string" ||
|
||||
!valueFlags.has(flag) ||
|
||||
value === undefined ||
|
||||
values.has(flag)
|
||||
)
|
||||
throw new Error(
|
||||
"Expected no arguments for local-fixture verification, or --address HOST:PORT --pid PID and optional remote auth flags",
|
||||
);
|
||||
values.set(flag, value);
|
||||
index += 1;
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
function parseRemotePid(address, pidValue) {
|
||||
if ((address === undefined) !== (pidValue === undefined))
|
||||
throw new Error("Remote verification requires both --address and --pid");
|
||||
if (address !== undefined && !isValidFridaRemoteAddress(address))
|
||||
throw new Error(
|
||||
"--address must be a host[:port] without credentials, path, query, or fragment",
|
||||
);
|
||||
const pid = pidValue === undefined ? undefined : Number(pidValue);
|
||||
if (pid !== undefined && (!Number.isSafeInteger(pid) || pid <= 0))
|
||||
throw new Error("--pid must be a positive process identifier");
|
||||
return pid;
|
||||
}
|
||||
|
||||
function assertNoRemoteOptions(values) {
|
||||
for (const flag of [
|
||||
"--token",
|
||||
"--certificate",
|
||||
"--origin",
|
||||
"--keepalive-interval",
|
||||
])
|
||||
if (values.has(flag))
|
||||
throw new Error("Remote connection options require --address and --pid");
|
||||
}
|
||||
|
||||
function parseKeepalive(value) {
|
||||
const interval = value === undefined ? undefined : Number(value);
|
||||
if (
|
||||
interval !== undefined &&
|
||||
(!Number.isSafeInteger(interval) || interval <= 0)
|
||||
)
|
||||
throw new Error("--keepalive-interval must be a positive integer");
|
||||
return interval;
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import assert from "node:assert/strict";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, mkdtemp, readFile, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { join, resolve, sep } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import Ajv2020 from "ajv/dist/2020.js";
|
||||
import {
|
||||
@@ -13,14 +13,18 @@ import { exec } from "./lib/verify-package-core.mjs";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
import { createGeminiModelFixture } from "./verify/clients/gemini-model-fixture.mjs";
|
||||
|
||||
assert(
|
||||
process.platform !== "win32",
|
||||
"Native Gemini verifier requires POSIX; Windows is unverified",
|
||||
);
|
||||
const repo = fileURLToPath(new URL("..", import.meta.url));
|
||||
const runtimeRoot = process.env.REA_VERIFY_RUNTIME_ROOT ?? repo;
|
||||
const command = process.env.REA_VERIFY_GEMINI_COMMAND ?? "gemini";
|
||||
const mode = process.argv[2] ?? "call";
|
||||
// npm installs of Gemini CLI provide a JavaScript entry point; on Windows only a gemini.cmd shim reaches
|
||||
// PATH, which Node does not spawn without a shell, so a selected .js entry runs under this Node. It is
|
||||
// resolved once, because the preflight runs from the caller's directory and the client from the workspace.
|
||||
const entryPoint = /\.(c|m)?js$/iu.test(command) ? resolve(command) : undefined;
|
||||
const launch = (args) =>
|
||||
entryPoint === undefined
|
||||
? [command, args]
|
||||
: [process.execPath, [entryPoint, ...args]];
|
||||
assert(
|
||||
["chat", "call"].includes(mode),
|
||||
"Usage: verify-gemini-client.mjs [chat|call]",
|
||||
@@ -60,11 +64,15 @@ const environment = {
|
||||
let clientVersion;
|
||||
try {
|
||||
clientVersion = (
|
||||
await exec(command, ["--version"], { env: environment, timeout: 30_000 })
|
||||
await exec(...launch(["--version"]), { env: environment, timeout: 30_000 })
|
||||
).stdout.trim();
|
||||
} catch (cause) {
|
||||
const windowsHint =
|
||||
process.platform === "win32"
|
||||
? " On Windows, select the JavaScript entry point; npm installs provide it as node_modules/@google/gemini-cli/bundle/gemini.js."
|
||||
: "";
|
||||
throw new Error(
|
||||
`Gemini preflight failed for ${command}; install Gemini CLI or set REA_VERIFY_GEMINI_COMMAND. ${String(cause)}`,
|
||||
`Gemini preflight failed for ${command}; install Gemini CLI or set REA_VERIFY_GEMINI_COMMAND.${windowsHint} ${String(cause)}`,
|
||||
);
|
||||
}
|
||||
const original = JSON.stringify(
|
||||
@@ -103,11 +111,11 @@ for (const args of [
|
||||
assert(parsed.plannedActions.some((a) => a.target === configPath));
|
||||
assert(
|
||||
parsed.plannedActions.some((a) =>
|
||||
a.target.startsWith(join(profile, ".agents", "skills") + "/"),
|
||||
a.target.startsWith(join(profile, ".agents", "skills") + sep),
|
||||
),
|
||||
);
|
||||
assert(
|
||||
parsed.plannedActions.every((a) => a.target.startsWith(profile + "/")),
|
||||
parsed.plannedActions.every((a) => a.target.startsWith(profile + sep)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -300,8 +308,7 @@ const fixture = await createGeminiModelFixture({
|
||||
let failure;
|
||||
try {
|
||||
const response = await exec(
|
||||
command,
|
||||
[
|
||||
...launch([
|
||||
"--model",
|
||||
"gemini-2.5-flash",
|
||||
"--approval-mode",
|
||||
@@ -314,7 +321,7 @@ try {
|
||||
mode === "chat"
|
||||
? "Say hello briefly."
|
||||
: `Use REA to analyze the JavaScript directory ${target}. Report the result.`,
|
||||
],
|
||||
]),
|
||||
{
|
||||
env: {
|
||||
...environment,
|
||||
|
||||
@@ -0,0 +1,528 @@
|
||||
#!/usr/bin/env node
|
||||
import assert from "node:assert/strict";
|
||||
import { isUtf8 } from "node:buffer";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { isAbsolute, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { parseEvidence } from "../dist/domain/evidence.js";
|
||||
import { goBinarySchema } from "../dist/domain/go/goBinary.js";
|
||||
import { PrivateRuntimeRoot } from "../dist/process/PrivateRuntimeRoot.js";
|
||||
import { mcpTextValue } from "./lib/mcp-verifier-results.mjs";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
const compiler = process.env.REA_VERIFY_GO_COMMAND ?? "go";
|
||||
if (process.env.REA_VERIFY_GO_COMMAND !== undefined && !isAbsolute(compiler))
|
||||
throw new Error(
|
||||
"REA_VERIFY_GO_COMMAND must be an absolute Go compiler path.",
|
||||
);
|
||||
let compilerVersion = null;
|
||||
const run = createVerifierRun();
|
||||
const root = await PrivateRuntimeRoot.create({ prefix: "rea-go-verifier-" });
|
||||
const entrypoint = fileURLToPath(new URL("./rea.mjs", import.meta.url));
|
||||
const environment = Object.fromEntries(
|
||||
Object.entries(process.env).filter(([, value]) => typeof value === "string"),
|
||||
);
|
||||
delete environment.HOPPER_TARGET_PATH;
|
||||
const goEnvironment = {
|
||||
...environment,
|
||||
CGO_ENABLED: "0",
|
||||
GOCACHEPROG: "",
|
||||
GO111MODULE: "on",
|
||||
GOENV: "off",
|
||||
GOFLAGS: "",
|
||||
GOMAXPROCS: "2",
|
||||
GOTOOLCHAIN: "local",
|
||||
GOWORK: "off",
|
||||
GOPROXY: "off",
|
||||
GOSUMDB: "off",
|
||||
GOPATH: join(root.path, "gopath"),
|
||||
GOCACHE: join(root.path, "cache"),
|
||||
GOMODCACHE: join(root.path, "modules"),
|
||||
GOTMPDIR: join(root.path, "tmp"),
|
||||
// Go's own verifier seam isolates telemetry; no global configuration is changed.
|
||||
TEST_TELEMETRY_DIR: join(root.path, "telemetry"),
|
||||
};
|
||||
const client = new Client({ name: "go-binary-verifier", version: "1" });
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
env: environment,
|
||||
stderr: "pipe",
|
||||
});
|
||||
const targets = [
|
||||
["linux", "amd64", "elf", 64, "little"],
|
||||
["linux", "386", "elf", 32, "little"],
|
||||
["linux", "arm64", "elf", 64, "little"],
|
||||
["linux", "ppc64", "elf", 64, "big"],
|
||||
["linux", "mips", "elf", 32, "big"],
|
||||
["windows", "amd64", "pe", 64, "little"],
|
||||
["windows", "386", "pe", 32, "little"],
|
||||
["darwin", "amd64", "macho", 64, "little"],
|
||||
["darwin", "arm64", "macho", 64, "little"],
|
||||
];
|
||||
const verified = [];
|
||||
const omittedCoverage = [];
|
||||
const failures = [];
|
||||
try {
|
||||
await prepareFixture();
|
||||
try {
|
||||
compilerVersion = (
|
||||
await execute(compiler, ["version"], {
|
||||
cwd: root.path,
|
||||
env: goEnvironment,
|
||||
timeout: 10_000,
|
||||
})
|
||||
).stdout.trim();
|
||||
} catch (cause) {
|
||||
throw new Error(
|
||||
"verify:go:binary requires Go on PATH or absolute REA_VERIFY_GO_COMMAND; Go is only a fixture producer, not a REA runtime dependency.",
|
||||
{ cause },
|
||||
);
|
||||
}
|
||||
const host = (await go(["env", "GOHOSTOS", "GOHOSTARCH"])).stdout
|
||||
.trim()
|
||||
.split("\n");
|
||||
const oracle = join(
|
||||
root.path,
|
||||
host[0] === "windows" ? "buildinfo-oracle.exe" : "buildinfo-oracle",
|
||||
);
|
||||
await go(
|
||||
["build", "-trimpath", "-buildvcs=false", "-o", oracle, "./oracle"],
|
||||
{ GOOS: host[0], GOARCH: host[1] },
|
||||
);
|
||||
await client.connect(transport);
|
||||
for (const target of targets) {
|
||||
const [os, arch] = target;
|
||||
const path = join(
|
||||
root.path,
|
||||
`${os}-${arch}${os === "windows" ? ".exe" : ""}`,
|
||||
);
|
||||
await go(
|
||||
[
|
||||
"build",
|
||||
"-trimpath",
|
||||
"-buildvcs=false",
|
||||
"-ldflags=-s -w",
|
||||
"-o",
|
||||
path,
|
||||
".",
|
||||
],
|
||||
{ GOOS: os, GOARCH: arch },
|
||||
);
|
||||
await verify(path, target, oracle, null, "stripped");
|
||||
if (os === "linux" && arch === "amd64") {
|
||||
const sectionless = join(root.path, "linux-amd64-sectionless");
|
||||
const bytes = Buffer.from(await readFile(path));
|
||||
bytes.fill(0, 40, 48); // ELF64 e_shoff.
|
||||
bytes.fill(0, 58, 64); // e_shentsize, e_shnum and e_shstrndx.
|
||||
await writeFile(sectionless, bytes);
|
||||
await verify(sectionless, target, oracle, null, "sectionless");
|
||||
}
|
||||
}
|
||||
for (const target of targets.filter(([os]) => os === "darwin")) {
|
||||
const [os, arch] = target;
|
||||
const path = join(root.path, `${os}-${arch}-unstripped`);
|
||||
await go(["build", "-trimpath", "-buildvcs=false", "-o", path, "."], {
|
||||
GOOS: os,
|
||||
GOARCH: arch,
|
||||
});
|
||||
await verify(path, target, oracle, null, "unstripped");
|
||||
}
|
||||
if (process.platform === "win32")
|
||||
omittedCoverage.push(
|
||||
"Compiler-produced non-UTF-8 argv strings were not verified on Windows; Windows argv cannot preserve arbitrary byte arguments.",
|
||||
);
|
||||
else {
|
||||
const path = join(root.path, "linux-amd64-byte-strings");
|
||||
const expected = JSON.parse(
|
||||
(
|
||||
await execute(oracle, ["--build-byte-fixture", compiler, path], {
|
||||
cwd: root.path,
|
||||
env: { ...goEnvironment, GOOS: "linux", GOARCH: "amd64" },
|
||||
timeout: 120_000,
|
||||
maxBuffer: 1024 * 1024,
|
||||
})
|
||||
).stdout,
|
||||
);
|
||||
await verify(path, targets[0], oracle, expected);
|
||||
}
|
||||
} catch (cause) {
|
||||
failures.push(cause);
|
||||
} finally {
|
||||
for (const close of [
|
||||
() => client.close(),
|
||||
() => transport.close(),
|
||||
() => root.close(),
|
||||
]) {
|
||||
try {
|
||||
await close();
|
||||
} catch (cause) {
|
||||
failures.push(cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
const verifier = await completeVerifierRun(run);
|
||||
try {
|
||||
await assert.rejects(readFile(join(root.path, "go.mod")), { code: "ENOENT" });
|
||||
if (verifier.process_lineage.status === "verified")
|
||||
assert.deepEqual(verifier.process_lineage.descendants, []);
|
||||
} catch (cause) {
|
||||
failures.push(cause);
|
||||
}
|
||||
if (failures.length > 0) {
|
||||
console.error(
|
||||
JSON.stringify(
|
||||
{
|
||||
status: "failed",
|
||||
compiler: compilerVersion,
|
||||
verified,
|
||||
omitted_coverage: omittedCoverage,
|
||||
verifier,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
throw new AggregateError(
|
||||
failures,
|
||||
"Real Go metadata verification failed; cleanup failures are retained.",
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
status: "passed",
|
||||
compiler: compilerVersion,
|
||||
binaries: verified.length,
|
||||
public_cases: verified.length * 2,
|
||||
verified,
|
||||
omitted_coverage: omittedCoverage,
|
||||
fixture_execution:
|
||||
"not-requested; only the Go fixture producer and test-owned buildinfo oracle/helper were executed",
|
||||
verifier,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
|
||||
async function go(args, overrides = {}) {
|
||||
return execute(compiler, args, {
|
||||
cwd: root.path,
|
||||
env: { ...goEnvironment, ...overrides },
|
||||
timeout: 120_000,
|
||||
maxBuffer: 1024 * 1024,
|
||||
});
|
||||
}
|
||||
|
||||
async function prepareFixture() {
|
||||
await mkdir(join(root.path, "tmp"));
|
||||
await mkdir(join(root.path, "telemetry"));
|
||||
await writeFile(join(root.path, "telemetry", "mode"), "off\n");
|
||||
await mkdir(join(root.path, "dependency"));
|
||||
await mkdir(join(root.path, "oracle"));
|
||||
await writeFile(
|
||||
join(root.path, "go.mod"),
|
||||
"module example.test/rea-go-fixture\n\ngo 1.20\n\nrequire example.test/dependency v1.2.3\nreplace example.test/dependency => ./dependency\n",
|
||||
);
|
||||
await writeFile(
|
||||
join(root.path, "dependency", "go.mod"),
|
||||
"module example.test/dependency\n\ngo 1.20\n",
|
||||
);
|
||||
await writeFile(
|
||||
join(root.path, "dependency", "dependency.go"),
|
||||
'package dependency\nfunc Value() string { return "REA fixture" }\n',
|
||||
);
|
||||
await writeFile(
|
||||
join(root.path, "main.go"),
|
||||
'package main\nimport ("fmt"; "example.test/dependency")\nfunc main() { fmt.Println(dependency.Value()) }\n',
|
||||
);
|
||||
await writeFile(
|
||||
join(root.path, "oracle", "main.go"),
|
||||
String.raw`package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"debug/buildinfo"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func main() {
|
||||
byteFixture := len(os.Args) == 4 && os.Args[1] == "--build-byte-fixture"
|
||||
path := os.Args[1]
|
||||
if byteFixture {
|
||||
path = os.Args[3]
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, os.Args[2], "build", "-buildvcs=false",
|
||||
"-tags=" + string([]byte{0xff}),
|
||||
"-ldflags=-X runtime.buildVersion=custom" + string([]byte{0xff}),
|
||||
"-o", path, ".")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil { panic(err) }
|
||||
}
|
||||
info, err := buildinfo.ReadFile(path)
|
||||
if err != nil { panic(err) }
|
||||
var result interface{} = info
|
||||
if byteFixture {
|
||||
settings := make([]map[string]string, 0)
|
||||
byteSettings := make([]map[string]string, 0)
|
||||
for _, setting := range info.Settings {
|
||||
if utf8.ValidString(setting.Key) && utf8.ValidString(setting.Value) {
|
||||
settings = append(settings, map[string]string{"Key": setting.Key, "Value": setting.Value})
|
||||
} else {
|
||||
byteSettings = append(byteSettings, map[string]string{
|
||||
"KeyBytesBase64": base64.StdEncoding.EncodeToString([]byte(setting.Key)),
|
||||
"ValueBytesBase64": base64.StdEncoding.EncodeToString([]byte(setting.Value)),
|
||||
})
|
||||
}
|
||||
}
|
||||
result = map[string]interface{}{
|
||||
"GoVersion": nil,
|
||||
"GoVersionBytesBase64": base64.StdEncoding.EncodeToString([]byte(info.GoVersion)),
|
||||
"Path": info.Path, "Main": info.Main, "Deps": info.Deps,
|
||||
"Settings": settings, "ByteSettings": byteSettings,
|
||||
}
|
||||
}
|
||||
if err := json.NewEncoder(os.Stdout).Encode(result); err != nil { panic(err) }
|
||||
}
|
||||
`,
|
||||
);
|
||||
}
|
||||
|
||||
async function inspect(mode, path) {
|
||||
let envelope;
|
||||
if (mode === "cli") {
|
||||
const { stdout } = await execute(
|
||||
process.execPath,
|
||||
[entrypoint, "inspect-go-binary", path, "--json"],
|
||||
{ env: environment, timeout: 30_000, maxBuffer: 8 * 1024 * 1024 },
|
||||
);
|
||||
envelope = JSON.parse(stdout);
|
||||
} else {
|
||||
const response = await client.callTool(
|
||||
{ name: "inspect_go_binary", arguments: { path } },
|
||||
{ timeout: 30_000 },
|
||||
);
|
||||
assert.notEqual(response.isError, true, mcpTextValue(response));
|
||||
envelope = JSON.parse(mcpTextValue(response));
|
||||
}
|
||||
const evidence = parseEvidence(envelope);
|
||||
assert.equal(evidence.subject.local_path, path);
|
||||
const report = goBinarySchema.parse(evidence.normalized_result);
|
||||
assert.equal(evidence.subject.digest.sha256, report.artifact.sha256);
|
||||
return { evidence, report };
|
||||
}
|
||||
|
||||
async function verify(
|
||||
path,
|
||||
target,
|
||||
oracle,
|
||||
byteExpected = null,
|
||||
fileKind = "stripped",
|
||||
) {
|
||||
const bytes = await readFile(path);
|
||||
const expected =
|
||||
byteExpected ??
|
||||
JSON.parse(
|
||||
(
|
||||
await execute(oracle, [path], {
|
||||
timeout: 10_000,
|
||||
maxBuffer: 1024 * 1024,
|
||||
})
|
||||
).stdout,
|
||||
);
|
||||
const reports = [];
|
||||
for (const mode of ["cli", "mcp"]) {
|
||||
const { evidence, report } = await inspect(mode, path);
|
||||
assert.equal(report.format, target[2]);
|
||||
assert.equal(report.architecture, target[1]);
|
||||
assert.equal(
|
||||
evidence.subject.architecture,
|
||||
{ amd64: "x86_64", 386: "x86", arm64: "arm64", mips: "mips" }[
|
||||
target[1]
|
||||
] ?? null,
|
||||
);
|
||||
assert.equal(report.bits, target[3]);
|
||||
assert.equal(report.byte_order, target[4]);
|
||||
assert.equal(report.artifact.path, path);
|
||||
assert.equal(report.artifact.bytes, bytes.length);
|
||||
assert.equal(
|
||||
report.artifact.sha256,
|
||||
createHash("sha256").update(bytes).digest("hex"),
|
||||
);
|
||||
const info = report.build_info;
|
||||
assert.notEqual(info, null);
|
||||
assert.equal(info.go_version, expected.GoVersion);
|
||||
assert.equal(info.module.path, expected.Path);
|
||||
assert.deepEqual(
|
||||
normalizeObservedModule(info.module.main),
|
||||
normalizeModule(expected.Main),
|
||||
);
|
||||
assert.deepEqual(
|
||||
info.module.dependencies.map(normalizeObservedModule),
|
||||
(expected.Deps ?? []).map(normalizeModule),
|
||||
);
|
||||
assert.deepEqual(
|
||||
info.module.settings,
|
||||
(expected.Settings ?? []).map(({ Key, Value }) => ({
|
||||
key: Key,
|
||||
value: Value,
|
||||
})),
|
||||
);
|
||||
assert.equal(info.module.complete, byteExpected === null);
|
||||
if (byteExpected === null) {
|
||||
assert.deepEqual(info.module.unparsed_lines, []);
|
||||
assert.deepEqual(info.module.unparsed_line_bytes_base64, []);
|
||||
} else verifyByteStrings(info, expected);
|
||||
verifySource(info, bytes);
|
||||
reports.push(report);
|
||||
assert.deepEqual(
|
||||
await readFile(path),
|
||||
bytes,
|
||||
`${mode} changed source bytes`,
|
||||
);
|
||||
}
|
||||
assert.deepEqual(
|
||||
reports[0],
|
||||
reports[1],
|
||||
"Public CLI and MCP projections disagree",
|
||||
);
|
||||
verified.push({
|
||||
target: `${target[0]}/${target[1]}`,
|
||||
file: byteExpected === null ? fileKind : "byte-valued-strings",
|
||||
go_version: expected.GoVersion,
|
||||
...(byteExpected === null
|
||||
? {}
|
||||
: { go_version_bytes_base64: expected.GoVersionBytesBase64 }),
|
||||
});
|
||||
}
|
||||
|
||||
function verifyByteStrings(info, expected) {
|
||||
const rawByte = Buffer.from([0xff]);
|
||||
const compilerBytes = Buffer.concat([Buffer.from("custom"), rawByte]);
|
||||
const ldflagsBytes = Buffer.concat([
|
||||
Buffer.from("-X runtime.buildVersion=custom"),
|
||||
rawByte,
|
||||
]);
|
||||
assert.equal(info.go_version, null);
|
||||
assert.equal(info.module_text, null);
|
||||
assert.equal(info.go_version_bytes_base64, compilerBytes.toString("base64"));
|
||||
assert.equal(info.go_version_bytes_base64, expected.GoVersionBytesBase64);
|
||||
assert.deepEqual(expected.ByteSettings, [
|
||||
{
|
||||
KeyBytesBase64: Buffer.from("-ldflags").toString("base64"),
|
||||
ValueBytesBase64: ldflagsBytes.toString("base64"),
|
||||
},
|
||||
{
|
||||
KeyBytesBase64: Buffer.from("-tags").toString("base64"),
|
||||
ValueBytesBase64: rawByte.toString("base64"),
|
||||
},
|
||||
]);
|
||||
assert.deepEqual(info.module.unparsed_lines, [
|
||||
'build\t-ldflags="-X runtime.buildVersion=custom\\xff"',
|
||||
]);
|
||||
assert.deepEqual(info.module.unparsed_line_bytes_base64, [
|
||||
Buffer.concat([Buffer.from("build\t-tags="), rawByte]).toString("base64"),
|
||||
]);
|
||||
}
|
||||
|
||||
function normalizeModule(module) {
|
||||
const identity = ({ Path, Version, Sum }) => ({
|
||||
path: Path,
|
||||
version: Version,
|
||||
sum: Sum === "" || Sum === undefined ? null : Sum,
|
||||
});
|
||||
return {
|
||||
...identity(module),
|
||||
replacement: module.Replace == null ? null : identity(module.Replace),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeObservedModule(module) {
|
||||
// debug/buildinfo JSON represents both absent and explicitly empty sums as "".
|
||||
const identity = (value) => ({
|
||||
...value,
|
||||
sum: value.sum === "" ? null : value.sum,
|
||||
});
|
||||
return {
|
||||
...identity(module),
|
||||
replacement:
|
||||
module.replacement === null ? null : identity(module.replacement),
|
||||
};
|
||||
}
|
||||
|
||||
function verifySource(info, bytes) {
|
||||
assert.deepEqual(
|
||||
bytes.subarray(info.header_offset, info.header_offset + 14),
|
||||
Buffer.from("ff20476f206275696c64696e663a", "hex"),
|
||||
);
|
||||
assert.equal(
|
||||
info.encoding,
|
||||
"inline",
|
||||
"Current compiler fixture must use inline string encoding",
|
||||
);
|
||||
const version = inlineString(bytes, info.header_offset + 32);
|
||||
const module = inlineString(bytes, version.offset + version.bytes.length);
|
||||
assert.deepEqual(info.version_location, {
|
||||
offset: version.offset,
|
||||
bytes: version.bytes.length,
|
||||
});
|
||||
assert.deepEqual(info.module_location, {
|
||||
offset: module.offset,
|
||||
bytes: module.bytes.length,
|
||||
});
|
||||
assert.equal(
|
||||
isUtf8(version.bytes) ? version.bytes.toString("utf8") : null,
|
||||
info.go_version,
|
||||
);
|
||||
assert.equal(version.bytes.toString("base64"), info.go_version_bytes_base64);
|
||||
assert.equal(module.bytes.toString("base64"), info.module_bytes_base64);
|
||||
assert.deepEqual(
|
||||
module.bytes.subarray(0, 16),
|
||||
Buffer.from("3077af0c9274080241e1c107e6d618e6", "hex"),
|
||||
);
|
||||
assert.deepEqual(
|
||||
module.bytes.subarray(-16),
|
||||
Buffer.from("f932433186182072008242104116d8f2", "hex"),
|
||||
);
|
||||
const moduleBody = module.bytes.subarray(16, -16);
|
||||
assert.equal(
|
||||
isUtf8(moduleBody) ? moduleBody.toString("utf8") : null,
|
||||
info.module_text,
|
||||
);
|
||||
assert.equal(moduleBody.at(-1), 10);
|
||||
}
|
||||
|
||||
function inlineString(bytes, start) {
|
||||
let length = 0;
|
||||
let offset = start;
|
||||
let shift = 0;
|
||||
for (;;) {
|
||||
assert.ok(
|
||||
offset < bytes.length && shift < 49,
|
||||
"Fixture string length is invalid",
|
||||
);
|
||||
const byte = bytes[offset++];
|
||||
length += (byte & 127) * 2 ** shift;
|
||||
if ((byte & 128) === 0) break;
|
||||
shift += 7;
|
||||
}
|
||||
assert.ok(
|
||||
length <= bytes.length - offset,
|
||||
"Fixture string contents are truncated",
|
||||
);
|
||||
return { offset, bytes: bytes.subarray(offset, offset + length) };
|
||||
}
|
||||
@@ -1,13 +1,19 @@
|
||||
import { json, run } from "./lib/verify-package-core.mjs";
|
||||
import {
|
||||
expandCapabilitiesOutput,
|
||||
expandProviderOutput,
|
||||
} from "./lib/mcp-verifier-results.mjs";
|
||||
|
||||
/** Verify packaged capabilities, providers, and non-Linux search results. */
|
||||
export async function verifyPackageCapabilitiesAndSearch({ cli, environment }) {
|
||||
const capabilities = json(
|
||||
await run(cli, ["capabilities", "--json"], environment),
|
||||
const capabilities = expandCapabilitiesOutput(
|
||||
json(await run(cli, ["capabilities", "--json"], environment)),
|
||||
);
|
||||
if (!Array.isArray(capabilities.capabilities))
|
||||
throw new Error("packaged capabilities CLI failed");
|
||||
const providers = json(await run(cli, ["providers", "--json"], environment));
|
||||
const providers = expandProviderOutput(
|
||||
json(await run(cli, ["providers", "--json"], environment)),
|
||||
);
|
||||
const candidates = providers.analysis_provider_candidates;
|
||||
if (
|
||||
!Array.isArray(candidates) ||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { requireMcpToolError } from "./lib/mcp-verifier-results.mjs";
|
||||
import {
|
||||
requireMcpLifecycleResult,
|
||||
requireMcpToolError,
|
||||
} from "./lib/mcp-verifier-results.mjs";
|
||||
import assert from "node:assert/strict";
|
||||
import { join } from "node:path";
|
||||
import { execFile } from "node:child_process";
|
||||
@@ -17,18 +20,18 @@ const execute = promisify(execFile);
|
||||
const verifyMcpToolsAndPrompts = async (client, mcpOptions) => {
|
||||
await verifyCompleteToolCatalog(client, mcpOptions);
|
||||
await prompts.verifyPromptCatalog(client, mcpOptions, prompts.names);
|
||||
await prompts.verifyPromptCompletion(client, mcpOptions, false);
|
||||
await prompts.verifyPromptCompletion(client, mcpOptions, []);
|
||||
};
|
||||
|
||||
const verifyMcpTargetFree = async (client, mcpOptions) => {
|
||||
const status = await client.callTool(
|
||||
const result = await client.callTool(
|
||||
{ name: "binary_session", arguments: {} },
|
||||
mcpOptions,
|
||||
);
|
||||
const currentDocument =
|
||||
status.structuredContent?.result?.tool_availability?.find(
|
||||
({ name }) => name === "current_document",
|
||||
);
|
||||
const status = requireMcpLifecycleResult(result, "binary_session");
|
||||
const currentDocument = status.tool_availability.find(
|
||||
({ name }) => name === "current_document",
|
||||
);
|
||||
if (
|
||||
currentDocument?.available !== false ||
|
||||
currentDocument.reason !== "target_required"
|
||||
@@ -67,15 +70,13 @@ const verifyMcpOpenAndBind = async (client, mcpOptions) => {
|
||||
);
|
||||
if (opened.isError === true)
|
||||
throw new Error("packaged MCP could not open a binary");
|
||||
const providerStatusEnvelope = json(
|
||||
prompts.mcpText(
|
||||
await client.callTool(
|
||||
{ name: "binary_session", arguments: {} },
|
||||
mcpOptions,
|
||||
),
|
||||
const providerStatus = requireMcpLifecycleResult(
|
||||
await client.callTool(
|
||||
{ name: "binary_session", arguments: {} },
|
||||
mcpOptions,
|
||||
),
|
||||
"binary_session",
|
||||
);
|
||||
const providerStatus = providerStatusEnvelope.result;
|
||||
if (
|
||||
providerStatus.analysis_provider_binding?.provider?.id !== "hopper" ||
|
||||
providerStatus.analysis_provider_binding?.selection_source !== "request"
|
||||
@@ -120,11 +121,8 @@ const verifyMcpNonLinuxCurrentDocument = async (
|
||||
|
||||
const verifyMcpBinaryLifecycle = async (client, mcpOptions) => {
|
||||
await verifyMcpOpenAndBind(client, mcpOptions);
|
||||
await prompts.verifyPromptCompletion(
|
||||
client,
|
||||
mcpOptions,
|
||||
process.platform !== "linux",
|
||||
);
|
||||
// Completion never starts a provider; only an ordinary operation readies it.
|
||||
await prompts.verifyPromptCompletion(client, mcpOptions, []);
|
||||
if (process.platform === "linux") {
|
||||
await verifyMcpLinuxToolAvailability(client, mcpOptions);
|
||||
} else {
|
||||
@@ -133,6 +131,7 @@ const verifyMcpBinaryLifecycle = async (client, mcpOptions) => {
|
||||
mcpOptions,
|
||||
);
|
||||
await verifyMcpNonLinuxCurrentDocument(client, mcpOptions, current);
|
||||
await prompts.verifyPromptCompletion(client, mcpOptions, ["fixture"]);
|
||||
}
|
||||
const closed = await client.callTool(
|
||||
{ name: "close_binary", arguments: {} },
|
||||
@@ -140,7 +139,7 @@ const verifyMcpBinaryLifecycle = async (client, mcpOptions) => {
|
||||
);
|
||||
if (closed.isError === true)
|
||||
throw new Error("packaged MCP could not close its binary");
|
||||
await prompts.verifyPromptCompletion(client, mcpOptions, false);
|
||||
await prompts.verifyPromptCompletion(client, mcpOptions, []);
|
||||
};
|
||||
|
||||
const verifyMcpEvidenceBundle = async (client, mcpOptions, evidenceRoot) => {
|
||||
|
||||
@@ -36,9 +36,8 @@ export const verifyPromptCatalog = async (client, options, expectedNames) => {
|
||||
throw new Error("packaged MCP guided prompt rendering failed");
|
||||
};
|
||||
|
||||
/** Verify live completion through each installed stdio target state. */
|
||||
export const verifyPromptCompletion = async (client, options, targetOpen) => {
|
||||
const expected = targetOpen ? ["fixture"] : [];
|
||||
/** Verify completion candidates for the installed provider readiness state. */
|
||||
export const verifyPromptCompletion = async (client, options, expected) => {
|
||||
const requests = [
|
||||
{
|
||||
ref: { type: "ref/prompt", name: "investigate_feature" },
|
||||
@@ -57,6 +56,8 @@ export const verifyPromptCompletion = async (client, options, targetOpen) => {
|
||||
result.completion.total !== expected.length ||
|
||||
result.completion.hasMore !== false
|
||||
)
|
||||
throw new Error("packaged MCP prompt completion lifecycle failed");
|
||||
throw new Error(
|
||||
`packaged MCP ${request.argument.name} completion mismatch: expected ${JSON.stringify(expected)}, received ${JSON.stringify(result.completion)}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { requireMcpOperationResult } from "./lib/mcp-verifier-results.mjs";
|
||||
import {
|
||||
expandProviderOutput,
|
||||
requireMcpOperationResult,
|
||||
} from "./lib/mcp-verifier-results.mjs";
|
||||
import { verifyGhidraCompactReferences } from "./lib/real-ghidra-compact-references.mjs";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
@@ -172,11 +175,13 @@ const digest = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
||||
const runtimeParent = join(workspace, "runtime with spaces");
|
||||
await mkdir(runtimeParent);
|
||||
const callerDirectory = join(workspace, "caller cwd with spaces");
|
||||
// Keep sorted for comparison with the final caller-directory listing.
|
||||
const scriptCollisions = [
|
||||
"ReaGhidraBridge.java",
|
||||
"ReaGhidraPrepareCom.java",
|
||||
"ReaGhidraAnalysisOptions.java",
|
||||
"ReaGhidraApplySeeds.java",
|
||||
"ReaGhidraBridge.java",
|
||||
"ReaGhidraNoReturnFix.java",
|
||||
"ReaGhidraPrepareCom.java",
|
||||
"ReaGhidraPrepareRaw.java",
|
||||
];
|
||||
await mkdir(callerDirectory);
|
||||
@@ -228,14 +233,16 @@ const assertCleanup = async () => {
|
||||
assert.equal(entries.length, 0, "Provider runtime cleanup left files.");
|
||||
};
|
||||
try {
|
||||
const providers = JSON.parse(
|
||||
(
|
||||
await exec(process.execPath, [entry, "providers", "--json"], {
|
||||
env: environment,
|
||||
cwd: callerDirectory,
|
||||
timeout: 30_000,
|
||||
})
|
||||
).stdout,
|
||||
const providers = expandProviderOutput(
|
||||
JSON.parse(
|
||||
(
|
||||
await exec(process.execPath, [entry, "providers", "--json"], {
|
||||
env: environment,
|
||||
cwd: callerDirectory,
|
||||
timeout: 30_000,
|
||||
})
|
||||
).stdout,
|
||||
),
|
||||
);
|
||||
assert.equal(providers.analysis_provider_binding, null);
|
||||
assert.ok(Array.isArray(providers.analysis_provider_candidates));
|
||||
|
||||
@@ -0,0 +1,294 @@
|
||||
#!/usr/bin/env node
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFile, writeFile, readdir } from "node:fs/promises";
|
||||
import { isAbsolute, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { PrivateRuntimeRoot } from "../dist/process/PrivateRuntimeRoot.js";
|
||||
import { parseEvidence } from "../dist/domain/evidence.js";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
|
||||
if (process.platform !== "linux")
|
||||
throw new Error(
|
||||
"Real packet capture verification requires Linux with util-linux prlimit.",
|
||||
);
|
||||
if (!isAbsolute(process.env.REA_TSHARK_COMMAND ?? ""))
|
||||
throw new Error("Supply absolute REA_TSHARK_COMMAND for TShark 4.x.");
|
||||
const entrypoint =
|
||||
process.argv[2] ?? fileURLToPath(new URL("./rea.mjs", import.meta.url));
|
||||
const run = createVerifierRun();
|
||||
const root = await PrivateRuntimeRoot.create({
|
||||
prefix: "rea-capture-verifier-",
|
||||
});
|
||||
const path = join(root.path, "network with spaces.pcap");
|
||||
const bluetooth = join(root.path, "bluetooth.pcap");
|
||||
const execute = promisify(execFile);
|
||||
const environment = {
|
||||
...process.env,
|
||||
TMPDIR: root.path,
|
||||
TMP: root.path,
|
||||
TEMP: root.path,
|
||||
};
|
||||
const client = new Client({ name: "packet-capture-verifier", version: "1" });
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
env: environment,
|
||||
stderr: "pipe",
|
||||
});
|
||||
|
||||
// Independently synthesize PCAP bytes; no external captures or device access.
|
||||
const pcap = (linktype, packets) => {
|
||||
const header = Buffer.alloc(24);
|
||||
header.writeUInt32LE(0xa1b2c3d4, 0);
|
||||
header.writeUInt16LE(2, 4);
|
||||
header.writeUInt16LE(4, 6);
|
||||
header.writeUInt32LE(65535, 16);
|
||||
header.writeUInt32LE(linktype, 20);
|
||||
return Buffer.concat([
|
||||
header,
|
||||
...packets.flatMap((bytes, i) => {
|
||||
const record = Buffer.alloc(16);
|
||||
record.writeUInt32LE(1700000000 + i, 0);
|
||||
record.writeUInt32LE(bytes.length, 8);
|
||||
record.writeUInt32LE(bytes.length, 12);
|
||||
return [record, bytes];
|
||||
}),
|
||||
]);
|
||||
};
|
||||
const udp = (destination, payload) => {
|
||||
const ip = Buffer.from("450000000001000040110000c0000201c0000202", "hex");
|
||||
ip.writeUInt16BE(28 + payload.length, 2);
|
||||
let checksum = 0;
|
||||
for (let i = 0; i < ip.length; i += 2) checksum += ip.readUInt16BE(i);
|
||||
while (checksum > 0xffff) checksum = (checksum & 0xffff) + (checksum >>> 16);
|
||||
ip.writeUInt16BE(~checksum & 0xffff, 10);
|
||||
const header = Buffer.alloc(8);
|
||||
header.writeUInt16BE(40000, 0);
|
||||
header.writeUInt16BE(destination, 2);
|
||||
header.writeUInt16BE(8 + payload.length, 4);
|
||||
return Buffer.concat([
|
||||
Buffer.from("0200000000020200000000010800", "hex"),
|
||||
ip,
|
||||
header,
|
||||
payload,
|
||||
]);
|
||||
};
|
||||
const dnsQuery = Buffer.from(
|
||||
"123401000001000000000000076578616d706c6504746573740000010001",
|
||||
"hex",
|
||||
);
|
||||
const source = pcap(1, [
|
||||
udp(5554, Buffer.from("REA")),
|
||||
udp(5555, dnsQuery),
|
||||
udp(5555, dnsQuery),
|
||||
]);
|
||||
// LINKTYPE_BLUETOOTH_HCI_H4 = 187; H4 command packet, HCI Reset opcode 0x0c03, no parameters.
|
||||
const bluetoothSource = pcap(187, [Buffer.from("01030c00", "hex")]);
|
||||
let cases = 0;
|
||||
try {
|
||||
await writeFile(path, source);
|
||||
await writeFile(bluetooth, bluetoothSource);
|
||||
await client.connect(transport);
|
||||
const tool = (await client.listTools()).tools.find(
|
||||
({ name }) => name === "inspect_packet_capture",
|
||||
);
|
||||
assert.ok(tool?.outputSchema);
|
||||
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
||||
assert.ok(ajv.validateSchema(tool.inputSchema));
|
||||
assert.ok(ajv.validateSchema(tool.outputSchema));
|
||||
const inspect = async (input) => {
|
||||
const response = await client.callTool({
|
||||
name: tool.name,
|
||||
arguments: input,
|
||||
});
|
||||
assert.notEqual(response.isError, true, JSON.stringify(response));
|
||||
assert.ok(
|
||||
ajv.validate(tool.outputSchema, response.structuredContent),
|
||||
JSON.stringify(ajv.errors),
|
||||
);
|
||||
const evidence = parseEvidence(response.structuredContent);
|
||||
const report = evidence.normalized_result;
|
||||
assert.equal(
|
||||
report.artifact.sha256,
|
||||
createHash("sha256")
|
||||
.update(await readFile(input.path))
|
||||
.digest("hex"),
|
||||
);
|
||||
assert.equal(report.hardware_acquisition, "not-performed");
|
||||
assert.equal(report.limits.address_space_bytes, 1073741824);
|
||||
assert.equal(report.tool.configured_path, process.env.REA_TSHARK_COMMAND);
|
||||
assert.equal(
|
||||
report.resource_limiter.configured_path,
|
||||
process.env.REA_TSHARK_PRLIMIT_COMMAND ?? "/usr/bin/prlimit",
|
||||
);
|
||||
assert.ok(
|
||||
report.resource_limiter.arguments.includes("--as=1073741824:1073741824"),
|
||||
);
|
||||
assert.equal(report.configuration, "private-empty-personal-profile");
|
||||
const flags = Object.entries(input)
|
||||
.filter(([key]) => key !== "path")
|
||||
.flatMap(([key, value]) =>
|
||||
key === "match_limit" && value === null
|
||||
? ["--all_matches"]
|
||||
: typeof value === "boolean"
|
||||
? [value ? `--${key}` : `--no-${key}`]
|
||||
: (Array.isArray(value) ? value : [value]).flatMap((item) => [
|
||||
`--${key}`,
|
||||
String(item),
|
||||
]),
|
||||
);
|
||||
const cli = JSON.parse(
|
||||
(
|
||||
await execute(
|
||||
process.execPath,
|
||||
[
|
||||
entrypoint,
|
||||
"inspect-packet-capture",
|
||||
input.path,
|
||||
...flags,
|
||||
"--format",
|
||||
"json",
|
||||
],
|
||||
{ env: environment, timeout: 60000, maxBuffer: 16 * 1024 * 1024 },
|
||||
)
|
||||
).stdout,
|
||||
);
|
||||
assert.deepEqual(parseEvidence(cli), evidence);
|
||||
const bundle = await client.callTool({
|
||||
name: "get_evidence_bundle",
|
||||
arguments: {},
|
||||
});
|
||||
assert.ok(JSON.stringify(bundle).includes(evidence.evidence_id));
|
||||
cases++;
|
||||
return report;
|
||||
};
|
||||
for (const two_pass of [true, false]) {
|
||||
const report = await inspect({
|
||||
path,
|
||||
fields: ["ip.addr", "udp.port", "tcp.port"],
|
||||
display_filter: "udp.dstport == 5555",
|
||||
two_pass,
|
||||
});
|
||||
assert.deepEqual(
|
||||
report.packets.map((p) => p["frame.number"]),
|
||||
[["2"], ["3"]],
|
||||
);
|
||||
assert.deepEqual(report.packets[0]["ip.addr"], ["192.0.2.1", "192.0.2.2"]);
|
||||
assert.deepEqual(report.packets[0]["udp.port"], ["40000", "5555"]);
|
||||
assert.equal(Object.hasOwn(report.packets[0], "tcp.port"), false);
|
||||
assert.equal(report.read_scope, "to-eof");
|
||||
}
|
||||
const selected = {
|
||||
path,
|
||||
fields: ["dns.qry.name"],
|
||||
decode_as: ["udp.port==5555,dns"],
|
||||
display_filter: "dns",
|
||||
};
|
||||
const dns = await inspect(selected);
|
||||
assert.equal(dns.packets.length, 2);
|
||||
assert.deepEqual(dns.packets[0]["dns.qry.name"], ["example.test"]);
|
||||
const prefix = await inspect({ ...selected, packet_limit: 1 });
|
||||
assert.deepEqual(prefix.packets, []);
|
||||
assert.equal(prefix.read_scope, "up-to-input-packet-limit");
|
||||
const empty = await inspect({
|
||||
path,
|
||||
fields: ["frame.number"],
|
||||
display_filter: "tcp",
|
||||
});
|
||||
assert.deepEqual(empty.packets, []);
|
||||
const pagedPath = join(root.path, "paged.pcap");
|
||||
const pagedSource = pcap(
|
||||
1,
|
||||
Array.from({ length: 120 }, () =>
|
||||
udp(5555, Buffer.from("owned paging fixture")),
|
||||
),
|
||||
);
|
||||
await writeFile(pagedPath, pagedSource);
|
||||
const page = await inspect({ path: pagedPath, fields: ["ip.addr"] });
|
||||
assert.equal(page.packets.length, 50);
|
||||
assert.deepEqual(page.output_window, {
|
||||
matching_packets: 120,
|
||||
returned_packets: 50,
|
||||
has_more: true,
|
||||
});
|
||||
const nextPage = await inspect({
|
||||
path: pagedPath,
|
||||
fields: ["ip.addr"],
|
||||
match_offset: 50,
|
||||
match_limit: 40,
|
||||
});
|
||||
assert.deepEqual(nextPage.packets[0]["frame.number"], ["51"]);
|
||||
assert.deepEqual(nextPage.packets.at(-1)["frame.number"], ["90"]);
|
||||
const complete = await inspect({
|
||||
path: pagedPath,
|
||||
fields: ["ip.addr"],
|
||||
match_limit: null,
|
||||
});
|
||||
assert.equal(complete.packets.length, 120);
|
||||
assert.equal(complete.output_window.has_more, false);
|
||||
assert.deepEqual(await readFile(pagedPath), pagedSource);
|
||||
const hci = await inspect({ path: bluetooth, fields: ["bthci_cmd.opcode"] });
|
||||
assert.deepEqual(hci.packets[0]["bthci_cmd.opcode"], ["0x0c03"]);
|
||||
assert.deepEqual(await readFile(path), source);
|
||||
assert.deepEqual(await readFile(bluetooth), bluetoothSource);
|
||||
for (const input of [
|
||||
{ path, fields: ["frame.number"], display_filter: "this is not a filter" },
|
||||
{ path, fields: ["no_such_field"] },
|
||||
{
|
||||
path,
|
||||
fields: ["frame.number"],
|
||||
decode_as: ["no_such_protocol==1,unknown"],
|
||||
},
|
||||
{ path: join(root.path, "absent.pcap"), fields: ["frame.number"] },
|
||||
{ path, fields: ["frame.number"], interface: "lo0" },
|
||||
]) {
|
||||
const response = await client.callTool({
|
||||
name: tool.name,
|
||||
arguments: input,
|
||||
});
|
||||
assert.equal(response.isError, true);
|
||||
await client.ping();
|
||||
cases++;
|
||||
}
|
||||
await writeFile(path, "not a capture");
|
||||
assert.equal(
|
||||
(
|
||||
await client.callTool({
|
||||
name: tool.name,
|
||||
arguments: { path, fields: ["frame.number"] },
|
||||
})
|
||||
).isError,
|
||||
true,
|
||||
);
|
||||
cases++;
|
||||
await client.close();
|
||||
assert.deepEqual((await readdir(root.path)).sort(), [
|
||||
"bluetooth.pcap",
|
||||
"network with spaces.pcap",
|
||||
"paged.pcap",
|
||||
]);
|
||||
} finally {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
await root.close();
|
||||
}
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
status: "passed",
|
||||
cases,
|
||||
host: `${process.platform}/${process.arch}`,
|
||||
scope:
|
||||
"real TShark CLI/MCP; synthetic Ethernet/IPv4/UDP/DNS and Bluetooth HCI PCAP; no hardware acquisition",
|
||||
...(await completeVerifierRun(run)),
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
@@ -10,6 +10,11 @@ import { pathToFileURL } from "node:url";
|
||||
import { lt, rcompare } from "semver";
|
||||
|
||||
import { CATALOG_IDENTITY } from "../dist/catalogIdentity.js";
|
||||
import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js";
|
||||
import {
|
||||
requireMcpLifecycleResult,
|
||||
sortVerifierNames,
|
||||
} from "./lib/mcp-verifier-results.mjs";
|
||||
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
|
||||
|
||||
const verifierRun = createVerifierRun();
|
||||
@@ -54,27 +59,39 @@ try {
|
||||
await client.connect(transport);
|
||||
const tools = await client.listTools();
|
||||
const toolNames = tools.tools.map(({ name }) => name);
|
||||
const canonicalToolNames = new Set(
|
||||
CATALOG_IDENTITY.tools.map(({ name }) => name),
|
||||
);
|
||||
const canonicalToolNames = new Set(TOOL_CONTRACTS.map(({ name }) => name));
|
||||
const unknownToolNames = toolNames.filter(
|
||||
(name) => !canonicalToolNames.has(name),
|
||||
);
|
||||
const publishedToolNames = new Set(toolNames);
|
||||
const missingToolNames = [...canonicalToolNames].filter(
|
||||
(name) => !publishedToolNames.has(name),
|
||||
);
|
||||
publishedToolCount = toolNames.length;
|
||||
if (
|
||||
publishedToolCount === 0 ||
|
||||
new Set(toolNames).size !== publishedToolCount ||
|
||||
unknownToolNames.length > 0
|
||||
publishedToolNames.size !== publishedToolCount ||
|
||||
unknownToolNames.length > 0 ||
|
||||
missingToolNames.length > 0
|
||||
)
|
||||
throw new Error(
|
||||
`Published MCP exposed an invalid capability-scoped tool projection (${String(publishedToolCount)} tools, unknown: ${unknownToolNames.join(", ") || "none"})`,
|
||||
`Published MCP exposed an invalid canonical tool catalog (${String(publishedToolCount)} tools, unknown: ${unknownToolNames.join(", ") || "none"}, missing: ${missingToolNames.join(", ") || "none"})`,
|
||||
);
|
||||
const status = await client.callTool({
|
||||
const statusReply = await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: {},
|
||||
});
|
||||
if (status.isError === true)
|
||||
throw new Error("Published target-free MCP session check failed");
|
||||
const status = requireMcpLifecycleResult(statusReply, "binary_session");
|
||||
const availabilityNames = sortVerifierNames(
|
||||
status.tool_availability.map(({ name }) => name),
|
||||
);
|
||||
if (
|
||||
JSON.stringify(availabilityNames) !==
|
||||
JSON.stringify(sortVerifierNames(canonicalToolNames))
|
||||
)
|
||||
throw new Error(
|
||||
"Published binary_session omitted canonical tool availability",
|
||||
);
|
||||
update = await verifyPublishedUpdate({ version, canaryRoot });
|
||||
} catch (cause) {
|
||||
throw new Error(`Published package verification failed: ${stderr}`, {
|
||||
|
||||
@@ -4,7 +4,11 @@ import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { PlaywrightElectronActiveProvider } from "../dist/browser/PlaywrightElectronActiveProvider.js";
|
||||
import { electronActiveObservationInputSchema } from "../dist/domain/javascript/electronActiveObservation.js";
|
||||
import { captureElectronScenario } from "../dist/application/javascript/ElectronActiveObservationService.js";
|
||||
import {
|
||||
electronActiveObservationInputSchema,
|
||||
electronActiveObservationResultSchema,
|
||||
} from "../dist/domain/javascript/electronActiveObservation.js";
|
||||
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
|
||||
import { verifyElectronToolContracts } from "./verify/electron/tool-contracts.mjs";
|
||||
|
||||
@@ -50,61 +54,65 @@ const input = electronActiveObservationInputSchema.parse({
|
||||
],
|
||||
});
|
||||
const verifierRun = createVerifierRun();
|
||||
const result = await new PlaywrightElectronActiveProvider(process.env).capture(
|
||||
const result = await captureElectronScenario(
|
||||
new PlaywrightElectronActiveProvider(process.env),
|
||||
input,
|
||||
);
|
||||
if (!result.ok) throw result.error;
|
||||
const capture = electronActiveObservationResultSchema.parse(
|
||||
result.value.normalized_result,
|
||||
);
|
||||
|
||||
const output = {
|
||||
verifier_run: await completeVerifierRun(verifierRun),
|
||||
electron: result.value.application,
|
||||
actions: result.value.actions,
|
||||
processes: result.value.processes,
|
||||
ipc: result.value.ipc,
|
||||
timeline: result.value.timeline,
|
||||
windows: result.value.windows,
|
||||
electron: capture.application,
|
||||
actions: capture.actions,
|
||||
processes: capture.processes,
|
||||
ipc: capture.ipc,
|
||||
timeline: capture.timeline,
|
||||
windows: capture.windows,
|
||||
verified:
|
||||
result.value.coverage.status === "partial_attach" &&
|
||||
result.value.actions.every(({ status }) => status === "completed") &&
|
||||
result.value.actions.some(
|
||||
capture.coverage.status === "partial_attach" &&
|
||||
capture.actions.every(({ status }) => status === "completed") &&
|
||||
capture.actions.some(
|
||||
({ kind, window_index }) =>
|
||||
kind === "renderer-reload" && window_index === 1,
|
||||
) &&
|
||||
result.value.actions.some(
|
||||
capture.actions.some(
|
||||
({ kind, window_index }) =>
|
||||
kind === "renderer-crash" && window_index === 1,
|
||||
) &&
|
||||
result.value.windows.length >= 2 &&
|
||||
result.value.ipc.events.some(
|
||||
capture.windows.length >= 2 &&
|
||||
capture.ipc.events.some(
|
||||
({ kind, channel }) =>
|
||||
kind === "main-handler-invocation" && channel === "readiness:echo",
|
||||
) &&
|
||||
result.value.timeline.events.some(
|
||||
capture.timeline.events.some(
|
||||
({ kind, event, phase }) =>
|
||||
kind === "window-lifecycle" &&
|
||||
event === "created" &&
|
||||
phase === "completed",
|
||||
) &&
|
||||
result.value.timeline.events.some(
|
||||
capture.timeline.events.some(
|
||||
({ kind, event }) =>
|
||||
kind === "process-lifecycle" && event === "utility-process-fork",
|
||||
) &&
|
||||
result.value.timeline.events.some(
|
||||
capture.timeline.events.some(
|
||||
({ kind, event, phase }) =>
|
||||
kind === "shell-attempt" &&
|
||||
event === "openExternal" &&
|
||||
phase === "blocked",
|
||||
) &&
|
||||
result.value.timeline.events.some(
|
||||
capture.timeline.events.some(
|
||||
({ kind, event, phase }) =>
|
||||
kind === "preload" && event === "configured" && phase === "completed",
|
||||
) &&
|
||||
result.value.timeline.events.some(
|
||||
capture.timeline.events.some(
|
||||
({ kind, event }) =>
|
||||
kind === "protocol" &&
|
||||
(event === "open-url" || event === "second-instance"),
|
||||
) &&
|
||||
result.value.timeline.events.some(
|
||||
capture.timeline.events.some(
|
||||
({ kind, event }) =>
|
||||
kind === "process-lifecycle" && event === "child.spawn",
|
||||
),
|
||||
|
||||
@@ -158,7 +158,7 @@ try {
|
||||
observations: {
|
||||
...x.observations,
|
||||
source_files: x.observations.source_files.map(
|
||||
({ name, ...file }) => file,
|
||||
({ name: _name, ...file }) => file,
|
||||
),
|
||||
},
|
||||
});
|
||||
|
||||
+334
@@ -0,0 +1,334 @@
|
||||
#!/usr/bin/env node
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, mkdir, readFile, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { parseBinaryTarget } from "../dist/application/BinaryTargetResolver.js";
|
||||
import { parseEvidence } from "../dist/domain/evidence.js";
|
||||
import { parseAnalysisSnapshot } from "../dist/domain/analysisSnapshot.js";
|
||||
import { functionDossierSchema } from "../dist/domain/hopperValues.js";
|
||||
import { inspectGhidraInstallation } from "../dist/ghidra/GhidraInstallation.js";
|
||||
import { buildMipsRelocatableFixture } from "../tests/conformance/ghidra/mips-fixture.mjs";
|
||||
import {
|
||||
assertMipsRelocations,
|
||||
inspectMipsRelocatableReadelf,
|
||||
} from "../tests/conformance/ghidra/mips-relocatable-checks.mjs";
|
||||
import { requireMcpOperationResult } from "./lib/mcp-verifier-results.mjs";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
|
||||
// Optional cross-target lane for ET_REL objects. No tool acquisition, no
|
||||
// linking and no target execution.
|
||||
if (process.argv.length > 2)
|
||||
throw new Error(
|
||||
"Usage: node scripts/verify-real-ghidra-mips-relocatable.mjs",
|
||||
);
|
||||
if (!["linux", "darwin"].includes(process.platform))
|
||||
throw new Error(
|
||||
"MIPS verification requires a supported Linux/macOS Ghidra host",
|
||||
);
|
||||
if (process.env.GHIDRA_INSTALL_DIR === undefined)
|
||||
throw new Error("Missing prerequisite: caller-supplied GHIDRA_INSTALL_DIR");
|
||||
const installation = inspectGhidraInstallation({
|
||||
environment: process.env,
|
||||
installDir: process.env.GHIDRA_INSTALL_DIR,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
: { javaHome: process.env.JAVA_HOME }),
|
||||
});
|
||||
if (installation.status !== "available")
|
||||
throw new Error(
|
||||
`Ghidra prerequisite unavailable: ${JSON.stringify(installation)}`,
|
||||
);
|
||||
const execute = promisify(execFile);
|
||||
const entrypoint = fileURLToPath(new URL("./rea.mjs", import.meta.url));
|
||||
const run = createVerifierRun();
|
||||
const workspace = await mkdtemp(join(tmpdir(), "rea-mips-rel-proof-"));
|
||||
const runtime = join(workspace, "runtime");
|
||||
await mkdir(runtime);
|
||||
const env = {
|
||||
PATH: process.env.PATH ?? "/usr/bin:/bin",
|
||||
TMPDIR: runtime,
|
||||
REA_LOG_LEVEL: "silent",
|
||||
REA_ANALYSIS_PROVIDER: "ghidra",
|
||||
REA_PROCESS_RUN_ID: run.run_id,
|
||||
GHIDRA_INSTALL_DIR: installation.installDir,
|
||||
JAVA_HOME: installation.javaHome,
|
||||
HOPPER_LAUNCHER_PATH: "/rea-unconfigured-deep-provider/hopper",
|
||||
};
|
||||
for (const setting of ["GHIDRA_HEADLESS_MAXMEM", "GHIDRA_MAXMEM"]) {
|
||||
if (process.env[setting] !== undefined) env[setting] = process.env[setting];
|
||||
}
|
||||
|
||||
/** Load every relocated word through the public read_bytes operation. */
|
||||
async function loadedWords(call, independent, segments, byteOrder) {
|
||||
const words = new Map();
|
||||
for (const relocation of independent.relocations) {
|
||||
const section = [...independent.sections.values()].find(
|
||||
(item) => item.name === relocation.section,
|
||||
);
|
||||
if (!section?.allocated) continue;
|
||||
const segment = segments.find((item) => item.name === section.name);
|
||||
assert.ok(segment, `Ghidra segment ${section.name}`);
|
||||
const address = BigInt(segment.start) + BigInt(relocation.offset);
|
||||
const read = await call("read_bytes", {
|
||||
address: `0x${address.toString(16)}`,
|
||||
length: 4,
|
||||
});
|
||||
assert.equal(read.returned_bytes, 4);
|
||||
const bytes = Buffer.from(read.bytes_hex, "hex");
|
||||
words.set(
|
||||
address,
|
||||
byteOrder === "little" ? bytes.readUInt32LE(0) : bytes.readUInt32BE(0),
|
||||
);
|
||||
}
|
||||
return words;
|
||||
}
|
||||
|
||||
async function verifyFixture(byteOrder, kernelModule) {
|
||||
const fixture = await buildMipsRelocatableFixture(
|
||||
workspace,
|
||||
byteOrder,
|
||||
kernelModule,
|
||||
);
|
||||
const independent = await inspectMipsRelocatableReadelf(
|
||||
fixture.path,
|
||||
byteOrder,
|
||||
fixture.float_abi,
|
||||
);
|
||||
const resolved = await parseBinaryTarget(fixture.path);
|
||||
if (!resolved.ok) throw resolved.error;
|
||||
assert.deepEqual(
|
||||
resolved.value.mips,
|
||||
independent.mips,
|
||||
"REA ELF/ABI interpretation disagrees with GNU readelf",
|
||||
);
|
||||
assert.equal(resolved.value.sha256, fixture.sha256);
|
||||
const label = `${byteOrder}${kernelModule ? "-module" : ""}`;
|
||||
const snapshotPath = join(workspace, `${label}.snapshot.json`);
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
env,
|
||||
stderr: "pipe",
|
||||
});
|
||||
const client = new Client({ name: "rea-real-mips-rel-proof", version: "1" });
|
||||
let stderr = "";
|
||||
transport.stderr?.on("data", (chunk) => {
|
||||
stderr = (stderr + chunk.toString()).slice(-65536);
|
||||
});
|
||||
const call = async (name, args = {}) =>
|
||||
requireMcpOperationResult(
|
||||
await client.callTool({ name, arguments: args }, undefined, {
|
||||
timeout: 180000,
|
||||
}),
|
||||
name,
|
||||
);
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const target = await call("open_binary", {
|
||||
path: fixture.path,
|
||||
provider_id: "ghidra",
|
||||
});
|
||||
assert.equal(target.architecture, "mips");
|
||||
assert.equal(target.sha256, fixture.sha256);
|
||||
const image = (await call("inspect_native_load_image")).observations;
|
||||
assert.equal(
|
||||
image.language_id,
|
||||
`MIPS:${byteOrder === "little" ? "LE" : "BE"}:32:default`,
|
||||
);
|
||||
assert.equal(image.source_files.length, 1);
|
||||
assert.equal(image.source_files[0].original_sha256, fixture.sha256);
|
||||
assert.notEqual(
|
||||
image.source_files[0].modified_sha256,
|
||||
fixture.sha256,
|
||||
"Relocations must change the loaded bytes",
|
||||
);
|
||||
const names = await call("list_names");
|
||||
const segments = await call("list_segments");
|
||||
const coverage = assertMipsRelocations({
|
||||
facts: independent,
|
||||
fileBytes: await readFile(fixture.path),
|
||||
segments,
|
||||
mappings: image.mappings,
|
||||
ghidraRelocations: image.relocations,
|
||||
words: await loadedWords(call, independent, segments, byteOrder),
|
||||
names,
|
||||
byteOrder,
|
||||
});
|
||||
assert.equal(coverage.unplaced, 0, "Fixture references an empty section");
|
||||
assert.ok(coverage.shared_hi16, "No HI16 shared by several LO16s");
|
||||
assert.ok(coverage.multiple_hi16, "No LO16 resolved several pending HI16s");
|
||||
assert.ok(coverage.lo16_carry, "No LO16 >= 0x8000 forced a HI16 carry");
|
||||
assert.ok(coverage.external_code, "No external code relocation");
|
||||
assert.ok(coverage.external_data, "No external data relocation");
|
||||
assert.ok(coverage.types.R_MIPS_32 > 0, "No R_MIPS_32 relocation");
|
||||
assert.equal(
|
||||
coverage.types.R_MIPS_26 === undefined,
|
||||
kernelModule,
|
||||
"Long calls must replace every R_MIPS_26 with HI16/LO16",
|
||||
);
|
||||
const procedures = await call("list_procedures");
|
||||
const named = (name) => {
|
||||
const found = procedures.filter((item) => item.value === name);
|
||||
assert.equal(found.length, 1, `Procedure ${name}`);
|
||||
return found[0].address;
|
||||
};
|
||||
const entry = named("rea_mips_rel_entry");
|
||||
const callees = await call("procedure_callees", { procedure: entry });
|
||||
for (const callee of [
|
||||
named("rea_mips_rel_leaf"),
|
||||
named("rea_mips_rel_far"),
|
||||
])
|
||||
assert.ok(callees.includes(callee), `Missing direct call to ${callee}`);
|
||||
// Ghidra lists the external function and its EXTERNAL-block thunk.
|
||||
assert.ok(
|
||||
procedures.some(
|
||||
(item) =>
|
||||
item.value === "<EXTERNAL>::rea_mips_rel_external" &&
|
||||
callees.includes(item.address),
|
||||
),
|
||||
"Missing call to the external function",
|
||||
);
|
||||
const dossier = functionDossierSchema.parse(
|
||||
await call("analyze_function", { procedure: entry }),
|
||||
);
|
||||
for (const name of [
|
||||
"rea_mips_rel_leaf",
|
||||
"rea_mips_rel_far",
|
||||
"rea_mips_rel_external",
|
||||
])
|
||||
assert.ok(dossier.pseudocode.includes(name), `Pseudocode lost ${name}`);
|
||||
// powf's float prototype comes from Ghidra's C library archive; soft-float
|
||||
// builds pass 1.5f/2.5f in $a0/$a1, hard-float builds in $f12/$f14.
|
||||
const scaled = functionDossierSchema.parse(
|
||||
await call("analyze_function", {
|
||||
procedure: named("rea_mips_rel_scaled"),
|
||||
}),
|
||||
);
|
||||
assert.match(scaled.pseudocode, /\bpowf\(1\.5,2\.5\)/u);
|
||||
assert.doesNotMatch(scaled.pseudocode, /\bin_f\d+\b/u);
|
||||
await call("close_binary", { snapshot_path: snapshotPath });
|
||||
const snapshot = parseAnalysisSnapshot(
|
||||
JSON.parse(await readFile(snapshotPath, "utf8")),
|
||||
);
|
||||
const parameters = snapshot.binding.analysis_profile.parameters;
|
||||
assert.equal(parameters.mips_elf.type, 1);
|
||||
assert.equal(
|
||||
parameters.mips_support_lane,
|
||||
"elf32-rel-o32-arch32r2-standard-v1",
|
||||
);
|
||||
assert.equal(
|
||||
parameters.mips_soft_float_storage,
|
||||
kernelModule ? "o32-soft-float-prototype-v1" : undefined,
|
||||
);
|
||||
assert.ok(
|
||||
snapshot.evidence_bundle.records.some((record) =>
|
||||
parseEvidence(record).limitations.some((item) =>
|
||||
item.includes("Relocatable MIPS ELF"),
|
||||
),
|
||||
),
|
||||
"Relocatable limitation missing from retained Evidence",
|
||||
);
|
||||
assert.equal(
|
||||
snapshot.evidence_bundle.records.some((record) =>
|
||||
parseEvidence(record).limitations.some((item) =>
|
||||
/Soft-float prototype outcome: [1-9]\d* functions/u.test(item),
|
||||
),
|
||||
),
|
||||
kernelModule,
|
||||
"Soft-float prototype must cover the archive-typed external in module builds",
|
||||
);
|
||||
await call("open_binary", {
|
||||
path: fixture.path,
|
||||
provider_id: "ghidra",
|
||||
snapshot_path: snapshotPath,
|
||||
});
|
||||
assert.deepEqual(await call("list_procedures"), procedures);
|
||||
await call("close_binary");
|
||||
// Same public operation through CLI, not a private injected provider.
|
||||
const cli = await execute(
|
||||
process.execPath,
|
||||
[
|
||||
entrypoint,
|
||||
"function",
|
||||
fixture.path,
|
||||
"rea_mips_rel_entry",
|
||||
"--provider",
|
||||
"ghidra",
|
||||
"--json",
|
||||
],
|
||||
{ env, timeout: 240000, maxBuffer: 16 * 1024 * 1024 },
|
||||
);
|
||||
const evidence = parseEvidence(JSON.parse(cli.stdout));
|
||||
assert.equal(evidence.subject?.architecture, "mips");
|
||||
assert.equal(evidence.subject?.digest.sha256, fixture.sha256);
|
||||
assert.equal(
|
||||
functionDossierSchema.parse(evidence.normalized_result).procedure.address,
|
||||
dossier.procedure.address,
|
||||
);
|
||||
assert.equal(
|
||||
createHash("sha256")
|
||||
.update(await readFile(fixture.path))
|
||||
.digest("hex"),
|
||||
fixture.sha256,
|
||||
"Analysis modified the source object",
|
||||
);
|
||||
return {
|
||||
...fixture,
|
||||
independent_reader: {
|
||||
command: independent.command,
|
||||
version: independent.version,
|
||||
},
|
||||
effective_language: image.language_id,
|
||||
relocation_coverage: coverage,
|
||||
procedures: procedures.length,
|
||||
status: "passed",
|
||||
};
|
||||
} catch (cause) {
|
||||
throw new Error(
|
||||
`MIPS ${label} relocatable verification failed; MCP stderr: ${stderr}`,
|
||||
{ cause },
|
||||
);
|
||||
} finally {
|
||||
try {
|
||||
await client.close();
|
||||
} finally {
|
||||
await transport.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const reports = [];
|
||||
let primaryFailure;
|
||||
try {
|
||||
for (const [byteOrder, kernelModule] of [
|
||||
["little", false],
|
||||
["big", false],
|
||||
["little", true],
|
||||
])
|
||||
reports.push(await verifyFixture(byteOrder, kernelModule));
|
||||
} catch (cause) {
|
||||
primaryFailure = cause;
|
||||
}
|
||||
const completed = await completeVerifierRun(run);
|
||||
if (
|
||||
completed.process_lineage.status !== "verified" ||
|
||||
completed.process_lineage.descendants.length !== 0
|
||||
)
|
||||
throw new Error(
|
||||
`Cleanup unverified; retained diagnostic workspace: ${workspace}`,
|
||||
{ cause: primaryFailure },
|
||||
);
|
||||
if (primaryFailure !== undefined)
|
||||
throw new Error(
|
||||
`MIPS relocatable verification failed; retained workspace: ${workspace}`,
|
||||
{ cause: primaryFailure },
|
||||
);
|
||||
await rm(workspace, { recursive: true, force: true });
|
||||
console.log(JSON.stringify({ ...completed, fixtures: reports }, null, 2));
|
||||
@@ -0,0 +1,338 @@
|
||||
#!/usr/bin/env node
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { parseBinaryTarget } from "../dist/application/BinaryTargetResolver.js";
|
||||
import { parseEvidence } from "../dist/domain/evidence.js";
|
||||
import { parseAnalysisSnapshot } from "../dist/domain/analysisSnapshot.js";
|
||||
import { buildMips16SharedFixture } from "../tests/conformance/ghidra/mips16-shared-fixture.mjs";
|
||||
import {
|
||||
requireMcpOperationResult,
|
||||
requireMcpToolError,
|
||||
} from "./lib/mcp-verifier-results.mjs";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
|
||||
if (
|
||||
process.env.GHIDRA_INSTALL_DIR === undefined ||
|
||||
!["linux", "darwin"].includes(process.platform)
|
||||
)
|
||||
throw new Error(
|
||||
"This optional lane requires BYO Ghidra on Linux/macOS and GNU MIPS cross-binutils.",
|
||||
);
|
||||
const execute = promisify(execFile);
|
||||
const run = createVerifierRun();
|
||||
const workspace = await mkdtemp(join(tmpdir(), "rea-mips-shared-proof-"));
|
||||
const runtime = join(workspace, "runtime");
|
||||
await mkdir(runtime);
|
||||
const env = {
|
||||
PATH: process.env.PATH ?? "/usr/bin:/bin",
|
||||
TMPDIR: runtime,
|
||||
REA_LOG_LEVEL: "silent",
|
||||
REA_ANALYSIS_PROVIDER: "ghidra",
|
||||
REA_PROCESS_RUN_ID: run.run_id,
|
||||
GHIDRA_INSTALL_DIR: process.env.GHIDRA_INSTALL_DIR,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
: { JAVA_HOME: process.env.JAVA_HOME }),
|
||||
...(process.env.GHIDRA_HEADLESS_MAXMEM === undefined
|
||||
? {}
|
||||
: { GHIDRA_HEADLESS_MAXMEM: process.env.GHIDRA_HEADLESS_MAXMEM }),
|
||||
};
|
||||
const reports = [];
|
||||
let failure;
|
||||
try {
|
||||
for (const byteOrder of ["big", "little"]) {
|
||||
for (const variant of [
|
||||
"declared",
|
||||
"recordless",
|
||||
"symbol-relative",
|
||||
"section-relocations",
|
||||
]) {
|
||||
const fixture = await buildMips16SharedFixture(
|
||||
workspace,
|
||||
byteOrder,
|
||||
variant,
|
||||
);
|
||||
const resolved = await parseBinaryTarget(fixture.path);
|
||||
if (!resolved.ok) throw resolved.error;
|
||||
assert.equal(resolved.value.sha256, fixture.sha256);
|
||||
assert.equal(resolved.value.architecture, "mips");
|
||||
if (variant === "section-relocations") {
|
||||
assert.equal(resolved.value.mips.sharedLoad.status, "unavailable");
|
||||
assert.match(
|
||||
resolved.value.mips.sharedLoad.reason,
|
||||
/section relocation declarations/u,
|
||||
);
|
||||
} else {
|
||||
assert.equal(resolved.value.mips.sharedLoad.status, "complete");
|
||||
assert.deepEqual(
|
||||
resolved.value.mips.sharedLoad.relocationTypes,
|
||||
[0, 3],
|
||||
);
|
||||
assert.equal(
|
||||
resolved.value.mips.sharedLoad.symbolRelativeCount,
|
||||
variant === "symbol-relative" ? 1 : 0,
|
||||
);
|
||||
}
|
||||
if (variant === "recordless")
|
||||
assert.equal(resolved.value.mips.abiFlags, null);
|
||||
else {
|
||||
assert.equal(resolved.value.mips.abiFlags.fpAbi, 5);
|
||||
assert.equal(resolved.value.mips.abiFlags.ases, 0x400);
|
||||
}
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: ["scripts/rea.mjs", "mcp"],
|
||||
cwd: process.cwd(),
|
||||
env,
|
||||
stderr: "pipe",
|
||||
});
|
||||
const client = new Client({
|
||||
name: "rea-mips16-shared-conformance",
|
||||
version: "1",
|
||||
});
|
||||
let stderr = "";
|
||||
transport.stderr?.on("data", (chunk) => {
|
||||
stderr = (stderr + chunk.toString()).slice(-262144);
|
||||
});
|
||||
let calls = 0;
|
||||
const reply = async (name, args = {}) => {
|
||||
const response = await client.callTool(
|
||||
{ name, arguments: args },
|
||||
{ timeout: 180000 },
|
||||
);
|
||||
await writeFile(
|
||||
join(workspace, `${byteOrder}-${variant}-${++calls}-${name}.json`),
|
||||
JSON.stringify(response, null, 2),
|
||||
);
|
||||
return response;
|
||||
};
|
||||
const call = async (name, args) =>
|
||||
requireMcpOperationResult(await reply(name, args), name);
|
||||
const original = await readFile(fixture.path);
|
||||
try {
|
||||
await client.connect(transport);
|
||||
await client.listTools();
|
||||
if (
|
||||
variant === "symbol-relative" ||
|
||||
variant === "section-relocations"
|
||||
) {
|
||||
const refusal = requireMcpToolError(
|
||||
await reply("open_binary", {
|
||||
path: fixture.path,
|
||||
provider_id: "ghidra",
|
||||
}),
|
||||
);
|
||||
assert.equal(refusal.category, "unsupported_provider");
|
||||
assert.match(
|
||||
JSON.stringify(refusal),
|
||||
variant === "symbol-relative"
|
||||
? /Symbol-bearing R_MIPS_REL32/u
|
||||
: /section relocation declarations/u,
|
||||
);
|
||||
assert.deepEqual(await readFile(fixture.path), original);
|
||||
await client.ping();
|
||||
reports.push({ ...fixture, status: "refused", ping: true });
|
||||
continue;
|
||||
}
|
||||
await call("open_binary", {
|
||||
path: fixture.path,
|
||||
provider_id: "ghidra",
|
||||
});
|
||||
const loadedReply = await reply("inspect_native_load_image");
|
||||
const loaded = requireMcpOperationResult(
|
||||
loadedReply,
|
||||
"inspect_native_load_image",
|
||||
);
|
||||
const evidence = parseEvidence(
|
||||
JSON.parse(
|
||||
loadedReply.content.find((item) => item.type === "text").text,
|
||||
),
|
||||
);
|
||||
const language = `MIPS:${byteOrder === "little" ? "LE" : "BE"}:32:default`;
|
||||
assert.equal(loaded.observations.language_id, language);
|
||||
assert.equal(loaded.observations.compiler_spec_id, "default");
|
||||
assert(
|
||||
loaded.observations.source_files.some(
|
||||
(file) => file.original_sha256 === fixture.sha256,
|
||||
),
|
||||
);
|
||||
assert(
|
||||
evidence.limitations.some((item) =>
|
||||
item.includes("External GOT bindings"),
|
||||
),
|
||||
);
|
||||
if (variant === "recordless")
|
||||
assert(
|
||||
evidence.limitations.some((item) =>
|
||||
item.includes("does not establish the floating-point ABI"),
|
||||
),
|
||||
);
|
||||
const base = BigInt(loaded.observations.image_base);
|
||||
const address = (source, clearTag = false) =>
|
||||
`0x${(base + (clearTag ? BigInt(source) & ~1n : BigInt(source))).toString(16)}`;
|
||||
const compressed = address(fixture.symbols.rea_mips16_probe, true);
|
||||
const standard = address(fixture.symbols.rea_mips32_probe);
|
||||
const procedures = await call("list_procedures");
|
||||
assert(
|
||||
procedures.some(
|
||||
(item) =>
|
||||
item.address === compressed && item.value === "rea_mips16_probe",
|
||||
),
|
||||
);
|
||||
assert(
|
||||
procedures.some(
|
||||
(item) =>
|
||||
item.address === standard && item.value === "rea_mips32_probe",
|
||||
),
|
||||
);
|
||||
let firstInstruction;
|
||||
const expected =
|
||||
byteOrder === "little"
|
||||
? ["5a6a", "8eea", "074a", "a0e8"]
|
||||
: ["6a5a", "ea8e", "4a07", "e8a0"];
|
||||
for (let i = 0; i < 4; i += 1) {
|
||||
const instruction = await call("inspect_native_instruction", {
|
||||
address: `0x${(BigInt(compressed) + BigInt(2 * i)).toString(16)}`,
|
||||
});
|
||||
assert.equal(instruction.status, "decoded");
|
||||
assert.equal(instruction.mode, "default");
|
||||
assert.equal(instruction.length, 2);
|
||||
assert.equal(instruction.bytes, expected[i]);
|
||||
assert.deepEqual(instruction.decoder_context, [
|
||||
{
|
||||
register: "ISA_MODE",
|
||||
value: "1",
|
||||
source: "ghidra-program-context",
|
||||
},
|
||||
]);
|
||||
if (i === 0) firstInstruction = instruction;
|
||||
}
|
||||
const standardInstruction = await call("inspect_native_instruction", {
|
||||
address: standard,
|
||||
});
|
||||
assert.equal(standardInstruction.length, 4);
|
||||
assert.equal(
|
||||
standardInstruction.bytes,
|
||||
byteOrder === "little" ? "03008224" : "24820003",
|
||||
);
|
||||
assert.equal(
|
||||
standardInstruction.decoder_context[0].register,
|
||||
"ISA_MODE",
|
||||
);
|
||||
assert(
|
||||
[null, "0"].includes(standardInstruction.decoder_context[0].value),
|
||||
);
|
||||
const pointer = await call("read_bytes", {
|
||||
address: address(fixture.symbols.rea_mips16_pointer),
|
||||
length: 4,
|
||||
});
|
||||
const pointerBytes = Buffer.from(pointer.bytes_hex, "hex");
|
||||
const pointerValue =
|
||||
byteOrder === "little"
|
||||
? pointerBytes.readUInt32LE(0)
|
||||
: pointerBytes.readUInt32BE(0);
|
||||
assert.equal(
|
||||
BigInt(pointerValue),
|
||||
base + BigInt(fixture.symbols.rea_mips16_probe),
|
||||
);
|
||||
const dossier = await call("analyze_function", {
|
||||
procedure: compressed,
|
||||
});
|
||||
assert.match(dossier.pseudocode, /\^\s*0x5a/u);
|
||||
assert.match(dossier.pseudocode, /\+\s*(?:7|0x7)\b/u);
|
||||
const standardDossier = await call("analyze_function", {
|
||||
procedure: standard,
|
||||
});
|
||||
assert.match(standardDossier.pseudocode, /\+\s*(?:3|0x3)\b/u);
|
||||
const snapshotPath = join(
|
||||
workspace,
|
||||
`${byteOrder}-${variant}.snapshot.json`,
|
||||
);
|
||||
await call("close_binary", { snapshot_path: snapshotPath });
|
||||
const snapshot = parseAnalysisSnapshot(
|
||||
JSON.parse(await readFile(snapshotPath, "utf8")),
|
||||
);
|
||||
assert.equal(
|
||||
snapshot.binding.analysis_profile.parameters.language_selection,
|
||||
"provider-pinned-v1",
|
||||
);
|
||||
assert.equal(
|
||||
snapshot.binding.analysis_profile.parameters.language_id,
|
||||
language,
|
||||
);
|
||||
await call("open_binary", {
|
||||
path: fixture.path,
|
||||
provider_id: "ghidra",
|
||||
snapshot_path: snapshotPath,
|
||||
});
|
||||
assert.deepEqual(
|
||||
await call("inspect_native_instruction", { address: compressed }),
|
||||
firstInstruction,
|
||||
);
|
||||
await call("close_binary");
|
||||
await client.ping();
|
||||
const cli = await execute(
|
||||
process.execPath,
|
||||
[
|
||||
"scripts/rea.mjs",
|
||||
"inspect-native-instruction",
|
||||
fixture.path,
|
||||
compressed,
|
||||
"--provider",
|
||||
"ghidra",
|
||||
"--format",
|
||||
"json",
|
||||
],
|
||||
{ env, timeout: 180000, maxBuffer: 8 * 1024 * 1024 },
|
||||
);
|
||||
assert.deepEqual(
|
||||
parseEvidence(JSON.parse(cli.stdout)).normalized_result,
|
||||
firstInstruction,
|
||||
);
|
||||
assert.deepEqual(await readFile(fixture.path), original);
|
||||
reports.push({
|
||||
...fixture,
|
||||
status: "passed",
|
||||
language_id: language,
|
||||
mixed_mode: true,
|
||||
standard_decoder_context: standardInstruction.decoder_context,
|
||||
pointer_tag_preserved: true,
|
||||
snapshot_context_preserved: true,
|
||||
cli_mcp_parity: true,
|
||||
source_unchanged: true,
|
||||
ping: true,
|
||||
});
|
||||
} finally {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
await writeFile(
|
||||
join(workspace, `${byteOrder}-${variant}.stderr`),
|
||||
stderr,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (cause) {
|
||||
failure = cause;
|
||||
}
|
||||
const completed = await completeVerifierRun(run);
|
||||
if (
|
||||
completed.process_lineage.status !== "verified" ||
|
||||
completed.process_lineage.descendants.length !== 0
|
||||
)
|
||||
throw new Error(`Cleanup unverified; retained workspace: ${workspace}`, {
|
||||
cause: failure,
|
||||
});
|
||||
if (failure !== undefined)
|
||||
throw new Error(
|
||||
`MIPS16 shared verification failed; retained workspace: ${workspace}`,
|
||||
{ cause: failure },
|
||||
);
|
||||
await rm(workspace, { recursive: true, force: true });
|
||||
console.log(JSON.stringify({ ...completed, fixtures: reports }, null, 2));
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
assertMipsLoadedImage,
|
||||
assertMipsProbe,
|
||||
assertMipsGlobal,
|
||||
assertMipsSoftFloatStorage,
|
||||
} from "../tests/conformance/ghidra/mips-checks.mjs";
|
||||
import { parseEvidence } from "../dist/domain/evidence.js";
|
||||
import { parseAnalysisSnapshot } from "../dist/domain/analysisSnapshot.js";
|
||||
@@ -77,16 +78,64 @@ const env = {
|
||||
for (const setting of ["GHIDRA_HEADLESS_MAXMEM", "GHIDRA_MAXMEM"]) {
|
||||
if (process.env[setting] !== undefined) env[setting] = process.env[setting];
|
||||
}
|
||||
|
||||
/**
|
||||
* Typed float signatures must use soft-float o32 storage, and callers must see
|
||||
* the source constants through it rather than FPU inputs.
|
||||
*/
|
||||
async function verifySoftFloat(call, symbols, byteOrder) {
|
||||
const boundaries = {};
|
||||
for (const name of [
|
||||
"rea_mips_soft_pick",
|
||||
"rea_mips_soft_wide",
|
||||
"rea_mips_soft_mixed",
|
||||
"rea_mips_soft_struct",
|
||||
]) {
|
||||
const api = await call("inspect_native_api", { procedure: symbols[name] });
|
||||
boundaries[name] = api.boundary;
|
||||
}
|
||||
assertMipsSoftFloatStorage(boundaries, byteOrder);
|
||||
const caller = functionDossierSchema.parse(
|
||||
await call("analyze_function", {
|
||||
procedure: symbols.rea_mips_soft_caller,
|
||||
}),
|
||||
);
|
||||
// Includes the struct call and the indirect call through a typed pointer.
|
||||
assert.doesNotMatch(caller.pseudocode, /\bin_f\d+\b/u);
|
||||
for (const literal of [
|
||||
"1.5",
|
||||
"2.5",
|
||||
"3.25",
|
||||
"4.75",
|
||||
"5.5",
|
||||
"6.125",
|
||||
"7.5",
|
||||
"8.5",
|
||||
"9.5",
|
||||
])
|
||||
assert.ok(
|
||||
caller.pseudocode.includes(literal),
|
||||
`Soft-float caller lost argument ${literal}`,
|
||||
);
|
||||
return { storage: boundaries };
|
||||
}
|
||||
const reports = [];
|
||||
let primaryFailure;
|
||||
try {
|
||||
for (const byteOrder of psp ? ["little"] : ["little", "big"]) {
|
||||
for (const [byteOrder, floatAbi] of psp
|
||||
? [["little", "hard"]]
|
||||
: [
|
||||
["little", "hard"],
|
||||
["big", "hard"],
|
||||
["little", "soft"],
|
||||
["big", "soft"],
|
||||
]) {
|
||||
const fixture = psp
|
||||
? await buildPspFixture(workspace)
|
||||
: await buildMipsFixture(workspace, byteOrder);
|
||||
: await buildMipsFixture(workspace, byteOrder, floatAbi);
|
||||
const independent = psp
|
||||
? fixture
|
||||
: await inspectMipsReadelf(fixture.path, byteOrder);
|
||||
: await inspectMipsReadelf(fixture.path, byteOrder, floatAbi);
|
||||
const resolved = await parseBinaryTarget(fixture.path);
|
||||
if (!resolved.ok) throw resolved.error;
|
||||
if (psp) {
|
||||
@@ -104,7 +153,10 @@ try {
|
||||
);
|
||||
}
|
||||
assert.equal(resolved.value.sha256, fixture.sha256);
|
||||
const snapshotPath = join(workspace, `${byteOrder}.snapshot.json`);
|
||||
const snapshotPath = join(
|
||||
workspace,
|
||||
`${byteOrder}-${floatAbi}.snapshot.json`,
|
||||
);
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
@@ -238,6 +290,10 @@ try {
|
||||
callees.includes(leaf.address),
|
||||
"Expected direct call not recovered",
|
||||
);
|
||||
const softFloat =
|
||||
floatAbi === "soft"
|
||||
? await verifySoftFloat(call, independent.symbols, byteOrder)
|
||||
: undefined;
|
||||
const assembly = await call("procedure_assembly", {
|
||||
procedure: entry.address,
|
||||
});
|
||||
@@ -293,6 +349,19 @@ try {
|
||||
},
|
||||
"Snapshot profile did not retain the independently inspected ELF/ABI declaration",
|
||||
);
|
||||
assert.equal(
|
||||
snapshot.binding.analysis_profile.parameters.mips_soft_float_storage,
|
||||
floatAbi === "soft" ? "o32-soft-float-prototype-v1" : undefined,
|
||||
);
|
||||
assert.equal(
|
||||
snapshot.evidence_bundle.records.some((record) =>
|
||||
/Soft-float prototype outcome: 4 functions and [1-9]\d* function-pointer definitions use __rea_soft_float\./u.test(
|
||||
JSON.stringify(record),
|
||||
),
|
||||
),
|
||||
floatAbi === "soft",
|
||||
"Soft-float prototype outcome missing from, or unexpected in, retained Evidence",
|
||||
);
|
||||
assert.ok(snapshot.evidence_bundle.records.length > 0);
|
||||
if (psp) {
|
||||
assert.equal(
|
||||
@@ -419,7 +488,10 @@ try {
|
||||
assert.ok(read32(offset + 4) + read32(offset + 16) <= cut);
|
||||
}
|
||||
const carvedBytes = sourceBytes.subarray(0, cut);
|
||||
const carvedPath = join(workspace, `${byteOrder}-carved.elf`);
|
||||
const carvedPath = join(
|
||||
workspace,
|
||||
`${byteOrder}-${floatAbi}-carved.elf`,
|
||||
);
|
||||
const carvedSha256 = createHash("sha256")
|
||||
.update(carvedBytes)
|
||||
.digest("hex");
|
||||
@@ -460,7 +532,7 @@ try {
|
||||
assert.ok(carvedDossier.pseudocode.trim().length > 0);
|
||||
const carvedSnapshotPath = join(
|
||||
workspace,
|
||||
`${byteOrder}-carved.snapshot.json`,
|
||||
`${byteOrder}-${floatAbi}-carved.snapshot.json`,
|
||||
);
|
||||
await call("close_binary", { snapshot_path: carvedSnapshotPath });
|
||||
const carvedSnapshot = parseAnalysisSnapshot(
|
||||
@@ -523,7 +595,11 @@ try {
|
||||
: "conditional branch destination",
|
||||
"global word and marker bytes",
|
||||
"CLI/MCP and snapshot identity",
|
||||
...(floatAbi === "soft"
|
||||
? ["soft-float o32 parameter/return storage and caller constants"]
|
||||
: []),
|
||||
],
|
||||
...(softFloat === undefined ? {} : { soft_float: softFloat }),
|
||||
procedures: procedures.length,
|
||||
carved: carved ?? {
|
||||
status: "not_run",
|
||||
@@ -534,7 +610,7 @@ try {
|
||||
});
|
||||
} catch (cause) {
|
||||
throw new Error(
|
||||
`MIPS ${byteOrder} verification failed; MCP stderr: ${stderr}`,
|
||||
`MIPS ${byteOrder} ${floatAbi}-float verification failed; MCP stderr: ${stderr}`,
|
||||
{ cause },
|
||||
);
|
||||
} finally {
|
||||
|
||||
@@ -53,6 +53,15 @@ const env = {
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
: { JAVA_HOME: process.env.JAVA_HOME }),
|
||||
...(process.env.GHIDRA_HEADLESS_MAXMEM === undefined
|
||||
? {}
|
||||
: { GHIDRA_HEADLESS_MAXMEM: process.env.GHIDRA_HEADLESS_MAXMEM }),
|
||||
...(process.env.REA_GHIDRA_DISABLED_ANALYZERS === undefined
|
||||
? {}
|
||||
: {
|
||||
REA_GHIDRA_DISABLED_ANALYZERS:
|
||||
process.env.REA_GHIDRA_DISABLED_ANALYZERS,
|
||||
}),
|
||||
};
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
@@ -160,6 +169,48 @@ try {
|
||||
assert.equal(cli.normalized_result.base_address, "0x8000000");
|
||||
assert.equal(cli.analysis_profile.digest, profiles[0]);
|
||||
assert.deepEqual(await readFile(path), bytes);
|
||||
const x86Targets = [];
|
||||
for (const architecture of ["x86", "x86_64"]) {
|
||||
const x86Bytes = Buffer.from("b82a000000c3", "hex"); // mov eax, 42; ret.
|
||||
const x86Sha256 = createHash("sha256").update(x86Bytes).digest("hex");
|
||||
const x86Path = join(workspace, `${architecture}.bin`);
|
||||
await writeFile(x86Path, x86Bytes);
|
||||
await call("open_binary", {
|
||||
path: x86Path,
|
||||
format: "raw-binary",
|
||||
architecture,
|
||||
entry_point: "0x1000",
|
||||
});
|
||||
const image = await call("inspect_native_load_image", {}, x86Sha256);
|
||||
assert.equal(
|
||||
image.normalized_result.status,
|
||||
"verified",
|
||||
JSON.stringify(image),
|
||||
);
|
||||
assert.equal(image.normalized_result.base_address, "0x1000");
|
||||
assert.equal(image.normalized_result.observations.compiler_spec_id, "gcc");
|
||||
assert.equal(image.analysis_profile.parameters.compiler_spec_id, "gcc");
|
||||
const memory = await call(
|
||||
"read_bytes",
|
||||
{ address: "0x1000", length: x86Bytes.length },
|
||||
x86Sha256,
|
||||
);
|
||||
assert.equal(memory.normalized_result.bytes_hex, x86Bytes.toString("hex"));
|
||||
const pseudo = await call(
|
||||
"procedure_pseudo_code",
|
||||
{ procedure: "0x1000" },
|
||||
x86Sha256,
|
||||
);
|
||||
assert.match(pseudo.normalized_result, /\b(?:42|0x2a)\b/iu);
|
||||
await call("close_binary");
|
||||
assert.deepEqual(await readFile(x86Path), x86Bytes);
|
||||
x86Targets.push({
|
||||
architecture,
|
||||
sha256: x86Sha256,
|
||||
compiler_spec_id: "gcc",
|
||||
return_42: true,
|
||||
});
|
||||
}
|
||||
report = {
|
||||
ok: true,
|
||||
mocked: false,
|
||||
@@ -179,6 +230,7 @@ try {
|
||||
invalid_entry_preserves_active_session: true,
|
||||
load_images_verified: true,
|
||||
original_unchanged: true,
|
||||
x86_targets: x86Targets,
|
||||
};
|
||||
} catch (error) {
|
||||
if (stderr.trim()) process.stderr.write(stderr);
|
||||
@@ -199,7 +251,7 @@ process.stdout.write(
|
||||
}) + "\n",
|
||||
);
|
||||
|
||||
async function call(name, args = {}) {
|
||||
async function call(name, args = {}, targetSha256 = sha256) {
|
||||
const result = await client.callTool(
|
||||
{ name, arguments: args },
|
||||
{ timeout: 240000 },
|
||||
@@ -213,7 +265,7 @@ async function call(name, args = {}) {
|
||||
)
|
||||
return projected;
|
||||
const evidence = parseEvidence(result.structuredContent);
|
||||
assert.equal(evidence.subject.digest.sha256, sha256);
|
||||
assert.equal(evidence.subject.digest.sha256, targetSha256);
|
||||
assert.equal(evidence.subject.format, "raw-binary");
|
||||
return evidence;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,391 @@
|
||||
#!/usr/bin/env node
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import {
|
||||
mkdtemp,
|
||||
mkdir,
|
||||
readFile,
|
||||
readdir,
|
||||
rm,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import Ajv from "ajv/dist/2020.js";
|
||||
import addFormats from "ajv-formats";
|
||||
import { parseBinaryTarget } from "../dist/application/BinaryTargetResolver.js";
|
||||
import { parseAnalysisSnapshot } from "../dist/domain/analysisSnapshot.js";
|
||||
import { parseEvidence } from "../dist/domain/evidence.js";
|
||||
import { functionDossierSchema } from "../dist/domain/hopperValues.js";
|
||||
import { inspectGhidraInstallation } from "../dist/ghidra/GhidraInstallation.js";
|
||||
import { buildRiscvFixture } from "../tests/conformance/ghidra/riscv-fixture.mjs";
|
||||
import {
|
||||
mcpTextValue,
|
||||
requireMcpOperationResult,
|
||||
requireMcpToolError,
|
||||
} from "./lib/mcp-verifier-results.mjs";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
|
||||
if (process.argv.length !== 2)
|
||||
throw new Error("Usage: node scripts/verify-real-ghidra-riscv.mjs");
|
||||
if (!["linux", "darwin"].includes(process.platform))
|
||||
throw new Error("This optional lane requires a Linux/macOS Ghidra host.");
|
||||
if (process.env.GHIDRA_INSTALL_DIR === undefined)
|
||||
throw new Error("Missing prerequisite: caller-supplied GHIDRA_INSTALL_DIR");
|
||||
for (const key of ["REA_GHIDRA_LANGUAGE_ID", "REA_GHIDRA_COMPILER_SPEC_ID"])
|
||||
if (process.env[key] !== undefined)
|
||||
throw new Error(
|
||||
`Unset ${key}: this lane verifies provider-pinned selection.`,
|
||||
);
|
||||
const installation = inspectGhidraInstallation({
|
||||
environment: process.env,
|
||||
installDir: process.env.GHIDRA_INSTALL_DIR,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
: { javaHome: process.env.JAVA_HOME }),
|
||||
});
|
||||
assert.equal(installation.status, "available", JSON.stringify(installation));
|
||||
assert.equal(installation.providerVersion, "12.1.4");
|
||||
|
||||
const execute = promisify(execFile);
|
||||
const entrypoint = fileURLToPath(new URL("./rea.mjs", import.meta.url));
|
||||
const run = createVerifierRun();
|
||||
const workspace = await mkdtemp(join(tmpdir(), "rea-riscv-proof-"));
|
||||
const runtime = join(workspace, "runtime");
|
||||
await mkdir(runtime);
|
||||
const env = {
|
||||
PATH: process.env.PATH ?? "/usr/bin:/bin",
|
||||
TMPDIR: runtime,
|
||||
REA_LOG_LEVEL: "silent",
|
||||
REA_ANALYSIS_PROVIDER: "ghidra",
|
||||
REA_PROCESS_RUN_ID: run.run_id,
|
||||
GHIDRA_INSTALL_DIR: installation.installDir,
|
||||
JAVA_HOME: installation.javaHome,
|
||||
};
|
||||
for (const key of ["GHIDRA_HEADLESS_MAXMEM", "GHIDRA_MAXMEM"])
|
||||
if (process.env[key] !== undefined) env[key] = process.env[key];
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
env,
|
||||
stderr: "pipe",
|
||||
});
|
||||
const client = new Client({ name: "rea-real-riscv-proof", version: "1" });
|
||||
let stderr = "";
|
||||
transport.stderr?.on("data", (chunk) => {
|
||||
stderr = (stderr + chunk.toString()).slice(-65536);
|
||||
});
|
||||
|
||||
const reports = [];
|
||||
let failure;
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const catalog = await client.listTools();
|
||||
const ajv = new Ajv({ strict: false });
|
||||
addFormats(ajv);
|
||||
const validators = new Map();
|
||||
for (const tool of catalog.tools) {
|
||||
assert.ok(
|
||||
ajv.validateSchema(tool.outputSchema),
|
||||
`${tool.name}: invalid output schema`,
|
||||
);
|
||||
const existing =
|
||||
typeof tool.outputSchema.$id === "string"
|
||||
? ajv.getSchema(tool.outputSchema.$id)
|
||||
: undefined;
|
||||
validators.set(tool.name, existing ?? ajv.compile(tool.outputSchema));
|
||||
}
|
||||
for (const bits of [32, 64]) {
|
||||
const fixture = await buildRiscvFixture(workspace, bits);
|
||||
const resolved = await parseBinaryTarget(fixture.path);
|
||||
if (!resolved.ok) throw resolved.error;
|
||||
assert.equal(resolved.value.architecture, "riscv");
|
||||
assert.equal(resolved.value.sha256, fixture.sha256);
|
||||
assert.deepEqual(resolved.value.riscv, fixture.riscv);
|
||||
const expectedLanguage = `RISCV:LE:${bits}:default`;
|
||||
const assertProfile = (profile) => {
|
||||
assert.equal(profile.provider.id, "ghidra");
|
||||
assert.equal(profile.provider.version, installation.providerVersion);
|
||||
const parameters = profile.parameters;
|
||||
assert.equal(parameters.language_id, expectedLanguage);
|
||||
assert.equal(parameters.compiler_spec_id, "gcc");
|
||||
assert.equal(parameters.language_selection, "provider-pinned-v1");
|
||||
assert.equal(
|
||||
parameters.riscv_support_lane,
|
||||
`elf${bits}-exec-le-double-float-generic-v1`,
|
||||
);
|
||||
assert.deepEqual(parameters.riscv_elf, {
|
||||
elf_class: bits,
|
||||
byte_order: "little",
|
||||
type: 2,
|
||||
flags: 5,
|
||||
float_abi_double: true,
|
||||
rvc_declared: true,
|
||||
rve_declared: false,
|
||||
tso_declared: false,
|
||||
});
|
||||
};
|
||||
const assertEvidence = (evidence) => {
|
||||
assert.equal(evidence.provider.id, "ghidra");
|
||||
assert.equal(evidence.subject.architecture, "riscv");
|
||||
assert.equal(evidence.subject.digest.sha256, fixture.sha256);
|
||||
assertProfile(evidence.analysis_profile);
|
||||
};
|
||||
const call = async (name, args = {}) => {
|
||||
const reply = await client.callTool(
|
||||
{ name, arguments: args },
|
||||
{ timeout: 240000 },
|
||||
);
|
||||
const projected = requireMcpOperationResult(reply, name);
|
||||
const textual = JSON.parse(mcpTextValue(reply));
|
||||
assert.deepEqual(reply.structuredContent, textual);
|
||||
const validate = validators.get(name);
|
||||
assert.ok(validate, `${name} missing from advertised catalog`);
|
||||
assert.ok(
|
||||
validate(textual),
|
||||
`${name}: ${JSON.stringify(validate.errors)}`,
|
||||
);
|
||||
if (!["open_binary", "close_binary", "binary_session"].includes(name))
|
||||
assertEvidence(parseEvidence(textual));
|
||||
return projected;
|
||||
};
|
||||
const opened = await call("open_binary", {
|
||||
path: fixture.path,
|
||||
provider_id: "ghidra",
|
||||
});
|
||||
assert.equal(opened.architecture, "riscv");
|
||||
assert.equal(opened.sha256, fixture.sha256);
|
||||
const image = await call("inspect_native_load_image");
|
||||
assert.equal(image.observations.language_id, expectedLanguage);
|
||||
assert.equal(image.observations.compiler_spec_id, "gcc");
|
||||
assert.ok(image.observations.source_files.length > 0);
|
||||
for (const source of image.observations.source_files) {
|
||||
assert.equal(source.original_sha256, fixture.sha256);
|
||||
assert.equal(source.modified_sha256, fixture.sha256);
|
||||
}
|
||||
const procedures = await call("list_procedures");
|
||||
for (const name of [
|
||||
"rea_riscv_entry",
|
||||
"rea_riscv_leaf",
|
||||
"rea_riscv_float",
|
||||
"rea_riscv_probe",
|
||||
]) {
|
||||
const procedure = procedures.find((value) => value.value === name);
|
||||
assert.ok(procedure, `${name} missing from Ghidra inventory`);
|
||||
assert.equal(BigInt(procedure.address), BigInt(fixture.symbols[name]));
|
||||
}
|
||||
const probe = await call("inspect_native_instruction", {
|
||||
address: fixture.symbols.rea_riscv_probe,
|
||||
});
|
||||
assert.equal(probe.status, "decoded");
|
||||
assert.equal(probe.architecture, expectedLanguage);
|
||||
assert.equal(probe.length, 4);
|
||||
assert.equal(probe.bytes, "13051501"); // addi a0, a0, 17
|
||||
const mapping = await call("address_to_file_offset", {
|
||||
address: fixture.symbols.rea_riscv_probe,
|
||||
});
|
||||
const sourceBytes = await readFile(fixture.path);
|
||||
assert.equal(
|
||||
sourceBytes
|
||||
.subarray(mapping.file_offset, mapping.file_offset + 4)
|
||||
.toString("hex"),
|
||||
probe.bytes,
|
||||
);
|
||||
const global = await call("read_bytes", {
|
||||
address: fixture.symbols.rea_riscv_global,
|
||||
length: 4,
|
||||
});
|
||||
assert.equal(global.bytes_hex, "07000000");
|
||||
const callees = await call("procedure_callees", {
|
||||
procedure: fixture.symbols.rea_riscv_entry,
|
||||
});
|
||||
for (const name of ["rea_riscv_leaf", "rea_riscv_probe"])
|
||||
assert.ok(
|
||||
callees.some(
|
||||
(address) => BigInt(address) === BigInt(fixture.symbols[name]),
|
||||
),
|
||||
);
|
||||
const dossier = functionDossierSchema.parse(
|
||||
await call("analyze_function", {
|
||||
procedure: fixture.symbols.rea_riscv_entry,
|
||||
}),
|
||||
);
|
||||
assert.ok(dossier.pseudocode.trim().length > 0);
|
||||
const floatCode = await call("procedure_pseudo_code", {
|
||||
procedure: fixture.symbols.rea_riscv_float,
|
||||
});
|
||||
assert.ok(typeof floatCode === "string" && floatCode.trim().length > 0);
|
||||
assert.match(floatCode, /\bdouble\b/u);
|
||||
|
||||
const refusals = [];
|
||||
for (const [flags, reason] of [
|
||||
[1, "EF_RISCV_FLOAT_ABI_DOUBLE"],
|
||||
[0x80000005, "(0x80000000)"],
|
||||
]) {
|
||||
// Header-mutated copies test admission; they are not new compiler claims.
|
||||
const rejectedPath = join(
|
||||
workspace,
|
||||
`rv${bits}-flags-${flags.toString(16)}.elf`,
|
||||
);
|
||||
const rejectedBytes = Buffer.from(sourceBytes);
|
||||
rejectedBytes.writeUInt32LE(flags, bits === 32 ? 36 : 48);
|
||||
await writeFile(rejectedPath, rejectedBytes);
|
||||
const reply = await client.callTool(
|
||||
{
|
||||
name: "open_binary",
|
||||
arguments: { path: rejectedPath, provider_id: "ghidra" },
|
||||
},
|
||||
{ timeout: 60000 },
|
||||
);
|
||||
const error = requireMcpToolError(reply);
|
||||
assert.ok(JSON.stringify(error).includes(reason), JSON.stringify(error));
|
||||
await assert.rejects(
|
||||
execute(
|
||||
process.execPath,
|
||||
[
|
||||
entrypoint,
|
||||
"function",
|
||||
rejectedPath,
|
||||
"rea_riscv_entry",
|
||||
"--provider",
|
||||
"ghidra",
|
||||
"--json",
|
||||
],
|
||||
{
|
||||
env,
|
||||
timeout: 60000,
|
||||
maxBuffer: 1024 * 1024,
|
||||
},
|
||||
),
|
||||
(cause) =>
|
||||
Number.isInteger(cause.code) &&
|
||||
cause.code !== 0 &&
|
||||
`${cause.stdout}\n${cause.stderr}`.includes(reason),
|
||||
);
|
||||
refusals.push({ flags, reason });
|
||||
}
|
||||
const snapshotPath = join(workspace, `rv${bits}.snapshot.json`);
|
||||
const saved = await call("close_binary", { snapshot_path: snapshotPath });
|
||||
assert.ok(saved.evidence_records > 0);
|
||||
const snapshot = parseAnalysisSnapshot(
|
||||
JSON.parse(await readFile(snapshotPath, "utf8")),
|
||||
);
|
||||
assert.equal(snapshot.target.architecture, "riscv");
|
||||
assert.equal(snapshot.target.sha256, fixture.sha256);
|
||||
assertProfile(snapshot.binding.analysis_profile);
|
||||
for (const record of snapshot.evidence_bundle.records)
|
||||
assertEvidence(parseEvidence(record));
|
||||
await call("open_binary", {
|
||||
path: fixture.path,
|
||||
provider_id: "ghidra",
|
||||
snapshot_path: snapshotPath,
|
||||
});
|
||||
assert.deepEqual(await call("list_procedures"), procedures);
|
||||
await call("close_binary");
|
||||
|
||||
for (const [command, arguments_] of [
|
||||
["search", ["rea_riscv_", "--kind", "procedures"]],
|
||||
["function", ["rea_riscv_entry"]],
|
||||
]) {
|
||||
const cli = await execute(
|
||||
process.execPath,
|
||||
[
|
||||
entrypoint,
|
||||
command,
|
||||
fixture.path,
|
||||
...arguments_,
|
||||
"--provider",
|
||||
"ghidra",
|
||||
"--json",
|
||||
],
|
||||
{ env, timeout: 240000, maxBuffer: 16 * 1024 * 1024 },
|
||||
);
|
||||
const evidence = parseEvidence(JSON.parse(cli.stdout));
|
||||
assertEvidence(evidence);
|
||||
if (command === "search")
|
||||
for (const name of [
|
||||
"rea_riscv_entry",
|
||||
"rea_riscv_leaf",
|
||||
"rea_riscv_float",
|
||||
"rea_riscv_probe",
|
||||
])
|
||||
assert.ok(
|
||||
evidence.normalized_result.some((value) => value.value === name),
|
||||
);
|
||||
else {
|
||||
const cliDossier = functionDossierSchema.parse(
|
||||
evidence.normalized_result,
|
||||
);
|
||||
assert.equal(cliDossier.procedure.address, dossier.procedure.address);
|
||||
assert.ok(cliDossier.pseudocode.trim().length > 0);
|
||||
}
|
||||
}
|
||||
assert.equal(
|
||||
createHash("sha256")
|
||||
.update(await readFile(fixture.path))
|
||||
.digest("hex"),
|
||||
fixture.sha256,
|
||||
);
|
||||
reports.push({
|
||||
...fixture,
|
||||
language: expectedLanguage,
|
||||
procedures: procedures.length,
|
||||
refusals,
|
||||
cli: true,
|
||||
stdio_mcp: true,
|
||||
snapshot_replay: true,
|
||||
original_unchanged: true,
|
||||
});
|
||||
}
|
||||
} catch (cause) {
|
||||
failure = cause;
|
||||
}
|
||||
for (const close of [() => client.close(), () => transport.close()]) {
|
||||
try {
|
||||
await close();
|
||||
} catch (cause) {
|
||||
failure = new AggregateError(
|
||||
failure === undefined ? [cause] : [failure, cause],
|
||||
"Verification or cleanup failed",
|
||||
);
|
||||
}
|
||||
}
|
||||
const completed = await completeVerifierRun(run);
|
||||
if (
|
||||
completed.process_lineage.status !== "verified" ||
|
||||
completed.process_lineage.descendants.length !== 0
|
||||
)
|
||||
throw new Error(`Cleanup unverified; retained workspace: ${workspace}`, {
|
||||
cause: failure,
|
||||
});
|
||||
if (failure !== undefined)
|
||||
throw new Error(
|
||||
`RISC-V verification failed; retained workspace: ${workspace}; MCP stderr: ${stderr}`,
|
||||
{ cause: failure },
|
||||
);
|
||||
assert.deepEqual(
|
||||
await readdir(runtime),
|
||||
[],
|
||||
`Runtime resources survived server shutdown; retained workspace: ${workspace}`,
|
||||
);
|
||||
await rm(workspace, { recursive: true, force: true });
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
verifier_run: completed,
|
||||
lane: "ghidra-riscv",
|
||||
mocked: false,
|
||||
host: { platform: process.platform, architecture: process.arch },
|
||||
provider: { id: "ghidra", version: installation.providerVersion },
|
||||
fixtures: reports,
|
||||
cleanup: "complete",
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
requireMcpOperationResult,
|
||||
requireMcpLifecycleResult,
|
||||
requireMcpEvidenceResult,
|
||||
sortVerifierNames,
|
||||
requireWorkflowEvidenceProvider,
|
||||
} from "./lib/mcp-verifier-results.mjs";
|
||||
import {
|
||||
@@ -283,8 +284,10 @@ try {
|
||||
const availableTools = initialStatus.tool_availability;
|
||||
if (!Array.isArray(availableTools))
|
||||
throw new Error("The real session omitted tool availability");
|
||||
const expectedNames = availableTools.map(({ name }) => name).sort();
|
||||
const actualNames = listed.tools.map(({ name }) => name).sort();
|
||||
const expectedNames = sortVerifierNames(
|
||||
availableTools.map(({ name }) => name),
|
||||
);
|
||||
const actualNames = sortVerifierNames(listed.tools.map(({ name }) => name));
|
||||
if (JSON.stringify(actualNames) !== JSON.stringify(expectedNames)) {
|
||||
const expected = new Set(expectedNames);
|
||||
const actual = new Set(actualNames);
|
||||
|
||||
@@ -16,6 +16,8 @@ const { values } = parseArgs({
|
||||
options: {
|
||||
target: { type: "string" },
|
||||
procedure: { type: "string", default: "rea_fixture_add" },
|
||||
"second-procedure": { type: "string" },
|
||||
"second-marker": { type: "string" },
|
||||
"package-root": { type: "string" },
|
||||
report: { type: "string" },
|
||||
},
|
||||
@@ -24,6 +26,14 @@ if (values.target === undefined || process.env.REA_IDA_MCP_CONFIG === undefined)
|
||||
throw new Error(
|
||||
"IDA verification requires --target and REA_IDA_MCP_CONFIG; see docs/ida-provider.md. No toolchain is installed by this lane.",
|
||||
);
|
||||
if (
|
||||
(values["second-procedure"] === undefined) !==
|
||||
(values["second-marker"] === undefined) ||
|
||||
values["second-marker"] === ""
|
||||
)
|
||||
throw new Error(
|
||||
"IDA verification requires --second-procedure and a nonempty --second-marker together; choose a marker unique to the second function's pseudocode.",
|
||||
);
|
||||
const packageRoot = resolve(
|
||||
values["package-root"] ?? fileURLToPath(new URL("..", import.meta.url)),
|
||||
);
|
||||
@@ -47,6 +57,14 @@ const [
|
||||
const registration = readIdaConfiguration(process.env.REA_IDA_MCP_CONFIG);
|
||||
if (!registration.ok) throw registration.error;
|
||||
const config = registration.value;
|
||||
if (
|
||||
config.protocol === "native" &&
|
||||
(values["second-procedure"] === undefined ||
|
||||
values["second-marker"] === undefined)
|
||||
)
|
||||
throw new Error(
|
||||
"Native IDA verification requires --second-procedure and --second-marker to verify distinct-function switching; see docs/ida-provider.md.",
|
||||
);
|
||||
const environment = Object.fromEntries(
|
||||
Object.entries({
|
||||
...process.env,
|
||||
@@ -57,6 +75,8 @@ const environment = Object.fromEntries(
|
||||
const report = {
|
||||
passed: false,
|
||||
mode: config.mode,
|
||||
protocol:
|
||||
config.protocol ?? (config.mode === "attached" ? "legacy" : "modern"),
|
||||
checks: [],
|
||||
observations: [],
|
||||
};
|
||||
@@ -75,6 +95,8 @@ const observe = (input) => {
|
||||
assert.equal(evidence.analysis_profile.parameters.cache_policy, "live");
|
||||
assert.equal(evidence.analysis_profile.parameters.engine_version, null);
|
||||
assert.ok(evidence.limitations.length > 0);
|
||||
if (config.protocol === "native" && evidence.operation === "analyze_function")
|
||||
assert.equal(evidence.relationship_coverage?.status, "unknown");
|
||||
assert.ok(
|
||||
evidence.locations.some((location) => location.kind === "artifact-path"),
|
||||
);
|
||||
@@ -156,7 +178,7 @@ const mcp = async (cliDossier) => {
|
||||
["procedure_address", { procedure: dossier.procedure.name }],
|
||||
["procedure_assembly", { procedure: dossier.procedure.address }],
|
||||
["procedure_callees", { procedure: dossier.procedure.address }],
|
||||
...(config.mode === "attached"
|
||||
...(config.mode === "attached" && config.protocol !== "native"
|
||||
? [["procedure_callers", { procedure: dossier.procedure.address }]]
|
||||
: []),
|
||||
["search_procedures", { pattern: dossier.procedure.name }],
|
||||
@@ -168,6 +190,38 @@ const mcp = async (cliDossier) => {
|
||||
const result = await call(name, args);
|
||||
observe(result);
|
||||
}
|
||||
if (values["second-procedure"] !== undefined) {
|
||||
const secondAddress = observe(
|
||||
await call("procedure_address", {
|
||||
procedure: values["second-procedure"],
|
||||
}),
|
||||
);
|
||||
assert.notEqual(secondAddress, dossier.procedure.address);
|
||||
const secondCode = observe(
|
||||
await call("procedure_pseudo_code", {
|
||||
procedure: values["second-procedure"],
|
||||
}),
|
||||
);
|
||||
assert.equal(typeof secondCode, "string");
|
||||
assert.ok(secondCode.length > 0);
|
||||
assert.ok(
|
||||
!dossier.pseudocode.includes(values["second-marker"]),
|
||||
"The second marker also appears in the first function's pseudocode.",
|
||||
);
|
||||
assert.ok(
|
||||
secondCode.includes(values["second-marker"]),
|
||||
"The second function's pseudocode omitted its expected marker.",
|
||||
);
|
||||
const restored = observe(
|
||||
await call("procedure_pseudo_code", {
|
||||
procedure: dossier.procedure.address,
|
||||
}),
|
||||
);
|
||||
assert.equal(restored, dossier.pseudocode);
|
||||
report.checks.push(
|
||||
"second-function pseudocode identity and return to the original function",
|
||||
);
|
||||
}
|
||||
const invalid = await client.callTool({
|
||||
name: "xrefs",
|
||||
arguments: { address: "not-an-address" },
|
||||
@@ -195,7 +249,10 @@ const cleanup = async () => {
|
||||
try {
|
||||
await upstream.connect();
|
||||
if (config.mode === "attached") {
|
||||
const metadata = await upstream.call("get_metadata", {});
|
||||
const metadata =
|
||||
config.protocol === "native"
|
||||
? await upstream.readResource("ida://idb/metadata")
|
||||
: await upstream.call("get_metadata", {});
|
||||
assert.equal(metadata.sha256.toLowerCase(), await digest());
|
||||
report.checks.push(
|
||||
"existing GUI target remains open with the original input identity",
|
||||
|
||||
@@ -0,0 +1,271 @@
|
||||
#!/usr/bin/env node
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFile, writeFile, readdir } from "node:fs/promises";
|
||||
import { isAbsolute, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { PrivateRuntimeRoot } from "../dist/process/PrivateRuntimeRoot.js";
|
||||
import { parseEvidence } from "../dist/domain/evidence.js";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
|
||||
if (process.platform !== "linux")
|
||||
throw new Error(
|
||||
"Real signal verification requires Linux with util-linux prlimit.",
|
||||
);
|
||||
if (!isAbsolute(process.env.REA_SIGROK_COMMAND ?? ""))
|
||||
throw new Error(
|
||||
"Supply an absolute REA_SIGROK_COMMAND for sigrok-cli 0.7.2.",
|
||||
);
|
||||
const entrypoint =
|
||||
process.argv[2] ?? fileURLToPath(new URL("./rea.mjs", import.meta.url));
|
||||
const run = createVerifierRun();
|
||||
const root = await PrivateRuntimeRoot.create({
|
||||
prefix: "rea-signal-verifier-",
|
||||
});
|
||||
const path = join(root.path, "recording with spaces.vcd");
|
||||
const pagedPath = join(root.path, "paged.vcd");
|
||||
const execute = promisify(execFile);
|
||||
const environment = {
|
||||
...process.env,
|
||||
TMPDIR: root.path,
|
||||
TMP: root.path,
|
||||
TEMP: root.path,
|
||||
};
|
||||
const client = new Client({ name: "signal-recording-verifier", version: "1" });
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
env: environment,
|
||||
stderr: "pipe",
|
||||
});
|
||||
// Independently synthesize 9600-baud 8N1 samples at 1 MHz: bytes 52 45 41.
|
||||
const lines = [
|
||||
"$timescale 1 us $end",
|
||||
"$scope module logic $end",
|
||||
"$var wire 1 ! RX $end",
|
||||
"$upscope $end",
|
||||
"$enddefinitions $end",
|
||||
"#0",
|
||||
"1!",
|
||||
];
|
||||
let tick = 1000;
|
||||
for (const byte of Buffer.from("REA")) {
|
||||
for (const bit of [
|
||||
0,
|
||||
...Array.from({ length: 8 }, (_, i) => (byte >> i) & 1),
|
||||
1,
|
||||
]) {
|
||||
lines.push(`#${tick}`, `${bit}!`);
|
||||
tick += 104;
|
||||
}
|
||||
tick += 208;
|
||||
}
|
||||
lines.push(`#${tick + 1000}`, "1!");
|
||||
const source = lines.join("\n") + "\n";
|
||||
let cases = 0;
|
||||
try {
|
||||
await writeFile(path, source);
|
||||
await client.connect(transport);
|
||||
const advertised = (await client.listTools()).tools.find(
|
||||
({ name }) => name === "decode_signal_recording",
|
||||
);
|
||||
assert.ok(advertised?.outputSchema);
|
||||
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
||||
assert.ok(ajv.validateSchema(advertised.inputSchema));
|
||||
assert.ok(ajv.validateSchema(advertised.outputSchema));
|
||||
for (const extra of [
|
||||
{ input_format: "vcd", annotations: "uart=rx-data" },
|
||||
{},
|
||||
]) {
|
||||
const input = { path, decoders: "uart:rx=RX:baudrate=9600", ...extra };
|
||||
const response = await client.callTool({
|
||||
name: advertised.name,
|
||||
arguments: input,
|
||||
});
|
||||
assert.notEqual(response.isError, true, JSON.stringify(response));
|
||||
assert.ok(
|
||||
ajv.validate(advertised.outputSchema, response.structuredContent),
|
||||
JSON.stringify(ajv.errors),
|
||||
);
|
||||
const evidence = parseEvidence(response.structuredContent);
|
||||
const report = evidence.normalized_result;
|
||||
for (const byte of ["52", "45", "41"])
|
||||
assert.match(
|
||||
report.annotations_text,
|
||||
new RegExp(`\\d+-\\d+ uart-1: ${byte}\\n`),
|
||||
);
|
||||
assert.equal(
|
||||
report.artifact.sha256,
|
||||
createHash("sha256").update(source).digest("hex"),
|
||||
);
|
||||
assert.equal(report.hardware_acquisition, "not-performed");
|
||||
assert.equal(report.limits.address_space_bytes, 1073741824);
|
||||
assert.equal(report.tool.configured_path, process.env.REA_SIGROK_COMMAND);
|
||||
assert.equal(
|
||||
report.resource_limiter.configured_path,
|
||||
process.env.REA_SIGROK_PRLIMIT_COMMAND ?? "/usr/bin/prlimit",
|
||||
);
|
||||
assert.ok(
|
||||
report.resource_limiter.arguments.includes("--as=1073741824:1073741824"),
|
||||
);
|
||||
assert.equal(report.diagnostics, "");
|
||||
const flags = Object.entries(input)
|
||||
.filter(([key]) => key !== "path")
|
||||
.flatMap(([key, value]) => [`--${key}`, value]);
|
||||
const cli = JSON.parse(
|
||||
(
|
||||
await execute(
|
||||
process.execPath,
|
||||
[
|
||||
entrypoint,
|
||||
"decode-signal-recording",
|
||||
path,
|
||||
...flags,
|
||||
"--format",
|
||||
"json",
|
||||
],
|
||||
{ env: environment, timeout: 60000, maxBuffer: 16 * 1024 * 1024 },
|
||||
)
|
||||
).stdout,
|
||||
);
|
||||
assert.equal(parseEvidence(cli).evidence_id, evidence.evidence_id);
|
||||
const bundle = await client.callTool({
|
||||
name: "get_evidence_bundle",
|
||||
arguments: {},
|
||||
});
|
||||
assert.ok(JSON.stringify(bundle).includes(evidence.evidence_id));
|
||||
assert.equal(await readFile(path, "utf8"), source);
|
||||
cases++;
|
||||
}
|
||||
const pagedLines = lines.slice(0, 7);
|
||||
let pagedTick = 1000;
|
||||
for (const byte of Array.from({ length: 120 }, (_, i) => i)) {
|
||||
for (const bit of [
|
||||
0,
|
||||
...Array.from({ length: 8 }, (_, i) => (byte >> i) & 1),
|
||||
1,
|
||||
]) {
|
||||
pagedLines.push(`#${pagedTick}`, `${bit}!`);
|
||||
pagedTick += 104;
|
||||
}
|
||||
pagedTick += 208;
|
||||
}
|
||||
pagedLines.push(`#${pagedTick + 1000}`, "1!");
|
||||
const pagedSource = pagedLines.join("\n") + "\n";
|
||||
await writeFile(pagedPath, pagedSource);
|
||||
for (const [options, first, count] of [
|
||||
[{}, 0, 50],
|
||||
[{ line_offset: 50, line_limit: 40 }, 50, 40],
|
||||
[{ line_limit: null }, 0, 120],
|
||||
]) {
|
||||
const input = {
|
||||
path: pagedPath,
|
||||
decoders: "uart:rx=RX:baudrate=9600",
|
||||
input_format: "vcd",
|
||||
annotations: "uart=rx-data",
|
||||
...options,
|
||||
};
|
||||
const response = await client.callTool({
|
||||
name: advertised.name,
|
||||
arguments: input,
|
||||
});
|
||||
assert.notEqual(response.isError, true, JSON.stringify(response));
|
||||
assert.ok(
|
||||
ajv.validate(advertised.outputSchema, response.structuredContent),
|
||||
JSON.stringify(ajv.errors),
|
||||
);
|
||||
const evidence = parseEvidence(response.structuredContent);
|
||||
const report = evidence.normalized_result;
|
||||
assert.deepEqual(report.output_window, {
|
||||
total_lines: 120,
|
||||
returned_lines: count,
|
||||
has_more: first + count < 120,
|
||||
});
|
||||
const observed = report.annotations_text
|
||||
.trimEnd()
|
||||
.split("\n")
|
||||
.map((line) => {
|
||||
const match = /^\d+-\d+ uart-1: ([0-9A-F]{2})$/.exec(line);
|
||||
assert.ok(match, line);
|
||||
return Number.parseInt(match[1], 16);
|
||||
});
|
||||
assert.deepEqual(
|
||||
observed,
|
||||
Array.from({ length: count }, (_, i) => first + i),
|
||||
);
|
||||
const flags = Object.entries(input)
|
||||
.filter(([key]) => key !== "path")
|
||||
.flatMap(([key, value]) =>
|
||||
key === "line_limit" && value === null
|
||||
? ["--all_lines"]
|
||||
: [`--${key}`, String(value)],
|
||||
);
|
||||
const cli = JSON.parse(
|
||||
(
|
||||
await execute(
|
||||
process.execPath,
|
||||
[
|
||||
entrypoint,
|
||||
"decode-signal-recording",
|
||||
pagedPath,
|
||||
...flags,
|
||||
"--format",
|
||||
"json",
|
||||
],
|
||||
{ env: environment, timeout: 60000, maxBuffer: 16 * 1024 * 1024 },
|
||||
)
|
||||
).stdout,
|
||||
);
|
||||
assert.equal(parseEvidence(cli).evidence_id, evidence.evidence_id);
|
||||
assert.equal(await readFile(pagedPath, "utf8"), pagedSource);
|
||||
cases++;
|
||||
}
|
||||
for (const input of [
|
||||
{ path, decoders: "no_such_decoder" },
|
||||
{ path: join(root.path, "absent.vcd"), decoders: "uart" },
|
||||
{ path, decoders: "uart", driver: "demo" },
|
||||
]) {
|
||||
const response = await client.callTool({
|
||||
name: advertised.name,
|
||||
arguments: input,
|
||||
});
|
||||
assert.equal(response.isError, true);
|
||||
await client.ping();
|
||||
cases++;
|
||||
}
|
||||
await writeFile(path, "not a recording");
|
||||
const invalid = await client.callTool({
|
||||
name: advertised.name,
|
||||
arguments: { path, decoders: "uart" },
|
||||
});
|
||||
assert.equal(invalid.isError, true);
|
||||
cases++;
|
||||
await client.close();
|
||||
assert.deepEqual((await readdir(root.path)).sort(), [
|
||||
"paged.vcd",
|
||||
"recording with spaces.vcd",
|
||||
]);
|
||||
} finally {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
await root.close();
|
||||
}
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
status: "passed",
|
||||
cases,
|
||||
host: `${process.platform}/${process.arch}`,
|
||||
scope:
|
||||
"real sigrok UART VCD through compiled CLI/MCP; no physical acquisition",
|
||||
...(await completeVerifierRun(run)),
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
@@ -122,15 +122,44 @@ try {
|
||||
new URL("../tests/fixtures/wasm/custom-names.wat", import.meta.url),
|
||||
"utf8",
|
||||
),
|
||||
];
|
||||
for (const [index, source] of sources.entries()) {
|
||||
`(module
|
||||
(memory 1)
|
||||
(data "x")
|
||||
(func (export "init")
|
||||
i32.const 0
|
||||
i32.const 0
|
||||
i32.const 1
|
||||
memory.init 0
|
||||
data.drop 0))\n`,
|
||||
].map((source) => ({ source, debugNames: false }));
|
||||
sources.push(
|
||||
{
|
||||
source:
|
||||
'(module $named (func (export "answer") (result i32) i32.const 42))\n',
|
||||
debugNames: true,
|
||||
},
|
||||
{
|
||||
source: await readFile(
|
||||
new URL("../tests/fixtures/wasm/module-names.wat", import.meta.url),
|
||||
"utf8",
|
||||
),
|
||||
debugNames: false,
|
||||
},
|
||||
);
|
||||
for (const [index, { source, debugNames }] of sources.entries()) {
|
||||
const fixtureRoot = join(root.path, `fixture-${index}`);
|
||||
await mkdir(fixtureRoot);
|
||||
const path = join(fixtureRoot, "module.wasm");
|
||||
await writeFile(join(fixtureRoot, "source.wat"), source);
|
||||
await tool(
|
||||
"wat2wasm",
|
||||
["--enable-all", "source.wat", "-o", "module.wasm"],
|
||||
[
|
||||
"--enable-all",
|
||||
...(debugNames ? ["--debug-names"] : []),
|
||||
"source.wat",
|
||||
"-o",
|
||||
"module.wasm",
|
||||
],
|
||||
fixtureRoot,
|
||||
);
|
||||
await tool("wasm-validate", ["--enable-all", "module.wasm"], fixtureRoot);
|
||||
@@ -218,8 +247,33 @@ try {
|
||||
'"test\nline"',
|
||||
'"fake"\nSection Details:\n Type start=0x0000000a end=0x0000000b (size=0x00000001) count: 0\n"end"',
|
||||
'"unicode-é\\\t"',
|
||||
'"visible"',
|
||||
'"\uFEFFsection"',
|
||||
'"\uFEFFname"',
|
||||
'"\uFEFF"',
|
||||
'""',
|
||||
],
|
||||
);
|
||||
if (debugNames) {
|
||||
assert.ok(report.headers.includes("\nmodule name: <named>\n"));
|
||||
assert.deepEqual(report.exports, ['(export "answer" (func 0))']);
|
||||
}
|
||||
if (index === 4) {
|
||||
assert.match(
|
||||
headers,
|
||||
/^DataCount start=0x[\da-f]+ end=0x[\da-f]+ \(size=0x[\da-f]+\) count: 1$/m,
|
||||
);
|
||||
assert.deepEqual(
|
||||
report.sections.find(({ kind }) => kind === "DataCount"),
|
||||
{
|
||||
kind: "DataCount",
|
||||
start: 0x23,
|
||||
end: 0x24,
|
||||
bytes: 1,
|
||||
description: "count: 1",
|
||||
},
|
||||
);
|
||||
}
|
||||
const bundleReply = await client.callTool({
|
||||
name: "get_evidence_bundle",
|
||||
arguments: {},
|
||||
|
||||
@@ -913,6 +913,30 @@ async function inspect(mode, input, errorCategory) {
|
||||
}
|
||||
assert.notEqual(result.isError, true, mcpTextValue(result));
|
||||
assertSensitiveLimitations(value, input.sensitive_values ?? []);
|
||||
if (input.format === "har") {
|
||||
const surface = await client.callTool({
|
||||
name: "inspect_analysis_view",
|
||||
arguments: {
|
||||
source: { kind: "retained-evidence", evidence_id: value.evidence_id },
|
||||
view: { kind: "api-surface" },
|
||||
},
|
||||
});
|
||||
if ((input.sensitive_values ?? []).length > 0) {
|
||||
// Derived view text cannot be checked against undisclosed declarations.
|
||||
assert.equal(surface.isError, true);
|
||||
const refused = JSON.parse(mcpTextValue(surface));
|
||||
for (const literal of input.sensitive_values)
|
||||
assert.ok(!JSON.stringify(refused).includes(literal));
|
||||
} else {
|
||||
assert.notEqual(surface.isError, true, mcpTextValue(surface));
|
||||
const projected = JSON.parse(mcpTextValue(surface));
|
||||
assert.equal(projected.normalized_result.kind, "api-surface");
|
||||
assert.equal(
|
||||
projected.normalized_result.records.examined,
|
||||
value.normalized_result.records.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
return value.normalized_result;
|
||||
}
|
||||
const args = [
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { requireMcpToolError } from "../../lib/mcp-verifier-results.mjs";
|
||||
import {
|
||||
requireMcpLifecycleResult,
|
||||
requireMcpToolError,
|
||||
sortVerifierNames,
|
||||
} from "../../lib/mcp-verifier-results.mjs";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
access,
|
||||
@@ -273,22 +277,23 @@ const verifyAndroidReadiness = async ({
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const catalog = await client.listTools();
|
||||
const catalogNames = catalog.tools.map(({ name }) => name).sort();
|
||||
const status = await client.callTool({
|
||||
const catalogNames = sortVerifierNames(
|
||||
catalog.tools.map(({ name }) => name),
|
||||
);
|
||||
const statusReply = await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: {},
|
||||
});
|
||||
assert.notEqual(status.isError, true, JSON.stringify(status));
|
||||
const availability = status.structuredContent?.result?.tool_availability;
|
||||
assert.ok(Array.isArray(availability));
|
||||
const status = requireMcpLifecycleResult(statusReply, "binary_session");
|
||||
const availability = status.tool_availability;
|
||||
assert.deepEqual(
|
||||
availability.map(({ name }) => name).sort(),
|
||||
TOOL_CONTRACTS.map(({ name }) => name).sort(),
|
||||
sortVerifierNames(availability.map(({ name }) => name)),
|
||||
sortVerifierNames(TOOL_CONTRACTS.map(({ name }) => name)),
|
||||
"Readiness must retain one availability record for the complete canonical catalog",
|
||||
);
|
||||
assert.deepEqual(
|
||||
catalogNames,
|
||||
TOOL_CONTRACTS.map(({ name }) => name).sort(),
|
||||
sortVerifierNames(TOOL_CONTRACTS.map(({ name }) => name)),
|
||||
"Readiness must not truncate the SDK tool catalog",
|
||||
);
|
||||
const byName = new Map(availability.map((item) => [item.name, item]));
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
@@ -48,6 +48,19 @@ export async function verifyNativeProvenance(app, executable) {
|
||||
assert.equal(mcp.raw_result, null);
|
||||
assert.ok(cli.normalized_result.provenance.length > 0);
|
||||
assert.deepEqual(mcp.normalized_result, cli.normalized_result);
|
||||
if (operation === "inspect_macho") {
|
||||
const delayed = cli.normalized_result.load_commands.items.find(
|
||||
({ fields }) => fields.name === "@rpath/libdelay.dylib (offset 28)",
|
||||
);
|
||||
assert.equal(delayed?.kind, "LC_LOAD_DYLIB");
|
||||
assert.equal(delayed.fields.options, "delay-init");
|
||||
assert.equal(delayed.fields["time stamp"], undefined);
|
||||
assert.ok(
|
||||
cli.normalized_result.dependencies.items.some(
|
||||
({ path }) => path === "@rpath/libdelay.dylib",
|
||||
),
|
||||
);
|
||||
}
|
||||
assert.deepEqual(
|
||||
JSON.parse(response.content.find((item) => item.type === "text").text),
|
||||
response.structuredContent,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile, readdir } from "node:fs/promises";
|
||||
import { join, relative, sep } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
@@ -100,7 +100,9 @@ const verifyRegions = (evidence) => {
|
||||
);
|
||||
assert.equal(gzip.reported_size, oracle.length);
|
||||
assert.equal(gzip.size_basis, "provider_reported_validation_unknown");
|
||||
return result.regions.map(({ provider_id, ...region }) => region);
|
||||
return result.regions.map(
|
||||
({ provider_id: _provider_id, ...region }) => region,
|
||||
);
|
||||
};
|
||||
const verifyFiles = async (evidence) => {
|
||||
const result = firmwareResultSchemas.extract_firmware.parse(
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import type {
|
||||
Device as VendorDevice,
|
||||
DeviceManager as VendorDeviceManager,
|
||||
Script as VendorScript,
|
||||
Session as VendorSession,
|
||||
} from "../../node_modules/frida/build/src/frida_binding.js";
|
||||
import type { Device, DeviceManager, Script, Session } from "frida";
|
||||
|
||||
type Assert<Condition extends true> = Condition;
|
||||
|
||||
type VendorDeviceManagerFitsShim = Assert<
|
||||
VendorDeviceManager extends DeviceManager ? true : false
|
||||
>;
|
||||
type VendorDeviceFitsShim = Assert<VendorDevice extends Device ? true : false>;
|
||||
type VendorSessionFitsShim = Assert<
|
||||
VendorSession extends Session ? true : false
|
||||
>;
|
||||
type VendorScriptFitsShim = Assert<VendorScript extends Script ? true : false>;
|
||||
|
||||
// These aliases intentionally fail when the pinned Frida API narrows incompatibly.
|
||||
const compatibility: readonly [
|
||||
VendorDeviceManagerFitsShim,
|
||||
VendorDeviceFitsShim,
|
||||
VendorSessionFitsShim,
|
||||
VendorScriptFitsShim,
|
||||
] = [true, true, true, true];
|
||||
|
||||
void compatibility;
|
||||
@@ -42,11 +42,66 @@ try {
|
||||
"",
|
||||
].join("\n"),
|
||||
);
|
||||
const output = await runHeadless(target, "seed-regression", [
|
||||
"-postScript",
|
||||
"ReaSeedRegressionProbe.java",
|
||||
seeds,
|
||||
]);
|
||||
// Headless can exit zero after a script fails, so require the probe's marker.
|
||||
assert.ok(output.includes("REA_SEED_REGRESSION_OK "), output);
|
||||
|
||||
const analyzer = "Decompiler Switch Analysis";
|
||||
const disabled = await runHeadless(target, "analyzer-regression-valid", [
|
||||
"-preScript",
|
||||
"ReaGhidraAnalysisOptions.java",
|
||||
analyzer,
|
||||
"-postScript",
|
||||
"ReaAnalyzerOptionsRegressionProbe.java",
|
||||
analyzer,
|
||||
]);
|
||||
assert.ok(
|
||||
disabled.includes(`REA_ANALYZER_OPTIONS_DISABLED_OK ${analyzer}`),
|
||||
disabled,
|
||||
);
|
||||
|
||||
const unknownAnalyzer = "REA Unknown Analyzer";
|
||||
const rejected = await runHeadless(target, "analyzer-regression-unknown", [
|
||||
"-preScript",
|
||||
"ReaGhidraAnalysisOptions.java",
|
||||
`${analyzer},${unknownAnalyzer}`,
|
||||
"-postScript",
|
||||
"ReaAnalyzerOptionsRegressionProbe.java",
|
||||
analyzer,
|
||||
]);
|
||||
assert.ok(
|
||||
rejected.includes(
|
||||
`Unknown Ghidra analyzer for this program: ${unknownAnalyzer}`,
|
||||
),
|
||||
rejected,
|
||||
);
|
||||
assert.ok(
|
||||
rejected.includes("Processing aborted as a result of pre-script."),
|
||||
rejected,
|
||||
);
|
||||
assert.ok(!rejected.includes("REA_ANALYZER_OPTIONS_DISABLED_OK"), rejected);
|
||||
} finally {
|
||||
if (supervisor !== undefined) {
|
||||
const stopped = await supervisor.stop();
|
||||
assert.notEqual(stopped.status, "incomplete", JSON.stringify(stopped));
|
||||
supervisor.dispose();
|
||||
}
|
||||
await rm(workspace, { recursive: true, force: true });
|
||||
}
|
||||
console.log(
|
||||
"Real Ghidra pre-script regression passed: descending function order, out-of-range seed, BSS label, BSS code rejection, analyzer option readback, unknown-analyzer abort before post-scripts, and owned-process cleanup.",
|
||||
);
|
||||
|
||||
async function runHeadless(target, project, scriptArguments) {
|
||||
const launch = await spawnOwnedProviderProcess({
|
||||
command: join(installation, "support", "analyzeHeadless"),
|
||||
arguments: [
|
||||
workspace,
|
||||
"seed-regression",
|
||||
project,
|
||||
"-import",
|
||||
target,
|
||||
"-loader",
|
||||
@@ -63,9 +118,7 @@ try {
|
||||
new URL("../../../tests/conformance/ghidra", import.meta.url),
|
||||
),
|
||||
].join(";"),
|
||||
"-postScript",
|
||||
"ReaSeedRegressionProbe.java",
|
||||
seeds,
|
||||
...scriptArguments,
|
||||
],
|
||||
runId: run.run_id,
|
||||
expectedCommand: null,
|
||||
@@ -82,16 +135,9 @@ try {
|
||||
const snapshot = supervisor.snapshot();
|
||||
const output = `${snapshot.stdout.text}\n${snapshot.stderr.text}`;
|
||||
assert.equal(snapshot.exitCode, 0, output);
|
||||
// Headless can exit zero after a script fails, so require the probe's marker.
|
||||
assert.ok(output.includes("REA_SEED_REGRESSION_OK "), output);
|
||||
} finally {
|
||||
if (supervisor !== undefined) {
|
||||
const stopped = await supervisor.stop();
|
||||
assert.notEqual(stopped.status, "incomplete", JSON.stringify(stopped));
|
||||
supervisor.dispose();
|
||||
}
|
||||
await rm(workspace, { recursive: true, force: true });
|
||||
const stopped = await supervisor.stop();
|
||||
assert.notEqual(stopped.status, "incomplete", JSON.stringify(stopped));
|
||||
supervisor.dispose();
|
||||
supervisor = undefined;
|
||||
return output;
|
||||
}
|
||||
console.log(
|
||||
"Real Ghidra seed regression passed: descending function order, out-of-range seed, BSS label, BSS code rejection, and owned-process cleanup.",
|
||||
);
|
||||
|
||||
@@ -77,6 +77,8 @@ async function verifyTarget(child, targetPath, name) {
|
||||
assert.equal(discovery.length, 1);
|
||||
const raw = discovery[0];
|
||||
assert.equal(typeof raw.id, "string");
|
||||
const expectedAttached =
|
||||
typeof raw.attached === "boolean" ? raw.attached : null;
|
||||
// Independent oracle: the fixture owns the pathname, and Node's discovery
|
||||
// serialization loses quotes/backslashes. Never decode underscores into it.
|
||||
const unresolved = process.platform === "win32" || /[_"\\]/u.test(targetPath);
|
||||
@@ -96,6 +98,7 @@ async function verifyTarget(child, targetPath, name) {
|
||||
const inventory = listed.normalized_result;
|
||||
assert.equal(inventory.targets.length, 1);
|
||||
assert.equal(inventory.targets[0].target_id, raw.id);
|
||||
assert.equal(inventory.targets[0].attached, expectedAttached);
|
||||
assert.deepEqual(inventory.targets[0].location, expectedLocation);
|
||||
assert.equal(inventory.excluded.unsupported_location, 0);
|
||||
const mcpList = await runMcp("list_javascript_runtime_targets", {
|
||||
@@ -122,7 +125,13 @@ async function verifyTarget(child, targetPath, name) {
|
||||
observation_ms: 100,
|
||||
});
|
||||
for (const result of [observed.normalized_result, mcpObservation])
|
||||
verifyObservation(result, raw.id, expectedLocation, targetPath);
|
||||
verifyObservation(
|
||||
result,
|
||||
raw.id,
|
||||
expectedLocation,
|
||||
targetPath,
|
||||
expectedAttached,
|
||||
);
|
||||
assert.deepEqual(mcpObservation.target, observed.normalized_result.target);
|
||||
process.stdout.write(
|
||||
`${JSON.stringify({
|
||||
@@ -133,6 +142,7 @@ async function verifyTarget(child, targetPath, name) {
|
||||
target_id: raw.id,
|
||||
discovery_url: raw.url,
|
||||
target_location: expectedLocation,
|
||||
attached: inventory.targets[0].attached,
|
||||
cli_scripts: observed.normalized_result.scripts.items.length,
|
||||
mcp_scripts: mcpObservation.scripts.items.length,
|
||||
listed_evidence_id: listed.evidence_id,
|
||||
@@ -141,9 +151,16 @@ async function verifyTarget(child, targetPath, name) {
|
||||
);
|
||||
}
|
||||
|
||||
function verifyObservation(result, targetId, expectedLocation, targetPath) {
|
||||
function verifyObservation(
|
||||
result,
|
||||
targetId,
|
||||
expectedLocation,
|
||||
targetPath,
|
||||
expectedAttached,
|
||||
) {
|
||||
assert.equal(result.target.target_id, targetId);
|
||||
assert.equal(result.target.runtime_kind, "node");
|
||||
assert.equal(result.target.attached, expectedAttached);
|
||||
assert.deepEqual(result.target.location, expectedLocation);
|
||||
assert.equal(result.capture.truncated, false);
|
||||
assert.ok(Array.isArray(result.directly_observed));
|
||||
|
||||
@@ -10,7 +10,7 @@ import { finished } from "node:stream/promises";
|
||||
|
||||
import { Cli } from "incur";
|
||||
|
||||
import { createStreamedCliJsonOutput } from "../../../dist/cli/streamedJsonOutput.js";
|
||||
import { createCliResultOutput } from "../../../dist/cli/cliResultOutput.js";
|
||||
import { createEvidence } from "../../../dist/domain/evidence.js";
|
||||
|
||||
// This opt-in format-boundary check writes one temporary file larger than the
|
||||
@@ -79,7 +79,7 @@ try {
|
||||
|
||||
destination = createWriteStream(path, { flags: "wx", mode: 0o600 });
|
||||
const argv = [metadata.command, "--format", format, "--full-output"];
|
||||
const output = createStreamedCliJsonOutput(argv, destination);
|
||||
const output = createCliResultOutput(argv, destination);
|
||||
assert.ok(output);
|
||||
let unexpectedOutputBytes = 0;
|
||||
let exitCode = 0;
|
||||
|
||||
+1
-1
@@ -16,9 +16,9 @@ from urllib.parse import quote, urlsplit
|
||||
SITE_ORIGIN = "https://rea.tools"
|
||||
NOTES_FIXTURES = {"examples/notes-electron/index.html", "examples/notes-web/index.html"}
|
||||
NAVIGATION = (
|
||||
("Get started", "get-started/"),
|
||||
("Showcases", "showcase/"),
|
||||
("Blog", "blog/"),
|
||||
("Get started", "get-started/"),
|
||||
("Guides", "guides/"),
|
||||
("FAQ", "faq/"),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user