fix(err): fix duplicate sourcemap (#40330)

This commit is contained in:
Hugues Pouillot
2025-10-24 19:37:55 +02:00
committed by GitHub
parent 6c717af11e
commit 681606daaf
5 changed files with 42 additions and 5 deletions

View File

@@ -141,7 +141,6 @@ impl TryInto<SymbolSetUpload> for SourcePair {
fn try_into(self) -> Result<SymbolSetUpload> {
let chunk_id = self
.sourcemap
.get_chunk_id()
.ok_or_else(|| anyhow!("Chunk ID not found"))?;
let source_content = self.source.inner.content;

View File

@@ -1 +1,3 @@
//# sourceMappingURL=/static/chunk-sourcemap.js.map
//# chunkId=1234

View File

@@ -1 +1,3 @@
{}
{
"chunk_id": "1234"
}

View File

@@ -1 +1,3 @@
//# sourceMappingURL=chunk-sourcemap.js.map
//# chunkId=4321

View File

@@ -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);
}