Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions packages/ssh/src/tunnel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,56 @@ const localRemoteShellLayer = (home: string) =>
);

describe("ssh tunnel scripts", () => {
it.live("distinguishes an incompatible remote Node from a missing executable", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const home = yield* fs.makeTempDirectoryScoped({ prefix: "t3-ssh-node-" });
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
for (const missing of [false, true]) {
const nodeFixture = missing
? "command() { return 1; }; "
: 'node() { cat >/dev/null; printf "Remote node 18.20.8 does not satisfy required range >=999.0.0.\\n" >&2; return 1; }; ';
const remoteShell = ChildProcessSpawner.make((command) => {
if (command._tag !== "StandardCommand") return spawner.spawn(command);
return spawner.spawn(
ChildProcess.make(
"sh",
["-c", `${nodeFixture}eval "$(cat)"`, "sh", ...commandArgs(command).slice(-1)],
{
...command.options,
env: {
...command.options.env,
HOME: home,
NVM_DIR: NodePath.join(home, ".nvm"),
FNM_DIR: NodePath.join(home, ".fnm"),
VOLTA_HOME: NodePath.join(home, ".volta"),
},
},
),
);
});
const result = yield* SshTunnel.launchOrReuseRemoteServer(
{ alias: "devbox", hostname: "devbox", username: null, port: null },
undefined,
{ nodeScriptPath: "/unused/server.ts", nodeEngineRange: ">=999.0.0" },
).pipe(
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, remoteShell),
Effect.result,
);
assert.isTrue(Result.isFailure(result));
if (!Result.isFailure(result)) return;
assert.isTrue(isSshCommandError(result.failure));
if (!isSshCommandError(result.failure)) return;
assert.equal(result.failure.exitCode, 1);
assert.equal(result.failure.stderr.includes("missing node on PATH"), missing);
assert.equal(
result.failure.stderr.includes("does not satisfy required range >=999.0.0"),
!missing,
);
}
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
);

it("rejects archive versions that are not a single exact version segment", () => {
for (const archiveVersion of [
"../other",
Expand Down
4 changes: 3 additions & 1 deletion packages/ssh/src/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,9 @@ if [ "$T3_ARCHIVE_MODE" = "1" ]; then
# archive before the port and readiness probes rely on it.
"$RUNNER_NEXT" --version >/dev/null
elif ! ensure_remote_node_path; then
printf 'Remote host is missing node on PATH. Install Node or configure a supported version manager for non-interactive shells.\\n' >&2
if ! command -v node >/dev/null 2>&1; then
printf 'Remote host is missing node on PATH. Install Node or configure a supported version manager for non-interactive shells.\\n' >&2
fi
exit 1
fi
# Recovery runs under its own lock and re-reads the owner there, so a waiter
Expand Down
Loading