[merge 2/5] feat(channels/web): per-runtime approval-surface bridge for E2E tests (#3471)
Summary
- Adds
fresh_approval_surface_subscription()— subscribes anApprovalSurfaceSubscriberon the current tokio runtime, bypassing the productionOnceLock, and returns theSubscriptionHandleto the caller. - Gated
#[cfg(debug_assertions)]so the OnceLock-bypassing helper cannot link into a release binary (where a second live subscriber would surface everyApprovalRequestedevent twice).
Problem
The production approval-surface bridge is registered once behind a process-level OnceLock, and its background task is tied to the runtime it was first registered on. Integration tests that build a fresh tokio runtime per test (the standard pattern in tests/*.rs) lose the bridge after the first test's runtime drops, so subsequent tests never receive approval_request SSE events.
Solution
fresh_approval_surface_subscription() lets each test register its own bridge on its own runtime and hold the handle for that test's lifetime (the handle aborts the task on drop). Production keeps using the OnceLock singleton (register_approval_surface_subscriber). The new helper is debug-only, so it physically cannot ship. Unit tests cover the subscription. Second of five PRs for the #3471 agent-harness E2E work.
Submission Checklist
- [x] Tests added — unit tests for
fresh_approval_surface_subscription. - [x] Diff coverage ≥ 80% — the one-line helper body is exercised by its unit tests; the
mod.rsre-export is non-executable. - [x] N/A — coverage matrix rows land in the docs PR of this series.
- [x] No new external network deps.
- [x] N/A — manual smoke: debug-only test affordance, no release-cut surface.
- [x] N/A — issue close (
Closes #3471) is on the final (docs) PR.
Impact
Debug builds gain a test-only subscription helper; release builds are unaffected (cfg-compiled out). No production behavior change — the singleton bridge is untouched.
Related
- Part of the #3471 agent-harness E2E series (PR 2 of 5). Independent of the TTL-override PR (disjoint files); the Rust E2E PR depends on both to compile.
📝 Walkthrough
Walkthrough
A new #[cfg(debug_assertions)]-gated function fresh_approval_surface_subscription is added to event_bus.rs. It calls subscribe_global directly on the current Tokio runtime, bypassing the production OnceLock singleton, and returns an Option<SubscriptionHandle>. The function is conditionally re-exported from web/mod.rs. Two unit tests validate that the function returns Some after bus initialization and produces independent handles on repeated calls.
Changes
Debug-only fresh approval-surface subscription
| Layer / File(s) | Summary |
|---|---|
Helper implementation and module re-export src/openhuman/channels/providers/web/event_bus.rs, src/openhuman/channels/providers/web/mod.rs |
fresh_approval_surface_subscription is defined under #[cfg(debug_assertions)] with #[doc(hidden)], calling subscribe_global and returning Option<SubscriptionHandle>; mod.rs conditionally re-exports it for per-runtime integration tests. |
Unit tests src/openhuman/channels/providers/web/event_bus.rs |
Two #[tokio::test] cases: one asserts the function returns Some after global bus initialization, another asserts repeated calls return distinct, independently droppable handles. |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
A bunny hops past the OnceLock gate, Spinning up subscriptions fresh — how great! Each handle unique, no singleton in sight, Debug builds only, kept well out of prod's light. 🐇✨ Tests confirm each handle drops just right!
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly and specifically identifies the main change: adding a per-runtime approval-surface bridge helper function for E2E tests. It accurately reflects the primary purpose and scope of the PR. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
Comment @coderabbitai help to get the list of available commands and usage tips.
Thanks for the review. Addressing the two nitpicks on event_bus.rs:
- Debug logging — added a
tracing::trace!at the top offresh_approval_surface_subscriptionto differentiate the debug-only OnceLock-bypass path from production registration (pushed). - None-case test — the bus-not-initialized branch can't be tested deterministically here: the global event bus is a process-wide singleton, and other tests in this binary initialize it, so
subscribe_globalreturnsSomeregardless of call order. A None assertion would be order-dependent/flaky. TheSomeand not-a-singleton cases are covered.