From 7c56ad302281f78cb6e5af4f56aaca97cd3a42b9 Mon Sep 17 00:00:00 2001 From: Archkon <180910180+Archkon@users.noreply.github.com> Date: Sun, 2 Aug 2026 15:33:44 +0800 Subject: [PATCH] src: treat signal-terminated tasks as failures Check term_signal when handling task runner process exits so scripts terminated by a signal do not incorrectly report success. Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com> --- src/node_task_runner.cc | 2 +- test/fixtures/run-script/package.json | 1 + test/message/node_run_non_existent.out | 1 + test/parallel/test-node-run.js | 11 +++++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/node_task_runner.cc b/src/node_task_runner.cc index 22c02e83e12e..e06e8cc67382 100644 --- a/src/node_task_runner.cc +++ b/src/node_task_runner.cc @@ -197,7 +197,7 @@ void ProcessRunner::ExitCallback(uv_process_t* handle, } void ProcessRunner::OnExit(int64_t exit_status, int term_signal) { - if (exit_status > 0) { + if (exit_status != 0 || term_signal != 0) { init_result_->exit_code_ = ExitCode::kGenericUserError; } else { init_result_->exit_code_ = ExitCode::kNoFailure; diff --git a/test/fixtures/run-script/package.json b/test/fixtures/run-script/package.json index 138f47f2f974..edd3c33de414 100644 --- a/test/fixtures/run-script/package.json +++ b/test/fixtures/run-script/package.json @@ -11,6 +11,7 @@ "path-env-windows": "path-env.bat", "special-env-variables": "special-env-variables", "special-env-variables-windows": "special-env-variables.bat", + "signal-termination": "kill -TERM $$", "pwd": "pwd", "pwd-windows": "cd" } diff --git a/test/message/node_run_non_existent.out b/test/message/node_run_non_existent.out index 06b2ab0bb16a..0b60f9401dba 100644 --- a/test/message/node_run_non_existent.out +++ b/test/message/node_run_non_existent.out @@ -12,5 +12,6 @@ Available scripts are: path-env-windows: path-env.bat special-env-variables: special-env-variables special-env-variables-windows: special-env-variables.bat + signal-termination: kill -TERM $$ pwd: pwd pwd-windows: cd diff --git a/test/parallel/test-node-run.js b/test/parallel/test-node-run.js index e24117f6b165..464552a8fa5d 100644 --- a/test/parallel/test-node-run.js +++ b/test/parallel/test-node-run.js @@ -34,6 +34,17 @@ describe('node --run [command]', () => { assert.strictEqual(child.code, 1); }); + it('reports signal-terminated scripts as failures', { + skip: common.isWindows, + }, async () => { + const child = await common.spawnPromisified( + process.execPath, + [ '--run', 'signal-termination'], + { cwd: fixtures.path('run-script') }, + ); + assert.strictEqual(child.code, 1); + }); + it('adds node_modules/.bin to path', async () => { const child = await common.spawnPromisified( process.execPath,