Skip to content

fix(alias): pass alias stdout through so 'wt <alias> | ...' works - #2479

Merged
max-sixty merged 1 commit into
mainfrom
fix/issue-2478
Apr 29, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/issue-2478

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Problem

wt <alias> writes the alias body's stdout onto wt's stderr instead of stdout, so wt my-alias | tr … (or any other downstream pipe) silently produces no output. Reported in #2478:

# config.toml
[aliases]
test-output = "echo 'hello'"

$ wt test-output | tr '[:lower:]' '[:upper:]'
hello   # ← should be HELLO

Root cause is in src/output/handlers.rs::execute_shell_command, which Cmd::shell(...).stdout(Stdio::from(io::stderr())) for every foreground command. The redirect was originally a hook-only behavior added for deterministic ordering with wt's own stderr "Running …" messages; PR #2089 unified hooks, aliases, and for-each onto this shared executor and inherited the redirect uniformly without distinguishing aliases.

Solution

Thread a redirect_stdout_to_stderr bool through ForegroundStep and execute_shell_command. Hooks (src/commands/hooks.rs) and wt step for-each (src/commands/for_each.rs) keep the merge (true) — their output is decoration around wt's stderr messages, and merging keeps ordering deterministic. Aliases (src/commands/alias.rs) pass through (false) — wt <alias> is a user-defined command and its stdout must remain pipeable.

Concurrent alias steps still write through output/concurrent.rs's prefixed-line stderr consumer — the gutter rendering (build │ BUILD) inherently belongs on stderr, so that path is unchanged.

Testing

  • Added test_alias_body_writes_to_stdout in tests/integration_tests/step_alias.rs. It runs an alias whose body is echo hello and asserts the output appears on stdout, not stderr. Failed before the fix; passes after.
  • Existing snapshot tests for step_alias pick up the routing change — diffs are limited to lines moving from ----- stderr ----- to ----- stdout -----, which is the user-visible behavior we want. Updated via cargo insta test --accept.
  • Manual end-to-end check: wt -y test-output | tr '[:lower:]' '[:upper:]' now prints HELLO.
  • Full cargo test --test integration (1569 tests) and cargo test --lib --bins (606 tests) pass.

Closes #2478 — automated triage

Aliases share `execute_shell_command` with hooks and `for-each`, all of
which were unconditionally redirecting child stdout onto wt's stderr for
deterministic ordering with wt's own progress messages. That ordering
guarantee is what hook output needs, but for aliases it makes
`wt my-alias | tr …` and similar compositions silently produce no output
because the alias body's stdout never reaches the pipe.

Threads a `redirect_stdout_to_stderr` flag through `ForegroundStep` and
`execute_shell_command`. Hooks and `for-each` keep the merge (`true`);
aliases pass it through (`false`). Concurrent alias steps still go
through the prefixed-line stderr writer in `output/concurrent.rs` —
their gutter rendering inherently belongs on stderr.

Closes #2478

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit f3eb8fe into main Apr 29, 2026
23 checks passed
@max-sixty
max-sixty deleted the fix/issue-2478 branch April 29, 2026 23:16
@max-sixty

Copy link
Copy Markdown
Owner

@worktrunk-bot can you do a survey of all the times we redirect child output?

@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

Surveyed every place where wt configures a child's stdout or stderr away from inherit. Three patterns turn up — only one is the bug shape from #2478, and it's now controlled by an explicit knob.

Merge child stdout onto stderr (the #2478 pattern)

src/output/handlers.rs — the shared foreground executor, gated on a redirect_stdout_to_stderr: bool after this PR. The three callers are:

Caller Setting Why
commands/hooks.rs:747 true hook output is decoration around wt's own stderr "Running …" lines
commands/for_each.rs:99 true wt step for-each prints decorated headers/footers; --format=json is emitted as a separate println! after children finish, so stdout pipes still work for the structured form
commands/alias.rs:568 false the fix in this PR — wt <alias> | …

src/output/concurrent.rs — concurrent groups capture both child streams and re-emit prefixed lines (build │ BUILD) on stderr only. This is shared by hook and alias concurrent steps; the gutter format inherently belongs on stderr, so concurrent aliases don't get the pipe-through behavior the foreground path now has. Worth flagging — wt my-concurrent-alias \| tr will still drop output. If we want full pass-through there, we'd need a single-step fast path that bypasses the gutter when there's only one concurrent step (or always for aliases), since interleaving multiple children's stdout onto a pipe would scramble it anyway.

Child output → log file (background jobs)

All deliberate, all logging both streams together so the .log files include interleaved stderr context:

  • commands/run_pipeline.rs:158-165 — wt hook run-pipeline step children
  • commands/process.rs at L223-L231 (Unix shell), L295-L303 (Windows shell), L403-L412 (Unix exec), L441-L450 (Windows exec) — detached background processes (background hooks, removal cleanup)

Child output → /dev/null (suppression)

Capture for parsing (not really redirection)

Cmd::run() and a few direct Command users pipe both streams to read them — shell_exec.rs (the standard runner), git/repository/mod.rs:1041-1046 (delayed-stream git), output/concurrent.rs:243-245 (before the prefix logic above). These return the bytes to the caller; nothing user-visible is rerouted.

Inherit (no redirection)

output/global.rs:454-498 (wt switch exec / spawn) and Cmd::stream()'s defaults — stdin/stdout/stderr all inherit. This is the path aliases now flow through.


The only follow-up I'd flag from this sweep is the concurrent-alias case noted above. Everything else either has an explicit reason in the comment or is plumbing that doesn't surface to the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output from wt <alias> is not usable in scripts

2 participants