fix: skip unsupported image profile refreshes

This commit is contained in:
2026-07-10 07:34:01 +08:00
parent c79e85e635
commit 135dbc845a
4 changed files with 55 additions and 9 deletions
+29
View File
@@ -139,6 +139,35 @@ class CodexRetryGatewayTUITests(unittest.TestCase):
self.assertEqual(payload, {})
self.assertEqual(error, "")
def test_dashboard_skips_image_profiles_endpoint_when_status_lacks_capability(self) -> None:
mod = load_module()
calls: list[str] = []
def fetch(url: str, timeout: int, access_key: str = "", *, allow_not_found: bool = False):
calls.append(url)
if url.endswith("/api/status"):
return {"config": {"profile_name": "legacy"}, "state": {}, "paths": {}}, ""
if "/api/requests" in url:
return {"entries": []}, ""
if "/api/logs" in url:
return {"entries": []}, ""
if "/api/profiles" in url:
return {"profiles": []}, ""
self.fail(f"unexpected endpoint {url}")
with mock.patch.object(mod, "fetch_optional_payload", side_effect=fetch):
snapshot = mod.fetch_dashboard_snapshot("http://127.0.0.1:4610", "", 5)
self.assertEqual(snapshot["image_profiles"], [])
self.assertEqual(snapshot["status_error"], "")
self.assertFalse(any("/api/image-profiles" in url for url in calls))
def test_gateway_image_profiles_capability_uses_status_field_presence(self) -> None:
mod = load_module()
self.assertFalse(mod.gateway_supports_image_profiles({"config": {"profile_name": "legacy"}}))
self.assertTrue(mod.gateway_supports_image_profiles({"config": {"image_profile_name": ""}}))
self.assertTrue(mod.gateway_supports_image_profiles({"paths": {"image_profiles_dir": "/tmp/profiles"}}))
def test_request_usage_summary_shows_cached_ratio(self) -> None:
mod = load_module()
row = {