fix(harness): remediation difetti review — gate↔CLI, D15, D7/D6, D14, robustezza
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>
This commit is contained in:
@@ -163,7 +163,8 @@ def finalize_cmd(session_id: str = typer.Argument(...), config: Path = CONFIG_OP
|
||||
from tht.execute.warnings import plan_warnings, runtime_warnings, static_warnings
|
||||
from tht.report import extract_reviewer_notes, render_validation_report
|
||||
from tht.session.artifacts import build_evidence_entries
|
||||
from tht.decisions import list_decisions
|
||||
from tht.phase import cte_plan as effective_cte_plan
|
||||
from tht.phase import effective_decisions
|
||||
from tht.session.models import SchemaLinking
|
||||
from tht.sqlcheck import validate_sql
|
||||
|
||||
@@ -186,8 +187,9 @@ def finalize_cmd(session_id: str = typer.Argument(...), config: Path = CONFIG_OP
|
||||
raise typer.Exit(code=5)
|
||||
|
||||
# --- gate di ingresso ---
|
||||
# Vista effective (D15): un sql_approved/cte ritirato o stale post-rollback non conta.
|
||||
problems = session_problems(cfg, session_id)
|
||||
decisions = list_decisions(sdir)
|
||||
decisions = effective_decisions(sdir)
|
||||
sql_file = sdir / "sql_final.sql"
|
||||
if not sql_file.exists():
|
||||
problems.append("sql_final.sql assente")
|
||||
@@ -196,8 +198,10 @@ def finalize_cmd(session_id: str = typer.Argument(...), config: Path = CONFIG_OP
|
||||
"decisione sql_approved assente: la validazione semantica del reviewer "
|
||||
"e' obbligatoria prima del finalize"
|
||||
)
|
||||
cte_dir = sdir / "ctes"
|
||||
if cte_dir.is_dir():
|
||||
# I CTE richiesti sono quelli del PIANO effettivo, non i file glob su disco: un
|
||||
# ctes/*.sql orfano lasciato da un teardown incompleto non deve bloccare il finalize.
|
||||
plan = effective_cte_plan(sdir)
|
||||
if plan:
|
||||
try:
|
||||
tested = {r.name for r in load_cte_tests(sdir)}
|
||||
except CteError as e:
|
||||
@@ -206,9 +210,9 @@ def finalize_cmd(session_id: str = typer.Argument(...), config: Path = CONFIG_OP
|
||||
fg=typer.colors.RED, err=True,
|
||||
)
|
||||
raise typer.Exit(code=3)
|
||||
for cte_file in sorted(cte_dir.glob("*.sql")):
|
||||
if cte_file.stem not in tested:
|
||||
problems.append(f"CTE mai testato: {cte_file.stem}")
|
||||
for name in plan:
|
||||
if name not in tested:
|
||||
problems.append(f"CTE mai testato: {name}")
|
||||
if problems:
|
||||
typer.secho(f"Finalize rifiutato per {session_id}:", fg=typer.colors.YELLOW)
|
||||
for p in problems:
|
||||
@@ -258,9 +262,13 @@ def finalize_cmd(session_id: str = typer.Argument(...), config: Path = CONFIG_OP
|
||||
(sdir / "evidence.json").write_text(json.dumps(entries, ensure_ascii=False, indent=2))
|
||||
|
||||
# --- manifest + riepilogo ---
|
||||
from tht.session.store import MANIFEST
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from tht.session.store import MANIFEST, current_author
|
||||
|
||||
manifest.status = "finalized"
|
||||
manifest.updated_at = datetime.now(UTC)
|
||||
manifest.updated_by = current_author()
|
||||
manifest.to_yaml(sdir / MANIFEST)
|
||||
typer.secho(f"OK: sessione {session_id} finalizzata. Artefatti:", fg=typer.colors.GREEN)
|
||||
for name in ARTIFACT_FILES:
|
||||
|
||||
Reference in New Issue
Block a user