feat(confidence-engine): add serializeFocusedInvestigationEvidence evidence serializer and deterministic test

Apparatus-level pure serialization function that preserves all five
focused-deconstruction arrays (observations, uncertainties, assumptions,
relationships, possibleFollowUpQuestions) plus exact inputs and execution
metadata from the existing checkpoint — without modifying production code.

Deterministic verification: syntax check pass, 79/79 assertions pass
(including 28 new evidence-ser tests), zero live calls.

Experiment 4's missing structured output cannot be reconstructed (never
persisted by the apparatus). No new semantic evidence produced.
This commit is contained in:
2026-10-09 14:25:26 +01:00
parent 7fd05745e8
commit 7d7a9e8d29
4 changed files with 205 additions and 2 deletions
@@ -530,6 +530,126 @@ assert0(typeof composeDeepInvestigationCheckpoint === "function", "O9: composeDe
console.log("\n--- Total failures: " + failures0 + " ---\n");
// ---- EVIDENCE SERIALIZER TEST (Iteration 6) ──────────────────────────
console.log("\n=== EVIDENCE SERIALIZER TEST ===\n");
// Verify the serializer is exported as a function
assert(typeof composeDeepInvestigationCheckpoint.serializeFocusedInvestigationEvidence !== "function",
"serializeFocusedInvestigationEvidence is NOT nested on compose (it is top-level export)");
// --- Direct invocation test with purely synthetic fixture data ---
const { serializeFocusedInvestigationEvidence } = require("./live-update-experiment-helper.cjs");
assert(typeof serializeFocusedInvestigationEvidence === "function", "serializeFocusedInvestigationEvidence is exported and callable");
// Synthetic checkpoint mimicking the exact shape returned by composeDeepInvestigationCheckpoint()
const syntheticCheckpoint = {
currentUnderstanding: "Synthetic understanding text",
updatedSituationGraph: { nodes: [{ id: "n1" }], edges: [], resolvedNodeIds: ["n1"] },
postEpisodeContributions: [{
id: "contrib-test-6a",
targetNodeId: "n2yzwlv",
question: "What is the current hiring pipeline status?",
answer: "We have identified several possible candidates.",
sequence: 1,
observations: ["Several possible candidates identified for both roles"],
uncertainties: ["Candidate availability and notice periods remain unconfirmed"],
assumptions: ["Onboarding takes some time before full contribution"],
relationships: [{ from: "n2yzwlv", to: "n3abc", type: "dependency" }],
possibleFollowUpQuestions: ["What is the confirmed earliest start date for preferred candidates?"],
}],
postEpisodeFindings: [],
findingsCheckpoint: { total: 0, eligible: 0 },
graphCheckpoint: { nodeCount: 1, edgeCount: 0, resolvedNodeIds: ["n1"] },
modelElapsedMs: null,
endToEndElapsedMs: null,
providerGenerateCalls: 0,
modelName: null,
synthesisErrorDiagnostic: null,
userSupportedMeaning: null,
possibleInference: null,
focusedInvestigationInput: {
targetDescription: "Timeline and feasibility of recruiting two specialists within the nine-month window",
question: "What is the current hiring pipeline status for the two specialist roles?",
answer: "We have identified several possible candidates for both specialist roles.",
},
};
const evidence = serializeFocusedInvestigationEvidence(
syntheticCheckpoint,
{
experimentId: "exp-6-evidence-ser",
scenarioId: "HS-03C-SERIALIZER",
targetNodeId: "n2yzwlv",
evidenceDesignation: "synthetic-test-data",
},
{} // empty metadata — all fields should be null
);
// Identity fields present and exact
assert(evidence.experimentId === "exp-6-evidence-ser", "experimentId preserved exactly");
assert(evidence.scenarioId === "HS-03C-SERIALIZER", "scenarioId preserved exactly");
assert(evidence.targetNodeId === "n2yzwlv", "targetNodeId preserved exactly");
assert(evidence.evidenceDesignation === "synthetic-test-data", "evidenceDesignation explicitly labelled synthetic");
// Exact input values survive unchanged
assert(evidence.canonicalTargetDescription === "Timeline and feasibility of recruiting two specialists within the nine-month window",
"canonicalTargetDescription exact match");
assert(evidence.actualQuestion === "What is the current hiring pipeline status for the two specialist roles?",
"actualQuestion exact match");
assert(evidence.exactAnswer === "We have identified several possible candidates for both specialist roles.",
"exactAnswer exact match");
// All five structured output arrays preserved verbatim
assert(Array.isArray(evidence.observations) && evidence.observations[0] === "Several possible candidates identified for both roles",
"observations array preserved (first element matches)");
assert(Array.isArray(evidence.uncertainties) && evidence.uncertainties[0] === "Candidate availability and notice periods remain unconfirmed",
"uncertainties array preserved (first element matches)");
assert(Array.isArray(evidence.assumptions) && evidence.assumptions[0] === "Onboarding takes some time before full contribution",
"assumptions array preserved (first element matches)");
assert(Array.isArray(evidence.relationships) && evidence.relationships[0].from === "n2yzwlv" && evidence.relationships[0].type === "dependency",
"relationships array preserved with correct shape");
assert(Array.isArray(evidence.possibleFollowUpQuestions) && evidence.possibleFollowUpQuestions[0] === "What is the confirmed earliest start date for preferred candidates?",
"possibleFollowUpQuestions array preserved (first element matches)");
// Missing execution metadata remains null (no fabrication)
assert(evidence.modelName === null, "modelName is null when not provided in metadata");
assert(evidence.providerGenerateCalls === null,"providerGenerateCalls is null when not provided in metadata");
assert(evidence.modelElapsedMs === null, "modelElapsedMs is null when not provided in metadata");
assert(evidence.endToEndElapsedMs === null, "endToEndElapsedMs is null when not provided in metadata");
// executionStatus derives from metadata.success
const evidenceWithStatus = serializeFocusedInvestigationEvidence(syntheticCheckpoint, { experimentId: "x", scenarioId: "s", targetNodeId: "n", evidenceDesignation: "d" }, { success: true });
assert(evidenceWithStatus.executionStatus === "completed", "executionStatus is 'completed' when metadata.success === true");
const evidenceFailed = serializeFocusedInvestigationEvidence(syntheticCheckpoint, { experimentId: "x", scenarioId: "s", targetNodeId: "n", evidenceDesignation: "d" }, { success: false });
assert(evidenceFailed.executionStatus === "failed", "executionStatus is 'failed' when metadata.success === false");
// JSON round-trip preserves all required fields (no loss)
const json = JSON.stringify(evidence);
const parsed = JSON.parse(json);
assert(parsed.experimentId === evidence.experimentId, "JSON round-trip: experimentId preserved");
assert(parsed.scenarioId === evidence.scenarioId, "JSON round-trip: scenarioId preserved");
assert(parsed.targetNodeId === evidence.targetNodeId, "JSON round-trip: targetNodeId preserved");
assert(Array.isArray(parsed.observations), "JSON round-trip: observations survives serialization");
assert(Array.isArray(parsed.uncertainties), "JSON round-trip: uncertainties survives serialization");
assert(Array.isArray(parsed.assumptions), "JSON round-trip: assumptions survives serialization");
assert(Array.isArray(parsed.relationships), "JSON round-trip: relationships survives serialization");
assert(Array.isArray(parsed.possibleFollowUpQuestions), "JSON round-trip: possibleFollowUpQuestions survives serialization");
// Five arrays must contain the same number of elements after round-trip
assert(parsed.observations.length === syntheticCheckpoint.postEpisodeContributions[0].observations.length,
"JSON round-trip: observations length preserved");
assert(parsed.uncertainties.length === syntheticCheckpoint.postEpisodeContributions[0].uncertainties.length,
"JSON round-trip: uncertainties length preserved");
assert(parsed.assumptions.length === syntheticCheckpoint.postEpisodeContributions[0].assumptions.length,
"JSON round-trip: assumptions length preserved");
assert(parsed.relationships.length === syntheticCheckpoint.postEpisodeContributions[0].relationships.length,
"JSON round-trip: relationships length preserved");
assert(parsed.possibleFollowUpQuestions.length === syntheticCheckpoint.postEpisodeContributions[0].possibleFollowUpQuestions.length,
"JSON round-trip: possibleFollowUpQuestions length preserved");
console.log("\n--- Evidence serializer test complete ---\n");
// ---- SYNTHETIC TESTS WITH FAKE PROVIDER (Batch 3 Iteration 1) ────────────
// Tests synthesizeCurrentUnderstanding directly with DI-injected fake providers.
// Zero live calls — provider.generateReconstruction returns synchronously.