feat: implement memory and evidence administration with guided repairs
Publish documentation / publish (push) Successful in 1m27s
Publish documentation / publish (push) Successful in 1m27s
Add PostgreSQL-backed memory, editable evidence with source review and activation, and human-approved archive repairs across the harness, API, and UI. Include migrations, deployment support, regression coverage, and validation documentation. Refresh permissions from validated session roles so existing administrator logins can access newly deployed archive management features.
This commit is contained in:
@@ -6,7 +6,6 @@ import typer
|
||||
|
||||
from tht.cli import db_cmd, memory_cmd
|
||||
from tht.cli.lsh_cmd import _extract_lsh_values
|
||||
from tht.memory import MemoryRecord
|
||||
from tht.mschema.models import Annotations, ColumnPhysical, PhysicalSchema, TablePhysical
|
||||
from tht.ports.dwh import DistinctValues, DwhHealth
|
||||
|
||||
@@ -57,58 +56,25 @@ def test_lsh_extraction_honors_configured_limit(limit, truncated):
|
||||
assert [report.indexed for report in reports] == ([limit] if truncated else [])
|
||||
|
||||
|
||||
def test_memory_command_writes_through_factory_vector_store(monkeypatch):
|
||||
store = SimpleNamespace(existing_hashes=lambda *args: {}, upsert=lambda table, rows: 1)
|
||||
captured = []
|
||||
original_upsert = store.upsert
|
||||
store.upsert = lambda table, rows: captured.extend(rows) or original_upsert(table, rows)
|
||||
# Legacy server deployments wrote directly through the factory and intentionally
|
||||
# did not configure the workstation-only REST writer key.
|
||||
cfg = SimpleNamespace(profile="server", embeddings=object(), vector_write_rest=None)
|
||||
manifest = SimpleNamespace(id="s1")
|
||||
snapshot = SimpleNamespace(manifest=manifest, decisions=[], artifacts={})
|
||||
record = MemoryRecord(
|
||||
id="m1", ts=datetime(2026, 1, 1, tzinfo=UTC), session_id="s1",
|
||||
decision_seq=7, type="concept_clarified", subject="paziente attivo",
|
||||
detail="flag_attivo = TRUE", question_context="q",
|
||||
)
|
||||
monkeypatch.setattr(memory_cmd, "_load_config_or_exit", lambda path: cfg)
|
||||
monkeypatch.setattr(memory_cmd, "load_snapshot_or_exit", lambda cfg, session: snapshot)
|
||||
monkeypatch.setattr(memory_cmd, "registry_path", lambda cfg: None)
|
||||
monkeypatch.setattr("tht.adapters.factory.build_vector_store", lambda cfg, require_write: store)
|
||||
monkeypatch.setattr("tht.cli.vector_cmd.make_embedder",
|
||||
lambda cfg: SimpleNamespace(embed_documents=lambda texts: [[0.1]]))
|
||||
monkeypatch.setattr("tht.memory.promote_snapshot", lambda *args, **kwargs: None)
|
||||
monkeypatch.setattr("tht.memory.load_registry", lambda path: [record])
|
||||
memory_cmd.save_one_cmd(session="s1", decision=7, json_out=True)
|
||||
from tht.ports.vector import VectorWriteRecord
|
||||
assert len(captured) == 1 and isinstance(captured[0], VectorWriteRecord)
|
||||
|
||||
|
||||
def test_solved_index_writes_through_writer_only_factory_store(monkeypatch):
|
||||
writer_only_store = SimpleNamespace(
|
||||
capabilities=SimpleNamespace(search=False, upsert=True),
|
||||
existing_hashes=lambda *args: {},
|
||||
upsert=lambda table, rows: 1,
|
||||
)
|
||||
cfg = SimpleNamespace(embeddings=object(), vector_write_rest=object())
|
||||
manifest = SimpleNamespace(id="s1")
|
||||
snapshot = SimpleNamespace(manifest=manifest, decisions=[], artifacts={})
|
||||
def test_save_one_passes_the_selected_source_to_authoritative_service(monkeypatch, capsys):
|
||||
snapshot = object()
|
||||
calls = []
|
||||
|
||||
service = SimpleNamespace(close=lambda: None, promote=lambda source, seqs:
|
||||
calls.append((source, seqs)) or [{"indexed": False, "saved": True}])
|
||||
monkeypatch.setattr(memory_cmd, "_load_config_or_exit", lambda path: object())
|
||||
monkeypatch.setattr(memory_cmd, "load_snapshot_or_exit", lambda cfg, session: snapshot)
|
||||
monkeypatch.setattr(
|
||||
"tht.adapters.factory.build_vector_store",
|
||||
lambda cfg, require_write: calls.append(require_write) or writer_only_store,
|
||||
)
|
||||
monkeypatch.setattr("tht.cli.sql_cmd.promoted_tables_for", lambda *args: [])
|
||||
monkeypatch.setattr(
|
||||
"tht.memory.index_solved_question",
|
||||
lambda loaded, tables, *, store, embedder: int(
|
||||
loaded is snapshot and tables == [] and store is writer_only_store
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr("tht.cli.vector_cmd.make_embedder", lambda cfg: object())
|
||||
monkeypatch.setattr(memory_cmd, "memory_service", lambda cfg: service)
|
||||
memory_cmd.save_one_cmd(session="s1", decision=7, json_out=True)
|
||||
assert calls == [(snapshot, [7])]
|
||||
assert '"indexed": false' in capsys.readouterr().out
|
||||
|
||||
assert memory_cmd.index_solved_session(cfg, "s1") == 1
|
||||
assert calls == [True]
|
||||
|
||||
def test_solved_recovery_uses_authority_without_recreating_historical_content(monkeypatch):
|
||||
snapshot = object()
|
||||
calls = []
|
||||
service = SimpleNamespace(close=lambda: None, retry_solved=lambda source:
|
||||
calls.append(source) or {"indexed": True, "action": "upsert"})
|
||||
monkeypatch.setattr(memory_cmd, "load_snapshot_or_exit", lambda cfg, session: snapshot)
|
||||
monkeypatch.setattr(memory_cmd, "memory_service", lambda cfg: service)
|
||||
assert memory_cmd.index_solved_session(object(), "s1") == 1
|
||||
assert calls == [snapshot]
|
||||
|
||||
Reference in New Issue
Block a user