From 55c50be90d7e31b0a09b6bc099b2fb96766442f6 Mon Sep 17 00:00:00 2001 From: anor Date: Wed, 28 Oct 2026 15:35:57 +1000 Subject: [PATCH] =?UTF-8?q?fix(=D0=BF=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5):=20=D1=81=D1=82=D0=BE=D1=80=D0=BE=D0=B6=20?= =?UTF-8?q?=D0=BA=D1=80=D0=B0=D1=81=D0=BD=D0=B5=D0=B5=D1=82,=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=B3=D0=B4=D0=B0=20=D0=BF=D0=BB=D0=B0=D1=82=D1=91=D0=B6?= =?UTF-8?q?=20=D0=B2=D0=B8=D1=81=D0=B8=D1=82=20=D0=BE=D1=82=D0=BA=D1=80?= =?UTF-8?q?=D1=8B=D1=82=D1=8B=D0=BC=20=D0=B4=D0=BE=D0=BB=D1=8C=D1=88=D0=B5?= =?UTF-8?q?=20=D1=82=D1=80=D1=91=D1=85=20=D1=81=D1=80=D0=BE=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B6=D0=B8=D0=B7=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpStateExt с ошибкой (код 4 при совпадении тестового и боевого номера) держал строку pending вечно при живой сверке, и сторож молчал, а человек мог уже заплатить. Co-Authored-By: Claude Opus 5.5 --- health_checks.py | 11 +++++++++++ tests/test_topup_health.py | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/health_checks.py b/health_checks.py index fc6d8e0..82e187f 100644 --- a/health_checks.py +++ b/health_checks.py @@ -911,6 +911,9 @@ def exit_code(results: list) -> int: TOPUP_PENDING_S = 30 * 60 TOPUP_TICK_S = 20 * 60 +# Three payment lifetimes (ExpirationDate 2 h): by then reconcile must have closed the row — +# still open means OpStateExt keeps failing for it (e.g. code 4) and the money may be stuck. +TOPUP_STUCK_S = 6 * 3600 NPD_WARN_RUB, NPD_ALARM_RUB = 1_900_000, 2_300_000 _MSK_S = 3 * 3600 # год НПД — по московскому календарю @@ -932,6 +935,10 @@ def check_topups() -> Check: old_open = conn.execute( "SELECT COUNT(*) FROM topups WHERE status IN ('new','pending') AND ts < ?", (time.time() - TOPUP_PENDING_S,)).fetchone()[0] + stuck = conn.execute( + "SELECT COUNT(*) FROM topups WHERE status IN ('new','pending') " + "AND provider_id IS NOT NULL AND ts < ?", + (time.time() - TOPUP_STUCK_S,)).fetchone()[0] last = conn.execute("SELECT provider_id FROM topups WHERE provider_id IS NOT NULL " "ORDER BY id DESC LIMIT 1").fetchone() if unapplied: @@ -942,6 +949,10 @@ def check_topups() -> Check: return Check("topups", False, f"сверка пополнений стоит: неоплаченных старше " f"{TOPUP_PENDING_S // 60} минут {old_open}, последний " f"тик сверки {int((time.time() - tick) // 60)} мин назад") + if stuck: + return Check("topups", False, f"не решена судьба платежей старше " + f"{TOPUP_STUCK_S // 3600} часов: {stuck} — платёжка не " + f"отдаёт их состояние, проверьте в её кабинете") import topup prov = topup.provider() if last and prov.creds(): diff --git a/tests/test_topup_health.py b/tests/test_topup_health.py index 66ed477..9e73851 100644 --- a/tests/test_topup_health.py +++ b/tests/test_topup_health.py @@ -80,6 +80,20 @@ def test_check_topups_red_on_stale_tick_with_old_pending(env): assert hc.check_topups().ok +def test_check_topups_red_on_payment_stuck_open_with_live_reconcile(env): + """Платёж с номером у платёжки висит открытым дольше трёх сроков жизни при живой + сверке — красная: сверка не может решить его судьбу (OpStateExt отвечает ошибкой, + например кодом 4 при совпадении тестового и боевого номера), а человек, возможно, + заплатил. Брошенная корзина младше этого — норма. Порча: не смотреть на возраст.""" + db, hc, dd, prov = env + db.set_app_setting("topup_reconcile_ts", str(time.time() - 60)) + _topup(db, "pending", age=2 * 3600) + assert hc.check_topups().ok + _topup(db, "pending", age=7 * 3600) + c = hc.check_topups() + assert not c.ok and c.level == "fail" and "не решена" in c.detail + + def test_check_topups_red_when_provider_status_down(env): """Платёжка не отвечает на запрос состояния — красная. Порча: не пробовать запрос.""" db, hc, dd, prov = env