mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 13:25:00 +00:00
Add backtracking tests for distribution incompatibilities (#2839)
## Summary Demonstrates some suboptimal behavior in how we handle invalid metadata, which are fixed in https://github.com/astral-sh/uv/pull/2834. The included wheels were modified by-hand to include invalid structures.
This commit is contained in:
parent
cedb5e4aec
commit
c11e9e5097
4 changed files with 128 additions and 0 deletions
|
@ -4397,6 +4397,50 @@ fn offline_registry() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Resolve a registry package without network access via the `--offline` flag. We should backtrack
|
||||
/// to the latest version of the package that's available in the cache.
|
||||
#[test]
|
||||
fn offline_registry_backtrack() -> Result<()> {
|
||||
let context = TestContext::new("3.12");
|
||||
let requirements_in = context.temp_dir.child("requirements.in");
|
||||
requirements_in.write_str("iniconfig==1.1.1")?;
|
||||
|
||||
// Populate the cache.
|
||||
uv_snapshot!(context.compile()
|
||||
.arg("requirements.in"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
# This file was autogenerated by uv via the following command:
|
||||
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in
|
||||
iniconfig==1.1.1
|
||||
|
||||
----- stderr -----
|
||||
Resolved 1 package in [TIME]
|
||||
"###
|
||||
);
|
||||
|
||||
// Resolve with `--offline`, with a looser requirement. We should backtrack to `1.1.1`, but
|
||||
// we don't right now.
|
||||
let requirements_in = context.temp_dir.child("requirements.in");
|
||||
requirements_in.write_str("iniconfig")?;
|
||||
|
||||
uv_snapshot!(context.compile()
|
||||
.arg("requirements.in")
|
||||
.arg("--offline"), @r###"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: Failed to download: iniconfig==2.0.0
|
||||
Caused by: Network connectivity is disabled, but the requested data wasn't found in the cache for: `https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl.metadata`
|
||||
"###
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Resolve a package without network access via the `--offline` flag, using `--find-links` for an
|
||||
/// HTML registry.
|
||||
#[test]
|
||||
|
@ -4504,6 +4548,90 @@ fn offline_direct_url() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Resolve a package with invalid metadata, by way of an invalid `Requires-Python` field in the
|
||||
/// `METADATA` file.
|
||||
#[test]
|
||||
fn invalid_metadata_requires_python() -> Result<()> {
|
||||
let context = TestContext::new("3.12");
|
||||
let requirements_in = context.temp_dir.child("requirements.in");
|
||||
requirements_in.write_str("validation==2.0.0")?;
|
||||
|
||||
// `2.0.0` has invalid metadata.
|
||||
uv_snapshot!(context.compile()
|
||||
.arg("requirements.in")
|
||||
.arg("--no-index")
|
||||
.arg("--find-links")
|
||||
.arg(context.workspace_root.join("scripts").join("links")), @r###"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: Failed to download: validation==2.0.0
|
||||
Caused by: Couldn't parse metadata of validation-2.0.0-py3-none-any.whl from validation==2.0.0
|
||||
Caused by: Failed to parse version: Unexpected end of version specifier, expected operator:
|
||||
12
|
||||
^^
|
||||
|
||||
"###
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Resolve a package with multiple `.dist-info` directories.
|
||||
#[test]
|
||||
fn invalid_metadata_multiple_dist_info() -> Result<()> {
|
||||
let context = TestContext::new("3.12");
|
||||
let requirements_in = context.temp_dir.child("requirements.in");
|
||||
requirements_in.write_str("validation==3.0.0")?;
|
||||
|
||||
// `3.0.0` has an invalid structure (multiple `.dist-info` directories).
|
||||
uv_snapshot!(context.compile()
|
||||
.arg("requirements.in")
|
||||
.arg("--no-index")
|
||||
.arg("--find-links")
|
||||
.arg(context.workspace_root.join("scripts").join("links")), @r###"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: Failed to download: validation==3.0.0
|
||||
Caused by: Multiple .dist-info directories found: validation-2.0.0, validation-3.0.0
|
||||
"###
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Resolve a package, but backtrack past versions with invalid metadata.
|
||||
#[test]
|
||||
fn invalid_metadata_backtrack() -> Result<()> {
|
||||
let context = TestContext::new("3.12");
|
||||
let requirements_in = context.temp_dir.child("requirements.in");
|
||||
requirements_in.write_str("validation")?;
|
||||
|
||||
// `2.0.0` and `3.0.0` have invalid metadata. We should backtrack to `1.0.0` (the preceding
|
||||
// version, which has valid metadata), but we don't right now.
|
||||
uv_snapshot!(context.compile()
|
||||
.arg("requirements.in")
|
||||
.arg("--no-index")
|
||||
.arg("--find-links")
|
||||
.arg(context.workspace_root.join("scripts").join("links")), @r###"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: Failed to download: validation==3.0.0
|
||||
Caused by: Multiple .dist-info directories found: validation-2.0.0, validation-3.0.0
|
||||
"###
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Resolve nested `-r` requirements files with relative paths.
|
||||
#[test]
|
||||
fn compile_relative_subfile() -> Result<()> {
|
||||
|
|
BIN
scripts/links/validation-1.0.0-py3-none-any.whl
Normal file
BIN
scripts/links/validation-1.0.0-py3-none-any.whl
Normal file
Binary file not shown.
BIN
scripts/links/validation-2.0.0-py3-none-any.whl
Normal file
BIN
scripts/links/validation-2.0.0-py3-none-any.whl
Normal file
Binary file not shown.
BIN
scripts/links/validation-3.0.0-py3-none-any.whl
Normal file
BIN
scripts/links/validation-3.0.0-py3-none-any.whl
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue