Skip to content

fix: surface auth failures and fix reconnect resubscription (#45, #46)#47

Merged
anilcancakir merged 5 commits intomasterfrom
fix/reconnect-and-wasm-uri
Apr 7, 2026
Merged

fix: surface auth failures and fix reconnect resubscription (#45, #46)#47
anilcancakir merged 5 commits intomasterfrom
fix/reconnect-and-wasm-uri

Conversation

@anilcancakir
Copy link
Copy Markdown
Contributor

Summary

Test plan

  • 870/870 tests pass (flutter test)
  • dart analyze — zero warnings
  • 5 new tests covering: auth failure interceptor routing, Log.error visibility, reconnect resubscription, onReconnect timing, partial failure resilience

Closes #45, closes #46

Relative `sqlite3.wasm` URI resolved against the current page path when
using path URL strategy, causing 404s on deep routes. Changed to absolute
`/sqlite3.wasm` so the binary always loads from the web root.
…tion (#45)

- Add `authFactory` constructor DI param to ReverbBroadcastDriver for
  testable auth (follows existing `channelFactory` pattern)
- Replace bare `catch(_)` in `_authenticateAndSubscribe()` with error
  logging via `Log.error()` and interceptor chain routing
- Await `_authenticateAndSubscribe()` in reconnect loop so
  `onReconnect` stream emits only after all resubscriptions complete
- Per-channel try/catch in reconnect ensures one auth failure does not
  block other channels from resubscribing
- Snapshot `_channels.keys.toList()` before iteration to prevent
  concurrent modification during reconnect
- Add 5 new tests covering auth failure visibility, reconnect
  resubscription, onReconnect timing, and partial failure resilience
Copilot AI review requested due to automatic review settings April 7, 2026 13:57
@sentry
Copy link
Copy Markdown

sentry Bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 61.90476% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../broadcasting/drivers/reverb_broadcast_driver.dart 61.90% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

… and #46

- Add [Unreleased] section to CHANGELOG.md with bug fix entries
- Update broadcasting doc: auto-resubscription after reconnect, auth
  error logging behavior, onReconnect timing guarantee
- Update skill reference: authFactory DI param, auth failure handling
- Update .claude/rules/broadcasting.md: reconnect resubscription and
  auth error handling conventions
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes two web-related reliability issues in the Magic framework: correct loading of sqlite3.wasm under path-based routing, and making Reverb WebSocket reconnects reliably re-authenticate/re-subscribe channels while surfacing auth failures via logging and interceptors.

Changes:

  • Load sqlite3.wasm from an absolute /sqlite3.wasm URL on web to avoid route-relative 404s.
  • Add authFactory DI + improved error logging/interceptor routing for broadcasting channel auth, and await resubscriptions during reconnect before emitting onReconnect.
  • Add reconnect resubscription tests, including auth failure visibility and partial failure resilience.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

File Description
test/broadcasting/drivers/reverb_broadcast_driver_test.dart Adds tests covering reconnect resubscription behavior and auth failure surfacing.
lib/src/database/connectors/connection_factory_web.dart Switches WASM load URL to an absolute path to work with path URL strategy.
lib/src/broadcasting/drivers/reverb_broadcast_driver.dart Introduces injectable auth, logs/auth error routing, and resubscribe-on-reconnect behavior changes.

Comment thread lib/src/broadcasting/drivers/reverb_broadcast_driver.dart Outdated
Comment thread lib/src/broadcasting/drivers/reverb_broadcast_driver.dart
Comment thread test/broadcasting/drivers/reverb_broadcast_driver_test.dart Outdated
- Validate response type in _defaultAuthFactory instead of force-cast —
  returns empty map for non-Map responses so malformed auth hits the
  warning path instead of throwing a generic TypeError
- Check _channels.containsKey(name) in reconnect loop to skip channels
  that were leave()'d after the snapshot was taken
- Add interceptor after initial subscribe in test so assertion only
  captures reconnect-time auth errors, not the initial subscribe failure
…path

Cover the Log.warning path triggered when auth response is missing the
'auth' key. Also verify that channels with malformed auth do not receive
subscribe frames.
@anilcancakir anilcancakir merged commit e7f0253 into master Apr 7, 2026
2 checks passed
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.

fix: sqlite3.wasm uses relative URI — breaks path URL strategy WebSocket channel subscriptions silently fail after reconnect

2 participants