Skip to content

watch: track all dependencies of an owner - #66139

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
christianaurichzm:watch-owner-dependencies
Nov 6, 2026
Merged

nodejs-github-bot merged 1 commit into
nodejs:mainfrom
christianaurichzm:watch-owner-dependencies

Conversation

@christianaurichzm

Copy link
Copy Markdown
Member

FilesWatcher#filterFile() reads #ownerDependencies with the dependency path, but writes the set back keyed by the owner. As a result, each call starts a fresh set and overwrites the previous one, so an owner keeps only the last dependency registered for it.

Each test child reports the modules it loads through watch:require/watch:import, with one filterFile() call per module. A test file with N dependencies therefore keeps 1 and loses N-1.

unfilterFilesOwnedBy() walks that set to release an owner's dependencies, so the lost dependencies remain in #filteredFiles and #dependencyOwners. A restart re-reports the modules the test still loads, which hides the stale state for those modules, but a dependency it stopped requiring is never reported again and therefore never removed:

# a.test.js requires dep1.js and dep2.js
node --test --watch a.test.js

# drop require('./dep1.js') from a.test.js   -> restarts, as expected
# touch dep1.js                              -> restarts again

The second restart should not happen: dep1.js is no longer a dependency of any test. Its stale entries otherwise remain for the lifetime of the process.

The bug was introduced with #45214 (97355c74e819), first released in v19.2.0 and later backported to v18.13.0. test-watch-file-shared-dependency does not catch it because it registers one dependency per owner, while this bug requires an owner with multiple dependencies.

The diff also stores the #dependencyOwners lookup in a local while removing an owner's dependencies, avoiding repeated map lookups for each dependency.

Refs: #45214

filterFile() reads #ownerDependencies with the dependency path, but
writes the set back keyed by the owner, so each call starts a fresh set
and overwrites the previous one. An owner keeps only the last
dependency registered for it.

unfilterFilesOwnedBy() walks that set to release an owner's
dependencies, so every other one stays in #filteredFiles and
#dependencyOwners. Under `node --test --watch` a restart re-reports the
modules the test still loads, which hides it for those, but a
dependency it stopped requiring is never reported again and keeps
re-running the test.

Read #ownerDependencies with the key it is written with, and collapse
the repeated #dependencyOwners lookup in the loop, which now runs once
per dependency rather than once per owner.

Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Sep 19, 2026
@codecov

codecov Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.28%. Comparing base (bca9bbe) to head (c3cc140).
⚠️ Report is 841 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #66139   +/-   ##
=======================================
  Coverage   90.28%   90.28%           
=======================================
  Files         790      790           
  Lines      271982   271985    +3     
  Branches    51915    51921    +6     
=======================================
+ Hits       245546   245571   +25     
+ Misses      16947    16901   -46     
- Partials     9489     9513   +24     
Files with missing lines Coverage Δ
lib/internal/watch_mode/files_watcher.js 91.55% <100.00%> (+0.11%) ⬆️

... and 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@christianaurichzm

Copy link
Copy Markdown
Member Author

@MoLow since this is in the FilesWatcher dependency tracking from #45214, could you take a look when you get a chance? cc @ShogunPanda. If it looks good, could you also add request-ci? Thanks!

@panva panva added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Oct 10, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 10, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@christianaurichzm

Copy link
Copy Markdown
Member Author

@panva Could you resume the CI when you get a chance? Thanks!

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@inoway46 inoway46 added the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 1, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 1, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@inoway46 inoway46 added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 6, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 280798a into nodejs:main Nov 6, 2026
83 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 280798a

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 6, 2026
aduh95 pushed a commit that referenced this pull request Nov 11, 2026
filterFile() reads #ownerDependencies with the dependency path, but
writes the set back keyed by the owner, so each call starts a fresh set
and overwrites the previous one. An owner keeps only the last
dependency registered for it.

unfilterFilesOwnedBy() walks that set to release an owner's
dependencies, so every other one stays in #filteredFiles and
#dependencyOwners. Under `node --test --watch` a restart re-reports the
modules the test still loads, which hides it for those, but a
dependency it stopped requiring is never reported again and keeps
re-running the test.

Read #ownerDependencies with the key it is written with, and collapse
the repeated #dependencyOwners lookup in the loop, which now runs once
per dependency rather than once per owner.

Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
PR-URL: #66139
Refs: #45214
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants