Files
themiz/themiz-next/tests/test_next_prodolzhenie_koni.py

112 lines
5.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""--resume с фазы Кони: контекст фаз до Кони лежит в state.json прогона, продолжение не гонит карту, практику,
позицию и черновик заново (класс themiz-resume-cannot-continue-koni, 14.10.2026: падало «контекст не сохраняется»,
полный прогон ~35 мин)."""
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import core # noqa: E402
import faza_dopros # noqa: E402
import run # noqa: E402
from next_helpers import make_case # noqa: E402
FAKTY = [{"tema": "дата", "znachenie": "11.09.2026", "status": "ок", "fail": "01.md"}]
POZITSIYA = {"trebovaniya": [], "dovody": ["довод"]}
AKTY = [{"nomer": "88-1/2026", "data": "01.01.2026"}]
def argv(case, *extra):
return ["--case", str(case), "--track", "FAST", "--doc", "исковое заявление", *extra]
def wire(monkeypatch, calls, koni_ok, seen=None):
def priem(run_, ctx):
ctx["intake"] = sorted((run_.case / "00_intake").glob("*"))
def karta(run_, ctx):
calls.append("karta")
m = run_.dir / "map.md"
m.write_text("карта", encoding="utf-8")
ctx.update(fakty=FAKTY, voprosy=[], texts={"01.md": m}, map=m)
def praktika(run_, ctx):
calls.append("praktika")
ctx["akty"] = AKTY
def pozitsiya(run_, ctx):
calls.append("pozitsiya")
ctx.update(pozitsiya=POZITSIYA, nedostaet=["стоимость объекта"])
def chernovik(run_, ctx):
calls.append("chernovik")
draft = core.contract(run_.case, core.slug(run_.doc))["draft_md"]
draft.parent.mkdir(parents=True, exist_ok=True)
draft.write_text("# Иск\n\nТекст.\n", encoding="utf-8")
ctx["draft"], ctx["prilozheniya"] = draft, [{"tekst": "Копия", "fail": "00_intake/01.md", "stranicy": ""}]
def koni(run_, ctx):
calls.append("koni")
if seen is not None:
seen.update({k: ctx.get(k) for k in ("draft", "fakty", "pozitsiya", "akty", "nedostaet", "prilozheniya", "texts", "map")})
Path(ctx["draft"]).write_text("# Иск\n\nТекст после круга Кони.\n", encoding="utf-8")
if not koni_ok:
raise core.Stop("Кони: потолок кругов")
ctx["verdict"] = "ГОТОВ К ПОДАЧЕ"
for pid, _, _ in core.PHASES:
monkeypatch.setitem(run.PHASE_FUNCS, pid, lambda run_, ctx, pid=pid: calls.append(pid))
for pid, func in (("priem", priem), ("karta", karta), ("praktika", praktika), ("pozitsiya", pozitsiya),
("chernovik", chernovik), ("koni", koni)):
monkeypatch.setitem(run.PHASE_FUNCS, pid, func)
monkeypatch.setattr(faza_dopros, "sozdat", lambda *a, **k: None)
monkeypatch.setattr(faza_dopros, "vorota", lambda *a, **k: None)
monkeypatch.setattr(run, "_odobren", lambda run_, draft: False)
def last_state(case):
runs = sorted(p for p in (case / ".agent" / "next").iterdir() if p.is_dir())
return json.loads((runs[-1] / "state.json").read_text(encoding="utf-8"))
def test_resume_from_koni_restores_context_without_rerun(tmp_path, monkeypatch):
case = make_case(tmp_path / "cases" / "c" / "d")
wire(monkeypatch, [], koni_ok=False)
assert run.main(argv(case)) == 1
state = last_state(case)
assert state["resume"] == "koni" and state["koni_ctx"]["pozitsiya"] == POZITSIYA
second, seen = [], {}
wire(monkeypatch, second, koni_ok=True, seen=seen)
assert run.main(argv(case, "--resume")) in (0, 5)
assert not {"karta", "praktika", "pozitsiya", "chernovik"} & set(second)
assert "koni" in second and "sborka" in second
assert seen["fakty"] == FAKTY and seen["pozitsiya"] == POZITSIYA and seen["akty"] == AKTY
assert seen["nedostaet"] == ["стоимость объекта"] and isinstance(seen["draft"], Path)
assert isinstance(seen["map"], Path) and all(isinstance(p, Path) for p in seen["texts"].values())
assert "Текст после круга Кони." in seen["draft"].read_text(encoding="utf-8") # правки Кони не сброшены
def test_second_resume_from_koni_still_has_context(tmp_path, monkeypatch):
case = make_case(tmp_path / "cases" / "c" / "d")
wire(monkeypatch, [], koni_ok=False)
run.main(argv(case))
wire(monkeypatch, [], koni_ok=False)
assert run.main(argv(case, "--resume")) == 1
assert last_state(case)["koni_ctx"]["fakty"] == FAKTY
third = []
wire(monkeypatch, third, koni_ok=True)
assert run.main(argv(case, "--resume")) in (0, 5)
assert "koni" in third and "karta" not in third
def test_resume_from_koni_with_changed_intake_stops(tmp_path, monkeypatch):
case = make_case(tmp_path / "cases" / "c" / "d")
wire(monkeypatch, [], koni_ok=False)
run.main(argv(case))
(case / "00_intake" / "02.md").write_text("Новый материал\n", encoding="utf-8")
second = []
wire(monkeypatch, second, koni_ok=True)
assert run.main(argv(case, "--resume")) == 1
assert "koni" not in second