From a43c85fa5fef2281b77701b8c839610c61e58409 Mon Sep 17 00:00:00 2001 From: "russell@unturf.com" Date: Wed, 3 Jun 2026 17:26:44 -0400 Subject: [PATCH] test_providence_query: assert merkle_proof carries context_root + sources --- tests/test_providence_query.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/test_providence_query.py b/tests/test_providence_query.py index 38da9c4..bb6d6c0 100644 --- a/tests/test_providence_query.py +++ b/tests/test_providence_query.py @@ -7,6 +7,7 @@ Covers Phase 2 step 1 + step 2 of #000072: """ from __future__ import annotations +import json import sqlite3 from pathlib import Path from typing import Iterator @@ -76,6 +77,39 @@ def test_first_call_persists_with_audit_event(setup): qaro.close() +def test_persisted_merkle_proof_has_context_root_and_sources(setup): + """merkle_proof column must hold the legacy-shape proof_obj: + {context_root, sources: [{document_root, ...}], retrieval_purity}. + arborist-viz Merkle Command Center reads this to synthesize the + leaf set under a multi-source context root — an empty list shows + 0 leaves in the 3D lattice.""" + corpus, qa = setup + stub = 'The core principle of anarchism is the "abolition of authority". [E1]' + r = providence_query( + corpus, "what is the core principle of anarchism?", + StubClient(answer=stub), + qa_db=qa, model_id="stub", top_k=2, + ) + qaro = sqlite3.connect(f"file:{qa}?mode=ro", uri=True) + proof_str = qaro.execute( + "SELECT merkle_proof FROM providence_cache WHERE cache_key = ?", + (r["cache_key"],), + ).fetchone()[0] + qaro.close() + proof = json.loads(proof_str) + assert isinstance(proof, dict), "merkle_proof must be a dict (was list/empty)" + assert proof["context_root"] == r["context_root"] + assert len(proof["sources"]) >= 1 + s0 = proof["sources"][0] + assert s0["document_root"] + assert "title" in s0 and "document_uri" in s0 + assert "source_role" in s0 + assert "used" in s0 and "used_pointer_ids" in s0 + assert "retrieval_purity" in proof + rp = proof["retrieval_purity"] + assert rp["total_sources"] == len(proof["sources"]) + + def test_second_call_returns_cache_hit(setup): """Second call with the SAME question + model + corpus must hit the cache and ignore the (different) stub answer."""