fix(interactive): collect vars before checking visited to handle duplicate task calls

This commit is contained in:
Valentin Maerten
2025-12-13 13:16:37 +01:00
parent 647052aaab
commit bd166ff271
2 changed files with 25 additions and 63 deletions

View File

@@ -17,19 +17,13 @@ func (e *Executor) collectAllRequiredVars(calls []*Call) ([]*ast.VarsWithValidat
var collect func(call *Call) error
collect = func(call *Call) error {
// Avoid infinite loops
if visited[call.Task] {
return nil
}
visited[call.Task] = true
// Compile to resolve variables (also fetches the task)
// Always compile to resolve variables (also fetches the task)
compiledTask, err := e.FastCompiledTask(call)
if err != nil {
return err
}
// Collect required vars from this task
// Always collect required vars from this task
if compiledTask.Requires != nil {
for _, v := range compiledTask.Requires.Vars {
// Check if var is already set
@@ -42,6 +36,13 @@ func (e *Executor) collectAllRequiredVars(calls []*Call) ([]*ast.VarsWithValidat
}
}
// Only skip recursion if already visited (to avoid infinite loops)
// We already collected the vars above, so we're good
if visited[call.Task] {
return nil
}
visited[call.Task] = true
// Recurse into deps
for _, dep := range compiledTask.Deps {
depCall := &Call{

View File

@@ -1,66 +1,27 @@
version: "3"
# Test case for the visited bug:
# - build is called twice with different vars
# - First call provides TARGET, second doesn't
# - BUG: we should prompt for TARGET but we don't
tasks:
main:
desc: Main task with nested deps
desc: Main task that calls build twice with different vars
deps:
- dep-a
- dep-b
- task: build
- task: build
cmds:
- echo "Main task done!"
- echo "Main done"
dep-a:
desc: Dependency A
deps:
- leaf-a1
- leaf-a2
cmds:
- echo "Dep A done"
dep-b:
desc: Dependency B
deps:
- leaf-b1
- leaf-b2
cmds:
- echo "Dep B done"
leaf-a1:
desc: Leaf A1 with enum
build:
desc: Build task requiring TARGET
requires:
vars:
- name: VAR_A1
- name: TARGET
enum:
- alpha
- beta
- gamma
- linux
- windows
- darwin
cmds:
- echo "Leaf A1 {{.VAR_A1}}"
leaf-a2:
desc: Leaf A2 with text
requires:
vars:
- VAR_A2
cmds:
- echo "Leaf A2 {{.VAR_A2}}"
leaf-b1:
desc: Leaf B1 with enum
requires:
vars:
- name: VAR_B1
enum:
- one
- two
- three
cmds:
- echo "Leaf B1 {{.VAR_B1}}"
leaf-b2:
desc: Leaf B2 with text
requires:
vars:
- VAR_B2
cmds:
- echo "Leaf B2 {{.VAR_B2}}"
- echo "Building for target = {{.TARGET}} (mode={{.MODE}})"