Audit findings 6.1-6.4 + the audit's remediation plan itself (docs/superpowers/plans/2026-07-20-full-audit-remediation-plan.md). - ruff: 34 → 0 (unused imports/f-strings auto-fixed; E702 semicolon lines split in test files; one unused local dropped). Suite still 819 green. - CLAUDE.md + PROJECT_STATE.md no longer claim "no database / settings in settings.json": the harness selects filesystem OR PostgreSQL session storage (repository.py, server mode), and settings flow through harness preferences with the JSON file as fallback only. - tools/replay: stub /me (SPA boot was parsing the SPA's own HTML as JSON) and /runtime/prewarm. - failSession best-effort persistence now logs its failure server-side instead of vanishing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
85 lines
3.6 KiB
Python
85 lines
3.6 KiB
Python
from tht.teardown import teardown_to_phase
|
|
|
|
|
|
def test_teardown_to_phase_4_deletes_phase5plus_artifacts(tmp_path):
|
|
s = tmp_path / "sess"
|
|
s.mkdir()
|
|
(s / "schema_linking.json").write_text("{}") # F4 artifact
|
|
(s / "cte_plan.json").write_text("[]") # F6 artifact
|
|
(s / "ctes").mkdir()
|
|
(s / "ctes" / "x.sql").write_text("SELECT 1") # F6 artifact
|
|
(s / "sql_final.sql").write_text("SELECT 1") # F7 artifact
|
|
report = teardown_to_phase(s, target_phase=4)
|
|
assert (s / "schema_linking.json").exists() # F4 preserved (target is 4)
|
|
assert not (s / "cte_plan.json").exists() # F6 deleted (>4)
|
|
assert not (s / "ctes").exists() # F6 dir deleted
|
|
assert not (s / "sql_final.sql").exists() # F7 deleted
|
|
assert "cte_plan.json" in report.deleted_files
|
|
assert "sql_final.sql" in report.deleted_files
|
|
|
|
|
|
def test_teardown_to_phase_1_deletes_everything(tmp_path):
|
|
"""Rollback a F1 cancella tutti gli artefatti (tutte le fasi > 1)."""
|
|
s = tmp_path / "sess"
|
|
s.mkdir()
|
|
(s / "question.md").write_text("q") # F3 artifact
|
|
(s / "schema_linking.json").write_text("{}") # F4 artifact
|
|
(s / "cte_plan.json").write_text("[]") # F6 artifact
|
|
(s / "ctes").mkdir()
|
|
(s / "ctes" / "a.sql").write_text("SELECT 1")
|
|
(s / "sql_final.sql").write_text("SELECT 1") # F7 artifact
|
|
report = teardown_to_phase(s, target_phase=1)
|
|
assert not (s / "question.md").exists()
|
|
assert not (s / "schema_linking.json").exists()
|
|
assert not (s / "cte_plan.json").exists()
|
|
assert not (s / "ctes").exists()
|
|
assert not (s / "sql_final.sql").exists()
|
|
assert len(report.deleted_files) >= 4
|
|
|
|
|
|
def test_teardown_to_phase_7_preserves_phase6_artifacts(tmp_path):
|
|
"""Rollback a F7 preserva gli artefatti delle fasi <= 7."""
|
|
s = tmp_path / "sess"
|
|
s.mkdir()
|
|
(s / "schema_linking.json").write_text("{}") # F4 artifact
|
|
(s / "cte_plan.json").write_text("[]") # F6 artifact
|
|
(s / "ctes").mkdir()
|
|
(s / "ctes" / "a.sql").write_text("SELECT 1") # F6 artifact
|
|
(s / "sql_final.sql").write_text("SELECT 1") # F7 artifact
|
|
report = teardown_to_phase(s, target_phase=7)
|
|
assert (s / "schema_linking.json").exists()
|
|
assert (s / "cte_plan.json").exists()
|
|
assert (s / "ctes").exists()
|
|
assert (s / "sql_final.sql").exists() # F7 preserved (target is 7)
|
|
assert report.deleted_files == [] # nothing > 7 has artifacts
|
|
|
|
|
|
def test_teardown_to_phase_on_empty_session_is_noop(tmp_path):
|
|
s = tmp_path / "sess"
|
|
s.mkdir()
|
|
report = teardown_to_phase(s, target_phase=4)
|
|
assert report.deleted_files == []
|
|
|
|
|
|
def test_teardown_to_phase_nonexistent_artifacts_no_error(tmp_path):
|
|
"""Se gli artefatti non esistono (sessione nuova), teardown non fallisce."""
|
|
s = tmp_path / "sess"
|
|
s.mkdir()
|
|
report = teardown_to_phase(s, target_phase=1)
|
|
assert report.deleted_files == []
|
|
|
|
|
|
def test_teardown_deletes_orphaned_cte_files_not_in_current_plan(tmp_path):
|
|
"""Il bug degli orfani CTE: dopo un re-derive con piano diverso, i vecchi .sql
|
|
non piu' nel piano restano su disco e bloccano finalize. teardown li pulisce."""
|
|
s = tmp_path / "sess"
|
|
s.mkdir()
|
|
(s / "ctes").mkdir()
|
|
(s / "ctes" / "old_cte.sql").write_text("SELECT 1") # orphan
|
|
(s / "ctes" / "another.sql").write_text("SELECT 2") # orphan
|
|
report = teardown_to_phase(s, target_phase=5) # F6 has ctes/ as artifact
|
|
assert not (s / "ctes").exists()
|
|
# i nomi dei file orfani sono registrati
|
|
assert "old_cte.sql" in report.deleted_files
|
|
assert "another.sql" in report.deleted_files
|