Repository navigation
fix(cargo): preserve compiler warnings in cargo test output on passing runs - #2877
CryptoKrad wants to merge 1 commit into
Conversation
…g runs What: CargoTestHandler (streaming) and filter_cargo_test (buffered/pipe path) previously dropped compile-phase 'warning:' blocks entirely on passing runs. Both now capture and emit warning blocks (mirroring CargoBuildHandler) and annotate the compact summary with '[N compiler warnings]'. The aggregate 'generated N warnings' count line stays stripped. Buffered path caps blocks at CAP_WARNINGS with an '+N more' marker and hard-terminates warning blocks on section markers (failures:/test result:/test /----/error) so short blocks cannot swallow subsequent sections. Why: exit-0 runs get no tee log, so dropped warnings were unrecoverable — an agent reading 'cargo test: N passed' concluded the build was clean when rustc had emitted warnings. Confirmed behaviorally pre-fix: raw 'cargo test' showed 3 warning lines; rtk showed none (review lane finding HIGH-2, docs/research/runs/rtk-review-2026-07-07 in Claude.md-improve). Verified: cargo test full suite 2394 passed / 0 failed (+ 6 integration suites green); 2 new tests (buffered + streamed handler) assert warning survival, warning-count annotation, and aggregate-line stripping; behavioral A/B on a real crate: passing-with-warnings now shows the block + count (exit 0), failing run still shows failure detail with exit 101 == raw. Open risk: pytest wrapper has the analogous success-path loss (warnings summary + stderr) — tracked as a follow-up, mitigated operationally by tee.mode=always in local config. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01K5bb4GKf9CNKP9uYhFDvsz
|
|
KuSh
left a comment
There was a problem hiding this comment.
Thanks for tackling this — dropping compile warnings on passing runs is a real gap, and preserving them on both the streaming and buffered paths is the right shape for the fix.
I found five issues that need addressing before this can go in. The first two are behaviour regressions on the compile-error path rather than gaps in the new feature, so they're the blocking ones; the last three affect the warning preservation itself.
A general note: the streaming handler (CargoTestHandler) and the buffered filter (filter_cargo_test) now implement warning capture twice, with slightly different logic. Whatever the fixes end up being, it's worth checking each one lands on both paths — three of the five below are cases where the two implementations disagree.
Separately, and unrelated to the code: the CLA is still showing as unsigned for this PR, so it can't be merged until that's done. You can sign it here: https://cla-assistant.io/rtk-ai/rtk?pullRequest=2877
| } | ||
|
|
||
| let mut result = String::new(); | ||
| result.push_str(&warnings_section); |
There was a problem hiding this comment.
Blocking: compile errors are silently dropped whenever a warning was captured.
Seeding result with the warnings section here, before any body content, makes the result.trim().is_empty() guard further down unreachable once a single warning block exists.
Concrete failure — a crate that both warns and fails to compile:
warning: unused variable: `x`
--> src/lib.rs:3:9
...
error[E0425]: cannot find value `y` in this scope
error: could not compile `failproj` (lib test) due to 1 previous error
There are no test result: lines and no test failures, so the only thing in result is the warnings section. That's non-empty, so the guard is false, and both the filter_cargo_build_labeled compile-error rendering and the last-5-meaningful-lines fallback are skipped. The output is the warning block and zero errors, on a non-zero exit. On develop the same input renders cargo test: 1 errors plus the error blocks, so this is a regression.
test_filter_cargo_test_compile_error_preserves_error_header doesn't catch it because its fixture has no warning in it.
Suggested fix: build the body into its own string and test that for emptiness, prepending warnings_section only at return. One thing to watch when you do — the tail fallback will then start running in cases it previously didn't, so it needs to exclude lines the warnings section already printed, or cargo test --no-run on a warning-only crate will print them twice.
| } | ||
| // Compile-phase warnings on a passing run were previously dropped | ||
| // (exit 0 → no tee → unrecoverable); stream them like CargoBuildHandler. | ||
| if !self.in_failure_section |
There was a problem hiding this comment.
Blocking: every warning is reported twice on the streaming compile-error path.
Emitting warning blocks live here is fine on its own, but format_summary's compile-error branch still hands the whole raw output to filter_cargo_build_labeled, and CargoBuildHandler collects warning blocks as well as error blocks. rtk cargo test goes through run_cargo_streamed, so on a crate with a warning plus a compile error the warning block is streamed once from here and then rendered a second time inside the summary.
The fix needs to suppress warning-block rendering for that one call site only — build, check and clippy share that helper and should keep rendering their warnings as they do today.
| } | ||
| // Aggregate count line ("warning: `x` generated N warnings"); individual | ||
| // warning blocks are already streamed via is_block_start below. | ||
| if line.starts_with("warning:") && line.contains("generated") && line.contains("warning") { |
There was a problem hiding this comment.
This heuristic swallows genuine warnings.
line.starts_with("warning:") && line.contains("generated") && line.contains("warning") — the third clause is tautological given the first, so this reduces to starts_with("warning:") && contains("generated"). Any real rustc or clippy warning whose message happens to contain "generated" matches, for example in a prost/tonic crate:
warning: unused import: `crate::generated::pb`
--> src/lib.rs:4:5
should_skip returns true, so is_block_start never fires, self.warnings isn't incremented, and the trailing --> / | / = note: lines match nothing and are dropped. The warning disappears entirely and [N compiler warnings] under-counts — the exact failure this PR is meant to fix.
Anchoring on the real shape of the aggregate line would avoid it, e.g. matching a generated \d+ warnings?$ suffix rather than a substring.
The same expression appears in the buffered path (filter_cargo_test), where the continue leaves in_warning_block false and the block body falls through to the failure detector and is discarded. Worth fixing in both places. The buffered copy also isn't gated on !in_failure_section, so a failing test whose captured stdout contains such a line loses it from the failure block.
| fn is_block_continuation(&mut self, line: &str, _block: &[String]) -> bool { | ||
| fn is_block_continuation(&mut self, line: &str, block: &[String]) -> bool { | ||
| if self.in_warning_block { | ||
| return !(line.trim().is_empty() && block.len() > 3); |
There was a problem hiding this comment.
block.len() > 3 means short warning blocks never terminate.
The blank-line terminator requires more than 3 lines already buffered, so span-less warnings never close on their trailing blank:
warning: unused manifest key: package.metadata.foo
warning: profiles for the non root package will be ignored
Running unittests ... and Doc-tests ... aren't in should_skip (it covers Compiling/Downloading/Downloaded/Finished, plus the lowercase running harness line), so they're treated as continuations and glued into the warning block.
The two paths then fail differently: the buffered filter emits that noise inside the warnings section, while the streaming handler holds the block open past test result: (consumed by should_skip) so it only surfaces at flush() — out of order, after everything else.
Terminating on the first blank line regardless of block length, or keying off the diagnostic's indentation, would handle both.
|
|
||
| let mut warnings_section = String::new(); | ||
| if !warnings.is_empty() { | ||
| for block in warnings.iter().take(CAP_WARNINGS) { |
There was a problem hiding this comment.
The cap is only applied on the path that isn't used for cargo test.
This caps warning blocks at CAP_WARNINGS with a … +N more warnings marker, but the streaming handler emits every warning block with no cap at all — and streaming is what rtk cargo test actually runs.
On a crate with 200 dead-code warnings, a passing rtk cargo test now emits all 200 blocks, which is a significant output regression on the most frequently run command, while the same raw output through the buffered path shows 10. Same input, two materially different outputs.
The cap should be enforced on the streaming side too, so both paths agree.
* fix(cargo): keep compiler warnings on a passing cargo test Ported from CryptoKrad/rtk b95acce (Apache-2.0; rtk-ai#2877). The buffered filter keeps warnings out of the result until the end, so a compile error after a warning still reaches the build-error fallback. * docs(readme): list the cargo test change beside the other command fixes
|
This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet. |
Summary
rtk cargo testsilently dropped compile-phasewarning:blocks on passing runs — an agent readingcargo test: N passedconcluded the build was clean while rustc had emitted warnings. Since exit-0 runs get no tee log, the information was unrecoverable (same class as thenever_worsesize-only guard: the lie is smaller, so it passes).CargoBuildHandler's warning capture into both paths:CargoTestHandler(streaming) now streams warning blocks live, andfilter_cargo_test(buffered/pipe) collects them, capped atCAP_WARNINGSwith an+N moremarker. The compact summary gains[N compiler warnings]; the aggregategenerated N warningsline stays stripped.failures:/test result:/test/----/error) so a short warning block can never swallow a following section.Test plan
cargo fmt --all --check && cargo clippy --all-targets && cargo test— fmt clean, clippy 0 issues, 2394 passed / 0 failed (+ integration suites green)test_filter_cargo_test_all_pass_preserves_compiler_warnings(buffered) andtest_streamed_cargo_test_handler_preserves_compiler_warnings(streaming) — assert warning survival,[N compiler warnings]annotation, and aggregate-line strippingcargo test: 3 passed (2 suites, 0.00s) [1 compiler warnings](exit 0); failing run still shows failure detail with exit 101 == raw;rtk cargo buildoutput unchanged (consistency restored between build and test)🤖 Generated with Claude Code
https://claude.ai/code/session_01K5bb4GKf9CNKP9uYhFDvsz