Files
ThothII/harness/tests/test_taskdoc.py
T
marcopanandClaude Fable 5 c4951e2aa5 chore: hygiene pass — ruff clean, docs storage-model truth, replay /me, failSession log
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>
2026-07-20 01:55:41 +02:00

76 lines
3.0 KiB
Python

from tht.taskdoc import generate_task_doc
def test_task_doc_includes_question_and_schema_scope(tmp_path):
s = tmp_path / "sess"
s.mkdir()
(s / "question.md").write_text("# Domanda\nQuanti pazienti?\n## Assunzioni\n- a")
(s / "schema_linking.json").write_text(
'{"question":"q","candidates":[{"kind":"table","name":"pazienti"}],"joins":[],"excluded":[],"open_questions":[]}'
)
doc = generate_task_doc(session_dir=s, phase=7)
assert "Quanti pazienti?" in doc.body
assert "pazienti" in doc.body
assert doc.byte_budget_ok is True
def test_task_doc_never_embeds_full_physical_yaml(tmp_path):
"""physical.yaml e' fatale per un 35B/<200k (~190k token). Mai incorporarlo."""
s = tmp_path / "sess"
s.mkdir()
(s / "question.md").write_text("q")
# un physical.yaml enorme fuori dalla sessione (come in ChironeWp3: artifacts/mschema/)
(s.parent / "physical.yaml").write_text("x: " + "y" * 800_000)
doc = generate_task_doc(session_dir=s, phase=7)
assert "physical.yaml" not in doc.body
assert len(doc.body) < 100_000 # bounded
def test_task_doc_byte_budget_enforced_on_normal_input(tmp_path):
s = tmp_path / "sess"
s.mkdir()
(s / "question.md").write_text("q")
doc = generate_task_doc(session_dir=s, phase=1)
assert doc.byte_budget_ok is True
def test_task_doc_byte_budget_violation_flagged(tmp_path):
"""Se un artefatto di sessione e' enorme (input perverso), byte_budget_ok diventa False."""
s = tmp_path / "sess"
s.mkdir()
(s / "question.md").write_text("q")
(s / "schema_linking.json").write_text("x: " + "y" * 400_000) # ~400KB -> over budget
doc = generate_task_doc(session_dir=s, phase=7)
assert doc.byte_budget_ok is False
def test_task_doc_carries_phase_header(tmp_path):
s = tmp_path / "sess"
s.mkdir()
(s / "question.md").write_text("q")
doc = generate_task_doc(session_dir=s, phase=4)
assert "fase 4" in doc.body.lower() or "fase 4" in doc.body
def test_task_doc_excludes_stale_decisions_post_rollback(tmp_path):
"""D15+D16: il task doc riflette lo stato effective, non quello stale.
Dopo rollback a F4, una sql_approved:7 stale non appare nel brief delle decisioni."""
from tht.decisions import append_decision
from tht.phase import current_phase
s = tmp_path / "sess"
s.mkdir()
(s / "question.md").write_text("q")
# simula: lavoro fino a F7, poi rollback a F4
append_decision(s, type="phase_approved", subject="phase:1")
append_decision(s, type="phase_approved", subject="phase:2")
append_decision(s, type="phase_approved", subject="phase:3")
append_decision(s, type="phase_approved", subject="phase:4")
append_decision(s, type="sql_approved", subject="phase:7", detail="SELECT 1")
append_decision(s, type="phase_reopened", subject="phase:4")
assert current_phase(s) == 4
doc = generate_task_doc(session_dir=s, phase=4)
# la decisione stale di fase 7 NON deve apparire nel brief
assert "sql_approved" not in doc.body
assert "phase:7" not in doc.body