Skip to content

Keep the UI tests off the real WebSocket - #56

Merged
fdussert merged 1 commit into
mainfrom
hotfix/flaky-socket-timer
Oct 20, 2026
Merged

fdussert merged 1 commit into
mainfrom
hotfix/flaky-socket-timer

Conversation

@fdussert

Copy link
Copy Markdown
Owner

CI on main (19ed0ba) failed once on ReferenceError: location is not defined at ui/src/shared/socket.ts:50, reported as an unhandled error from test/marketplace-modal.test.ts, then passed on rerun.

Cause. useSocket() is a page-wide singleton that reconnects forever. Component tests open it without meaning to: useAdminStore() subscribes to config, and useHealth() (through HealthMenu in TopBar) subscribes to the health channel. Under jsdom the socket dials ws://localhost:3000/ws, is refused, and arms setTimeout(connect, 500). That timer can outlive the test environment and fire once location is gone. Each close also sent the session check through whatever fetch the test had stubbed. Fourteen jsdom test files reached the real socket this way.

Fix. ui/test/setup.ts, loaded through setupFiles, installs a WebSocket that stays connecting: it never opens and never closes, so the reconnect loop never starts. The two tests that drive the wire (socket-cache-invalidation, socket-remote-session) still stub their own with vi.stubGlobal, and vi.unstubAllGlobals() restores the silent one.

useSocket() is unchanged. It belongs to the page, not to a component scope, so there is no owner whose disposal should stop it.

Verification.

  • With connect()/onclose temporarily instrumented over the whole UI suite: before, about 25 real sockets were opened and refused, each arming a retry; after, none (21 silent, 4 test-owned fakes).
  • pnpm typecheck and pnpm test are green (ui 874/874, server 2679 passed, 2 skipped).
  • The exact CI failure did not reproduce locally on Node 26/24; CI runs Node 22.

No user-visible change, so no changelog line.

🤖 Generated with Claude Code

useSocket() is a page-wide singleton that reconnects forever, and many
component tests open it without asking: useAdminStore() subscribes to
the config channel and useHealth() to the health one. Under jsdom that
dialled ws://localhost:3000/ws, was refused, and armed a retry timer the
test never knew about. One CI run on main saw that timer fire after
marketplace-modal.test.ts's environment was torn down, with `location`
gone, and fail the job with an unhandled ReferenceError although every
test had passed. Each close also sent the session check through
whatever fetch the test had stubbed.

Fourteen jsdom test files reached the real socket this way, so the fix
is one setup file rather than a vi.mock in each: a WebSocket that stays
connecting, never opens and never closes, so the reconnect loop never
starts. The two tests that drive the wire still stub their own with
vi.stubGlobal, and vi.unstubAllGlobals() brings the silent one back.

useSocket() itself is left as it is: it belongs to the page, not to a
component scope, so there is no owner whose disposal should stop it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying fremkit with  Cloudflare Pages  Cloudflare Pages

Latest commit: 074c795
Status: ✅  Deploy successful!
Preview URL: https://0a814b14.fremkit.pages.dev
Branch Preview URL: https://hotfix-flaky-socket-timer.fremkit.pages.dev

View logs

@fdussert
fdussert merged commit cc0e4df into main Oct 20, 2026
3 checks passed
@fdussert
fdussert deleted the hotfix/flaky-socket-timer branch October 20, 2026 13:41
fdussert added a commit that referenced this pull request Nov 18, 2026
The kiosk window becomes a non-activating panel that never turns key, so a
tap on the Edge no longer takes the keyboard (or the ⌘Tab switcher) away from
the app on the primary display. Tested on a real Edge with real touches.

The merge also brings origin/main's #55 (clipboard one-time codes, private
pasteboard markers) and #56 (UI tests off the real WebSocket), which local
main did not have yet; CHANGELOG entries from both sides are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant