Spaces:
Sleeping
Sleeping
File size: 1,144 Bytes
14184e3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | from app.agents.cerebras_errors import CerebrasErrorKind, CerebrasError, classify_error
def test_rate_limit_classification():
exc = Exception("Rate limit exceeded. Retry after 60 seconds.")
err = classify_error(exc)
assert err.kind == CerebrasErrorKind.RATE_LIMITED
assert err.retry_after_seconds == 60
def test_model_unsupported_classification():
exc = Exception("model_not_found: gemma-4-31b is not available")
err = classify_error(exc)
assert err.kind == CerebrasErrorKind.MODEL_UNSUPPORTED
def test_generic_classification():
exc = ValueError("something unexpected")
err = classify_error(exc)
assert err.kind == CerebrasErrorKind.GENERIC
def test_auth_classification():
exc = Exception("401 unauthorized: invalid auth key")
err = classify_error(exc)
assert err.kind == CerebrasErrorKind.AUTH_LOST
def test_friendly_payload():
err = CerebrasError(
kind=CerebrasErrorKind.RATE_LIMITED, message="slow down", retry_after_seconds=30
)
payload = err.to_frontend_payload()
assert payload["kind"] == "rate_limited"
assert payload["retry_after_seconds"] == 30
|