Repository navigation
Name undefined template variables and suggest corrections - #4350
Conversation
worktrunk-bot
left a comment
There was a problem hiding this comment.
env.set_debug(true) in template_environment isn't needed for the new span-based diagnostics, and it attaches template source and locals to every render error. Details inline.
|
|
Name reached template typos and suggest available variables through the existing parser-backed visitor. Keep MiniJinja 2.x collection rendering and preserve defined filter inputs, while rejecting undefined inputs instead of silently filtering an empty string. Accept engine globals during validation and name missing top-level inputs as undefined variables.
|
@worktrunk-bot Please review current head The latest commit is a test-only repair: the hook-error composition snapshot strips ANSI so it checks the same error and gutter content with or without optional syntax highlighting. Production formatting is unchanged, and dedicated formatter snapshots still cover highlighting. The original no-default failure also reproduces on pristine main Validation: the focused snapshot passes with default features, no default features, and CLI support without highlighting. The full all-features suite passes all 5,248 tests (one skipped); Clippy, formatting, lockfile, doctests and rustdoc pass. An independent Claude review approves the repair. Please report any findings without pushing changes or merging.
|
|
Two checks are red at
|
Foreground cancellation intentionally reaches every active scope in one process. A signal-producing run_custom unit test could therefore cancel the parallel missing-binary unit test under cargo test. Move raw custom-child SIGTERM coverage to the existing CLI PTY matrix, where each invocation owns its cancellation state, and retain the spawn-failure trace test.
|
@worktrunk-bot Please review current head The latest commit moves raw custom-child SIGTERM coverage from an in-process unit test into the existing real CLI PTY matrix. Foreground cancellation intentionally affects every active scope in one process; under parallel Validation: the failing feature combination's complete CLI unit suite passes all 1,010 tests; all 11 CLI signal matrix cases pass, including raw custom TERM returning 143. The canonical project gate passes all 5,248 tests (one skipped), Clippy, formatting, lockfile, doctests and rustdoc. An independent Claude source review approves the repair without material downside. Please report findings without pushing changes or merging.
|
Integrate branch-addressed merge and the completed main signal-test isolation repair. Retain main's subprocess-isolated typed interruption unit test and the real CLI raw-TERM regression case; template diagnostics keep their approved behavior.
|
@worktrunk-bot Please review current head This commit integrates main Validation: the canonical project gate passes all 5,278 tests (one skipped), Clippy, formatting, lockfile, doctests and rustdoc. The no-default-features CLI unit suite passes all 1,011 tests, including the isolated signal and missing-binary tests. All 36 targeted branch-addressed merge and CLI signal cases pass. Please report findings without pushing changes or merging.
|
…runk variable (#4440) 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. Co-authored-by: worktrunk-bot <[email protected]>
A hook containing
{{ brnch }}names the undefined variable, shows its source line, and suggestsbranch. MiniJinja's failing expression span selects the reached output; compound expressions, nested values and locally bound names retain a general diagnostic when the missing input is ambiguous. Preflight validation uses MiniJinja's undeclared-variable analysis and accepts engine globals.Config migration and diagnostics share the existing AST visitor, and similarity suggestions have one shared implementation. MiniJinja stays on 2.x (minimum 2.24); compiled source-span support leaves the environment's runtime debug defaults unchanged.
Custom filters now reject undefined inputs instead of silently converting them to empty strings. This includes an absent optional value, such as
upstream, passed directly into a custom filter; guard it or supply a default. Defined non-string values retain their existing behavior.The CLI signal matrix also checks that raw SIGTERM from a custom child reaches the shell as status 143.
Validation: actual Claude full review found no material code downsides. All 48 defined-input/filter contrasts preserve output, all eight custom filters reject undefined input, and focused config and CLI regressions pass. Pinned Rust 1.98 project validation passed: 5,278 tests, Clippy, formatting, lockfile, doctests and rustdoc (one test skipped). The hook-error composition snapshot also passes with default features, no default features, and CLI support without syntax highlighting. The no-default-features CLI unit suite passes all 1,011 tests; all 11 real CLI signal cases pass, including raw SIGTERM.