Implementazione del piano di remediation progressiva sui difetti emersi dall'analisi dell'harness. Tutto verificato: 214 test Python (incl. L0 su Postgres reale), 14 test JS del gate, ruff pulito. Blocco 1 (CRITICA, integrazione gate↔CLI): - phase advance: gate usa --auto + exit 6; reviewer_confirm kind:phase fa advance esplicito che applica i prerequisiti (prima non avanzava per le fasi a conferma umana). - cte plan riceve i --name dal gate (param names); set-question con id posizionale; skill `tht search find`; nuovo comando `tht memory save-one` con dedup hash client-side in save_one_memory. Blocco 2 (D15, stato post-rollback): - campo `phase` su DecisionRecord + effective_decisions phase-aware per i subject "a nome" (cte_approved ecc.); _compute_promotions e finalize sulla vista effective; finalize confronta col piano CTE effettivo, non glob; `decision add --retracts` + comando `decision retract`. Blocco 3 (D7 read-only + D6 manifest): - assert_read_only su tutti e quattro i codepath (direct + REST); - manifest author/summary/updated_at/updated_by/schema_version popolati + helper touch_manifest sulle mutazioni. Blocco 4-5 (D14a/D14b): - decision_min_phase data-driven via `emits:` in workflow.yaml; - formula evidence: status auto, search_formulas, gruppo CLI `tht formula`, `search find --kind formula`, load_evidence_dir salta i .sql.md. Blocco 6 (robustezza): - taskdoc slice promoted_tables + bound enforced; report escaping/bound + rsplit note; filtro kind reader REST/direct; conteggio upserted robusto; guard REST run_query non-list; LSH disallineato -> LshIndexError. Blocco 7 (pulizia): - dead code gate e KIND_TO_TABLE morto rimossi; doc Postgres-only (README + connection.py). Blocco 0 (parziale): test di compatibilità firma gate↔CLI (tests/integration). Rinviati: fake-Pi runtime completo, artifact-gate da disco (#23), parità eligibility REST/direct (#28), unificazione reserved-labels (#30), memory_rejected da deselezione (#33). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
"""Blocco 6: robustness fixes -- taskdoc slice/bound, report escaping, upsert count."""
|
|
from tht.report import _markdown_table, extract_reviewer_notes
|
|
from tht.taskdoc import generate_task_doc
|
|
|
|
|
|
def test_taskdoc_slices_to_promoted_tables(tmp_path):
|
|
s = tmp_path / "sess"
|
|
s.mkdir()
|
|
(s / "question.md").write_text("q")
|
|
(s / "schema_linking.json").write_text(
|
|
'{"question":"q","candidates":['
|
|
'{"kind":"table","name":"pazienti","decision":"promoted"},'
|
|
'{"kind":"table","name":"ricoveri","decision":"promoted"}],'
|
|
'"joins":[],"excluded":[],"open_questions":[]}'
|
|
)
|
|
doc = generate_task_doc(session_dir=s, phase=4, promoted_tables=["pazienti"])
|
|
assert "pazienti" in doc.body
|
|
assert "ricoveri" not in doc.body # sliced out
|
|
|
|
|
|
def test_taskdoc_truncates_over_budget(tmp_path):
|
|
s = tmp_path / "sess"
|
|
s.mkdir()
|
|
(s / "question.md").write_text("# Domanda\n" + "x" * 200_000)
|
|
doc = generate_task_doc(session_dir=s, phase=1)
|
|
assert doc.byte_budget_ok is False
|
|
assert len(doc.body.encode()) <= 80_000
|
|
assert "troncato" in doc.body
|
|
|
|
|
|
def test_markdown_table_escapes_pipes_and_newlines():
|
|
table = _markdown_table(["c"], [("a|b\nc",)])
|
|
# the cell must not introduce a raw pipe or newline that breaks the row
|
|
body_line = table.splitlines()[2]
|
|
assert "\\|" in body_line
|
|
assert "\n" not in body_line
|
|
|
|
|
|
def test_extract_reviewer_notes_uses_last_heading():
|
|
report = (
|
|
"## Note del reviewer\nnella cella di dati appariva questo testo\n"
|
|
"## Note del reviewer\nnota vera del reviewer"
|
|
)
|
|
assert extract_reviewer_notes(report) == "nota vera del reviewer"
|
|
|
|
|
|
def test_upsert_count_handles_postgrest_list_wrapping():
|
|
from unittest.mock import MagicMock
|
|
|
|
from tht.vectorstore.rest_client import VectorRestClient
|
|
|
|
client = VectorRestClient.__new__(VectorRestClient)
|
|
client._call = MagicMock(return_value=[{"upserted": 7}]) # list-wrapped scalar
|
|
assert client.upsert_records("memory", [{}, {}]) == 7
|