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
9 changes: 9 additions & 0 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ func Start(cfg Config) (*Runner, error) {
if _, err := exec.LookPath(cfg.Command); err != nil {
return nil, fmt.Errorf("agent %q not found on PATH: %w", cfg.Command, err)
}
// Checked here because the PTY start cannot say it. pty.StartWithSize sets
// SysProcAttr, and with that set os.StartProcess skips its own check of the
// directory, so a missing one is reported as "fork/exec <command>: no such
// file or directory", which blames an executable that is there.
if cfg.Dir != "" {
if _, err := os.Stat(cfg.Dir); err != nil {
return nil, fmt.Errorf("start %s: session directory: %w", cfg.Command, err)
}
}

cmd := exec.Command(cfg.Command, cfg.Args...)
cmd.Dir = cfg.Dir
Expand Down
17 changes: 17 additions & 0 deletions internal/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package agent

import (
"os"
"path/filepath"
"strings"
"testing"
"time"
Expand All @@ -22,6 +23,22 @@ func screenContains(t *testing.T, r *Runner, want string, timeout time.Duration)
return false
}

// TestStartNamesAMissingDirectory: a session whose directory is gone says so.
// Through a PTY the start itself reports it as "fork/exec <command>: no such
// file or directory", which sent the reader looking for an executable that was
// there all along.
func TestStartNamesAMissingDirectory(t *testing.T) {
dir := filepath.Join(t.TempDir(), "gone")
r, err := Start(Config{Command: "bash", Dir: dir, Width: 80, Height: 24})
if err == nil {
r.Stop()
t.Fatal("started in a directory that does not exist")
}
if !strings.Contains(err.Error(), dir) || strings.Contains(err.Error(), "fork/exec") {
t.Errorf("err = %q, want it to name %s rather than the executable", err, dir)
}
}

func TestRunnerShowsOutput(t *testing.T) {
r, err := Start(Config{
Command: "bash",
Expand Down
Loading