Redact packse version in snapshots (#5483)

Every packse version update is currently causing a huge diff (the size
of the `lock_scenarios.rs` diff in this PR). By redacting the version
from the snapshots, we will only have the actual change in the diff and
not the redundant version change noise.

The second commit moves all remaining packse url arg values to
`common/mod.rs`, which acts as a single source of truth for the packse
version.
This commit is contained in:
konsti 2024-07-29 17:04:46 +02:00 committed by GitHub
parent a346d257cb
commit 0f87d174b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 274 additions and 537 deletions

View File

@ -26,10 +26,17 @@ use uv_python::{
// Exclude any packages uploaded after this date.
static EXCLUDE_NEWER: &str = "2024-03-25T00:00:00Z";
pub const PACKSE_VERSION: &str = "0.3.30";
/// Using a find links url allows using `--index-url` instead of `--extra-index-url` in tests
/// to prevent dependency confusion attacks against our test suite.
pub const BUILD_VENDOR_LINKS_URL: &str =
"https://raw.githubusercontent.com/astral-sh/packse/0.3.31/vendor/links.html";
pub fn build_vendor_links_url() -> String {
format!("https://raw.githubusercontent.com/astral-sh/packse/{PACKSE_VERSION}/vendor/links.html")
}
pub fn packse_index_url() -> String {
format!("https://astral-sh.github.io/packse/{PACKSE_VERSION}/simple-html/")
}
#[doc(hidden)] // Macro and test context only, don't use directly.
pub const INSTA_FILTERS: &[(&str, &str)] = &[
@ -300,6 +307,13 @@ impl TestContext {
// Destroy any remaining UNC prefixes (Windows only)
filters.push((r"\\\\\?\\".to_string(), String::new()));
// Remove the version from the packse url in lockfile snapshots. This avoid having a huge
// diff any time we upgrade packse
filters.push((
format!("https://astral-sh.github.io/packse/{PACKSE_VERSION}/"),
"https://astral-sh.github.io/packse/PACKSE_VERSION/".to_string(),
));
Self {
temp_dir,
cache_dir,

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,10 @@ use assert_cmd::assert::OutputAssertExt;
use assert_fs::fixture::{FileWriteStr, PathChild};
use predicates::prelude::predicate;
use common::{get_bin, python_path_with_versions, uv_snapshot, TestContext};
use common::{
build_vendor_links_url, get_bin, packse_index_url, python_path_with_versions, uv_snapshot,
TestContext,
};
mod common;
@ -27,9 +30,9 @@ fn command(context: &TestContext, python_versions: &[&str]) -> Command {
.arg("compile")
.arg("requirements.in")
.arg("--index-url")
.arg("https://astral-sh.github.io/packse/0.3.31/simple-html/")
.arg(packse_index_url())
.arg("--find-links")
.arg("https://raw.githubusercontent.com/astral-sh/packse/0.3.31/vendor/links.html");
.arg(build_vendor_links_url());
context.add_shared_args(&mut command);
command.env_remove("UV_EXCLUDE_NEWER");
command.env("UV_TEST_PYTHON_PATH", python_path);

View File

@ -15,7 +15,7 @@ use url::Url;
use common::{uv_snapshot, TestContext};
use uv_fs::Simplified;
use crate::common::{get_bin, venv_bin_path, BUILD_VENDOR_LINKS_URL};
use crate::common::{build_vendor_links_url, get_bin, venv_bin_path};
mod common;
@ -4431,7 +4431,7 @@ fn already_installed_dependent_editable() {
// Disable the index to guard this test against dependency confusion attacks
.arg("--no-index")
.arg("--find-links")
.arg(BUILD_VENDOR_LINKS_URL), @r###"
.arg(build_vendor_links_url()), @r###"
success: true
exit_code: 0
----- stdout -----
@ -4468,7 +4468,7 @@ fn already_installed_dependent_editable() {
// Disable the index to guard this test against dependency confusion attacks
.arg("--no-index")
.arg("--find-links")
.arg(BUILD_VENDOR_LINKS_URL), @r###"
.arg(build_vendor_links_url()), @r###"
success: false
exit_code: 1
----- stdout -----
@ -4532,7 +4532,7 @@ fn already_installed_local_path_dependent() {
// Disable the index to guard this test against dependency confusion attacks
.arg("--no-index")
.arg("--find-links")
.arg(BUILD_VENDOR_LINKS_URL), @r###"
.arg(build_vendor_links_url()), @r###"
success: true
exit_code: 0
----- stdout -----
@ -4567,7 +4567,7 @@ fn already_installed_local_path_dependent() {
// Disable the index to guard this test against dependency confusion attacks
.arg("--no-index")
.arg("--find-links")
.arg(BUILD_VENDOR_LINKS_URL), @r###"
.arg(build_vendor_links_url()), @r###"
success: false
exit_code: 1
----- stdout -----
@ -4609,7 +4609,7 @@ fn already_installed_local_path_dependent() {
// Disable the index to guard this test against dependency confusion attacks
.arg("--no-index")
.arg("--find-links")
.arg(BUILD_VENDOR_LINKS_URL), @r###"
.arg(build_vendor_links_url()), @r###"
success: false
exit_code: 1
----- stdout -----
@ -4631,7 +4631,7 @@ fn already_installed_local_path_dependent() {
// Disable the index to guard this test against dependency confusion attacks
.arg("--no-index")
.arg("--find-links")
.arg(BUILD_VENDOR_LINKS_URL), @r###"
.arg(build_vendor_links_url()), @r###"
success: true
exit_code: 0
----- stdout -----

View File

@ -13,7 +13,7 @@ use assert_cmd::prelude::*;
use common::venv_to_interpreter;
use crate::common::{get_bin, uv_snapshot, TestContext};
use crate::common::{build_vendor_links_url, get_bin, packse_index_url, uv_snapshot, TestContext};
mod common;
@ -46,9 +46,9 @@ fn command(context: &TestContext) -> Command {
.arg("pip")
.arg("install")
.arg("--index-url")
.arg("https://astral-sh.github.io/packse/0.3.31/simple-html/")
.arg(packse_index_url())
.arg("--find-links")
.arg("https://raw.githubusercontent.com/astral-sh/packse/0.3.31/vendor/links.html");
.arg(build_vendor_links_url());
context.add_shared_args(&mut command);
command.env_remove("UV_EXCLUDE_NEWER");
command

View File

@ -250,22 +250,28 @@ def main(scenarios: list[Path], snapshot_update: bool = True):
def update_common_mod_rs(packse_version: str):
"""Update the value of `BUILD_VENDOR_LINKS_URL` used in non-scenario tests."""
"""Update the value of `PACKSE_VERSION` used in non-scenario tests.
Example:
```rust
pub const PACKSE_VERSION: &str = "0.3.30";
```
"""
test_common = TESTS_COMMON_MOD_RS.read_text()
url_before_version = "https://raw.githubusercontent.com/astral-sh/packse/"
url_after_version = "/vendor/links.html"
build_vendor_links_url = f"{url_before_version}{packse_version}{url_after_version}"
before_version = 'pub const PACKSE_VERSION: &str = "'
after_version = '";'
build_vendor_links_url = f"{before_version}{packse_version}{after_version}"
if build_vendor_links_url in test_common:
logging.info(f"Up-to-date: {TESTS_COMMON_MOD_RS}")
else:
logging.info(f"Updating: {TESTS_COMMON_MOD_RS}")
url_matcher = re.compile(
re.escape(url_before_version) + "[^/]+" + re.escape(url_after_version)
re.escape(before_version) + '[^"]+' + re.escape(after_version)
)
assert (
len(url_matcher.findall(test_common)) == 1
), f"BUILD_VENDOR_LINKS_URL not found in {TESTS_COMMON_MOD_RS}"
test_common = url_matcher.sub(build_vendor_links_url, test_common)
), f"PACKSE_VERSION not found in {TESTS_COMMON_MOD_RS}"
test_common = url_matcher.sub(packse_version, test_common)
TESTS_COMMON_MOD_RS.write_text(test_common)

View File

@ -13,7 +13,7 @@ use assert_cmd::assert::OutputAssertExt;
use assert_fs::fixture::{FileWriteStr, PathChild};
use predicates::prelude::predicate;
use common::{python_path_with_versions, get_bin, uv_snapshot, TestContext};
use common::{build_vendor_links_url, packse_index_url, python_path_with_versions, get_bin, uv_snapshot, TestContext};
mod common;
@ -27,9 +27,9 @@ fn command(context: &TestContext, python_versions: &[&str]) -> Command {
.arg("compile")
.arg("requirements.in")
.arg("--index-url")
.arg("{{index_url}}")
.arg(packse_index_url())
.arg("--find-links")
.arg("{{vendor_links}}");
.arg(build_vendor_links_url());
context.add_shared_args(&mut command);
command.env_remove("UV_EXCLUDE_NEWER");
command.env("UV_TEST_PYTHON_PATH", python_path);

View File

@ -13,7 +13,7 @@ use assert_cmd::prelude::*;
use common::{venv_to_interpreter};
use crate::common::{get_bin, uv_snapshot, TestContext};
use crate::common::{build_vendor_links_url, get_bin, packse_index_url, uv_snapshot, TestContext};
mod common;
@ -47,9 +47,9 @@ fn command(context: &TestContext) -> Command {
.arg("pip")
.arg("install")
.arg("--index-url")
.arg("{{index_url}}")
.arg(packse_index_url())
.arg("--find-links")
.arg("{{vendor_links}}");
.arg(build_vendor_links_url());
context.add_shared_args(&mut command);
command.env_remove("UV_EXCLUDE_NEWER");
command

View File

@ -10,7 +10,7 @@ use anyhow::Result;
use assert_fs::prelude::*;
use insta::assert_snapshot;
use common::{uv_snapshot, TestContext};
use common::{packse_index_url, TestContext, uv_snapshot};
mod common;
@ -53,7 +53,7 @@ fn {{module_name}}() -> Result<()> {
let mut cmd = context.lock();
cmd.env_remove("UV_EXCLUDE_NEWER");
cmd.arg("--index-url").arg("{{index_url}}");
cmd.arg("--index-url").arg(packse_index_url());
{{#expected.explanation_lines}}
// {{.}}
{{/expected.explanation_lines}}