Skip to content

feat(config): add wt config alias show and dry-run subcommands - #2291

Merged
max-sixty merged 7 commits into
mainfrom
config-alias
Apr 18, 2026
Merged

max-sixty merged 7 commits into
mainfrom
config-alias

Conversation

@max-sixty

@max-sixty max-sixty commented Apr 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

Third PR in the series simplifying alias-control flags. Introduces wt config alias as the home for alias introspection and removes the --dry-run flag that lived on alias dispatch.

  • wt config alias show <name> — prints the configured template, source-labeled (user/project). Each step in a pipeline is rendered in a single gutter block with # <step-name> comment lines above named steps.
  • wt config alias dry-run <name> [-- args...] — parses the arguments with the same parser wt <alias> uses, renders templates against the execution-time context, and prints without running. Args after -- are forwarded verbatim, so wt config alias dry-run s -- target-branch previews exactly what wt s target-branch would run. Same layout as show; only the header verb differs (: vs would run:).
  • --dry-run removed from AliasOptions — both wt <alias> --dry-run and wt step <alias> --dry-run now return an actionable error pointing at the new subcommand. No deprecation period: top-level alias dispatch is recent, so cutover is acceptable.
  • Tab-completion completes alias names under show / dry-run.

Output format

○ Alias deploy (project) would run:
 ┃ # install
 ┃ npm install
 ┃ # build
 ┃ npm run build

The ○ Alias <name> (<source>) header matches the existing info_message style. Bolding the name (what the user typed) and tagging the source in parens keeps the invocation identifier visually primary. When both user and project define the same alias, both entries print back-to-back (user first, matching runtime execution order).

Design notes

  • The new subcommand reuses AliasOptions::parse as the source of truth for invocation parsing, so preview stays aligned with runtime. When user and project configs both define the alias, referenced_vars is unioned across entries so a flag binds if any template references it.
  • Templates referencing vars.* are shown unexpanded, mirroring the lazy execution path — those values are read from git config just before each step runs, potentially after earlier steps have set them. Syntax errors still surface up front.
  • wt step <alias> also breaks since both paths share AliasOptions::parse. That's fine — wt step <alias> has no forward-compat promise beyond the basic call.
  • AliasSource is promoted to pub(crate) with a label() helper so wt config alias and the alias runtime code read from one enum.

Navigating the diff

  • src/cli/config.rs — adds ConfigAliasCommand + the Alias variant on ConfigCommand.
  • src/commands/config/alias.rs — new module. handle_alias_show and handle_alias_dry_run share a format_entry helper; the verb: Option<&str> parameter is the only difference between show and dry-run output. render_preview replaces the old render_for_dry_run in alias dispatch.
  • src/commands/alias.rs — the --dry-run flag and its rendering branch are gone. The parser bails on --dry-run with a migration message pointing at the new subcommand; the bail sits after the -- literal-mode check, so wt alias -- --dry-run still forwards as positional.
  • src/completion.rs — alias_name_completer() mirrors the existing hook_command_name_completer pattern.
  • tests/integration_tests/step_alias.rs — existing --dry-run tests migrate to wt config alias dry-run, plus new coverage for show, unknown-alias suggestions, and the retired-flag error.
  • docs/content/extending.md — adds an "Inspecting and previewing" subsection.

Test plan

  • Full suite via wt hook pre-merge --yes (3271 tests, all passing)
  • cargo insta test --accept — all snapshots up to date
  • cargo test --test integration test_command_pages_and_skill_files_are_in_sync — docs synced
  • Manual verification: wt config alias show <name> and wt config alias dry-run <name> [-- args...] in a repo with mixed user/project aliases

This was written by Claude Code on behalf of Maximilian

max-sixty and others added 2 commits April 18, 2026 12:10
Introduce `wt config alias show <name>` (print the configured template,
source-labeled) and `wt config alias dry-run <name> [-- args...]` (render
the expansion for a specific invocation). The new subcommands pull the
preview / introspection surface off the alias dispatch path and give it a
natural home next to the rest of `wt config`.

Remove the `--dry-run` flag from `AliasOptions` — previously reachable as
`wt <alias> --dry-run` and `wt step <alias> --dry-run`. Both paths now
surface an actionable error pointing at the new subcommand (no deprecation
period: top-level alias dispatch is recent and cutover is acceptable).

Other changes:
- Tab-completion completes alias names under `show` / `dry-run`.
- `AliasSource` and a new `step_names_from_config` helper are promoted to
  shared utilities so `wt config alias`, the alias announcement, and the
  alias summary formatter read from one source.
