From ec2bc6504bcb0c43c663bc00d4ef7af7c2c40672 Mon Sep 17 00:00:00 2001 From: Bastiaan <17990055+bbassie@users.noreply.github.com> Date: Tue, 17 Nov 2026 11:44:17 +0100 Subject: [PATCH] Exit run scripts with the code that stopped the restart loop (#1212) run-controller.sh and run-host.sh ran `exit $?` after the `[[ ]]` test, so they exited with the test's status (0) even when the process exited with 8 to ask not to be restarted. Save the status before testing it. The .cmd scripts now pass 8 to `exit /b` explicitly instead of relying on a bare `exit /b` to carry the errorlevel through. Closes #1208. Co-authored-by: Claude Opus 5.5 --- packages/create/create.js | 10 ++++++---- test/create.js | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/create/create.js b/packages/create/create.js index 512dc389..37871bbe 100755 --- a/packages/create/create.js +++ b/packages/create/create.js @@ -446,7 +446,7 @@ set "NODE_OPTIONS=--enable-source-maps %NODE_OPTIONS%" :restart call .\\node_modules\\.bin\\clusteriocontroller.cmd run --can-restart if %errorlevel% equ 0 exit /b -if %errorlevel% equ 8 exit /b +if %errorlevel% equ 8 exit /b 8 goto restart ` ); @@ -458,7 +458,8 @@ goto restart export "NODE_OPTIONS=--enable-source-maps $NODE_OPTIONS" while true; do ./node_modules/.bin/clusteriocontroller run --can-restart - if [[ $? -eq 0 || $? -eq 8 ]]; then exit $?; fi + code=$? + if [[ $code -eq 0 || $code -eq 8 ]]; then exit $code; fi done `, { mode: 0o755 }, @@ -498,7 +499,7 @@ set "NODE_OPTIONS=--enable-source-maps %NODE_OPTIONS%" ${extraCaCertsLine}:restart call .\\node_modules\\.bin\\clusteriohost.cmd run --can-restart if %errorlevel% equ 0 exit /b -if %errorlevel% equ 8 exit /b +if %errorlevel% equ 8 exit /b 8 goto restart ` ); @@ -511,7 +512,8 @@ goto restart export "NODE_OPTIONS=--enable-source-maps $NODE_OPTIONS" ${extraCaCertsLine}while true; do ./node_modules/.bin/clusteriohost run --can-restart - if [[ $? -eq 0 || $? -eq 8 ]]; then exit $?; fi + code=$? + if [[ $code -eq 0 || $code -eq 8 ]]; then exit $code; fi done `, { mode: 0o755 }, diff --git a/test/create.js b/test/create.js index 36f0559c..9fa29e2d 100644 --- a/test/create.js +++ b/test/create.js @@ -195,6 +195,20 @@ describe("create installer CLI", function() { await fs.access(path.join(directory, `run-host${process.platform === "win32" ? ".cmd" : ".sh"}`)); }); + it("writes a run script that exits with the code that stopped the restart loop", async function() { + if (process.platform === "win32") { + this.skip(); + } + await run(hostArgs()); + const binDir = path.join(directory, "node_modules", ".bin"); + await fs.mkdir(binDir, { recursive: true }); + await fs.writeFile(path.join(binDir, "clusteriohost"), "#!/bin/sh\nexit 8\n", { mode: 0o755 }); + await assert.rejects( + execFileAsync(path.join(directory, "run-host.sh"), [], { cwd: directory }), + { code: 8 }, + ); + }); + it("adds the trailing slash the host requires to the controller URL", async function() { await run(hostArgs(controllerUrl.slice(0, -1))); assert((await commands()).includes(hostSet("host.controller_url", controllerUrl)));