fix(v3/wake): propagate included Taskfile vars so preconditions expand correctly#5613
fix(v3/wake): propagate included Taskfile vars so preconditions expand correctly#5613leaanthony wants to merge 2 commits into
Conversation
…d correctly
When wake resolves `includes:`, it cloned tasks into the parent Taskfile but
dropped the included file's top-level `vars:` block entirely. This caused any
template reference inside a cloned task's preconditions or commands — such as
`{{.CROSS_IMAGE}}` in the `linux:build:docker` precondition — to be rendered
literally rather than expanded. The unexpanded shell command also made the
precondition fail on a literal string, so cross-compilation via Docker was
completely broken even after running `wails3 task setup:docker`.
Three coordinated changes:
* parse/parse.go: inject the included file's top-level vars into each cloned
task's Vars map (included-file vars are defaults; task-own vars win).
* exec/runner.go: call parse.ExpandTemplates on both pc.Sh and pc.Msg before
executing the precondition shell check or formatting the error message.
* exec/exec.go: move mergeVars before checkPreconditions so the fully-merged
variable map is available for template expansion in preconditions.
Adds a regression test in parse_test.go that verifies top-level vars from an
included file propagate into all cloned tasks and that task-level vars still
take precedence.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughTwo variable-propagation fixes in the ChangesVariable propagation for includes and preconditions
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes wake’s Taskfile includes: handling so that variables defined at the top-level of an included Taskfile are available when executing the cloned, namespaced tasks—specifically enabling correct template expansion inside preconditions (e.g., {{.CROSS_IMAGE}}) and improving related error messages.
Changes:
- Propagate included Taskfile top-level
vars:into each cloned task during include resolution. - Expand templates in precondition
shandmsg, and ensure merged vars are available before precondition checks. - Add a regression test covering var propagation and precedence.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| v3/internal/wake/parse/parse.go | Injects included Taskfile vars into cloned tasks during ResolveIncludes. |
| v3/internal/wake/parse/parse_test.go | Adds a regression test ensuring included vars propagate and task vars still win. |
| v3/internal/wake/exec/runner.go | Expands templates in precondition shell commands/messages using a provided vars map. |
| v3/internal/wake/exec/exec.go | Computes merged vars before running preconditions so expansion has full context. |
Comments suppressed due to low confidence (1)
v3/internal/wake/exec/exec.go:214
mergeVars()is now executed before the up-to-date fast-path. Previously, tasks skipped byisUpToDate()avoided the (potentially non-trivial) fixed-point template expansion work inmergeVars(). If wake is frequently run with many cached tasks, this could introduce unnecessary overhead.
mergedVars := e.mergeVars(task, depVars)
if err := checkPreconditions(task, mergedVars); err != nil {
return err
}
if !e.Force && isUpToDate(task, e.Dir) {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if len(tfResolved.Vars) > 0 { | ||
| merged := make(map[string]*ast.Var, len(tfResolved.Vars)+len(cloned.Vars)) | ||
| for k, v := range tfResolved.Vars { | ||
| merged[k] = v | ||
| } | ||
| for k, v := range cloned.Vars { | ||
| merged[k] = v | ||
| } | ||
| cloned.Vars = merged | ||
| } |
There was a problem hiding this comment.
Good catch — fixed in 011f378. The injected included vars are now deep-copied (`vClone := *v`) just like `Task.Clone` does, so the in-place mutation in `ResolveVars`/`ResolveAllVarShells` no longer leaks across tasks that share an included file. Added a regression assertion (distinct pointers + mutation isolation) in `TestResolveIncludesInjectsTopLevelVarsIntoClonedTasks`.
…hed preconditionless tasks Address PR review feedback: - Deep-copy the included Taskfile's top-level vars when injecting them into cloned tasks (consistent with Task.Clone). Sharing *ast.Var by pointer let the in-place mutation in ResolveVars/ResolveAllVarShells leak across all tasks that include the same file. Regression test asserts distinct pointers and isolation under mutation. - Compute mergedVars lazily: tasks without preconditions that are up-to-date no longer pay for the fixed-point template expansion.
|
Addressed review feedback in 011f378:
|
Problem
When wake resolves
includes:, it clones tasks from the included Taskfile into the parent but silently drops the included file's top-levelvars:block. This caused two visible failures:{{.CROSS_IMAGE}}appeared literally in the error box instead of the image namewails-cross.docker image inspect {{.CROSS_IMAGE}}, which always fails regardless of whether the image exists. So even after runningwails3 task setup:docker, thelinux:build:dockertask would refuse to run.The same bug affects
darwin/Taskfile.ymlandwindows/Taskfile.yml, which also defineCROSS_IMAGEas a top-level var.Root cause
resolveIncludesinparse/parse.go(line 468) only copies tasks:mergeVarsat execution time has three sources: roottf.Vars,depVars, andtask.Vars. None of them contain the included file'sCROSS_IMAGE.Additionally,
checkPreconditionswas called beforemergeVarsran, and usedpc.Sh/pc.Msgraw without template expansion — so even if vars had been available, they wouldn't have been applied.Changes
parse/parse.goVarsinto each cloned task'sVarsmap. Task-own vars have higher priority.exec/runner.gocheckPreconditionsnow acceptsvars map[string]*ast.Varand callsparse.ExpandTemplateson bothpc.Shandpc.Msg.exec/exec.gomergeVarscall beforecheckPreconditionsso the merged variable map is available for expansion.parse/parse_test.goTesting
Summary by CodeRabbit