diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index 91252ac7c..5f50d655c 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -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<()> { diff --git a/scripts/links/validation-1.0.0-py3-none-any.whl b/scripts/links/validation-1.0.0-py3-none-any.whl new file mode 100644 index 000000000..8808be42f Binary files /dev/null and b/scripts/links/validation-1.0.0-py3-none-any.whl differ diff --git a/scripts/links/validation-2.0.0-py3-none-any.whl b/scripts/links/validation-2.0.0-py3-none-any.whl new file mode 100644 index 000000000..fa560c775 Binary files /dev/null and b/scripts/links/validation-2.0.0-py3-none-any.whl differ diff --git a/scripts/links/validation-3.0.0-py3-none-any.whl b/scripts/links/validation-3.0.0-py3-none-any.whl new file mode 100644 index 000000000..52ba2e5fd Binary files /dev/null and b/scripts/links/validation-3.0.0-py3-none-any.whl differ