Skip to content

The agent that grows with you

test(agent): fold body-carried status tests into test_error_classifier.py (#121270)

kshitijk4poor6da360ba1664
diff --git a/tests/agent/test_error_classifier.py b/tests/agent/test_error_classifier.py
index 5c9eede798b..4d0eb70407b 100644
--- a/tests/agent/test_error_classifier.py
+++ b/tests/agent/test_error_classifier.py
@@ -2114,6 +2114,24 @@ class TestAuthErrorNamesOffRouteEndpoint:
assert result.message == "API keys are not supported by this endpoint.", base_url
+class TestBodyCarriedStatus:
+ """An in-stream SSE error object's numeric ``code`` classifies like the equivalent HTTP
+ response (#121270)."""
+
+ def test_top_level_code_and_status_keys_also_count(self):
+ assert _extract_status_code(MockAPIError("x", body={"code": 503})) == 503
+ assert _extract_status_code(MockAPIError("x", body={"error": {"http_status": 502}})) == 502
+
+ def test_403_ban_is_auth_not_transient_retry(self):
+ body = {"error": {"code": 403, "message": "Your account has been banned by the upstream provider",
+ "metadata": {"provider_name": "acme"}}}
+ result = classify_api_error(MockAPIError("Error code: 403", body=body), provider="custom")
+ assert result.status_code == 403
+ assert result.reason == FailoverReason.auth
+ assert result.retryable is False
+ assert result.should_fallback is True
+
+
class TestStreamingRenderFormatError:
"""Status-less Jinja render failures (LM Studio / llama.cpp) fail over; see #62662."""
diff --git a/tests/agent/test_error_classifier_body_status.py b/tests/agent/test_error_classifier_body_status.py
deleted file mode 100644
index 55331d4de50..00000000000
--- a/tests/agent/test_error_classifier_body_status.py
+++ /dev/null
@@ -1,51 +0,0 @@
-"""Body-carried HTTP status extraction — an in-stream SSE error object's numeric
-``code`` must classify like the equivalent HTTP response (#121270)."""
-
-from types import SimpleNamespace
-
-from agent.error_classifier import (
- FailoverReason,
- classify_api_error,
- _extract_status_code,
-)
-
-
-class MockAPIError(Exception):
- """Simulates a status-less OpenAI SDK APIError raised mid-stream."""
-
- def __init__(self, message, status_code=None, body=None, headers=None):
- super().__init__(message)
- self.status_code = status_code
- self.body = body or {}
- self.response = SimpleNamespace(headers=headers or {})
-
-
-_BAN_BODY = {
- "error": {
- "code": 403,
- "message": "Your account has been banned by the upstream provider",
- "metadata": {"provider_name": "acme"},
- }
-}
-
-
-class TestBodyCarriedStatusExtraction:
- def test_top_level_code_and_status_keys_also_count(self):
- assert _extract_status_code(MockAPIError("x", body={"code": 503})) == 503
- assert (
- _extract_status_code(
- MockAPIError("x", body={"error": {"http_status": 502}})
- )
- == 502
- )
-
-
-class TestInStreamErrorClassification:
- def test_403_ban_is_auth_not_transient_retry(self):
- result = classify_api_error(
- MockAPIError("Error code: 403", body=_BAN_BODY), provider="custom"
- )
- assert result.status_code == 403
- assert result.reason == FailoverReason.auth
- assert result.retryable is False
- assert result.should_fallback is True