refactor(evidence): remove legacy Python layout (#31)

This commit is contained in:
2026-08-24 02:36:30 +02:00
parent 44f1efa5ba
commit 840848df94
36 changed files with 246 additions and 321 deletions
+13 -27
View File
@@ -1,12 +1,13 @@
from datetime import UTC, datetime
import hashlib
import inspect
from pathlib import Path
from types import SimpleNamespace
import pytest
from tht.corpus.models import CanonicalDocument, CorpusManifest
from tht.corpus.store import CorpusStore
from tht.evidence.corpus.models import CanonicalDocument, CorpusManifest
from tht.evidence.corpus.store import CorpusStore
from tht.decisions import DecisionRecord
from tht.evidence import (
acquire,
@@ -18,15 +19,12 @@ from tht.evidence import (
project_session,
resolve_citation,
)
from tht.ports.evidence import (
from tht.evidence.contracts import (
AcquiredDocument,
EvidenceSourceError,
EvidenceSourceErrorCategory,
SourceObject,
)
from tht.search.evidence import active_searcher as legacy_active_searcher
from tht.search.evidence import resolve_evidence_file
from tht.session.artifacts import build_evidence_entries
from tht.session.models import Candidate, SchemaLinking
@@ -91,8 +89,6 @@ def test_acquisition_facade_preserves_classified_errors():
def test_source_factory_preserves_legacy_first_order_and_filesystem_configuration(tmp_path):
from tht.adapters.factory import build_evidence_sources
legacy_root = tmp_path / "legacy"
configured_root = tmp_path / "configured"
(legacy_root / "evidence").mkdir(parents=True)
@@ -108,16 +104,14 @@ def test_source_factory_preserves_legacy_first_order_and_filesystem_configuratio
)],
))
legacy = build_evidence_sources(cfg)
current = build_sources(cfg.evidence)
assert [type(source) for source in current] == [type(source) for source in legacy]
assert [source.root for source in current] == [
(legacy_root / "evidence").resolve(),
configured_root.resolve(),
]
assert current[1].patterns == legacy[1].patterns == ("*.md",)
assert current[1].max_bytes == legacy[1].max_bytes == 1024
assert current[1].patterns == ("*.md",)
assert current[1].max_bytes == 1024
def test_preprocessing_factory_forwards_only_evidence_pipeline_dependencies(monkeypatch):
@@ -127,7 +121,7 @@ def test_preprocessing_factory_forwards_only_evidence_pipeline_dependencies(monk
def __init__(self, **kwargs):
captured.update(kwargs)
monkeypatch.setattr("tht.corpus.pipeline.CorpusPipeline", FakePipeline)
monkeypatch.setattr("tht.evidence.preprocessing.CorpusPipeline", FakePipeline)
dependencies = {
"store": object(),
"sources": [object()],
@@ -176,18 +170,14 @@ class OrderedDelegate:
def test_search_facade_preserves_active_filtering_and_global_order(tmp_path):
cfg = _active_config(tmp_path)
legacy_delegate = OrderedDelegate()
facade_delegate = OrderedDelegate()
legacy = legacy_active_searcher(
cfg, legacy_delegate, workspace_id="workspace-a",
).search([1.0], top_n=2, kinds=["evidence", "memory"])
current = active_searcher(
cfg, facade_delegate, workspace_id="workspace-a",
).search([1.0], top_n=2, kinds=["evidence", "memory"])
assert [hit.id for hit in current] == [hit.id for hit in legacy] == ["higher", "lower"]
assert facade_delegate.calls == legacy_delegate.calls
assert [hit.id for hit in current] == ["higher", "lower"]
assert facade_delegate.calls == [([1.0], 2, ["memory"], None)]
def test_retrieval_entries_preserve_hit_order_and_existing_projection_shape():
@@ -225,14 +215,12 @@ def test_citation_facade_matches_active_corpus_resolution(tmp_path):
store = _canonical_store(tmp_path / "corpus", "evi-used")
materialized = tmp_path / "materialized"
legacy = resolve_evidence_file(
store, "evi-used", materialized_root=materialized,
)
current = resolve_citation(
store, "evi-used", materialized_root=materialized,
)
assert current == legacy
assert current.endswith(".md")
assert Path(current).read_text(encoding="utf-8") == "# evi-used\n"
assert resolve_citation(store, "missing", materialized_root=materialized) == ""
@@ -245,7 +233,7 @@ def test_session_projection_routes_corpus_citations_through_the_facade(tmp_path,
calls.append((store.root, evidence_id, materialized_root))
return f"/materialized/{evidence_id}.md"
monkeypatch.setattr("tht.evidence.resolve_citation", fake_resolve)
monkeypatch.setattr("tht.evidence.session.resolve_citation", fake_resolve)
linking = SchemaLinking(
question="q",
candidates=[Candidate(
@@ -257,7 +245,7 @@ def test_session_projection_routes_corpus_citations_through_the_facade(tmp_path,
)],
)
assert build_evidence_entries([], linking, evidence_root) == [{
assert project_session([], linking, evidence_root) == [{
"id": "evi-used",
"file": "/materialized/evi-used.md",
"esito": "usata",
@@ -299,10 +287,8 @@ def test_session_projection_facade_preserves_outcome_precedence_and_order(tmp_pa
)],
)
legacy = build_evidence_entries(decisions, linking, evidence_root)
current = project_session(decisions, linking, evidence_root)
assert current == legacy
assert [(row["id"], row["esito"], row["decision_seq"]) for row in current] == [
("used", "usata", 17),
("accepted", "accettata", 21),