Skip to content

Fix wails3 task variable injection#5135

Open
symball wants to merge 5 commits intowailsapp:masterfrom
symball:task_call_vars
Open

Fix wails3 task variable injection#5135
symball wants to merge 5 commits intowailsapp:masterfrom
symball:task_call_vars

Conversation

@symball
Copy link
Copy Markdown
Contributor

@symball symball commented Apr 12, 2026

Description

call.Vars is not visible at the top level so, also make use of e.Taskfile.Vars to make sure variables are injected earlier in the lifecycle

There is a bug where variables were not properly being forwarded from wails3 task ...

This PR is additive to also make use of a variable declaration section that is visible to the whole Taskfile

Fixes # (issue)

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

The fastest way to test this bug (without even needing to modify wails at all) is:

Step 1

  • open one of the Taskfiles relevant to your platform (for example build/darwin/Taskfile.yml)
  • add a var such as DEBUG_MODE: '{{default "false" .DEBUG_MODE}}'.
  • Replace the contents of the run task with
- |
        if [ "{{.DEBUG_MODE}}" = "true" ]; then
          echo "Running in debug mode"
        else
          echo "Running in normal mode"
        fi

Step 2

  • Open the atterpac/refresh config for your project and modify the execution list (comment out tasks unimportant for the test) and add the debug mode property as shown below
  executes:
#    - cmd: wails3 build DEV=true
#      type: blocking
#    - cmd: wails3 task common:dev:frontend
#      type: background
    - cmd: wails3 task run DEBUG_MODE=true
      type: primary

Step 3

Run wails3 dev

Summary by CodeRabbit

  • Bug Fixes
    • Fixed handling of CLI variables passed as KEY=VALUE so they are properly initialized and included in the task’s variable set. CLI-specified variables now propagate consistently during task execution, ensuring values provided on the command line are available to tasks and related runtime processing.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7a9df9ee-cc3c-4ab0-b301-bb5178c41fad

📥 Commits

Reviewing files that changed from the base of the PR and between 00dfde7 and 07f5bc3.

📒 Files selected for processing (2)
  • v3/UNRELEASED_CHANGELOG.md
  • v3/internal/commands/task.go
✅ Files skipped from review due to trivial changes (1)
  • v3/UNRELEASED_CHANGELOG.md

Walkthrough

Ensures CLI KEY=VALUE variables are initialized and propagated into the Taskfile-level vars when running a task: Taskfile.Vars is created if nil and parsed CLI variables are written into both e.Taskfile.Vars and call.Vars.

Changes

Cohort / File(s) Summary
CLI Variable Propagation
v3/internal/commands/task.go
Initialize e.Taskfile.Vars when nil; on parsing CLI KEY=VALUE args, write variables into both call.Vars and e.Taskfile.Vars (guarded by e.Taskfile != nil).
Changelog
v3/UNRELEASED_CHANGELOG.md
Replaced placeholder with a bullet noting the fix for CLI KEY=VALUE variable handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

Suggested labels

cli, v3-alpha

Poem

🐇 I parsed the keys at morning light,

