Skip to content

Commit d6063b5

Browse files
committed
fix(ssh): distinguish incompatible Node from a missing executable
1 parent 91f55d9 commit d6063b5

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,47 @@ const localRemoteShellLayer = (home: string) =>
165165
);
166166

167167
describe("ssh tunnel scripts", () => {
168+
it.live("distinguishes an incompatible remote Node from a missing executable", () =>
169+
Effect.gen(function* () {
170+
const fs = yield* FileSystem.FileSystem;
171+
const home = yield* fs.makeTempDirectoryScoped({ prefix: "t3-ssh-node-" });
172+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
173+
for (const missing of [false, true]) {
174+
const nodeFixture = missing
175+
? 'command() { [ "$*" != "-v node" ] && type "$2"; }; '
176+
: 'node() { cat >/dev/null; printf "Remote node 18.20.8 does not satisfy required range >=999.0.0.\\n" >&2; return 1; }; ';
177+
const remoteShell = ChildProcessSpawner.make((command) => {
178+
if (command._tag !== "StandardCommand") return spawner.spawn(command);
179+
return spawner.spawn(
180+
ChildProcess.make(
181+
"sh",
182+
["-c", `${nodeFixture}eval "$(cat)"`, "sh", ...commandArgs(command).slice(-1)],
183+
{ ...command.options, env: { ...command.options.env, HOME: home } },
184+
),
185+
);
186+
});
187+
const result = yield* SshTunnel.launchOrReuseRemoteServer(
188+
{ alias: "devbox", hostname: "devbox", username: null, port: null },
189+
undefined,
190+
{ nodeScriptPath: "/unused/server.ts", nodeEngineRange: ">=999.0.0" },
191+
).pipe(
192+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, remoteShell),
193+
Effect.result,
194+
);
195+
assert.isTrue(Result.isFailure(result));
196+
if (!Result.isFailure(result)) return;
197+
assert.isTrue(isSshCommandError(result.failure));
198+
if (!isSshCommandError(result.failure)) return;
199+
assert.equal(result.failure.exitCode, 1);
200+
assert.equal(result.failure.stderr.includes("missing node on PATH"), missing);
201+
assert.equal(
202+
result.failure.stderr.includes("does not satisfy required range >=999.0.0"),
203+
!missing,
204+
);
205+
}
206+
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
207+
);
208+
168209
it("rejects archive versions that are not a single exact version segment", () => {
169210
for (const archiveVersion of [
170211
"../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)