From 681606daafd635b2aad637f85019ba297fb8161a Mon Sep 17 00:00:00 2001 From: Hugues Pouillot Date: Fri, 24 Oct 2025 19:37:55 +0200 Subject: [PATCH] fix(err): fix duplicate sourcemap (#40330) --- cli/src/sourcemaps/source_pairs.rs | 1 - .../_cases/search/public/chunk-prefix.js | 2 + .../search/public/chunk-sourcemap.js.map | 4 +- cli/tests/_cases/search/public/chunk.js | 2 + cli/tests/sourcemap.rs | 38 +++++++++++++++++-- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/cli/src/sourcemaps/source_pairs.rs b/cli/src/sourcemaps/source_pairs.rs index 58dcc0f156..e9add7099f 100644 --- a/cli/src/sourcemaps/source_pairs.rs +++ b/cli/src/sourcemaps/source_pairs.rs @@ -141,7 +141,6 @@ impl TryInto for SourcePair { fn try_into(self) -> Result { let chunk_id = self - .sourcemap .get_chunk_id() .ok_or_else(|| anyhow!("Chunk ID not found"))?; let source_content = self.source.inner.content; diff --git a/cli/tests/_cases/search/public/chunk-prefix.js b/cli/tests/_cases/search/public/chunk-prefix.js index 82bdafa4f9..d74215e365 100644 --- a/cli/tests/_cases/search/public/chunk-prefix.js +++ b/cli/tests/_cases/search/public/chunk-prefix.js @@ -1 +1,3 @@ //# sourceMappingURL=/static/chunk-sourcemap.js.map + +//# chunkId=1234 diff --git a/cli/tests/_cases/search/public/chunk-sourcemap.js.map b/cli/tests/_cases/search/public/chunk-sourcemap.js.map index 0967ef424b..0bf0c730d2 100644 --- a/cli/tests/_cases/search/public/chunk-sourcemap.js.map +++ b/cli/tests/_cases/search/public/chunk-sourcemap.js.map @@ -1 +1,3 @@ -{} +{ + "chunk_id": "1234" +} diff --git a/cli/tests/_cases/search/public/chunk.js b/cli/tests/_cases/search/public/chunk.js index afbce4ff93..4f0f290705 100644 --- a/cli/tests/_cases/search/public/chunk.js +++ b/cli/tests/_cases/search/public/chunk.js @@ -1 +1,3 @@ //# sourceMappingURL=chunk-sourcemap.js.map + +//# chunkId=4321 diff --git a/cli/tests/sourcemap.rs b/cli/tests/sourcemap.rs index b558b58682..6f4274866c 100644 --- a/cli/tests/sourcemap.rs +++ b/cli/tests/sourcemap.rs @@ -62,9 +62,6 @@ fn test_search_with_prefix() { #[test] fn test_ignore() { - let pairs = read_pairs(&get_case_path(""), &Vec::new(), &None).expect("Failed to read pairs"); - assert_eq!(pairs.len(), 6); - let pairs = read_pairs(&get_case_path(""), &["**/search/**".to_string()], &None) .expect("Failed to read pairs"); assert_eq!(pairs.len(), 3); @@ -166,3 +163,38 @@ fn test_reinject_with_new_release() { release_id.clone() ); } + +#[test] +fn test_upload_set() { + let case_path = get_case_path("search"); + let pairs = read_pairs(&case_path, &Vec::new(), &None).expect("Failed to read pairs"); + + // Find pairs where source and sourcemap have different chunk IDs + let pair_with_different_ids = pairs + .into_iter() + .find(|p| { + let source_chunk_id = p.source.get_chunk_id(); + let sourcemap_chunk_id = p.sourcemap.get_chunk_id(); + + source_chunk_id.is_some() + && sourcemap_chunk_id.is_some() + && source_chunk_id != sourcemap_chunk_id + }) + .expect("Should find at least one pair with different chunk IDs"); + + let source_chunk_id = pair_with_different_ids.source.get_chunk_id().unwrap(); + let sourcemap_chunk_id = pair_with_different_ids.sourcemap.get_chunk_id().unwrap(); + + // Verify they are different + assert_ne!(source_chunk_id, sourcemap_chunk_id); + + // Convert to UploadSet + use posthog_cli::api::symbol_sets::SymbolSetUpload; + let upload_set: SymbolSetUpload = pair_with_different_ids + .try_into() + .expect("Failed to convert to SymbolSetUpload"); + + // Verify that the upload set uses the source's chunk ID, not the sourcemap's + assert_eq!(upload_set.chunk_id, source_chunk_id); + assert_ne!(upload_set.chunk_id, sourcemap_chunk_id); +}