fix: 修复监控链路 api_key 未解码致 401、瞬时 401 误禁、前端表单多处问题 - monitor: 调度链路对 base64 存储的 api_key 解码(此前直接发送编码串导致所有账号 401) - fetcher: 401/403 先按重试次数确认再判定禁用,避免瞬时 401 误杀;POST 自动补 Content-Type: application/json - ui: val/err 兼容 # 前缀(保存无反应的根因);平台编辑回填 headers 反转义;监控页补添加账号入口 - test: 新增 monitor 解码回归测试,共 51 个用例

This commit is contained in:
2026-08-05 00:21:31 +08:00
parent 17d2496a65
commit edf19e121b
7 changed files with 132 additions and 13 deletions
+15 -3
View File
@@ -105,7 +105,7 @@ class TestFetchBalance:
assert result.ok
assert captured["data"] == '{"api_key": "sk-2"}'
def test_401_is_auth_error_no_retry(self, monkeypatch):
def test_401_retries_then_auth_error(self, monkeypatch):
calls = []
def fake_get(url, headers=None, timeout=10):
@@ -113,9 +113,21 @@ class TestFetchBalance:
return FakeResponse(401, text="unauthorized")
monkeypatch.setattr("requests.get", fake_get)
result = fetch_balance(PLATFORM_GET, "bad", retry_count=3, timeout=10)
result = fetch_balance(PLATFORM_GET, "bad", retry_count=2, timeout=10)
assert not result.ok and result.auth_error
assert len(calls) == 1
assert len(calls) == 3 # 401 也按重试次数确认后再判定
def test_transient_401_then_success(self, monkeypatch):
calls = []
def fake_get(url, headers=None, timeout=10):
calls.append(1)
return FakeResponse(401) if len(calls) == 1 else FakeResponse(200, json_data={"data": {"balance": 6.6}})
monkeypatch.setattr("requests.get", fake_get)
result = fetch_balance(PLATFORM_GET, "k", retry_count=2, timeout=10)
assert result.ok and result.balance == 6.6
assert len(calls) == 2 # 瞬时 401 重试后成功,不误判禁用
def test_5xx_retries_then_success(self, monkeypatch):
calls = []