From 5773b12fa9083c1116a00e3c3a95d1b93c1f494b Mon Sep 17 00:00:00 2001 From: Sidharth Anil <44941778+sid-38@users.noreply.github.com> Date: Mon, 1 Dec 2025 06:41:21 -0500 Subject: [PATCH] Isolating test from accessing global git credential helper config (#16895) ## Summary Resolves: https://github.com/astral-sh/uv/issues/1980 Added a utility function to TestContext called **with_git_credential_helper_blocked** that isolates the test from accessing the credential helper value defined in global/system git config. It does so, by writing to a file .gitconfig in the temporary home_dir that is created as part of the TestContext. ## Test Plan Tested it by running the test pip_install::install_git_private_https_pat_and_username, and making sure it doesn't affect the keyring. ## Note: The commit hash for the uv-private-package seems to have changed. Kindly, ensure that the modification related to that is correct. --- crates/uv/tests/it/common/mod.rs | 18 +++++++++++++++++- crates/uv/tests/it/pip_install.rs | 8 ++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/crates/uv/tests/it/common/mod.rs b/crates/uv/tests/it/common/mod.rs index 1399b584d..0d59482b3 100644 --- a/crates/uv/tests/it/common/mod.rs +++ b/crates/uv/tests/it/common/mod.rs @@ -12,10 +12,13 @@ use uv_python::downloads::ManagedPythonDownloadList; use assert_cmd::assert::{Assert, OutputAssertExt}; use assert_fs::assert::PathAssert; -use assert_fs::fixture::{ChildPath, PathChild, PathCopy, PathCreateDir, SymlinkToFile}; +use assert_fs::fixture::{ + ChildPath, FileWriteStr, PathChild, PathCopy, PathCreateDir, SymlinkToFile, +}; use base64::{Engine, prelude::BASE64_STANDARD as base64}; use futures::StreamExt; use indoc::formatdoc; +use indoc::indoc; use itertools::Itertools; use predicates::prelude::predicate; use regex::Regex; @@ -563,6 +566,19 @@ impl TestContext { self } + // Unsets the git credential helper using temp home gitconfig + pub fn with_unset_git_credential_helper(self) -> Self { + let git_config = self.home_dir.child(".gitconfig"); + git_config + .write_str(indoc! {r" + [credential] + helper = + "}) + .expect("Failed to unset git credential helper"); + + self + } + /// Clear filters on `TestContext`. pub fn clear_filters(mut self) -> Self { self.filters.clear(); diff --git a/crates/uv/tests/it/pip_install.rs b/crates/uv/tests/it/pip_install.rs index 8441f7c38..b88c39d34 100644 --- a/crates/uv/tests/it/pip_install.rs +++ b/crates/uv/tests/it/pip_install.rs @@ -2501,14 +2501,10 @@ fn install_git_private_https_pat_at_ref() { /// Install a package from a private GitHub repository using a PAT and username /// An arbitrary username is supported when using a PAT. -/// -/// TODO(charlie): This test modifies the user's keyring. -/// See: . #[test] #[cfg(feature = "git")] -#[ignore = "Modifies the user's keyring"] fn install_git_private_https_pat_and_username() { - let context = TestContext::new(DEFAULT_PYTHON_VERSION); + let context = TestContext::new(DEFAULT_PYTHON_VERSION).with_unset_git_credential_helper(); let token = decode_token(common::READ_ONLY_GITHUB_TOKEN); let user = "astral-test-bot"; @@ -2522,7 +2518,7 @@ fn install_git_private_https_pat_and_username() { Resolved 1 package in [TIME] Prepared 1 package in [TIME] Installed 1 package in [TIME] - + uv-private-pypackage==0.1.0 (from git+https://astral-test-bot:****@github.com/astral-test/uv-private-pypackage@6c09ce9ae81f50670a60abd7d95f30dd416d00ac) + + uv-private-pypackage==0.1.0 (from git+https://astral-test-bot:****@github.com/astral-test/uv-private-pypackage@d780faf0ac91257d4d5a4f0c5a0e4509608c0071) "###); context.assert_installed("uv_private_pypackage", "0.1.0");