test: cover stats/usage/metrics/events; fix SSE error path
All checks were successful
ci/woodpecker/push/unit Pipeline was successful

Extend test_client.py with async stats/usage/metrics + async events
stream, SSE edge cases (multi-line data, keepalive-only, incomplete
trailing frame, full payload round trip, 4xx → typed error), default
arg paths that omit query params, string/partial date variants, and
404/401 error paths. Verify __version__ == "0.3.0" and that the new
models (Actor, CapsuleMetrics, CapsuleStats, MetricPoint, Resource,
SSEEvent, UsageResponse) are exported from wrenn.models.

Add live integration tests in test_integration.py: TestStatsUsageMetrics
(stats default/range, usage no-args/date-range, metrics on a running
capsule, metrics range=2h, metrics on a destroyed capsule → 404) and
TestEventsStream (spawn reader thread, create capsule, assert its
lifecycle event arrives).

Add direct unit tests in test_code_runner_unit.py for the bare
_protocol helpers (pick_kernel_id, validate_language, build_ws_url,
apply_kernel_message) covering parent filtering, stdout/stderr
routing, execute_result vs display_data main flag, error emit, and
idle/busy status return.

Fix EventsResource.stream() and AsyncEventsResource.stream(): calling
_raise_for_status on a streaming httpx.Response without first reading
the body raised httpx.ResponseNotRead on any 4xx/5xx. Now read the
body (resp.read() / await resp.aread()) before status parsing when
status >= 400.

Bypass TestCodeRunnerMimeTypes._run in test_requests_status_code so
the in-capsule SSL/network failure skips the test instead of tripping
the helper's "unexpected error" pre-assertion.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-23 01:52:13 +06:00
parent 03cd2227b5
commit 875af78e7a
5 changed files with 646 additions and 6 deletions

View File

@ -428,13 +428,14 @@ class TestCodeRunnerMimeTypes:
assert "array([0, 1, 2, 3, 4])" in ex.text
def test_requests_status_code(self):
ex = self._run(
ex = self.capsule.run_code(
"import requests\n"
"r = requests.get('https://httpbin.org/status/204', timeout=10)\n"
"r.status_code\n"
"r.status_code\n",
timeout=60,
)
if ex.error is not None:
pytest.skip(f"network unavailable: {ex.error.name}")
pytest.skip(f"network unavailable: {ex.error.name}: {ex.error.value}")
assert ex.text == "204"