Skip to content

Commit beaa647

Browse files
fix(ssh): distinguish incompatible Node from a missing executable (pingdotgg#35607)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 2ff2770 commit beaa647

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

‎packages/ssh/src/tunnel.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,56 @@ const localRemoteShellLayer = (home: string) =>
170170
);
171171

172172
describe("ssh tunnel scripts", () => {
173+
it.live("distinguishes an incompatible remote Node from a missing executable", () =>
174+
Effect.gen(function* () {
175+
const fs = yield* FileSystem.FileSystem;
176+
const home = yield* fs.makeTempDirectoryScoped({ prefix: "t3-ssh-node-" });
177+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
178+
for (const missing of [false, true]) {
179+
const nodeFixture = missing
180+
? "command() { return 1; }; "
181+
: 'node() { cat >/dev/null; printf "Remote node 18.20.8 does not satisfy required range >=999.0.0.\\n" >&2; return 1; }; ';
182+
const remoteShell = ChildProcessSpawner.make((command) => {
183+
if (command._tag !== "StandardCommand") return spawner.spawn(command);
184+
return spawner.spawn(
185+
ChildProcess.make(
186+
"sh",
187+
["-c", `${nodeFixture}eval "$(cat)"`, "sh", ...commandArgs(command).slice(-1)],
188+
{
189+
...command.options,
190+
env: {
191+
...command.options.env,
192+
HOME: home,
193+
NVM_DIR: NodePath.join(home, ".nvm"),
194+
FNM_DIR: NodePath.join(home, ".fnm"),
195+
VOLTA_HOME: NodePath.join(home, ".volta"),
196+
},
197+
},
198+
),
199+
);
200+
});
201+
const result = yield* SshTunnel.launchOrReuseRemoteServer(
202+
{ alias: "devbox", hostname: "devbox", username: null, port: null },
203+
undefined,
204+
{ nodeScriptPath: "/unused/server.ts", nodeEngineRange: ">=999.0.0" },
205+
).pipe(
206+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, remoteShell),
207+
Effect.result,
208+
);
209+
assert.isTrue(Result.isFailure(result));
210+
if (!Result.isFailure(result)) return;
211+
assert.isTrue(isSshCommandError(result.failure));
212+
if (!isSshCommandError(result.failure)) return;
213+
assert.equal(result.failure.exitCode, 1);
214+
assert.equal(result.failure.stderr.includes("missing node on PATH"), missing);
215+
assert.equal(
216+
result.failure.stderr.includes("does not satisfy required range >=999.0.0"),
217+
!missing,
218+
);
219+
}
220+
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
221+
);
222+
173223
it("rejects archive versions that are not a single exact version segment", () => {
174224
for (const archiveVersion of [
175225
"../other",

‎packages/ssh/src/tunnel.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,9 @@ if [ "$T3_ARCHIVE_MODE" = "1" ]; then
604604
# archive before the port and readiness probes rely on it.
605605
"$RUNNER_NEXT" --version >/dev/null
606606
elif ! ensure_remote_node_path; then
607-
printf 'Remote host is missing node on PATH. Install Node or configure a supported version manager for non-interactive shells.\\n' >&2
607+
if ! command -v node >/dev/null 2>&1; then
608+
printf 'Remote host is missing node on PATH. Install Node or configure a supported version manager for non-interactive shells.\\n' >&2
609+
fi
608610
exit 1
609611
fi
610612
# Recovery runs under its own lock and re-reads the owner there, so a waiter

0 commit comments

Comments
 (0)