fix(evidence): name the failed constraint when a bundle is rejected

evidence-import, evidence-export, compare and the MCP bundle tools gave
every rejected file the same message: "Evidence is invalid or has
changed. Recreate or re-import it". That included a single Evidence
record, which is what every command prints, so `rea compare a.json
b.json` on two command results looked like tampering.

Report a single record as such and point to export_evidence_bundle.
Locate the first schema issue, and keep thrown constraint messages such
as a semantic identifier mismatch. EvidenceIntegrityError now accepts
the userMessage option that other typed errors already use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kaoru0822
2026-10-08 13:59:48 +00:00
co-authored by Claude Opus 5.5
parent 40e18b2e37
commit cf96ceb211
6 changed files with 138 additions and 8 deletions
@@ -136,7 +136,40 @@ describe("evidence bundle filesystem adapter", () => {
);
expect(await readEvidenceBundle(tamperedPath)).toMatchObject({
ok: false,
error: { _tag: "EvidenceIntegrityError" },
error: {
_tag: "EvidenceIntegrityError",
userMessage: expect.stringContaining(
"Evidence semantic identifier does not match its record",
),
},
});
});
it("names the failed bundle constraint for a single record or schema mismatch", async () => {
const directory = await createTestTempDirectory("rea-evidence-");
const record = bundle().records[0];
const single = join(directory, "record.json");
await writeFile(single, JSON.stringify(record));
expect(await readEvidenceBundle(single)).toMatchObject({
ok: false,
error: {
_tag: "EvidenceIntegrityError",
userMessage: expect.stringContaining(
`this JSON is one Evidence record (${String(record?.evidence_id)})`,
),
},
});
const mismatched = join(directory, "mismatched.json");
await writeFile(mismatched, JSON.stringify({ ...bundle(), records: {} }));
expect(await readEvidenceBundle(mismatched)).toMatchObject({
ok: false,
error: {
_tag: "EvidenceIntegrityError",
userMessage: expect.stringContaining(
"does not match the bundle schema at records:",
),
},
});
});
});