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>
48 lines
2.0 KiB
Python
48 lines
2.0 KiB
Python
"""D15 (§4.8): effective_decisions must stale-filter name-subject decisions too.
|
|
|
|
The reference bug (CRITICA #1): effective_decisions only filtered decisions whose
|
|
subject was "phase:N". cte_approved uses the CTE *name* as subject, so a cte_approved
|
|
from F6 stayed "effective" after a rollback to F4 -- a stale decision that still counted
|
|
(the exact invariant §4.8 forbids). The fix records the emitting phase on each
|
|
DecisionRecord (high-water-mark) and effective_decisions falls back to it when the
|
|
subject is not "phase:N".
|
|
"""
|
|
from pathlib import Path
|
|
|
|
from tht.decisions import append_decision
|
|
from tht.phase import approved_ctes, current_phase, effective_decisions
|
|
|
|
|
|
def _walk_to_phase(session: Path, target: int) -> None:
|
|
"""Approva in ordine fino a raggiungere `target` (il fold avanza solo su n==cur)."""
|
|
while current_phase(session) < target:
|
|
append_decision(session, type="phase_approved", subject=f"phase:{current_phase(session)}")
|
|
|
|
|
|
def test_cte_approved_name_subject_is_stale_after_reopen(tmp_path):
|
|
s = tmp_path / "sess"
|
|
s.mkdir()
|
|
_walk_to_phase(s, 6) # ora in F6
|
|
# piano CTE + approvazione di un CTE (subject = NOME del CTE, non "phase:6")
|
|
(s / "cte_plan.json").write_text('["pazienti_base"]')
|
|
append_decision(s, type="cte_approved", subject="pazienti_base")
|
|
assert "pazienti_base" in approved_ctes(s)
|
|
assert current_phase(s) == 6
|
|
|
|
# rollback a F4: la cte_approved di F6 deve diventare stale (esclusa dalla vista)
|
|
append_decision(s, type="phase_reopened", subject="phase:4")
|
|
assert current_phase(s) == 4
|
|
assert "pazienti_base" not in approved_ctes(s), (
|
|
"cte_approved (subject a nome) di F6 NON deve contare dopo un reopen a F4"
|
|
)
|
|
types = [d.type for d in effective_decisions(s)]
|
|
assert "cte_approved" not in types
|
|
|
|
|
|
def test_phase_field_recorded_on_append(tmp_path):
|
|
s = tmp_path / "sess"
|
|
s.mkdir()
|
|
_walk_to_phase(s, 4)
|
|
rec = append_decision(s, type="value_grounded", subject="ablazione")
|
|
assert rec.phase == 4 # emitting phase recorded for the high-water-mark filter
|