test(confidence-engine): preserve focused investigation evidence seam

This commit is contained in:
2026-10-05 09:35:04 +01:00
parent e996a542b3
commit 8e3f4388d6
2 changed files with 77 additions and 6 deletions
+41 -4
View File
@@ -18,6 +18,9 @@
const dotenv = require("dotenv");
dotenv.config({ path: ".env.local" });
// Re-export production helper for apparatus use — avoids fabricating Finding propositions.
const { deriveFindingsFromContributions } = require("../../lib/graph/finding-helpers.js");
function assertRequiredEnv(name) {
const value = process.env[name];
if (!value) {
@@ -268,7 +271,25 @@ async function runLiveExperiment({ graph, previousQuestion, answer, findings = [
* - currentUnderstanding from the synthesis result
* - findingsCheckpoint with accurate post-episode accumulated findings count
*/
async function composeDeepInvestigationCheckpoint({ situationGraph, previousQuestion, answer, findings = [], targetNodeId, episodeMode }) {
/**
* Deterministically derive a canonical Contribution from the fixed answer
* when the caller does not supply one. Mirrors production appendFocusedContribution
* shape: id, targetNodeId, question, answer, sequence, observations, etc.
*/
function _deriveContributionFromAnswer({ answer, previousQuestion, targetNodeId, sequence }) {
return {
id: `contrib-ep-${String(sequence).padStart(4, "0")}`,
targetNodeId: targetNodeId ?? null,
question: previousQuestion ?? "",
answer: answer ?? "",
sequence: sequence,
observations: [answer],
uncertainties: [],
possibleFollowUpQuestions: [],
};
}
async function composeDeepInvestigationCheckpoint({ situationGraph, previousQuestion, answer, findings = [], contributions = [], targetNodeId, episodeMode }) {
dotenv.config({ path: ".env.local" });
const baseUrl = assertRequiredEnv("OLLAMA_BASE_URL");
@@ -306,6 +327,19 @@ async function composeDeepInvestigationCheckpoint({ situationGraph, previousQues
let episodeResult;
/* ── Production-equivalent focused-episode seam: targetNodeId triggers the same path as executeEpisodeDone → handleEpisodeMode ─── */
// Derive a canonical Contribution from the fixed answer when none supplied.
// Mirrors production appendFocusedContribution: user answer → canonical Contribution
const effectiveContributions = contributions.length > 0 ? [...contributions] : [];
let newFindingsFromContributions = [];
if (effectiveContributions.length === 0 && answer && targetNodeId) {
const contribSeq = effectiveContributions.length + 1;
const derivedContrib = _deriveContributionFromAnswer({ answer, previousQuestion, targetNodeId, sequence: contribSeq });
effectiveContributions.push(derivedContrib);
// Derive canonical Findings from the Contribution (production seam)
newFindingsFromContributions = deriveFindingsFromContributions([derivedContrib]).findings;
}
if (episodeMode === true && targetNodeId) {
// Mirrors produceEpisodeAwareGraph: prepareCompletedEpisode → reconsiderCompletedEpisode → applyValidatedProposal
const { prepareCompletedEpisode } = await import("../../lib/graph/episode-preparation.js");
@@ -314,7 +348,7 @@ async function composeDeepInvestigationCheckpoint({ situationGraph, previousQues
const prepared = prepareCompletedEpisode({
situationGraph,
targetNodeId,
contributions: [], // no focused contributions in checkpoint helper (mirrors production when called without explicit contributions)
contributions: effectiveContributions,
findings,
});
@@ -365,10 +399,10 @@ async function composeDeepInvestigationCheckpoint({ situationGraph, previousQues
/* ── Step 2: Current Understanding synthesis (mirrors production synthesizeFn) ─── */
const updatedGraph = episodeResult.updatedSituationGraph;
// Accumulate prior findings + newly appended Findings for CU synthesis
// Accumulate prior findings + newly derived Findings (from new Contribution) for CU synthesis
const priorFindings = Array.isArray(findings) ? [...findings] : [];
const accumulatedEpisodes = episodeResult.appendedFindings ?? [];
const postEpisodeFindings = [...priorFindings, ...accumulatedEpisodes];
const postEpisodeFindings = [...priorFindings, ...newFindingsFromContributions, ...accumulatedEpisodes];
let currentUnderstanding = null;
if (episodeResult.success && updatedGraph) {
@@ -405,6 +439,9 @@ async function composeDeepInvestigationCheckpoint({ situationGraph, previousQues
/* ── updatedSituationGraph (NEW — for longitudinal Episode N+1 state feeding) ─── */
updatedSituationGraph: updatedGraph,
/* ── postEpisodeContributions (NEW — accumulated Contributions for longitudinal tracking) ─── */
postEpisodeContributions: effectiveContributions,
/* ── postEpisodeFindings (NEW — accumulated Findings for Episode N+1) ─── */
postEpisodeFindings: postEpisodeFindings,