test_providence_query: assert merkle_proof carries context_root + sources
This commit is contained in:
parent
cd608b9d85
commit
a43c85fa5f
1 changed files with 34 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ Covers Phase 2 step 1 + step 2 of #000072:
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Iterator
|
from typing import Iterator
|
||||||
|
|
@ -76,6 +77,39 @@ def test_first_call_persists_with_audit_event(setup):
|
||||||
qaro.close()
|
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):
|
def test_second_call_returns_cache_hit(setup):
|
||||||
"""Second call with the SAME question + model + corpus must hit
|
"""Second call with the SAME question + model + corpus must hit
|
||||||
the cache and ignore the (different) stub answer."""
|
the cache and ignore the (different) stub answer."""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue