Skip to content

Commit 8a1cbc9

Browse files
committed
fix(server): SSH device connection tests explain missing Node
1 parent 3da48c1 commit 8a1cbc9

2 files changed

Lines changed: 60 additions & 21 deletions

File tree

‎apps/server/src/device/DeviceService.test.ts‎

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,41 @@ const layerSecretResolver = Layer.succeed(SecretResolver.SecretResolver, {
611611
invalidate: () => Effect.void,
612612
});
613613

614-
it.effect.each([1, 9009])(
615-
"Test connection preserves Windows exit %s guidance across the wire",
616-
(exitCode) =>
614+
it.effect.each([
615+
{
616+
name: "Windows exit 1",
617+
exitCode: 1,
618+
windowsHost: true,
619+
stderr: "private SSH diagnostics",
620+
reason:
621+
"Connected over SSH, but this host runs Windows, and SSH device hosts currently need macOS or Linux. To use this machine's devices, run T3 Code on it and connect to that environment.",
622+
},
623+
{
624+
name: "Windows exit 9009",
625+
exitCode: 9009,
626+
windowsHost: true,
627+
stderr: "private SSH diagnostics",
628+
reason:
629+
"Connected over SSH, but this host runs Windows, and SSH device hosts currently need macOS or Linux. To use this machine's devices, run T3 Code on it and connect to that environment.",
630+
},
631+
{
632+
name: "missing Node on a POSIX host",
633+
exitCode: 1,
634+
windowsHost: false,
635+
stderr: "private SSH diagnostics\r\nNode is missing from the non-interactive SSH PATH\r\n",
636+
reason:
637+
"Connected over SSH, but Node is not on this host's PATH for non-interactive SSH commands.",
638+
},
639+
{
640+
name: "unrecognized POSIX failure",
641+
exitCode: 1,
642+
windowsHost: false,
643+
stderr: "private SSH diagnostics",
644+
reason: null,
645+
},
646+
])(
647+
"Test connection preserves $name guidance across the wire",
648+
({ exitCode, windowsHost, stderr, reason }) =>
617649
Effect.gen(function* () {
618650
const { host } = yield* fixture();
619651
const service = yield* DeviceService.make.pipe(
@@ -636,10 +668,14 @@ it.effect.each([1, 9009])(
636668
pid: ChildProcessSpawner.ProcessId(123),
637669
stdout: Stream.make(
638670
new TextEncoder().encode(
639-
config ? "hostname 192.0.2.1\nport 22\n" : windows ? "Windows_NT\r\n" : "",
671+
config
672+
? "hostname 192.0.2.1\nport 22\n"
673+
: windows && windowsHost
674+
? "Windows_NT\r\n"
675+
: "",
640676
),
641677
),
642-
stderr: Stream.make(new TextEncoder().encode("private SSH diagnostics")),
678+
stderr: Stream.make(new TextEncoder().encode(stderr)),
643679
all: Stream.empty,
644680
exitCode: Effect.succeed(
645681
ChildProcessSpawner.ExitCode(config || windows ? 0 : exitCode),
@@ -656,19 +692,19 @@ it.effect.each([1, 9009])(
656692
),
657693
);
658694
const error = yield* service
659-
.testHost({ kind: "ssh", id: "windows", label: "Windows test", target: "windows.test" })
695+
.testHost({ kind: "ssh", id: "remote", label: "SSH test", target: "remote.test" })
660696
.pipe(Effect.flip);
661-
expect(error).toMatchObject({
662-
_tag: "DeviceHostUnavailableError",
663-
hostId: "windows",
664-
hostLabel: "Windows test",
665-
reason:
666-
"Connected over SSH, but this host runs Windows, and SSH device hosts currently need macOS or Linux. To use this machine's devices, run T3 Code on it and connect to that environment.",
667-
});
697+
expect(error).toMatchObject(
698+
reason === null
699+
? { _tag: "DeviceOperationError", operation: "probe host", reason: "request_failed" }
700+
: { _tag: "DeviceHostUnavailableError", hostId: "remote", hostLabel: "SSH test", reason },
701+
);
668702
const codec = Schema.fromJsonString(DeviceError);
669703
const decoded = yield* Schema.decodeEffect(codec)(yield* Schema.encodeEffect(codec)(error));
670704
expect(decoded.message).toBe(
671-
"Windows test is unavailable: Connected over SSH, but this host runs Windows, and SSH device hosts currently need macOS or Linux. To use this machine's devices, run T3 Code on it and connect to that environment.",
705+
reason === null
706+
? "Device probe host failed: Could not communicate with device support. Try refreshing devices."
707+
: `SSH test is unavailable: ${reason}`,
672708
);
673709
expect(decoded.message).not.toContain("private SSH diagnostics");
674710
}).pipe(

‎apps/server/src/device/DeviceService.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ export const DEVICE_HUB_ROUTE_PREFIX = "/api/device-hub";
8484

8585
const isSshCommandError = Schema.is(SshCommandError);
8686

87+
const isSshNodeMissing = (cause: unknown) =>
88+
isSshCommandError(cause) &&
89+
cause.exitCode === 1 &&
90+
cause.stderr
91+
.split(/\r?\n/u)
92+
.some((line) => line.trim() === "Node is missing from the non-interactive SSH PATH");
93+
8794
const sshProbeFailureMessage = (error: DeviceHost.DeviceHostError): string => {
8895
const windows = SshDeviceHost.isSshWindowsHostError(error.cause) ? error.cause : null;
8996
const cause = windows ? windows.cause : error.cause;
@@ -96,12 +103,7 @@ const sshProbeFailureMessage = (error: DeviceHost.DeviceHostError): string => {
96103
return "Could not connect to this host over SSH.";
97104

98105
// Only the known bootstrap diagnostic is safe to expose as Node guidance.
99-
if (
100-
cause.exitCode === 1 &&
101-
cause.stderr
102-
.split(/\r?\n/u)
103-
.some((line) => line.trim() === "Node is missing from the non-interactive SSH PATH")
104-
)
106+
if (isSshNodeMissing(cause))
105107
return "Connected over SSH, but Node is not on this host's PATH for non-interactive SSH commands.";
106108
if (windows) return windows.message;
107109

@@ -1389,7 +1391,8 @@ export const make = Effect.gen(function* () {
13891391
return yield* SshDeviceHost.probe(host).pipe(Effect.provide(probeContext));
13901392
}).pipe(
13911393
Effect.mapError((error) =>
1392-
error._tag === "DeviceHostError" && SshDeviceHost.isSshWindowsHostError(error.cause)
1394+
error._tag === "DeviceHostError" &&
1395+
(SshDeviceHost.isSshWindowsHostError(error.cause) || isSshNodeMissing(error.cause))
13931396
? new DeviceHostUnavailableError({
13941397
hostId: host.id,
13951398
hostLabel: host.label,

0 commit comments

Comments
 (0)