- `render_for_dry_run` is gone; its lazy-expansion logic lives in
  `handle_alias_dry_run::render_preview`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Resolves conflicts with main's two major landings since the branch diverged:

- Global `-y`/`--yes` flag (PR #2279): `AliasOptions` no longer carries a
  `yes` field — approval skip comes from the top-level global. The post-alias
  `--yes` form now errors as an unknown flag, and post-alias `-y` falls into
  the positional-args branch.
- Approvals module split (PR #2282): `add_approvals` / `clear_approvals`
  moved from `hook_commands` into `src/commands/config/approvals.rs`.

The alias changes in this branch are compatible with both landings:
- `AliasOptions` drops both `dry_run` and `yes`, keeping only `name`, `vars`,
  and `positional_args`.
- `run_alias` uses `global_yes` from main's signature as the sole source for
  skipping approval.
- `--dry-run` remains a parser-level error pointing at
  `wt config alias dry-run <name>`.
- Existing `wt config alias dry-run` integration tests dropped the unused
  `-y` flag — dry-run never needs approval because it doesn't execute.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
worktrunk-bot
worktrunk-bot previously approved these changes Apr 18, 2026

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

CI failure on Linux is real and mechanical. The tests test_step_alias_dry_run and test_step_alias_dry_run_vars_across_steps were renamed to test_config_alias_dry_run{,_vars_across_steps} and their snapshots regenerated under the new names, but the old .snap files weren't removed. cargo insta test --unreferenced reject aborts on them.

error: aborting because of unreferenced snapshots
  tests/snapshots/integration__integration_tests__step_alias__step_alias_dry_run.snap
  tests/snapshots/integration__integration_tests__step_alias__step_alias_dry_run_vars_across_steps.snap

Fix:

git rm tests/snapshots/integration__integration_tests__step_alias__step_alias_dry_run.snap \
       tests/snapshots/integration__integration_tests__step_alias__step_alias_dry_run_vars_across_steps.snap

Happy to push this as a follow-up commit if you'd like.

@worktrunk-bot
worktrunk-bot dismissed their stale review April 18, 2026 19:47

CI failed — two unreferenced snapshot files from the rename need to be removed

- Drop two snapshots orphaned when the original `--dry-run` tests moved to
  `wt config alias dry-run` (insta --unreferenced reject caught these in CI).
- Add `test_config_alias_show_user_and_project` to exercise the multi-entry
  display path — triggers the inter-entry separator that the single-source
  snapshot tests skip.
- Add `test_config_alias_show_unknown_no_suggestions` to cover the empty-
  `did_you_mean` branch of `unknown_alias_error` — the existing unknown-name
  test uses a typo with a near match, always hitting the context-with-
  suggestions path.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
worktrunk-bot
worktrunk-bot previously approved these changes Apr 18, 2026
max-sixty and others added 2 commits April 18, 2026 15:04
Replace the two-line `name (source)` / `pipeline: ...` header with a
single info-style line and join all commands into one gutter block:

    ○ Alias deploy (project):
     ┃ # install
     ┃ npm install
     ┃ # build
     ┃ npm run build

`dry-run` keeps the same layout and only differs in the header verb
(`... would run:`), mirroring the pre-split `wt <alias> --dry-run`
output. Drops the redundant `(single command)` / `N unnamed steps`
fallback lines.

Co-Authored-By: Claude <[email protected]>
# Conflicts:
#	docs/content/extending.md
#	skills/worktrunk/reference/extending.md
#	src/commands/alias.rs
#	tests/integration_tests/step_alias.rs
#	tests/snapshots/integration__integration_tests__step_alias__step_alias_binds_space_separated_var.snap

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

CI is red on the merge commit with a compile error in src/commands/config/alias.rs:94. PR #2299 (now on main) changed referenced_vars_for_config to return anyhow::Result<BTreeSet<String>>, and the new call site here calls it without ? — so .extend() is fed the Result instead of the inner BTreeSet. Same message across lint/test (linux/macos/windows)/coverage.

Happy to push the ? as a follow-up if that helps.

Comment thread src/commands/config/alias.rs Resolved
@worktrunk-bot
worktrunk-bot dismissed their stale review April 18, 2026 22:27

CI failing — compile error from main merge (referenced_vars_for_config signature change not propagated)

max-sixty and others added 2 commits April 18, 2026 15:29
PR #2299 landed on main during my merge: `referenced_vars_for_config`
now returns `anyhow::Result<BTreeSet<String>>` and surfaces template
parse errors instead of silently skipping them. The dry-run call site
in `handle_alias_dry_run` needs `?` to unwrap before extending.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit c7b94a7 into main Apr 18, 2026
25 checks passed
@max-sixty
max-sixty deleted the config-alias branch April 18, 2026 23:00
max-sixty added a commit that referenced this pull request Apr 19, 2026
Routes `--KEY=VALUE` tokens based on what the template references.
Tokens whose `KEY` appears as `{{ KEY }}` in the alias bind to that
variable; everything else joins `{{ args }}`. Space form `--KEY VALUE`
is equivalent.

Key changes:
- Parser uses template reference introspection (via
`referenced_vars_for_config`) to decide binding at parse time.
- Post-alias `--yes` retired — use `wt -y <alias>` (the global form)
instead. `--dry-run` on an alias invocation is also retired; `wt config
alias show/dry-run <name>` replaces it (landed separately in #2291).
- Hyphens in keys canonicalize to underscores, so `--my-var=x` binds `{{
my_var }}`.
- `--` is a literal-forward escape — everything after it forwards to `{{
args }}` regardless of bindings.
- `wt <alias> --help` / `-h` prints a hint pointing at `wt config alias
show/dry-run` rather than silently forwarding the flag into `{{ args
}}`. `wt <alias> -- --help` still forwards.

Advisory warnings (printed on stderr, don't affect execution):
- `--KEY VALUE` with `--`-prefixed VALUE: almost always a typo where
`--KEY=VALUE` was meant.
- `wt config alias show`/`dry-run` on a name that shadows a top-level
built-in (e.g. `list`): the alias is unreachable via `wt <name>`.

`wt config alias dry-run` now prints `# bound:` and `# args:` routing
comments above the rendered command so users can see how each token was
interpreted.

Docs rewrite of the aliases section: concrete fly preview-env example,
"Passing values" section (renamed from the opaque "How arguments are
routed"), routing mechanism moved above the introspection tools, `up`
rebase recipe restored, `since-main` alias added.

## Test plan
- [x] `cargo test --lib --bins commands::alias::tests` — unit tests
(new: duplicate-key precedence, footgun warning, multi-`=` value)
- [x] `cargo test --test integration step_alias` — integration tests
(new: shadow warning on `show` and `dry-run`, `--help` intercept,
retired `--dry-run` via `wt step`)
- [x] `cargo test --test integration
test_command_pages_and_skill_files_are_in_sync` — skill file sync
- [x] `cargo run -- hook pre-merge --yes` — full test suite + lints
green

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Co-authored-by: Worktrunk Bot <[email protected]>
max-sixty pushed a commit that referenced this pull request Oct 1, 2026
)

`wt <alias> --<Tab>` (and `wt step <alias> --<Tab>`) offered `--dry-run`
and `--var`, but neither does anything useful after an alias.
`AliasOptions::parse` rejects `--dry-run` with "`--dry-run` is no longer
supported; use `wt config alias dry-run <name>` instead" (unless the
template references `dry_run`), and passes `--var KEY=VALUE` through to
the alias as plain positional arguments. Completion was steering users
into an error or a flag that silently does nothing.

The flags come from `build_alias_completion_command` in
`src/completion.rs`, a stub that predates alias argument routing (added
in #1641; `--dry-run` was retired for aliases in #2291 and #2304). This
PR removes the stub's own `--dry-run`, `--yes` and `--var` declarations,
so the stub declares nothing beyond the alias name and help text.
Aliases that wrap a built-in (`co = "wt switch {{ args }}"`) still
mirror that built-in's flags through `mirror_alias_command`, which this
PR doesn't touch.

**Test:** `test_complete_step_alias_shows_flags`, which asserted the
stale flags were present, becomes
`test_complete_step_alias_offers_no_misleading_flags` and asserts
`--dry-run` and `--var` are absent. It fails on `main` (`Unexpected
--dry-run flag`) and passes with the fix. All 80 completion integration
tests pass.

**Not covered:** `--yes` still completes after an alias, and so do
`--config` and `--verbose`, because they are clap `global = true` flags
on the root command and propagate into every subcommand's completions.
After an alias they also forward as arguments (the alias parser tests
note that `global = true` doesn't cross `external_subcommand`). Removing
them would mean hiding globals per alias stub, which is a separate
decision. The stub's own `--yes` declaration duplicated the global, so
dropping it changes nothing.

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