feat(confidence-engine): verify disk persistence of focused-investigation evidence serializer (Experiment 7, Iteration 7)
Extended deterministic test to write serialized evidence record to OS temp directory, read back from disk, parse JSON, and assert deep structural equality. Verified: five structured arrays preserved with correct lengths; exact inputs unchanged; identity fields intact; null metadata fields survive round-trip. Temp file cleaned in finally block. Zero live model calls. Zero browser calls. No production code or canonical-helper modifications. Experiment 4 original structured output remains unavailable. Co-Authored-By: Claude Code <noreply@anthropic.com> Signed-off-by: robbond <rob@rdbsolutions.co.uk>
This commit is contained in:
@@ -650,6 +650,96 @@ assert(parsed.possibleFollowUpQuestions.length === syntheticCheckpoint.postEpiso
|
||||
|
||||
console.log("\n--- Evidence serializer test complete ---\n");
|
||||
|
||||
// ---- DISK PERSISTENCE VERIFICATION (Experiment 7 — Iteration 7) ───────────────
|
||||
// Verifies that serializeFocusedInvestigationEvidence output survives write-to-disk
|
||||
// and read-back without loss of any required evidence fields.
|
||||
|
||||
console.log("\n=== DISK PERSISTENCE VERIFICATION ===\n");
|
||||
|
||||
{
|
||||
const { writeFileSync, readFileSync, unlinkSync } = require("fs");
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
|
||||
const tmpDir = os.tmpdir();
|
||||
const tmpFile = path.join(tmpDir, "exp7-evidence-disk-persistence-" + Date.now() + ".json");
|
||||
|
||||
try {
|
||||
// Write serialized evidence to temp file on disk
|
||||
writeFileSync(tmpFile, JSON.stringify(evidence), "utf8");
|
||||
|
||||
// Read the file back from disk
|
||||
const recoveredRaw = readFileSync(tmpFile, "utf8");
|
||||
const recovered = JSON.parse(recoveredRaw);
|
||||
|
||||
// Deep structural equality via JSON round-trip comparison
|
||||
assert(
|
||||
JSON.stringify(evidence) === JSON.stringify(recovered),
|
||||
"Disk round-trip: deep structural equality preserved"
|
||||
);
|
||||
|
||||
// Five structured arrays remain present after disk round-trip
|
||||
assert(Array.isArray(recovered.observations), "disk recovery: observations array preserved");
|
||||
assert(Array.isArray(recovered.uncertainties), "disk recovery: uncertainties array preserved");
|
||||
assert(Array.isArray(recovered.assumptions), "disk recovery: assumptions array preserved");
|
||||
assert(Array.isArray(recovered.relationships), "disk recovery: relationships array preserved");
|
||||
assert(Array.isArray(recovered.possibleFollowUpQuestions), "disk recovery: possibleFollowUpQuestions array preserved");
|
||||
|
||||
// All five arrays retain correct lengths after disk round-trip
|
||||
assert(
|
||||
recovered.observations.length === syntheticCheckpoint.postEpisodeContributions[0].observations.length,
|
||||
"disk recovery: observations length matches original"
|
||||
);
|
||||
assert(
|
||||
recovered.uncertainties.length === syntheticCheckpoint.postEpisodeContributions[0].uncertainties.length,
|
||||
"disk recovery: uncertainties length matches original"
|
||||
);
|
||||
assert(
|
||||
recovered.assumptions.length === syntheticCheckpoint.postEpisodeContributions[0].assumptions.length,
|
||||
"disk recovery: assumptions length matches original"
|
||||
);
|
||||
assert(
|
||||
recovered.relationships.length === syntheticCheckpoint.postEpisodeContributions[0].relationships.length,
|
||||
"disk recovery: relationships length matches original"
|
||||
);
|
||||
assert(
|
||||
recovered.possibleFollowUpQuestions.length === syntheticCheckpoint.postEpisodeContributions[0].possibleFollowUpQuestions.length,
|
||||
"disk recovery: possibleFollowUpQuestions length matches original"
|
||||
);
|
||||
|
||||
// Exact synthetic input values remain unchanged after disk round-trip
|
||||
assert(
|
||||
recovered.canonicalTargetDescription === "Timeline and feasibility of recruiting two specialists within the nine-month window",
|
||||
"disk recovery: canonicalTargetDescription exact match preserved"
|
||||
);
|
||||
assert(
|
||||
recovered.actualQuestion === "What is the current hiring pipeline status for the two specialist roles?",
|
||||
"disk recovery: actualQuestion exact match preserved"
|
||||
);
|
||||
assert(
|
||||
recovered.exactAnswer === "We have identified several possible candidates for both specialist roles.",
|
||||
"disk recovery: exactAnswer exact match preserved"
|
||||
);
|
||||
|
||||
// Identity fields remain present after disk round-trip
|
||||
assert(recovered.experimentId === "exp-6-evidence-ser", "disk recovery: experimentId preserved");
|
||||
assert(recovered.scenarioId === "HS-03C-SERIALIZER", "disk recovery: scenarioId preserved");
|
||||
assert(recovered.targetNodeId === "n2yzwlv", "disk recovery: targetNodeId preserved");
|
||||
assert(recovered.evidenceDesignation === "synthetic-test-data", "disk recovery: evidenceDesignation preserved");
|
||||
|
||||
// Execution metadata (all null) remains present after disk round-trip
|
||||
assert(recovered.modelName === null, "disk recovery: modelName is null");
|
||||
assert(recovered.providerGenerateCalls === null,"disk recovery: providerGenerateCalls is null");
|
||||
assert(recovered.modelElapsedMs === null, "disk recovery: modelElapsedMs is null");
|
||||
assert(recovered.endToEndElapsedMs === null, "disk recovery: endToEndElapsedMs is null");
|
||||
|
||||
console.log("\n=== DISK PERSISTENCE VERIFICATION COMPLETE — ALL ASSERTIONS PASSED ===\n");
|
||||
} finally {
|
||||
// Always clean up the temporary file
|
||||
try { unlinkSync(tmpFile); } catch (_) { /* already removed or never created */ }
|
||||
}
|
||||
}
|
||||
|
||||
// ---- SYNTHETIC TESTS WITH FAKE PROVIDER (Batch 3 Iteration 1) ────────────
|
||||
// Tests synthesizeCurrentUnderstanding directly with DI-injected fake providers.
|
||||
// Zero live calls — provider.generateReconstruction returns synchronously.
|
||||
|
||||
Reference in New Issue
Block a user