Skip to content

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

Open
dfrankland wants to merge 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
Open

dfrankland wants to merge 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.

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

…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>
@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.00%. Comparing base (868861c) to head (7c302f6).

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                                                         84.92%   85.00%   +0.07%     
================================================================================================
  Files                                                                80       81       +1     
  Lines                                                             18185    18295     +110     
================================================================================================
+ Hits                                                              15444    15552     +108     
- Misses                                                             2741     2743       +2     

☔ 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 fails because it expects 2 + 2 to equal 5, but the result is 4. Logs ↗︎

View Full Report ↗︎ ⋅ Docs

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>
@trunk-io

trunk-io Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Static Badge   Static Badge   Static Badge

View Full Report ↗︎ ⋅ Docs

This branch has not been deployed

No deployments
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.

2 participants