Skip to content

fix: forward exit codes in err, test, and summary commands#559

Open
FlorianBruniaux wants to merge 2 commits intodevelopfrom
fix/exit-code-propagation
Open

fix: forward exit codes in err, test, and summary commands#559
FlorianBruniaux wants to merge 2 commits intodevelopfrom
fix/exit-code-propagation

Conversation

@FlorianBruniaux
Copy link
Collaborator

Problem

rtk err, rtk test, and rtk summary always returned exit code 0, even when the wrapped command failed. The exit code was computed but never forwarded.

Reproduction from #557:

rtk err zsh -c 'exit 1'  # → exit: 0 (wrong)
rtk test false            # → exit: 0 (wrong)
rtk summary false         # → exit: 0 (wrong)

Root cause

All three commands called std::process::exit nowhere after computing exit_code. They returned Ok(()) unconditionally.

Fix

Added if exit_code != 0 { std::process::exit(exit_code); } before returning in runner::run_err, runner::run_test, and summary::run.

Verification

rtk err false       # → exit: 1 ✓
rtk err true        # → exit: 0 ✓
rtk summary false   # → exit: 1 ✓
rtk test false      # → exit: 1 ✓

Integration tests added (marked #[ignore], require rtk on PATH):

  • test_err_forwards_exit_code_nonzero
  • test_err_forwards_exit_code_zero
  • test_test_forwards_exit_code_nonzero

Closes #557

FlorianBruniaux and others added 2 commits March 13, 2026 10:32
Commands `rtk err`, `rtk test`, and `rtk summary` were always returning
exit code 0, even when the wrapped command failed. The exit code was
computed but never forwarded via `std::process::exit`.

Fixes #557

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Florian BRUNIAUX <florian@bruniaux.com>
Sync module count with actual main.rs (64 modules) to pass pre-push validation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Florian BRUNIAUX <florian@bruniaux.com>
Copilot AI review requested due to automatic review settings March 13, 2026 09:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes RTK’s err, test, and summary wrappers so they propagate the wrapped command’s non-zero exit status to the caller (addressing #557), aligning RTK behavior with typical CLI/CI expectations.

Changes:

  • Forward non-zero exit codes from runner::run_err, runner::run_test, and summary::run via std::process::exit(exit_code).
  • Add ignored integration-style tests that assert exit code forwarding for rtk err and rtk test.
  • Update module counts in ARCHITECTURE.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/summary.rs Computes exit code and exits non-zero after printing/tracking summary output.
src/runner.rs Exits non-zero for err/test modes after printing/tracking; adds ignored integration tests for exit code forwarding.
ARCHITECTURE.md Updates documented module totals.
Comments suppressed due to low confidence (1)

ARCHITECTURE.md:301

  • The updated module totals ("64 modules" / "42 command modules + 22 infrastructure modules") conflict with the breakdown immediately below (currently 34 command / 20 infrastructure). Please reconcile these numbers so the architecture doc is internally consistent.
**Total: 64 modules** (42 command modules + 22 infrastructure modules)

### Module Count Breakdown

- **Command Modules**: 34 (directly exposed to users)
- **Infrastructure Modules**: 20 (utils, filter, tracking, tee, config, init, gain, toml_filter, verify_cmd, etc.)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +278 to +305
#[test]
#[ignore]
fn test_err_forwards_exit_code_nonzero() {
// Requires rtk to be installed on PATH (cargo install --path .)
let output = std::process::Command::new("rtk")
.args(["err", "sh", "-c", "exit 2"])
.output()
.expect("failed to run rtk — install with: cargo install --path .");
assert_eq!(output.status.code(), Some(2));
}

#[test]
#[ignore]
fn test_err_forwards_exit_code_zero() {
let output = std::process::Command::new("rtk")
.args(["err", "sh", "-c", "exit 0"])
.output()
.expect("failed to run rtk — install with: cargo install --path .");
assert_eq!(output.status.code(), Some(0));
}

#[test]
#[ignore]
fn test_test_forwards_exit_code_nonzero() {
let output = std::process::Command::new("rtk")
.args(["test", "sh", "-c", "exit 1"])
.output()
.expect("failed to run rtk — install with: cargo install --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.

2 participants