Skip to content

fix(hook): keep hook protocol stderr silent; make stream tests portable to Windows - #3582

Open
twaugh-godaddy wants to merge 1 commit into
rtk-ai:developfrom
twaugh-godaddy:fix/windows-test-failures
Open

twaugh-godaddy wants to merge 1 commit into
rtk-ai:developfrom
twaugh-godaddy:fix/windows-test-failures

Conversation

@twaugh-godaddy

Copy link
Copy Markdown

Hi! We're heavy rtk users at GoDaddy, and while running an internal code-quality-gate pilot against rtk on a Windows machine we hit two sets of test failures. Both are reproduced and fixed here, verified on Windows (rustc 1.97.1, PowerShell, no unix tools on PATH).

1. tests/copilot_selfheal_test.rs — 10/12 failing (real product bug, all platforms)

Every failing test tripped the same assertion: stderr must stay silent (protocol safety), with stderr containing:

[rtk] /!\ No hook installed — run `rtk init -g` for automatic token savings

Root cause: run_cli() (src/main.rs) calls hook_check::maybe_warn() for every command except Gain — including rtk hook <agent>. So the daily missing/outdated-hook warning can land on stderr in the middle of hook protocol execution. Unix CI never sees it because the test sandbox sets HOME and resolve_claude_dir() resolves ~/.claude through it; on Windows dirs::home_dir() ignores HOME, so the hook reads the real ~/.claude and the warning fires. Any real user (any OS) with Claude Code installed but no rtk hook registered would get the same protocol-breaking stderr once a day from rtk hook copilot.

Fix: skip maybe_warn() for Commands::Hook { .. }, exactly like Gain is already skipped — a nag has no business on a protocol stream. This also makes the test suite deterministic on Windows.

2. src/core/stream.rs unit tests — 16 failing (test-harness bug)

test_run_streaming_passthrough_echo and 15 siblings spawn unix coreutils directly (echo, sh -c, true, false, cat, dd | tr | fold), which don't exist on stock Windows → Failed to spawn process.

Fix: a small shell() test helper runs each script through sh -c / cmd /C (same pattern as build_shell_command in src/cmds/rust/runner.rs), using scripts valid in both shells. The 10 MiB cap tests now stream a Rust-generated temp file via cat/type instead of dd | tr | fold. Bonus: the two filter tests that were #[cfg(not(windows))]-gated (test_run_streaming_streaming_filter_drops_lines, test_run_streaming_buffered_filter) now genuinely run and pass on Windows. test_exit_code_signal_kill stays cfg(unix) since signals are inherently unix.

Verification (Windows)

before after
unit tests (--bin rtk) 2562 passed / 16 failed 2580 passed / 0 failed (8 ignored)
copilot_selfheal_test 2 passed / 10 failed 12 passed / 0 failed
full cargo test failed all targets green (incl. 12/12 guard_integration)

cargo clippy --all-targets and cargo fmt are clean on the touched files. No behavior change for the warning outside hook invocations.

🤖 Generated with Claude Code

…le to Windows

Running the test suite on Windows surfaced two issues:

1. Product bug: rtk hook <agent> invocations ran the daily
   missing/outdated-hook check, which prints a warning to stderr in the
   middle of hook protocol execution — exactly what
   copilot_selfheal_test's 'stderr must stay silent (protocol safety)'
   asserts against. Unix CI never sees it because the test sandbox sets
   HOME and the check resolves ~/.claude through it; on Windows
   dirs::home_dir() ignores HOME, so the real ~/.claude leaks in and the
   warning fires (10 of 12 tests failed). Fix: skip maybe_warn() for
   Commands::Hook, like Gain already does — a warning has no business on
   a protocol stream regardless of platform.

2. Test bug: src/core/stream.rs unit tests spawned unix coreutils
   (echo, sh, true, false, cat, dd|tr|fold) that don't exist on stock
   Windows, failing 16 tests with 'Failed to spawn process'. Fix: a
   small shell() helper runs each script through sh -c / cmd /C, the
   10 MiB cap tests stream a Rust-generated temp file via cat/type, and
   the two previously cfg(not(windows))-gated filter tests now run on
   Windows too.

Verified on Windows (PowerShell, no unix tools on PATH): full suite
2580 unit + 12 copilot_selfheal + 12 guard_integration passed, 0 failed
(before: 16 + 10 failures). cargo clippy --all-targets clean.

Co-Authored-By: Claude Code <[email protected]>
@CLAassistant

CLAassistant commented Aug 15, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Hey @twaugh-godaddy, thanks for this and for the detailed write-up, and sorry it sat this long. The hook-warning half has since landed on develop (maybe_warn now skips Commands::Hook, in src/lib.rs), which is why src/main.rs conflicts. The stream.rs half still applies cleanly and is still useful: those tests spawn echo, sh and dd directly. Could you rebase on develop and keep just the stream.rs change? I'll run it on Windows once it's updated, with and without Git's Unix tools on PATH.

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.

3 participants