Skip to content

fix: reject removed commits prompt variable - #4066

Closed
fzlzjerry wants to merge 2 commits into
max-sixty:mainfrom
fzlzjerry:fix/2984-reject-commits-template
Closed

fzlzjerry wants to merge 2 commits into
max-sixty:mainfrom
fzlzjerry:fix/2984-reject-commits-template

Conversation

@fzlzjerry

Copy link
Copy Markdown

Fixes #2984.

Changes

  • Stop supplying the removed commits variable to commit/squash prompts and user/project append fragments. Parsed-template validation reports the affected setting, commit_details, and wt config update; literals, comments, local bindings, and unrelated variables remain unaffected.
  • Keep the retirement check and replacement mapping in the config-deprecation layer. Validation runs when building a prompt, not while loading config, so config show, config update, and unrelated commands can still work with an old config. The existing warning/update invariant and migration rule remain intact.
  • Preserve subject-only loops during migration through the existing CommitDetailValue rendering. Update the removal/recovery notes and generated help/config documentation. This implements the requested removal step, with no wall-clock check or reintroduction of the old name as an object alias.

Validation

  • cargo run -- hook pre-merge --yes: 4,868 tests passed with all features; the existing nightly-only crate-archive build test remains ignored. Pre-commit/clippy, Rust documentation, and doctests passed.
  • Regression coverage includes 22 primary/append-template cases, preview failure, real step squash and merge calls that neither invoke the configured generator nor change branch refs, and a config-update/render/idempotence test.
  • An independent old/new binary check confirms that migration preserves the prompt byte-for-byte. Rejected operations leave both refs and the generator call count unchanged; after migration, a real squash invokes that same recorder exactly once and retains the target branch.
  • Three targeted omission checks detect removal of either rendering guard or the migration entry; the restored source passes again.
  • Generated docs/help synchronization, Astro checks, 15 documentation-renderer tests, and the production docs build passed.

Linux validation used the pinned Rust 1.97 toolchain and Git 2.54.0, plus real bash/zsh/fish/Nushell/PowerShell test shells. The test process used the standard umask and dropped root's file-permission-bypass capabilities so the existing permission assertions were meaningful. The suite's explicit UID-based skips still apply. Native cross-platform CI is still separate from these local results.

Copilot AI lite review requested due to automatic review settings September 11, 2026 09:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Two points beyond the inline suggestions; the first is outside the diff.

squash_template's own doc comment still advertises the variable this PR removes. In src/config/user/sections.rs, the field documented as "Inline template for squash commit message prompt" carries /// Available variables: {{ commits }}, {{ target_branch }}, {{ branch }}, {{ repo }} immediately above #[serde(default, rename = "squash-template")]. That is the description schemars derives for the key and the first thing a reader of CommitGenerationConfig sees, so after this change it names the one variable that now hard-errors. One word (commit_details) fixes it — take it here, or say so and I'll push it.

The deprecation warning still calls commits "deprecated" while rendering now rejects it. The PR's own snapshot puts both lines in one run:

▲ User config: template variable commits is deprecated in favor of commit_details
↳ To see details, run wt config show; to apply updates, run wt config update
✗ Template commit.generation.squash-template uses removed variable commits; use commit_details (run wt config update)

The warning fires on every command that loads config, so a user who has not yet triggered a generation reads "deprecated in favor of" as "still works, migrate when convenient" — and then wt merge fails outright. DeprecationKind::TemplateVar is shared with four pairs that genuinely do still work at runtime (repo_root, worktree, …), so telling the retired one apart costs a payload on that variant or a separate kind. That cost is why this is a decision rather than a suggestion; the two lines contradicting each other in one terminal is the part worth deciding about.

Comment thread src/config/deprecation.rs
let (old, new) = RETIRED_COMMITS_VAR;
if template.undeclared_variables(false).contains(old) {
anyhow::bail!(cformat!(
"Template <bold>{location}</> uses removed variable <bold>{old}</>; use <bold>{new}</> (run <bold>wt config update</>)"

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.

The recovery command lands inside a trailing parenthetical, so the closing paren sits against the string the user has to copy. .claude/skills/writing-user-outputs/SKILL.md gives the shape for this case — "Description + command in single message" (join with a semicolon, <bold> for the command in warnings/errors) and "End with the command for easy copying":

Suggested change
"Template <bold>{location}</> uses removed variable <bold>{old}</>; use <bold>{new}</> (run <bold>wt config update</>)"
"Template <bold>{location}</> uses removed variable <bold>{old}</>; replace it with <bold>{new}</>, or run <bold>wt config update</>"

Four snapshots pin this string — three inline in src/llm.rs and the renamed …__step_squash_show_prompt_removed_commits_errors.snap — so this needs a cargo insta test --accept pass.

Comment on lines +185 to +186
Run `wt config update` to migrate existing configuration; a loop that prints each element directly keeps producing its subject.
This removal takes effect with the release containing it, not by checking the current date. Older binaries retain their previous behavior.

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.

This line answers the issue's "after 2026-09-06" framing rather than a question a reader of the docs has: nothing in Worktrunk ever gated a template variable on the calendar, so "not by checking the current date" introduces a mechanism only to deny it, and "older binaries retain their previous behavior" is true of every change in every release. The two lines above it already carry what a user needs — what is gone and how to migrate.

Suggested change
Run `wt config update` to migrate existing configuration; a loop that prints each element directly keeps producing its subject.
This removal takes effect with the release containing it, not by checking the current date. Older binaries retain their previous behavior.
Run `wt config update` to migrate existing configuration; a loop that prints each element directly keeps producing its subject.

This page is the primary, so the two generated mirrors follow from cargo test --test integration test_docs_are_in_sync.

@max-sixty

Copy link
Copy Markdown
Owner

@worktrunk-bot can you implement this afresh? just remove the deprecated behavior

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Done — #4080 implements it afresh, with none of this PR's validation/error machinery.

The removal is in the renderer: build_prompt supplies only commit_details, to the squash template and to the append fragments. The commits → commit_details rename stays, but moves to a Structural row in src/config/deprecation.rs, so it is applied every time config loads rather than only by wt config update. That's what keeps an unmigrated squash template rendering its commit list — build_prompt uses minijinja's default UndefinedBehavior::Lenient, which iterates an undefined value as an empty sequence, so a bare removal would have dropped the commit list from the prompt silently. The warning and the wt config update rewrite are unchanged, and the existing test_step_squash_show_prompt_deprecated_commits_warns snapshot is byte-identical on the branch.

If you'd rather the old name stop resolving at all, that's now one line — deleting the RETIRED_VARS row — and I'll push it on request.

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.

Turn deprecated commits squash template variable into an error (after 2026-09-06)

4 participants