mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
* feat(evidence)!: name the Evidence subject by its target identity (format revision 2) The Evidence subject carries subject.identity (kind, sha256, format, architecture, selection) and the Evidence ID commits to it, so raw/DOL entry points and ESP flash offsets of the same bytes are different subjects. Every record declares evidence_format: 2; revision 1 bundles, standalone records and snapshots are refused with the recreate guidance. binaryTargetIdentity is the one projection of an open target, used by Evidence and snapshot comparison. BREAKING CHANGE: Evidence format revision 2. Evidence IDs commit to the subject's target identity (subject.identity, including the raw/DOL entry point or ESP flash offsets), and every record declares evidence_format: 2. Evidence bundles, records and analysis snapshots from earlier releases are refused; recreate the observations with this release. * refactor(analysis-view): read parent subjects through the Evidence identity accessors (#11423) Analysis views compare their parent's file identity (evidenceFileTarget) and take path and digest from evidenceSubjectTarget instead of reading the subject's digest, format and architecture members, which duplicate subject.identity until they are removed. A counted guard (evidence-subject-declaration-read) keeps new direct reads out and records the 20 remaining files. * fix(evidence): carry format refusals through Evidence readers and bind target selections - safeParseEvidence/safeParseImmutableEvidence return the format refusal as an expected failure; every consumer maps it to the one integrity refusal with the recreate guidance. An unmarked object is an earlier record only when it has every member records have always carried. - ArtifactProvider inventory roots and provider subjects that name the target's own bytes carry the target's selection (ESP flash offsets). - Snapshot rows bind only Evidence whose identity, selection included, matches the snapshot target. - Entry-point selections use the raw-binary entry point form. * fix(evidence): refuse unauthenticated or earlier-format records instead of reading them as absent - recognizeEvidence (evidenceValidation) replaces tryParseEvidence: input without an evidence_id is not Evidence (ok(undefined)); a record that names one but fails authentication or is from another format revision is an EvidenceIntegrityError carrying the recreate guidance, never undefined. - Direct analysis retains that refusal as a secondary failure instead of silently skipping source capture; cleanup projection, source-closure annotation and the flutter, debugger and release-exposure recoveries use the same owner (the last three previously read the unauthenticated schema). - A desktop capture.json from an earlier format is refused with the recreate guidance instead of "not desktop application capture Evidence". * fix(evidence): advertise revision 2 ledger examples and rank delivery omissions by serialized size - The obligation ledger and reconstruction coverage examples named evidence_format 1, which revision 2 refuses; they now use EVIDENCE_FORMAT_REVISION. - MCP delivery chose which unretained recovery to omit by a parsed-storage lower bound clipped at the response budget. Once revision 2 subjects made the source record's estimate cross the budget, both candidates tied at the clip and the smaller source was omitted ahead of the larger completed observation. Candidates are now ranked by serialized size, which is what the budget counts. * refactor(native): compare function snapshots by their Evidence target identity (#11450) Function snapshots carry the subject's file target identity instead of the duplicated subject declaration. Call paths and function comparisons compare targets through sameTargetIdentity, so the same bytes opened at a different raw entry point or ESP flash offset no longer count as one coordinate space: build_call_path refuses the mix, and compare_functions no longer matches entries by address across selections. Structural candidates and native function matching read the architecture and digest through evidenceFileTarget. Refs #11417 * refactor(artifacts): compare artifact and WASM summaries by their Evidence target identity (#11461) Artifact comparison authenticates a summary against its retained inventory through sameTargetIdentity and rebinds the alias with the whole target, selection included, so a flash-selected inventory summary taken under an alias path is no longer refused. WASM comparison, the analysis view artifact projection and the inventory root check read the digest, format and display path through the Evidence identity accessors. Refs #11417 * refactor(evidence): read record subjects through the identity accessors in JS, managed, ledger and bundle readers (#11470) JavaScript application graphs, runtime reconciliation, managed inspection and native verification sources, the record summary filter, the ledger's residual-unknown target and bundle scope selection read the subject digest, format and display path through evidenceFileTarget and evidenceSubjectDisplay. No comparison changes: each reader matches one record's facts against its own payload or a caller filter. Refs #11417 * refactor(evidence)!: name the Evidence subject only by its target identity (#11497) * refactor(evidence)!: name the Evidence subject only by its target identity The subject keeps `identity` and the display facts `name` and `local_path`. The duplicated `digest`, `format` and `architecture` members are removed; the format-owned declaration now validates the identity itself. Readers the type checker found move to the owner accessors; untyped reads in verify scripts, the efficiency harness and test matchers move to `subject.identity`. The `evidence-subject-declaration-read` text guard and its baseline are deleted. Fixes #11473 Refs #11417 BREAKING CHANGE: the Evidence subject no longer has `digest`, `format` or `architecture`; read `subject.identity.sha256`, `subject.identity.format` and `subject.identity.architecture`. A record that still carries them is refused. * test(evidence): give the Flutter verifier fixture the identity subject and check the DOL declaration without the ID * test(evidence): drop the removed subject members from the declaration matrix and tamper fixtures * feat(evidence)!: give every Evidence record an explicit subject identity (#11536) * feat(evidence)!: give every Evidence record an explicit subject identity A producer that cannot name a file passes an `unknown` target identity with a closed reason (derived-from-linked-evidence, not-observed, unsupported-subject) instead of no subject. The subject is non-null; unknown subjects have no display facts. The generic missing-subject limitation and `subjectUnavailableReason` are removed; producer-specific explanations are ordinary limitations. Comparison identity requires the derived unknown, and null-subject consumers ask the owner accessors. Refs #11417 BREAKING CHANGE: every Evidence record has a subject. A record without a file target names `subject.identity` `{ "kind": "unknown", "reason": … }` with `name` and `local_path` null, instead of `subject: null` and the limitation "Artifact identity is unavailable for this observation.". Their Evidence IDs change. * fix(evidence): name explicit unknown subjects in JavaScript callers and keep a managed graph's file subject The verification scripts are not type-checked, so five createEvidence callers still passed undefined (or a missing first target) after the subject became required. They now pass unknownTarget("not-observed"). A managed application graph chose the first present input subject. Every subject is now present, so an unknown artifact subject hid a file subject on the member or boundary Evidence. The graph now takes the first input subject that names a file. * test(evidence): assert the subject kind instead of a presence the type now guarantees Every Evidence record has a subject after this change, so test guards and assertions that checked it for null always passed. Each now checks that the fixture subject names a file, or is removed where a later fileIdentity, fileSubjectTarget or fileSubjectDisplay call already requires that. Non-null assertions on Evidence subjects are removed; analysis-view inputs, whose subject is optional, keep an undefined check. * test(evidence): expect the Evidence subject format under its identity Two boundary tests still matched subject.format, which slice 2e moved into subject.identity. toMatchObject is not type-checked against the Evidence shape, so they failed only when run (the signature test on macOS).
673 lines
23 KiB
JavaScript
673 lines
23 KiB
JavaScript
#!/usr/bin/env node
|
|
import { canonicalOutputSchema } from "./lib/canonical-output-schema.mjs";
|
|
import assert from "node:assert/strict";
|
|
import { execFile } from "node:child_process";
|
|
import { createHash } from "node:crypto";
|
|
import { mkdir, readFile, readdir, 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 { Ajv2020 } from "ajv/dist/2020.js";
|
|
import { parseEvidence } from "../dist/domain/evidence.js";
|
|
import {
|
|
requireMcpEvidenceBundle,
|
|
requireMcpOutput,
|
|
mcpTextValue,
|
|
requireMcpToolError,
|
|
} from "./lib/mcp-verifier-results.mjs";
|
|
import { closeVerifierResources } from "./lib/verifier-cleanup.mjs";
|
|
import { onceConfirmed, VerifierFixture } from "./lib/verifier-fixture.mjs";
|
|
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
|
import { WABT_OPERATION_TIMEOUT_MS } from "./lib/wabt-verifier-timeouts.mjs";
|
|
|
|
import { verifyWabtCleanup } from "./lib/verify-wabt-cleanup.mjs";
|
|
|
|
const directory = process.env.REA_WABT_BIN_DIRECTORY;
|
|
if (!isAbsolute(directory ?? "")) {
|
|
if (process.argv.includes("--require-tools"))
|
|
throw new Error(
|
|
"Supply absolute REA_WABT_BIN_DIRECTORY containing WABT 1.0.42 tools.",
|
|
);
|
|
console.log(
|
|
JSON.stringify({
|
|
status: "skipped",
|
|
reason:
|
|
"WABT real-tool lane requires caller-supplied REA_WABT_BIN_DIRECTORY; no tools installed.",
|
|
}),
|
|
);
|
|
process.exit(0);
|
|
}
|
|
const entrypoint =
|
|
process.argv.slice(2).find((arg) => !arg.startsWith("--")) ??
|
|
fileURLToPath(new URL("./rea.mjs", import.meta.url));
|
|
const execute = promisify(execFile);
|
|
const environment = Object.fromEntries(
|
|
Object.entries(process.env).filter(([, value]) => typeof value === "string"),
|
|
);
|
|
const toolPath = (tool) =>
|
|
join(directory, `${tool}${process.platform === "win32" ? ".exe" : ""}`);
|
|
const tool = (name, args, cwd) =>
|
|
execute(toolPath(name), args, {
|
|
cwd,
|
|
env: environment,
|
|
timeout: 30_000,
|
|
maxBuffer: 32 * 1024 * 1024,
|
|
});
|
|
const sha256 = (value) => createHash("sha256").update(value).digest("hex");
|
|
const assertEvidenceParity = (cli, mcp, path) => {
|
|
const { caller_input_path: callerInputPath, ...cliShared } = cli;
|
|
assert.equal(callerInputPath, path);
|
|
assert.equal(Object.hasOwn(mcp, "caller_input_path"), false);
|
|
assert.deepEqual(cliShared, mcp);
|
|
};
|
|
const run = createVerifierRun();
|
|
const root = await VerifierFixture.open({ prefix: "rea-wabt-verifier-" });
|
|
// Keep provider scratch outside the leased private input root. On Windows the
|
|
// root's retained DELETE handle blocks child temp creation beneath that root.
|
|
let childTemp;
|
|
try {
|
|
childTemp = await VerifierFixture.open({
|
|
prefix: "rea-wabt-child-temp-",
|
|
private: false,
|
|
});
|
|
} catch (cause) {
|
|
try {
|
|
await root.release();
|
|
} catch (cleanupCause) {
|
|
throw new AggregateError(
|
|
[cause, cleanupCause],
|
|
"Could not allocate verifier temp space or release its private root.",
|
|
);
|
|
}
|
|
throw cause;
|
|
}
|
|
const childTempRoot = childTemp.path;
|
|
const client = new Client({ name: "wabt-artifact-verifier", version: "1" });
|
|
const callTool = (request) =>
|
|
client.callTool(request, { timeout: WABT_OPERATION_TIMEOUT_MS });
|
|
const transport = new StdioClientTransport({
|
|
command: process.execPath,
|
|
args: [entrypoint, "mcp"],
|
|
env: {
|
|
...environment,
|
|
TMPDIR: childTempRoot,
|
|
TMP: childTempRoot,
|
|
TEMP: childTempRoot,
|
|
},
|
|
stderr: "pipe",
|
|
});
|
|
let cases = 0;
|
|
const failures = [];
|
|
try {
|
|
for (const name of ["wat2wasm", "wasm-validate", "wasm-objdump", "wasm2wat"])
|
|
assert.equal(
|
|
(await tool(name, ["--version"], root.path)).stdout.trim(),
|
|
"1.0.42",
|
|
);
|
|
await client.connect(transport);
|
|
const advertised = (await client.listTools()).tools.find(
|
|
({ name }) => name === "inspect_wasm_artifact",
|
|
);
|
|
assert.ok(advertised, "WASM tool must advertise output schema");
|
|
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
|
assert.ok(ajv.validateSchema(advertised.inputSchema));
|
|
assert.ok(ajv.validateSchema(canonicalOutputSchema(advertised.name)));
|
|
const inspectCli = async (input) => {
|
|
try {
|
|
return JSON.parse(
|
|
(
|
|
await execute(
|
|
process.execPath,
|
|
[
|
|
entrypoint,
|
|
"inspect-wasm-artifact",
|
|
input.path,
|
|
...(input.command_timeout_ms === undefined
|
|
? []
|
|
: ["--command-timeout-ms", String(input.command_timeout_ms)]),
|
|
...input.glue_paths.flatMap((path) => ["--glue_paths", path]),
|
|
...input.candidate_paths.flatMap((path) => [
|
|
"--candidate_paths",
|
|
path,
|
|
]),
|
|
"--format",
|
|
"json",
|
|
],
|
|
{
|
|
env: {
|
|
...environment,
|
|
TMPDIR: childTempRoot,
|
|
TMP: childTempRoot,
|
|
TEMP: childTempRoot,
|
|
},
|
|
timeout: WABT_OPERATION_TIMEOUT_MS,
|
|
maxBuffer: 64 * 1024 * 1024,
|
|
},
|
|
)
|
|
).stdout,
|
|
);
|
|
} catch (cause) {
|
|
if (typeof cause.code === "number" && typeof cause.stdout === "string")
|
|
return JSON.parse(cause.stdout);
|
|
throw cause;
|
|
}
|
|
};
|
|
const sources = [
|
|
await readFile(
|
|
new URL("../tests/fixtures/wasm/module.wat", import.meta.url),
|
|
"utf8",
|
|
),
|
|
"(module)\n",
|
|
'(module (import "env.with.dot" "field.with.dot" (global i32)) (import "env" "table" (table 1 funcref)) (memory (export "memory") 1) (export "g" (global 0)) (export "t" (table 0)) (func (export "name\\0aline") (result i32) i32.const 42))\n',
|
|
await readFile(
|
|
new URL("../tests/fixtures/wasm/custom-names.wat", import.meta.url),
|
|
"utf8",
|
|
),
|
|
`(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",
|
|
...(debugNames ? ["--debug-names"] : []),
|
|
"source.wat",
|
|
"-o",
|
|
"module.wasm",
|
|
],
|
|
fixtureRoot,
|
|
);
|
|
await tool("wasm-validate", ["--enable-all", "module.wasm"], fixtureRoot);
|
|
const original = await readFile(path);
|
|
// Independent modes avoid treating a custom name's text as a framing marker.
|
|
const headers = (
|
|
await tool("wasm-objdump", ["-h", "module.wasm"], fixtureRoot)
|
|
).stdout;
|
|
const details = (
|
|
await tool("wasm-objdump", ["-x", "module.wasm"], fixtureRoot)
|
|
).stdout;
|
|
const wat = (
|
|
await tool("wasm2wat", ["--enable-all", "module.wasm"], fixtureRoot)
|
|
).stdout;
|
|
await writeFile(join(fixtureRoot, "decoded.wat"), wat);
|
|
await tool(
|
|
"wat2wasm",
|
|
["--enable-all", "decoded.wat", "-o", "roundtrip.wasm"],
|
|
fixtureRoot,
|
|
);
|
|
await tool(
|
|
"wasm-validate",
|
|
["--enable-all", "roundtrip.wasm"],
|
|
fixtureRoot,
|
|
);
|
|
const candidateRoot = join(fixtureRoot, "other");
|
|
await mkdir(candidateRoot);
|
|
const candidate = join(candidateRoot, "module.wasm");
|
|
await writeFile(join(candidateRoot, "source.wat"), "(module (memory 2))");
|
|
await tool("wat2wasm", ["source.wat", "-o", "module.wasm"], candidateRoot);
|
|
const glueValues = [
|
|
"./module.wasm",
|
|
"https://example.invalid/module.wasm?version=1",
|
|
...["\n", "\r", "\r\n", "\u2028", "\u2029"].flatMap((separator) => [
|
|
`https://example.invalid/module.wasm?query=a${separator}b`,
|
|
`https://example.invalid/module.wasm#fragment=a${separator}b`,
|
|
]),
|
|
];
|
|
const glueLiterals = glueValues.map((value) =>
|
|
JSON.stringify(value)
|
|
.replace(/\u2028/gu, "\\u2028")
|
|
.replace(/\u2029/gu, "\\u2029"),
|
|
);
|
|
const glueSource = [
|
|
`fetch(${glueLiterals[0]}); new URL(${glueLiterals[1]}, import.meta.url);`,
|
|
...glueLiterals.slice(2).map((literal) => `fetch(${literal});`),
|
|
].join("\n");
|
|
const glueSources = [
|
|
glueSource,
|
|
'import source module from "./module.wasm"; new URL("https://example.invalid/module.wasm?version=1", import.meta.url);',
|
|
'const module = await import.source("./module.wasm"); new URL("https://example.invalid/module.wasm?version=1", import.meta.url);',
|
|
`\uFEFF${glueSource}`,
|
|
`\uFEFF\n${glueSource}`,
|
|
`#!/usr/bin/env node\n${glueSource}`,
|
|
`\uFEFF#!/usr/bin/env node\n${glueSource}`,
|
|
];
|
|
const gluePaths = glueSources.map((_, index) =>
|
|
join(fixtureRoot, `glue-${index}.js`),
|
|
);
|
|
for (const [index, gluePath] of gluePaths.entries())
|
|
await writeFile(gluePath, glueSources[index]);
|
|
const input = {
|
|
path,
|
|
glue_paths: gluePaths,
|
|
candidate_paths: [candidate],
|
|
...(index === 0 ? { command_timeout_ms: 60_000 } : {}),
|
|
};
|
|
assert.ok(ajv.validate(advertised.inputSchema, input));
|
|
const cliValue = await inspectCli(input);
|
|
assert.equal(cliValue.category, undefined, JSON.stringify(cliValue));
|
|
const cli = parseEvidence(cliValue);
|
|
const reply = await callTool({
|
|
name: "inspect_wasm_artifact",
|
|
arguments: input,
|
|
});
|
|
assert.notEqual(reply.isError, true, mcpTextValue(reply));
|
|
assert.ok(
|
|
ajv.validate(
|
|
canonicalOutputSchema(advertised.name),
|
|
reply.structuredContent,
|
|
),
|
|
JSON.stringify(ajv.errors),
|
|
);
|
|
const mcp = parseEvidence(requireMcpOutput(reply, "inspect_wasm_artifact"));
|
|
assert.equal(cli.evidence_id, mcp.evidence_id);
|
|
assertEvidenceParity(cli, mcp, path);
|
|
const report = mcp.normalized_result;
|
|
assert.equal(
|
|
report.tool_profile.timeout_ms,
|
|
input.command_timeout_ms ?? 30_000,
|
|
);
|
|
assert.equal(mcp.parameters.command_timeout_ms, input.command_timeout_ms);
|
|
assert.equal(report.artifact.sha256, sha256(original));
|
|
assert.equal(report.artifact.bytes, original.length);
|
|
assert.equal(report.wat.text, wat);
|
|
assert.equal(report.wat.sha256, sha256(wat));
|
|
assert.equal(report.headers, `${headers}\n`);
|
|
assert.equal(report.details, details.slice(1));
|
|
assert.equal(report.glue.length, glueSources.length);
|
|
for (const [index, source] of glueSources.entries()) {
|
|
const observed = report.glue[index];
|
|
const expectedValues =
|
|
index === 1 || index === 2 ? glueValues.slice(0, 2) : glueValues;
|
|
const expectedLiterals = glueLiterals.slice(0, expectedValues.length);
|
|
assert.equal(observed.artifact.path, gluePaths[index]);
|
|
assert.equal(observed.artifact.sha256, sha256(source));
|
|
assert.equal(observed.artifact.bytes, Buffer.byteLength(source));
|
|
assert.equal(await readFile(gluePaths[index], "utf8"), source);
|
|
assert.equal(observed.parse_status, "complete");
|
|
assert.deepEqual(
|
|
observed.references.map(({ value }) => value),
|
|
expectedValues,
|
|
);
|
|
assert.deepEqual(
|
|
observed.references.map(({ candidate_paths }) => candidate_paths),
|
|
expectedValues.map((_, index) =>
|
|
index === 0 ? [path] : [path, candidate],
|
|
),
|
|
);
|
|
assert.deepEqual(
|
|
observed.references.map(({ association }) => association),
|
|
expectedValues.map((_, index) =>
|
|
index === 0 ? "local-path-candidate" : "basename-candidates",
|
|
),
|
|
);
|
|
assert.deepEqual(
|
|
observed.references.map(({ line, column }) => ({ line, column })),
|
|
expectedLiterals.map((literal) => {
|
|
const offset = source.indexOf(literal);
|
|
assert.notEqual(offset, -1);
|
|
return {
|
|
line: source.slice(0, offset).split("\n").length,
|
|
column: offset - source.lastIndexOf("\n", offset) - 1,
|
|
};
|
|
}),
|
|
);
|
|
}
|
|
assert.notEqual(report.candidates[0].sha256, report.candidates[1].sha256);
|
|
for (const command of report.tool_profile.commands)
|
|
assert.equal(command.sha256, sha256(await readFile(command.path)));
|
|
if (index === 0) {
|
|
assert.ok(
|
|
report.sections.some(
|
|
({ kind, description }) =>
|
|
kind === "Custom" && description === '"test"',
|
|
),
|
|
);
|
|
assert.ok(report.wat.text.includes('(@custom "test" "payload")'));
|
|
assert.equal(
|
|
sha256(await readFile(join(fixtureRoot, "roundtrip.wasm"))),
|
|
sha256(original),
|
|
);
|
|
}
|
|
if (index === 3)
|
|
assert.deepEqual(
|
|
report.sections.map(({ description }) => description),
|
|
[
|
|
'"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 callTool({
|
|
name: "get_evidence_bundle",
|
|
arguments: {},
|
|
});
|
|
const bundle = requireMcpEvidenceBundle(bundleReply);
|
|
const retained = bundle.records.find(
|
|
({ evidence_id }) => evidence_id === mcp.evidence_id,
|
|
);
|
|
assert.deepEqual(retained, mcp);
|
|
assert.deepEqual(await readFile(path), original);
|
|
cases += 2;
|
|
for (const [label, invalidBytes] of [
|
|
["truncated", original.subarray(0, 7)],
|
|
["invalid", Buffer.from("not a wasm module")],
|
|
]) {
|
|
const invalidPath = join(fixtureRoot, `${label}.wasm`);
|
|
await writeFile(invalidPath, invalidBytes);
|
|
const invalidInput = {
|
|
path: invalidPath,
|
|
glue_paths: [],
|
|
candidate_paths: [],
|
|
...(index === 0 ? { command_timeout_ms: 42_000 } : {}),
|
|
};
|
|
const cliError = await inspectCli(invalidInput);
|
|
assert.equal(
|
|
cliError.category,
|
|
"invalid_input",
|
|
JSON.stringify(cliError),
|
|
);
|
|
const error = requireMcpToolError(
|
|
await callTool({
|
|
name: "inspect_wasm_artifact",
|
|
arguments: invalidInput,
|
|
}),
|
|
);
|
|
assert.equal(error.category, "invalid_input");
|
|
const partial = error.details.partial_observation;
|
|
assert.equal(partial.kind, "retained-evidence");
|
|
const failedBundleReply = await callTool({
|
|
name: "get_evidence_bundle",
|
|
arguments: {},
|
|
});
|
|
const failedBundle = requireMcpEvidenceBundle(failedBundleReply);
|
|
const failed = failedBundle.records.find(
|
|
({ evidence_id }) => evidence_id === partial.evidence_id,
|
|
);
|
|
assert.ok(failed, "Retained failed WASM Evidence missing from bundle");
|
|
assert.equal(failed.subject.identity.sha256, sha256(invalidBytes));
|
|
assert.equal(
|
|
failed.normalized_result.tool_profile.timeout_ms,
|
|
invalidInput.command_timeout_ms ?? 30_000,
|
|
);
|
|
assert.equal(
|
|
failed.normalized_result.tool_profile.output_budget_bytes,
|
|
32 * 1024 * 1024,
|
|
);
|
|
assert.equal(
|
|
failed.normalized_result.validation,
|
|
"rejected-by-selected-profile",
|
|
);
|
|
assert.equal(
|
|
cliError.details.partial_observation.evidence_id,
|
|
failed.evidence_id,
|
|
);
|
|
assert.ok(
|
|
error.details?.captured_output?.stderr?.length > 0,
|
|
JSON.stringify(error),
|
|
);
|
|
assert.deepEqual(await readFile(invalidPath), invalidBytes);
|
|
cases += 2;
|
|
}
|
|
}
|
|
// Source-owned inert core and raw optional payloads reproduce #6885 without
|
|
// asking wat2wasm to repair or regenerate the malformed name metadata.
|
|
const core = Buffer.from(
|
|
"0061736d0100000001040160000003020100070501016600000a040102000b",
|
|
"hex",
|
|
);
|
|
for (const [label, payload, metadata, observedName] of [
|
|
["valid-name", Buffer.from("00060568656c6c6f", "hex"), "complete", true],
|
|
[
|
|
"valid-name-map",
|
|
Buffer.from("00060568656c6c6f010100", "hex"),
|
|
"complete",
|
|
true,
|
|
],
|
|
[
|
|
"inner-name-error",
|
|
Buffer.from("00060568656c6c6f010101", "hex"),
|
|
"unknown",
|
|
true,
|
|
],
|
|
[
|
|
"partial-name",
|
|
Buffer.from("00060568656c6c6f010201", "hex"),
|
|
"uninterpretable",
|
|
true,
|
|
],
|
|
[
|
|
"initial-name-error",
|
|
Buffer.from("0006056e616d65", "hex"),
|
|
"uninterpretable",
|
|
false,
|
|
],
|
|
]) {
|
|
const fixtureRoot = join(root.path, label);
|
|
await mkdir(fixtureRoot);
|
|
const path = join(fixtureRoot, "module.wasm"),
|
|
custom = Buffer.concat([Buffer.from([4]), Buffer.from("name"), payload]),
|
|
original = Buffer.concat([core, Buffer.from([0, custom.length]), custom]);
|
|
await writeFile(path, original);
|
|
const validation = await tool(
|
|
"wasm-validate",
|
|
["--enable-all", "--ignore-custom-section-errors", "module.wasm"],
|
|
fixtureRoot,
|
|
),
|
|
dump = await tool(
|
|
"wasm-objdump",
|
|
["-h", "-x", "module.wasm"],
|
|
fixtureRoot,
|
|
),
|
|
decoded = await tool(
|
|
"wasm2wat",
|
|
["--enable-all", "--ignore-custom-section-errors", "module.wasm"],
|
|
fixtureRoot,
|
|
);
|
|
const input = { path, glue_paths: [], candidate_paths: [] };
|
|
const cli = parseEvidence(await inspectCli(input));
|
|
const reply = await callTool({
|
|
name: "inspect_wasm_artifact",
|
|
arguments: input,
|
|
});
|
|
assert.notEqual(reply.isError, true, mcpTextValue(reply));
|
|
assert.ok(
|
|
ajv.validate(
|
|
canonicalOutputSchema(advertised.name),
|
|
reply.structuredContent,
|
|
),
|
|
JSON.stringify(ajv.errors),
|
|
);
|
|
const mcp = parseEvidence(requireMcpOutput(reply, "inspect_wasm_artifact"));
|
|
assertEvidenceParity(cli, mcp, path);
|
|
const report = mcp.normalized_result;
|
|
assert.equal(report.validation, "valid");
|
|
assert.equal(report.artifact.sha256, sha256(original));
|
|
assert.equal(report.artifact.bytes, original.length);
|
|
assert.equal(report.debug_name_metadata, metadata);
|
|
assert.equal(report.interface.state, "complete");
|
|
assert.deepEqual(report.exports, ['(export "f" (func 0))']);
|
|
assert.deepEqual(
|
|
report.interface.entries.map(({ direction, name, signature }) => ({
|
|
direction,
|
|
name,
|
|
signature,
|
|
})),
|
|
[
|
|
{
|
|
direction: "export",
|
|
name: "f",
|
|
signature: { kind: "func", params: [], results: [] },
|
|
},
|
|
],
|
|
);
|
|
assert.equal(
|
|
report.headers.includes("module name: <hello>\n"),
|
|
observedName,
|
|
);
|
|
assert.equal(report.sections.at(-1).end, original.length);
|
|
assert.equal(report.wat.text, decoded.stdout);
|
|
assert.equal(report.wat.sha256, sha256(decoded.stdout));
|
|
assert.ok(report.wat.text.includes('(@custom "name"'));
|
|
const warnings = [
|
|
{ tool: "wasm-validate", text: validation.stderr },
|
|
{ tool: "wasm-objdump", text: dump.stderr },
|
|
{ tool: "wasm2wat", text: decoded.stderr },
|
|
].filter(({ text }) => text !== "");
|
|
assert.equal(warnings.length, metadata === "complete" ? 0 : 3);
|
|
assert.deepEqual(report.custom_section_warnings, warnings);
|
|
if (metadata !== "complete")
|
|
assert.ok(
|
|
report.limitations.some((text) =>
|
|
text.includes("complete debug-name coverage remains unknown"),
|
|
),
|
|
);
|
|
assert.deepEqual(await readFile(path), original);
|
|
cases += 2;
|
|
}
|
|
for (const following of [false, true]) {
|
|
const path = join(root.path, `invalid-custom-name-${following}.wasm`);
|
|
const original = Buffer.concat([
|
|
core,
|
|
Buffer.from("000a02fffe7061796c6f6164", "hex"),
|
|
...(following ? [Buffer.from("00050174616263", "hex")] : []),
|
|
]);
|
|
await writeFile(path, original);
|
|
const input = { path, glue_paths: [], candidate_paths: [] };
|
|
const cli = parseEvidence(await inspectCli(input));
|
|
const reply = await callTool({
|
|
name: "inspect_wasm_artifact",
|
|
arguments: input,
|
|
});
|
|
assert.notEqual(reply.isError, true, mcpTextValue(reply));
|
|
assert.ok(
|
|
ajv.validate(
|
|
canonicalOutputSchema(advertised.name),
|
|
reply.structuredContent,
|
|
),
|
|
JSON.stringify(ajv.errors),
|
|
);
|
|
const mcp = parseEvidence(requireMcpOutput(reply, "inspect_wasm_artifact"));
|
|
assertEvidenceParity(cli, mcp, path);
|
|
const report = mcp.normalized_result;
|
|
assert.equal(report.artifact.sha256, sha256(original));
|
|
assert.equal(report.debug_name_metadata, "unknown");
|
|
assert.equal(report.interface.state, "complete");
|
|
assert.deepEqual(report.exports, ['(export "f" (func 0))']);
|
|
const custom = report.sections.filter(({ kind }) => kind === "Custom");
|
|
assert.deepEqual(
|
|
custom.map(({ description }) => description),
|
|
following ? ["", '"t"'] : [""],
|
|
);
|
|
assert.equal(report.sections.at(-1).end, original.length);
|
|
assert.equal(report.custom_section_warnings.length, 3);
|
|
assert.ok(
|
|
report.custom_section_warnings.every(({ text }) =>
|
|
text.includes("error: invalid utf-8 encoding: section name"),
|
|
),
|
|
);
|
|
assert.ok(
|
|
report.limitations.some((text) =>
|
|
text.includes("custom-section name is invalid UTF-8"),
|
|
),
|
|
);
|
|
assert.deepEqual(await readFile(path), original);
|
|
cases += 2;
|
|
}
|
|
cases += await verifyWabtCleanup(entrypoint, environment, childTempRoot);
|
|
} catch (cause) {
|
|
failures.push(cause);
|
|
}
|
|
// The MCP server child uses both roots until it exits, so each is released
|
|
// only after the client and transport close. The two roots are otherwise
|
|
// independent; a leaked provider workspace keeps the child temp root.
|
|
const closeClient = onceConfirmed(() => client.close());
|
|
const closeTransport = onceConfirmed(() => transport.close());
|
|
for (const fixture of [childTemp, root]) {
|
|
fixture.releaseAfter(closeClient);
|
|
fixture.releaseAfter(closeTransport);
|
|
}
|
|
childTemp.releaseAfter(async () =>
|
|
assert.ok(
|
|
!(await readdir(childTempRoot)).some((name) =>
|
|
name.startsWith("rea-wabt-"),
|
|
),
|
|
"Provider workspace leaked",
|
|
),
|
|
);
|
|
try {
|
|
await closeVerifierResources([
|
|
() => childTemp.release(),
|
|
() => root.release(),
|
|
]);
|
|
} catch (cause) {
|
|
failures.push(cause);
|
|
}
|
|
if (failures.length > 0)
|
|
throw new AggregateError(failures, "WABT real-tool verification failed.");
|
|
console.log(
|
|
JSON.stringify(
|
|
{
|
|
status: "passed",
|
|
cases,
|
|
tool_profile: "wabt@1.0.42",
|
|
entrypoint,
|
|
verifier: await completeVerifierRun(run),
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
);
|