From 78c9a556e0bd920ba1740a8a96539293afef62ca Mon Sep 17 00:00:00 2001 From: qingyingliu Date: Fri, 26 Jun 2026 09:53:36 -0700 Subject: [PATCH] fix: reject include without taskfile or dir --- task_test.go | 19 +++++++++++++++++++ taskfile/ast/include.go | 4 ++++ .../includes_missing_taskfile/Taskfile.yml | 5 +++++ 3 files changed, 28 insertions(+) create mode 100644 testdata/includes_missing_taskfile/Taskfile.yml diff --git a/task_test.go b/task_test.go index 80915c2c47..449eb87ae0 100644 --- a/task_test.go +++ b/task_test.go @@ -1082,6 +1082,25 @@ func TestIncludesIncorrect(t *testing.T) { assert.Contains(t, err.Error(), "Failed to parse testdata/includes_incorrect/incomplete.yml:", err.Error()) } +func TestIncludesMissingTaskfile(t *testing.T) { + t.Parallel() + + const dir = "testdata/includes_missing_taskfile" + + var buff bytes.Buffer + e := task.NewExecutor( + task.WithDir(dir), + task.WithStdout(&buff), + task.WithStderr(&buff), + task.WithSilent(true), + ) + + err := e.Setup() + require.Error(t, err) + assert.Contains(t, err.Error(), "include must specify taskfile or dir") + assert.NotContains(t, err.Error(), "include cycle detected") +} + func TestIncludesEmptyMain(t *testing.T) { t.Parallel() diff --git a/taskfile/ast/include.go b/taskfile/ast/include.go index 18090b662d..64432c1949 100644 --- a/taskfile/ast/include.go +++ b/taskfile/ast/include.go @@ -2,6 +2,7 @@ package ast import ( "iter" + "strings" "sync" "github.com/elliotchance/orderedmap/v3" @@ -171,6 +172,9 @@ func (include *Include) UnmarshalYAML(node *yaml.Node) error { if err := node.Decode(&includedTaskfile); err != nil { return errors.NewTaskfileDecodeError(err, node) } + if strings.TrimSpace(includedTaskfile.Taskfile) == "" && strings.TrimSpace(includedTaskfile.Dir) == "" { + return errors.NewTaskfileDecodeError(nil, node).WithMessage("include must specify taskfile or dir") + } include.Taskfile = includedTaskfile.Taskfile include.Dir = includedTaskfile.Dir include.Optional = includedTaskfile.Optional diff --git a/testdata/includes_missing_taskfile/Taskfile.yml b/testdata/includes_missing_taskfile/Taskfile.yml new file mode 100644 index 0000000000..1832c2eea7 --- /dev/null +++ b/testdata/includes_missing_taskfile/Taskfile.yml @@ -0,0 +1,5 @@ +version: '3' + +includes: + GOBIN: + sh: echo $(go env GOPATH)/bin