test(confidence-engine): establish longitudinal synthesis checkpoints

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-10-08 10:33:59 +01:00
co-authored by Claude Code
parent 8d9df8c939
commit 57c88b713a
3 changed files with 356 additions and 1 deletions
@@ -611,4 +611,133 @@ describe("CU synthesis experiment helper — --include-output flag", function ()
expect(JSON.stringify(situationGraph)).toBe(JSON.stringify(graphBefore));
expect(JSON.stringify(findings)).toBe(JSON.stringify(fixBefore));
});
});
// ── Longitudinal checkpoint deterministic verification ──
import longitudinalManifest from "@/tests/fixtures/current-understanding-longitudinal-checkpoints.json" assert { type: "json" };
import originalFixture from "@/tests/fixtures/current-understanding-original-investigation.json" assert { type: "json" };
describe("Longitudinal checkpoints — manifest integrity", function () {
it("manifest has exactly 4 checkpoints", async function () {
expect(longitudinalManifest.checkpoints.length).toBe(4);
});
it("checkpoint counts are 0, 2, 7, 9", async function () {
const expectedCounts = [0, 2, 7, 9];
longitudinalManifest.checkpoints.forEach((cp, i) => {
expect(cp.includedFindings.length).toBe(expectedCounts[i]);
});
});
it("checkpoint-0 has no included findings", async function () {
expect(longitudinalManifest.checkpoints[0].includedFindings).toEqual([]);
});
it("checkpoint-1 includes exactly contrib-0001 findings", async function () {
const expected = ["finding-3bw5f0", "finding-i5zdcq"];
expect(longitudinalManifest.checkpoints[1].includedFindings).toEqual(expected);
});
it("checkpoint-2 is cumulative of checkpoint-1 plus contrib-0002 findings", async function () {
const cp2 = new Set(longitudinalManifest.checkpoints[2].includedFindings);
const cp1 = longitudinalManifest.checkpoints[1].includedFindings;
cp1.forEach(f => expect(cp2.has(f)).toBe(true)); // all checkpoint-1 findings present in cp2
expect(cp2.size).toBe(7);
});
it("checkpoint-3 includes all 9 original findings", async function () {
const expected = [
"finding-3bw5f0", "finding-i5zdcq",
"finding-hciikc", "finding-ybfsm3", "finding-k45vyt",
"finding-vhftyr", "finding-9bgkmw",
"finding-23192q", "finding-kkh39k"
];
expect(longitudinalManifest.checkpoints[3].includedFindings).toEqual(expected);
});
it("all checkpoint findings are verbatim from the original fixture", async function () {
const originalMap = {};
originalFixture.findings.forEach(f => { originalMap[f.id] = f; });
longitudinalManifest.checkpoints.forEach(cp => {
cp.includedFindings.forEach(fid => {
expect(originalMap[fid]).toBeDefined();
const manifestFinding = longitudinalManifest.findingsById[fid];
expect(manifestFinding).toEqual(originalMap[fid]);
});
});
});
it("contribution ordering matches recorded timestamps", async function () {
const contribs = longitudinalManifest.contributions;
for (let i = 1; i < contribs.length; i++) {
expect(new Date(contribs[i].timestamp).getTime()).toBeGreaterThan(
new Date(contribs[i - 1].timestamp).getTime()
);
}
});
it("manifest ordering matches fixture finding order", async function () {
const originalIds = originalFixture.findings.map(f => f.id);
const manifestIds = Object.keys(longitudinalManifest.findingsById);
expect(manifestIds).toEqual(originalIds);
});
it("checkpoint-3 is cumulative of all checkpoints before it", async function () {
for (let i = 0; i < 3; i++) {
const cpSet = new Set(longitudinalManifest.checkpoints[i].includedFindings);
const cp3 = longitudinalManifest.checkpoints[3].includedFindings;
cpSet.forEach(f => expect(cp3.includes(f)).toBe(true));
}
});
it("no findings appear before their contribution boundary", async function () {
const contribOrder = {};
longitudinalManifest.contributions.forEach(c => { contribOrder[c.id] = c.ordering; });
Object.entries(longitudinalManifest.findingsById).forEach(([fid, f]) => {
const cpIndex = longitudinalManifest.checkpoints.findIndex(cp =>
cp.includedFindings.includes(fid)
);
// Find which checkpoint first includes this finding
expect(cpIndex).toBeGreaterThanOrEqual(contribOrder[f.contributionId] - 1);
});
});
it("original fixture is unchanged (spot check)", async function () {
expect(originalFixture.findings.length).toBe(9);
expect(longitudinalManifest.checkpoints[3].includedFindings.length).toBe(9);
});
it("production synthesis contract accepts checkpoint inputs", async function () {
// Verify that the filtered findings from each checkpoint can reach synthesizeCurrentUnderstanding
const fake = makeFakeProvider();
for (const cp of longitudinalManifest.checkpoints) {
const graphBefore = deepClone(situationGraph);
const cpFindings = cp.includedFindings.map(fid => originalFixture.findings.find(f => f.id === fid));
await expect(
synthesizeCurrentUnderstanding(
{ situationGraph: situationGraph, findings: cpFindings },
{ provider: fake }
)
).resolves.toBeDefined();
// Immutability check per checkpoint
expect(JSON.stringify(situationGraph)).toBe(JSON.stringify(graphBefore));
}
});
it("manifest references the source fixture path", async function () {
expect(longitudinalManifest.sourceFixture).toBe(
"tests/fixtures/current-understanding-original-investigation.json"
);
});
it("manifest does not fabricate historical graph state", async function () {
// Manifest contains findings data only, not resolvedNodeIds, activeUnknownNodeId, or reasoningState
expect(longitudinalManifest.checkpoints).not.toHaveProperty([0, "resolvedNodeIds"]);
expect(longitudinalManifest.contributions).not.toHaveProperty([0, "reasoningState"]);
});
});