Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,587 changes: 1,023 additions & 564 deletions .github/workflows/qualification.yml

Large diffs are not rendered by default.

53 changes: 43 additions & 10 deletions compat/downstream/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ real-world consumers. This manifest defines the test matrix:

```
compat/downstream/
manifest.toml # Machine-readable package inventory
README.md # This file
manifest.toml # Machine-readable package inventory
README.md # This file
status.toml # Current qualification status
behavioral_fixtures/ # Package-specific behavioral test fixtures
test_httpx_contract_behavior.py
test_respx_behavior.py
test_pytest_httpx_behavior.py
test_starlette_behavior.py
test_httpx_sse_behavior.py
test_httpx_auth_behavior.py
test_opentelemetry_behavior.py
test_anthropic_behavior.py
```

## How to Add a New Fixture
Expand All @@ -44,17 +54,25 @@ compat/downstream/
python scripts/run_downstream_compat.py
```

### Generate downstream matrix
```bash
python scripts/generate_downstream_matrix.py \
--manifest compat/downstream/manifest.toml \
--output /tmp/downstream-matrix.json
```

### Run package-specific integration tests
```bash
cd crates/eggfetch-python && maturin develop
EGGFETCH_COMPAT_REQUIRED=1 pytest crates/eggfetch-python/tests/compat/test_downstream_portfolio.py -v --strict-markers
EGGFETCH_COMPAT_REQUIRED=1 pytest compat/downstream/behavioral_fixtures/ -v --strict-markers
```

### Install all downstream packages for manual testing
```bash
pip install httpx==0.28.1 respx==0.21.1 pytest-httpx==0.30.0 starlette==0.37.2
pip install anthropic==0.39.0 groq==0.13.0 httpx-sse==0.4.0 httpcore==1.0.5
pip install anyio==4.8.0 httpx-auth==0.22.0 httpx-ws==0.7.0 pydantic==2.10.0
pip install httpx==0.28.1 respx==0.23.1 pytest-httpx==0.36.2 starlette==0.37.2
pip install anthropic==0.39.0 httpx-sse==0.4.3 httpx-auth==0.23.1
pip install opentelemetry-instrumentation-httpx==0.65b0 opentelemetry-sdk==1.44.0
pip install httpcore==1.0.5 anyio==4.8.0 pydantic==2.10.0
```

## Isolation Requirements
Expand All @@ -78,14 +96,29 @@ pip install anyio==4.8.0 httpx-auth==0.22.0 httpx-ws==0.7.0 pydantic==2.10.0
| Category | What It Tests |
|----------|--------------|
| contract-tests | Reference httpx API surface |
| mock-transport-user | MockTransport, Router, request interception |
| mock-transport-request-matching | MockTransport, Router, request interception |
| framework-test-client | Pytest fixtures, request matching |
| framework-asgi-transport | ASGITransport, in-process ASGI |
| asgi-test-client | ASGITransport, in-process ASGI |
| sdk-async-client | AsyncClient, custom auth, streaming, timeouts |
| sdk-sync-client | Client, custom auth, timeout config |
| streaming-upload-download | Streaming responses, SSE, chunked transfer |
| streaming-sse-consumption | Streaming responses, SSE, chunked transfer |
| custom-transport-subclass | BaseTransport/AsyncBaseTransport subclassing |
| async-testing-support | Async context managers, task groups |
| custom-auth-flow | Auth subclassing, OAuth, token refresh |
| event-hook-instrumentation | Transport extensions, connection lifecycle |
| event-hooks-instrumentation | Transport extensions, connection lifecycle |
| heavy-config-user | base_url, params, headers, cookies, timeouts |

## Release-Blocking Coverage

All 8 Stage C categories are covered by release-blocking packages:

| Category | Package | Version |
|----------|---------|---------|
| contract-tests | httpx | 0.28.1 |
| mock-transport-request-matching | respx | 0.23.1 |
| framework-test-client | pytest-httpx | 0.36.2 |
| asgi-test-client | starlette | 0.37.2 |
| sdk-async-client | anthropic | 0.39.0 |
| streaming-sse-consumption | httpx-sse | 0.4.3 |
| custom-auth-flow | httpx-auth | 0.23.1 |
| event-hooks-instrumentation | opentelemetry-instrumentation-httpx | 0.65b0 |
83 changes: 83 additions & 0 deletions compat/downstream/behavioral_fixtures/test_anthropic_behavior.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""Category: sdk-async-client — exercises anthropic SDK with controlled transport.

anthropic is a major AI SDK using httpx.AsyncClient with custom auth,
base_url, timeouts, streaming, and exception inspection. This fixture
constructs the SDK with a controlled async HTTP client/transport and
exercises one local or mocked request path without credentials or external
network.
"""

import httpx


def test_anthropic_sdk_custom_async_client():
"""anthropic SDK accepts a custom async HTTP client for controlled transport."""
try:
from anthropic import AsyncAnthropic
except ImportError:
import pytest
pytest.skip("anthropic not installed")

# Build a controlled transport that returns a mock response
mock_response = httpx.Response(
200,
json={
"id": "msg_test",
"type": "message",
"role": "assistant",
"content": [{"type": "text", "text": "Hello from mock"}],
"model": "claude-3-sonnet-20240229",
},
headers={"content-type": "application/json"},
)
transport = httpx.MockTransport(lambda r: mock_response)

# Construct the SDK with a controlled async HTTP client
custom_client = httpx.AsyncClient(
transport=transport,
base_url="http://test/anthropic",
timeout=30.0,
)

client = AsyncAnthropic(
api_key="test-key-not-real",
http_client=custom_client,
base_url="http://test/anthropic",
)

# Verify the SDK was constructed with our controlled client
assert client.base_url == "http://test/anthropic"
# The SDK's http_client should be our custom client
assert client.http_client is custom_client or client.http_client.transport is transport


def test_anthropic_sdk_custom_transport():
"""anthropic SDK works with a custom transport without external network."""
try:
from anthropic import AsyncAnthropic
except ImportError:
import pytest
pytest.skip("anthropic not installed")

mock_response = httpx.Response(
200,
json={
"id": "msg_test_2",
"type": "message",
"role": "assistant",
"content": [{"type": "text", "text": "Mocked response"}],
"model": "claude-3-sonnet-20240229",
},
headers={"content-type": "application/json"},
)
transport = httpx.MockTransport(lambda r: mock_response)

client = AsyncAnthropic(
api_key="test-key-not-real",
http_client=httpx.AsyncClient(transport=transport),
base_url="http://test/anthropic",
)

# Verify the SDK is configured to use our controlled transport
assert client.base_url == "http://test/anthropic"
assert client.api_key == "test-key-not-real"
52 changes: 52 additions & 0 deletions compat/downstream/behavioral_fixtures/test_httpx_auth_behavior.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Category: custom-auth-flow — exercises httpx-auth.

httpx-auth is an authentication library implementing OAuth, Digest, and API
key flows on top of httpx.Auth. This fixture applies a real package auth
object, sends a request, and asserts the generated auth header.
"""

import httpx
import httpx_auth


def test_httpx_auth_basic():
"""httpx-auth Basic auth generates the correct Authorization header."""
auth = httpx_auth.Basic("user", "pass")
transport = httpx.MockTransport(
lambda r: httpx.Response(200, json={"auth": r.headers.get("authorization", "")})
)
with httpx.Client(auth=auth, transport=transport) as c:
r = c.get("http://test/auth")
assert r.status_code == 200
auth_header = r.json()["auth"]
assert auth_header.startswith("Basic ")


def test_httpx_auth_api_key():
"""httpx-auth API key auth generates the correct header."""
auth = httpx_auth.HeaderApiKey(
api_key="secret-key",
header_name="X-API-Key",
)
transport = httpx.MockTransport(
lambda r: httpx.Response(200, json={"api_key": r.headers.get("x-api-key", "")})
)
with httpx.Client(auth=auth, transport=transport) as c:
r = c.get("http://test/api")
assert r.status_code == 200
assert r.json()["api_key"] == "secret-key"


def test_httpx_auth_query():
"""httpx-auth query parameter auth appends the key to the URL."""
auth = httpx_auth.QueryApiKey(
api_key="query-secret",
query_parameter_name="api_key",
)
transport = httpx.MockTransport(
lambda r: httpx.Response(200, json={"path": str(r.url)})
)
with httpx.Client(auth=auth, transport=transport) as c:
r = c.get("http://test/query")
assert r.status_code == 200
assert "api_key=query-secret" in r.json()["path"]
151 changes: 151 additions & 0 deletions compat/downstream/behavioral_fixtures/test_httpx_contract_behavior.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
"""Category: contract-tests — exercises the HTTPX 0.28.1 public API contract.

This fixture runs a curated public-behavior subset that does not depend on
HTTPX private internals unavailable by design. It covers request construction,
response construction, headers and repeated values, query parameters and
repeated values, URL behavior, cookies, timeout configuration, sync client
request flow, async client request flow, auth flow, event hooks, mock
transport, and exception request context.
"""

import httpx


def test_contract_request_construction():
"""Request construction preserves method, url, headers, content."""
req = httpx.Request("POST", "http://test/api", json={"key": "value"})
assert req.method == "POST"
assert req.url.path == "/api"
assert req.headers.get("content-type") == "application/json"


def test_contract_response_construction():
"""Response construction preserves status, headers, body."""
resp = httpx.Response(201, json={"created": True}, headers={"X-Custom": "yes"})
assert resp.status_code == 201
assert resp.json()["created"] is True
assert resp.headers.get("x-custom") == "yes"


def test_contract_headers_repeated_values():
"""Headers preserve repeated values."""
h = httpx.Headers([("set-cookie", "a=1"), ("set-cookie", "b=2")])
assert h.get_list("set-cookie") == ["a=1", "b=2"]


def test_contract_query_repeated_values():
"""Query parameters preserve repeated values."""
url = httpx.URL("http://test/api?a=1&a=2&b=3")
assert url.params.get_list("a") == ["1", "2"]
assert url.params.get("b") == "3"


def test_contract_url_behavior():
"""URL parsing and reconstruction works correctly."""
url = httpx.URL("http://user:pass@example.com:8080/path?query=1#frag")
assert url.scheme == "http"
assert url.host == "example.com"
assert url.port == 8080
assert url.path == "/path"
assert url.query == b"query=1"


def test_contract_cookies():
"""Cookies can be set and read from a response."""
req = httpx.Request("GET", "http://test/cookies")
resp = httpx.Response(200, headers={"set-cookie": "session=abc123"}, request=req)
assert resp.cookies.get("session") == "abc123"


def test_contract_timeout_config():
"""Timeout configuration is accepted and stored."""
with httpx.Client(timeout=30.0) as c:
assert c.timeout.read == 30.0


def test_contract_sync_client_flow():
"""Sync client request flow works end-to-end."""
transport = httpx.MockTransport(lambda r: httpx.Response(200, json={"ok": True}))
with httpx.Client(transport=transport) as c:
resp = c.get("http://test/sync")
assert resp.status_code == 200
assert resp.json()["ok"] is True


def test_contract_async_client_flow():
"""Async client request flow works end-to-end."""
import pytest

transport = httpx.MockTransport(lambda r: httpx.Response(200, json={"ok": True}))

@pytest.mark.asyncio
async def _run():
async with httpx.AsyncClient(transport=transport) as c:
resp = await c.get("http://test/async")
assert resp.status_code == 200
assert resp.json()["ok"] is True

import asyncio
asyncio.run(_run())


def test_contract_auth_flow():
"""Auth flow with single yield works."""

class TokenAuth(httpx.Auth):
def auth_flow(self, request):
request.headers["Authorization"] = "Bearer token"
yield request

transport = httpx.MockTransport(
lambda r: httpx.Response(200, json={"auth": r.headers.get("authorization", "")})
)
with httpx.Client(auth=TokenAuth(), transport=transport) as c:
resp = c.get("http://test/auth")
assert resp.status_code == 200
assert resp.json()["auth"] == "Bearer token"


def test_contract_event_hooks():
"""Event hooks are called during request/response."""
hook_calls = []

def on_request(request):
hook_calls.append("request")

def on_response(response):
hook_calls.append("response")

transport = httpx.MockTransport(lambda r: httpx.Response(200))
with httpx.Client(
transport=transport,
event_hooks={"request": [on_request], "response": [on_response]},
) as c:
c.get("http://test/hooks")
assert "request" in hook_calls
assert "response" in hook_calls


def test_contract_mock_transport():
"""MockTransport dispatches correctly."""
transport = httpx.MockTransport(lambda r: httpx.Response(200, json={"mock": True}))
with httpx.Client(transport=transport) as c:
resp = c.get("http://test/mock")
assert resp.status_code == 200
assert resp.json()["mock"] is True


def test_contract_exception_request_context():
"""Exceptions carry the original request context."""

def handler(r):
raise httpx.ConnectError("refused", request=r)

transport = httpx.MockTransport(handler)
with httpx.Client(transport=transport) as c:
try:
c.get("http://test/error")
assert False, "Expected ConnectError"
except httpx.ConnectError as exc:
assert exc.request is not None
assert exc.request.url.path == "/error"
Loading
Loading