Skip to content

test(mobile): cover the AbortSignal polyfill (CODE-478) - #326

Merged
AprilNEA merged 1 commit into
masterfrom
xuan/code-478
Jul 29, 2026
Merged

test(mobile): cover the AbortSignal polyfill (CODE-478)#326
AprilNEA merged 1 commit into
masterfrom
xuan/code-478

Conversation

@AprilNEA

Copy link
Copy Markdown
Member

Summary

apps/mobile/src/polyfills.ts (CODE-462) is what lets the mobile client open a socket at all, and it had no test. This adds apps/mobile/src/__tests__/polyfills.test.ts — four cases in the app's existing vitest project, no production code touched.

The module patches at import time behind typeof AbortSignal.prototype.throwIfAborted !== "function", with no exported installer, so each case hands it a runtime without the API (delete throwIfAborted + reason off the prototype) and re-runs it through vi.resetModules() + dynamic import(). afterEach puts all three patched globals back, AbortController.prototype.abort included.

Cases:

  1. throwIfAborted is installed when the runtime lacks it, and a live signal does not throw.
  2. The reason round-tripabort(reason)signal.reasonthrowIfAborted() rethrows the same value by identity, with a non-Error reason so a future narrowing would fail here. RN 0.86 discards the argument to abort(reason) entirely, and ConnectionController re-throws signal.reason when a run is superseded, so the symbol-recording wrapper is the only thing keeping that value alive on device.
  3. abort() with no argument yields a foxts AbortError, from both signal.reason and the throw.
  4. A runtime that already has the Abort API is left untouched — descriptor identity for throwIfAborted, reason, and abort. This is the guard that will let CODE-477 delete the module on RN 0.87 / Expo SDK 58 without ceremony.

Salvaged from the closed PR #309 (CODE-466, a duplicate of CODE-462): that branch shipped a second, weaker polyfill; only its test was worth keeping, and it is rewritten here against the surviving module.

Verification

  • pnpm test polyfills — 4 passed.
  • pnpm test — 256 files passed, 3 skipped; 2,082 tests passed, 5 skipped.
  • pnpm format:check, pnpm lint (0 errors), pnpm typecheck — all pass.
  • Mutation-checked, since a test for a polyfill is easy to write vacuously. Removing the AbortController.prototype.abort wrapper fails cases 2 and 3 only; forcing the guard always-true fails case 4 only. Both mutations were reverted.

No device run: the change is test-only and the module it covers is unchanged.

Checklist

  • pnpm check:ci and pnpm test both pass (plus cargo fmt / clippy / test for Rust changes)
  • I ran the affected surface and observed the change working — the vitest project, including the two mutation runs above
  • If a wire message changed: WIRE_PROTOCOL_VERSION is bumped (not applicable)
  • New code and assets are my own work, or their origin and license compatibility are noted above
  • Docs and comments are updated where behavior changed (no behavior change)

@linear-code

linear-code Bot commented Jul 29, 2026

Copy link
Copy Markdown

CODE-478

@AprilNEA
AprilNEA merged commit 1bbbacd into master Jul 29, 2026
10 checks passed
@AprilNEA
AprilNEA deleted the xuan/code-478 branch July 29, 2026 22:15
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