Skip to content

Commit 8b4b315

Browse files
runningcodeclaude
andcommitted
test(build): Use fixed version override for deterministic test fixtures
Solves the maintenance problem where the test fixture SHA would change with every CLI version release. Now uses SENTRY_CLI_VERSION_OVERRIDE environment variable to set a fixed version (0.0.0-test) in tests, ensuring stable SHA checksums across releases. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b7db7a8 commit 8b4b315

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/utils/build/normalize.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::io::Write as _;
55
#[cfg(not(windows))]
66
use std::os::unix::fs::PermissionsExt as _;
77
use std::path::{Path, PathBuf};
8+
use std::sync::LazyLock;
89

910
use crate::constants::VERSION;
1011
use crate::utils::fs::TempFile;
@@ -16,6 +17,21 @@ use walkdir::WalkDir;
1617
use zip::write::SimpleFileOptions;
1718
use zip::{DateTime, ZipWriter};
1819

20+
static VERSION_RESOLVED: LazyLock<String> = LazyLock::new(|| {
21+
#[cfg(test)]
22+
{
23+
std::env::var("SENTRY_CLI_VERSION_OVERRIDE").unwrap_or_else(|_| VERSION.to_string())
24+
}
25+
#[cfg(not(test))]
26+
{
27+
VERSION.to_string()
28+
}
29+
});
30+
31+
fn get_version() -> &'static str {
32+
&VERSION_RESOLVED
33+
}
34+
1935
fn sort_entries(path: &Path) -> Result<impl Iterator<Item = (PathBuf, PathBuf)>> {
2036
Ok(WalkDir::new(path)
2137
.into_iter()
@@ -86,8 +102,9 @@ fn metadata_file_options() -> SimpleFileOptions {
86102
pub fn write_version_metadata<W: std::io::Write + std::io::Seek>(
87103
zip: &mut ZipWriter<W>,
88104
) -> Result<()> {
105+
let version = get_version();
89106
zip.start_file(".sentry-cli-metadata.txt", metadata_file_options())?;
90-
writeln!(zip, "sentry-cli-version: {VERSION}")?;
107+
writeln!(zip, "sentry-cli-version: {version}")?;
91108
Ok(())
92109
}
93110

68 Bytes
Binary file not shown.

tests/integration/build/upload.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ static CONTENT_TYPE_REGEX: LazyLock<Regex> = LazyLock::new(|| {
109109
/// and that the data sent to the chunk upload endpoint is exactly as expected.
110110
/// It also verifies that the correct calls are made to the assemble endpoint.
111111
fn command_build_upload_apk_chunked() {
112+
// Override version for deterministic binary comparison of chunk content
113+
std::env::set_var("SENTRY_CLI_VERSION_OVERRIDE", "0.0.0-test");
114+
112115
let is_first_assemble_call = AtomicBool::new(true);
113116
let expected_chunk_body = fs::read("tests/integration/_expected_requests/build/apk_chunk.bin")
114117
.expect("expected chunk body file should be present");
@@ -162,7 +165,7 @@ fn command_build_upload_apk_chunked() {
162165
if is_first_assemble_call.swap(false, Ordering::Relaxed) {
163166
r#"{
164167
"state": "created",
165-
"missingChunks": ["985f82b2ff9f3749f9d4c71ecb02e0396b9bc5a3"]
168+
"missingChunks": ["4c57ae0573fd4342c8996f9b2c9efd00ac84b5ea"]
166169
}"#
167170
} else {
168171
r#"{

0 commit comments

Comments
 (0)