feat(confidence-engine): add saveFocusedInvestigationEvidence persistence operation (Experiment 8)

Add exported saveFocusedInvestigationEvidence(checkpoint, identity, metadata,
outputPath) to the canonical experiment helper. Validates output path, exactly
one valid deconstruction contribution, required identity fields, and exact input
values. Writes formatted JSON, reads back, verifies deep structural equality.
Rejects ambiguous checkpoints instead of silently selecting a contribution.

Deterministic test covers: positive file write, structured evidence completeness,
input fidelity, identity fidelity, return values, missing path rejection, missing
contribution rejection, ambiguous contribution rejection. All OS temp files cleaned
in finally blocks.

Zero live model calls. Zero browser calls. No production code modified.
This commit is contained in:
2026-10-09 14:33:33 +01:00
parent aa57d8589c
commit 0698a1a61e
4 changed files with 273 additions and 2 deletions
+24
View File
@@ -767,3 +767,27 @@ Returns JSON-serializable record with: five deconstruction arrays (`observations
**Distinction:** This test proves that the serializer's JSON-serializable output survives write-to-disk and read-back without loss. It does NOT establish a production/live-run command for writing evidence to files — that remains an untested operational boundary for future work. The apparatus produces correct in-memory records; disk persistence of those records is now independently verified at the test level.
**Experiment 4's original structured output remains unavailable.** Experiment 4 was executed before `serializeFocusedInvestigationEvidence` existed; its raw deconstruction checkpoint was never captured. No amount of apparatus testing can retroactively reconstruct it. The PARTIAL semantic fidelity classification for Experiment 4 stands unchanged.
### Iterated Eight — Explicit Evidence Persistence Operation (Experiment 8, 2026-10-09)
**Type:** Apparatus persistence operation experiment (Iteration 8 of bounded iteration loop). Zero-live-call apparatus experiment.
**Objective:** Answer whether the existing canonical experiment apparatus can expose one explicit, reusable operation that saves a completed focused-investigation checkpoint to a durable JSON file without modifying production code or changing model execution.
**Exported function:** `saveFocusedInvestigationEvidence(checkpoint, identity, metadata, outputPath)` — `tests/graph/live-update-experiment-helper.cjs`.
**Required arguments:**
- `checkpoint` — object returned by `composeDeepInvestigationCheckpoint()` (must contain `postEpisodeContributions` with exactly one valid deconstruction contribution; must contain `focusedInvestigationInput` with exact values)
- `identity` — `{ experimentId, scenarioId, targetNodeId, evidenceDesignation }` (all four fields required, no nulls)
- `metadata` — optional `{ modelName?, providerGenerateCalls?, modelElapsedMs?, endToEndElapsedMs?, success? }`
- `outputPath` — explicit non-empty string file path
**Verified output contract:** Returns `{ output_path: string, verifiedEvidence: object }`. Writes complete structured evidence as formatted JSON to the specified file. Reads file back and verifies deep structural equality with serialized record before returning. Five structured arrays preserved verbatim (including legitimately empty ones). All identity fields preserved exactly. Exact input values preserved exactly.
**Ambiguous contribution handling:** Rejected — throws `Error` when multiple valid deconstruction-carrying contributions exist in the checkpoint. Does not silently select one.
**Production changes:** None. No production code modified. No live model calls. No Ollama invocation. No graph behaviour change. No new dependencies.
**Targeted test result:** `node --check` on helper — PASS. Full deterministic test suite — 0 failures across all sections including 6 new save-evidence assertions (positive: file write, structured content, input fidelity, identity fidelity, return values; negative: missing path rejection, missing contribution rejection, ambiguous contribution rejection). All OS temp files cleaned in `finally` blocks.
**Operational note:** Future live experiments must explicitly call `saveFocusedInvestigationEvidence()` after a completed checkpoint to persist the evidence record. The function is not invoked automatically. Experiment 4's raw output remains unavailable — it was never persisted by the apparatus at that time.