diff --git a/src/api/data_types/chunking/upload/capability.rs b/src/api/data_types/chunking/upload/capability.rs index 03c71dacc6..b79f62c761 100644 --- a/src/api/data_types/chunking/upload/capability.rs +++ b/src/api/data_types/chunking/upload/capability.rs @@ -2,13 +2,6 @@ use serde::{Deserialize, Deserializer}; #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum ChunkUploadCapability { - /// Chunked upload of standalone artifact bundles - ArtifactBundles, - - /// Like `ArtifactBundles`, but with deduplicated chunk - /// upload. - ArtifactBundlesV2, - /// Upload of Dart symbol maps DartSymbolMap, @@ -28,8 +21,6 @@ impl<'de> Deserialize<'de> for ChunkUploadCapability { D: Deserializer<'de>, { Ok(match String::deserialize(deserializer)?.as_str() { - "artifact_bundles" => ChunkUploadCapability::ArtifactBundles, - "artifact_bundles_v2" => ChunkUploadCapability::ArtifactBundlesV2, "dartsymbolmap" => ChunkUploadCapability::DartSymbolMap, "preprod_artifacts" => ChunkUploadCapability::PreprodArtifacts, "proguard" => ChunkUploadCapability::Proguard, diff --git a/src/api/mod.rs b/src/api/mod.rs index c9f2a0e9d6..0a09334c26 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -749,32 +749,6 @@ impl AuthenticatedApi<'_> { .convert_rnf(ApiErrorKind::ProjectNotFound) } - #[deprecated = "release bundle uploads are deprecated in favor of artifact bundle uploads"] - pub fn assemble_release_artifacts( - &self, - org: &str, - release: &str, - checksum: Digest, - chunks: &[Digest], - ) -> ApiResult { - let url = format!( - "/organizations/{}/releases/{}/assemble/", - PathArg(org), - PathArg(release) - ); - - self.request(Method::Post, &url)? - .with_json_body(&ChunkedArtifactRequest { - checksum, - chunks, - projects: &[], - version: None, - dist: None, - })? - .send()? - .convert_rnf(ApiErrorKind::ReleaseNotFound) - } - pub fn assemble_artifact_bundle( &self, org: &str, diff --git a/src/commands/sourcemaps/upload.rs b/src/commands/sourcemaps/upload.rs index a08f13a9b1..2eaaa51aa0 100644 --- a/src/commands/sourcemaps/upload.rs +++ b/src/commands/sourcemaps/upload.rs @@ -10,7 +10,7 @@ use glob::{glob_with, MatchOptions}; use itertools::Itertools as _; use log::{debug, warn}; -use crate::api::{Api, ChunkUploadCapability}; +use crate::api::Api; use crate::config::Config; use crate::constants::DEFAULT_MAX_WAIT; use crate::utils::args::validate_distribution; @@ -429,19 +429,13 @@ pub fn execute(matches: &ArgMatches) -> Result<()> { let projects = config.get_projects(matches)?; let api = Api::current(); let mut processor = SourceMapProcessor::new(); - let mut chunk_upload_options = api.authenticated()?.get_chunk_upload_options(&org)?; + let chunk_upload_options = api.authenticated()?.get_chunk_upload_options(&org)?; if matches.get_flag("use_artifact_bundle") || env::var("SENTRY_FORCE_ARTIFACT_BUNDLES").ok().as_deref() == Some("1") { log::warn!("The --use-artifact-bundle option and the SENTRY_FORCE_ARTIFACT_BUNDLES environment variable \ are both deprecated, and both will be removed in the next major version."); - - if !chunk_upload_options.supports(ChunkUploadCapability::ArtifactBundles) { - chunk_upload_options - .accept - .push(ChunkUploadCapability::ArtifactBundles); - } } if matches.contains_id("bundle") && matches.contains_id("bundle_sourcemap") { diff --git a/src/utils/file_upload.rs b/src/utils/file_upload.rs index fa24f81c14..d3b5db72e6 100644 --- a/src/utils/file_upload.rs +++ b/src/utils/file_upload.rs @@ -7,15 +7,14 @@ use std::str; use std::sync::Arc; use std::time::{Duration, Instant}; -use anyhow::{anyhow, bail, Result}; +use anyhow::{bail, Result}; use console::style; use sha1_smol::Digest; use symbolic::common::ByteView; use symbolic::debuginfo::js; use symbolic::debuginfo::sourcebundle::SourceFileType; -use crate::api::NewRelease; -use crate::api::{Api, ChunkServerOptions, ChunkUploadCapability}; +use crate::api::{Api, ChunkServerOptions}; use crate::constants::DEFAULT_MAX_WAIT; use crate::utils::chunks::{upload_chunks, Chunk, ASSEMBLE_POLL_INTERVAL}; use crate::utils::fs::get_sha1_checksums; @@ -25,39 +24,6 @@ use crate::utils::source_bundle; use super::file_search::ReleaseFileMatch; -/// Old versions of Sentry cannot assemble artifact bundles straight away, they require -/// that those bundles are associated to a release. -/// -/// This function checks whether the configured server supports artifact bundles -/// and only creates a release if the server requires that. -pub fn initialize_legacy_release_upload(context: &UploadContext) -> Result<()> { - // if the remote sentry service supports artifact bundles, we don't - // need to do anything here. Artifact bundles will also only work - // if a project is provided which is technically unnecessary for the - // legacy upload though it will unlikely to be what users want. - let chunk_options = context.chunk_upload_options; - if chunk_options.supports(ChunkUploadCapability::ArtifactBundles) - || chunk_options.supports(ChunkUploadCapability::ArtifactBundlesV2) - { - return Ok(()); - } - - if let Some(version) = context.release { - let api = Api::current(); - api.authenticated()?.new_release( - context.org, - &NewRelease { - version: version.to_owned(), - projects: context.projects.into(), - ..Default::default() - }, - )?; - } else { - bail!("This version of Sentry does not support artifact bundles. A release slug is required (provide with --release or by setting the SENTRY_RELEASE environment variable)"); - } - Ok(()) -} - #[derive(Debug, Clone)] pub struct UploadContext<'a> { pub org: &'a str, @@ -70,13 +36,6 @@ pub struct UploadContext<'a> { pub chunk_upload_options: &'a ChunkServerOptions, } -impl UploadContext<'_> { - pub fn release(&self) -> Result<&str> { - self.release - .ok_or_else(|| anyhow!("A release slug is required (provide with --release or by setting the SENTRY_RELEASE environment variable)")) - } -} - #[derive(Eq, PartialEq, Debug, Copy, Clone, Hash)] pub enum LogLevel { Warning, @@ -227,8 +186,6 @@ impl<'a> FileUpload<'a> { } pub fn upload(&self) -> Result<()> { - // multiple projects OK - initialize_legacy_release_upload(self.context)?; upload_files_chunked(self.context, &self.files, self.context.chunk_upload_options) } } @@ -256,39 +213,16 @@ fn poll_assemble( let api = Api::current(); let authenticated_api = api.authenticated()?; - let server_supports_artifact_bundles = options.supports(ChunkUploadCapability::ArtifactBundles) - || options.supports(ChunkUploadCapability::ArtifactBundlesV2); - - if !server_supports_artifact_bundles { - log::warn!( - "[DEPRECATION NOTICE] Your Sentry server does not support artifact bundle \ - uploads. Falling back to deprecated release bundle upload. Support for this \ - deprecated upload method will be removed in Sentry CLI 3.0.0. Please upgrade your \ - Sentry server, or if you cannot upgrade, pin your Sentry CLI version to 2.x, so \ - you don't get upgraded to 3.x when it is released." - ); - } - let response = loop { // prefer standalone artifact bundle upload over legacy release based upload - let response = if server_supports_artifact_bundles { - authenticated_api.assemble_artifact_bundle( - context.org, - context.projects, - checksum, - chunks, - context.release, - context.dist, - )? - } else { - #[expect(deprecated, reason = "fallback to legacy upload")] - authenticated_api.assemble_release_artifacts( - context.org, - context.release()?, - checksum, - chunks, - )? - }; + let response = authenticated_api.assemble_artifact_bundle( + context.org, + context.projects, + checksum, + chunks, + context.release, + context.dist, + )?; // Poll until there is a response, unless the user has specified to skip polling. In // that case, we return the potentially partial response from the server. This might @@ -359,23 +293,16 @@ fn upload_files_chunked( style(">").dim(), )); - // Filter out chunks that are already on the server. This only matters if the server supports - // `ArtifactBundlesV2`, otherwise the `missing_chunks` field is meaningless. - if let Some(projects) = options - .supports(ChunkUploadCapability::ArtifactBundlesV2) - .then_some(context.projects) - { - let api = Api::current(); - let response = api.authenticated()?.assemble_artifact_bundle( - context.org, - projects, - checksum, - &checksums, - context.release, - context.dist, - )?; - chunks.retain(|Chunk((digest, _))| response.missing_chunks.contains(digest)); - }; + let api = Api::current(); + let response = api.authenticated()?.assemble_artifact_bundle( + context.org, + context.projects, + checksum, + &checksums, + context.release, + context.dist, + )?; + chunks.retain(|Chunk((digest, _))| response.missing_chunks.contains(digest)); if !chunks.is_empty() { upload_chunks(&chunks, options, progress_style)?; @@ -410,21 +337,10 @@ fn print_upload_context_details(context: &UploadContext) { style("> Dist:").dim(), style(context.dist.unwrap_or("None")).yellow() ); - let upload_type = if context - .chunk_upload_options - .supports(ChunkUploadCapability::ArtifactBundles) - || context - .chunk_upload_options - .supports(ChunkUploadCapability::ArtifactBundlesV2) - { - "artifact bundle" - } else { - "release bundle" - }; println!( "{} {}", style("> Upload type:").dim(), - style(upload_type).yellow() + style("artifact bundle").yellow() ); } diff --git a/src/utils/sourcemaps.rs b/src/utils/sourcemaps.rs index 974893f836..aa1cfd2e4d 100644 --- a/src/utils/sourcemaps.rs +++ b/src/utils/sourcemaps.rs @@ -19,9 +19,7 @@ use symbolic::debuginfo::sourcebundle::SourceFileType; use url::Url; use crate::utils::file_search::ReleaseFileMatch; -use crate::utils::file_upload::{ - initialize_legacy_release_upload, FileUpload, SourceFile, SourceFiles, UploadContext, -}; +use crate::utils::file_upload::{FileUpload, SourceFile, SourceFiles, UploadContext}; use crate::utils::fs; use crate::utils::logging::is_quiet_mode; use crate::utils::progress::ProgressBar; @@ -666,7 +664,6 @@ impl SourceMapProcessor { /// Uploads all files, and on success, returns the number of files that were /// uploaded, wrapped in Ok() pub fn upload(&mut self, context: &UploadContext<'_>) -> Result { - initialize_legacy_release_upload(context)?; self.flush_pending_sources(); // If there is no release, we have to check that the files at least diff --git a/tests/integration/_cases/sourcemaps/sourcemaps-upload-no-dedupe.trycmd b/tests/integration/_cases/sourcemaps/sourcemaps-upload-no-dedupe.trycmd deleted file mode 100644 index ee633b6ae8..0000000000 --- a/tests/integration/_cases/sourcemaps/sourcemaps-upload-no-dedupe.trycmd +++ /dev/null @@ -1,32 +0,0 @@ -``` -$ sentry-cli sourcemaps upload tests/integration/_fixtures/bundle.min.js.map tests/integration/_fixtures/vendor.min.js.map --release=wat-release --no-dedupe -? success - WARN [..] [DEPRECATION NOTICE] The --no-dedupe flag is deprecated and has no effect. It will be removed in the next major version. -> Found 1 file -> Found 1 file -> Analyzing 2 sources -> Analyzing completed in [..] -> Rewriting sources -> Rewriting completed in [..] -> Adding source map references -> Bundling completed in [..] -> Bundled 2 files for upload -> Bundle ID: [..]-[..]-[..]-[..]-[..] -> Optimizing completed in [..] -> Uploading completed in [..] -> Uploaded files to Sentry - WARN [..] [DEPRECATION NOTICE] Your Sentry server does not support artifact bundle uploads. Falling back to deprecated release bundle upload. Support for this deprecated upload method will be removed in Sentry CLI 3.0.0. Please upgrade your Sentry server, or if you cannot upgrade, pin your Sentry CLI version to 2.x, so you don't get upgraded to 3.x when it is released. -> Processing completed in [..] -> File upload complete (processing pending on server) -> Organization: wat-org -> Projects: wat-project -> Release: wat-release -> Dist: None -> Upload type: release bundle - -Source Map Upload Report - Source Maps - ~/bundle.min.js.map - ~/vendor.min.js.map - -``` diff --git a/tests/integration/_cases/sourcemaps/sourcemaps-upload-skip-already-uploaded.trycmd b/tests/integration/_cases/sourcemaps/sourcemaps-upload-skip-already-uploaded.trycmd deleted file mode 100644 index 1e25abe4c1..0000000000 --- a/tests/integration/_cases/sourcemaps/sourcemaps-upload-skip-already-uploaded.trycmd +++ /dev/null @@ -1,31 +0,0 @@ -``` -$ sentry-cli sourcemaps upload tests/integration/_fixtures/bundle.min.js.map tests/integration/_fixtures/vendor.min.js.map --release=wat-release -? success -> Found 1 file -> Found 1 file -> Analyzing 2 sources -> Analyzing completed in [..] -> Rewriting sources -> Rewriting completed in [..] -> Adding source map references -> Bundling completed in [..] -> Bundled 2 files for upload -> Bundle ID: [..]-[..]-[..]-[..]-[..] -> Optimizing completed in [..] -> Uploading completed in [..] -> Uploaded files to Sentry - WARN [..] [DEPRECATION NOTICE] Your Sentry server does not support artifact bundle uploads. Falling back to deprecated release bundle upload. Support for this deprecated upload method will be removed in Sentry CLI 3.0.0. Please upgrade your Sentry server, or if you cannot upgrade, pin your Sentry CLI version to 2.x, so you don't get upgraded to 3.x when it is released. -> Processing completed in [..] -> File upload complete (processing pending on server) -> Organization: wat-org -> Projects: wat-project -> Release: wat-release -> Dist: None -> Upload type: release bundle - -Source Map Upload Report - Source Maps - ~/bundle.min.js.map - ~/vendor.min.js.map - -``` diff --git a/tests/integration/_cases/sourcemaps/sourcemaps-upload-successfully-upload-file.trycmd b/tests/integration/_cases/sourcemaps/sourcemaps-upload-successfully-upload-file.trycmd deleted file mode 100644 index e364e968ee..0000000000 --- a/tests/integration/_cases/sourcemaps/sourcemaps-upload-successfully-upload-file.trycmd +++ /dev/null @@ -1,29 +0,0 @@ -``` -$ sentry-cli sourcemaps upload tests/integration/_fixtures/bundle.min.js.map --release=wat-release -? success -> Found 1 file -> Analyzing 1 sources -> Analyzing completed in [..] -> Rewriting sources -> Rewriting completed in [..] -> Adding source map references -> Bundling completed in [..] -> Bundled 1 file for upload -> Bundle ID: [..]-[..]-[..]-[..]-[..] -> Optimizing completed in [..] -> Uploading completed in [..] -> Uploaded files to Sentry - WARN [..] [DEPRECATION NOTICE] Your Sentry server does not support artifact bundle uploads. Falling back to deprecated release bundle upload. Support for this deprecated upload method will be removed in Sentry CLI 3.0.0. Please upgrade your Sentry server, or if you cannot upgrade, pin your Sentry CLI version to 2.x, so you don't get upgraded to 3.x when it is released. -> Processing completed in [..] -> File upload complete (processing pending on server) -> Organization: wat-org -> Projects: wat-project -> Release: wat-release -> Dist: None -> Upload type: release bundle - -Source Map Upload Report - Source Maps - ~/bundle.min.js.map - -``` diff --git a/tests/integration/mod.rs b/tests/integration/mod.rs index a3a0812ac2..525b90bd1b 100644 --- a/tests/integration/mod.rs +++ b/tests/integration/mod.rs @@ -34,7 +34,7 @@ use std::io; use std::path::Path; use test_utils::MockEndpointBuilder; -use test_utils::{chunk_upload, env, AssertCommand, ChunkOptions, ServerBehavior, TestManager}; +use test_utils::{chunk_upload, env, AssertCommand, TestManager}; pub const UTC_DATE_FORMAT: &str = r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6,9}Z"; const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/tests/integration/react_native/xcode.rs b/tests/integration/react_native/xcode.rs index f78a12f0dc..9255b491d2 100644 --- a/tests/integration/react_native/xcode.rs +++ b/tests/integration/react_native/xcode.rs @@ -1,9 +1,9 @@ -use crate::integration::{ServerBehavior, TestManager}; +use crate::integration::TestManager; #[test] fn xcode_upload_source_maps_missing_plist() { TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Modern, Default::default()) + .mock_common_upload_endpoints(None, None) .register_trycmd_test("react_native/xcode-upload-source-maps-invalid-plist.trycmd") .with_default_token(); } @@ -11,7 +11,7 @@ fn xcode_upload_source_maps_missing_plist() { #[test] fn xcode_upload_source_maps_release_and_dist_from_env() { TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Modern, Default::default()) + .mock_common_upload_endpoints(None, Some(vec!["60f215dae7d29497357013d08c35e93716b6a46c"])) .register_trycmd_test( "react_native/xcode-upload-source-maps-release_and_dist_from_env.trycmd", ) diff --git a/tests/integration/sourcemaps/upload.rs b/tests/integration/sourcemaps/upload.rs index f21aeaabbb..8820022d0e 100644 --- a/tests/integration/sourcemaps/upload.rs +++ b/tests/integration/sourcemaps/upload.rs @@ -1,4 +1,4 @@ -use crate::integration::{ChunkOptions, ServerBehavior, TestManager}; +use crate::integration::TestManager; #[test] fn command_sourcemaps_upload_help() { @@ -10,37 +10,10 @@ fn command_sourcemaps_upload() { TestManager::new().register_trycmd_test("sourcemaps/sourcemaps-upload.trycmd"); } -#[test] -fn command_sourcemaps_upload_successfully_upload_file() { - TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default()) - .register_trycmd_test("sourcemaps/sourcemaps-upload-successfully-upload-file.trycmd") - .with_default_token() - .assert_mock_endpoints(); -} - -#[test] -fn command_sourcemaps_upload_skip_already_uploaded() { - TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default()) - .register_trycmd_test("sourcemaps/sourcemaps-upload-skip-already-uploaded.trycmd") - .with_default_token() - .assert_mock_endpoints(); -} - -#[test] -fn command_sourcemaps_upload_no_dedupe() { - TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default()) - .register_trycmd_test("sourcemaps/sourcemaps-upload-no-dedupe.trycmd") - .with_default_token() - .assert_mock_endpoints(); -} - #[test] fn command_sourcemaps_upload_modern() { TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Modern, Default::default()) + .mock_common_upload_endpoints(None, Some(vec!["95d152c0530efb498133138c7e7092612f5abab1"])) .register_trycmd_test("sourcemaps/sourcemaps-upload-modern.trycmd") .with_default_token() .assert_mock_endpoints(); @@ -50,12 +23,8 @@ fn command_sourcemaps_upload_modern() { fn command_sourcemaps_upload_modern_v2() { TestManager::new() .mock_common_upload_endpoints( - ServerBehavior::ModernV2, - ChunkOptions { - missing_chunks: vec!["ec8450a9db19805703a27a2545c18b7b27ba0d7d".to_owned()], - // Set the chunk size so the bundle will be split into two chunks - chunk_size: 512, - }, + Some(512), + Some(vec!["ec8450a9db19805703a27a2545c18b7b27ba0d7d"]), ) .register_trycmd_test("sourcemaps/sourcemaps-upload-modern.trycmd") .with_default_token() @@ -65,22 +34,7 @@ fn command_sourcemaps_upload_modern_v2() { #[test] fn command_sourcemaps_upload_some_debugids() { TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Modern, Default::default()) - .register_trycmd_test("sourcemaps/sourcemaps-upload-some-debugids.trycmd") - .with_default_token() - .assert_mock_endpoints(); -} - -#[test] -fn command_sourcemaps_upload_some_debugids_v2() { - TestManager::new() - .mock_common_upload_endpoints( - ServerBehavior::ModernV2, - ChunkOptions { - missing_chunks: vec!["ff16e0ac593a74b454cc34814f6249f45a1a2dfe".to_owned()], - chunk_size: 524288, - }, - ) + .mock_common_upload_endpoints(None, Some(vec!["fa69a6c8e0aeaad598ad22432f51e68ec0c723e0"])) .register_trycmd_test("sourcemaps/sourcemaps-upload-some-debugids.trycmd") .with_default_token() .assert_mock_endpoints(); @@ -90,7 +44,7 @@ fn command_sourcemaps_upload_some_debugids_v2() { #[test] fn command_sourcemaps_upload_debugid_alias() { TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Modern, Default::default()) + .mock_common_upload_endpoints(None, Some(vec!["a910d4d579b82b2df9b71ee55fbac70d2bb8d2cd"])) .register_trycmd_test("sourcemaps/sourcemaps-upload-debugid-alias.trycmd") .with_default_token() .assert_mock_endpoints(); @@ -99,7 +53,7 @@ fn command_sourcemaps_upload_debugid_alias() { #[test] fn command_sourcemaps_upload_no_debugids() { TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Modern, Default::default()) + .mock_common_upload_endpoints(None, None) .register_trycmd_test("sourcemaps/sourcemaps-upload-no-debugids.trycmd") .with_default_token(); } @@ -107,7 +61,7 @@ fn command_sourcemaps_upload_no_debugids() { #[test] fn command_sourcemaps_upload_file_ram_bundle() { TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Modern, Default::default()) + .mock_common_upload_endpoints(None, Some(vec!["e268173df7cbb38ca44334572c2815a264a2c28f"])) .register_trycmd_test("sourcemaps/sourcemaps-upload-file-ram-bundle.trycmd") .with_default_token(); } @@ -115,7 +69,7 @@ fn command_sourcemaps_upload_file_ram_bundle() { #[test] fn command_sourcemaps_upload_indexed_ram_bundle() { TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Modern, Default::default()) + .mock_common_upload_endpoints(None, Some(vec!["47ef8e33f7213b9baa452715d04e251c090d0aaa"])) .register_trycmd_test("sourcemaps/sourcemaps-upload-indexed-ram-bundle.trycmd") .with_default_token(); } @@ -123,7 +77,7 @@ fn command_sourcemaps_upload_indexed_ram_bundle() { #[test] fn command_sourcemaps_upload_hermes_bundle_with_referencing_debug_id() { TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Modern, Default::default()) + .mock_common_upload_endpoints(None, Some(vec!["06903ba4e1ff6ec904338fe064f3109c4fed37b2"])) .register_trycmd_test( "sourcemaps/sourcemaps-upload-file-hermes-bundle-reference-debug-id.trycmd", ) @@ -133,7 +87,7 @@ fn command_sourcemaps_upload_hermes_bundle_with_referencing_debug_id() { #[test] fn command_sourcemaps_upload_cjs_mjs() { TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Modern, Default::default()) + .mock_common_upload_endpoints(None, None) .register_trycmd_test("sourcemaps/sourcemaps-upload-cjs-mjs.trycmd") .with_default_token(); } @@ -141,7 +95,7 @@ fn command_sourcemaps_upload_cjs_mjs() { #[test] fn command_sourcemaps_upload_complex_extension() { TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Modern, Default::default()) + .mock_common_upload_endpoints(None, None) .register_trycmd_test("sourcemaps/sourcemaps-upload-complex-extension.trycmd") .with_default_token(); } @@ -149,7 +103,7 @@ fn command_sourcemaps_upload_complex_extension() { #[test] fn command_sourcemaps_upload_skip_invalid_utf8() { TestManager::new() - .mock_common_upload_endpoints(ServerBehavior::Modern, Default::default()) + .mock_common_upload_endpoints(None, None) .register_trycmd_test("sourcemaps/sourcemaps-with-invalid-utf8.trycmd") .with_default_token(); } diff --git a/tests/integration/test_utils/mock_common_endpoints.rs b/tests/integration/test_utils/mock_common_endpoints.rs index 613c319705..fb4a6fb533 100644 --- a/tests/integration/test_utils/mock_common_endpoints.rs +++ b/tests/integration/test_utils/mock_common_endpoints.rs @@ -1,4 +1,9 @@ -use std::fmt::Display; +use std::{ + fmt::Display, + sync::atomic::{AtomicBool, Ordering}, +}; + +use serde_json::json; use crate::integration::test_utils::MockEndpointBuilder; @@ -6,30 +11,11 @@ use crate::integration::test_utils::MockEndpointBuilder; /// These can be used to generate mocks for the upload endpoints. pub(super) fn common_upload_endpoints( server_url: impl Display, - behavior: ServerBehavior, - chunk_options: ChunkOptions, + chunk_size: Option, + initial_missing_chunks: Option>, ) -> impl Iterator { - let ChunkOptions { - chunk_size, - missing_chunks, - } = chunk_options; - let (accept, release_request_count, assemble_endpoint) = match behavior { - ServerBehavior::Legacy => ( - "\"release_files\"", - 2, - "/api/0/organizations/wat-org/releases/wat-release/assemble/", - ), - ServerBehavior::Modern => ( - "\"release_files\", \"artifact_bundles\"", - 0, - "/api/0/organizations/wat-org/artifactbundle/assemble/", - ), - ServerBehavior::ModernV2 => ( - "\"release_files\", \"artifact_bundles_v2\"", - 0, - "/api/0/organizations/wat-org/artifactbundle/assemble/", - ), - }; + let chunk_size = chunk_size.unwrap_or(8388608); + let assemble_endpoint = "/api/0/organizations/wat-org/artifactbundle/assemble/"; let chunk_upload_response = format!( "{{ \"url\": \"{server_url}/api/0/organizations/wat-org/chunk-upload/\", @@ -38,46 +24,38 @@ pub(super) fn common_upload_endpoints( \"maxRequestSize\": 33554432, \"concurrency\": 8, \"hashAlgorithm\": \"sha1\", - \"accept\": [{accept}] + \"accept\": [] }}", ); + let is_first_request = AtomicBool::new(true); + vec![ - MockEndpointBuilder::new("POST", "/api/0/projects/wat-org/wat-project/releases/") - .with_status(208) - .with_response_file("releases/get-release.json") - .expect(release_request_count), MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/") .with_response_body(chunk_upload_response), MockEndpointBuilder::new("POST", "/api/0/organizations/wat-org/chunk-upload/") .with_response_body("[]"), MockEndpointBuilder::new("POST", assemble_endpoint) - .with_response_body(format!( - r#"{{"state":"created","missingChunks":{}}}"#, - serde_json::to_string(&missing_chunks).unwrap() - )) + .with_response_fn(move |_| { + let response = if let Some(missing_chunks) = is_first_request + .swap(false, Ordering::Relaxed) + .then_some(initial_missing_chunks.as_ref()) + .flatten() + { + json!({ + "state": "not_found", + "missingChunks": missing_chunks, + }) + } else { + json!({ + "state": "created", + "missingChunks": [], + }) + }; + + serde_json::to_vec(&response).expect("failed to serialize response") + }) .expect_at_least(1), ] .into_iter() } - -pub enum ServerBehavior { - Legacy, - Modern, - ModernV2, -} - -#[derive(Debug)] -pub struct ChunkOptions { - pub chunk_size: usize, - pub missing_chunks: Vec, -} - -impl Default for ChunkOptions { - fn default() -> Self { - Self { - chunk_size: 8388608, - missing_chunks: vec![], - } - } -} diff --git a/tests/integration/test_utils/mod.rs b/tests/integration/test_utils/mod.rs index 4a082600a6..7e8b2b17b9 100644 --- a/tests/integration/test_utils/mod.rs +++ b/tests/integration/test_utils/mod.rs @@ -7,7 +7,6 @@ mod mock_common_endpoints; mod mock_endpoint_builder; mod test_manager; -pub use mock_common_endpoints::{ChunkOptions, ServerBehavior}; pub use mock_endpoint_builder::MockEndpointBuilder; pub use test_manager::{AssertCommand, TestManager}; diff --git a/tests/integration/test_utils/test_manager.rs b/tests/integration/test_utils/test_manager.rs index bbec5385d1..ba041108d2 100644 --- a/tests/integration/test_utils/test_manager.rs +++ b/tests/integration/test_utils/test_manager.rs @@ -8,7 +8,7 @@ use trycmd::TestCases; use crate::integration::{env, MockEndpointBuilder, VERSION}; -use super::{mock_common_endpoints, ChunkOptions, MockServerInfo, ServerBehavior}; +use super::{mock_common_endpoints, MockServerInfo}; #[derive(Error, Debug)] pub enum Error { @@ -45,11 +45,15 @@ impl TestManager { /// Mock the common upload endpoints. pub fn mock_common_upload_endpoints( self, - behavior: ServerBehavior, - chunk_options: ChunkOptions, + chunk_size: Option, + initial_missing_chunks: Option>, ) -> Self { - mock_common_endpoints::common_upload_endpoints(self.server_url(), behavior, chunk_options) - .fold(self, |manager, builder| manager.mock_endpoint(builder)) + mock_common_endpoints::common_upload_endpoints( + self.server_url(), + chunk_size, + initial_missing_chunks, + ) + .fold(self, |manager, builder| manager.mock_endpoint(builder)) } /// Assert that all mocks have been called the correct number of times.