From 70597599dc3bd535ad96bf752b6c208f4652edea Mon Sep 17 00:00:00 2001 From: anor Date: Wed, 18 Nov 2026 04:33:30 +1000 Subject: [PATCH] =?UTF-8?q?fix(=D0=A2=D0=A1=D0=9D):=20=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=BE=D0=B6=20=D0=B1=D0=B0=D0=B7=D1=8B=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D1=82=D1=80=D0=B5=D0=B2=D0=BE=D0=B6=D0=B8=D1=82,=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B0;=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D1=81=D0=B2?= =?UTF-8?q?=D0=B5=D0=B6=D0=B5=D1=81=D1=82=D0=B8=20=D0=B1=D0=B5=D1=80=D1=83?= =?UTF-8?q?=D1=82=20=D0=B4=D0=B0=D1=82=D1=83=20=D0=BF=D0=BE=20UTC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - check_tsn_ref: отсутствие базы при TSN_ENABLED=off — справка (info), при on — проблема; битый файл и чужая схема остаются проблемой всегда (контракт T12). - Проверки, ждавшие «нет важных находок», глушат сторожей НИАЦ и ТСН: в песочнице нет сети и базы, находки были про обстановку, а не про дедуп меток. - test_freshness_thresholds и test_summary_has_period_and_date: прибитая дата 18.07.2026 выдавалась за «сегодня» — с ноября проверки краснели; теперь дата берётся по UTC, как в коде. Co-Authored-By: Claude Code --- ext_check.py | 10 +++++++++- tests/test_ext_check.py | 5 +++++ tests/test_ext_check_tsn.py | 16 +++++++++++++++- tests/test_ext_status.py | 10 ++++++++-- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/ext_check.py b/ext_check.py index 7b60fc6..2ba91ea 100644 --- a/ext_check.py +++ b/ext_check.py @@ -396,7 +396,15 @@ def check_tsn_ref(seen: dict) -> tuple[list[dict], dict]: findings: list[dict] = [] problem = tsn_ref._problem_of() if problem: - findings.append({"source": "tsn_ref", "level": "problem", + # Пока функция выключена, отсутствие базы — не поломка (контракт T12); + # битый файл и чужая схема остаются проблемой всегда. + try: + import norm_base + enabled = norm_base.tsn_enabled() + except Exception: # noqa: BLE001 + enabled = False + level = "info" if problem == "db_unavailable" and not enabled else "problem" + findings.append({"source": "tsn_ref", "level": level, "message": f"база ТСН: {tsn_ref._MESSAGES.get(problem, problem)}"}) return findings, seen rel = tsn_ref.latest_release() diff --git a/tests/test_ext_check.py b/tests/test_ext_check.py index 3924133..69d341d 100644 --- a/tests/test_ext_check.py +++ b/tests/test_ext_check.py @@ -401,6 +401,8 @@ def test_notify_called_only_with_findings(_tmp, monkeypatch): monkeypatch.setattr(email_service, "send_operator_digest", lambda to, subj, html: calls.append((to, subj)) or True) _engine_synced(_tmp) # цены движка собраны → нет новостей + monkeypatch.setattr(ec, "check_niac_tsn", lambda seen, **kw: ([], seen)) + monkeypatch.setattr(ec, "check_tsn_ref", lambda seen: ([], seen)) ec.run_check(regions=[323], notify=True) assert calls == [] _snapshot(_tmp, "323/191/427", "b") # скачана новая форма → «собери цены» @@ -438,6 +440,9 @@ def test_ручной_прогон_без_важных_находок_засев # здесь важно поведение дедупа, а не они monkeypatch.setattr(ec, "check_engine_prices", lambda seen: ([], seen)) monkeypatch.setattr(ec, "check_fgis_ref", lambda seen: ([], seen)) + # НИАЦ в этой обстановке недоступен, а база ТСН не собрана — не про дедуп метки + monkeypatch.setattr(ec, "check_niac_tsn", lambda seen, **kw: ([], seen)) + monkeypatch.setattr(ec, "check_tsn_ref", lambda seen: ([], seen)) with es.update_state() as st: st["sources"]["fgis_split_form"] = {"323/191": {"period_id": 426}} rep = ec.run_check(regions=[323], notify=False) diff --git a/tests/test_ext_check_tsn.py b/tests/test_ext_check_tsn.py index e605071..f69414f 100644 --- a/tests/test_ext_check_tsn.py +++ b/tests/test_ext_check_tsn.py @@ -49,8 +49,22 @@ def test_discovery_failure_is_problem(monkeypatch): assert findings[0]["level"] == "problem" -def test_missing_db_is_problem(monkeypatch, tmp_path): +def test_missing_db_is_problem_only_when_tsn_enabled(monkeypatch): + """Контракт T12: нет базы при включённой ТСН — поломка; при выключенной — справка.""" + import norm_base monkeypatch.setattr(tsn_ref, "_problem_of", lambda path=None: "db_unavailable") + monkeypatch.setattr(norm_base, "tsn_enabled", lambda: True) + findings, _ = ext_check.check_tsn_ref({}) + assert findings[0]["level"] == "problem" + monkeypatch.setattr(norm_base, "tsn_enabled", lambda: False) + findings, _ = ext_check.check_tsn_ref({}) + assert findings[0]["level"] == "info" + + +def test_corrupt_db_is_problem_even_when_disabled(monkeypatch): + import norm_base + monkeypatch.setattr(tsn_ref, "_problem_of", lambda path=None: "db_corrupt") + monkeypatch.setattr(norm_base, "tsn_enabled", lambda: False) findings, _ = ext_check.check_tsn_ref({}) assert findings[0]["level"] == "problem" diff --git a/tests/test_ext_status.py b/tests/test_ext_status.py index 2a7c9de..fc2088d 100644 --- a/tests/test_ext_status.py +++ b/tests/test_ext_status.py @@ -28,9 +28,13 @@ def _meta(path: Path): def _seed_prices(zones): + """«Сегодня» берём тем же способом, что и код (UTC): прибитая дата 18.07.2026 + делала проверку красной спустя месяц после написания (инцидент 18.11.2026).""" + from datetime import datetime, timezone + now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") with es.update_state() as st: st["sources"]["fgis_split_form"] = { - k: {"period_id": p, "pulled_at": "2026-07-18T03:00:00Z"} for k, p in zones.items()} + k: {"period_id": p, "pulled_at": now} for k, p in zones.items()} def test_completeness_and_missing_regions(_tmp): @@ -124,7 +128,9 @@ def test_summary_has_period_and_date(_tmp): _seed_prices({"323/191": 426}) es.write_heartbeat() line = est.status_summary() - assert "2 квартал 2026 г." in line and "2026-07-18" in line + from datetime import datetime, timezone + today = datetime.now(timezone.utc).strftime("%Y-%m-%d") + assert "2 квартал 2026 г." in line and today in line # цены движка по зонам не собраны → расчёт недоступен везде, а не «по части регионов» assert "не собраны" in line.lower() and "недоступен" in line.lower(), line assert "части регионов" not in line.lower(), line