Skip to content

test_runner: stop reading process state in run()#64186

Open
Chrismart04 wants to merge 1 commit into
nodejs:mainfrom
Chrismart04:test-runner-decouple-run-from-process
Open

test_runner: stop reading process state in run()#64186
Chrismart04 wants to merge 1 commit into
nodejs:mainfrom
Chrismart04:test-runner-decouple-run-from-process

Conversation

@Chrismart04

Copy link
Copy Markdown

run(), getRunArgs(), and runTestFile() read ambient process state
(process.execArgv, process.env, and process.env.NODE_TEST_CONTEXT)
directly from their bodies, which makes the programmatic run() API depend on
how the host process was started. This is the remaining work from #53867 after
#54705 added the cwd option.

This change:

  • captures references to process.execArgv and process.env once at the
    run() boundary and threads them through the internal opts object
    (processExecArgv / processEnv), so getRunArgs() and runTestFile() no
    longer read process.* in their bodies;
  • reads the NODE_TEST_CONTEXT recursion guard once into a module-level
    constant (isTestRunnerChildProcess).

These are internal captures only — no new public option is added, and the
emitted child argv/env, the isolation: 'none' env guard, and the
recursion guard are all preserved byte-for-byte. Behavior is unchanged for both
the CLI and the programmatic run() API (semver-patch). The mechanism mirrors
how #54705 threaded the cwd option.

A regression test is added for the default process.env inheritance path (the
env option omitted), which was previously untested.

Scope

This intentionally addresses the process.execArgv / process.env /
NODE_TEST_CONTEXT reads called out in #53867. A few unrelated ambient touches
are deliberately left for a possible follow-up to keep the diff focused:
process.execPath (the child binary), getOptionsAsFlagsFromBinding(), and the
process.env.NODE_TEST_WORKER_ID write on the isolation: 'none' path.

Checklist
  • the affected test_runner suite passes locally
    (tools/test.py "test/parallel/test-runner-*") and eslint is clean for the
    changed files
  • tests are included
  • documentation is changed or added (n/a — internal refactor, no public API
    or behavior change)
  • commit message follows commit guidelines

Fixes: #53867

run(), getRunArgs(), and runTestFile() reached into ambient process
state (process.execArgv, process.env, and process.env.NODE_TEST_CONTEXT)
from their bodies, which made the result of run() depend on the host
process. Capture references to process.execArgv and process.env once at
the run() boundary and thread them through the internal opts object, and
read the NODE_TEST_CONTEXT recursion guard once into a module-level
constant. Behavior is unchanged for the CLI and the programmatic run()
API, and no new public option is added.

Also add a regression test for the previously untested default
process.env inheritance path.

Fixes: nodejs#53867
Signed-off-by: Christopher Martínez <chrismartinez.2054@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_runner: do not read from process.argv and process.cwd() in run()

2 participants