From c9deb8fdfd312034ba6ed5c1d81b1429eaeda27b Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 03:07:13 +0000 Subject: [PATCH] fix(process): let Program.Find validate existing paths --- program.go | 10 +++++++--- program_test.go | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/program.go b/program.go index 4661efe..2bc76a1 100644 --- a/program.go +++ b/program.go @@ -44,12 +44,16 @@ type Program struct { // // if err := p.Find(); err != nil { return err } func (p *Program) Find() error { - if p.Name == "" { + target := p.Name + if target == "" { + target = p.Path + } + if target == "" { return coreerr.E("Program.Find", "program name is empty", nil) } - path, err := exec.LookPath(p.Name) + path, err := exec.LookPath(target) if err != nil { - return coreerr.E("Program.Find", core.Sprintf("%q: not found in PATH", p.Name), ErrProgramNotFound) + return coreerr.E("Program.Find", core.Sprintf("%q: not found in PATH", target), ErrProgramNotFound) } p.Path = path return nil diff --git a/program_test.go b/program_test.go index 9627691..0f89097 100644 --- a/program_test.go +++ b/program_test.go @@ -2,6 +2,7 @@ package process_test import ( "context" + "os/exec" "path/filepath" "testing" "time" @@ -32,6 +33,15 @@ func TestProgram_Find_UnknownBinary(t *testing.T) { assert.ErrorIs(t, err, process.ErrProgramNotFound) } +func TestProgram_Find_UsesExistingPath(t *testing.T) { + path, err := exec.LookPath("echo") + require.NoError(t, err) + + p := &process.Program{Path: path} + require.NoError(t, p.Find()) + assert.Equal(t, path, p.Path) +} + func TestProgram_Find_EmptyName(t *testing.T) { p := &process.Program{} require.Error(t, p.Find())