fix(reconstruction): resolve latest verifier observations without input-order bias
Group observations by exact normalized instant, retaining arbitrary fractional precision and offset equivalence. Coalesce equivalent assessments and all supporting Evidence; report conflicting latest assessments as unknown with verifier-result-ambiguous. Use the same instant comparison for freshness and future checks. Replace first-input-wins coverage with permutation, provenance, offset, sub-millisecond ordering, and future-clock regressions, including the public MCP workflow. Validation: focused reconstruction/offset tests and MCP workflow passed; converted JSON Schema validation, typecheck/lint, and docs checks passed. Full suite and real-provider lanes were not run.
This commit is contained in:
@@ -286,14 +286,18 @@ describe("reconstruction coverage verifier selection", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("reconstruction coverage verifier result ordering", () => {
|
||||
it("preserves the first input result when verifier timestamps tie", () => {
|
||||
describe("reconstruction coverage conflicting latest verifier observations", () => {
|
||||
it("keeps conflicting tied assessments unknown regardless of input order", () => {
|
||||
const workspace = completeReconstructionCoverageData();
|
||||
const result = workspace.verifier_results[0];
|
||||
const boundary = workspace.boundaries[0];
|
||||
if (result === undefined || boundary === undefined)
|
||||
throw new Error("Expected complete reconstruction coverage fixture");
|
||||
const failed = { ...result, status: "fail" as const };
|
||||
const failed = {
|
||||
...result,
|
||||
status: "fail" as const,
|
||||
evidence_ids: [reconstructionCoverageEvidenceId("1")],
|
||||
};
|
||||
const firstPass = createReconstructionCoverageData({
|
||||
...workspace,
|
||||
verifier_results: [result, failed],
|
||||
@@ -303,23 +307,109 @@ describe("reconstruction coverage verifier result ordering", () => {
|
||||
verifier_results: [failed, result],
|
||||
});
|
||||
|
||||
const firstPassResult = evaluateReconstructionClosure(
|
||||
firstPass,
|
||||
boundary.boundary_id,
|
||||
RECONSTRUCTION_COVERAGE_NOW,
|
||||
);
|
||||
const firstFailResult = evaluateReconstructionClosure(
|
||||
firstFail,
|
||||
boundary.boundary_id,
|
||||
RECONSTRUCTION_COVERAGE_NOW,
|
||||
);
|
||||
expect(firstPassResult).toEqual(firstFailResult);
|
||||
expect(firstPassResult).toMatchObject({
|
||||
status: "unknown",
|
||||
reasons: [
|
||||
expect.objectContaining({
|
||||
code: "verifier-result-ambiguous",
|
||||
subject_id: "claim.cli.help",
|
||||
}),
|
||||
],
|
||||
});
|
||||
expect(firstPassResult.evidence_ids).toEqual(
|
||||
expect.arrayContaining([
|
||||
reconstructionCoverageEvidenceId("3"),
|
||||
reconstructionCoverageEvidenceId("1"),
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("reconstruction coverage equivalent latest verifier observations", () => {
|
||||
it("coalesces equivalent equal-instant observations and retains all evidence", () => {
|
||||
const workspace = completeReconstructionCoverageData();
|
||||
const result = workspace.verifier_results[0];
|
||||
const boundary = workspace.boundaries[0];
|
||||
if (result === undefined || boundary === undefined)
|
||||
throw new Error("Expected complete reconstruction coverage fixture");
|
||||
const first = {
|
||||
...result,
|
||||
observed_at: "2026-07-16T11:00:00.123456789012345678900Z",
|
||||
};
|
||||
const equivalent = {
|
||||
...first,
|
||||
observed_at: "2026-07-16T06:00:00.1234567890123456789-05:00",
|
||||
covered_claim_ids: [...result.covered_claim_ids].reverse(),
|
||||
covered_dimensions: [...result.covered_dimensions].reverse(),
|
||||
artifact_sha256s: [...result.artifact_sha256s].reverse(),
|
||||
owner_sha256s: [...result.owner_sha256s].reverse(),
|
||||
evidence_ids: [reconstructionCoverageEvidenceId("1")],
|
||||
};
|
||||
const forward = createReconstructionCoverageData({
|
||||
...workspace,
|
||||
verifier_results: [first, equivalent],
|
||||
});
|
||||
const reversed = createReconstructionCoverageData({
|
||||
...workspace,
|
||||
verifier_results: [equivalent, first],
|
||||
});
|
||||
const forwardResult = evaluateReconstructionClosure(
|
||||
forward,
|
||||
boundary.boundary_id,
|
||||
RECONSTRUCTION_COVERAGE_NOW,
|
||||
);
|
||||
const reversedResult = evaluateReconstructionClosure(
|
||||
reversed,
|
||||
boundary.boundary_id,
|
||||
RECONSTRUCTION_COVERAGE_NOW,
|
||||
);
|
||||
|
||||
expect(forwardResult).toEqual(reversedResult);
|
||||
expect(forwardResult.status).toBe("ready");
|
||||
expect(forwardResult.evidence_ids).toEqual(
|
||||
expect.arrayContaining([
|
||||
reconstructionCoverageEvidenceId("3"),
|
||||
reconstructionCoverageEvidenceId("1"),
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("reconstruction coverage verifier timestamp selection", () => {
|
||||
it("lets a later unambiguous observation supersede an older tie", () => {
|
||||
const workspace = completeReconstructionCoverageData();
|
||||
const result = workspace.verifier_results[0];
|
||||
const boundary = workspace.boundaries[0];
|
||||
if (result === undefined || boundary === undefined)
|
||||
throw new Error("Expected complete reconstruction coverage fixture");
|
||||
const failed = { ...result, status: "fail" as const };
|
||||
const latestPass = {
|
||||
...result,
|
||||
observed_at: "2026-07-16T11:30:00.000Z",
|
||||
};
|
||||
const changed = createReconstructionCoverageData({
|
||||
...workspace,
|
||||
verifier_results: [result, failed, latestPass],
|
||||
});
|
||||
|
||||
expect(
|
||||
evaluateReconstructionClosure(
|
||||
firstPass,
|
||||
boundary.boundary_id,
|
||||
RECONSTRUCTION_COVERAGE_NOW,
|
||||
).status,
|
||||
).toBe("ready");
|
||||
expect(
|
||||
evaluateReconstructionClosure(
|
||||
firstFail,
|
||||
changed,
|
||||
boundary.boundary_id,
|
||||
RECONSTRUCTION_COVERAGE_NOW,
|
||||
),
|
||||
).toMatchObject({
|
||||
status: "failed",
|
||||
reasons: [expect.objectContaining({ code: "verifier-failed" })],
|
||||
});
|
||||
).toMatchObject({ status: "ready", reasons: [] });
|
||||
});
|
||||
|
||||
it("orders offset-bearing verifier timestamps chronologically", () => {
|
||||
@@ -352,6 +442,68 @@ describe("reconstruction coverage verifier result ordering", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("selects the later result when timestamps differ below millisecond precision", () => {
|
||||
const workspace = completeReconstructionCoverageData();
|
||||
const result = workspace.verifier_results[0];
|
||||
if (result === undefined)
|
||||
throw new Error("Expected fixture verifier result");
|
||||
const changed = createReconstructionCoverageData({
|
||||
...workspace,
|
||||
verifier_results: [
|
||||
{ ...result, observed_at: "2026-07-16T11:00:00.1231Z" },
|
||||
{
|
||||
...result,
|
||||
observed_at: "2026-07-16T11:00:00.1239Z",
|
||||
status: "fail",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(
|
||||
evaluateReconstructionClosure(
|
||||
changed,
|
||||
"replacement.cli",
|
||||
RECONSTRUCTION_COVERAGE_NOW,
|
||||
),
|
||||
).toMatchObject({
|
||||
status: "failed",
|
||||
reasons: [expect.objectContaining({ code: "verifier-failed" })],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("reconstruction coverage verifier future timestamps", () => {
|
||||
it("treats an observation beyond millisecond-precision now as future", () => {
|
||||
const workspace = completeReconstructionCoverageData();
|
||||
const result = workspace.verifier_results[0];
|
||||
if (result === undefined)
|
||||
throw new Error("Expected fixture verifier result");
|
||||
const changed = createReconstructionCoverageData({
|
||||
...workspace,
|
||||
verifier_results: [
|
||||
{ ...result, observed_at: "2026-07-16T12:00:00.1239Z" },
|
||||
],
|
||||
});
|
||||
|
||||
expect(
|
||||
evaluateReconstructionClosure(
|
||||
changed,
|
||||
"replacement.cli",
|
||||
Date.parse("2026-07-16T12:00:00.123Z") + 0.5,
|
||||
),
|
||||
).toMatchObject({
|
||||
status: "unknown",
|
||||
reasons: [expect.objectContaining({ code: "verifier-result-stale" })],
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a non-finite evaluation clock", () => {
|
||||
const workspace = completeReconstructionCoverageData();
|
||||
expect(() =>
|
||||
evaluateReconstructionClosure(workspace, "replacement.cli", Number.NaN),
|
||||
).toThrow("Expected finite epoch milliseconds.");
|
||||
});
|
||||
|
||||
it("rejects verifier observations from the future", () => {
|
||||
const workspace = completeReconstructionCoverageData();
|
||||
const result = workspace.verifier_results[0];
|
||||
|
||||
Reference in New Issue
Block a user