From e155a965617fa48be493480d724ef65de9690b2d Mon Sep 17 00:00:00 2001 From: Tyler Beebe Date: Mon, 9 Nov 2026 16:23:51 +0000 Subject: [PATCH 1/3] feat(upload): link failing tests by GUID when only the quarantine lookup named the collection The failing-tests table built its GUID links only from the upload's ids. A dry run or a failed upload has none, so it fell back to the `/t/?repo=` short link even when the v2 quarantine lookup had already returned the collection uuid and repository id. The run now uses the lookup's pair when the upload gives none. Also pins ADR-0019's `--no-repo` golden vector at the URL layer. Part of TRUNK-21084 Co-Authored-By: Claude Opus 5.5 --- api/src/urls.rs | 17 ++++++++++++ cli/src/context.rs | 1 + cli/src/context_quarantine.rs | 8 ++++++ cli/src/upload_command.rs | 2 ++ cli/tests/upload.rs | 51 +++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+) diff --git a/api/src/urls.rs b/api/src/urls.rs index 265f7e17..10c4d91a 100644 --- a/api/src/urls.rs +++ b/api/src/urls.rs @@ -236,6 +236,23 @@ mod tests { ); } + /// ADR-0019's `--no-repo` vector: the server names no repository with the nil UUID. + #[test] + fn test_collection_guid_url_generated_without_a_repo() { + let test_case = test_case_with_id("88e5353c-190c-5dce-9d06-0e66c3e062b1"); + let ids = TestCaseGuidScope { + test_collection_id: String::from(COLLECTION_ID), + repo_id: Uuid::nil().to_string(), + }; + + assert_eq!( + test_case_url(&test_case, Some("tc_123"), Some(&ids)), + Ok(String::from( + "https://app.trunk-staging.io/bad-app-org/flaky-tests/collections/tc_123/tests/943a80af-66b0-84bb-ad01-56b3b72fe363" + )), + ); + } + #[test] fn test_collection_guid_url_falls_back_for_an_unparseable_server_id() { let ids = TestCaseGuidScope { diff --git a/cli/src/context.rs b/cli/src/context.rs index 4de65ed7..7256862b 100644 --- a/cli/src/context.rs +++ b/cli/src/context.rs @@ -859,6 +859,7 @@ pub async fn gather_exit_code_and_quarantined_tests_context( org_url_slug: String::default(), fetch_status: QuarantineFetchStatus::FetchSkipped, quarantine_resolution_mode: api::message::QuarantineResolutionMode::Unspecified, + guid_scope: None, } } else { // default to success if no test run result (i.e. `upload`) diff --git a/cli/src/context_quarantine.rs b/cli/src/context_quarantine.rs index 62673594..4112b651 100644 --- a/cli/src/context_quarantine.rs +++ b/cli/src/context_quarantine.rs @@ -45,6 +45,7 @@ pub struct QuarantineContext { pub org_url_slug: String, pub fetch_status: QuarantineFetchStatus, pub quarantine_resolution_mode: QuarantineResolutionMode, + pub guid_scope: Option, } impl QuarantineContext { pub fn quarantining(&self, disable_quarantining: bool) -> Quarantining { @@ -70,6 +71,7 @@ impl QuarantineContext { org_url_slug: String::default(), fetch_status: QuarantineFetchStatus::FetchSkipped, quarantine_resolution_mode: QuarantineResolutionMode::Unspecified, + guid_scope: None, } } @@ -82,6 +84,7 @@ impl QuarantineContext { org_url_slug: String::default(), fetch_status: QuarantineFetchStatus::FetchFailed(error), quarantine_resolution_mode: QuarantineResolutionMode::Unspecified, + guid_scope: None, } } } @@ -338,6 +341,7 @@ pub async fn gather_quarantine_context( failures: Vec::default(), fetch_status: QuarantineFetchStatus::FetchSkipped, quarantine_resolution_mode: QuarantineResolutionMode::Unspecified, + guid_scope: None, }); } @@ -395,6 +399,7 @@ pub async fn gather_quarantine_context( org_url_slug: request.org_url_slug.clone(), fetch_status: quarantine_fetch_status, quarantine_resolution_mode, + guid_scope, }); } else { // quarantining is enabled, continue with quarantine process and update exit code @@ -487,6 +492,7 @@ pub async fn gather_quarantine_context( org_url_slug: request.org_url_slug.clone(), fetch_status: quarantine_fetch_status, quarantine_resolution_mode, + guid_scope, }) } @@ -711,6 +717,7 @@ mod tests { org_url_slug: String::new(), fetch_status: QuarantineFetchStatus::FetchSucceeded, quarantine_resolution_mode: QuarantineResolutionMode::Unspecified, + guid_scope: None, }; assert_eq!( quarantine_query_result(false, &success_ctx), @@ -741,6 +748,7 @@ mod tests { repo: RepoUrlParts::default(), org_url_slug: String::new(), quarantine_resolution_mode: QuarantineResolutionMode::Unspecified, + guid_scope: None, }; assert_eq!( quarantine_query_result(false, &repo_disabled_ctx), diff --git a/cli/src/upload_command.rs b/cli/src/upload_command.rs index b4c64642..0d0543c4 100644 --- a/cli/src/upload_command.rs +++ b/cli/src/upload_command.rs @@ -764,6 +764,8 @@ pub async fn run_upload( )), ), }; + // A dry run or a failed upload has no upload ids, but a v2 quarantine lookup returns the same pair. + let guid_scope = guid_scope.or_else(|| quarantine_context.guid_scope.clone()); if guid_scope.is_none() && upload_args.test_collection_short_id.is_some() { tracing::debug!( "No test collection ids returned for this upload; test links will use the short-link form" diff --git a/cli/tests/upload.rs b/cli/tests/upload.rs index 4eb7dac7..3df5abe9 100644 --- a/cli/tests/upload.rs +++ b/cli/tests/upload.rs @@ -384,6 +384,57 @@ async fn upload_bundle_falls_back_to_short_links_without_collection_ids() { .stdout(predicate::str::contains("/collections/tc_123/tests/").not()); } +// NOTE: must be multi threaded to start a mock server +#[tokio::test(flavor = "multi_thread")] +async fn failed_v2_upload_links_tests_by_the_quarantine_lookup_ids() { + use axum::routing::post; + use serde_json::{Value, json}; + + let temp_dir = tempdir().unwrap(); + generate_mock_git_repo(&temp_dir); + generate_mock_valid_junit_xmls(&temp_dir); + + let mut builder = MockServerBuilder::new(); + builder.route( + "/v1/metrics/getUploadApiVersion", + post(|| async { Json(json!({"apiVersion": "v2"})) }), + ); + builder.route( + "/v2/test-collections/:id/quarantine-status", + post(|Json(body): Json| async move { + let tests: Vec = body["testIdentifiers"] + .as_array() + .unwrap() + .iter() + .map(|identifier| json!({"clientTestId": identifier["id"], "quarantined": false})) + .collect(); + Json(json!({ + "testCollectionUuid": MOCK_TEST_COLLECTION_ID, + "repositoryId": MOCK_REPO_ID, + "quarantineEnabled": true, + "tests": tests, + })) + }), + ); + builder.route( + "/v2/test-collections/:id/uploads", + post(|| async { (StatusCode::BAD_REQUEST, Json(json!({}))) }), + ); + let state = builder.spawn_mock_server().await; + + CommandBuilder::upload(temp_dir.path(), state.host.clone()) + .command() + .arg("--test-collection-id") + .arg("tc_123") + .assert() + .failure() + .stdout(predicate::str::contains( + "/test-org/flaky-tests/collections/tc_123/tests/", + )) + .stdout(predicate::str::contains("/collections/tc_123/t/").not()) + .stdout(predicate::str::contains("?repo=trunk-io%2Fanalytics-cli").not()); +} + // NOTE: must be multi threaded to start a mock server #[tokio::test(flavor = "multi_thread")] async fn upload_bundle_prints_test_collection_upload_link() { From e79dceccfdf2869b6fc70768baaff9830458ed5a Mon Sep 17 00:00:00 2001 From: Tyler Beebe Date: Thu, 12 Nov 2026 16:31:38 +0000 Subject: [PATCH 2/3] test(upload): pin the exact GUID link the quarantine lookup ids produce (TRUNK-21084) The test only checked the `/collections/tc_123/tests/` prefix, so a link built from the short id, a nil repo id or the wrong test still passed. It now uploads the checked-in junit0_fail.xml instead of the randomly seeded mock, so the one failing test's id is stable, and asserts the full URL and that it is the only test link printed. Co-Authored-By: Claude Opus 5.5 --- cli/tests/upload.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cli/tests/upload.rs b/cli/tests/upload.rs index 3df5abe9..09bb297d 100644 --- a/cli/tests/upload.rs +++ b/cli/tests/upload.rs @@ -392,7 +392,11 @@ async fn failed_v2_upload_links_tests_by_the_quarantine_lookup_ids() { let temp_dir = tempdir().unwrap(); generate_mock_git_repo(&temp_dir); - generate_mock_valid_junit_xmls(&temp_dir); + fs::copy( + get_test_file_path("test_fixtures/junit0_fail.xml"), + temp_dir.path().join("junit.xml"), + ) + .unwrap(); let mut builder = MockServerBuilder::new(); builder.route( @@ -422,15 +426,19 @@ async fn failed_v2_upload_links_tests_by_the_quarantine_lookup_ids() { ); let state = builder.spawn_mock_server().await; + // The GUID hashes MOCK_TEST_COLLECTION_ID, MOCK_REPO_ID and the id of junit0_fail.xml's one test. CommandBuilder::upload(temp_dir.path(), state.host.clone()) + .junit_paths("junit.xml") .command() .arg("--test-collection-id") .arg("tc_123") .assert() .failure() - .stdout(predicate::str::contains( - "/test-org/flaky-tests/collections/tc_123/tests/", - )) + .stdout(predicate::str::contains(format!( + "{}/test-org/flaky-tests/collections/tc_123/tests/ae979ba6-6f93-8657-9f84-0265e5ac404c", + state.host + ))) + .stdout(predicate::str::contains("/tests/").count(1)) .stdout(predicate::str::contains("/collections/tc_123/t/").not()) .stdout(predicate::str::contains("?repo=trunk-io%2Fanalytics-cli").not()); } From d7a238380365485188ec374adcf3b2e3b260e55a Mon Sep 17 00:00:00 2001 From: Tyler Beebe Date: Thu, 12 Nov 2026 19:52:41 +0000 Subject: [PATCH 3/3] test(urls): pass the collection short id as &str after #1298 (TRUNK-21084) #1298 made test_case_url's short_id required, so the no-repo GUID test no longer compiled once rebased onto main. Co-Authored-By: Claude Opus 5.5 --- api/src/urls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/urls.rs b/api/src/urls.rs index 10c4d91a..df9b97de 100644 --- a/api/src/urls.rs +++ b/api/src/urls.rs @@ -246,7 +246,7 @@ mod tests { }; assert_eq!( - test_case_url(&test_case, Some("tc_123"), Some(&ids)), + test_case_url(&test_case, "tc_123", Some(&ids)), Ok(String::from( "https://app.trunk-staging.io/bad-app-org/flaky-tests/collections/tc_123/tests/943a80af-66b0-84bb-ad01-56b3b72fe363" )),