free-claude-code/smoke/lib/skips.py
Alishahryar1 f3a7528d49
Some checks are pending
CI / checks (push) Waiting to run
Major refactor: API, providers, messaging, and Anthropic protocol
Consolidates the incremental refactor work into a single change set: modular web tools (api/web_tools), native Anthropic request building and SSE block policy, OpenAI conversion and error handling, provider transports and rate limiting, messaging handler and tree queue, safe logging, smoke tests, and broad test coverage.
2026-04-26 03:01:14 -07:00

65 lines
1.8 KiB
Python

"""Skip helpers for expected live-smoke environment gaps."""
from __future__ import annotations
import httpx
import pytest
from core.anthropic.stream_contracts import SSEEvent
UPSTREAM_UNAVAILABLE_MARKERS = (
"connection refused",
"connecterror",
"connect timeout",
"readtimeout",
"server disconnected",
"service unavailable",
"temporary failure",
"timed out",
"upstream provider",
)
def is_upstream_unavailable_text(text: str) -> bool:
normalized = text.lower()
return any(marker in normalized for marker in UPSTREAM_UNAVAILABLE_MARKERS)
def skip_upstream_unavailable(reason: str) -> None:
pytest.skip(f"upstream_unavailable: {reason}")
def fail_missing_env(reason: str) -> None:
pytest.fail(f"missing_env: {reason}")
def skip_if_upstream_unavailable_exception(exc: Exception) -> None:
if isinstance(
exc,
(
httpx.ConnectError,
httpx.ConnectTimeout,
httpx.ReadTimeout,
httpx.RemoteProtocolError,
httpx.ProxyError,
),
):
skip_upstream_unavailable(f"{type(exc).__name__}: {exc}")
if is_upstream_unavailable_text(f"{type(exc).__name__}: {exc}"):
skip_upstream_unavailable(f"{type(exc).__name__}: {exc}")
def skip_if_upstream_unavailable_events(events: list[SSEEvent]) -> None:
for event in events:
if getattr(event, "event", None) != "error":
continue
data = getattr(event, "data", {})
message = ""
if isinstance(data, dict):
error = data.get("error")
if isinstance(error, dict):
message = str(error.get("message", ""))
else:
message = str(data)
if is_upstream_unavailable_text(message):
skip_upstream_unavailable(message[:500])