Skip to content

Fix version json tests to work outside git checkout #13566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 85 additions & 35 deletions crates/uv/tests/it/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,22 @@ fn version_get_fallback_unmanaged_short() -> Result<()> {
Ok(())
}

/// In tarball builds of uv, git version info is missing (distros do this)
fn git_version_info_expected() -> bool {
// This is setup to aggressively panic to make sure this is working at all
// If you're a packager of uv and this does indeed blow up for you, we will
// gladly change these expects into "just return false" or something.
let manifest_dir = std::env::var(uv_static::EnvVars::CARGO_MANIFEST_DIR)
.expect("CARGO_MANIFEST_DIR not defined");
let git_dir = std::path::Path::new(&manifest_dir)
.parent()
.expect("parent of manifest dir missing")
.parent()
.expect("grandparent of manifest dir missing")
.join(".git");
git_dir.exists()
}

// version_get_fallback with `--json`
#[test]
fn version_get_fallback_unmanaged_json() -> Result<()> {
Expand Down Expand Up @@ -945,26 +961,43 @@ fn version_get_fallback_unmanaged_json() -> Result<()> {
),
])
.collect::<Vec<_>>();
uv_snapshot!(filters, context.version()
.arg("--output-format").arg("json"), @r#"
success: true
exit_code: 0
----- stdout -----
{
"package_name": "uv",
"version": "[VERSION]",
"commit_info": {
"short_commit_hash": "[LONGHASH]",
"commit_hash": "[LONGHASH]",
"commit_date": "[DATE]",
"last_tag": "[TAG]",
"commits_since_last_tag": [COUNT]
if git_version_info_expected() {
uv_snapshot!(filters, context.version()
.arg("--output-format").arg("json"), @r#"
success: true
exit_code: 0
----- stdout -----
{
"package_name": "uv",
"version": "[VERSION]",
"commit_info": {
"short_commit_hash": "[LONGHASH]",
"commit_hash": "[LONGHASH]",
"commit_date": "[DATE]",
"last_tag": "[TAG]",
"commits_since_last_tag": [COUNT]
}
}
}

----- stderr -----
warning: Failed to read project metadata (The project is marked as unmanaged: `[TEMP_DIR]/`). Running `uv self version` for compatibility. This fallback will be removed in the future; pass `--preview` to force an error.
"#);
----- stderr -----
warning: Failed to read project metadata (The project is marked as unmanaged: `[TEMP_DIR]/`). Running `uv self version` for compatibility. This fallback will be removed in the future; pass `--preview` to force an error.
"#);
} else {
uv_snapshot!(filters, context.version()
.arg("--output-format").arg("json"), @r#"
success: true
exit_code: 0
----- stdout -----
{
"package_name": "uv",
"version": "[VERSION]",
"commit_info": null
}

----- stderr -----
warning: Failed to read project metadata (The project is marked as unmanaged: `[TEMP_DIR]/`). Running `uv self version` for compatibility. This fallback will be removed in the future; pass `--preview` to force an error.
"#);
}

let pyproject = fs_err::read_to_string(&pyproject_toml)?;
assert_snapshot!(
Expand Down Expand Up @@ -1176,25 +1209,42 @@ fn self_version_json() -> Result<()> {
),
])
.collect::<Vec<_>>();
uv_snapshot!(filters, context.self_version()
.arg("--output-format").arg("json"), @r#"
success: true
exit_code: 0
----- stdout -----
{
"package_name": "uv",
"version": "[VERSION]",
"commit_info": {
"short_commit_hash": "[LONGHASH]",
"commit_hash": "[LONGHASH]",
"commit_date": "[DATE]",
"last_tag": "[TAG]",
"commits_since_last_tag": [COUNT]

if git_version_info_expected() {
uv_snapshot!(filters, context.self_version()
.arg("--output-format").arg("json"), @r#"
success: true
exit_code: 0
----- stdout -----
{
"package_name": "uv",
"version": "[VERSION]",
"commit_info": {
"short_commit_hash": "[LONGHASH]",
"commit_hash": "[LONGHASH]",
"commit_date": "[DATE]",
"last_tag": "[TAG]",
"commits_since_last_tag": [COUNT]
}
}
}

----- stderr -----
"#);
----- stderr -----
"#);
} else {
uv_snapshot!(filters, context.self_version()
.arg("--output-format").arg("json"), @r#"
success: true
exit_code: 0
----- stdout -----
{
"package_name": "uv",
"version": "[VERSION]",
"commit_info": null
}

----- stderr -----
"#);
}

let pyproject = fs_err::read_to_string(&pyproject_toml)?;
assert_snapshot!(
Expand Down
Loading