Skip to content

test(frontend): cover useSSE reconnect backoff, malformed events and cleanup - #2202

Open
chidii wants to merge 1 commit into
LabsCrypt:mainfrom
chidii:test/2136-sse-reconnect
Open

chidii wants to merge 1 commit into
LabsCrypt:mainfrom
chidii:test/2136-sse-reconnect

Conversation

@chidii

@chidii chidii commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Closes #2136

Adds 28 deterministic tests for the real useSSE transport, driven against a fake SSE server that rejects pending reads with AbortError on abort, like fetch does.

Covered:

  • Connection and authorization: Accept header, bearer token, reconnect when the token or url changes, null/cleared url
  • Delivery: multiple frames per chunk, frames split across chunks, comment/non-data lines ignored, latest onMessage used without reconnecting
  • Malformed events: unparsable frames are logged and skipped; the stream stays up and later frames are delivered
  • Retry backoff: non-OK, null body, network and non-Error failures; 1s then 2s delays; three-attempt cap; backoff reset after a successful open
  • Fallback polling: default 30s and custom intervals; never without a handler
  • Cleanup: unmount aborts the stream and clears pending retry timers and polling

The new file is added to the scoped frontend regression step in ci.yml, so it runs in CI.

Behaviour pinned (worth a look): every successful open resets the attempt counter, so a server that opens and then closes cleanly never triggers fallback polling. Not asserted: after three failures with no onFallbackPoll handler the status stays "connecting" rather than "disconnected".

Verification: CI's exact scoped command (jest ... --runInBand) passes, 100 tests; prettier clean on the new file. tsc reports 2 pre-existing errors in src/components/PWAComponents.tsx, identical on main.

Note: submitted after the Oct 22 due date; please let me know if it can still count.

…cleanup

Adds 28 deterministic tests for the real useSSE transport, driven against a
fake SSE server that rejects reads with AbortError on abort like fetch does:

- connection and authorization: Accept header, bearer token, reconnect on
  token / url change, null url
- delivery: multi-frame chunks, frames split across chunks, comment and
  non-data lines, latest onMessage without reconnecting
- malformed events: unparsable frames are logged and skipped, the stream
  stays up and later frames are delivered
- backoff: non-OK / null body / network / non-Error failures, 1s then 2s
  delays, three-attempt cap, backoff reset after a successful open
- fallback polling: default and custom intervals, never without a handler
- cleanup: unmount aborts the stream and clears pending timers and polling

The new file is added to the scoped frontend regression step in ci.yml so it
runs in CI.

Closes LabsCrypt#2136
@github-actions github-actions Bot added the security:malware-suspected Automated malware indicator found in a pull request label Oct 26, 2026
@github-actions

Copy link
Copy Markdown

Malware detection scan flagged this pull request

The scan found 2 indicator(s) in the PR diff. This PR is blocked until a maintainer reviews the flagged files.

  • frontend/src/app/hooks/useSSE.reconnect.test.tsx — remote-package-source (medium)
  • frontend/src/app/hooks/useSSE.reconnect.test.tsx — hidden-appended-config-payload (high)

This is an automated triage signal; maintainers must verify whether the finding is malicious or intentional.

This branch has not been deployed

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

Labels

security:malware-suspected Automated malware indicator found in a pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[test] Cover frontend SSE reconnect handling

1 participant