Skip to content

feat(cli): use the test collection Trunk infers from the repository - #1287

Merged
trunk-io[bot] merged 4 commits into
mainfrom
tylerbeebe/trunk-23145-use-inferred-test-collection
Nov 4, 2026
Merged

trunk-io[bot] merged 4 commits into
mainfrom
tylerbeebe/trunk-23145-use-inferred-test-collection

Conversation

@acatxnamedvirtue

Copy link
Copy Markdown
Contributor

Part of TRUNK-23145.

What

A run without --test-collection-id now asks POST /v1/metrics/getUploadApiVersion too, sending its repo (still one decision per run, 2 s timeout, any failure is v1). The response gains an optional, additive testCollectionShortId, which trunk1 sends only with v2 for a run that named no collection, when it inferred the org's collection from the repository (TRUNK-23144).

Run Answer Behaviour
no --test-collection-id v2 + testCollectionShortId v2 quarantine lookup and upload against that id, exactly as if it had been passed; prints one deprecation warning
no --test-collection-id v2 without an id (old server or bug) v1 for the run, logged at debug; no v2 route is called without a collection
no --test-collection-id v1 (or anything else, or a failure) v1, as today
--test-collection-id anything unchanged; an id in the response is ignored

The warning:

Uploading to test collection <id>, inferred from the repository. Pass --test-collection-id <id>: analytics-cli 1.0.0 requires it.

The test-runner plugins (test_report) get the same behaviour. Their wording says Set TRUNK_TEST_COLLECTION_ID=<id> instead of naming the flag. The inferred id is stored in the on-disk API version cache, so every worker process's quarantine lookup and the final upload use the same collection. The gem's console shows only error-level logs, so the plugin prints the warning on stderr, as it already does for the summary-file line.

Parsing ignores an absent field and unknown fields.

Also: deprecation notices now show in the upload output

The CLI's console shows tracing output only with --verbose, so a tracing::warn! deprecation, this one or the existing --team/--print-files/--hide-banner/--use-quarantining ones, was visible only in --summary-output-file. render_upload now prints each Deprecation notice at the top of the upload report. So those existing flag deprecations become visible too.

Rollout

This depends on trunk1's TRUNK-23144 change to the decision route. Until that ships, servers never send testCollectionShortId and never answer v2 for a run without a collection, so behaviour is unchanged. Safe to merge first.

The version bump and release are separate (TRUNK-23146). 0.17.0 must be cut before Dylan's summary-output change (#1273) lands.

Tests

  • api/tests/v2_client.rs: the inferred id is used, unknown fields are tolerated, a v2 with no id (absent, null, blank) or a v1 carrying one reads as v1, an explicit id ignores the inferred one, and there is no call without a token, or without both a collection and a named repo.
  • cli/tests/upload.rs: end-to-end upload to the inferred collection (both v2 routes take that id, the bundle meta names it, the warning is printed). v2 with no id uploads on v1. An explicit id ignores an inferred one and prints no warning.
  • test_report/tests/quarantine.rs: two plugin "processes" both look up quarantine on v2 under the inferred id, with one decision call.
  • cli/tests/summary/upload.rs: deprecation notices render first in the text report.

🤖 Generated with Claude Code

A run without --test-collection-id now asks the decision route too, by its
repository. When trunk1 answers v2 with a testCollectionShortId, the run uses
that collection for the v2 quarantine lookup and upload, as if it had been
passed, and warns that 1.0.0 requires the id. A v2 answer with no collection
falls back to v1. A run that names its collection ignores any inferred one.

The test-runner plugins keep the inferred collection in their API version
cache, so every worker process uses it, and print the warning on stderr.
Deprecation notices now show in the upload's text output, since the console
shows tracing only when verbose.

Part of TRUNK-23145

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

😎 Merged successfully - details.

@trunk-staging-io

trunk-staging-io Bot commented Nov 3, 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 quarantine test failed because it expected 2 + 2 to equal 5, but the result was 4. Logs ↗︎

View Full Report ↗︎ ⋅ Docs

@codecov-commenter

codecov-commenter commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.24771% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.76%. Comparing base (11aa736) to head (9287c00).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cli/src/upload_command.rs 94.91% 3 Missing ⚠️
test_report/src/report.rs 94.73% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1287      +/-   ##
==========================================
+ Coverage   85.58%   85.76%   +0.18%     
==========================================
  Files          86       86              
  Lines       19259    19405     +146     
==========================================
+ Hits        16482    16642     +160     
+ Misses       2777     2763      -14     

☔ 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.

@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.

Some notes on clarity/correctness

Comment thread api/src/client/mod.rs Resolved
Comment thread api/src/client/mod.rs Resolved
Comment thread cli/src/upload_command.rs Resolved
Comment thread cli/src/upload_command.rs Resolved
Comment thread api/src/message.rs Resolved
acatxnamedvirtue and others added 3 commits November 4, 2026 17:39
When getUploadApiVersion answers missingTestCollection, the run named no
collection and Trunk could not infer one for a fully migrated org, so
ingestion would drop a v1 upload. The CLI and the test-runner plugins now
skip the upload and its telemetry and warn, with an UPLOAD_SKIPPED notice
in the summary. The quarantine lookup is unchanged.

Part of TRUNK-23145

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UploadApiDecision::from_response holds the rules: a run that named its
collection takes the answer's version as it is, and only a run that named
none reads testCollectionShortId (with v2) or missingTestCollection (with
v1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With missingTestCollection the CLI now skips the quarantine lookup as well
as the upload, and the test-runner plugins report a test as not
quarantined without a lookup. v1 answers that lookup for a fully migrated
org with 404 "A test collection is required", which quarantined nothing,
so the exit code is the same as before.

Part of TRUNK-23145

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trunk-io
trunk-io Bot merged commit 03962cd into main Nov 4, 2026
35 checks passed
trunk-io Bot pushed a commit that referenced this pull request Nov 4, 2026
* feat(cli): print the summary on stdout and remove EndOutput

run() returns a Report, and main sends each part of it to its own stream:
the summary goes to stdout with superconsole's emit_aux, while notices
(deprecation warnings, BEP parse errors), the error of a run that fails
outright, the test command header and the summary file message go to
stderr. DisplayMessage::Final and the EndOutput trait are replaced by
Report and Notice variants that carry the rendered lines.

Scripts that capture only stderr will lose the summary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): show UploadSkipped notices with the others on stderr

main's #1287 printed Deprecation and UploadSkipped notices inside the upload
summary. This branch already prints every notice on stderr through
render_notices, so render UploadSkipped there and drop the copy in the
summary, which would have printed each notice twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Dylan Frankland <2488926+dfrankland@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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