fix(comparison): account for unpaired records after explicit bundle pairing (#603)

* fix(comparison): account for unpaired records after explicit bundle pairing

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

* test(browser): preserve unknown with-scope loader bindings

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

---------

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
Rudy Mizrahi Celekli
2026-10-06 02:08:42 +08:00
committed by GitHub
parent 2b7bb3bb6a
commit 12a2e3793a
2 changed files with 53 additions and 2 deletions
+51
View File
@@ -24,6 +24,57 @@ const evidence = (label: string) =>
authority: "analyst-inference",
});
describe("bundle comparison explicit cross-pairs", () => {
it("accounts for every unpaired occurrence after cross-pairing shared records", () => {
const first = evidence("first-cross-pair");
const second = evidence("second-cross-pair");
const unchanged = evidence("unchanged-cross-pair");
const bundle = createEvidenceBundle([first, second, unchanged]);
const result = compareBundles(bundle, bundle, [
{
left_evidence_id: first.evidence_id,
right_evidence_id: second.evidence_id,
},
]);
expect(result.summary).toMatchObject({
records_unchanged: 1,
records_changed: 1,
records_added: 0,
records_removed: 0,
unresolved: 2,
});
expect(result.changes).toEqual(
expect.arrayContaining([
expect.objectContaining({
classification: "unknown",
conclusion_kind: "unresolved_branch",
left_evidence_ids: [second.evidence_id],
}),
expect.objectContaining({
classification: "unknown",
conclusion_kind: "unresolved_branch",
right_evidence_ids: [first.evidence_id],
}),
]),
);
expect(result.status).toBe("unknown");
expect(result.changes).toHaveLength(3);
const changedOrUnknown = result.changes.filter(
({ entity }) => entity === "evidence",
);
expect(
result.summary.records_unchanged +
changedOrUnknown.flatMap(({ left_evidence_ids }) => left_evidence_ids)
.length,
).toBe(bundle.records.length);
expect(
result.summary.records_unchanged +
changedOrUnknown.flatMap(({ right_evidence_ids }) => right_evidence_ids)
.length,
).toBe(bundle.records.length);
});
});
describe("bundle comparison", () => {
it("accepts long caller-selected bundle paths", () => {
const path = `/${"deep/".repeat(1_000)}bundle.json`;
+2 -2
View File
@@ -166,10 +166,10 @@ const compareRecords = (
(id) => rightIds.has(id) && !pairedLeft.has(id) && !pairedRight.has(id),
);
const removed = [...leftIds].filter(
(id) => !rightIds.has(id) && !pairedLeft.has(id),
(id) => !pairedLeft.has(id) && (!rightIds.has(id) || pairedRight.has(id)),
);
const added = [...rightIds].filter(
(id) => !leftIds.has(id) && !pairedRight.has(id),
(id) => !pairedRight.has(id) && (!leftIds.has(id) || pairedLeft.has(id)),
);
for (const [ids, side] of [
[removed, "left"],