fix: return full path in getTaskPath() instead of bare filename - #2971
fix: return full path in getTaskPath() instead of bare filename#2971Nithwin wants to merge 3 commits into
Conversation
os.(*FileInfo).Name() returns only the base filename ("task"),
not the path used to stat the file ("./bin/task"). This caused
exec.Command to search $PATH instead of using the locally-built
binary, making signal tests silently run against a system-installed
task binary rather than the one built from source.
Fix: store the path in a constant and return it directly when the
stat succeeds, ensuring the locally-built binary is always preferred.
|
@trulede Could you give me your review please. |
trulede
left a comment
There was a problem hiding this comment.
I make a suggestion, but otherwise fine.
| func getTaskPath() (string, error) { | ||
| if info, err := os.Stat("./bin/task"); err == nil { | ||
| return info.Name(), nil | ||
| const localTaskBin = "./bin/task" |
There was a problem hiding this comment.
I suggest this, with associated changes:
var sleepit, _ = filepath.Abs("./bin/sleepit")
var localTaskBinary, _ = filepath.Abs("./bin/task")
...
func TestSignalSentToProcessGroup(t *testing.T) {
task := localTaskBinary
if task == "" {
// Fallback to system task if local build doesn't exist
var err error
task, err = exec.LookPath("task")
if err != nil {
t.Fatal(err)
}
}
// ... rest of test
}
There was a problem hiding this comment.
Thanks for the suggestion! 👍
I've implemented your approach and it's much better.
|
FYI - Using "Squash and merge" when merging this PR would ensure the contribution shows up in the contributors list. Thanks! |
| ) | ||
|
|
||
| var SLEEPIT, _ = filepath.Abs("./bin/sleepit") | ||
| var localTaskBinary, _ = filepath.Abs("./bin/task") |
There was a problem hiding this comment.
Fix sleepit too, style matters.
| task, err := getTaskPath() | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| task := localTaskBinary |
There was a problem hiding this comment.
Now you don't check if the path exists? So the following code is not hit. Right?
This style is better when possible:
if task, err = exec.LookPath("task"); err != nil {
t.Fatal(err)
}
- Addressed review feedback by replacing global `filepath.Abs` variables with proper `exec.LookPath` existence checks for both local and system fallbacks. - Fixed a silent test failure introduced during Go 1.22 migration where `for range tc.sendSigs - 1` looped zero times and never actually sent SIGINT signals.
|
@trulede Thanks for catching that! You were totally right the path wasn't being checked for existence, so the fallback was never hit. I just pushed an update:
Thanks again for the help! |
Summary
Fixes #2970
Problem
In
signals_test.go,getTaskPath()usesos.Stat("./bin/task")and returnsinfo.Name(). TheFileInfo.Name()method only returns the base filename ("task"), not the path passed toos.Stat("./bin/task").This means
exec.Commandreceives"task"(bare name) and resolves it via$PATH, silently running signal tests against a system-installed binary instead of the locally-built one.Fix
Store the path in a constant and return it directly:
func getTaskPath() (string, error) { - if info, err := os.Stat("./bin/task"); err == nil { - return info.Name(), nil + const localTaskBin = "./bin/task" + if _, err := os.Stat(localTaskBin); err == nil { + return localTaskBin, nil }Testing
signals_test.go)os.FileInfo.Name()only returns the base filename per the Go standard library docs