Skip to content

fix(templates): don't suggest a different variable for an unset Worktrunk variable - #4440

Merged
max-sixty merged 1 commit into
mainfrom
nightly/clean-38215348500-vars
Oct 13, 2026
Merged

max-sixty merged 1 commit into
mainfrom
nightly/clean-38215348500-vars

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

When a template reads a Worktrunk variable that the current operation left unset, the undefined-variable error no longer offers a "Did you mean" suggestion. Before this change it suggested a similarly named variable, which points the user at a different value.

The reachable case is a post-switch hook containing echo {{ target }}, run when switching to a detached worktree. TemplateVars::for_post_switch leaves target unset there but sets target_worktree_path. Rendering fails with undefined variable target, and #4350's suggestion logic matched target_worktree_path (Jaro–Winkler ≈ 0.86, above the 0.7 cutoff). The right fix for the user is a {% if target %} guard, not a rename. base / base_worktree_path have the same shape.

build_undefined_vars_error now skips the suggestion when the missing name is in vars_available_in for some hook scope. Typos of real names (brnch → branch) still get the hint, and the "Available variables" list is unchanged.

test_unset_worktrunk_variable_gets_no_suggestion failed before the fix (Some("target_worktree_path")) and passes now. The existing suggestion tests in config::expansion and the template-related integration tests also pass.

…runk variable

A post-switch hook that reads {{ target }} fails when switching to a
detached worktree, because the operation leaves target unset. The
undefined-variable error then suggested target_worktree_path, steering
the user to a different value instead of a {% if target %} guard. Skip
the suggestion when the missing name is one Worktrunk defines in some
scope; the Did-you-mean hint stays for genuine typos.
@worktrunk-bot worktrunk-bot added the nightly-cleanup Issues found by nightly code quality sweep label Oct 12, 2026
@max-sixty
max-sixty merged commit e0a564e into main Oct 13, 2026
37 of 47 checks passed
@max-sixty
max-sixty deleted the nightly/clean-38215348500-vars branch October 13, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nightly-cleanup Issues found by nightly code quality sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants