Closes the dynamic-coverage gap on the `notifications/claude/channel`
push-UX bridge — until now we had static pins on the wire shape
(_build_channel_notification) and the initialize handshake, but the
threading + asyncio + stdout chain that ships notifications to the
host was never exercised under realistic conditions.
The three failure modes anticipated in #2444 §2 are each now pinned:
test_inbox_bridge_emits_channel_notification_to_writer
Drives a fake inbox event from a daemon thread, asserts the
notification lands on a real os.pipe-backed asyncio writer with
the correct JSON-RPC envelope. Catches: bridge wired up
incorrectly (no-op _on_inbox_message), run_coroutine_threadsafe
drift, _build_channel_notification call missing.
test_inbox_bridge_swallows_closed_pipe_drain_error
Closes the pipe's read end before firing, captures the
concurrent.futures.Future that run_coroutine_threadsafe returns,
asserts its exception() is None. Catches: narrowing the broad
`except Exception` in _emit (e.g. to RuntimeError), or removing
it. Without the swallow, the future carries a ConnectionResetError
and the test fails with a clear message naming the regression.
test_inbox_bridge_swallows_closed_loop_runtime_error
Builds the bridge against a closed event loop, fires the
callback, asserts no exception escapes. Catches: removing the
`except RuntimeError` swallow on the run_coroutine_threadsafe
call. Without it the poller thread would crash with
"RuntimeError: Event loop is closed" during shutdown.
To make the bridge testable, extracted the closures from main() into
a top-level `_setup_inbox_bridge(writer, loop) -> Callable[[dict],
None]` helper. main()'s wire-up is now a single line that calls the
helper. Behavior is unchanged — same write, same drain, same
swallows — just no longer trapped inside main()'s closures.
Verified each test catches its regression by injection: removing
each swallow / no-op'ing the bridge each turn the matching test red
with a specific failure message that points at the missing piece.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>