I tucked them in Taskfile, snug and tight,
From CLI to call they gently glide,
So every task has what it needs inside,
Hop, tasks—run true into the night!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is largely incomplete. It lacks proper issue reference format (Fixes # should have a number), missing test platform checkboxes, and incomplete checklist items. Fill in the issue number after 'Fixes #', check appropriate testing platforms (Windows/macOS/Linux), include wails doctor output, and complete the checklist items including changelog and documentation updates.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main bug fix: improving variable injection for wails3 tasks by ensuring variables are propagated through the Taskfile object.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

🔧 OpenGrep (1.17.0)
v3/internal/commands/task.go

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
v3/internal/commands/task.go (1)

175-186: Consider centralizing CLI var propagation to reduce drift risk.

The dual writes at Line 179 and Line 183 are correct, but this parsing behavior is mirrored elsewhere (e.g., parseTaskCall in tests). A small local helper here would make future updates safer.

Refactor sketch
+	setParsedVar := func(key, value string) {
+		call.Vars.Set(key, ast.Var{Value: value})
+		if e.Taskfile != nil {
+			e.Taskfile.Vars.Set(key, ast.Var{Value: value})
+		}
+	}
+
 	for _, v := range cliVars {
 		if strings.Contains(v, "=") {
 			parts := strings.SplitN(v, "=", 2)
 			if len(parts) == 2 {
-				call.Vars.Set(parts[0], ast.Var{
-					Value: parts[1],
-				})
-				if e.Taskfile != nil {
-					e.Taskfile.Vars.Set(parts[0], ast.Var{
-						Value: parts[1],
-					})
-				}
+				setParsedVar(parts[0], parts[1])
 			}
 		}
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@v3/internal/commands/task.go` around lines 175 - 186, Centralize the CLI var
parsing/propagation by extracting the repeated logic in the loop over cliVars
into a small helper (e.g., parseAndPropagateCLIVar or setCLIVar) that takes the
raw var string (or key/value), the Call object (call.Vars.Set) and the
executor/context (e.Taskfile) and performs the split-on-"=" check and the two
Set calls; replace the inline block in the cliVars loop with a call to this
helper and update parseTaskCall test usages to call the same helper or mirror
its behavior so parsing logic is single-sourced.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@v3/internal/commands/task.go`:
- Around line 175-186: Centralize the CLI var parsing/propagation by extracting
the repeated logic in the loop over cliVars into a small helper (e.g.,
parseAndPropagateCLIVar or setCLIVar) that takes the raw var string (or
key/value), the Call object (call.Vars.Set) and the executor/context
(e.Taskfile) and performs the split-on-"=" check and the two Set calls; replace
the inline block in the cliVars loop with a call to this helper and update
parseTaskCall test usages to call the same helper or mirror its behavior so
parsing logic is single-sourced.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b7201ae7-c1f7-4f1d-9ec0-4f03d2ac59b0

📥 Commits

Reviewing files that changed from the base of the PR and between bb4fbf9 and 00dfde7.

📒 Files selected for processing (1)
  • v3/internal/commands/task.go

@atterpac
Copy link
Copy Markdown
Member

This looks good to me can you add the change to v3/UNRELEASED_CHANGELOG.md and I can approve

… of `e.Taskfile.Vars` to make sure variables are injected earlier in the lifecycle
@symball
Copy link
Copy Markdown
Contributor Author

symball commented Apr 14, 2026

Changelog has been updated

@leaanthony leaanthony changed the base branch from v3-alpha to master April 29, 2026 13:08
@leaanthony
Copy link
Copy Markdown
Member

Triaged by Wails PR Reviewer

This PR has been reviewed and accepted. Test sub-issues have been created for all platforms.

Head Ref OID: 08f2e3413385f07f99eb957a7610b5096b16ab6b


This comment serves as a signature that this PR has been triaged. Future runs will skip this PR based on the headRefOid.

@leaanthony
Copy link
Copy Markdown
Member

Tested on Windows — verdict: ✓ pass

  • Commit: 08f2e3413385f07f99eb957a7610b5096b16ab6b
  • Platform: Windows 11 (Hyper-V VM), Go 1.26.2 windows/amd64
  • Build: 27,743ms — successful
  • Unit tests: 6/6 passing (TestTaskParameterPassing + full commands package)
  • Smoke test: ✓ all 3 CLI variable injection scenarios pass

The Taskfile.Vars nil-guard and CLI var propagation work correctly on Windows.

@leaanthony
Copy link
Copy Markdown
Member

The CI "failure" on this run is a cancellation, not a test failure.

Run breakdown (run 24403404466):

Job Result
Run Go Tests v3 (ubuntu-latest, 1.24) ✅ success
Run Go Tests v3 (windows-latest, 1.24) ✅ success
Run Go Tests v3 (macos-latest, 1.24) ⚪ cancelled
v3 Build Results (aggregation) ❌ failure (because macOS was cancelled)

The macOS job checked out the code successfully but was cancelled during Setup Go — before any tests ran. The overall run conclusion is cancelled, not failure. This is not a code defect introduced by this PR.

For reference, the previous commit on this branch (0aad58bed3) had a fully green Build + Test v3 run.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants