Skip to content

fix: return full path in getTaskPath() instead of bare filename - #2971

Closed
Nithwin wants to merge 1 commit into
go-task:mainfrom
Nithwin:fix/signals-test-get-task-path
Closed

fix: return full path in getTaskPath() instead of bare filename#2971
Nithwin wants to merge 1 commit into
go-task:mainfrom
Nithwin:fix/signals-test-get-task-path

Conversation

@Nithwin

@Nithwin Nithwin commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2970

Problem

In signals_test.go, getTaskPath() uses os.Stat("./bin/task") and returns info.Name(). The FileInfo.Name() method only returns the base filename ("task"), not the path passed to os.Stat ("./bin/task").

This means exec.Command receives "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

  • The fix is in the test file itself (signals_test.go)
  • Verified that os.FileInfo.Name() only returns the base filename per the Go standard library docs

@Nithwin

Nithwin commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

@trulede Could you give me your review please.

@trulede trulede left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I make a suggestion, but otherwise fine.

Comment thread signals_test.go Outdated
func getTaskPath() (string, error) {
if info, err := os.Stat("./bin/task"); err == nil {
return info.Name(), nil
const localTaskBin = "./bin/task"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! 👍

I've implemented your approach and it's much better.

@Nithwin
Nithwin requested a review from trulede August 13, 2026 16:23
@Nithwin

Nithwin commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

FYI - Using "Squash and merge" when merging this PR would ensure the contribution shows up in the contributors list. Thanks!

Comment thread signals_test.go Outdated
)

var SLEEPIT, _ = filepath.Abs("./bin/sleepit")
var localTaskBinary, _ = filepath.Abs("./bin/task")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix sleepit too, style matters.

Comment thread signals_test.go Outdated
task, err := getTaskPath()
if err != nil {
t.Fatal(err)
task := localTaskBinary

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
}

@Nithwin

Nithwin commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

@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:

  1. I used exec.LookPath for both task and sleepit so the style is consistent. If the local binaries don't exist, it now properly falls back to the system ones.
  2. I also fixed a bug I found while testing: for range tc.sendSigs - 1 was causing the loop to run 0 times, so the tests weren't even sending the signals! I changed it to for range tc.sendSigs and the tests pass properly now.

Thanks again for the help!
Looking forward to learn more from you

@Nithwin
Nithwin requested a review from trulede August 14, 2026 06:30

@trulede trulede left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest starting again. This is going nowhere.

Just fix the original problem.

@Nithwin
Nithwin force-pushed the fix/signals-test-get-task-path branch from 0fdaafe to dfa702a Compare August 15, 2026 08:29
@Nithwin

Nithwin commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

@trulede I've reset the branch and pushed a single minimal commit that directly fixes #2970 by returning filepath.Abs("./bin/task") in getTaskPath() instead of info.Name().

Thanks for the feedback!

@Nithwin
Nithwin requested a review from trulede August 15, 2026 08:31
@trulede

trulede commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

What agent do you use to write this?

I suggest to put the original code into google.ai and look at what it suggests, and then really think about which of those suggestions is the best. And more importantly, if they are better than what you currently have.

@pd93

pd93 commented Aug 15, 2026

Copy link
Copy Markdown
Member

I'm closing this PR as it doesn't follow our contribution guidelines. Please refer to our AI usage policy.

@pd93 pd93 closed this Aug 15, 2026
@Nithwin
Nithwin deleted the fix/signals-test-get-task-path branch August 15, 2026 13:36
@Nithwin

Nithwin commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

Thank you so much for your feedback! It helped me realize that I have been overly dependent on AI. I will ensure to solve future problems myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getTaskPath() in signals_test.go returns bare filename instead of full path

3 participants