Skip to content

docs: alias template-expansion timing; fix narrow help-test env redaction - #3006

Merged
max-sixty merged 3 commits into
mainfrom
docs-alias-expansion
Jun 7, 2026
Merged

max-sixty merged 3 commits into
mainfrom
docs-alias-expansion

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Docs: alias template-expansion timing

The main addition documents a gotcha that's easy to hit and hard to diagnose: an alias body renders its {{ … }} once at dispatch, in the invoking worktree, so a per-worktree variable like {{ branch }} is baked to a single value before a nested wt step for-each / wt switch --execute iterates — printing the same value in every worktree. The fix is {% raw %}…{% endraw %} deferral (plus a quoted sh -c '…' for for-each, since the deferred {{ branch }} contains spaces).

  • extending.md — rewrote "Deferring expansion to a nested wt command" around the for-each symptom; improved the up rebase recipe.
  • faq.md, troubleshooting.md — symptom-first entries with wt config alias dry-run as the diagnostic.
  • hook.md / config.md / step.md — distinguish repo-level (constant) vs per-worktree (active) variables; note {{ default_branch }} needs no deferral; cross-link the {{ default_branch }} variable vs the wt config state default-branch shell command.

Factual corrections

  • integration_reason JSON values are hyphenated (trees-match, no-added-changes, merge-adds-nothing) — the docs had underscores. Verified against src/commands/list/model/state.rs.
  • SKILL.md: 7 → 10 hook types (5 events × pre/post), added an aliases/multi-worktree task section, fixed stale anchor links.

Test fix: narrow help-test env redaction

test_help_list_narrow_terminal built its own insta::Settings but skipped add_standard_env_redactions (every other help snapshot routes through snapshot_help, which calls it). Its snapshot env block therefore leaked host-specific paths (LLVM_PROFILE_FILE = the machine's temp dir, plus the WORKTRUNK_* paths), which churn whenever the snapshot is regenerated on a different machine. Adding the one call mirrors snapshot_help and makes the snapshot reproducible.

Worth noting (and a candidate follow-up): this gap was masked under cargo test (libtest) because the repo fixture's mem::forget'd bind_to_scope() guard leaks redaction settings across the shared process's reused threads. Under nextest (process-per-test, what the pre-merge hook uses) there's no leak, so a test missing its own redactions is exposed. A few other help tests (test_help_md, test_version, test_nested_subcommand_suggestion) have the same gap and could be consolidated through one settings helper — left out of this PR to keep it focused.

This was written by Claude Code on behalf of max

max-sixty and others added 2 commits June 6, 2026 23:38
…nv redaction

Document the two-pass `{% raw %}` deferral for nested `wt` commands in aliases
(`for-each` / `--execute`), distinguish repo-level from per-worktree template
variables, and cross-link `{{ default_branch }}` vs the shell command. Refresh
the worktrunk skill (7 → 10 hook types, aliases/multi-worktree task section,
stale anchors) and correct the `integration_reason` values to their hyphenated
JSON form (`trees-match`, etc.).

Also fix `test_help_list_narrow_terminal`, which built its own `insta::Settings`
without `add_standard_env_redactions` — so its snapshot env block leaked
host-specific paths (`LLVM_PROFILE_FILE`, `WORKTRUNK_*`) that churn per machine.
Adding the call mirrors `snapshot_help` and makes the snapshot reproducible.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

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

The accuracy pass checks out — verified the integration_reason hyphenation, wt hook show --expanded, the for-each "template error aborts / command failure tolerated" split, the -x tmux -- attach arg form, and the 10 hook types against source. The help_list_narrow_80 redaction fix is a real determinism win.

One omission in the new repo-vs-active variable note: the active list leaves out worktree_name, which the table just above it classifies as active and which varies per worktree. Suggestion on the source of truth below.

Comment thread src/cli/mod.rs Resolved
The active-vs-repo variable note omitted worktree_name, which the table
directly above classifies as active (varies per worktree). Addresses tend
review feedback on #3006.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@max-sixty
max-sixty merged commit 5da0d2c into main Jun 7, 2026
38 checks passed
@max-sixty
max-sixty deleted the docs-alias-expansion branch June 7, 2026 07:00
max-sixty added a commit that referenced this pull request Jun 9, 2026
)

## Consolidate help-snapshot insta settings

Follow-up to #3006, which fixed one instance of this in
`test_help_list_narrow_terminal`.

### The bug

Insta's `info:` / `env:` block is metadata — written to the `.snap` file
but **not** part of insta's pass/fail comparison (only
`stdout`/`stderr`/`exit` are compared). Several help tests in
`tests/integration_tests/help.rs` constructed their own
`insta::Settings` inline and skipped `add_standard_env_redactions`, so
host-specific env baked into their committed snapshots and passed
forever on the machine that generated them. Three snapshots
(`help_md_root`, `help_md_merge`, `nested_subcommand_hook_pre_start`)
carried a developer's literal `LLVM_PROFILE_FILE` temp path
(`/var/folders/…/wt-test-profraw/…`); it only diffs when the snapshot is
regenerated elsewhere.

### The fix

One private `help_settings() -> Settings` builder (snapshot path +
`add_standard_env_redactions`); every help/version/usage snapshot test
now routes through it, so the redaction can't be forgotten. The seven
affected snapshots are force-regenerated — env blocks now uniformly
redacted, command-output bodies byte-identical.

This is latent-correctness hygiene: because the env block isn't part of
the comparison, it never fails CI; the payoff is that the next
regeneration on any machine won't reintroduce host churn.

> _This was written by Claude Code on behalf of max_

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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