refactor(evidence): migrate runtime consumption (#29)
This commit is contained in:
@@ -77,7 +77,7 @@ def test_finalize_commits_session_before_best_effort_post_commit_read_failure(
|
||||
monkeypatch.setattr("tht.execute.warnings.runtime_warnings", lambda *args: [])
|
||||
monkeypatch.setattr("tht.execute.warnings.static_warnings", lambda *args: [])
|
||||
monkeypatch.setattr("tht.report.render_validation_report", lambda **kwargs: "verified\n")
|
||||
monkeypatch.setattr("tht.session.artifacts.build_evidence_entries", lambda *args: [])
|
||||
monkeypatch.setattr("tht.evidence.project_session", lambda *args: [])
|
||||
|
||||
session_cmd.finalize_cmd(session_id, config=Path("unused.yaml"))
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ from tht.decisions import DecisionRecord
|
||||
from tht.evidence import (
|
||||
acquire,
|
||||
active_searcher,
|
||||
build_retrieval_entries,
|
||||
discover,
|
||||
project_session,
|
||||
resolve_citation,
|
||||
@@ -125,6 +126,18 @@ def test_search_facade_preserves_active_filtering_and_global_order(tmp_path):
|
||||
assert facade_delegate.calls == legacy_delegate.calls
|
||||
|
||||
|
||||
def test_retrieval_entries_preserve_hit_order_and_existing_projection_shape():
|
||||
hits = [
|
||||
SimpleNamespace(label="Second", status="reviewed", content="abcdefgh"),
|
||||
SimpleNamespace(label="First", status=None, content="12345678"),
|
||||
]
|
||||
|
||||
assert build_retrieval_entries(hits, excerpt_chars=5) == [
|
||||
{"title": "Second", "status": "reviewed", "excerpt": "abcde"},
|
||||
{"title": "First", "status": None, "excerpt": "12345"},
|
||||
]
|
||||
|
||||
|
||||
def _canonical_store(root, evidence_id):
|
||||
content = f"# {evidence_id}\n"
|
||||
digest = hashlib.sha256(content.encode()).hexdigest()
|
||||
@@ -159,6 +172,40 @@ def test_citation_facade_matches_active_corpus_resolution(tmp_path):
|
||||
assert resolve_citation(store, "missing", materialized_root=materialized) == ""
|
||||
|
||||
|
||||
def test_session_projection_routes_corpus_citations_through_the_facade(tmp_path, monkeypatch):
|
||||
evidence_root = tmp_path / "artifacts" / "evidence"
|
||||
(tmp_path / "corpus").mkdir()
|
||||
calls = []
|
||||
|
||||
def fake_resolve(store, evidence_id, *, materialized_root=None):
|
||||
calls.append((store.root, evidence_id, materialized_root))
|
||||
return f"/materialized/{evidence_id}.md"
|
||||
|
||||
monkeypatch.setattr("tht.evidence.resolve_citation", fake_resolve)
|
||||
linking = SchemaLinking(
|
||||
question="q",
|
||||
candidates=[Candidate(
|
||||
kind="table",
|
||||
name="fact_procedure",
|
||||
evidence=["evi-used"],
|
||||
decision="promoted",
|
||||
decision_seq=17,
|
||||
)],
|
||||
)
|
||||
|
||||
assert build_evidence_entries([], linking, evidence_root) == [{
|
||||
"id": "evi-used",
|
||||
"file": "/materialized/evi-used.md",
|
||||
"esito": "usata",
|
||||
"decision_seq": 17,
|
||||
}]
|
||||
assert calls == [(
|
||||
tmp_path / "corpus",
|
||||
"evi-used",
|
||||
tmp_path / "artifacts" / ".materialized-evidence",
|
||||
)]
|
||||
|
||||
|
||||
def _record(seq, type_, subject):
|
||||
return DecisionRecord(
|
||||
seq=seq,
|
||||
|
||||
@@ -93,6 +93,18 @@ def _patch(monkeypatch, embedder, searcher):
|
||||
|
||||
|
||||
def test_pack_single_embed_and_sections(tmp_path, monkeypatch):
|
||||
import tht.evidence as evidence_facade
|
||||
|
||||
projected = []
|
||||
build_retrieval_entries = evidence_facade.build_retrieval_entries
|
||||
monkeypatch.setattr(
|
||||
evidence_facade,
|
||||
"build_retrieval_entries",
|
||||
lambda results, *, excerpt_chars: (
|
||||
projected.append((list(results), excerpt_chars))
|
||||
or build_retrieval_entries(results, excerpt_chars=excerpt_chars)
|
||||
),
|
||||
)
|
||||
cfg = _workspace(tmp_path)
|
||||
emb = _FakeEmbedder()
|
||||
searcher = _FakeSearcher()
|
||||
@@ -109,6 +121,7 @@ def test_pack_single_embed_and_sections(tmp_path, monkeypatch):
|
||||
# must not leak into a new search pack.
|
||||
assert "Dominio ablazione" not in res.output
|
||||
assert "SELECT 1" in res.output
|
||||
assert projected == [([], 400)]
|
||||
|
||||
|
||||
def test_pack_json_and_session_file(tmp_path, monkeypatch):
|
||||
|
||||
@@ -9,8 +9,8 @@ import pytest
|
||||
from tht.corpus.models import CanonicalDocument, CorpusManifest
|
||||
from tht.corpus.store import CorpusStore
|
||||
from tht.decisions import DecisionRecord, append_decision
|
||||
from tht.evidence import project_session
|
||||
from tht.phase import current_phase, effective_decisions
|
||||
from tht.session.artifacts import build_evidence_entries
|
||||
from tht.session.models import Candidate, SchemaLinking
|
||||
from tht.workflow import load_workflow
|
||||
|
||||
@@ -173,7 +173,7 @@ def test_schema_linking_evidence_used_resolves_from_the_active_canonical_corpus(
|
||||
)
|
||||
store.publish(generation)
|
||||
|
||||
entries = build_evidence_entries(
|
||||
entries = project_session(
|
||||
[],
|
||||
_linking("evi-used"),
|
||||
tmp_path / "artifacts" / "evidence",
|
||||
@@ -195,7 +195,7 @@ def test_legacy_evidence_without_a_canonical_corpus_keeps_used_and_reviewed_outc
|
||||
for evidence_id in ("evi-used", "evi-accepted", "evi-rejected"):
|
||||
(evidence_root / f"{evidence_id}.md").write_text(f"# {evidence_id}\n")
|
||||
|
||||
entries = build_evidence_entries(
|
||||
entries = project_session(
|
||||
[
|
||||
_record(21, "evidence_accepted", "evi-accepted"),
|
||||
_record(22, "evidence_rejected", "evi-rejected"),
|
||||
|
||||
Reference in New Issue
Block a user