Files
reverse-engineering-anything/tests/boundary/mcp/evidenceInputResolutionCatalog.test.ts
T
morluto fbfcad3152 fix(evidence): route web script export and WASM comparison through shared Evidence inputs (#15385)
* fix(evidence): resolve web script and WASM comparison sources through the shared Evidence input owner

export_web_scripts accepts its capture as declared Evidence input: a
complete record, a retained reference, or a retained inspect_analysis_view
summary, which reads its retained parent. compare_wasm_interfaces admits
both sides through resolveEvidenceRequest, so a malformed side is a
bounded evidence_integrity_mismatch and a summary reads its parent. The
summary-to-parent rule lives in the shared resolver as completeProducers.
A catalog test checks that every declared Evidence input resolves a
retained reference through the shared resolver.

Refs #15341

* fix(evidence): retain an inline web script capture before publishing and commit the schema summary
2026-11-30 20:42:45 -05:00

97 lines
3.6 KiB
TypeScript

import { expect, it } from "vitest";
import { TOOL_CONTRACTS } from "../../../src/contracts/toolContracts.js";
import { getEvidenceInputContract } from "../../../src/domain/evidenceInputContract.js";
import { ok } from "../../../src/domain/result.js";
import { createApplicationMcpHarness } from "../../fixtures/applicationMcpHarness.js";
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
/** A distinct absent identity, so sources that must differ still do. */
const missingId = (index: number): string =>
`ev_${index.toString(16).padStart(64, "f")}`;
const missing = (index: number) => ({
kind: "retained-evidence",
evidence_id: missingId(index),
});
/** Inputs for contracts whose advertised examples select no Evidence source. */
const SOURCE_INPUTS: Readonly<Record<string, unknown>> = {
compare_wasm_interfaces: {
left: missing(0),
right: missing(1),
scope: "both",
},
export_web_scripts: {
capture: missing(0),
output_directory: "/rea-evidence-catalog/never-created",
},
};
/** Every declared Evidence position in `input`, each replaced by an absent reference. */
const withMissingSources = (
contract: (typeof TOOL_CONTRACTS)[number],
input: unknown,
): {
readonly input: unknown;
readonly sources: ReadonlySet<string>;
readonly first: string | undefined;
} => {
const evidence = getEvidenceInputContract(contract.inputSchema);
const framed = evidence.frameSchema.safeParse(input);
const sources = new Set<string>();
if (!framed.success) return { input, sources, first: undefined };
const replaced = evidence.resolve(framed.data, () => {
const reference = missing(sources.size);
sources.add(reference.evidence_id);
return ok(reference);
});
return {
input: replaced.ok ? replaced.value : input,
sources,
first: [...sources][0],
};
};
it("resolves every declared Evidence input through the shared resolver", async () => {
const { client } = await createApplicationMcpHarness();
const contracts = TOOL_CONTRACTS.filter(
({ inputSchema }) => getEvidenceInputContract(inputSchema).hasEvidence,
);
expect(contracts.map(({ name }) => name)).toEqual(
expect.arrayContaining(Object.keys(SOURCE_INPUTS)),
);
const failures: string[] = [];
for (const contract of contracts) {
const candidates = [
...(SOURCE_INPUTS[contract.name] === undefined
? []
: [SOURCE_INPUTS[contract.name]]),
...contract.examples.map(({ input }) => input),
];
const selected = candidates
.map((input) => withMissingSources(contract, input))
.find(({ sources }) => sources.size > 0);
if (selected === undefined) {
failures.push(`${contract.name}: no input selects an Evidence source`);
continue;
}
const response = await client.callTool({
name: contract.name,
arguments: selected.input as Record<string, unknown>,
});
if (response.isError !== true) {
failures.push(`${contract.name}: admitted a missing reference`);
continue;
}
const { error } = parseMcpToolError(response);
const details: Readonly<Record<string, unknown>> = error.details ?? {};
// The shared resolver stops at the first declared position and names its
// exact missing reference; an adapter that parses Evidence itself reports
// a schema or kind failure instead. Later positions need a valid
// producer-specific source first, so each owner's tests cover them.
if (details.evidence_id !== selected.first || details.reason !== "missing")
failures.push(`${contract.name}: ${error.code} ${error.message}`);
}
expect(failures).toEqual([]);
});