feat(evidence): contribute to semantic stages (#42)

This commit is contained in:
2026-08-24 22:05:30 +02:00
parent 3420c57c8b
commit f1a9b567ba
17 changed files with 619 additions and 23 deletions
+28 -2
View File
@@ -5,7 +5,9 @@ from types import SimpleNamespace
from typer.testing import CliRunner
from tht.cli import app
from tht.config import load_config
from tht.config import load_config, workspace_id_for_config
from tht.evidence.corpus.models import CorpusManifest
from tht.evidence.corpus.store import CorpusStore
from tht.jobs.dwh_pipeline import DwhPreprocessPipeline, config_dwh_binding
from tht.mschema.models import ColumnPhysical, PhysicalSchema, TablePhysical
from tht.ports.vector import VectorReadUnavailable
@@ -75,6 +77,19 @@ def _workspace(tmp_path, with_session=None):
],
lsh_filenames=("s_lsh.pkl", "s_minhashes.pkl", "s_meta.json"),
).run()
corpus = CorpusStore(tmp_path / "corpus")
generation = "gen:" + "a" * 32
active = corpus.stage(
CorpusManifest(
vector_generation=generation,
embedding_model="test",
embedding_dimensions=1,
metadata={"workspace_id": workspace_id_for_config(load_config(cfg), cfg)},
),
{},
generation=generation,
)
corpus.publish(active)
if with_session:
sdir = tmp_path / "sessions" / with_session
sdir.mkdir(parents=True)
@@ -111,7 +126,7 @@ def test_pack_single_embed_and_sections(tmp_path, monkeypatch):
_patch(monkeypatch, emb, searcher)
res = CliRunner().invoke(app, ["search", "pack", "quanti pazienti", "-c", str(cfg)])
assert res.exit_code == 0, res.output
assert emb.calls == 1 # UN solo embedding per le tre ricerche
assert emb.calls == 2 # schema/memory share one; Evidence embeds its own deterministic text
assert [call["kinds"] for call in searcher.calls] == [
["schema_table", "schema_column"],
["solved_question"],
@@ -167,3 +182,14 @@ def test_pack_degrades_gracefully(tmp_path, monkeypatch):
data = json.loads(res.output[res.output.index("{"):])
assert data["tables"] == [] and data["evidence"] == [] and data["solved"] == []
assert any("retrieval non disponibile" in w for w in data["warnings"])
def test_pack_refuses_to_treat_an_unavailable_evidence_corpus_as_no_matches(tmp_path, monkeypatch):
cfg = _workspace(tmp_path)
(tmp_path / "corpus" / "ACTIVE").unlink()
_patch(monkeypatch, _FakeEmbedder(), _FakeSearcher())
result = CliRunner().invoke(app, ["search", "pack", "q", "-c", str(cfg)])
assert result.exit_code == 1
assert "Evidence non disponibile" in result.output