From cba3d965076841a6fd6bdb6542b809adb9eb5231 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Wed, 2 Dec 2026 11:49:12 -0500 Subject: [PATCH 1/2] Give the pip case of the quoted-URL credential test its own venv `a_hosted_warning_quotes_a_lock_entry_without_its_token` (#2445) scans a project that declares `six` by a direct reference and has no venv. A scan reads the installed packages, so without a venv it read the Python on PATH. That Python holds `six` 1.16.0 on Ubuntu, which ships it, so the test passed in PR CI. On the Windows runner and on a Mac without `six` the scan ends with "No packages found" and never quotes the entry, and the three `scan` runs of the case fail. The project now has its own venv with `six` 1.16.0 in it, laid out as the crawler looks for it on each platform. Co-Authored-By: Claude Fable 5.2 --- .../tests/scan/quoted_url_credentials.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/socket-patch-cli/tests/scan/quoted_url_credentials.rs b/crates/socket-patch-cli/tests/scan/quoted_url_credentials.rs index 27c9f7b81..0cde192f5 100644 --- a/crates/socket-patch-cli/tests/scan/quoted_url_credentials.rs +++ b/crates/socket-patch-cli/tests/scan/quoted_url_credentials.rs @@ -72,6 +72,10 @@ fn cargo_git(root: &Path) { } /// pip, with `six` installed from a private mirror by direct reference. +/// The project has its own venv with `six` in it: a scan reads the +/// installed packages, and without one it reads those of the Python on +/// PATH, which holds `six` 1.16.0 on some machines (Ubuntu ships it) and +/// not on others. fn requirements_direct_reference(root: &Path) { std::fs::write( root.join("requirements.txt"), @@ -80,6 +84,20 @@ fn requirements_direct_reference(root: &Path) { ), ) .unwrap(); + // The layout the crawler looks for differs by platform. + let site_packages = if cfg!(windows) { + root.join(".venv").join("Lib").join("site-packages") + } else { + root.join(".venv/lib/python3.12/site-packages") + }; + let dist_info = site_packages.join("six-1.16.0.dist-info"); + std::fs::create_dir_all(&dist_info).unwrap(); + std::fs::write( + dist_info.join("METADATA"), + "Metadata-Version: 2.1\nName: six\nVersion: 1.16.0\n", + ) + .unwrap(); + std::fs::write(site_packages.join("six.py"), "").unwrap(); } const YARN: Case = Case { From 20d65dfeacd8fbb0ad08df9e4f1fb8da72435a46 Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Wed, 2 Dec 2026 11:58:42 -0500 Subject: [PATCH 2/2] Keep an activated virtualenv out of the quoted-URL credential test The Python crawler reads an activated virtualenv (`VIRTUAL_ENV`) ahead of the project's own venv, and the test ran the binary with that variable passed through. Run from a shell with a virtualenv activated, the pip case read that one and failed the same way as before. The child now runs without the variable, as the other scan tests do. The module's header no longer calls every project file-only. Co-Authored-By: Claude Fable 5.2 --- .../tests/scan/quoted_url_credentials.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/socket-patch-cli/tests/scan/quoted_url_credentials.rs b/crates/socket-patch-cli/tests/scan/quoted_url_credentials.rs index 0cde192f5..1862147e8 100644 --- a/crates/socket-patch-cli/tests/scan/quoted_url_credentials.rs +++ b/crates/socket-patch-cli/tests/scan/quoted_url_credentials.rs @@ -3,14 +3,16 @@ //! entry must not copy that credential to the terminal, a CI log or the //! `--json` document (#2287). //! -//! Each case plants one token in a file-only project, runs the built -//! binary against a wiremock patch API, and reads both streams back. +//! Each case plants one token in a small project (the pip one has its +//! own venv, the others hold files alone), runs the built binary against +//! a wiremock patch API, and reads both streams back. use std::path::Path; use wiremock::MockServer; use crate::common; +use crate::common::hermetic::{self, Extra}; use crate::hosted_fixture::*; /// The planted credential. No message may carry it. @@ -180,7 +182,16 @@ async fn run_quotes_without_the_token( "--api-token", "fake", ]); - let (code, stdout, stderr) = common::run_with_env(&root, &args, &[]); + // As `common::run` runs it, and without an activated virtualenv: the + // Python crawler reads one ahead of the project's own venv. + let mut cmd = common::hermetic_command(&common::binary()); + cmd.args(&args).current_dir(&root); + common::jvm_env::isolate_cli(&mut cmd); + hermetic::scrub_extra(&mut cmd, &[Extra::Go, Extra::Venv]); + let out = cmd.output().expect("failed to execute socket-patch binary"); + let code = out.status.code().unwrap_or(-1); + let stdout = String::from_utf8_lossy(&out.stdout).to_string(); + let stderr = String::from_utf8_lossy(&out.stderr).to_string(); let run = format!("{} --mode {mode} (exit {code})", command.join(" ")); let both = format!("{stdout}\n{stderr}"); if both.contains(SECRET) {