ssh: say why when there is no shell to run
CI / test (push) Successful in 3m34s
Release / release (push) Successful in 5m4s

The published container image has no shell, so a session used to end at once with
nothing printed for a command. It now explains that, and what to do about it,
and exits with status 127.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
VeillaxandClaude Sonnet 5.5 committed 2026-10-31 02:04:28 -06:00
1 parent a2403ecf9d
commit 79bd4d8646
2 files changed
+37

No files matched your search

+29
View File
@@ -82,3 +82,32 @@ func TestShell(t *testing.T) {
t.Fatalf("got %q, %v", out.String(), err)
}
}
// A machine with no shell (the published container image is one) must say so, not just hang up.
func TestNoShellIsExplained(t *testing.T) {
t.Setenv("SHELL", "/nonexistent/shell")
for name, usePty := range map[string]bool{"exec": false, "pty shell": true} {
s, done := session(t)
var stderr, stdout strings.Builder
s.Stderr, s.Stdout = &stderr, &stdout
var err error
if usePty {
if err = s.RequestPty("xterm", 24, 80, ssh.TerminalModes{}); err == nil {
err = s.Shell()
if err == nil {
err = s.Wait()
}
}
} else {
err = s.Run("true")
}
done()
var ee *ssh.ExitError
if !errors.As(err, &ee) || ee.ExitStatus() != 127 {
t.Errorf("%s: want exit status 127, got %v", name, err)
}
if !strings.Contains(stderr.String()+stdout.String(), "no shell to run") {
t.Errorf("%s: no explanation (stderr %q, stdout %q)", name, stderr.String(), stdout.String())
}
}
}