Skip to content

Conversation

@dario-piotrowicz
Copy link
Member

@dario-piotrowicz dario-piotrowicz commented Apr 19, 2025

Currently the logic for filtering out watch related flags before passing them to the watch target script is flawed, as it includes any flag (starting with -) that follows a flag starting with --watch (code), this allows some watch flags to make it pass the filtering resulting in the generation of multiple watch processes which is both wasteful and can cause duplicate terminal logs (alongside other issues if the target script is side-effectful).

For example if I run

node --watch --watch index.js

the current implementation will spawn a process equivalent to:

node --watch index.js

which will then finally spawn the correct:

node index.js

Here I'm addressing the incorrect filtering so that all the watch flags are correctly filtered out (making the extra process spawning disappear)


Fixes #57124

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Apr 19, 2025
]);
});

it('when multiple `--watch` flags are provided should run as if only one was', async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: maybe node should error if multiple --watch flags are provided?

I did not go with such a solution because that would be a breaking change, just ignoring extra --watch flags is a non breaking change and it solves the issue at hand

If someone believes that multiple --watch flags should cause an error I would propose to first land this change right now as a patch then as a followup I can also add the stricter validation which will be included as a breaking change in the next major 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And/or maybe, the erroring when multiple --watch flags are provided is part of the bigger issues of node being quite permissive with its cli flags: #57864 and could be addressed as part of that 🤔

@codecov
Copy link

codecov bot commented Apr 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.27%. Comparing base (25842c5) to head (685fb31).
Report is 162 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57936      +/-   ##
==========================================
- Coverage   92.26%   90.27%   -1.99%     
==========================================
  Files         325      630     +305     
  Lines      126673   186112   +59439     
  Branches    20783    36470   +15687     
==========================================
+ Hits       116869   168017   +51148     
- Misses       9576    10976    +1400     
- Partials      228     7119    +6891     

see 412 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.

@dario-piotrowicz dario-piotrowicz changed the title watch: fix --watch args not being properly filtered watch: fix watch args not being properly filtered Apr 19, 2025
@dario-piotrowicz dario-piotrowicz force-pushed the dario/57124/node-watch-args-filtering-fix branch from cdc049a to 4fa1ec0 Compare April 19, 2025 22:35
currently when --watch is used, the argv arguments that
the target script receives are filtered so that they don't
include watch related arguments, however the current
filtering logic is incorrect and it causes some watch values
to incorrectly pass the filtering, the changes here address
such issue
@dario-piotrowicz dario-piotrowicz force-pushed the dario/57124/node-watch-args-filtering-fix branch from 4fa1ec0 to 685fb31 Compare April 19, 2025 22:49
@dario-piotrowicz dario-piotrowicz added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels May 4, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 4, 2025
@nodejs-github-bot
Copy link
Collaborator

@dario-piotrowicz dario-piotrowicz added the commit-queue Add this label to land a pull request using GitHub Actions. label May 5, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 5, 2025
@nodejs-github-bot nodejs-github-bot merged commit 4acb854 into nodejs:main May 5, 2025
64 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 4acb854

@dario-piotrowicz dario-piotrowicz deleted the dario/57124/node-watch-args-filtering-fix branch May 5, 2025 15:22
]);
});

it('when multiple `--watch` flags are provided should run as if only one was', async () => {
Copy link
Member

@joyeecheung joyeecheung May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if it's this PR, but test-watch-mode has been extremely flaky in both Jenkins and GitHub actions recently e.g. https://ci.nodejs.org/job/node-test-commit/79645/ https://ci.nodejs.org/job/node-test-commit/79644/ and many others. Please refrain from appending new test cases in existing test files as https://github.com/nodejs/node/blob/main/doc/contributing/writing-tests.md suggests - especially this file because it's already being ignored by Jenkins so you are not going to get any proper coverage by appending test cases here, it's only going to make the CI more orange than before, and when it increases flakiness you won't be able to notice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thank you very much and sorry for the trouble, I will keep this in mind and create tests in new files whenever possible 🙇

@joyeecheung
Copy link
Member

Actually, this PR landed despite failing many platforms in the test file it appends to: https://ci.nodejs.org/job/node-test-pull-request/66587/

@joyeecheung
Copy link
Member

Sending a revert since it should not have landed #58190

@aduh95 aduh95 added dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. dont-land-on-v23.x dont-land-on-v24.x PRs that should not land on the v24.x-staging branch and should not be released in v24.x. labels May 8, 2025
@dario-piotrowicz
Copy link
Member Author

Actually, this PR landed despite failing many platforms in the test file it appends to: https://ci.nodejs.org/job/node-test-pull-request/66587/

Note: I've addressed those issues in #58183, I wonder if there were actually other issues as well 🤔

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

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. dont-land-on-v24.x PRs that should not land on the v24.x-staging branch and should not be released in v24.x. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--watch combined with --watch-path results in duplicate restart events/logs

6 participants