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:
@@ -520,4 +520,67 @@ async function composeDeepInvestigationCheckpoint({ situationGraph, previousQues
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { runLiveExperiment, extractLiveExperimentCheckpoint, _extractReasoningState, composeDeepInvestigationCheckpoint };
|
||||
/**
|
||||
* Serialize a completed deep-investigation checkpoint into the durable
|
||||
* focused-deconstruction evidence record.
|
||||
*
|
||||
* Pure function — no side effects, no I/O, no model calls. Intended for
|
||||
* deterministic test fixtures and external audit tools that need a stable
|
||||
* JSON-serializable representation of the five deconstruction arrays plus
|
||||
* exact input values and execution metadata.
|
||||
*
|
||||
* @param {object} checkpoint — returned from composeDeepInvestigationCheckpoint()
|
||||
* @param {object} identity — { experimentId, scenarioId, targetNodeId, evidenceDesignation }
|
||||
* - experimentId: unique identifier for the experiment run
|
||||
* - scenarioId: identifier for the scenario (e.g. "HS-03C")
|
||||
* - targetNodeId: the situationGraph node that was selected as focus
|
||||
* - evidenceDesignation: "synthetic" or "real-user" (or any string)
|
||||
* @param {object} [metadata] — optional execution metadata from the apparatus
|
||||
* - modelName, providerGenerateCalls, modelElapsedMs, endToEndElapsedMs, success
|
||||
* Any missing field is set to null (never fabricated).
|
||||
* @returns {object} JSON-serializable evidence record per fixed contract
|
||||
*/
|
||||
function serializeFocusedInvestigationEvidence(checkpoint, identity, metadata) {
|
||||
/* ── Extract the five structured deconstruction arrays ────────────── */
|
||||
const contributions = Array.isArray(checkpoint?.postEpisodeContributions)
|
||||
? checkpoint.postEpisodeContributions
|
||||
: [];
|
||||
|
||||
// There should be exactly one contribution per focused-investigation run;
|
||||
// if multiple exist (episode path with accumulated contributions),
|
||||
// take the first one that carries the deconstruction arrays.
|
||||
const deconContribution = contributions.find(
|
||||
(c) => Array.isArray(c?.observations) && Array.isArray(c?.uncertainties)
|
||||
) || contributions[0] || {};
|
||||
|
||||
return {
|
||||
/* ── Identity (supplied by caller, not derived) ─────────────────── */
|
||||
experimentId: identity.experimentId ?? null,
|
||||
scenarioId: identity.scenarioId ?? null,
|
||||
targetNodeId: identity.targetNodeId ?? null,
|
||||
evidenceDesignation: identity.evidenceDesignation ?? null,
|
||||
|
||||
/* ── Exact focused-investigation inputs (from checkpoint) ──────── */
|
||||
canonicalTargetDescription: checkpoint.focusedInvestigationInput?.targetDescription ?? "",
|
||||
actualQuestion: checkpoint.focusedInvestigationInput?.question ?? "",
|
||||
exactAnswer: checkpoint.focusedInvestigationInput?.answer ?? "",
|
||||
|
||||
/* ── Structured model output (preserved verbatim, no transformation) ─── */
|
||||
observations: deconContribution.observations ?? null,
|
||||
uncertainties: deconContribution.uncertainties ?? null,
|
||||
assumptions: deconContribution.assumptions ?? null,
|
||||
relationships: deconContribution.relationships ?? null,
|
||||
possibleFollowUpQuestions: deconContribution.possibleFollowUpQuestions ?? null,
|
||||
|
||||
/* ── Execution metadata (supplied by caller; null when not exposed) ─ */
|
||||
modelName: metadata?.modelName ?? null,
|
||||
providerGenerateCalls: metadata?.providerGenerateCalls ?? null,
|
||||
modelElapsedMs: metadata?.modelElapsedMs ?? null,
|
||||
endToEndElapsedMs: metadata?.endToEndElapsedMs ?? null,
|
||||
executionStatus: (metadata?.success !== undefined)
|
||||
? (metadata.success === true ? "completed" : "failed")
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { runLiveExperiment, extractLiveExperimentCheckpoint, _extractReasoningState, composeDeepInvestigationCheckpoint, serializeFocusedInvestigationEvidence };
|
||||
|
||||
Reference in New Issue
Block a user