diff --git a/nanobot/webui/remote_ssh.py b/nanobot/webui/remote_ssh.py index 5631bceae..e13cd2c86 100644 --- a/nanobot/webui/remote_ssh.py +++ b/nanobot/webui/remote_ssh.py @@ -159,13 +159,13 @@ async def run_check( await stop_process(process) if process.returncode == 0: break - # Windows sshd may report a missing command as 1. Match the - # quoted executable in cmd.exe's diagnostic, not its language. - first_line = stderr.partition(b"\n")[0] + # Windows sshd can return 1. Match the executable in cmd.exe's + # trailing one- or two-line diagnostic, after any login banner. + diagnostic = b"\n".join(stderr.splitlines()[-2:]) if not sudo and (process.returncode in {49, 127, 9009} or ( process.returncode == 1 and ( b"CommandNotFoundException" in stderr - or any(f"{quote}{executable}{quote}".encode() in first_line for quote in ("'", '"')) + or any(f"{quote}{executable}{quote}".encode() in diagnostic for quote in ("'", '"')) ) )): continue diff --git a/tests/webui/test_remote_instances.py b/tests/webui/test_remote_instances.py index e8c79b513..5136f8a68 100644 --- a/tests/webui/test_remote_instances.py +++ b/tests/webui/test_remote_instances.py @@ -1046,10 +1046,13 @@ async def test_probe_ignores_shell_banners_without_exposing_them(monkeypatch, ba (127, b"python3: not found", ""), (49, b"'python3' is not recognized as an internal or external command", ""), (1, b"'python3' is not recognized as an internal or external command", ""), + (1, b"Authorized users only.\r\n'python3' is not recognized as an internal or external command,\r\n" + b"operable program or batch file.\r\n", ""), (1, '"python3" 不是内部或外部命令'.encode(), ""), (1, b"FullyQualifiedErrorId : CommandNotFoundException", ""), (255, b"Permission denied (publickey).", "ssh_auth_failed"), - (1, b"Traceback (most recent call last):", "probe_failed"), + (1, b"Use 'python3' for authorized jobs.\r\nTraceback (most recent call last):\r\n" + b"RuntimeError: probe failed\r\n", "probe_failed"), ]) async def test_probe_only_retries_when_the_remote_interpreter_is_missing(monkeypatch, returncode, stderr, expected_error): data = {"port": 8765, "secret": "synthetic-root"}