From 174509a60b6a361c0f247e49cd97615c6772bfcf Mon Sep 17 00:00:00 2001 From: anor Date: Wed, 18 Nov 2026 02:36:13 +1000 Subject: [PATCH] =?UTF-8?q?feat(=D0=A2=D0=A1=D0=9D):=20=D1=81=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D1=8F=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B0=D0=B7=D1=8B?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=20(T12)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tsn_stage(): нет базы, битая, есть и что внутри. 8 проверок. Co-Authored-By: Claude Code --- ext_status.py | 17 +++++++++++++++++ tests/test_ext_check_tsn.py | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/ext_status.py b/ext_status.py index 4f69e88..5942eff 100644 --- a/ext_status.py +++ b/ext_status.py @@ -393,3 +393,20 @@ def status_summary() -> str: segs.append("Только отслеживаются публикации (сами тексты НЕ загружены и недоступны " "для ответов): " + "; ".join(watch) + ".") return " ".join(segs) + +def tsn_stage() -> dict: + """Состояние ТСН для оператора и строки покрытия: есть ли база и что в ней.""" + try: + import tsn_ref + except Exception as e: # noqa: BLE001 + return {"status": "db_unavailable", "label": f"ТСН недоступна: {type(e).__name__}"} + problem = tsn_ref._problem_of() + if problem: + return {"status": problem, "label": tsn_ref._MESSAGES.get(problem, problem)} + vr = tsn_ref.verify_db(tsn_ref.db_path()) + if not vr.get("ok"): + return {"status": vr.get("problem", "db_unavailable"), "label": "база ТСН не прошла проверку"} + rel = tsn_ref.latest_release() or {} + return {"status": "served", "works": vr.get("works"), "values": vr.get("values"), + "built_at": rel.get("built_at"), + "label": f"ТСН-2001: {vr.get('works')} расценок, {vr.get('values')} коэффициентов"} diff --git a/tests/test_ext_check_tsn.py b/tests/test_ext_check_tsn.py index c89c6c3..e605071 100644 --- a/tests/test_ext_check_tsn.py +++ b/tests/test_ext_check_tsn.py @@ -76,3 +76,12 @@ def test_fresh_db_has_no_findings(monkeypatch): "x": {"extract_ok": True, "fetched_at": "2026-11-18T01:00:00Z"}}}}) findings, _ = ext_check.check_tsn_ref({}) assert findings == [] + + +def test_tsn_stage_served_when_db_ok(monkeypatch): + import ext_status + monkeypatch.setattr(tsn_ref, "_problem_of", lambda path=None: None) + monkeypatch.setattr(tsn_ref, "verify_db", lambda p: {"ok": True, "works": 10, "values": 20}) + monkeypatch.setattr(tsn_ref, "latest_release", lambda: {"built_at": "2026-11-18T00:00:00Z"}) + st = ext_status.tsn_stage() + assert st["status"] == "served" and "10" in st["label"]