Skip to content

fix(cargo): don't inject a redundant summary line when 0 crates compiled - #3385

Open
pszymkowiak wants to merge 1 commit into
developfrom
fix/cargo-build-zero-crates-summary
Open

fix(cargo): don't inject a redundant summary line when 0 crates compiled#3385
pszymkowiak wants to merge 1 commit into
developfrom
fix/cargo-build-zero-crates-summary

Conversation

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Summary

cargo_build_success_line() always prepended a "cargo build (N crates compiled)" line — even when N == 0 and cargo's own Finished line already said so. On a no-op build (nothing to recompile), this turns a single-line raw output into two lines: a net token increase, not a reduction.

Caught live via scripts/benchmark.sh:

🔴 cargo build   │ cargo build 2>&1 || true │ rtk cargo build 2>&1 │  18 →  25 (-38%)

Also covers the sibling case where no Finished line is captured at all (still 0 crates compiled) — distinguishing a genuine success from a silent failure.

Fix

fn cargo_build_success_line(compiled: usize, finished: Option<&str>, label: &str) -> String {
    match finished {
        Some(f) if compiled == 0 => format!("{}\n", f),
        Some(f) => format!("cargo {} ({} crates compiled)\n{}\n", label, compiled, f),
        None if compiled == 0 => format!("cargo {}: ok (up to date, nothing recompiled)\n", label),
        None => format!("cargo {} ({} crates compiled)\n", label, compiled),
    }
}

Context

Test plan

  • 2 new unit tests: test_filter_cargo_build_up_to_date_with_finished_line, test_filter_cargo_build_up_to_date_no_finished_line
  • Existing test_filter_cargo_build_success (compiled > 0 path) unaffected
  • cargo fmt --all && cargo clippy --all-targets && cargo test --all — 2494 passed, 0 failed
  • Verified against the real release binary:
    raw: "    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s"
    rtk: "Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s"
    

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

cargo_build_success_line() always prepended "cargo build (N crates
compiled)" even when N was 0 and cargo's own "Finished" line already
said so — turning a 1-line raw output into 2 lines, a net token
increase instead of a reduction (caught by scripts/benchmark.sh:
18 -> 25 tokens, -38%).

Also covers the sibling case with no captured "Finished" line at all,
which #1140 originally targeted but never landed (closed for being
branched off the wrong base, not on merit).

Fixes #759
Supersedes #1140

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@pszymkowiak
pszymkowiak requested a review from aeppling August 3, 2026 20:53
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.

cargo output on success is too terse, making it ambiguous

1 participant