Skip to content

test: wait for rules-proxy watchers before changing _redirects - #8560

Merged
paulo merged 2 commits into
mainfrom
test/rules-proxy-watcher-ready
Oct 5, 2026
Merged

paulo merged 2 commits into
mainfrom
test/rules-proxy-watcher-ready

Conversation

@paulo

@paulo paulo commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Summary

This fixes a flaky unit test from #8553. tests/unit/utils/rules-proxy.test.ts → "reloads rules when the _redirects file changes" fails intermittently on macOS:

AssertionError: expected { … } to match object { to: '/newer' }
-   "to": "/newer",
+   "to": "/new",

It failed in 2 of the last 10 Unit (macOS-latest, 24) runs (on #8558's branch at 81a5cc3b3 and 57eb7cd32). Neither failure has anything to do with that branch's changes.

Cause: createRewriter starts its chokidar watchers without waiting for them to be ready. The test makes one request and then rewrites _redirects. When the write lands before the watcher has armed its file watch, the change is never reported:

  • the failing runs wait the full 5s waitFor timeout instead of the usual ~200ms for the whole file;
  • the "Reloading redirect rules" log line never appears.

On fast machines the first request (which builds the matcher) outlasts watcher setup, so the test usually passes.

Fix: the rewriterFor test helper waits for every watcher's ready event before returning. createRewriter returns synchronously right after starting the watchers, and ready only fires after filesystem I/O, so the listener is always attached in time and can't hang. Production code is unchanged. A person editing _redirects during netlify dev does so long after the watchers are ready.

How this was verified

  • The file passes 9/9 tests, 15 runs in a row, and still finishes in about 0.4s.
  • The full unit suite with coverage passes. The generate-autocompletion failure also happens on main.
  • Not reproduced locally: I couldn't make the flake happen here, even under CPU load or with chokidar on its own. So there's no local before-and-after; repeated green macOS runs are the real confirmation.

  • Open a bug/issue before writing your code 🧑‍💻
  • Read the contribution guidelines 📖
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

createRewriter starts its chokidar watchers without waiting for them to
be ready. The reload test rewrote _redirects right after the first
request, and on slow macOS runners that write sometimes landed before
the watcher was armed, so the change was never reported and the test
timed out (2 of the last 10 macOS unit runs).
@paulo
paulo requested a review from a team as a code owner October 5, 2026 09:35
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 3c035401-86c1-4417-82a5-934c85e60bb4
📥 Commits

Reviewing files that changed from the base of the PR and between 086fbfc and b9ae9fd.

📒 Files selected for processing (1)
  • tests/unit/utils/rules-proxy.test.ts
 _____________________________
< I speak fluent stack trace. >
 -----------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@paulo
paulo enabled auto-merge (squash) October 5, 2026 09:36
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

📊 Benchmark results

Comparing with 086fbfc

  • Dependency count: 1,018 (no change)
  • Package size: 381 MB (no change)
  • Number of ts-expect-error directives: 331 (no change)

@pkg-pr-new

pkg-pr-new Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/netlify-cli@8560

commit: b9ae9fd

chokidar types the 'ready' listener as () => void, so passing the
Promise resolve function directly failed typecheck.
@paulo
paulo merged commit 9fa2967 into main Oct 5, 2026
36 of 37 checks passed
@paulo
paulo deleted the test/rules-proxy-watcher-ready branch October 5, 2026 09:46
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.

2 participants