Skip to content

test(swr): make remote mutation race deterministic - #752

Merged
leonidaz merged 2 commits into
mainfrom
fix/swr-remote-mutation-flake
Aug 13, 2026
Merged

leonidaz merged 2 commits into
mainfrom
fix/swr-remote-mutation-flake

Conversation

@leonidaz

@leonidaz leonidaz commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Make SWR's pinned remote-mutation race oracle deterministic without modifying the byte-exact vendored upstream suite.
  • Hold the initial request completion until the mutation click has started, then release it so the unchanged stale-data assertion always observes a real overlap.
  • Record and directly test the timer-gate contract in the React-parity evidence.

Why

  • PR #746 uncovered the flake in its React parity shard job.
  • The upstream test starts a 10 ms request and assumes Testing Library can render, query, and click before that timer fires. On a loaded runner, the request can finish first and legitimately render foo before the mutation exists, so the test no longer exercises the race it claims to cover.

Changes

  • Map the pristine SWR Jest suite through a narrow Testing Library harness keyed to the exact upstream race case.
  • Add a reusable timer gate that holds only the first 10 ms completion during render and releases it after the click starts the mutation.
  • Add a Node contract test and hash the new support files into the SWR parity manifest.
  • Document the harness while preserving all vendored upstream bytes and assertions.

Validation

  • pnpm format:check — not run; scoped formatting check passed for all seven changed files.
  • pnpm typecheck — not run; no TypeScript or public API changed.
  • pnpm test — not run; validation was kept SWR-scoped as requested.
  • targeted tests:
    • Formerly failing Jest case: 20/20 repeated passes.
    • Full SWR pristine Jest suite: 362 passed, 5 skipped, 6 snapshots passed.
    • node --test scripts/react-parity/swr-upstream-timer-gate.test.mjs: 1 passed.
    • pnpm --filter @octanejs/swr upstream:verify: passed (367 identities accounted for).
    • pnpm vitest run --project swr --project swr-differential: 11 files and 39 tests passed.
    • node scripts/react-parity/check.mjs --validate-only: passed.
  • pnpm sync

Risk / follow-ups

  • The harness is intentionally keyed to the pinned upstream test name and timing fixture. A future SWR pin should remove it if upstream replaces the wall-clock setup with explicit deferred promises.

Provenance

  • An agent produced this diff (agent-authored)

Note

Low Risk
Changes are limited to audit/test harness and parity metadata; vendored upstream bytes and SWR runtime are untouched.

Overview
Fixes flaky CI on the pinned byte-exact SWR 2.4.2 pristine Jest suite by making one upstream remote-mutation race case deterministic without changing vendored tests or assertions.

The pristine Jest config now maps @testing-library/react to a narrow harness that only activates for useSWR - remote mutation should prevent race conditions with useSWR. On render, it uses holdFirstTimeout to defer the first 10 ms setTimeout (the initial request completion); on click, it releases that timer so the mutation starts before the request finishes—preserving the overlap the upstream test assumes but that loaded runners can violate.

Adds upstream-timer-gate.cjs, a Node contract test, parity manifest hashes/notes, and UPSTREAM.md documentation for the harness.

Reviewed by Cursor Bugbot for commit f444bd4. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent test PR: tests only labels Aug 13, 2026
@leonidaz
leonidaz marked this pull request as ready for review August 13, 2026 20:38
@leonidaz
leonidaz merged commit 8512d42 into main Aug 13, 2026
45 checks passed
@leonidaz
leonidaz deleted the fix/swr-remote-mutation-flake branch August 13, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent test PR: tests only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants