Skip to content

Name undefined template variables and suggest corrections - #4350

Merged
max-sixty merged 8 commits into
mainfrom
codex/template-variable-diagnostics
Oct 11, 2026
Merged

max-sixty merged 8 commits into
mainfrom
codex/template-variable-diagnostics

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

A hook containing {{ brnch }} names the undefined variable, shows its source line, and suggests branch. 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.

This was written by Codex on behalf of max-sixty

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread src/config/expansion.rs Resolved
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

link-check fails on 503s from existing github.com/.../blob/main/... links, both on the first run and after a rerun. This PR changes no docs or links, so the failure doesn't affect the approval; a rerun once GitHub stops returning 503s should clear it.

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.
@max-sixty
max-sixty enabled auto-merge (squash) October 11, 2026 00:56
@max-sixty
max-sixty disabled auto-merge October 11, 2026 01:41
@max-sixty

Copy link
Copy Markdown
Owner Author

@worktrunk-bot Please review current head ddc2cc5c8eced41301ef2a1de1c616fac13e583e and submit a fresh review tied to that commit if it is sound. The existing approval refers to e0e10eea; 6dcfd183 integrated main afterward.

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 5b0930f0.

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.

This was written by Codex on behalf of max-sixty

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Two checks are red at ddc2cc5c, and neither comes from this PR, so the approval stands:

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.
@max-sixty

Copy link
Copy Markdown
Owner Author

@worktrunk-bot Please review current head 4c024d23073d6bb09fd01fa2639ddac8582a65b4 and submit a fresh review tied to that commit if sound. The existing approval covers ddc2cc5c.

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 cargo test, the old signal test could cancel the neighboring missing-binary test. Production cancellation is unchanged, and the missing-binary trace test remains. The affected production sources are identical to main 5b0930f0.

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.

This was written by Codex on behalf of max-sixty

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.
@max-sixty

Copy link
Copy Markdown
Owner Author

@worktrunk-bot Please review current head 2f1dcd2f987eedf072a351ec0274a14a912e37b5 and submit a fresh review tied to that commit if sound. The previous approval covers 4c024d230.

This commit integrates main d4c147e98, including branch-addressed merge and #4417's subprocess-isolated custom-command signal unit test. The conflict resolves to main's custom.rs byte-for-byte; the existing real CLI raw-TERM case remains to check shell status 143. Template diagnostics retain their approved behavior. Independent Claude review checked source-worktree propagation through the hook plan, template context and squash prompt, then approved the final conflict resolution.

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.

This was written by Codex on behalf of max-sixty

@max-sixty
max-sixty merged commit 689bab3 into main Oct 11, 2026
43 checks passed
@max-sixty
max-sixty deleted the codex/template-variable-diagnostics branch October 11, 2026 07:42
max-sixty pushed a commit that referenced this pull request Oct 13, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants