fix: 凭据告警误报停止 + 清理注册遗留默认 token + 补还车前先看小程序状态

线上事故:部署后全站收到「微信凭据已过期」邮件,实际 token 没过期。

根因(实测复现)
- 只填 token_id、没有 access_token 的用户,请求只能用假签名(fake_signature),
  上游对假签名一律回 102001;而 alerts.check_user_credentials_alive 把 102001
  当成「凭据过期」,于是每个 token-only 用户都收到一封「已过期」。
  收件人是「alert_email 或用户自己的 email」→ 看起来就是给全站群发。

改动
1) check_user_credentials_alive 不再发信、也不再探测
- 没有 access_token 就无法区分「token 过期」和「假签名被拒」,探测纯属浪费上游配额;
  改为只统计并打印一条日志。真正的到期提醒交给 check_user_credentials(能解析 exp 的)

2) 注册遗留的默认 token
- 老库 users.token_id 列带 DEFAULT '1291378',注册没写该列的用户被灌了假凭据
- init_db 迁移:token_id='1291378' 且无 access_token → 置 NULL(本地库实测清掉 3 个)
- 告警三处(user/global/alive)统一用 _is_legacy_default_token 跳过这类值

3) 补还车前先看小程序状态(用户手动还过车的情况)
- 新增 _upstream_ride_active(user_id, order_id):查 /user/info 的 nonDealOrder
- _run_recovery 先问上游:上游说这单已结束 → 只做本地收尾(expired=1 + returned_at +
  取消计时器),不再发 /record/return(避免 204010 与重复还车)
- sweep / 重启补还车 / 巡检三条路径都带 order_id
- _close_local_reminder 改名 _close_rental_locally,reminder 单与「已在小程序还车」共用

4) 顺手修:test_history_30d 的 subprocess 在 Windows 用 GBK 读 UTF-8 输出报错

本地库实测
- 迁移清理 3 个默认 token;check_user_credentials_alive() 返回 0(14 个 token-only 用户只记日志)
- 全局凭据 10.9 天后到期 → 不触发三级告警(符合预期)

测试:161 pytest(新增凭据误报回归 2 条、上游优先补还车 2 条)+ 32 node 全绿
This commit is contained in:
zzy
2026-11-15 21:53:24 +08:00
parent 246f81137a
commit c1014ff912
6 changed files with 197 additions and 48 deletions
+1 -1
View File
@@ -106,7 +106,7 @@ sys.exit(1 if failures else 0)
def test_history_30d_contract():
r = subprocess.run([sys.executable, "-c", CHILD],
capture_output=True, text=True, timeout=180,
cwd=str(ROOT))
cwd=str(ROOT), encoding="utf-8", errors="replace")
out = (r.stdout or "") + (r.stderr or "")
print(out[-4000:] if len(out) > 4000 else out)
assert r.returncode == 0, "子进程契约验证失败(见上方输出)"