← Back to Pull requests

Reject accidental PyPI access in local-scenario tests #1885

Open
zaniebot opened this pull request with 220 lines diff across 8 files
View on GitHub
zaniebot zaniebot commented on Sep 17, 2026 18:44 UTC
Author

After the test suite defaults to local package indexes, accidental public-index access should fail instead of silently reintroducing a PyPI dependency. Add a test-only uv-client policy that rejects public-index requests and redirect targets, rebuilds reused clients when their policy differs, and rejects opaque custom clients that cannot enforce it. Enable the policy for local test commands and artifact helpers, with an explicit opt-out for the dedicated PyPI cases. test_pypi_guard_blocks_requests_and_redirects covers both redirect modes; test_pypi_guard_rebuilds_reused_clients covers client reuse. This is the final hardening layer, after #1685 and #1693.

Diff: 220 lines (+214 / -6) across 8 files Reviewer: woodruffw Review duration: 109060m
All Vouch review confidence checks passed
Residual risk 0.06 = Change Risk (0.53) × (1 − Review Confidence (0.89)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.53 · 220 lines diff across 8 files
0.53
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.91 · 5 substantive comment(s)
0.91
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
89%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.323
Real PR Conversation Timeline
9 items
codspeed[bot] codspeed[bot] commented on Sep 17, 2026 19:23 UTC
Bot

<!-- __CODSPEED_PERFORMANCE_REPORT_COMMENT__ -->

Merging this PR will not alter performance

✅ 41 untouched benchmarks

---

<sub>Comparing <code>zb/packse-review-test-network-policy</code> (ff32539) with <code>zb/packse-simplify-scenarios</code> (ec6263f)[^unexpected-base]</sub>

<a href="https://app.codspeed.io/astral-sh/uv-dev/branches/zb%2Fpackse-review-test-network-policy?utm_source=github&utm_medium=comment-v2&utm_content=button">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://codspeed.io/pr-report/open-in-codspeed-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="https://codspeed.io/pr-report/open-in-codspeed-light.svg">
<img alt="Open in CodSpeed" src="https://codspeed.io/pr-report/open-in-codspeed-light.svg" width="169" height="32">
</picture>
</a>

[^unexpected-base]: No successful run was found on <code>zb/packse-simplify-scenarios</code> (bfeb735) during the generation of this report, so 1b9d8d6 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

woodruffw woodruffw commented on code on Sep 17, 2026 21:14 UTC
Code Review
crates/uv-client/src/base_client.rs:1
@@ -72,14 +72,16 @@ pub enum ClientBuildError {
     Credentials(#[from] CredentialsFromUrlError),
     #[error(transparent)]
     IndexCredentials(#[from] IndexCredentialsError),
+    #[error("a custom HTTP client cannot enforce the test-only PyPI access restriction")]
+    TestPypiCustomClient,

It seems like this should be a #[cfg(test)] variant?

woodruffw woodruffw commented on code on Sep 17, 2026 21:14 UTC
Code Review
crates/uv-client/src/base_client.rs:1
@@ -134,6 +136,8 @@ pub struct BaseClientBuilder<'a> {
     client_name: Option<&'static str>,
     /// Whether to disable retry delays (for testing).
     no_retry_delay: bool,
+    /// Whether to reject public-index access from local-scenario tests.
+    deny_pypi: bool,

Same here.

woodruffw woodruffw commented on code on Sep 17, 2026 21:15 UTC
Code Review
crates/uv-client/src/base_client.rs:1
@@ -72,14 +72,16 @@ pub enum ClientBuildError {
     Credentials(#[from] CredentialsFromUrlError),
     #[error(transparent)]
     IndexCredentials(#[from] IndexCredentialsError),
+    #[error("a custom HTTP client cannot enforce the test-only PyPI access restriction")]
+    TestPypiCustomClient,

Or whatever works across crate boundaries.

woodruffw woodruffw commented on code on Sep 17, 2026 21:17 UTC
Code Review
crates/uv-static/src/env_vars.rs:1
@@ -736,6 +736,18 @@ impl EnvVars {
     #[attr_added_in("0.8.0")]
     pub const UV_INTERNAL__TEST_PYTHON_MANAGED: &'static str = "UV_INTERNAL__TEST_PYTHON_MANAGED";
 
+    /// Stop virtual environment discovery at this directory during tests.
+    #[attr_hidden]
+    pub const UV_INTERNAL__TEST_PYTHON_CEILING: &'static str = "UV_INTERNAL__TEST_PYTHON_CEILING";

This seems like it belongs in a different PR and should have a better name.

zaniebot zaniebot commented on code on Sep 17, 2026 21:40 UTC
Code Review
crates/uv-client/src/base_client.rs:1
@@ -72,14 +72,16 @@ pub enum ClientBuildError {
     Credentials(#[from] CredentialsFromUrlError),
     #[error(transparent)]
     IndexCredentials(#[from] IndexCredentialsError),
+    #[error("a custom HTTP client cannot enforce the test-only PyPI access restriction")]
+    TestPypiCustomClient,

This is now the final hardening layer. The error variant, policy fields, middleware, and redirect checks are behind #[cfg(any(test, feature = "test"))]. uv-test enables the uv-client/test feature so the policy also works across crate boundaries in integration-test binaries; ordinary client builds omit it.

zaniebot zaniebot commented on code on Sep 17, 2026 21:41 UTC
Code Review
crates/uv-client/src/base_client.rs:1
@@ -134,6 +136,8 @@ pub struct BaseClientBuilder<'a> {
     client_name: Option<&'static str>,
     /// Whether to disable retry delays (for testing).
     no_retry_delay: bool,
+    /// Whether to reject public-index access from local-scenario tests.
+    deny_pypi: bool,

The builder and client fields now use the same test-only configuration as the middleware and error variant.

zaniebot zaniebot commented on code on Sep 17, 2026 21:41 UTC
Code Review
crates/uv-static/src/env_vars.rs:1
@@ -736,6 +736,18 @@ impl EnvVars {
     #[attr_added_in("0.8.0")]
     pub const UV_INTERNAL__TEST_PYTHON_MANAGED: &'static str = "UV_INTERNAL__TEST_PYTHON_MANAGED";
 
+    /// Stop virtual environment discovery at this directory during tests.
+    #[attr_hidden]
+    pub const UV_INTERNAL__TEST_PYTHON_CEILING: &'static str = "UV_INTERNAL__TEST_PYTHON_CEILING";

Moved this to #1936 and renamed it UV_INTERNAL__TEST_VIRTUALENV_DISCOVERY_ROOT. That PR includes a focused case showing that discovery stops before the test root while still finding a virtualenv inside it.

Reviewers
Assignees
zaniebot zaniebot
Labels
risk: low confidence: 89.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 52.5% (MEDIUM) · Higher = larger blast radius
52.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 89.5% · Lower = rushed or shallow review
89.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 5.5% · Safe to merge
5.5%