mirror of
https://github.com/max-sixty/worktrunk.git
synced 2026-11-23 01:51:13 +08:00
codex/vars-read-errors
156
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
12d33b3e30 |
fix(shell): keep the Nushell wrapper working when its stdout is redirected (#4525)
Since #4400 rewrote the Nushell wrapper around `try … finally`, redirecting the stdout of a `wt` command that prints nothing there aborts the wrapper. `nu --no-config-file -c 'source init.nu; cd repo; wt switch --create y o> /dev/null; print $env.PWD'` prints `repo.y` on v0.80.0, but on main it fails with `nu::shell::cant_convert ... can't convert nothing to string` at the `try {`, stops the script, and loses the cd. Nushell 0.116 fails to convert a `try … finally` that evaluates to nothing under `o>` or `o+e>`. A plain `try`, `| ignore` and `e>` are unaffected. The wrapper's `try … finally` now evaluates to a record holding the exit code and captured stdout, and the wrapper returns stdout or propagates the failure after the block, as v0.80.0 did. A failure's stdout still prints inside the block, so a failing cd directive can't drop it, and the `finally` still applies the directive and removes the temp files on Ctrl-C. Returning `""` from the empty branch would also have avoided the error, but it prints a blank line when `wt switch` is the last command of a `nu -c` script. Verified with nu 0.116.0 against v0.80.0, main and this branch: `o> /dev/null`, `o> file`, `| ignore`, `e> /dev/null`, `o+e> /dev/null`, plain and captured (`let x = (wt switch …)`) calls, a stdout-producing command redirected and piped, a failing command (exit 1 with no source trace, with and without `o>`), and `--execute` under `o>` all match v0.80.0 on this branch. Main fails the `o> /dev/null`, `o> file`, `o+e>` and `--execute` under `o>` cases. An interactive PTY session runs `wt switch` with and without `o> /dev/null` and changes directory both times. The new `test_nu_wrapper_redirected_stdout_applies_cd` fails on main with the same `cant_convert` error and passes here. The nushell, shell-wrapper, init and foreground-job integration tests (291) pass with `--features shell-integration-tests`. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> |
||
|
|
cd6732e93a |
fix: preserve native foreground job control (#4400)
Foreground hooks could hang when they changed terminal settings: Worktrunk created a separate process group without giving it the terminal, so the kernel stopped the child with SIGTTOU. Foreground commands now stay in the caller's native job group, consistently for single and concurrent commands. Terminal access, Ctrl-C and job suspension follow the shell's native behavior. ### Design - `signal_forwarder` owns foreground cancellation and child admission. Native SIGINT/SIGTERM deaths stop later hooks and worktree steps; a child that catches Ctrl-C keeps its ordinary exit semantics, including exit code 130. SIGTERM addressed to wt cancels its owned work even when a child catches it. - `shell_exec` and concurrent output share that lifecycle. Output drains stop on cancellation; complete buffered stdin uses an anonymous temporary file instead of writer threads. Real process pipelines remain pipes. Buffered stdin therefore requires temporary storage and is seekable. - Help and preview pagers use Git's pager selection and the same process primitives. Interactive pager cancellation propagates silently, and preview deadlines cover output and child waits. - Shell wrappers apply directory directives and clean temporary files while preserving native interrupt behavior. Nushell integration now requires 0.113 or newer and uses native `finally` cleanup. Nushell 0.116's `finally` itself can abort a noninteractive script after Ctrl-C even when the child catches it and exits successfully. Worktrunk's directory change and cleanup still complete; the same script-continuation difference reproduces in a minimal Nushell `try/finally` without Worktrunk. Bash applies aborted-line cleanup through a writable `PROMPT_COMMAND`. With a readonly prompt command or `set -a`, it applies ordinary cleanup while preserving that configuration; Ctrl-C can leave the pending directory directive unapplied. The main behavioral coverage uses real children and PTYs: terminal ownership/settings, raw and caught Ctrl-C, PID-targeted cancellation, stopped jobs, concurrent output, pagers, and generated shell wrappers. Module contracts describe ownership and platform differences. ### Validation The complete project pre-merge gate passes locally, including the real-shell/PTY suite, Clippy, formatting, locked dependencies, and documentation checks. The change also received an independent Opus correctness and simplicity review, with fixes reviewed through convergence. macOS runtime validation is local; Linux and Windows run in CI. Closes #4389. Thanks to @user753 for the reproduction. > _This was written by Codex on behalf of max-sixty_ |
||
|
|
2469187460 |
Separate config state, advice and parser diagnostics (#4351)
Config views report plugin, shell and tool state neutrally, with installation and authentication advice on separate rows. Missing project config and existing config with no hooks remain distinct. Typed config and approvals errors preserve their source and share one parser diagnostic through reports, hook commands and strict loading. String rendering no longer propagates impossible formatting failures from CI-tool status or the project parser diagnostic. The absent-directory errors remain: they prevent config and approvals writes when the OS cannot locate a home directory. These errors were already uncovered on main before the typed-error rename. Validation: the required pre-merge gate passed 5,029 tests with one skipped, including real config/hook/approvals commands, strict invalid-environment loading, unreadable approvals sources, successful commit-generation probing and both home-relative and quoted absolute path forms. Lint, documentation and independent local review passed. Linux, macOS and Windows suites, all affected-test suites and project coverage pass on the current head. Automated review found no new code issues. Current patch coverage is 97.14% against the 98.38% target. The remaining eight missed lines are six pre-existing absent-directory safeguards and two changed call endings in the already-uncovered GitHub/GitLab diagnostic routes. Maintainer max-sixty explicitly approved this patch-coverage exception and merge after reviewing these retained lines. > _This was written by Codex on behalf of max-sixty_ |
||
|
|
9669d4a7bb |
test(shell): isolate fish startup configuration in PTY fixtures (#4353)
Fish PTY tests currently load startup configuration, which can prepend PATH and replace a fixture's stub command with a host command. Launch fish with `--no-config`, matching the existing non-PTY shell helper, and keep the error-forwarding fixture's HOME and XDG_CONFIG_HOME inside its temporary directory. The regression fixture installs a fish startup config that would select a fake cargo exiting with status 23; the expected CLI error must still come from the intended cargo stub. This changes test isolation only. Validation: the full project pre-merge gate passed: 5,021 tests, one skipped, plus formatting, lint, documentation and doctests. Real fish PTY tests exercise the startup-config regression. > _This was written by Codex on behalf of max-sixty_ |
||
|
|
6502630366 |
docs: share project instructions through AGENTS.md (#4245)
Make `AGENTS.md` the canonical project instructions in nine directories. Each directory also has a one-line `CLAUDE.md` importing its adjacent `AGENTS.md`, so Claude Code loads the instructions even on accounts where native `AGENTS.md` support is gated off. The root `AGENTS.md` replaces the old symlink; ordinary files work on Windows checkouts without symlink support. References in source comments, CI, Clawpatch metadata, maintainer skills, and the demo fixture point to the canonical paths. I verified Claude Code's `@` import in a live isolated probe with tools disabled: a `CLAUDE.md` import loaded a marker found only in the imported file. The wrappers keep the existing Claude Code instruction-loading path while Codex reads `AGENTS.md` directly. Verified: `test_docs_are_in_sync`, `test_plugin_layout_is_consolidated`, `test_no_host_specific_paths_in_snapshots`, the docs production build, 20 built-site tests, Python compilation of the demo helper, JSON parsing of the feature metadata, and `git diff --check`. > _This was written by Codex on behalf of max-sixty_ |
||
|
|
baf161bf60 |
Run switch --execute as literal argv (#3977)
## Summary - Treat `wt switch -x` as one program plus arguments that bypass Worktrunk shell parsing; program lookup and argument decoding use native operating-system behavior. - Launch the program from `wt` in the selected worktree, preserving terminal access, signals, and exit status. - Remove the shell exec directive, shell-specific escaping, and implicit `sh` dependency. Shell wrappers now carry only the directory change. - Make the Nushell wrapper recognize clustered execute flags such as `-cx`, stop scanning at `--`, and warn when a retired exec-file wrapper buffers stdout away from the terminal. Shell syntax remains explicit: `-x sh -- -c 'code . && test -f Cargo.toml'`. On Windows, shell shims need their extension (`-x code.cmd`) or an explicit shell such as `-x cmd.exe -- /C code`. This completes the argv cutover proposed in #2860 and removes the remaining Nushell-on-Windows problem in #3944. It adds no PATHEXT lookup, custom Windows quoting, or PowerShell launcher path, and still removes 597 lines from `src` and `templates` on net. ## Validation - `cargo run -- hook pre-merge --yes` - 4,712 tests passed; one skipped - Formatting, clippy, docs, doctests, lockfile, and snapshot checks passed Thanks @omgreenfield for testing the migration path in #2860. Closes #2860 Closes #3944 > _This was written by Codex on behalf of @max-sixty_ |
||
|
|
d971d03502 | fix(shell): propagate nushell wrapper exit codes without spawning sh (#3945) | ||
|
|
df2bc6e7f1 |
Require Git 2.43 and test it nightly (#3895)
Worktrunk now uses Git 2.43 as its tested support baseline and checks the version once before dispatching a command. Git 2.43 is Ubuntu 24.04's system package, so CI can exercise the full supported range with an exact nightly row. This is a policy cutoff rather than a feature boundary; Git-dependent commands on older versions fail centrally instead of accumulating compatibility branches. The Git-independent `config shell` namespace remains available so shell startup and generated integration still work while Git is upgraded. The existing nightly full-test matrix gains an exact Git 2.43.0 row. Test fixtures that isolate PATH retain the runner-selected Git instead of falling back to an older platform Git. `wt step relocate` uses `git switch` because Git 2.43 does not support `git checkout --end-of-options`, and the worktree-registration test now lets each Git version generate metadata it can consume. Tested with the full 4,680-test suite on exact Git 2.43.0 and the normal development environment. Also validated the Ubuntu 24.04 amd64 package installation and the workflow with `actionlint`. > _This was written by Codex on behalf of @max-sixty_ |
||
|
|
bdd7113c95 | fix(shell): catch a failing --execute body in the nushell wrapper (#3734) | ||
|
|
78010166bd |
fix(shell): bypass rm aliases in the nushell wrapper's cleanup (#3732)
## Problem The nushell wrapper's temp-file cleanup called a bare `rm -f`. Nushell resolves aliases at parse time, and `config.nu` runs before the `$nu.vendor-autoload-dirs` file the wrapper installs into — so a user's `alias rm = ...` is already in scope when the wrapper's `def` is parsed, and intercepts the cleanup. #3714 fixed the same shadowing in the bash and zsh wrappers with `command rm`; nushell has no `command` builtin, so it was left out. Two failures, both verified end-to-end against nushell 0.114.1 (the version CI pins) driving the real rendered wrapper: | `alias rm =` | before | after | |---|---|---| | *(none)* | exit 0, stdout returned, 0 temp files left | unchanged | | `^false` | exit 1, **stdout empty**, **3 temp files leaked** | exit 0, stdout returned, 0 left | | `^echo TRASHED` | `TRASHED -f /tmp/...` lines **injected into stdout**, **3 temp files leaked** | exit 0, stdout returned, 0 left | The `^false` row is the serious one. Cleanup sits between `let output = (open $stdout_file --raw)` and the function's return, and nushell 0.98+ raises `ShellError` on a non-zero external exit — so an `rm` alias that fails, prompts, or isn't installed on that machine aborts the wrapper before it returns, and the command's stdout is silently discarded. Only stdout is affected; stderr has already streamed to the terminal, which is why the symptom hides on `wt switch` (its output is on stderr) and shows on `wt config show`. ## Solution Consolidate the two cleanup calls into one, after the last read of any temp file, and branch at runtime on `$nu.os-info.family`: ```nu if $nu.os-info.family == "windows" { try { rm -f $cd_file $exec_file $stdout_file } } else { try { ^rm -f $cd_file $exec_file $stdout_file } } ``` `^rm` bypasses alias expansion entirely — the Unix fix is complete, not partial. Windows keeps the builtin because `^rm` is external-only and Windows has no external `rm`; `try` covers both branches so cleanup can never abort the wrapper again. Branching at *runtime* rather than forking the template by build platform is what keeps this cheap: `wt config shell init nu` renders one text on every platform, so there's a single `init_nu` snapshot and no platform-specific rendering to maintain. <details><summary>Options considered and rejected</summary> - **`` `rm` `` (backtick-quoted)** — bypasses the alias, but `` `rm` `` with `PATH` emptied reports ``Command `rm` not found``, and `` `rm` `` with no args prints `/usr/bin/rm: missing operand`. It resolves to the *external*, so it's just `^rm` spelled differently — same Windows gap, no benefit. - **`hide rm`** — works inside the `def`, but `hide` is a parse-time keyword that leaks into the enclosing scope. For an autoloaded file that scope is the user's session, so installing shell integration would silently unbind their own `rm` alias. Same leak inside a `do {}` closure. Worse than the bug. - **`try` alone, no `^rm`** — cross-platform and kills the abort, but leaves the alias running: a `trash` alias still trashes worktrunk's temp files on every invocation, and an `rm -i`-style alias still prompts. - **Forking the template by build platform** — same end state on each platform, at the cost of platform-specific `init_nu` snapshots. The runtime branch gets there without them. </details> ## Testing `test_nu_wrapper_cleanup_survives_rm_alias` in `tests/integration_tests/shell_wrapper.rs` runs the real wrapper through a PTY with `alias rm = ^false` declared ahead of it, against a dedicated `TMPDIR`, and asserts both symptoms: the wrapper's stdout comes back non-empty, and the temp dir is empty afterwards. It fails on the current template (marker absent — the wrapper aborted) and passes with the fix. Also run locally: `cargo test --lib --bins`, and the full `shell_wrapper` + `config_show` + `test_docs_are_in_sync` integration set with `--features shell-integration-tests` (201 passed). ## Not fixed here A user alias to a *custom command or builtin* whose signature rejects `-f` — e.g. `alias rm = print "…"` — makes the whole wrapper file fail to parse, leaving `wt` undefined rather than merely broken. That's pre-existing (today's template has two bare `rm -f` calls) and survives this change, because the Windows branch is still parsed on Unix even though it never runs. Eliminating it means emitting no bare `rm` at all on Unix, which is the template fork above. Flagged on #3730 rather than bundled in here. --- Closes #3730 — automated triage Co-authored-by: worktrunk-bot <254187624+worktrunk-bot@users.noreply.github.com> |
||
|
|
1b35950a9c |
test: simplify the integration suite (#3657)
This reduces duplicated and false-confidence integration coverage while preserving the suite's semantic and user-facing contracts. ## What changed - Replaces three overlapping list-layout suites with two representative CLI integrations, leaving exhaustive geometry at the direct layout layer. - Groups Git error render variants into labeled family snapshots and removes command-by-shell wrapper cross-products while retaining shell-specific conformance and regression cases. - Updates test-authoring guidance around boundary choice, minimal contrasts, and PTY use, and runs local and CI coverage through Nextest isolation. ## Results - Test catalog: 4,642 to 4,562 - Snapshots: 1,193 to 1,131 - Warm all-feature runtime: 84.70s to 78.17-80.35s - Full coverage: 97.32% of lines ## Testing - `cargo run -- hook pre-merge --yes` - `cargo llvm-cov nextest --features shell-integration-tests --summary-only` > _This was written by Claude Code on behalf of max_. |
||
|
|
9032308400 |
refactor(tests): give the PTY test environment one home (#3618)
Follow-up to #3616, which fixed a PTY snapshot flake by adding one env knob — and to add it I had to touch three separate env builders, none of which knew about the others. This consolidates that surface. ## What was there The environment a test subprocess runs in was assembled at nine sites: five copies of the PTY prologue (`env_clear`, HOME, PATH, the Windows block, coverage passthrough) and four partial restatements of the determinism knobs. There was no rule for which belonged where, so adding a knob meant finding every copy, and a missed copy surfaced later as a flake somewhere unrelated. ## What's there now Three named layers, each with one home in `src/testing/mod.rs`: | Layer | Home | Contents | |---|---|---| | Baseline | `STATIC_TEST_ENV_VARS` | knobs every child needs, whatever it's attached to | | Terminal | `PTY_TEST_ENV_VARS` (new) | knobs only a TTY triggers — `WORKTRUNK_TEST_SPINNERS=0` | | Fixture | `pty_env_vars(TestEnvPaths { … })` (new) | the paths that vary per fixture | `configure_cli_command` and `configure_pty_command` apply them by transport. That turns the standing `// NOTE: TERM is intentionally NOT in STATIC_TEST_ENV_VARS` comment into a consequence rather than an exception: `TERM` is transport-level, so it can't sit in a baseline both transports share. `WORKTRUNK_TEST_SPINNERS` stays out of the shared baseline deliberately. It's inert on a pipe, and insta-cmd records the whole environment into every snapshot it writes (`Info::from_std_command` builds it unconditionally from `cmd.get_envs()` — there's no hook to suppress it), so putting it there would add a no-op line to 1043 snapshot files. `configure_pty_command` is now the only place a PTY child's isolation is set up. `shell_command`, `execute_shell_script`, `configure_pty_environment`, `exec_in_pty_shell`, `exec_bash_truly_interactive` and two `wt switch` spawns all delegate to it. `shell_wrapper`'s `STANDARD_TEST_ENV` and `bare_repository`'s hand-rolled `test_env_vars` are gone, as are `configure_shell`'s hand-copied knobs and four redundant `CLICOLOR_FORCE` lines in `switch_picker`. Net −149 lines. One spawn stays outside: the Windows ConPTY smoke test, which runs PowerShell against a deliberately bare environment and isn't a wt child at all. ## Reviewing Start at `src/testing/mod.rs` — the three layers and their doc comments are the whole design. Everything under `tests/` is deletion plus a delegation call. Two snapshots change: `install_preview_with_gutter` and `install_preview_declined` now carry ANSI, because those two tests previously ran without `CLICOLOR_FORCE`. Text is identical. Arguably a fix — the test named "with_gutter" couldn't see the gutter (a background-color block), while its own prompt line was already colored, so the file was internally inconsistent. ## Testing Full `wt hook pre-merge --yes` green: 4601 tests, `--features shell-integration-tests`, `RUSTFLAGS='-D warnings'`, `insta --check`. The knob's delivery path was verified by probe rather than by inspection. With `sleep 6` in the mock `llm`, `test_readme_example_hooks_pre_merge` passes; flipping `PTY_TEST_ENV_VARS` to `"1"` reproduces the original failure byte for byte: ``` +␛[1G␛[J␛[2m↳␛[22m ␛[2mWaiting for the commit generation command (4s)␛[22m␛[1G␛[J␛[2m↳␛[22m ␛[2mWaiting for the commit generation command (5s)␛[22m ``` So the knob reaches the shell-wrapper PTY child through the shared setup, not through a surviving copy. Both probe edits are reverted. > _This was written by Claude Code on behalf of max_ Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> |
||
|
|
d6ef23d573 |
test(pty): suppress the TTY spinners in PTY captures (#3616)
`test_readme_example_hooks_pre_merge` flakes when the whole suite runs together. The mock `commit.generation` command gets starved past the watchdog's 4s threshold, and the PTY capture records the redraw frames a terminal would have erased: ``` ↳ Waiting for the commit generation command (4s) ``` The elapsed seconds vary run to run, so accepting the snapshot just moves the flake. ## The fix Both spinners in `src/progress.rs` now check `WORKTRUNK_TEST_SPINNERS` alongside the existing TTY (and, for `Watchdog`, verbosity) gate, and the PTY env builders set it to `0`. This is the shape the repo already uses for `WORKTRUNK_TEST_DELAYED_STREAM_MS=-1`, whose comment names the same failure mode: "slow CI triggers progress messages that don't appear on faster systems". Only the render is gated, so the counters behind the summary lines the snapshots do assert are untouched. Gating both spinner types rather than the one call site closes the latent exposure elsewhere: `Progress` renders after 300ms in any PTY test that copies or removes files, and `Watchdog` also wraps `wt switch` and the version check. ## Why not filter the frames out of the capture A line-scoped filter in `add_pty_filters` would be a one-liner, but it only covers the single-row block. Past 10s the watchdog escalates to two rows and redraws with a cursor-up, which spans a newline the filter cannot follow, and the revealed command line carries a tempdir path. Closing that would mean modeling cursor arithmetic in a regex that silently deletes bytes from captured output. ## Evidence Reproduced first, by making the mock command slow directly rather than waiting for ambient CPU starvation to do it. The resulting diff is byte-identical to the reported flake, including the `(4s)` / `(5s)` counters: - `sleep 6` in the mock, before the fix: FAIL, same diff as reported - `sleep 6`, after the fix: pass - `sleep 12` (past the 10s escalation tier, where a filter would not have helped): pass - negative control, `sleep 6` with only `WORKTRUNK_TEST_SPINNERS` flipped from `0` to `1`: FAIL again, so the knob is what engages Full gate green: 4601 tests, no pending snapshots. > _This was written by Claude Code on behalf of Maximilian_ Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> |
||
|
|
1d46c0083b |
fix(test): treat Linux PTY EIO-on-close as EOF in read helpers (#3398)
## Problem
The `code-coverage` job failed on [run
29053905721](https://github.com/max-sixty/worktrunk/actions/runs/29053905721)
(default branch, commit
|
||
|
|
220220f4bc |
test: poll PTY output instead of blind sleeps in bash job-control test (#3218)
`exec_bash_truly_interactive` (used only by `test_bash_job_control_suppression`) gated bash startup and command completion on fixed `thread::sleep` calls, then read the PTY only after sending `exit`. This streams the PTY over a channel and polls for the startup prompt and the command's success output, so the presence half of the test waits on real output instead of a timing guess. The test's core assertion is that suppressed job-control notifications (`[1]+ Done`) do not leak: an absence check with no event to poll for. That keeps a fixed window, but now the shared `SLEEP_FOR_ABSENCE_CHECK` marker, and the window starts after the command's output appears rather than before it runs, so a leak has the full window to surface even on slow CI. The expected success substring is now a parameter so the generically-named helper doesn't silently depend on one caller's output. Follow-up to #3206, which consolidated absence-window sleeps behind `SLEEP_FOR_ABSENCE_CHECK`; this sleep was missed there because it read as PTY output sequencing. > _This was written by Claude Code on behalf of max_ Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> |
||
|
|
2c0a70127a |
test: isolate bash PTY tests from the host ~/.bashrc (#3173)
## Problem The bash arm of `exec_in_pty_shell` (`tests/integration_tests/shell_wrapper.rs`) was the only shell arm without rc-file isolation. zsh sets `ZDOTDIR=/dev/null` + `--no-rcs`, nu sets `--no-config-file`, and the sibling `exec_bash_truly_interactive` already passes `--norc --noprofile` — but the bash arm did not. Because the PTY harness sets `HOME` to the real home, interactive `bash -i` sourced the host's `~/.bashrc`, leaking host-specific startup output into the captured PTY snapshots. ## Fix Add `--norc --noprofile` to the bash arm, mirroring the zsh/nu arms and `exec_bash_truly_interactive`. It's orthogonal to job control (that's driven by `-i`), so the job-control leak-detection tests (`test_*_no_job_control*`) still exercise the interactive path; it's a no-op for the non-interactive `bash -c` path used by `test_source_flag_forwards_errors`. Follow-up to #3161 / #3165, which fixed the macOS PTY-test hang and isolated several other tests but left this arm untouched. ## Tests All 88 `shell_wrapper` tests pass, plus the full pre-merge gate (4102 tests, all lints and doctests). > _This was written by Claude Code on behalf of max_ Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> |
||
|
|
3fb96deb71 |
fix(test): run --source error test non-interactively to prevent a PTY wedge (#3161)
## Problem `unix_tests::test_source_flag_forwards_errors` (rstest over bash/zsh/fish in `tests/integration_tests/shell_wrapper.rs`) flaked in CI by **timing out** at the 180s nextest slow-timeout — a hang, not an assertion failure. ## Root cause The test ran `bash -i` / `zsh -i` inside a PTY. An interactive shell does job-control initialization at startup: it checks whether it owns the terminal's foreground process group, and if it decides it doesn't, it sends its own process group `SIGTTIN` and **stops** — waiting to be brought to the foreground, which the test harness never does. A stopped shell produces no output and never exits, so the PTY read blocks until the harness kills the run. The evidence fits this and little else: the hang was **macOS-only**, the shell **never exited**, and the captured output was **empty** — so it stopped at job-control init, before running the `-c` script at all. The trigger is a rare startup race under heavy parallel load; it never reproduced locally across thousands of runs, but CI hit it. ## Fix `test_source_flag_forwards_errors` asserts exactly one thing: that the `--source` branch forwards wt's `unrecognized subcommand` error. It never backgrounds a job and never checks for job-control messages, so it doesn't need an interactive shell. Running it **non-interactively** (no `-i`) removes the job-control path — and the wedge — structurally, not probabilistically. `exec_in_pty_interactive` gains a sibling `exec_in_pty_shell(.., interactive: bool)`; the interactive wrapper is unchanged for the tests that genuinely verify job-control suppression (e.g. `test_zsh_no_job_control`), which still pass `interactive = true`. The error-passthrough assertions and the shared snapshot are unchanged. The net diff is ~40 lines in one file. (An earlier revision of this PR bounded the PTY read and retried the wedged shell — recovering from the timeout rather than preventing it; that was reverted in favor of this structural fix.) ## Tests All three cases (bash/zsh/fish) pass — verified 15× consecutively, plus the full pre-merge gate (4044 tests, all lints and doctests). > _This was written by Claude Code on behalf of max_ --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> |
||
|
|
21e0b27e49 |
refactor(verbose): rename output.log → subprocess.log; -vv keeps Info on stderr (#2913)
## Motivation The `-v` / `-vv` UX had three small issues that compounded: 1. **`output.log` is misnamed.** It holds the *uncapped raw stdout/stderr of every subprocess `wt` spawns* — multi-MB possible (`git log -p`, patch-id pipelines, etc.). "output" reads as "stuff `wt` printed" — the small thing — when it's actually the big thing. Easy to misread. 2. **`-vv` went fully dark on stderr.** PR #2892 moved the noisy debug pipeline to files at `-vv`; in the process, the stderr layer was disabled entirely. Users running `-vv` to see hook output (info-level, which `-v` shows on stderr) suddenly couldn't. 3. **`-v` help text was a 150-char one-liner** packed into a parenthetical, and the surrounding docs leaned on a "stderr stays readable / `log::*` pipeline" framing that was Rust-jargon-flavored and implied stderr-quiet at `-vv` — which is no longer true after change #2. ## Change - **Rename `output.log` → `subprocess.log`.** Filename now matches content. `OUTPUT` static → `SUBPROCESS`, plus the related `OutputMakeWriter` / `OutputFileFormat` / `build_output_layer` symbol renames. - **`-vv` keeps the Info baseline on stderr.** `build_stderr_layer` no longer returns `None` at `-vv`; debug-level records still route to file layers only, so the terminal stays readable while info-level status (hook output, template variables, the `Tracing to ...` pointer) shows the same as at `-v`. - **`-v` help text rewritten** to describe both levels cleanly without a wall of detail. - **`docs/content/faq.md` gets a "What does -v / -vv do?" section** with a three-level table. - **Docs cleanup**: drop "stderr stays readable" / `log::*` jargon / "but not subprocess.log" negative framing from user-facing prose. ## Notes for review - The only `log::info!` site in the codebase is `commands/picker/mod.rs:389` (a single picker error message), so making `-vv` show info-level on stderr doesn't add meaningful noise. - `test_vv_log_pipeline_silent_on_stderr` is renamed to `test_vv_debug_pipeline_silent_on_stderr` — its assertions only check debug-level records stay out of stderr (they do); the old name implied the whole `log::*` pipeline was silent, which was never quite true (direct `eprintln!` always showed) and is less true now (info-level routes to stderr). - 67 of the 69 changed files are snapshot updates (help text and one diagnostic snapshot) and auto-synced doc/skill mirrors. `git diff --stat -- 'tests/snapshots/*' 'docs/content/*' 'skills/worktrunk/reference/*' | tail -1` separates them. - CHANGELOG: not touched. The historical entry that introduced `output.log` (`#2201`) stays accurate for its release; this rename gets a new line in the next release. ## Tests 3870 tests pass. Re-snapshotted all `test_help_*` snapshots, three `step_alias` snapshots that quote the global help, and the diagnostic file format snapshot. > _This was written by Claude Code on behalf of max-sixty_ Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> |
||
|
|
93b441c8f0 |
feat(switch): deprecate shell command lines in --execute (#2852)
## What
A future release will switch `wt switch --execute` (`-x`) to an argv
input model: a single program name, with arguments after `--` passed
verbatim, run via `execvp` with no implicit shell. That is a breaking
change to a protected CLI interface, so it ships as a two-release
deprecation — **this PR is the warn phase.**
`validate_switch_templates` now emits a deprecation warning when the
`-x` value is not a single program token — it contains shell syntax,
multiple words, or `{{ }}` template markup. The hint shows the concrete,
copy-pasteable migration:
```
▲ --execute will change in a future release: it will run a single program,
with arguments after --, not a shell command line
↳ To run this command line unchanged, pass it to a shell:
--execute sh -- -c 'echo hi && ls'
```
`sh` is itself a single program token, so the suggested form works
today, does not warn, and survives the cutover. A single program name —
including a path — stays silent.
The `-x` help examples in `src/cli/mod.rs` move to the argv-compatible
form (`-x code -- '{{ worktree_path }}'`) so the docs no longer
recommend a form that warns.
## Why no PATH check
The classifier is purely structural — it decides whether the value is
one bare program token, nothing more. It deliberately does not check
whether a bare name resolves to a real executable. An earlier iteration
did, to also warn on `-x my-alias`, but a PATH lookup at pre-flight is
environment-sensitive, runs in the source worktree rather than where
`-x` will execute, and cannot distinguish a shell alias from a typo or
an uninstalled tool. A bare alias/function `-x` is left to fail loudly
(`execvp` → `ENOENT`) at the cutover rather than guessed at here. The
warning still catches every multi-word / shell-syntax form, which is
what users actually write.
## Testing
`cargo run -- hook pre-merge --yes` — 3799 tests pass; clippy, fmt, and
pre-commit hooks green. New: a unit test for the token classifier and an
integration test covering the warn and no-warn cases. Most of the
32-file diff is snapshot regeneration — the warning is new stderr output
on existing `-x` tests.
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
||
|
|
ec62580c29 |
revert(hooks): keep docs on pre-start/post-start; code accepts both (#2857)
Per @max-sixty's [direction in #2838](https://github.com/max-sixty/worktrunk/issues/2838#issuecomment-4509447593): revert the docs portion of #2840 and keep the code. Docs continue to recommend `pre-start`/`post-start`; both names work in code so anyone who already followed the briefly-changed docs (e.g. @EcksDy) isn't stranded once a release ships these aliases. ## User-visible — back to `pre-start`/`post-start` - README, docs site, skill mirrors, `dev/*.example.toml`, `plugins/worktrunk/README.md`, `flake.nix`, `.config/wt.toml` - `src/cli/mod.rs` / `src/cli/config.rs` / `src/cli/step.rs` / `src/help.rs` after_long_help and example snippets — and the auto-synced `docs/content/` and `skills/worktrunk/reference/` mirrors - `wt hook --help` canonical subcommand names; completion advertises `-start` only - `HookType` Display via strum, serde `rename`, and clap `ValueEnum` name — all `pre-start`/`post-start`. The Rust variant identifiers stay `PreCreate`/`PostCreate` (internal; we already paid for that rename in #2840, and now the eventual flip is a Display-only change) - `HooksConfig` serde canonical fields ## `*-create` still works (kept code) - `wt hook pre-create` / `post-create` — CLI alias on the canonical subcommand - `pre-create` / `post-create` in config: top-level, `[hooks.*]`, and per-project, in string, `[table]`, and `[[array-of-tables]]` form. Mechanism: serde `alias = ...` on the field, plus a silent in-memory rename in `migrate_content()` so the round-trip in `unknown_tree` doesn't flag table forms as schema-unknown. - The pre-0.32.0 `post-create` fatal-load-error machinery stays removed — the name is reclaimed, and both forms load without error. ## Smaller bits - `valid_user_config_keys()` / `valid_project_config_keys()` append `pre-create` / `post-create` so the unknown-field round-trip skips them. `test_valid_*_keys_all_deserialize` skips both aliases (they can't sit alongside the canonical without a duplicate-field error). - `DEPRECATED_SECTION_KEYS` drops the `pre-start`/`post-start` entries #2840 added — `pre-start`/`post-start` are canonical again. - `find_pre_start_from_doc` / `find_post_start_from_doc` / `find_renamed_hook_key` / `is_non_empty_item` / `migrate_start_hooks_doc` and their tests are removed; the migration direction flips via a new `migrate_create_hooks_doc` (silent, mirrors the prior shape). - Test files `e2e_shell_post_create.rs` and `post_create_commands.rs` rename back to `_post_start_` (via `git mv`, so the rename shows as a rename). ## Testing `cargo run -- hook pre-merge --yes` — 3806 tests pass; the 10 failures are all `case_4` of `shell_wrapper::unix_tests::*` (nu-shell case; `nu` isn't installed in this runner; same failures occur on `main`). Also manually verified that a fresh `wt switch --create` against a project config with `[post-create]` loads cleanly with no unknown-field warning and the hook fires as `post-start`. ## Follow-up Per @max-sixty: in a couple of weeks, once a release with both-names-work is out and users have had a chance to upgrade, the docs flip is straightforward (most of it is in `src/cli/mod.rs`'s `after_long_help` and the doc-sync test propagates). Re #2838. Co-authored-by: worktrunk-bot <254187624+worktrunk-bot@users.noreply.github.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com> |
||
|
|
d7e3f88422 |
feat(hooks): rename worktree-creation hooks to pre-create/post-create (#2840)
Phase 1 of the staged hook rename tracked in #2838: the worktree-creation hooks `pre-start`/`post-start` become `pre-create`/`post-create`. The old names keep working with no deprecation warning yet (Phase 2, months out, adds the warning). ## What changes - `pre-create`/`post-create` are canonical everywhere: the `HookType` enum, the `HooksConfig` serde fields, the `wt hook` CLI, completion, and all docs. - Old names keep working: `migrate_content()` rewrites `pre-start`/`post-start` config keys to `-create` before serde, and `parse_hook_type` accepts the old CLI names as silent aliases. `wt config update` rewrites them on disk; `wt config show` shows the migration diff. `wt hook <type>` execution and `wt hook show` both accept the old names; completion and `--help` advertise only the canonical names. - `detect_deprecations()` flags the old keys so `update`/`show` act on them, but `format_deprecation_warnings()` stays silent (Phase 2 adds the warning). A new empty-warnings guard in `check_and_migrate` keeps a `-start`-only config from emitting a stray hint. - The dead pre-0.32.0 `post-create` machinery is removed: the fatal `POST_CREATE_REMOVED_MSG` load error, the vestigial `HooksConfig.post_create` merge-fold, and `find_post_create_from_doc`. `post-create` is reclaimed as the canonical background creation hook. ## Semantic flip Before v0.32.0, the key `post-create` named a *blocking* hook. It now names the *background* one. Since v0.44.0, a pre-0.32.0 `post-create` config is a fatal load error on the `check_and_migrate` paths: `ProjectConfig::load` and user/system config loading, which fire on essentially every `wt` command. A repo carrying one has been unusable ever since. The one path that skips that check is `project_config_at_ref` (the base-ref read behind `wt switch --create`), which applies only structural migration. A pre-0.32.0 `post-create` surviving solely on a base ref, never checked out into a worktree, would now load as a background hook rather than folding into the blocking `pre-start`. That edge case is accepted: once `post-create` is valid again, reclaiming the name and detecting the dead key are mutually exclusive. ## Reviewing this diff 205 files, but the substance is ~36 files under `src/`. The rest is regenerated snapshots and auto-synced doc mirrors. Start with: - `src/config/deprecation.rs` — detection (`find_renamed_hook_key`), migration (`rename_hook_key`), removal of the fatal block, the empty-warnings guard, and the `DEPRECATED_SECTION_KEYS` entries that stop unknown-field detection from flagging the migrated keys. - `src/config/hooks.rs`, `src/git/mod.rs` — the serde field and enum renames. - `src/config/project.rs` — `ProjectConfig::load` deserializes `check_and_migrate`'s migrated content, so a current-worktree config using the old keys loads into the canonical fields. - `src/cli/hook.rs`, `src/commands/hook_commands.rs`, `src/completion.rs`, `src/main.rs` — the CLI alias layer; `wt hook show` accepts the old type names as hidden value-parser aliases. - `src/cli/mod.rs` — the `wt hook` docs, including the soft-deprecation note linking #2838. The ~93 modified snapshots also pick up deterministic env-block lines (`GIT_*: ""`, `LLVM_PROFILE_FILE`) that pre-existing snapshots already carry. That is stale-snapshot drift surfaced by the regeneration, not a behavior change. ## Testing Full suite green (3799 tests). New coverage: `snapshot_migrate_start_to_create` (migration preserves value shape and position), `test_deprecated_start_hook_key_runs_silently` and `test_standalone_hook_start_alias_runs_silently` (old config and CLI names run with no warning), `test_config_show_displays_start_hook_migration` (`config show` reveals the diff without an "unknown field" warning), and `test_hook_show_accepts_deprecated_start_hooks` (a current-worktree config using the old keys loads, and `wt hook show` takes both the canonical and the deprecated type arguments). Part of #2838. 🤖 Generated with [Claude Code](https://claude.com/claude-code) |
||
|
|
68ee0a327b |
feat(hook): expose pr_number and pr_url to PR/MR worktree hooks (#2300)
## Summary `pr_number` and `pr_url` are now first-class template variables for hooks running on PR/MR-created worktrees (`wt switch pr:N` / `mr:N`). Previously the ForkRef code path injected `pr_*` (GitHub) or `mr_*` (GitLab) extras into the pre-start template context, but those names weren't in the validation allowlist — any user hook referencing them was rejected before the hook could run, so the feature was unreachable. This PR canonicalizes on a single pair (`pr_number`/`pr_url`) for both platforms, threads it through the validation scope, plumbs it into post-switch and post-start hooks via `SwitchResult::Created`, and documents it in CLI help (which auto-syncs to docs and skill reference). ## Notable decisions - **One canonical pair, not two.** GitHub and GitLab both populate `pr_number`/`pr_url`; no `mr_*` aliases. Keeps the template surface low-cardinality. - **Symmetric across pre/post.** The `hook_extras` table accepts `pr_number`/`pr_url` for `pre-switch`/`post-switch` and `pre-start`/`post-start`. Pre-switch never actually populates them (PR resolution hasn't happened yet at that point), but grouping pre/post pairs matches the existing `base`/`target` convention and avoids a one-off scope arm. - **Threaded through `SwitchResult::Created`.** Earlier drafts only wired pre-start; post-switch and post-start were silently dropping the data. The Option fields on `SwitchResult::Created` carry it forward to background hooks via `switch_extra_vars`. ## Test coverage - `test_validate_template_scope_rejects_out_of_scope_vars` — accepts `pr_number`/`pr_url` for pre-start, rejects for pre-merge. - `test_switch_pr_hooks_see_pr_vars` — fork-PR scenario with mocked `gh`; pre-start, post-start, and post-switch hooks each write a marker file and the test asserts all three observe `pr_number=42 pr_url=...`. ## Drive-by fix: stub cargo in --source flag test Last commit replaces `cargo run --bin wt` in `test_source_flag_forwards_errors` with a stub-cargo shell script that execs the existing wt binary directly. Real cargo unlinks and re-links `target/debug/wt` on every invocation (~3.9% non-existence window measured locally), racing against any concurrent test that `spawn(target/debug/wt)` and producing the long-standing ENOENT flake in `test_wrapper_switch_with_hooks` on Linux CI. Same end-to-end coverage of the `--source` branch; runs in 2s instead of 30–60s. > _This was written by Claude Code on behalf of Maximilian Roos_ --------- Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
016eb030e7 |
docs(extending): rename "external subcommand" to "custom subcommand" (#2270)
## Summary Renames the git-style `wt-<name>` dispatch feature to "custom subcommand" across user-facing docs and internal code. Two motivations: - **Avoid overloading "external."** The codebase already uses "external command" for the `shell_exec` concept (subprocesses like `git` and `gh`). Using the same word for the `wt-foo` dispatch feature is ambiguous. - **Cargo uses "custom command" / "external subcommand" interchangeably.** kubectl calls theirs "plugins," gh calls theirs "extensions"; git doesn't have a settled term. "Custom subcommand" reads naturally in prose and matches cargo's user-facing phrasing. ## Changes **User-facing docs** — `docs/content/extending.md` (section heading, description, comparison table) and `docs/content/faq.md` (link + anchor). Skill references auto-sync. **Internal code** — `src/commands/external.rs` → `custom.rs`, `Commands::External` → `Commands::Custom`, `handle_external_command` → `handle_custom_command`, plus matching renames in `src/completion.rs` (inject/discover/forward functions) and corresponding tests. Also renames `tests/integration_tests/external.rs` → `custom.rs`. **Kept intact** — clap's `#[command(external_subcommand)]` attribute and `.allow_external_subcommands(true)` are clap's own vocabulary, not ours. CHANGELOG is historical and left unchanged. ## Test plan - [x] `cargo build` clean - [x] `cargo clippy --all-targets --all-features` clean - [x] `cargo test --lib --bins` — all pass - [x] `cargo test --test integration` — all pass (1476) - [x] `pre-commit run --all-files` clean > _This was written by Claude Code on behalf of Maximilian_ --------- Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
5daf70db6b |
feat(config): add WORKTRUNK_PROJECT_CONFIG_PATH override (#2267)
Adds a \`WORKTRUNK_PROJECT_CONFIG_PATH\` environment variable that overrides the project config path, mirroring the existing \`WORKTRUNK_CONFIG_PATH\` (user) and \`WORKTRUNK_SYSTEM_CONFIG_PATH\` (system) overrides. Missing files at the overridden path resolve to no project config — same as a missing \`.config/wt.toml\` today. Uses it to fully isolate completion tests in \`tests/integration_tests/shell_wrapper.rs\`, which previously only isolated user and system config. After #2266 made aliases appear as top-level completion candidates at \`wt <Tab>\`, any \`[aliases]\` added to this repo's own \`.config/wt.toml\` would silently pollute completion snapshots. The helper \`set_empty_user_config\` is renamed \`set_empty_configs\` and now points all three env vars at \`/dev/null\`. Also cleans up \`wt config show --format=json\` to use \`project_config_path()\` for the \`project.path\` field (was hardcoded \`.config/wt.toml\`), so the override is reflected in both path and config. \`configure_cli_command\` intentionally leaves \`WORKTRUNK_PROJECT_CONFIG_PATH\` unset — the \`WORKTRUNK_*\` env_remove loop prevents host leakage, and setting it would break tests that rely on the default \`.config/wt.toml\` lookup in their own test repo. Completion tests opt in explicitly via \`set_empty_configs\`. ## Test plan - [x] \`cargo run --quiet --bin wt -- hook pre-merge --yes\` — 3222/3222 green - [x] New integration test \`test_project_config_path_env_var_override\` covers override-to-different-file and override-to-missing-file Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
a1be5645c4 |
feat(alias): dispatch aliases from top-level wt <name> (#2266)
`wt deploy` now resolves `deploy` against configured aliases before falling through to a `wt-deploy` PATH binary. Built-ins still win (clap matches before alias dispatch ever runs), and `wt step <name>` keeps working at runtime — only the docs cut over to the new form. ## Why `wt deploy` reads better than `wt step deploy`, and aliases as first-class commands lower friction for using them as everyday shortcuts. ## Precedence built-in (clap) → alias (user/project config, merged) → `wt-<name>` PATH binary → "unrecognized subcommand" error. User config wins over PATH binaries because aliases are how users customize wt — same model as git, where `[alias]` entries shadow `git-foo` externals. ## Navigating the diff - `src/commands/alias.rs` — refactored `step_alias` to share `run_alias` with the new `try_alias(name, rest) -> Result<Option<()>>`. Returns `Ok(None)` when the name isn't a configured alias or when not in a git repo; propagates config-load errors so a broken `wt.toml` fails loudly instead of silently turning into "unrecognized subcommand". Argument parsing is gated on alias-membership, so unrelated args meant for an external binary don't surface as alias parse errors. New `alias_names_for_suggestions()` mixes alias names into "did you mean" hints. `HelpContext` enum lets the help splice annotate "(shadowed by built-in)" against the right level (top-level builtins for `wt --help`, step builtins for `wt step --help`). The user-facing "shadow warning" was removed entirely — under the new model an alias named `commit` runs fine via `wt commit`, only `wt step commit` is shadowed. - `src/commands/external.rs` — `handle_external_command` calls `try_alias` first, then PATH lookup, then unrecognized-subcommand error. Suggestions include alias names. Non-UTF-8 args bypass alias dispatch (alias parser requires UTF-8; binary subcommands get raw `OsStr`). - `src/help.rs` + `src/main.rs` — early-parse pass returns `Option<HelpContext>`; help splice fires for both `wt --help` and `wt step --help`. - `src/completion.rs` — aliases injected at the top level in addition to `step`. - `src/cli/mod.rs` — long Aliases section moved out of `Step::after_long_help` into hand-authored `docs/content/extending.md`. New sync test `test_top_level_builtins_match_clap` keeps the `TOP_LEVEL_BUILTINS` constant aligned with the `Cli` enum. ## Tests 3221 tests pass, lints clean. New integration tests: `test_top_level_alias_dispatch`, `test_top_level_alias_with_step_builtin_name`, `test_top_level_alias_did_you_mean`. Removed `test_step_alias_shadows_builtin_plural` (warning gone). Reframed `test_step_alias_shadows_builtin` to verify shadow filtering of typo suggestions instead. Completion tests now isolate user config via `WORKTRUNK_CONFIG_PATH=/dev/null` — project config isolation is a noted gap (commented inline). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> |
||
|
|
670a572bdf |
test(completion): bypass shell startup files to keep PATH hermetic (#2237)
`test_zsh_completion_subcommands` (and the bash siblings) pass a clean
PATH via `.env("PATH", ...)`, but `zsh -c` still runs `/etc/zprofile`
(which calls `path_helper`) and `~/.zshenv`, which re-prepend
`~/.cargo/bin` before the script runs. If the user has `wt-sync`
installed there, clap-complete's external-subcommand discovery emits an
extra `sync` entry and the snapshot test fails locally.
Fix: invoke `zsh -f` and `bash --noprofile --norc` in the three tests
that spawn shells, so startup files don't run and PATH stays exactly
what the test sets. The fish/nushell tests run the `wt` binary directly
(no shell in between) and were already hermetic.
## Test plan
- [x] `cargo test --test integration --features shell-integration-tests
completion` — 66/66 pass locally with `~/.cargo/bin/wt-sync` present
- [x] Snapshots unchanged (visible subcommands remain `switch list
remove merge step hook config`)
> _This was written by Claude Code on behalf of Maximilian_
---------
Co-authored-by: Claude <noreply@anthropic.com>
|
||
|
|
7c03072e81 |
Restore clap-native error for unrecognized subcommands (#2212)
`#[command(external_subcommand)]` (added in #2054 for `wt-<name>` dispatch) captures every unknown subcommand, so clap's native `InvalidSubcommand` error path was dead — `wt s` printed a custom git-style line instead of clap's formatted error with suggestions and Usage block. This PR synthesizes a real `clap::Error{InvalidSubcommand}` when no `wt-<name>` binary is on PATH and routes it through `enhance_and_exit_error`, so the output matches what clap would have produced: \`\`\` error: unrecognized subcommand 's' tip: some similar subcommands exist: 'step', 'switch' Usage: wt [OPTIONS] [COMMAND] For more information, try '--help'. \`\`\` Nested-subcommand hints (`wt squash` → `wt step squash`) now layer on top of clap's error via the same path instead of a separate branch, so all unrecognized subcommands flow through one code path. Swap Levenshtein for Jaro-Winkler > 0.7 to match clap's internal `did_you_mean`, so short names like `s` get suggestions that match short-prefix typos. Exit code is now 2 (clap standard), matching pre-#2054 behavior. ## Test plan - [x] `cargo run -- s` / `siwtch` / `squash` / unknown → verified output and exit codes - [x] `wt hook pre-merge --yes` (full test suite, 3178 tests) - [x] Updated integration tests in `tests/integration_tests/external.rs` - [x] Regenerated 5 snapshots (4 nested-suggestion help + 1 shell source-flag) Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
b6ae21d6e1 |
refactor: prefer raw strings over escaped literals (#2150)
Converts ~29 string literals across 16 files from escaped form
(`"\\d+"`, `"{\"name\": 1}"`) to raw-string form (`r"\d+"`, `r#"{"name":
1}"#`) where possible. Strings containing control escapes (`\n`, `\t`,
`\u{1b}`, etc.) are left alone — raw strings can't represent those.
No behavior change; `cargo check/clippy -D warnings/fmt/test` all clean
locally.
> _This was written by Claude Code on behalf of max-sixty_
Co-authored-by: Claude <noreply@anthropic.com>
|
||
|
|
37fb27bc97 |
Deprecate table form for pre-* hooks (#2135)
## Summary
Multi-entry table form for pre-* hooks currently runs serially, while
the same form for post-* hooks runs concurrently. The parser produces
`HookStep::Concurrent` either way, but the foreground executor flattens
steps and runs them serially. To unify the semantics — table form will
run concurrently for all hook types in a future version — this
deprecates the current form for pre-* hooks and auto-migrates it to
pipeline form, which is explicitly serial.
## Implementation
Follows the existing deprecation recipe in `src/config/deprecation.rs`:
- **Detection** and **migration** for top-level hooks (user/project
config) and per-project overrides (`[projects."id".pre-*]`).
- **Warning**: matches the terse `{old} → {new}` pattern of existing
deprecations (`[merge] no-ff → ff`, `post-create → pre-start`, etc.).
- **Auto-migration** at load time: table form rewrites to pipeline of
inline tables so current behavior (serial) is preserved until users run
`wt config update`.
## Docs
Replaces the transitional "concurrent for post-*, sequential for pre-*"
framing with a neutral three-form description (string / table /
pipeline), plus a note recommending pipeline form for pre-* hooks to
avoid the upcoming behavior change.
## Tests
- `snapshot_migrate_pre_hook_table_form` — TOML migration diff
- `test_config_show_displays_pre_hook_table_form_deprecation` — full
user-facing `wt config show` output, covering the "Project config" label
and multi-hook list form
- Unit tests for detection/migration of top-level and per-project
variants
- Existing integration test fixtures migrated to canonical pipeline form
> _This was written by Claude Code on behalf of max-sixty_
Co-authored-by: Claude <noreply@anthropic.com>
|
||
|
|
b174658e29 |
Split directive file into CD (raw path) and EXEC (shell) files (#2118)
The shell wrapper previously used a single `WORKTRUNK_DIRECTIVE_FILE` where wt wrote shell commands (`cd '/path'`, arbitrary `--execute` payloads). This meant the cd path went through shell parsing — any content wt wrote was sourced as shell. This splits the protocol into two files with different trust levels: - **`WORKTRUNK_DIRECTIVE_CD_FILE`** — raw path, read with `cd -- "$(< file)"`. No shell parsing, no escaping, no injection surface. Safe to pass through to alias/hook child processes. - **`WORKTRUNK_DIRECTIVE_EXEC_FILE`** — arbitrary shell (from `--execute`), sourced by the wrapper. Scrubbed from alias/hook child environments so hook bodies cannot inject shell into the parent session. When a nested `wt` inside an alias body tries `--execute` without the EXEC file, the command is dropped with a warning linking to #2101 for user feedback. The old `WORKTRUNK_DIRECTIVE_FILE` is silently honored for one release (users who upgrade wt without restarting their shell). Bash, zsh, fish, and PowerShell self-update on restart; nushell requires `wt config shell install`. Closes #2101 > _This was written by Claude Code on behalf of @max-sixty_ --------- Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
de9bc631d6 | Forward shell completions to external subcommands (wt-*) (#2074) | ||
|
|
5709eb50d4 |
Add git-style external subcommand dispatch (wt-<name>) (#2054)
## Summary - `wt foo` now runs `wt-foo` from PATH when `foo` is not a built-in, mirroring `git foo` → `git-foo`. Third-party tools like a hypothetical `wt-sync` can be installed and invoked as `wt sync` without touching this repo. - Built-ins always take precedence (clap only dispatches `External` when no built-in matched), so external binaries cannot shadow existing subcommands. - Nested subcommand hints still pre-empt the PATH lookup — `wt squash` continues to suggest `wt step squash` rather than searching for `wt-squash`. - When nothing matches, wt prints a git-style `'foo' is not a wt command` error with a Levenshtein-based typo suggestion (replacing the old clap `InvalidSubcommand` handler). - The global `-C <path>` flag is forwarded as the child's working directory, matching git's semantics. - Child exit codes (including Unix signal codes) are propagated verbatim. wt does **not** decorate child failures with its own error line — the child has already reported whatever it needed to. Requested in #2053 — the original PR added `wt sync` as a built-in, but the preferred approach is a generic extensibility mechanism so `wt sync` can call any `wt-sync` binary on PATH. ## Implementation - `Commands::External(Vec<OsString>)` captured via clap's `#[command(external_subcommand)]`. - `src/commands/external.rs` owns the dispatch: nested-suggestion check first, then `which::which("wt-<name>")`, then run with `Command::status()` inheriting stdio. - `main()` dispatches `External` directly (instead of via `dispatch_command`) so the parsed `-C <path>` can be forwarded as the child's cwd. - The nested-suggestion path moved from clap's built-in error renderer to our module; help snapshots updated to the cleaner worktrunk-style output (✗ / ↳). ## Test plan - [x] `cargo test --test integration external_subcommand` — 7 new integration tests cover happy path, not-found error, typo suggestion, nested suggestion winning over PATH lookup, exit-code propagation (exit 42), `-C` flag forwarding, and `--help` passthrough. - [x] `cargo test --bins` — 3 new unit tests for `closest_subcommand` (typo, unrelated, hidden). - [x] `cargo test --test integration` — full suite passes (1407 tests). - [x] `cargo test --lib --bins` — full unit suite passes (500 tests). - [x] `cargo fmt --check` and `cargo clippy --all-targets --all-features -- -D warnings`. - [x] Manual smoke tests: `wt wt-<name>`, `wt unknown`, `wt siwtch`, `wt squash`, `wt -C /tmp wt-<name>`, `wt wt-<name> --help`, child exit code 42 propagation. --------- Co-authored-by: worktrunk-bot <254187624+worktrunk-bot@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> |
||
|
|
c5c446539e |
Simplify code by extracting helpers and normalizing config (#1813)
Refactoring branch with 13 commits that decompose large functions into smaller, focused helpers across the codebase. Net -104 lines. Key changes: - **Config system**: Extract `merged_project_config()` for repetitive project-override lookups; move deprecated config normalization (`[commit-generation]` → `[commit.generation]`, `[select]` → `[switch.picker]`) from lazy per-access to eager at load time; extract persistence helpers (`update_bool_flag`, `sync_string_field`, `sync_serialized_section`) - **Output handlers**: Split `handle_switch_output` and `handle_removed_worktree_output` into phase-based helpers; extract `BranchDeletionDisplay` struct and `print_retained_unmerged_branch`; parameterize `FlagNote::after()` by color instead of duplicating methods - **main.rs**: Decompose `main()` into `parse_cli`, `init_logging`, `dispatch_command`, `handle_command_failure`, etc. - **shell_exec**: Extract `ExternalCommandLog`, `apply_common_settings`, shared builder logic between `run()` and `stream()` - **remote_ref**: Extract `run_cli_api()` and `CliApiRequest` shared between GitHub and GitLab modules - **Tests**: Extract snapshot filter groups into semantic helpers; consolidate shell wrapper test setup The one behavioral change is in config loading: deprecated config sections are now normalized eagerly on load rather than checked lazily on every accessor call. This simplifies accessor methods and is functionally equivalent. > _This was written by Claude Code on behalf of @max-sixty_ --------- Co-authored-by: Maximilian Roos <maximilian@Maximilians-MacBook-Pro.local> Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
5c1672932f |
docs: remove deprecated post-create from documentation (#1776)
Replace all `post-create` references with `pre-start` across documentation, skills, example config, and test names. The Rust deprecation handling code (migration, alias, config parsing) remains intact for users with existing configs. Also removes `post-create` from the `wt hook show` value_parser — it was listed as a valid hook type for display even though it's been deprecated. > _This was written by Claude Code on behalf of @max-sixty_ Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
efad9312db |
feat!: rationalize hooks — rename post-create, add post-commit, background post-merge (#1679)
Implements the hook rationalization from #1670, establishing a symmetric `pre-` (blocking) / `post-` (background) pattern for every lifecycle event. ## Changes **Rename `post-create` → `pre-start`**: The old name suggested it ran *after* creation, but it actually runs *before* `post-start` as a blocking dependency step. Both names accepted for one release cycle — config deprecation detection, migration file generation, `wt config update` support, and CLI alias all in place. `merge_with` folds old-name hooks into new-name so cross-config combinations don't silently drop hooks. **Add `post-commit` hook**: New background hook firing after successful commits (including squash commits), completing the commit lifecycle pair. Included in approval batches for `wt step commit`, `wt step squash`, and `wt merge`. **Change `post-merge` to background**: Was blocking with `Warn` strategy, now runs in background like all other `post-` hooks. `--foreground` flag available for debugging. The hook table is now a clean symmetric grid: | Event | `pre-` (blocking) | `post-` (background) | |-------|-------------------|---------------------| | start | `pre-start` | `post-start` | | switch | `pre-switch` | `post-switch` | | commit | `pre-commit` | `post-commit` | | merge | `pre-merge` | `post-merge` | | remove | `pre-remove` | `post-remove` | ## Testing 868 lib + 483 bin + 1227 integration tests pass, all 13 lint checks pass. The deprecation has 23 dedicated unit tests covering detection at all three config scopes, migration, empty table filtering, cross-config merge safety, and integration with `wt config show` / `wt config update`. Closes #1670 > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
1afa9c230b | refactor: rename get_* functions to bare nouns (#1586) | ||
|
|
2e29a275dd |
docs: use .localhost subdomains instead of .lvh.me for Caddy routing (#1343)
Replace `.lvh.me` with `.localhost` in all Caddy subdomain routing examples (docs, CLI help, tests). `.localhost` resolves to 127.0.0.1 via the OS on macOS and Linux with systemd-resolved — no external DNS dependency. Also fixes a flaky PTY test: `WORKTRUNK_TEST_DELAYED_STREAM_MS` was missing from `STANDARD_TEST_ENV` in shell_wrapper.rs, causing `git worktree add` output to appear non-deterministically under heavy parallel load. Closes #1334 > _This was written by Claude Code on behalf of maximilian_ --------- Co-authored-by: worktrunk-bot <254187624+worktrunk-bot@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Maximilian Roos <m@maxroos.com> |
||
|
|
b0aa493074 |
fix: use marker file in fish completions test to avoid PTY race (#1286)
## Problem `test_fish_completions_registered` failed on macOS CI with empty PTY output. The test relied on reading `__COMPLETION_REGISTERED__` from the PTY combined output, but PTY buffer flushing is unreliable on CI — the output was completely empty despite the script running successfully (exit code 0). This is a flaky test, not caused by the commit under test (`dc7f5bca` — bright-black to underline formatting change). ## Solution Use the marker file pattern already established by `test_zsh_wrapper_function_registered` (line 1930). Instead of checking PTY output for the marker string, the fish script writes its result to a file, and the test polls for that file using `wait_for_file_content()`. This is the right level to fix because: - The zsh test already uses this pattern with the comment "PTY buffer flushing is unreliable on CI" - The fish test was the only remaining shell registration test relying on PTY output - The marker file + polling approach is robust against PTY timing issues ## Alternatives considered - **Retry the CI run**: Would work short-term but the flake would recur - **Add a sleep before reading PTY output**: Unreliable, the zsh test already moved away from this approach ## Testing - Ran `cargo test --test integration test_fish_completions_registered --features shell-integration-tests` — passes locally --- 🤖 Automated fix for [failed run](https://github.com/max-sixty/worktrunk/actions/runs/22713095708) --------- Co-authored-by: worktrunk-bot <254187624+worktrunk-bot@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> |
||
|
|
687762b820 |
fix(test): use marker file for fish binary-not-found test on macOS (#1268)
## Problem
The `test_fish_binary_not_found_clear_error::case_1` test fails on macOS
CI because PTY output capture for fish shell returns empty output. The
test asserts on `output.combined.contains("wt: command not found")`, but
the combined output string is empty on macOS.
This is a known macOS PTY behavior — the sibling test
`test_fish_wrapper_binary_not_found_no_infinite_loop` already documents
and works around this:
> "This is reliable even when PTY output capture fails on macOS"
## Solution
Apply the same marker-file pattern used by the sibling test:
1. Write the exit code to a marker file from within the fish script
2. Use the marker file as the **primary check** (exit code = 127)
3. Demote the PTY output assertion to a **secondary check** that only
runs when output is actually captured
This matches the established pattern in the codebase and is robust
across platforms.
## Alternatives considered
- **Retry/increase timeout**: Wouldn't help — the empty output is a
consistent PTY behavior on macOS, not a timing issue
- **Skip on macOS**: Too broad — the test logic is valid, just the
verification method was fragile
## Testing
- Test passes locally on Linux: `cargo test --test integration
test_fish_binary_not_found_clear_error --features
shell-integration-tests`
- Waiting for macOS CI to confirm the fix
---
🤖 Automated fix for [failed
run](https://github.com/max-sixty/worktrunk/actions/runs/22697350335)
---------
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
|
||
|
|
cbd5e4da50 |
feat: add nushell tab completions (#1220)
## Summary
- Add `nu-complete wt` completer function to the nushell init template,
wiring it to the wrapper's rest parameter via `@"nu-complete wt"`
- The completer calls the binary with `COMPLETE=nu` and parses
tab-separated output into nushell's `{value, description}` record format
- Add `"nu"` to multi-shell completion test loops (help, version,
single-dash, deprecated flags) and a dedicated subcommand snapshot test
Thanks to @omerxx for reporting in #1215.
Closes #1215
## Limitations
Nushell's completion engine bypasses custom completers when the current
token starts with `-`, so flag completions (e.g. `wt switch --<TAB>`)
don't appear. Subcommand and value completions work correctly. This is a
nushell engine limitation (nushell/nushell#14504), not something we can
fix in our template.
## Test plan
- [x] Unit tests pass (`cargo test --lib --bins`) — snapshot updated
- [x] Integration tests pass (`cargo test --test integration`) — 1121
tests
- [x] Shell integration test (`cargo test --test integration --features
shell-integration-tests -- test_nushell_completion_subcommands`)
- [x] Lints pass (`pre-commit run --all-files`)
- [x] Manual verification in nushell 0.110.0: `wt <TAB>` shows
subcommands, `wt switch <TAB>` shows branches with descriptions
> _This was written by Claude Code on behalf of @max-sixty_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude <noreply@anthropic.com>
|
||
|
|
23c3ded8fa | fix(test): use relative paths in mixed stdout/stderr snapshot test (#1213) | ||
|
|
670d6cc7d2 |
feat: add system-wide config file support (#963)
* feat: add system-wide config file support
Load organization-wide defaults from a system config file before user
config, allowing companies to distribute shared preferences via
configuration management.
Config loading order (later overrides earlier):
1. System config (organization defaults)
2. User config (personal preferences)
3. Environment variables
System config search locations:
- $WORKTRUNK_SYSTEM_CONFIG_PATH (explicit override)
- $XDG_CONFIG_DIRS directories (colon-separated)
- Linux: /etc/xdg/worktrunk/config.toml
- macOS: /Library/Application Support/worktrunk/config.toml
- Windows: %PROGRAMDATA%\worktrunk\config.toml
Uses the same format as user config. Visible in `wt config show`.
https://claude.ai/code/session_01FeQXY5Hu8STpn5DZPvkxWC
* fix: apply cargo fmt formatting
Apply rustfmt formatting to fix CI lint failures:
- Split long `pub use` statement across multiple lines in `mod.rs`
- Condense multi-line path building to single line in `path.rs`
- Format long string assignment in `tests.rs`
- Improve method chaining formatting in integration tests
* fix: ensure consistent system config path in tests across platforms
Add `WORKTRUNK_SYSTEM_CONFIG_PATH` to test environment setup to prevent
platform-specific system config paths from appearing in snapshots.
Changes:
- Set `WORKTRUNK_SYSTEM_CONFIG_PATH=/etc/xdg/worktrunk/config.toml` in `configure_wt_cmd()` (TestRepo)
- Set `WORKTRUNK_SYSTEM_CONFIG_PATH=/etc/xdg/worktrunk/config.toml` in `configure_cli_command()` (standalone tests)
- Add filter for non-canonicalized macOS temp paths (`/var/folders/...`)
This ensures tests show consistent "Not found (optional)" for system config
across Linux, macOS, and Windows, preventing snapshot mismatches.
* style: apply cargo fmt to tests/common/mod.rs
https://claude.ai/code/session_01FeQXY5Hu8STpn5DZPvkxWC
* fix: add WORKTRUNK_SYSTEM_CONFIG_PATH to PTY test environment
Add `WORKTRUNK_SYSTEM_CONFIG_PATH` to `test_env_vars()` to ensure PTY-based
tests (like switch picker) have consistent system config behavior across platforms.
Without this, PTY tests would fall back to platform-specific system config
paths, causing test output to vary between Linux, macOS, and Windows.
* refactor: remove #[cfg(test)] guards from config path resolution
Eliminate all test/non-test cfg annotations from path.rs. Both user
config and system config now use the same pattern: env var check first,
then platform default. Test isolation relies on env vars set by
TestRepo (WORKTRUNK_CONFIG_PATH, WORKTRUNK_SYSTEM_CONFIG_PATH), which
already covered integration tests.
Delete system_config_search_dirs() (fragile double-.parent() hack),
replace with default_system_config_path() that returns the env var
or first platform default.
Co-authored-by: Claude <noreply@anthropic.com>
* test: add integration tests for XDG_CONFIG_DIRS and platform default paths
Cover the system config resolution paths that were previously behind
#[cfg(not(test))] and never tested: XDG_CONFIG_DIRS lookup (found and
not-found cases), and platform default display path fallback.
Co-authored-by: Claude <noreply@anthropic.com>
* test: add coverage for system config edge cases in config show
Add tests for empty system config (hint message), invalid system config
(TOML parse error display), and unknown keys warning during config loading.
These exercise the render_system_config() and config loading paths.
Co-Authored-By: Claude <noreply@anthropic.com>
* docs: reduce system config prominence in config page
System config is a niche feature for organizations. Replace the dedicated
section, TOML example, and table row with a single sentence pointing to
`wt config show`. Env vars remain in the table for discoverability.
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: update powershell test snapshot for system config section
Test from main needed its snapshot updated to include the new
SYSTEM CONFIG section in config show output.
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(config): resolve list timeout from per-project config (#1063)
* refactor(list): move timeout resolution into collect
Move raw_timeout extraction from handle_list into the collect function's
config resolution phase. This simplifies the public API by removing an
unused field from ShowConfig::DeferredToParallel and consolidates timeout
logic (including the --full override) into a single location where it can
access the merged project-specific config.
* refactor(config): add repo.config() for resolved config access
Add Repository::config() -> &ResolvedConfig and
Repository::user_config() -> &UserConfig, both lazily loaded and cached
in RepoCache. This makes correct config resolution the default path —
callers use repo.config() and get project-specific overrides applied
automatically.
Migrate wt list / wt select to use repo.config() instead of receiving
&UserConfig as a parameter. This removes the manual config resolution
that led to the timeout_ms bug (reading global config instead of merged
project-specific config).
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor(select): move config resolution into handle_select
Move CLI flag + config resolution from callers into handle_select(),
which already creates a Repository. This simplifies main.rs callers
and improves coverage on changed lines (callers in untestable
terminal paths now have minimal code).
Also switch select's post-selection switch to repo.user_config()
instead of UserConfig::load().
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
* feat(switch): enrich error hints with --execute context (#1064)
* feat(switch): enrich error hints with --execute and trailing args context
When `wt switch --execute=<cmd> -- <args>` fails (branch not found, already
exists, path exists), error hints now include the full command context so
users can copy-paste the suggested fix directly.
Also fixes `suggest_command()` to place flags before positional args (and
before any `--` separator), preventing flags from being treated as positional
args when dash-prefixed branches are involved.
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(coverage): remove unreachable -- separator branch in apply()
Clap's `#[arg(last = true)]` on execute_args means `--` always routes
to execute_args, so a dash-prefixed branch can't coexist with --execute
via the CLI. The suggested command never has a pre-existing `--`
separator when SwitchSuggestionCtx is applied, making this branch
dead code.
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
* Refactor approvals into separate file with deprecation migration (#1042)
* Refactor approvals into separate file
Approved commands are now stored in `~/.config/worktrunk/approvals.toml`,
independent of user config. This enables dotfile management of
`config.toml` without exposing machine-local trust state.
The `Approvals` type provides the same mutation interface as
`UserConfig` (approve/revoke commands, file locking) but stores
exclusively approval data. For backward compatibility, approvals
are silently read from `config.toml` if `approvals.toml` doesn't exist.
All command approval code now uses `Approvals::load()` and passes
`&approvals` to `approve_command_batch()`. Tests use isolated
`test_approvals_path()` to prevent pollution of user approvals.
* Add deprecation warning for approved-commands in config.toml
Approved commands moved to approvals.toml in the previous commit but
stale entries in config.toml were silently ignored. Now `wt config show`
detects them, generates a migration file that removes the entries, and
shows a diff + mv command. Other commands show a brief warning.
Also updates all CLI help text, docs, and FAQ to reference
approvals.toml as the storage location, and migrates all test configs
to use write_test_approvals() for approved-commands content.
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: document fallback path asymmetry and add config.toml fallback tests
Address PR review feedback:
- Document why `load_from_config_fallback()` uses `get_config_path()` while
`reload_from()` uses sibling derivation, and why both converge in production
- Add `test_load_from_config_file` testing the extraction logic
- Add `test_mutation_picks_up_config_toml_fallback` testing the full mutation
path with config.toml fallback (no approvals.toml → reads config.toml →
preserves existing commands alongside new one)
- Inline `get_config_path` import (only used in `#[cfg(not(test))]` block)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: single fallback path for config.toml approvals
Replace two separate fallback implementations (load_from_config_fallback
via get_config_path, and reload_from via sibling derivation) with a
single load_with_fallback(path) that both load() and reload_from() use.
The shared helper derives config.toml as a sibling of the approvals
file, which is always correct since get_approvals_path() derives
approvals.toml as a sibling of config.toml.
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(tests): pass WORKTRUNK_APPROVALS_PATH in shell wrapper tests
Shell wrapper tests only passed WORKTRUNK_CONFIG_PATH to the binary,
so it derived the approvals path from config and found approved-commands
in config.toml, triggering the new deprecation warnings. This broke
4 snapshot tests and likely caused 6 timeouts on CI.
Fix: pass WORKTRUNK_APPROVALS_PATH alongside WORKTRUNK_CONFIG_PATH in
all shell wrapper test environments (build_shell_script, build_test_env_vars,
and custom script builders for all shell types). Migrate all approved-commands
writes from test_config_path() to write_test_approvals().
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(docs): escape brackets in doc comments for rustdoc
Rustdoc interprets `[projects]` as a broken intra-doc link.
Escape with `\[...\]` to treat as literal text.
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(tests): migrate approvals in e2e_shell_post_start and approval_pty tests
- e2e_shell_post_start: write approved-commands to approvals.toml
instead of config.toml (fixes 5 timeout failures from unanswered
approval prompts)
- approval_pty permission test: use a subdirectory for the read-only
approvals path so the temp root stays writable for .zshrc and other
test files
Co-Authored-By: Claude <noreply@anthropic.com>
* test: improve coverage for approvals and deprecation modules
Add tests covering error paths, edge cases, and new deprecation features:
- approvals.rs: load_from_file parse errors, load_from_config_file parse
errors, load_from_path nonexistent, revoke on nonexistent projects,
clear_all when empty, save_to with empty project, revoke_project with
empty commands
- deprecation.rs: remove_approved_commands with invalid TOML,
format_deprecation_details with approved_commands flag,
write_migration_file with approved_commands
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: remove unused revoke_command from Approvals
Adversarial review found a normalization bug: revoke_command used exact
string matching while is_command_approved normalizes template variables.
Rather than fix a method with no production callers, remove it entirely.
Production code uses revoke_project (removes all approvals for a project)
and clear_all.
Rewrote test_concurrent_revoke_preserves_all_changes to use revoke_project.
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
* refactor: consolidate shell escaping on shell_escape, drop shlex (#1065)
Both `shell_escape` and `shlex` were used for shell quoting. `shell_escape`
is the project standard (~10 files); `shlex` was only used in 2 call sites
for `try_quote()`. Consolidate on the single crate.
Co-authored-by: Claude <noreply@anthropic.com>
* fix(test): wait for item content in switch picker PTY tests (#1066)
* fix(test): wait for item content in switch picker PTY tests
On macOS CI under heavy load, skim may render the prompt and header
line before item rows, causing wait_for_stable (500ms threshold) to
capture the screen too early — before branch entries appear.
Fix by passing expected content to the pre-abort wait, ensuring the
test waits until items are actually rendered. This matches the pattern
already used by test_switch_picker_respects_list_config.
Also harden test_switch_picker_with_multiple_worktrees with the same
pattern as a preventive measure.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(switch): replace remaining shlex reference with shell_escape
Commit
|
||
|
|
600da7101b |
Refactor approvals into separate file with deprecation migration (#1042)
* Refactor approvals into separate file Approved commands are now stored in `~/.config/worktrunk/approvals.toml`, independent of user config. This enables dotfile management of `config.toml` without exposing machine-local trust state. The `Approvals` type provides the same mutation interface as `UserConfig` (approve/revoke commands, file locking) but stores exclusively approval data. For backward compatibility, approvals are silently read from `config.toml` if `approvals.toml` doesn't exist. All command approval code now uses `Approvals::load()` and passes `&approvals` to `approve_command_batch()`. Tests use isolated `test_approvals_path()` to prevent pollution of user approvals. * Add deprecation warning for approved-commands in config.toml Approved commands moved to approvals.toml in the previous commit but stale entries in config.toml were silently ignored. Now `wt config show` detects them, generates a migration file that removes the entries, and shows a diff + mv command. Other commands show a brief warning. Also updates all CLI help text, docs, and FAQ to reference approvals.toml as the storage location, and migrates all test configs to use write_test_approvals() for approved-commands content. Co-Authored-By: Claude <noreply@anthropic.com> * fix: document fallback path asymmetry and add config.toml fallback tests Address PR review feedback: - Document why `load_from_config_fallback()` uses `get_config_path()` while `reload_from()` uses sibling derivation, and why both converge in production - Add `test_load_from_config_file` testing the extraction logic - Add `test_mutation_picks_up_config_toml_fallback` testing the full mutation path with config.toml fallback (no approvals.toml → reads config.toml → preserves existing commands alongside new one) - Inline `get_config_path` import (only used in `#[cfg(not(test))]` block) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: single fallback path for config.toml approvals Replace two separate fallback implementations (load_from_config_fallback via get_config_path, and reload_from via sibling derivation) with a single load_with_fallback(path) that both load() and reload_from() use. The shared helper derives config.toml as a sibling of the approvals file, which is always correct since get_approvals_path() derives approvals.toml as a sibling of config.toml. Co-Authored-By: Claude <noreply@anthropic.com> * fix(tests): pass WORKTRUNK_APPROVALS_PATH in shell wrapper tests Shell wrapper tests only passed WORKTRUNK_CONFIG_PATH to the binary, so it derived the approvals path from config and found approved-commands in config.toml, triggering the new deprecation warnings. This broke 4 snapshot tests and likely caused 6 timeouts on CI. Fix: pass WORKTRUNK_APPROVALS_PATH alongside WORKTRUNK_CONFIG_PATH in all shell wrapper test environments (build_shell_script, build_test_env_vars, and custom script builders for all shell types). Migrate all approved-commands writes from test_config_path() to write_test_approvals(). Co-Authored-By: Claude <noreply@anthropic.com> * fix(docs): escape brackets in doc comments for rustdoc Rustdoc interprets `[projects]` as a broken intra-doc link. Escape with `\[...\]` to treat as literal text. Co-Authored-By: Claude <noreply@anthropic.com> * fix(tests): migrate approvals in e2e_shell_post_start and approval_pty tests - e2e_shell_post_start: write approved-commands to approvals.toml instead of config.toml (fixes 5 timeout failures from unanswered approval prompts) - approval_pty permission test: use a subdirectory for the read-only approvals path so the temp root stays writable for .zshrc and other test files Co-Authored-By: Claude <noreply@anthropic.com> * test: improve coverage for approvals and deprecation modules Add tests covering error paths, edge cases, and new deprecation features: - approvals.rs: load_from_file parse errors, load_from_config_file parse errors, load_from_path nonexistent, revoke on nonexistent projects, clear_all when empty, save_to with empty project, revoke_project with empty commands - deprecation.rs: remove_approved_commands with invalid TOML, format_deprecation_details with approved_commands flag, write_migration_file with approved_commands Co-Authored-By: Claude <noreply@anthropic.com> * refactor: remove unused revoke_command from Approvals Adversarial review found a normalization bug: revoke_command used exact string matching while is_command_approved normalizes template variables. Rather than fix a method with no production callers, remove it entirely. Production code uses revoke_project (removes all approvals for a project) and clear_all. Rewrote test_concurrent_revoke_preserves_all_changes to use revoke_project. Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
8408c020ff |
fix(test): eliminate spurious blank lines in PTY snapshots (#1040)
* Remove blank lines after prompts; add prompt-aware PTY tests Remove redundant eprintln!() after read_line() in prompt functions — the Enter key echo already provides the line break, so the extra blank line violated "blank before prompts, not after." Add prompt-aware PTY test helpers that wait for the prompt marker before sending input, so captured output matches real terminal behavior. The PTY module now exposes 3 composable functions (build_pty_command + exec_cmd_in_pty / exec_cmd_in_pty_prompted) instead of 8 wrappers. Co-Authored-By: Claude <noreply@anthropic.com> * fix(test): eliminate PTY echo artifact causing blank lines in snapshots portable_pty's UnixMasterWriter::drop() sends \n + EOT to the PTY master. When drop(writer) happened before child.wait(), the terminal echoed this \n as \r\n — producing a spurious blank line in captured output. Fix by reordering: wait for the child first, then drop the writer (echo goes to a dead PTY). Also remove the "collapse consecutive newlines" filter in configure_shell tests that was masking this bug. Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
c7128ce11b | Add nushell support (#964) | ||
|
|
3b5b609a04 |
refactor(env): rename WT_TEST_* env vars to WORKTRUNK_TEST_* (#1016)
Standardize the two remaining `WT_`-prefixed env vars to use the `WORKTRUNK_` prefix, completing the migration noted in the changelog. - WT_TEST_EPOCH → WORKTRUNK_TEST_EPOCH - WT_TEST_DELAYED_STREAM_MS → WORKTRUNK_TEST_DELAYED_STREAM_MS Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
50d12a7e14 |
refactor: rename wt select references to wt switch interactive picker (#959)
* refactor: rename `wt select` references to `wt switch` interactive picker Update all documentation, comments, and test references from the deprecated `wt select` to `wt switch` interactive picker. Migrate TUI tests from select.rs to switch_picker.rs exercising `wt switch` directly. - Docs/comments: Replace `wt select` with `wt switch` interactive picker - Tests: Rename select.rs → switch_picker.rs, use `wt switch` CLI args - Remove redundant tests covered by existing switch.rs tests - Fix pre-existing incorrect binary/path in src/commands/CLAUDE.md - Leave alone: CHANGELOG, runtime deprecation warnings, [select] config section names, demo assets Co-Authored-By: Claude <noreply@anthropic.com> * fix: add missing switch_picker snapshot files for CI The switch_picker tests (migrated from select tests) generate snapshots via PTY execution, which need to be committed for CI to pass. Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
4bfe85403c |
fix(ci): use compile-time binary path for nextest compatibility (#884)
* fix(ci): build wt binary before running nextest
## Problem
The test `test_switch_with_execute_through_wrapper` was failing on macOS CI with:
```
bash: /Users/runner/work/worktrunk/worktrunk/target/debug/wt: No such file or directory
```
Root cause: `cargo nextest` only builds test binaries, not the main binary. The
shell_wrapper tests use `insta_cmd::get_cargo_bin("wt")` which expects the main
binary to exist at `target/debug/wt`. When running via nextest without building
the binary first, this path doesn't exist, causing the test to fail.
The issue surfaced after commit
|
||
|
|
e154b9ee50 |
Add LLM setup prompt for first-time commit configuration (#867)
* Add LLM setup prompt for first-time commit configuration Implement one-time interactive prompt when users attempt commit/merge/squash without LLM configuration. Detects available tools (claude, codex) and offers auto-configuration with preview on `?`. Adds `skip-commit-generation-prompt` flag to suppress re-prompting, `set_commit_generation_command()` config method, and reusable `prompt_yes_no_preview()` utility. Updates commit message templates to clarify format requirements, fixes Claude Code command syntax (spaces to equals in flags), and adds visual styling to section headers in documentation. * Update snapshots for template format changes Co-Authored-By: Claude <noreply@anthropic.com> * Simplify commit template format guidance Remove redundant trivial-changes line from template format section. Fix duplicate "# Other" header from merge. Document skip-commit-generation-prompt in first-run prompts section alongside skip-shell-integration-prompt. Co-Authored-By: Claude <noreply@anthropic.com> * Add unit tests for command detection functions Cover command_exists() and detect_llm_tool() with basic unit tests to improve test coverage on the commit generation module. Co-Authored-By: Claude <noreply@anthropic.com> * Add PTY tests for commit generation prompt Test the interactive prompt flow for LLM commit configuration: - No tool found → sets skip flag - User declines → sets skip flag - User accepts → saves config - User requests preview → shows preview Uses fake claude script to test the prompt path that requires a detected LLM tool. Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> |
||
|
|
f8aaead5b3 |
refactor: restructure commit-generation config to [commit.generation] (#809)
* refactor: restructure commit-generation config to [commit.generation] - Move `[commit-generation]` to `[commit.generation]` (nested under commit) - Replace `command` + `args` with single `command` string (shell execution) - Add deprecation warning for old format with backward compatibility - Update docs to present Claude CLI and llm as equal options The new format uses shell execution (`sh -c`) so environment variables can be set inline in the command string. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: update tests and docs for new commit.generation config format Fix test regressions identified by Codex review where tests using WORKTRUNK_COMMIT_GENERATION__ARGS were silently failing because args is now ignored with the new shell-based command format. Tests now use the correct pattern: WORKTRUNK_COMMIT_GENERATION__COMMAND="cat >/dev/null && echo 'message'" Also update CLI docs to show: - New config path: commit.generation.command (not commit-generation.command) - New env var format: WORKTRUNK_COMMIT__GENERATION__COMMAND - Remove args documentation (no longer applicable) Co-Authored-By: Claude <noreply@anthropic.com> * fix: update doc comments and add validation for new config path Address Codex review feedback: - Update per-project doc example to show new format (commit.generation instead of commit-generation) - Update env var comment to show new format (COMMIT__GENERATION__COMMAND instead of COMMIT_GENERATION__COMMAND) - Add validation for projects.*.commit.generation path (was only validating deprecated commit-generation path) Co-Authored-By: Claude <noreply@anthropic.com> * fix: address remaining Codex review issues - Use ShellConfig for LLM command execution (Windows compatibility) - Improve error handling when LLM stderr is empty - Format reproduction commands with conditional sh -c wrapping - Update tests to use new env var format (WORKTRUNK_COMMIT__GENERATION__) - Make test assertion more specific ([commit] not just "commit") - Document cformat safety for shell commands in output guidelines Co-Authored-By: Claude <noreply@anthropic.com> * refactor: use shell_escape crate for reproduction command escaping Replace manual single-quote escaping with the shell_escape crate which is already a dependency used elsewhere in the codebase. Co-Authored-By: Claude <noreply@anthropic.com> * feat: unify deprecation handling with single .new migration file Consolidate all deprecation handling into deprecation.rs: - Add [commit-generation] → [commit.generation] section migration - Merge deprecated `args` field into `command` string - Generate single .new file with all migrations (template vars + sections) - Skip migration if new section already exists (don't overwrite) - Skip warning for empty deprecated sections - Use shell_escape for proper quoting when merging args - Rename hint from deprecated-project-config to deprecated-config Remove separate warn_deprecated_commit_generation() from user.rs. Co-Authored-By: Claude <noreply@anthropic.com> * fix: harden commit-generation migration against edge cases Fixes found during adversarial testing: 1. Args data loss prevention: merge_args_into_command() now validates preconditions (args is array, command is string) BEFORE removing the args field. Previously, table.remove("args") happened unconditionally, losing data if command was missing or non-string. 2. Malformed generation detection: When checking if new [commit.generation] exists, now verify it's actually a table (is_table || is_inline_table). A malformed value like `generation = "string"` no longer suppresses deprecation warnings for the old section. 3. Inline table support: Both detection and migration now handle inline table format (e.g., `commit-generation = { command = "..." }`). Detection uses as_inline_table() in addition to as_table(). Migration converts InlineTable to Table via into_table(). Added comprehensive tests for all edge cases. Co-Authored-By: Claude <noreply@anthropic.com> * test: add coverage for project-level inline table migration Add tests for: - Project-level inline table migration - Preserving existing [commit] fields during migration - Empty inline table detection (should not flag as deprecated) Co-Authored-By: Claude <noreply@anthropic.com> * test: add integration test for commit-generation deprecation warning Add test that exercises the full deprecation path through check_and_migrate() for commit-generation section rename and args merge. This improves coverage on the warning output and migration file generation paths. Co-Authored-By: Claude <noreply@anthropic.com> * test: add integration test for project-level commit-generation deprecation Add test that exercises the project_keys iteration path in check_and_migrate() for project-level commit-generation deprecation warnings. This covers the warning message format that includes project identifiers. Co-Authored-By: Claude <noreply@anthropic.com> * test: add edge case tests for merge_args_into_command Cover the early-return paths in merge_args_into_command(): - Args without command: args preserved (no command to merge into) - Non-string command: args preserved (can't merge into non-string) - Command-only: clean migration without args field These tests exercise the !can_merge validation path. Co-Authored-By: Claude <noreply@anthropic.com> * test: cover malformed config fallback branches in migration Add tests for the `_ => None` fallback branches that handle unusual cases where commit-generation is neither a table nor inline table (e.g., a string value like `commit-generation = "not a table"`). These tests exercise lines 264 and 305 in deprecation.rs. Co-Authored-By: Claude <noreply@anthropic.com> * test: add coverage for edge cases in deprecation migration Add unit tests for: - Empty command with args: args become the command when command="" - Invalid TOML parsing: returns content unchanged - Deduplication path: second call with same path hits early return These tests cover previously uncovered code paths in deprecation.rs. Co-Authored-By: Claude <noreply@anthropic.com> * test: add unit tests for llm helper functions Add tests for format_reproduction_command and is_lock_file to improve code coverage. Co-Authored-By: Claude <noreply@anthropic.com> * test: add unit tests for config merge logic Add tests for: - CommitConfig merge when only base/override has generation - CommitConfig merge when both have generation - CommitGenerationConfig merge for squash_template fields These cover previously uncovered branches in the Merge implementations. Co-Authored-By: Claude <noreply@anthropic.com> * test: add validation tests for new commit.generation format Add tests for validation error paths in the new [commit.generation] config format (both top-level and per-project). Co-Authored-By: Claude <noreply@anthropic.com> * test: add save_to() tests for commit.generation serialization Cover the "create from scratch" branch in save_to() which serializes commit.generation and deprecated commit-generation sections to new files. Previously only the "update existing file" branch was tested. Co-Authored-By: Claude <noreply@anthropic.com> * docs: fix "Claude CLI" to "Claude Code" Co-Authored-By: Claude <noreply@anthropic.com> * docs: deduplicate LLM setup from config page Remove Claude Code/llm setup examples from config docs since they duplicate llm-commits.md. Config page now links to llm-commits.md for setup and keeps only the custom prompt templates section. Co-Authored-By: Claude <noreply@anthropic.com> * fix: trigger deprecation warnings in `wt config show` Previously `config show` read files directly without calling the config loaders, so deprecation warnings weren't shown. Now we call UserConfig::load() and repo.load_project_config() to trigger warnings while still displaying invalid configs (the deprecation check runs on raw content before parsing). Co-Authored-By: Claude <noreply@anthropic.com> * docs: move aichat into Setup section with other options Move aichat example from "Alternative tools" into the Setup section as "Option 3: aichat" alongside Claude CLI and llm. Add "Custom scripts" subsection for the generic example. Remove the now-redundant "Alternative tools" section. Co-Authored-By: Claude <noreply@anthropic.com> * docs: reframe LLM setup as examples, not numbered options Change from "Option 1/2/3" to just showing examples of tools that work. Lead with the concept: any command that reads stdin and outputs a commit message. Simplify Claude Code example and condense install instructions. Co-Authored-By: Claude <noreply@anthropic.com> * Simplify LLM commit generation setup documentation Remove redundant setup instructions and tool-specific examples from config templates and documentation. Consolidate guidance to reference the main LLM commits docs page for setup details. * Skip deprecated section key in unknown fields warning Skip the "commit-generation" key when warning about unknown fields, since it's already handled by the deprecated sections warning and this prevents duplicate warnings in config output. * Extract DEPRECATED_SECTION_KEYS constant for reuse Instead of hardcoding "commit-generation" in the skip check, define a constant that documents which section keys are deprecated. This makes it easier to add future deprecated sections without forgetting to update the skip logic. Co-Authored-By: Claude <noreply@anthropic.com> * Remove unused has_args field from CommitGenerationDeprecations The has_args field was tracked but never used in production code — the migration logic runs unconditionally and handles both cases (with or without args). This simplifies the struct and removes a redundant test. Co-Authored-By: Claude <noreply@anthropic.com> * Move deprecated section filtering to callers of warn_unknown_fields Instead of having warn_unknown_fields know about deprecated sections and skip them internally, make the constant public and have callers filter before calling. This is cleaner because: 1. warn_unknown_fields doesn't need to know about the deprecation system 2. Callers already interact with deprecation, so filtering there is natural 3. The coupling is explicit rather than hidden inside the function Co-Authored-By: Claude <noreply@anthropic.com> * fix: use Unix shell escaping for migration hint command The `mv` command in the migration hint is a Unix command, so use `shell_escape::unix::escape` instead of the platform-specific `escape` to get consistent output on all platforms. Co-Authored-By: Claude <noreply@anthropic.com> * fix: normalize path separators before shell escaping Convert backslashes to forward slashes before shell escaping so the migration hint command is consistent across platforms. Forward slashes work in Git Bash on Windows. Co-Authored-By: Claude <noreply@anthropic.com> * fix: remove shell escaping from migration hint paths Shell escaping was producing different output on Windows vs Unix even with unix::escape, likely due to some invisible path characteristic. Since config paths rarely contain special characters, just output the paths directly with forward slashes. Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> |