feat(движок): смета считается по ценовой зоне места стройки, а не по одной вшитой форме

Цены ресурсов берутся из разобранной формы ФГИС той зоны, что названа в запросе (engine_prices:
каталог по зонам и периодам, JSON). Без региона или при нескольких зонах — отказ без чисел и
уточнение; без квартала — последний период с пометкой; ресурсы без цены в форме зоны — список и
неполный итог. Панель показывает основу цен, пересчёт повторяет ту же зону. Чекер и панель
состояния вместо «выбери регион и примени» следят за собранностью цен по зонам. Версия 2026-09-14c.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADvViaqN9hgCWVNH3HVQ6r
This commit is contained in:
anor
2026-09-14 18:50:48 +10:00
co-authored by Claude Opus 5
parent 29361267c9
commit 4a1440426e
23 changed files with 1293 additions and 493 deletions
+34 -17
View File
@@ -52,27 +52,42 @@ def test_freshness_thresholds(_tmp, monkeypatch):
assert next(x for x in est.normative_status()["sources"] if x["key"] == "fgis_split_form")["freshness"] == "stale"
def test_engine_unset(_tmp):
_seed_prices({"323/191": 426})
def _engine_catalog(root, zones, snapshots):
import json
for k, sha in snapshots.items():
d = root / "snapshots" / "fgis" / "split_form" / k
d.mkdir(parents=True, exist_ok=True)
(d / "meta.json").write_text(json.dumps({"sha256": sha}), encoding="utf-8")
if zones is None:
return
d = root / "derived" / "engine_prices"
d.mkdir(parents=True, exist_ok=True)
(d / "catalog.json").write_text(json.dumps({"built_at": "2026-09-14T00:00:00Z", "zones": [
{"subject_id": int(k.split("/")[0]), "zone_id": int(k.split("/")[1]),
"period_id": int(k.split("/")[2]), "sha256": sha, "period_label": label, "file": ""}
for k, (sha, label) in zones.items()]}), encoding="utf-8")
def test_engine_prices_not_built(_tmp):
_engine_catalog(_tmp, None, {"323/191/427": "a"})
e = est.normative_status()["engine"]
assert e["status"] == "unset" and "дефолтного" in e["message"]
assert e["status"] == "unset" and "не собраны" in e["message"]
def test_engine_ok_and_behind_pulled(_tmp):
"""Движок применён на 425, а скачано 426 → флаг behind_pulled (скачано≠применено)."""
with es.update_state() as st:
st["sources"]["fgis_split_form"] = {"323/191": {"period_id": 426, "pulled_at": "2026-07-18T03:00:00Z"}}
st.setdefault("active", {})["fgis_split_form"] = {
"subject": 323, "zone": 191, "period_id": 425, "activated_at": "2026-07-01T00:00:00Z"}
def test_engine_prices_ready(_tmp):
_engine_catalog(_tmp, {"323/191/427": ("a", "3 квартал 2026"), "264/118/426": ("b", "2 квартал 2026"),
"264/118/427": ("c", "3 квартал 2026")},
{"323/191/427": "a", "264/118/426": "b", "264/118/427": "c"})
e = est.normative_status()["engine"]
assert e["status"] == "ok" and e["applied_period"] == "1 квартал 2026 г."
assert e["pulled_period_id"] == 426 and e["behind_pulled"] is True
assert e["status"] == "ok" and e["zones"] == 2 # две зоны, у одной два периода
assert e["periods"] == ["2 квартал 2026", "3 квартал 2026"]
def test_engine_unknown_legacy(_tmp):
with es.update_state() as st:
st.setdefault("active", {})["fgis_split_form"] = {"target": "/x.xlsx", "sha256": "ab"}
assert est.normative_status()["engine"]["status"] == "unknown"
def test_engine_prices_behind(_tmp):
_engine_catalog(_tmp, {"323/191/427": ("a", "3 квартал 2026")},
{"323/191/427": "перезалит", "264/118/427": "новая"})
e = est.normative_status()["engine"]
assert e["status"] == "behind" and e["behind"] == 2
def test_doc_sources_counts_and_modes(_tmp):
@@ -110,7 +125,9 @@ def test_summary_has_period_and_date(_tmp):
es.write_heartbeat()
line = est.status_summary()
assert "2 квартал 2026 г." in line and "2026-07-18" in line
assert "не применён" in line.lower() and "движ" in line.lower() # движок unset → оговорка в строке
# цены движка по зонам не собраны → расчёт недоступен везде, а не «по части регионов»
assert "не собраны" in line.lower() and "недоступен" in line.lower(), line
assert "части регионов" not in line.lower(), line
def test_summary_empty_when_no_data(_tmp):
@@ -247,7 +264,7 @@ def test_malformed_records_degrade_not_crash(_tmp):
s = est.normative_status() # НЕ падает (главное)
price = next(x for x in s["sources"] if x["key"] == "fgis_split_form")
assert price["freshness"] in ("unknown", "error") and price.get("zones", 0) == 0 # деградация
assert s["engine"]["status"] == "unknown" # active без zone → unknown, не KeyError
assert s["engine"]["status"] == "unset" # прежняя запись active движку больше не нужна, не KeyError
assert len(s["sources"]) == 7 # все источники на месте, не 500