Skip to content

test: cover direct browser stream cancellation - #148

Merged
rgarcia merged 1 commit into
mainfrom
hypeship/test-routing-cancel
Aug 10, 2026
Merged

test: cover direct browser stream cancellation#148
rgarcia merged 1 commit into
mainfrom
hypeship/test-routing-cancel

Conversation

@rgarcia

@rgarcia rgarcia commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

summary

  • add an async telemetry stream that blocks until its consumer is canceled
  • verify cancellation stops the consumer and closes the direct-routed response body
  • assert the request reaches the browser VM telemetry path

tests

  • pytest -q — 671 passed
  • ruff check .
  • pyright --pythonpath /tmp/kernel-python-venv/bin/python tests/test_browser_routing.py

Note

Low Risk
Test-only addition with no runtime code changes; low risk beyond CI/test maintenance.

Overview
Adds test_async_telemetry_stream_cancellation_survives_direct_routing, which exercises AsyncKernel when telemetry/stream is allowlisted for direct browser VM routing.

The test uses a mock httpx.AsyncByteStream that blocks until the stream consumer is cancelled, then asserts the consumer raises CancelledError and the underlying response read/teardown completes (via read_stopped). It also pins that the request hits /browser/kernel/telemetry/stream on the cached browser route.

No production or SDK behavior changes—only regression coverage for cancelling long-lived SSE reads on direct-routed telemetry streams.

Reviewed by Cursor Bugbot for commit b136c50. Bugbot is set up for automated code reviews on this repo. Configure here.

@rgarcia
rgarcia requested a review from Jayko001 August 8, 2026 14:11
@rgarcia
rgarcia merged commit 98659ce into main Aug 10, 2026
11 checks passed
@rgarcia
rgarcia deleted the hypeship/test-routing-cancel branch August 10, 2026 18:54
@Sayan-

Sayan- commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Post-merge verification. Passes cleanly (24 tests in this file), no objection to it landing. Flagging that it guards less than the title suggests, so it is not counted as coverage we have when we do not.

Two things I checked:

  1. The routing assertion is redundant. I disabled the rewrite in rewrite_direct_vm_options and this test failed, but so did three pre-existing tests, including test_telemetry_stream_routes_directly_to_vm immediately above it. So the /browser/kernel/telemetry/stream path assertion adds nothing new.

  2. The cancellation assertions are close to tautological. pytest.raises(asyncio.CancelledError) after consumer.cancel() is a property of asyncio, not of this SDK. read_stopped is set by the test's own mock in both __aiter__'s finally and aclose(), so either path satisfies it and the assertion cannot tell them apart.

More to the point, there is no analogous defect available to regress. The whole routing surface is two hooks in _client.py (lines 337 and 341): rewrite_direct_vm_options, which model_copys FinalRequestOptions and edits only url and params, and strip_direct_vm_auth, which pops a header. Neither touches request construction, the transport, or the cancel scope, which is exactly why Python was never affected by the Node defect.

If you want this to earn its name, the assertion that would actually bite is that cancellation reaches the transport, for example by asserting the mock transport observed the disconnect rather than that the mock's own bookkeeping flag was set.

Nit: yield b"" after await asyncio.Event().wait() is unreachable.

@Sayan- Sayan- left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified post-merge: passes, no objection. Approving; see the note above on what it does and does not guard.

@rgarcia

rgarcia commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

addressed in #151. The test now records CancelledError inside the transport byte stream, so it proves consumer cancellation reaches the transport. It also removes the duplicate route-path assertion and unreachable mock yield.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants