Merge remote-tracking branch 'origin/main' into fix/ida-native-verification-oracles

This commit is contained in:
N0zoM1z0
2026-10-13 08:17:06 +08:00
351 changed files with 19764 additions and 1714 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ export const bundleRuntime = async (root) => {
{
cli: "cli.js",
cliOutput: "cliOutput.js",
streamedJsonOutput: "cli/streamedJsonOutput.js",
cliResultOutput: "cli/cliResultOutput.js",
mcpDoctor: "mcpDoctor.js",
},
],
+10
View File
@@ -30,6 +30,8 @@ export const toolFamilyCatalog = (sources) => {
...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,
],
},
{
@@ -196,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,
+4
View File
@@ -47,6 +47,10 @@ const SOURCE_PATHS = {
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",
+2
View File
@@ -9,6 +9,8 @@ const MIGRATED_PROVIDER_ROOTS = new Set([
"evm",
"go",
"wasm",
"captures",
"signals",
"android",
"firmware",
"ghidra",
+1 -1
View File
@@ -49,7 +49,7 @@ if (await pathExists(join(root, "src"))) {
"dist/mcp/main.js",
"dist/cli-runtime/cli.js",
"dist/cli-runtime/cliOutput.js",
"dist/cli-runtime/streamedJsonOutput.js",
"dist/cli-runtime/cliResultOutput.js",
"dist/cli-runtime/mcpDoctor.js",
"dist/mcpDoctor.js",
"dist/cli.js",
+4 -4
View File
@@ -37,7 +37,7 @@ const runtimeFiles = isMcpMode
: [
"dist/cli-runtime/cli.js",
"dist/cli-runtime/cliOutput.js",
"dist/cli-runtime/streamedJsonOutput.js",
"dist/cli-runtime/cliResultOutput.js",
];
if (!(await compiledRuntimeExists(runtimeFiles))) {
@@ -60,8 +60,8 @@ if (!(await compiledRuntimeExists(runtimeFiles))) {
} else {
const { cliConfigurationError, createCli } =
await import("../dist/cli-runtime/cli.js");
const { createStreamedCliJsonOutput } =
await import("../dist/cli-runtime/streamedJsonOutput.js");
const { createCliResultOutput } =
await import("../dist/cli-runtime/cliResultOutput.js");
const {
renderCliOutputArgumentError,
renderEmptyFilteredCliOutput,
@@ -77,7 +77,7 @@ if (!(await compiledRuntimeExists(runtimeFiles))) {
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 -2
View File
@@ -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);
+19 -9
View File
@@ -115,16 +115,25 @@ try {
],
{ GOOS: os, GOARCH: arch },
);
await verify(path, target, oracle);
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);
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.",
@@ -317,7 +326,13 @@ async function inspect(mode, path) {
return { evidence, report };
}
async function verify(path, target, oracle, byteExpected = null) {
async function verify(
path,
target,
oracle,
byteExpected = null,
fileKind = "stripped",
) {
const bytes = await readFile(path);
const expected =
byteExpected ??
@@ -387,12 +402,7 @@ async function verify(path, target, oracle, byteExpected = null) {
);
verified.push({
target: `${target[0]}/${target[1]}`,
file:
byteExpected === null
? path.endsWith("sectionless")
? "sectionless"
: "stripped"
: "byte-valued-strings",
file: byteExpected === null ? fileKind : "byte-valued-strings",
go_version: expected.GoVersion,
...(byteExpected === null
? {}
+294
View File
@@ -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,
),
);
+28 -20
View File
@@ -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",
),
@@ -124,9 +124,7 @@ async function verifyFixture(byteOrder, kernelModule) {
});
const call = async (name, args = {}) =>
requireMcpOperationResult(
await client.callTool({ name, arguments: args }, undefined, {
timeout: 180000,
}),
await client.callTool({ name, arguments: args }, { timeout: 180000 }),
name,
);
try {
-3
View File
@@ -171,7 +171,6 @@ try {
const call = async (name, args = {}) => {
const reply = await client.callTool(
{ name, arguments: args },
undefined,
{ timeout: 180000 },
);
return requireMcpOperationResult(reply, name);
@@ -184,7 +183,6 @@ try {
name: "open_binary",
arguments: { path: fixture.path, provider_id: "ghidra" },
},
undefined,
{ timeout: 60000 },
);
const error = requireMcpToolError(rejected);
@@ -423,7 +421,6 @@ try {
snapshot_path: snapshotPath,
},
},
undefined,
{ timeout: 180000 },
);
requireMcpToolError(wrongSnapshot);
+271
View File
@@ -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,
),
);
+2
View File
@@ -236,6 +236,8 @@ try {
await exec("/usr/bin/xcrun", [
"swiftc",
"-emit-library",
"-module-name",
"ReaWitnessFixture",
"-O",
...mode.flags
.map((flag) => flag.replace(/^-Wl,/u, "-Xlinker\0"))
+2 -2
View File
@@ -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;
+4 -3
View File
@@ -41,9 +41,10 @@ const cli = async (...args) => {
return parseEvidence(JSON.parse(stdout));
};
const call = async (name, args) => {
const result = await client.callTool({ name, arguments: args }, undefined, {
timeout: 150000,
});
const result = await client.callTool(
{ name, arguments: args },
{ timeout: 150000 },
);
assert.notEqual(result.isError, true, mcpTextValue(result));
return parseEvidence(JSON.parse(mcpTextValue(result)));
};