Files
rea/src/domain/bundleComparison.test.ts
T
morluto 9c25dc4ed2 fix!: repair boundary contracts across CLI and MCP (#597)
* fix(comparisons)!: preserve unknowns across partial observations

Share absence and digest semantics, keep unobserved managed bodies unknown, and match unique managed type/name/signatures before structural fallback.

BREAKING CHANGE: Managed comparison metadata adds exact-signature matching and its count, and name_matching now reports exact-signature-fallback.

* fix(javascript): preserve projected result binding semantics

Share syntax-aware property reads and assigned-result resolution. Retain destructuring paths and downgrade downstream whole-result relationships instead of resolving nested or wrapped calls as aliases.

* fix(native)!: admit complete parser values and preserve typed failures

Decode Mach headers by named columns, validate complete slice keys and lipo alignment, and preserve codesign runtime flags and tagged parser errors. Rename the Ghidra test dossier fixture and connect fake-backed suites to real verification lanes.

BREAKING CHANGE: Native load-command results no longer contain the unused, always-null file_offset field.

* fix(process): preserve host identity and actionable boundary failures

Thread selected platform and environment through process and Doctor seams, stamp observed producer identity in Evidence, and retain PTY, filesystem, lease and lazy-provider failure causes. Drain cancelled lazy loads and omit exited descendants from verified lineage.

* fix(browser): preserve cleanup and document-transition evidence

Make V8 and Playwright teardown cancellation-aware, expose primary failures alongside incomplete cleanup, share frame-tree and navigation rules, and clear stale WebMCP registrations without pruning unrelated child frames.

* fix(adapters): align managed targets and typed CLI outcomes

Inspect managed PE/CLI targets independently of native provider selection, reuse successful managed selections, and keep evidence bound to the actual inspected target. Classify canonical CLI error envelopes and exhaustive setup/update/uninstall outcomes, audit registered CLI coverage, and assert platform-specific runtime results.

* docs: refresh boundary contracts and shipped roadmap behavior
2026-10-06 00:50:38 +08:00

218 lines
6.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
bundleComparisonInputSchema,
bundleComparisonResultSchema,
compareBundles,
} from "./bundleComparison.js";
import { createEvidence } from "./evidence.js";
import { createEvidenceBundle } from "./evidenceBundle.js";
import {
createResidualUnknown,
recordUnknownInputSchema,
updateResidualUnknown,
updateUnknownInputSchema,
} from "./residualUnknown.js";
const PROVIDER = { id: "fixture", name: "Fixture", version: "1" } as const;
const evidence = (label: string) =>
createEvidence(undefined, PROVIDER, {
operation: "observe",
parameters: { label },
result: { label },
confidence: "derived",
authority: "analyst-inference",
});
describe("bundle comparison", () => {
it("accepts long caller-selected bundle paths", () => {
const path = `/${"deep/".repeat(1_000)}bundle.json`;
expect(
bundleComparisonInputSchema.parse({
left_bundle_path: path,
right_bundle_path: path,
}),
).toMatchObject({ left_bundle_path: path, right_bundle_path: path });
});
it("returns unchanged only for equal canonical bundles", () => {
const first = evidence("first");
const second = evidence("second");
const left = createEvidenceBundle([first, second]);
const right = createEvidenceBundle([second, first]);
const result = compareBundles(left, right);
expect(bundleComparisonResultSchema.parse(result)).toMatchObject({
status: "unchanged",
summary: {
records_unchanged: 2,
records_added: 0,
records_removed: 0,
unresolved: 0,
},
changes: [],
});
expect(result.left_bundle_sha256).toBe(result.right_bundle_sha256);
});
it("classifies explicit pairs and leaves one-sided membership unresolved", () => {
const oldRecord = evidence("old");
const newRecord = evidence("new");
const removed = evidence("removed");
const added = evidence("added");
const left = createEvidenceBundle([oldRecord, removed]);
const right = createEvidenceBundle([newRecord, added]);
const pairs = [
{
left_evidence_id: oldRecord.evidence_id,
right_evidence_id: newRecord.evidence_id,
},
];
const first = compareBundles(left, right, pairs);
const repeated = compareBundles(left, right, pairs);
expect(first).toEqual(repeated);
expect(first).toMatchObject({
status: "unknown",
summary: {
records_added: 0,
records_removed: 0,
records_changed: 1,
unresolved: 2,
},
changes: expect.arrayContaining([
expect.objectContaining({ classification: "changed" }),
expect.objectContaining({
classification: "unknown",
conclusion_kind: "unresolved_branch",
}),
]),
});
expect(first.changes).toHaveLength(3);
expect(first.limitations).toContain(
"EvidenceBundle has no inventory completeness marker; one-sided membership remains unknown.",
);
});
it("returns more than 500 changes without a display-page ceiling", () => {
const records = Array.from({ length: 501 }, (_, index) =>
evidence(`record-${String(index)}`),
);
const result = compareBundles(
createEvidenceBundle([]),
createEvidenceBundle(records),
);
expect(result.changes).toHaveLength(501);
expect(bundleComparisonResultSchema.parse(result).changes).toHaveLength(
501,
);
});
it("rejects missing and non-bijective explicit pairs", () => {
const leftRecord = evidence("left");
const rightRecord = evidence("right");
const left = createEvidenceBundle([leftRecord]);
const right = createEvidenceBundle([rightRecord]);
expect(() =>
compareBundles(left, right, [
{
left_evidence_id: evidence("missing").evidence_id,
right_evidence_id: rightRecord.evidence_id,
},
]),
).toThrow(/missing left evidence/u);
expect(() =>
compareBundles(left, right, [
{
left_evidence_id: leftRecord.evidence_id,
right_evidence_id: rightRecord.evidence_id,
},
{
left_evidence_id: leftRecord.evidence_id,
right_evidence_id: rightRecord.evidence_id,
},
]),
).toThrow(/one-to-one/u);
expect(() =>
compareBundles({ ...left, records: [leftRecord, leftRecord] }, right),
).toThrow(/duplicate record IDs/u);
});
});
describe("bundle comparison history", () => {
it("distinguishes advanced and missing unknown histories from equality", () => {
const mutationOne = evidence("mutation-one");
const initial = createResidualUnknown(
recordUnknownInputSchema.parse({
question: "Which branch remains unexplained?",
severity: "high",
domain: "comparison",
supporting_evidence_ids: [],
contradicting_evidence_ids: [],
required_authority: "shipped-artifact",
required_confidence: "observed",
required_environment: null,
recommended_probes: [],
relationships: [],
}),
mutationOne.evidence_id,
null,
);
const mutationTwo = evidence("mutation-two");
const advanced = updateResidualUnknown(
initial,
updateUnknownInputSchema.parse({
unknown_id: initial.unknown_id,
expected_revision: 1,
status: "investigating",
severity: initial.severity,
supporting_evidence_ids: [],
contradicting_evidence_ids: [],
required_authority: initial.required_authority,
required_confidence: initial.required_confidence,
required_environment: null,
recommended_probes: [],
relationships: [],
resolution: null,
}),
mutationTwo.evidence_id,
);
const initialBundle = createEvidenceBundle([mutationOne], [initial]);
const advancedBundle = createEvidenceBundle(
[mutationOne, mutationTwo],
[initial, advanced],
);
expect(compareBundles(initialBundle, advancedBundle)).toMatchObject({
status: "unknown",
summary: { unknowns_advanced: 1, unresolved: 1 },
changes: [
expect.objectContaining({
entity: "evidence",
classification: "unknown",
}),
expect.objectContaining({
entity: "residual_unknown",
classification: "history_advanced",
}),
],
});
const absent = createEvidenceBundle([]);
const missing = compareBundles(initialBundle, absent);
expect(missing).toMatchObject({
status: "unknown",
summary: {
unknowns_added: 0,
unknowns_removed: 0,
unresolved: 2,
},
});
expect(missing.changes).toContainEqual(
expect.objectContaining({
classification: "unknown",
conclusion_kind: "unresolved_branch",
limitations: [
"EvidenceBundle has no inventory completeness marker; one-sided history membership remains unknown.",
],
}),
);
});
});