Skip to content

Define each CLI exit code in one place, with its documentation - #1255

Merged
trunk-io[bot] merged 2 commits into
dylan/trunk-22403-add-summary-output-file-to-upload-and-testfrom
dylan/trunk-22762-define-each-cli-exit-code-in-one-place-with-its
Oct 29, 2026
Merged

trunk-io[bot] merged 2 commits into
dylan/trunk-22403-add-summary-output-file-to-upload-and-testfrom
dylan/trunk-22762-define-each-cli-exit-code-in-one-place-with-its

Conversation

@dfrankland

@dfrankland dfrankland commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Stacked on #1246. Refs TRUNK-22762.

Each exit code the CLI can return is now defined once, in cli/src/exit_code.rs, with a doc comment saying when it's used. --help and the summary's JSON Schema are generated from those doc comments. No behavior change.

What changes.

  • ExitCode has a variant per code: Success (0), Failure (1), PassedThrough(code) (the test command's code, or --test-process-exit-code), Error (70), Interrupted (130), Terminated (143), and Usage (2) and Panic (101), which clap and Rust choose but users still see. strum's EnumMessage derive reads each variant's doc comment at runtime (get_documentation()), and EnumIter lists the variants. strum 0.27.2 was already in Cargo.lock through other dependencies.
  • Every exit code decision and every field that holds one uses it: quarantining, ErrorKind and ErrorReport, UploadReport (including cli_exit_code()), ValidateReport, ErrorSummary, the test command, main.rs (close_out_and_exit takes an ExitCode) and shutdown.rs. TestRunResult.exit_code stays an i32, because it's the child process's raw status.
  • Two exit codes are equal when the process exits with the same number, so PassedThrough(1) == Failure.
  • ExitCode serializes as a plain number, so the JSON doesn't change. Its JsonSchema impl gives summary-output-schema an ExitCode definition whose description lists every code, generated from the doc comments.
  • --help on the top-level command and each subcommand ends with an "Exit codes" section (clap's after_long_help), laid out and styled like clap's own sections. -h is unchanged.
  • EXIT_SUCCESS and EXIT_FAILURE are gone from constants, and so is the exitcode dependency.

Documented, not in the issue's table. upload also exits 0 with failed tests when quarantining is turned off for the repo in Trunk (the quarantining test in tests/upload.rs checks this), or when no test reports were found. test passes its command's code through when the upload fails, but errors before the upload (e.g. the repo root isn't a git repository) still exit 70.

#1253 is stacked on this. Its no-tests check uses ExitCode::is_success() instead of EXIT_SUCCESS.

Out of scope. The two fail-open bugs (#1250, #1251), JSON output (TRUNK-22405) and the summary on stdout (TRUNK-22404).

Testing.

  • The tests only change how they build their inputs and name their expected codes: quarantine_context.exit_code = 1 becomes ExitCode::Failure, Some(70) becomes Some(ExitCode::Error), and exitcode::USAGE becomes ExitCode::PassedThrough(64). The expected numbers and text don't change.
  • New unit tests cover each code's number, equality, serialization, and that --help and the schema description list every code.
  • cargo test -p trunk-analytics-cli -p test_report -p constants: all pass except the three Swift xunit tests in tests/upload.rs, which fail the same way on the base branch locally.
  • cargo clippy -p trunk-analytics-cli --tests: no new warnings. cargo fmt --all --check: clean.

🤖 Generated with Claude Code

@codecov-commenter

codecov-commenter commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.24138% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.63%. Comparing base (ad00eed) to head (3dea134).

Files with missing lines Patch % Lines
cli/src/exit_code.rs 97.24% 3 Missing ⚠️
cli/src/context_quarantine.rs 90.90% 1 Missing ⚠️
Additional details and impacted files
@@                                       Coverage Diff                                        @@
##           dylan/trunk-22403-add-summary-output-file-to-upload-and-test    #1255      +/-   ##
================================================================================================
+ Coverage                                                         85.45%   85.63%   +0.17%     
================================================================================================
  Files                                                                84       85       +1     
  Lines                                                             18927    19037     +110     
================================================================================================
+ Hits                                                              16175    16303     +128     
+ Misses                                                             2752     2734      -18     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trunk-staging-io

trunk-staging-io Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Static Badge   Static Badge   Static Badge

Failed Test Failure Summary Logs
pending_quarantine_test should be quarantined when run with variant A test marked as pending was expected to fail but unexpectedly passed. Logs ↗︎
variant_quarantine_test should be quarantined when run with variant The quarantined variant test failed because it expected 2 + 2 to equal 5, but the result was 4. Logs ↗︎
multiple_exception_error_test nested context with multiple failures multiple expectations that fail The failure aggregation test reports three failed expectations and an additional RuntimeError raised inside the aggregation block. Logs ↗︎
multiple_exception_error_test with before and after hook failures test execution with hook errors The test failed because both its before hook and after hook raised errors, preventing RSpec from matching the failure to a backtrace line. Logs ↗︎

... and 3 more

View Full Report ↗︎ ⋅ Docs

@trunk-io

trunk-io Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Static Badge   Static Badge   Static Badge

View Full Report ↗︎ ⋅ Docs

@dfrankland
dfrankland force-pushed the dylan/trunk-22762-define-each-cli-exit-code-in-one-place-with-its branch from 7c302f6 to f8f7d82 Compare October 27, 2026 20:42

@TylerJang27 TylerJang27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🙏🙏🙏

@dfrankland
dfrankland added this pull request to stack #1268 October 28, 2026 15:54
dfrankland and others added 2 commits October 28, 2026 21:00
…tion

Add `ExitCode` (cli/src/exit_code.rs) with a variant per code and a doc comment
on each saying when it's used, plus `PassedThrough(code)` for the test
command's code and --test-process-exit-code. Two exit codes are equal when the
process exits with the same number.

Every exit code decision and every field that holds one now uses it:
quarantining, ErrorKind and ErrorReport, UploadReport (including
cli_exit_code()), ValidateReport, ErrorSummary, the test command, main.rs
and shutdown.rs. It serializes as a plain number, so the JSON doesn't change.

The doc comments generate the user-facing docs:
- an "Exit codes" section in --help (via clap's after_long_help), on the
  top-level command and each subcommand;
- the ExitCode description in summary-output-schema.

Remove EXIT_SUCCESS and EXIT_FAILURE from constants and drop the exitcode
dependency. No behavior change: the tests only change how they build their
inputs and name their expected codes; the expected numbers and text are the
same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
strum's EnumMessage derive exposes each variant's doc comment through
get_documentation(), and EnumIter lists the variants, so ExitCode no longer
needs macro_rules! to keep its doc comments as strings. The numbers move into
a plain match in code(). --help and summary-output-schema print exactly the
same text as before.

strum 0.27.2 was already in Cargo.lock through other dependencies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dfrankland
dfrankland force-pushed the dylan/trunk-22762-define-each-cli-exit-code-in-one-place-with-its branch from f8f7d82 to 3dea134 Compare October 28, 2026 21:28
@trunk-io
trunk-io Bot merged commit 76991c0 into main Oct 29, 2026
89 of 101 checks passed
@trunk-io

trunk-io Bot commented Oct 29, 2026

Copy link
Copy Markdown

This pull request was merged into main as part of stacked PR 1265.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants