import json import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1])) import progress # noqa: E402 from next_helpers import make_case # noqa: E402 def _run(case: Path, name: str, state: dict) -> Path: run_dir = case / ".agent" / "next" / name run_dir.mkdir(parents=True) (run_dir / "state.json").write_text(json.dumps(state), encoding="utf-8") return run_dir def test_plan_counts_tasks_by_evidence(tmp_path): (tmp_path / "themiz-next" / "tests").mkdir(parents=True) (tmp_path / "themiz-next" / "tests" / "test_next_board.py").write_text("", encoding="utf-8") (tmp_path / "themiz-next" / "tests" / "test_next_dry_run.py").write_text("", encoding="utf-8") tasks = progress.plan(tmp_path) assert len(tasks) == 11 and tasks[0][1] is True and sum(ok for _, ok in tasks) == 1 case = make_case(tmp_path / "themiz-next" / "pilot" / "cases" / "c" / "d") _run(case, "20261007-100000", {"status": "ok", "track": "FAST"}) assert progress.plan(tmp_path)[8][1] is True and progress.plan(tmp_path)[9][1] is False def test_live_runs_skip_dead_and_finished(tmp_path): case = make_case(tmp_path / "cases" / "c" / "d") _run(case, "20261007-100000", {"status": "ok", "phases": {}}) _run(case, "20261007-110000", {"status": "running", "phases": {}}) # замок никто не держит assert progress.live(tmp_path) == [] def test_laws_counts_only_downloaded(tmp_path): assert progress.laws(tmp_path) == {"done": 0, "total": 0} db = tmp_path / ".agent" / "maintenance" / "background" / "queue.sqlite3" db.parent.mkdir(parents=True) import sqlite3 with sqlite3.connect(db) as conn: conn.execute("create table jobs (state text)") conn.executemany("insert into jobs values (?)", [("current",), ("updated",), ("blocked",), ("deferred",)]) assert progress.laws(tmp_path) == {"done": 2, "total": 4} def test_live_run_shows_case_progress(tmp_path): import core case = make_case(tmp_path / "cases" / "ivanov-ivan" / "delo") with core.Run(case, "FAST", "иск") as run: run.phase_start("priem") run.phase_ok("priem") [item] = progress.live(tmp_path) assert item == {"case": "delo", "done": 1, "total": 8, "pct": 12, "phase": "Карта"}