:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(cli): keep the stamped release when hermes clone has no release flags (#126048)
Rafael Audiberte5ddfc79ecff
diff --git a/cli/.sampo/changesets/steady-clone-keeps-release.md b/cli/.sampo/changesets/steady-clone-keeps-release.mdnew file mode 100644index 000000000000..3942394d21bb--- /dev/null+++ b/cli/.sampo/changesets/steady-clone-keeps-release.md@@ -0,0 +1,5 @@+---+cargo/posthog-cli: patch+---++Keep the release that `hermes inject` stamped when `hermes clone` runs in symbol-set mode without release flagsdiff --git a/cli/src/sourcemaps/hermes/clone.rs b/cli/src/sourcemaps/hermes/clone.rsindex ed64447aaa53..3adec9b13751 100644--- a/cli/src/sourcemaps/hermes/clone.rs+++ b/cli/src/sourcemaps/hermes/clone.rs@@ -42,7 +42,10 @@ pub struct CloneArgs {pub fn clone(args: &CloneArgs) -> Result<()> {context().capture_command_invoked("hermes_clone");+ clone_maps(args)+}+fn clone_maps(args: &CloneArgs) -> Result<()> {let CloneArgs {minified_map_path,composed_map_path,@@ -72,9 +75,12 @@ pub fn clone(args: &CloneArgs) -> Result<()> {// Without this, a later release collides with the release that uploaded the map first.let release_id = match release_mode {ReleaseMode::Event => None,+ // Without release flags, a map that already carries a release resolves none, and that+ // release stays. `hermes inject` stamped it, and the upload binds the symbol set to it.ReleaseMode::SymbolSet => {get_release_for_maps(minified_map_path, release.clone(), [&minified_map])?.map(|r| r.id.to_string())+ .or_else(|| minified_map.get_release_id())}};@@ -120,7 +126,8 @@ pub fn clone_metadata(minified_map: &SourceMapFile, composed_map: &mut SourceMap#[cfg(test)]mod test {- use super::clone_metadata;+ use super::{clone_maps, clone_metadata, CloneArgs};+ use crate::sourcemaps::args::{ReleaseArgs, ReleaseMode};use crate::sourcemaps::content::SourceMapFile;use crate::utils::files::SourceFile;use std::path::PathBuf;@@ -192,4 +199,62 @@ mod test {assert_eq!(composed.get_release_id(), None);}++ #[test]+ fn symbol_set_clone_without_release_flags_keeps_the_stamped_release() {+ // `hermes inject` stamps the release into the packager map. A clone without release+ // flags resolves none, and must not clear it, or the upload binds to no release.+ let dir = tempfile::tempdir().unwrap();+ let minified_map_path = dir.path().join("main.jsbundle.map");+ let composed_map_path = dir.path().join("main.hbc.map");+ std::fs::write(+ &minified_map_path,+ serde_json::json!({+ "version": 3,+ "mappings": "AAAA",+ "sources": ["App.js"],+ "names": [],+ "chunk_id": "c96bfa94-ca84-4f98-8d5e-f15adba692ca",+ "release_id": "11111111-2222-4333-8444-555555555555",+ })+ .to_string(),+ )+ .unwrap();+ std::fs::write(+ &composed_map_path,+ serde_json::json!({+ "version": 3,+ "mappings": "AAAA",+ "sources": ["App.js"],+ "names": [],+ "x_hermes_function_offsets": {},+ })+ .to_string(),+ )+ .unwrap();++ clone_maps(&CloneArgs {+ minified_map_path: minified_map_path.clone(),+ composed_map_path: composed_map_path.clone(),+ release: ReleaseArgs {+ name: None,+ version: None,+ build: None,+ info_plist: None,+ skip_release_on_fail: true,+ },+ release_mode: ReleaseMode::SymbolSet,+ })+ .unwrap();++ for path in [minified_map_path, composed_map_path] {+ assert_eq!(+ SourceMapFile::load(&path)+ .unwrap()+ .get_release_id()+ .as_deref(),+ Some("11111111-2222-4333-8444-555555555555")+ );+ }+ }}diff --git a/hog/src/error-tracking/run.ts b/hog/src/error-tracking/run.tsindex ec52ce4934cb..b78ea2a30907 100644--- a/hog/src/error-tracking/run.ts+++ b/hog/src/error-tracking/run.ts@@ -694,6 +694,8 @@ export async function cloneMaps(let reported: ReleaseReport | null = nulllet releaseId: string | null = nullif (options.releaseMode === 'symbol-set') {+ // Without release flags, the release `inject` stamped stays, and the upload binds to it.+ releaseId = from.map.releaseIdconst fields = await releaseFields(ctx, options)if (releaseRequested(fields) || from.map.releaseId === null) {const resolved = resolveJsRelease(fields, ctx.runtime.env, from.path, warnings)diff --git a/hog/test/parity/golden/e2e/hermes-clone-symbol-set-keeps-release.json b/hog/test/parity/golden/e2e/hermes-clone-symbol-set-keeps-release.jsonnew file mode 100644index 000000000000..4bdaad0324b8--- /dev/null+++ b/hog/test/parity/golden/e2e/hermes-clone-symbol-set-keeps-release.json@@ -0,0 +1,9 @@+{+ "exitCode": 0,+ "requests": [],+ "files": {+ "android/hbc/index.android.bundle.hbc.composed.map": "utf8:{\"release_id\":\"3fd4c79f-4dd7-53b7-b5f3-e51dce5a9e80\",\"chunk_id\":\"<v7-1>\",\"mappings\":\"AAAA,SACA,cAAAC\",\"names\":[\"App\",\"<global>\"],\"sources\":[\"src/App.js\",\"node_modules/react-native/Libraries/polyfill.js\"],\"sourcesContent\":[\"function App() {\\n return \\\"héllo\\\";\\n}\\nApp();\\n\",null],\"version\":3,\"x_facebook_sources\":[[{\"mappings\":\"AAA,CCC\",\"names\":[\"<global>\",\"App\"]}],null],\"x_google_ignoreList\":[1],\"x_hermes_function_offsets\":{\"0\":[0,28],\"1\":[0]},\"x_unicode\":\"😀 </script> \\\"q\\\" \\\\ \\t\"}",+ "android/index.android.bundle": "utf8:!function(){try{var e=\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof globalThis?globalThis:\"undefined\"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._posthogChunkIds=e._posthogChunkIds||{},e._posthogChunkIds[n]=\"<v7-1>\")}catch(e){}}();var __BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now();\nfunction App(){return \"héllo\"}App();\n//# sourceMappingURL=index.android.bundle.map\n//# chunkId=<v7-1>",+ "android/index.android.bundle.map": "utf8:{\"release_id\":\"3fd4c79f-4dd7-53b7-b5f3-e51dce5a9e80\",\"chunk_id\":\"<v7-1>\",\"mappings\":\"qTACA;AAAA,SAAUA\",\"names\":[\"App\"],\"sources\":[\"src/App.js\",\"node_modules/react-native/Libraries/polyfill.js\"],\"sourcesContent\":[\"function App() {\\n return \\\"héllo\\\";\\n}\\nApp();\\n\",null],\"version\":3,\"x_facebook_sources\":[[{\"mappings\":\"AAA,CCC\",\"names\":[\"<global>\",\"App\"]}],null],\"x_google_ignoreList\":[1],\"x_test\":{\"a\":\" /é\\u0001\",\"b\":1.0,\"big\":1.8446744073709552e19,\"n\":-0.0,\"z\":1e21}}"+ }+}diff --git a/hog/test/parity/scenarios.ts b/hog/test/parity/scenarios.tsindex da9d088c8a0a..26ebd9e8dbb2 100644--- a/hog/test/parity/scenarios.ts+++ b/hog/test/parity/scenarios.ts@@ -221,6 +221,15 @@ SCENARIOS.push(before: [hermesArgs.inject('android')],}),+ hermes(+ 'clone-symbol-set-keeps-release',+ hermesArgs.clone(ANDROID_MAP, ANDROID_COMPOSED, symbolSet),+ () => HERMES_BUILD,+ {+ before: [hermesArgs.inject('android', [...appRelease, ...symbolSet])],+ randomIds: true,+ }+ ),hermes('clone-debug-id',hermesArgs.clone('ios/main.jsbundle.map', 'ios/hbc/main.jsbundle.hbc.composed.map'),