Merge pull request #1073 from morluto/fix/evidence-bundle-diagnostics

fix(evidence): name the failed constraint when a bundle is rejected
This commit is contained in:
Kaoru0822
2026-10-08 07:27:21 -07:00
committed by GitHub
6 changed files with 147 additions and 8 deletions
@@ -163,7 +163,55 @@ 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 partial = join(directory, "partial.json");
await writeFile(partial, JSON.stringify({ evidence_id: "typo" }));
const rejected = await readEvidenceBundle(partial);
expect(rejected).toMatchObject({
ok: false,
error: {
userMessage: expect.stringContaining(
"does not match the bundle schema",
),
},
});
expect(rejected).not.toMatchObject({
error: { userMessage: expect.stringContaining("one Evidence record") },
});
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:",
),
},
});
});
});