1#![allow(dead_code, unreachable_pub)]
3
4use std::borrow::BorrowMut;
5use std::ffi::OsString;
6use std::io::Write as _;
7use std::iter::Iterator;
8use std::path::{Path, PathBuf};
9use std::process::{Command, ExitStatus, Output, Stdio};
10use std::str::FromStr;
11use std::{env, io};
12use uv_preview::Preview;
13use uv_python::downloads::ManagedPythonDownloadList;
14
15use assert_cmd::assert::{Assert, OutputAssertExt};
16use assert_fs::assert::PathAssert;
17use assert_fs::fixture::{
18 ChildPath, FileWriteStr, PathChild, PathCopy, PathCreateDir, SymlinkToFile,
19};
20use base64::{Engine, prelude::BASE64_STANDARD as base64};
21use futures::StreamExt;
22use indoc::{formatdoc, indoc};
23use itertools::Itertools;
24use predicates::prelude::predicate;
25use regex::Regex;
26use tokio::io::AsyncWriteExt;
27
28use uv_cache::{Cache, CacheBucket};
29use uv_fs::Simplified;
30use uv_python::managed::ManagedPythonInstallations;
31use uv_python::{
32 EnvironmentPreference, PythonInstallation, PythonPreference, PythonRequest, PythonVersion,
33};
34use uv_static::EnvVars;
35
36static EXCLUDE_NEWER: &str = "2024-03-25T00:00:00Z";
38
39pub const PACKSE_VERSION: &str = "0.3.59";
40pub const DEFAULT_PYTHON_VERSION: &str = "3.12";
41
42pub const LATEST_PYTHON_3_15: &str = "3.15.0a6";
44pub const LATEST_PYTHON_3_14: &str = "3.14.3";
45pub const LATEST_PYTHON_3_13: &str = "3.13.12";
46pub const LATEST_PYTHON_3_12: &str = "3.12.12";
47pub const LATEST_PYTHON_3_11: &str = "3.11.14";
48pub const LATEST_PYTHON_3_10: &str = "3.10.19";
49
50pub fn build_vendor_links_url() -> String {
53 env::var(EnvVars::UV_TEST_PACKSE_INDEX)
54 .map(|url| format!("{}/vendor/", url.trim_end_matches('/')))
55 .ok()
56 .unwrap_or(format!(
57 "https://astral-sh.github.io/packse/{PACKSE_VERSION}/vendor/"
58 ))
59}
60
61pub fn packse_index_url() -> String {
62 env::var(EnvVars::UV_TEST_PACKSE_INDEX)
63 .map(|url| format!("{}/simple-html/", url.trim_end_matches('/')))
64 .ok()
65 .unwrap_or(format!(
66 "https://astral-sh.github.io/packse/{PACKSE_VERSION}/simple-html/"
67 ))
68}
69
70#[macro_export]
77macro_rules! test_context {
78 ($python_version:expr) => {
79 $crate::TestContext::new_with_bin(
80 $python_version,
81 std::path::PathBuf::from(env!("CARGO_BIN_EXE_uv")),
82 )
83 };
84}
85
86#[macro_export]
93macro_rules! test_context_with_versions {
94 ($python_versions:expr) => {
95 $crate::TestContext::new_with_versions_and_bin(
96 $python_versions,
97 std::path::PathBuf::from(env!("CARGO_BIN_EXE_uv")),
98 )
99 };
100}
101
102#[macro_export]
107macro_rules! get_bin {
108 () => {
109 std::path::PathBuf::from(env!("CARGO_BIN_EXE_uv"))
110 };
111}
112
113#[doc(hidden)] pub const INSTA_FILTERS: &[(&str, &str)] = &[
115 (r"--cache-dir [^\s]+", "--cache-dir [CACHE_DIR]"),
116 (r"(\s|\()(\d+m )?(\d+\.)?\d+(ms|s)", "$1[TIME]"),
118 (r"(\s|\()(\d+\.)?\d+([KM]i)?B", "$1[SIZE]"),
120 (r"tv_sec: \d+", "tv_sec: [TIME]"),
122 (r"tv_nsec: \d+", "tv_nsec: [TIME]"),
123 (r"\\([\w\d]|\.)", "/$1"),
125 (r"uv\.exe", "uv"),
126 (
128 r"uv(-.*)? \d+\.\d+\.\d+(-(alpha|beta|rc)\.\d+)?(\+\d+)?( \([^)]*\))?",
129 r"uv [VERSION] ([COMMIT] DATE)",
130 ),
131 (r"([^\s])[ \t]+(\r?\n)", "$1$2"),
133];
134
135pub struct TestContext {
142 pub root: ChildPath,
143 pub temp_dir: ChildPath,
144 pub cache_dir: ChildPath,
145 pub python_dir: ChildPath,
146 pub home_dir: ChildPath,
147 pub user_config_dir: ChildPath,
148 pub bin_dir: ChildPath,
149 pub venv: ChildPath,
150 pub workspace_root: PathBuf,
151
152 pub python_version: Option<PythonVersion>,
154
155 pub python_versions: Vec<(PythonVersion, PathBuf)>,
157
158 uv_bin: PathBuf,
160
161 filters: Vec<(String, String)>,
163
164 extra_env: Vec<(OsString, OsString)>,
166
167 #[allow(dead_code)]
168 _root: tempfile::TempDir,
169
170 #[allow(dead_code)]
173 _extra_tempdirs: Vec<tempfile::TempDir>,
174}
175
176impl TestContext {
177 pub fn new_with_bin(python_version: &str, uv_bin: PathBuf) -> Self {
181 let new = Self::new_with_versions_and_bin(&[python_version], uv_bin);
182 new.create_venv();
183 new
184 }
185
186 #[must_use]
188 pub fn with_exclude_newer(mut self, exclude_newer: &str) -> Self {
189 self.extra_env
190 .push((EnvVars::UV_EXCLUDE_NEWER.into(), exclude_newer.into()));
191 self
192 }
193
194 #[must_use]
196 pub fn with_http_timeout(mut self, http_timeout: &str) -> Self {
197 self.extra_env
198 .push((EnvVars::UV_HTTP_TIMEOUT.into(), http_timeout.into()));
199 self
200 }
201
202 #[must_use]
204 pub fn with_concurrent_installs(mut self, concurrent_installs: &str) -> Self {
205 self.extra_env.push((
206 EnvVars::UV_CONCURRENT_INSTALLS.into(),
207 concurrent_installs.into(),
208 ));
209 self
210 }
211
212 #[must_use]
217 pub fn with_filtered_counts(mut self) -> Self {
218 for verb in &[
219 "Resolved",
220 "Prepared",
221 "Installed",
222 "Uninstalled",
223 "Audited",
224 ] {
225 self.filters.push((
226 format!("{verb} \\d+ packages?"),
227 format!("{verb} [N] packages"),
228 ));
229 }
230 self.filters.push((
231 "Removed \\d+ files?".to_string(),
232 "Removed [N] files".to_string(),
233 ));
234 self
235 }
236
237 #[must_use]
239 pub fn with_filtered_cache_size(mut self) -> Self {
240 self.filters
242 .push((r"(?m)^\d+\n".to_string(), "[SIZE]\n".to_string()));
243 self.filters.push((
245 r"(?m)^\d+(\.\d+)? [KMGT]i?B\n".to_string(),
246 "[SIZE]\n".to_string(),
247 ));
248 self
249 }
250
251 #[must_use]
253 pub fn with_filtered_missing_file_error(mut self) -> Self {
254 self.filters.push((
257 r"[^:\n]* \(os error 2\)".to_string(),
258 " [OS ERROR 2]".to_string(),
259 ));
260 self.filters.push((
264 r"[^:\n]* \(os error 3\)".to_string(),
265 " [OS ERROR 2]".to_string(),
266 ));
267 self
268 }
269
270 #[must_use]
273 pub fn with_filtered_exe_suffix(mut self) -> Self {
274 self.filters
275 .push((regex::escape(env::consts::EXE_SUFFIX), String::new()));
276 self
277 }
278
279 #[must_use]
281 pub fn with_filtered_python_sources(mut self) -> Self {
282 self.filters.push((
283 "virtual environments, managed installations, or search path".to_string(),
284 "[PYTHON SOURCES]".to_string(),
285 ));
286 self.filters.push((
287 "virtual environments, managed installations, search path, or registry".to_string(),
288 "[PYTHON SOURCES]".to_string(),
289 ));
290 self.filters.push((
291 "virtual environments, search path, or registry".to_string(),
292 "[PYTHON SOURCES]".to_string(),
293 ));
294 self.filters.push((
295 "virtual environments, registry, or search path".to_string(),
296 "[PYTHON SOURCES]".to_string(),
297 ));
298 self.filters.push((
299 "virtual environments or search path".to_string(),
300 "[PYTHON SOURCES]".to_string(),
301 ));
302 self.filters.push((
303 "managed installations or search path".to_string(),
304 "[PYTHON SOURCES]".to_string(),
305 ));
306 self.filters.push((
307 "managed installations, search path, or registry".to_string(),
308 "[PYTHON SOURCES]".to_string(),
309 ));
310 self.filters.push((
311 "search path or registry".to_string(),
312 "[PYTHON SOURCES]".to_string(),
313 ));
314 self.filters.push((
315 "registry or search path".to_string(),
316 "[PYTHON SOURCES]".to_string(),
317 ));
318 self.filters
319 .push(("search path".to_string(), "[PYTHON SOURCES]".to_string()));
320 self
321 }
322
323 #[must_use]
326 pub fn with_filtered_python_names(mut self) -> Self {
327 for name in ["python", "pypy"] {
328 let suffix = if cfg!(windows) {
331 let exe_suffix = regex::escape(env::consts::EXE_SUFFIX);
335 format!(r"(\d\.\d+|\d)?{exe_suffix}")
336 } else {
337 if name == "python" {
339 r"(\d\.\d+|\d)?(t|d|td)?".to_string()
341 } else {
342 r"(\d\.\d+|\d)(t|d|td)?".to_string()
344 }
345 };
346
347 self.filters.push((
348 format!(r"[\\/]{name}{suffix}"),
351 format!("/[{}]", name.to_uppercase()),
352 ));
353 }
354
355 self
356 }
357
358 #[must_use]
361 pub fn with_filtered_virtualenv_bin(mut self) -> Self {
362 self.filters.push((
363 format!(
364 r"[\\/]{}[\\/]",
365 venv_bin_path(PathBuf::new()).to_string_lossy()
366 ),
367 "/[BIN]/".to_string(),
368 ));
369 self.filters.push((
370 format!(r"[\\/]{}", venv_bin_path(PathBuf::new()).to_string_lossy()),
371 "/[BIN]".to_string(),
372 ));
373 self
374 }
375
376 #[must_use]
380 pub fn with_filtered_python_install_bin(mut self) -> Self {
381 let suffix = if cfg!(windows) {
384 let exe_suffix = regex::escape(env::consts::EXE_SUFFIX);
385 format!(r"(\d\.\d+|\d)?{exe_suffix}")
387 } else {
388 r"\d\.\d+|\d".to_string()
390 };
391
392 if cfg!(unix) {
393 self.filters.push((
394 format!(r"[\\/]bin/python({suffix})"),
395 "/[INSTALL-BIN]/python$1".to_string(),
396 ));
397 self.filters.push((
398 format!(r"[\\/]bin/pypy({suffix})"),
399 "/[INSTALL-BIN]/pypy$1".to_string(),
400 ));
401 } else {
402 self.filters.push((
403 format!(r"[\\/]python({suffix})"),
404 "/[INSTALL-BIN]/python$1".to_string(),
405 ));
406 self.filters.push((
407 format!(r"[\\/]pypy({suffix})"),
408 "/[INSTALL-BIN]/pypy$1".to_string(),
409 ));
410 }
411 self
412 }
413
414 #[must_use]
420 pub fn with_pyvenv_cfg_filters(mut self) -> Self {
421 let added_filters = [
422 (r"home = .+".to_string(), "home = [PYTHON_HOME]".to_string()),
423 (
424 r"uv = \d+\.\d+\.\d+(-(alpha|beta|rc)\.\d+)?(\+\d+)?".to_string(),
425 "uv = [UV_VERSION]".to_string(),
426 ),
427 (
428 r"extends-environment = .+".to_string(),
429 "extends-environment = [PARENT_VENV]".to_string(),
430 ),
431 ];
432 for filter in added_filters {
433 self.filters.insert(0, filter);
434 }
435 self
436 }
437
438 #[must_use]
441 pub fn with_filtered_python_symlinks(mut self) -> Self {
442 for (version, executable) in &self.python_versions {
443 if fs_err::symlink_metadata(executable).unwrap().is_symlink() {
444 self.filters.extend(
445 Self::path_patterns(executable.read_link().unwrap())
446 .into_iter()
447 .map(|pattern| (format! {" -> {pattern}"}, String::new())),
448 );
449 }
450 self.filters.push((
452 regex::escape(&format!(" -> [PYTHON-{version}]")),
453 String::new(),
454 ));
455 }
456 self
457 }
458
459 #[must_use]
461 pub fn with_filtered_path(mut self, path: &Path, name: &str) -> Self {
462 for pattern in Self::path_patterns(path)
466 .into_iter()
467 .map(|pattern| (pattern, format!("[{name}]/")))
468 {
469 self.filters.insert(0, pattern);
470 }
471 self
472 }
473
474 #[inline]
482 #[must_use]
483 pub fn with_filtered_link_mode_warning(mut self) -> Self {
484 let pattern = "warning: Failed to hardlink files; .*\n.*\n.*\n";
485 self.filters.push((pattern.to_string(), String::new()));
486 self
487 }
488
489 #[inline]
491 #[must_use]
492 pub fn with_filtered_not_executable(mut self) -> Self {
493 let pattern = if cfg!(unix) {
494 r"Permission denied \(os error 13\)"
495 } else {
496 r"\%1 is not a valid Win32 application. \(os error 193\)"
497 };
498 self.filters
499 .push((pattern.to_string(), "[PERMISSION DENIED]".to_string()));
500 self
501 }
502
503 #[must_use]
505 pub fn with_filtered_python_keys(mut self) -> Self {
506 let platform_re = r"(?x)
508 ( # We capture the group before the platform
509 (?:cpython|pypy|graalpy)# Python implementation
510 -
511 \d+\.\d+ # Major and minor version
512 (?: # The patch version is handled separately
513 \.
514 (?:
515 \[X\] # A previously filtered patch version [X]
516 | # OR
517 \[LATEST\] # A previously filtered latest patch version [LATEST]
518 | # OR
519 \d+ # An actual patch version
520 )
521 )? # (we allow the patch version to be missing entirely, e.g., in a request)
522 (?:(?:a|b|rc)[0-9]+)? # Pre-release version component, e.g., `a6` or `rc2`
523 (?:[td])? # A short variant, such as `t` (for freethreaded) or `d` (for debug)
524 (?:(\+[a-z]+)+)? # A long variant, such as `+freethreaded` or `+freethreaded+debug`
525 )
526 -
527 [a-z0-9]+ # Operating system (e.g., 'macos')
528 -
529 [a-z0-9_]+ # Architecture (e.g., 'aarch64')
530 -
531 [a-z]+ # Libc (e.g., 'none')
532";
533 self.filters
534 .push((platform_re.to_string(), "$1-[PLATFORM]".to_string()));
535 self
536 }
537
538 #[must_use]
540 pub fn with_filtered_latest_python_versions(mut self) -> Self {
541 for (minor, patch) in [
544 ("3.15", LATEST_PYTHON_3_15.strip_prefix("3.15.").unwrap()),
545 ("3.14", LATEST_PYTHON_3_14.strip_prefix("3.14.").unwrap()),
546 ("3.13", LATEST_PYTHON_3_13.strip_prefix("3.13.").unwrap()),
547 ("3.12", LATEST_PYTHON_3_12.strip_prefix("3.12.").unwrap()),
548 ("3.11", LATEST_PYTHON_3_11.strip_prefix("3.11.").unwrap()),
549 ("3.10", LATEST_PYTHON_3_10.strip_prefix("3.10.").unwrap()),
550 ] {
551 let pattern = format!(r"(\b){minor}\.{patch}(\b)");
553 let replacement = format!("${{1}}{minor}.[LATEST]${{2}}");
554 self.filters.push((pattern, replacement));
555 }
556 self
557 }
558
559 #[must_use]
561 pub fn with_filtered_windows_temp_dir(mut self) -> Self {
562 let pattern = regex::escape(
563 &self
564 .temp_dir
565 .simplified_display()
566 .to_string()
567 .replace('/', "\\"),
568 );
569 self.filters.push((pattern, "[TEMP_DIR]".to_string()));
570 self
571 }
572
573 #[must_use]
575 pub fn with_filtered_compiled_file_count(mut self) -> Self {
576 self.filters.push((
577 r"compiled \d+ files".to_string(),
578 "compiled [COUNT] files".to_string(),
579 ));
580 self
581 }
582
583 #[must_use]
585 pub fn with_cyclonedx_filters(mut self) -> Self {
586 self.filters.push((
587 r"urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}".to_string(),
588 "[SERIAL_NUMBER]".to_string(),
589 ));
590 self.filters.push((
591 r#""timestamp": "[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]+Z""#
592 .to_string(),
593 r#""timestamp": "[TIMESTAMP]""#.to_string(),
594 ));
595 self.filters.push((
596 r#""name": "uv",\s*"version": "\d+\.\d+\.\d+(-(alpha|beta|rc)\.\d+)?(\+\d+)?""#
597 .to_string(),
598 r#""name": "uv",
599 "version": "[VERSION]""#
600 .to_string(),
601 ));
602 self
603 }
604
605 #[must_use]
607 pub fn with_collapsed_whitespace(mut self) -> Self {
608 self.filters.push((r"[ \t]+".to_string(), " ".to_string()));
609 self
610 }
611
612 #[must_use]
614 pub fn with_python_download_cache(mut self) -> Self {
615 self.extra_env.push((
616 EnvVars::UV_PYTHON_CACHE_DIR.into(),
617 env::var_os(EnvVars::UV_PYTHON_CACHE_DIR).unwrap_or_else(|| {
619 uv_cache::Cache::from_settings(false, None)
620 .unwrap()
621 .bucket(CacheBucket::Python)
622 .into()
623 }),
624 ));
625 self
626 }
627
628 #[must_use]
629 pub fn with_empty_python_install_mirror(mut self) -> Self {
630 self.extra_env.push((
631 EnvVars::UV_PYTHON_INSTALL_MIRROR.into(),
632 String::new().into(),
633 ));
634 self
635 }
636
637 #[must_use]
639 pub fn with_managed_python_dirs(mut self) -> Self {
640 let managed = self.temp_dir.join("managed");
641
642 self.extra_env.push((
643 EnvVars::UV_PYTHON_BIN_DIR.into(),
644 self.bin_dir.as_os_str().to_owned(),
645 ));
646 self.extra_env
647 .push((EnvVars::UV_PYTHON_INSTALL_DIR.into(), managed.into()));
648 self.extra_env
649 .push((EnvVars::UV_PYTHON_DOWNLOADS.into(), "automatic".into()));
650
651 self
652 }
653
654 #[must_use]
655 pub fn with_versions_as_managed(mut self, versions: &[&str]) -> Self {
656 self.extra_env.push((
657 EnvVars::UV_INTERNAL__TEST_PYTHON_MANAGED.into(),
658 versions.iter().join(" ").into(),
659 ));
660
661 self
662 }
663
664 #[must_use]
666 pub fn with_filter(mut self, filter: (impl Into<String>, impl Into<String>)) -> Self {
667 self.filters.push((filter.0.into(), filter.1.into()));
668 self
669 }
670
671 #[must_use]
673 pub fn with_unset_git_credential_helper(self) -> Self {
674 let git_config = self.home_dir.child(".gitconfig");
675 git_config
676 .write_str(indoc! {r"
677 [credential]
678 helper =
679 "})
680 .expect("Failed to unset git credential helper");
681
682 self
683 }
684
685 #[must_use]
687 pub fn clear_filters(mut self) -> Self {
688 self.filters.clear();
689 self
690 }
691
692 pub fn with_cache_on_cow_fs(self) -> anyhow::Result<Option<Self>> {
697 let Some(dir) = env::var(EnvVars::UV_INTERNAL__TEST_COW_FS).ok() else {
698 return Ok(None);
699 };
700 self.with_cache_on_fs(&dir, "COW_FS").map(Some)
701 }
702
703 pub fn with_cache_on_alt_fs(self) -> anyhow::Result<Option<Self>> {
708 let Some(dir) = env::var(EnvVars::UV_INTERNAL__TEST_ALT_FS).ok() else {
709 return Ok(None);
710 };
711 self.with_cache_on_fs(&dir, "ALT_FS").map(Some)
712 }
713
714 pub fn with_cache_on_nocow_fs(self) -> anyhow::Result<Option<Self>> {
719 let Some(dir) = env::var(EnvVars::UV_INTERNAL__TEST_NOCOW_FS).ok() else {
720 return Ok(None);
721 };
722 self.with_cache_on_fs(&dir, "NOCOW_FS").map(Some)
723 }
724
725 pub fn with_working_dir_on_cow_fs(self) -> anyhow::Result<Option<Self>> {
732 let Some(dir) = env::var(EnvVars::UV_INTERNAL__TEST_COW_FS).ok() else {
733 return Ok(None);
734 };
735 self.with_working_dir_on_fs(&dir, "COW_FS").map(Some)
736 }
737
738 pub fn with_working_dir_on_alt_fs(self) -> anyhow::Result<Option<Self>> {
745 let Some(dir) = env::var(EnvVars::UV_INTERNAL__TEST_ALT_FS).ok() else {
746 return Ok(None);
747 };
748 self.with_working_dir_on_fs(&dir, "ALT_FS").map(Some)
749 }
750
751 pub fn with_working_dir_on_nocow_fs(self) -> anyhow::Result<Option<Self>> {
758 let Some(dir) = env::var(EnvVars::UV_INTERNAL__TEST_NOCOW_FS).ok() else {
759 return Ok(None);
760 };
761 self.with_working_dir_on_fs(&dir, "NOCOW_FS").map(Some)
762 }
763
764 fn with_cache_on_fs(mut self, dir: &str, name: &str) -> anyhow::Result<Self> {
765 fs_err::create_dir_all(dir)?;
766 let tmp = tempfile::TempDir::new_in(dir)?;
767 self.cache_dir = ChildPath::new(tmp.path()).child("cache");
768 fs_err::create_dir_all(&self.cache_dir)?;
769 let replacement = format!("[{name}]/[CACHE_DIR]/");
770 self.filters.extend(
771 Self::path_patterns(&self.cache_dir)
772 .into_iter()
773 .map(|pattern| (pattern, replacement.clone())),
774 );
775 self._extra_tempdirs.push(tmp);
776 Ok(self)
777 }
778
779 fn with_working_dir_on_fs(mut self, dir: &str, name: &str) -> anyhow::Result<Self> {
780 fs_err::create_dir_all(dir)?;
781 let tmp = tempfile::TempDir::new_in(dir)?;
782 self.temp_dir = ChildPath::new(tmp.path()).child("temp");
783 fs_err::create_dir_all(&self.temp_dir)?;
784 let canonical_temp_dir = self.temp_dir.canonicalize()?;
787 self.venv = ChildPath::new(canonical_temp_dir.join(".venv"));
788 let temp_replacement = format!("[{name}]/[TEMP_DIR]/");
789 self.filters.extend(
790 Self::path_patterns(&self.temp_dir)
791 .into_iter()
792 .map(|pattern| (pattern, temp_replacement.clone())),
793 );
794 let venv_replacement = format!("[{name}]/[VENV]/");
795 self.filters.extend(
796 Self::path_patterns(&self.venv)
797 .into_iter()
798 .map(|pattern| (pattern, venv_replacement.clone())),
799 );
800 self._extra_tempdirs.push(tmp);
801 Ok(self)
802 }
803
804 pub fn test_bucket_dir() -> PathBuf {
813 std::env::temp_dir()
814 .simple_canonicalize()
815 .expect("failed to canonicalize temp dir")
816 .join("uv")
817 .join("tests")
818 }
819
820 pub fn new_with_versions_and_bin(python_versions: &[&str], uv_bin: PathBuf) -> Self {
827 let bucket = Self::test_bucket_dir();
828 fs_err::create_dir_all(&bucket).expect("Failed to create test bucket");
829
830 let root = tempfile::TempDir::new_in(bucket).expect("Failed to create test root directory");
831
832 fs_err::create_dir_all(root.path().join(".git"))
835 .expect("Failed to create `.git` placeholder in test root directory");
836
837 let temp_dir = ChildPath::new(root.path()).child("temp");
838 fs_err::create_dir_all(&temp_dir).expect("Failed to create test working directory");
839
840 let cache_dir = ChildPath::new(root.path()).child("cache");
841 fs_err::create_dir_all(&cache_dir).expect("Failed to create test cache directory");
842
843 let python_dir = ChildPath::new(root.path()).child("python");
844 fs_err::create_dir_all(&python_dir).expect("Failed to create test Python directory");
845
846 let bin_dir = ChildPath::new(root.path()).child("bin");
847 fs_err::create_dir_all(&bin_dir).expect("Failed to create test bin directory");
848
849 if cfg!(not(feature = "git")) {
851 Self::disallow_git_cli(&bin_dir).expect("Failed to setup disallowed `git` command");
852 }
853
854 let home_dir = ChildPath::new(root.path()).child("home");
855 fs_err::create_dir_all(&home_dir).expect("Failed to create test home directory");
856
857 let user_config_dir = if cfg!(windows) {
858 ChildPath::new(home_dir.path())
859 } else {
860 ChildPath::new(home_dir.path()).child(".config")
861 };
862
863 let canonical_temp_dir = temp_dir.canonicalize().unwrap();
865 let venv = ChildPath::new(canonical_temp_dir.join(".venv"));
866
867 let python_version = python_versions
868 .first()
869 .map(|version| PythonVersion::from_str(version).unwrap());
870
871 let site_packages = python_version
872 .as_ref()
873 .map(|version| site_packages_path(&venv, &format!("python{version}")));
874
875 let workspace_root = Path::new(&env::var(EnvVars::CARGO_MANIFEST_DIR).unwrap())
878 .parent()
879 .expect("CARGO_MANIFEST_DIR should be nested in workspace")
880 .parent()
881 .expect("CARGO_MANIFEST_DIR should be doubly nested in workspace")
882 .to_path_buf();
883
884 let download_list = ManagedPythonDownloadList::new_only_embedded().unwrap();
885
886 let python_versions: Vec<_> = python_versions
887 .iter()
888 .map(|version| PythonVersion::from_str(version).unwrap())
889 .zip(
890 python_installations_for_versions(&temp_dir, python_versions, &download_list)
891 .expect("Failed to find test Python versions"),
892 )
893 .collect();
894
895 if cfg!(unix) {
898 for (version, executable) in &python_versions {
899 let parent = python_dir.child(version.to_string());
900 parent.create_dir_all().unwrap();
901 parent.child("python3").symlink_to_file(executable).unwrap();
902 }
903 }
904
905 let mut filters = Vec::new();
906
907 filters.extend(
908 Self::path_patterns(&uv_bin)
909 .into_iter()
910 .map(|pattern| (pattern, "[UV]".to_string())),
911 );
912
913 if cfg!(windows) {
915 filters.push((" --link-mode <LINK_MODE>".to_string(), String::new()));
916 filters.push((r#"link-mode = "copy"\n"#.to_string(), String::new()));
917 filters.push((r"exit code: ".to_string(), "exit status: ".to_string()));
919 }
920
921 for (version, executable) in &python_versions {
922 filters.extend(
924 Self::path_patterns(executable)
925 .into_iter()
926 .map(|pattern| (pattern, format!("[PYTHON-{version}]"))),
927 );
928
929 filters.extend(
931 Self::path_patterns(python_dir.join(version.to_string()))
932 .into_iter()
933 .map(|pattern| {
934 (
935 format!("{pattern}[a-zA-Z0-9]*"),
936 format!("[PYTHON-{version}]"),
937 )
938 }),
939 );
940
941 if version.patch().is_none() {
944 filters.push((
945 format!(r"({})\.\d+", regex::escape(version.to_string().as_str())),
946 "$1.[X]".to_string(),
947 ));
948 }
949 }
950
951 filters.extend(
952 Self::path_patterns(&bin_dir)
953 .into_iter()
954 .map(|pattern| (pattern, "[BIN]/".to_string())),
955 );
956 filters.extend(
957 Self::path_patterns(&cache_dir)
958 .into_iter()
959 .map(|pattern| (pattern, "[CACHE_DIR]/".to_string())),
960 );
961 if let Some(ref site_packages) = site_packages {
962 filters.extend(
963 Self::path_patterns(site_packages)
964 .into_iter()
965 .map(|pattern| (pattern, "[SITE_PACKAGES]/".to_string())),
966 );
967 }
968 filters.extend(
969 Self::path_patterns(&venv)
970 .into_iter()
971 .map(|pattern| (pattern, "[VENV]/".to_string())),
972 );
973
974 if let Some(site_packages) = site_packages {
976 filters.push((
977 Self::path_pattern(
978 site_packages
979 .strip_prefix(&canonical_temp_dir)
980 .expect("The test site-packages directory is always in the tempdir"),
981 ),
982 "[SITE_PACKAGES]/".to_string(),
983 ));
984 }
985
986 filters.push((
988 r"[\\/]lib[\\/]python\d+\.\d+[\\/]".to_string(),
989 "/[PYTHON-LIB]/".to_string(),
990 ));
991 filters.push((r"[\\/]Lib[\\/]".to_string(), "/[PYTHON-LIB]/".to_string()));
992
993 filters.extend(
994 Self::path_patterns(&temp_dir)
995 .into_iter()
996 .map(|pattern| (pattern, "[TEMP_DIR]/".to_string())),
997 );
998 filters.extend(
999 Self::path_patterns(&python_dir)
1000 .into_iter()
1001 .map(|pattern| (pattern, "[PYTHON_DIR]/".to_string())),
1002 );
1003 let mut uv_user_config_dir = PathBuf::from(user_config_dir.path());
1004 uv_user_config_dir.push("uv");
1005 filters.extend(
1006 Self::path_patterns(&uv_user_config_dir)
1007 .into_iter()
1008 .map(|pattern| (pattern, "[UV_USER_CONFIG_DIR]/".to_string())),
1009 );
1010 filters.extend(
1011 Self::path_patterns(&user_config_dir)
1012 .into_iter()
1013 .map(|pattern| (pattern, "[USER_CONFIG_DIR]/".to_string())),
1014 );
1015 filters.extend(
1016 Self::path_patterns(&home_dir)
1017 .into_iter()
1018 .map(|pattern| (pattern, "[HOME]/".to_string())),
1019 );
1020 filters.extend(
1021 Self::path_patterns(&workspace_root)
1022 .into_iter()
1023 .map(|pattern| (pattern, "[WORKSPACE]/".to_string())),
1024 );
1025
1026 filters.push((
1028 r"Activate with: (.*)\\Scripts\\activate".to_string(),
1029 "Activate with: source $1/[BIN]/activate".to_string(),
1030 ));
1031 filters.push((
1032 r"Activate with: Scripts\\activate".to_string(),
1033 "Activate with: source [BIN]/activate".to_string(),
1034 ));
1035 filters.push((
1036 r"Activate with: source (.*/|)bin/activate(?:\.\w+)?".to_string(),
1037 "Activate with: source $1[BIN]/activate".to_string(),
1038 ));
1039
1040 filters.push((r"(\\|\/)\.tmp.*(\\|\/)".to_string(), "/[TMP]/".to_string()));
1043
1044 filters.push((r"file:///".to_string(), "file://".to_string()));
1046
1047 filters.push((r"\\\\\?\\".to_string(), String::new()));
1049
1050 filters.push((
1053 format!("https://astral-sh.github.io/packse/{PACKSE_VERSION}"),
1054 "https://astral-sh.github.io/packse/PACKSE_VERSION".to_string(),
1055 ));
1056 if let Ok(packse_test_index) = env::var(EnvVars::UV_TEST_PACKSE_INDEX) {
1058 filters.push((
1059 packse_test_index.trim_end_matches('/').to_string(),
1060 "https://astral-sh.github.io/packse/PACKSE_VERSION".to_string(),
1061 ));
1062 }
1063 filters.push((r"127\.0\.0\.1:\d*".to_string(), "[LOCALHOST]".to_string()));
1065 filters.push((
1067 format!(
1068 r#"requires = \["uv_build>={},<[0-9.]+"\]"#,
1069 uv_version::version()
1070 ),
1071 r#"requires = ["uv_build>=[CURRENT_VERSION],<[NEXT_BREAKING]"]"#.to_string(),
1072 ));
1073 filters.push((
1075 r"environments-v(\d+)[\\/](\w+)-[a-z0-9]+".to_string(),
1076 "environments-v$1/$2-[HASH]".to_string(),
1077 ));
1078 filters.push((
1080 r"archive-v(\d+)[\\/][A-Za-z0-9\-\_]+".to_string(),
1081 "archive-v$1/[HASH]".to_string(),
1082 ));
1083
1084 Self {
1085 root: ChildPath::new(root.path()),
1086 temp_dir,
1087 cache_dir,
1088 python_dir,
1089 home_dir,
1090 user_config_dir,
1091 bin_dir,
1092 venv,
1093 workspace_root,
1094 python_version,
1095 python_versions,
1096 uv_bin,
1097 filters,
1098 extra_env: vec![],
1099 _root: root,
1100 _extra_tempdirs: vec![],
1101 }
1102 }
1103
1104 pub fn command(&self) -> Command {
1106 let mut command = self.new_command();
1107 self.add_shared_options(&mut command, true);
1108 command
1109 }
1110
1111 pub fn disallow_git_cli(bin_dir: &Path) -> std::io::Result<()> {
1112 let contents = r"#!/bin/sh
1113 echo 'error: `git` operations are not allowed — are you missing a cfg for the `git` feature?' >&2
1114 exit 127";
1115 let git = bin_dir.join(format!("git{}", env::consts::EXE_SUFFIX));
1116 fs_err::write(&git, contents)?;
1117
1118 #[cfg(unix)]
1119 {
1120 use std::os::unix::fs::PermissionsExt;
1121 let mut perms = fs_err::metadata(&git)?.permissions();
1122 perms.set_mode(0o755);
1123 fs_err::set_permissions(&git, perms)?;
1124 }
1125
1126 Ok(())
1127 }
1128
1129 #[must_use]
1134 pub fn with_git_lfs_config(mut self) -> Self {
1135 let git_lfs_config = self.root.child(".gitconfig");
1136 git_lfs_config
1137 .write_str(indoc! {r#"
1138 [filter "lfs"]
1139 clean = git-lfs clean -- %f
1140 smudge = git-lfs smudge -- %f
1141 process = git-lfs filter-process
1142 required = true
1143 "#})
1144 .expect("Failed to setup `git-lfs` filters");
1145
1146 self.extra_env.push((
1149 EnvVars::GIT_CONFIG_GLOBAL.into(),
1150 git_lfs_config.as_os_str().into(),
1151 ));
1152 self
1153 }
1154
1155 pub fn add_shared_options(&self, command: &mut Command, activate_venv: bool) {
1166 self.add_shared_args(command);
1167 self.add_shared_env(command, activate_venv);
1168 }
1169
1170 pub fn add_shared_args(&self, command: &mut Command) {
1172 command.arg("--cache-dir").arg(self.cache_dir.path());
1173 }
1174
1175 pub fn add_shared_env(&self, command: &mut Command, activate_venv: bool) {
1177 let path = env::join_paths(std::iter::once(self.bin_dir.to_path_buf()).chain(
1179 env::split_paths(&env::var(EnvVars::PATH).unwrap_or_default()),
1180 ))
1181 .unwrap();
1182
1183 if cfg!(not(windows)) {
1186 command.env(EnvVars::SHELL, "bash");
1187 }
1188
1189 command
1190 .env_remove(EnvVars::VIRTUAL_ENV)
1192 .env(EnvVars::UV_NO_WRAP, "1")
1194 .env(EnvVars::COLUMNS, "100")
1197 .env(EnvVars::PATH, path)
1198 .env(EnvVars::HOME, self.home_dir.as_os_str())
1199 .env(EnvVars::APPDATA, self.home_dir.as_os_str())
1200 .env(EnvVars::USERPROFILE, self.home_dir.as_os_str())
1201 .env(
1202 EnvVars::XDG_CONFIG_DIRS,
1203 self.home_dir.join("config").as_os_str(),
1204 )
1205 .env(
1206 EnvVars::XDG_DATA_HOME,
1207 self.home_dir.join("data").as_os_str(),
1208 )
1209 .env(EnvVars::UV_PYTHON_INSTALL_DIR, "")
1210 .env(EnvVars::UV_PYTHON_DOWNLOADS, "never")
1212 .env(EnvVars::UV_TEST_PYTHON_PATH, self.python_path())
1213 .env(EnvVars::UV_EXCLUDE_NEWER, EXCLUDE_NEWER)
1215 .env(EnvVars::UV_TEST_CURRENT_TIMESTAMP, EXCLUDE_NEWER)
1216 .env(EnvVars::UV_PYTHON_INSTALL_REGISTRY, "0")
1219 .env(EnvVars::UV_TEST_NO_CLI_PROGRESS, "1")
1222 .env(EnvVars::GIT_CEILING_DIRECTORIES, self.root.path())
1236 .current_dir(self.temp_dir.path());
1237
1238 for (key, value) in &self.extra_env {
1239 command.env(key, value);
1240 }
1241
1242 if activate_venv {
1243 command.env(EnvVars::VIRTUAL_ENV, self.venv.as_os_str());
1244 }
1245
1246 if cfg!(unix) {
1247 command.env(EnvVars::LC_ALL, "C");
1249 }
1250 }
1251
1252 pub fn pip_compile(&self) -> Command {
1254 let mut command = self.new_command();
1255 command.arg("pip").arg("compile");
1256 self.add_shared_options(&mut command, true);
1257 command
1258 }
1259
1260 pub fn pip_sync(&self) -> Command {
1262 let mut command = self.new_command();
1263 command.arg("pip").arg("sync");
1264 self.add_shared_options(&mut command, true);
1265 command
1266 }
1267
1268 pub fn pip_show(&self) -> Command {
1269 let mut command = self.new_command();
1270 command.arg("pip").arg("show");
1271 self.add_shared_options(&mut command, true);
1272 command
1273 }
1274
1275 pub fn pip_freeze(&self) -> Command {
1277 let mut command = self.new_command();
1278 command.arg("pip").arg("freeze");
1279 self.add_shared_options(&mut command, true);
1280 command
1281 }
1282
1283 pub fn pip_check(&self) -> Command {
1285 let mut command = self.new_command();
1286 command.arg("pip").arg("check");
1287 self.add_shared_options(&mut command, true);
1288 command
1289 }
1290
1291 pub fn pip_list(&self) -> Command {
1292 let mut command = self.new_command();
1293 command.arg("pip").arg("list");
1294 self.add_shared_options(&mut command, true);
1295 command
1296 }
1297
1298 pub fn venv(&self) -> Command {
1300 let mut command = self.new_command();
1301 command.arg("venv");
1302 self.add_shared_options(&mut command, false);
1303 command
1304 }
1305
1306 pub fn pip_install(&self) -> Command {
1308 let mut command = self.new_command();
1309 command.arg("pip").arg("install");
1310 self.add_shared_options(&mut command, true);
1311 command
1312 }
1313
1314 pub fn pip_uninstall(&self) -> Command {
1316 let mut command = self.new_command();
1317 command.arg("pip").arg("uninstall");
1318 self.add_shared_options(&mut command, true);
1319 command
1320 }
1321
1322 pub fn pip_tree(&self) -> Command {
1324 let mut command = self.new_command();
1325 command.arg("pip").arg("tree");
1326 self.add_shared_options(&mut command, true);
1327 command
1328 }
1329
1330 pub fn pip_debug(&self) -> Command {
1332 let mut command = self.new_command();
1333 command.arg("pip").arg("debug");
1334 self.add_shared_options(&mut command, true);
1335 command
1336 }
1337
1338 pub fn help(&self) -> Command {
1340 let mut command = self.new_command();
1341 command.arg("help");
1342 self.add_shared_env(&mut command, false);
1343 command
1344 }
1345
1346 pub fn init(&self) -> Command {
1349 let mut command = self.new_command();
1350 command.arg("init");
1351 self.add_shared_options(&mut command, false);
1352 command
1353 }
1354
1355 pub fn sync(&self) -> Command {
1357 let mut command = self.new_command();
1358 command.arg("sync");
1359 self.add_shared_options(&mut command, false);
1360 command
1361 }
1362
1363 pub fn lock(&self) -> Command {
1365 let mut command = self.new_command();
1366 command.arg("lock");
1367 self.add_shared_options(&mut command, false);
1368 command
1369 }
1370
1371 pub fn workspace_metadata(&self) -> Command {
1373 let mut command = self.new_command();
1374 command.arg("workspace").arg("metadata");
1375 self.add_shared_options(&mut command, false);
1376 command
1377 }
1378
1379 pub fn workspace_dir(&self) -> Command {
1381 let mut command = self.new_command();
1382 command.arg("workspace").arg("dir");
1383 self.add_shared_options(&mut command, false);
1384 command
1385 }
1386
1387 pub fn workspace_list(&self) -> Command {
1389 let mut command = self.new_command();
1390 command.arg("workspace").arg("list");
1391 self.add_shared_options(&mut command, false);
1392 command
1393 }
1394
1395 pub fn export(&self) -> Command {
1397 let mut command = self.new_command();
1398 command.arg("export");
1399 self.add_shared_options(&mut command, false);
1400 command
1401 }
1402
1403 pub fn format(&self) -> Command {
1405 let mut command = self.new_command();
1406 command.arg("format");
1407 self.add_shared_options(&mut command, false);
1408 command.env(EnvVars::UV_EXCLUDE_NEWER, "2026-02-15T00:00:00Z");
1410 command
1411 }
1412
1413 pub fn build(&self) -> Command {
1415 let mut command = self.new_command();
1416 command.arg("build");
1417 self.add_shared_options(&mut command, false);
1418 command
1419 }
1420
1421 pub fn version(&self) -> Command {
1422 let mut command = self.new_command();
1423 command.arg("version");
1424 self.add_shared_options(&mut command, false);
1425 command
1426 }
1427
1428 pub fn self_version(&self) -> Command {
1429 let mut command = self.new_command();
1430 command.arg("self").arg("version");
1431 self.add_shared_options(&mut command, false);
1432 command
1433 }
1434
1435 pub fn self_update(&self) -> Command {
1436 let mut command = self.new_command();
1437 command.arg("self").arg("update");
1438 self.add_shared_options(&mut command, false);
1439 command
1440 }
1441
1442 pub fn publish(&self) -> Command {
1444 let mut command = self.new_command();
1445 command.arg("publish");
1446 self.add_shared_options(&mut command, false);
1447 command
1448 }
1449
1450 pub fn python_find(&self) -> Command {
1452 let mut command = self.new_command();
1453 command
1454 .arg("python")
1455 .arg("find")
1456 .env(EnvVars::UV_PREVIEW, "1")
1457 .env(EnvVars::UV_PYTHON_INSTALL_DIR, "");
1458 self.add_shared_options(&mut command, false);
1459 command
1460 }
1461
1462 pub fn python_list(&self) -> Command {
1464 let mut command = self.new_command();
1465 command
1466 .arg("python")
1467 .arg("list")
1468 .env(EnvVars::UV_PYTHON_INSTALL_DIR, "");
1469 self.add_shared_options(&mut command, false);
1470 command
1471 }
1472
1473 pub fn python_install(&self) -> Command {
1475 let mut command = self.new_command();
1476 command.arg("python").arg("install");
1477 self.add_shared_options(&mut command, true);
1478 command
1479 }
1480
1481 pub fn python_uninstall(&self) -> Command {
1483 let mut command = self.new_command();
1484 command.arg("python").arg("uninstall");
1485 self.add_shared_options(&mut command, true);
1486 command
1487 }
1488
1489 pub fn python_upgrade(&self) -> Command {
1491 let mut command = self.new_command();
1492 command.arg("python").arg("upgrade");
1493 self.add_shared_options(&mut command, true);
1494 command
1495 }
1496
1497 pub fn python_pin(&self) -> Command {
1499 let mut command = self.new_command();
1500 command.arg("python").arg("pin");
1501 self.add_shared_options(&mut command, true);
1502 command
1503 }
1504
1505 pub fn python_dir(&self) -> Command {
1507 let mut command = self.new_command();
1508 command.arg("python").arg("dir");
1509 self.add_shared_options(&mut command, true);
1510 command
1511 }
1512
1513 pub fn run(&self) -> Command {
1515 let mut command = self.new_command();
1516 command.arg("run").env(EnvVars::UV_SHOW_RESOLUTION, "1");
1517 self.add_shared_options(&mut command, true);
1518 command
1519 }
1520
1521 pub fn tool_run(&self) -> Command {
1523 let mut command = self.new_command();
1524 command
1525 .arg("tool")
1526 .arg("run")
1527 .env(EnvVars::UV_SHOW_RESOLUTION, "1");
1528 self.add_shared_options(&mut command, false);
1529 command
1530 }
1531
1532 pub fn tool_upgrade(&self) -> Command {
1534 let mut command = self.new_command();
1535 command.arg("tool").arg("upgrade");
1536 self.add_shared_options(&mut command, false);
1537 command
1538 }
1539
1540 pub fn tool_install(&self) -> Command {
1542 let mut command = self.new_command();
1543 command.arg("tool").arg("install");
1544 self.add_shared_options(&mut command, false);
1545 command
1546 }
1547
1548 pub fn tool_list(&self) -> Command {
1550 let mut command = self.new_command();
1551 command.arg("tool").arg("list");
1552 self.add_shared_options(&mut command, false);
1553 command
1554 }
1555
1556 pub fn tool_dir(&self) -> Command {
1558 let mut command = self.new_command();
1559 command.arg("tool").arg("dir");
1560 self.add_shared_options(&mut command, false);
1561 command
1562 }
1563
1564 pub fn tool_uninstall(&self) -> Command {
1566 let mut command = self.new_command();
1567 command.arg("tool").arg("uninstall");
1568 self.add_shared_options(&mut command, false);
1569 command
1570 }
1571
1572 pub fn add(&self) -> Command {
1574 let mut command = self.new_command();
1575 command.arg("add");
1576 self.add_shared_options(&mut command, false);
1577 command
1578 }
1579
1580 pub fn remove(&self) -> Command {
1582 let mut command = self.new_command();
1583 command.arg("remove");
1584 self.add_shared_options(&mut command, false);
1585 command
1586 }
1587
1588 pub fn tree(&self) -> Command {
1590 let mut command = self.new_command();
1591 command.arg("tree");
1592 self.add_shared_options(&mut command, false);
1593 command
1594 }
1595
1596 pub fn clean(&self) -> Command {
1598 let mut command = self.new_command();
1599 command.arg("cache").arg("clean");
1600 self.add_shared_options(&mut command, false);
1601 command
1602 }
1603
1604 pub fn prune(&self) -> Command {
1606 let mut command = self.new_command();
1607 command.arg("cache").arg("prune");
1608 self.add_shared_options(&mut command, false);
1609 command
1610 }
1611
1612 pub fn cache_size(&self) -> Command {
1614 let mut command = self.new_command();
1615 command.arg("cache").arg("size");
1616 self.add_shared_options(&mut command, false);
1617 command
1618 }
1619
1620 pub fn build_backend(&self) -> Command {
1624 let mut command = self.new_command();
1625 command.arg("build-backend");
1626 self.add_shared_options(&mut command, false);
1627 command
1628 }
1629
1630 pub fn interpreter(&self) -> PathBuf {
1634 let venv = &self.venv;
1635 if cfg!(unix) {
1636 venv.join("bin").join("python")
1637 } else if cfg!(windows) {
1638 venv.join("Scripts").join("python.exe")
1639 } else {
1640 unimplemented!("Only Windows and Unix are supported")
1641 }
1642 }
1643
1644 pub fn python_command(&self) -> Command {
1645 let mut interpreter = self.interpreter();
1646
1647 if !interpreter.exists() {
1649 interpreter.clone_from(
1650 &self
1651 .python_versions
1652 .first()
1653 .expect("At least one Python version is required")
1654 .1,
1655 );
1656 }
1657
1658 let mut command = Self::new_command_with(&interpreter);
1659 command
1660 .arg("-B")
1663 .env(EnvVars::PYTHONUTF8, "1");
1665
1666 self.add_shared_env(&mut command, false);
1667
1668 command
1669 }
1670
1671 pub fn auth_login(&self) -> Command {
1673 let mut command = self.new_command();
1674 command.arg("auth").arg("login");
1675 self.add_shared_options(&mut command, false);
1676 command
1677 }
1678
1679 pub fn auth_logout(&self) -> Command {
1681 let mut command = self.new_command();
1682 command.arg("auth").arg("logout");
1683 self.add_shared_options(&mut command, false);
1684 command
1685 }
1686
1687 pub fn auth_helper(&self) -> Command {
1689 let mut command = self.new_command();
1690 command.arg("auth").arg("helper");
1691 self.add_shared_options(&mut command, false);
1692 command
1693 }
1694
1695 pub fn auth_token(&self) -> Command {
1697 let mut command = self.new_command();
1698 command.arg("auth").arg("token");
1699 self.add_shared_options(&mut command, false);
1700 command
1701 }
1702
1703 #[must_use]
1707 pub fn with_real_home(mut self) -> Self {
1708 if let Some(home) = env::var_os(EnvVars::HOME) {
1709 self.extra_env
1710 .push((EnvVars::HOME.to_string().into(), home));
1711 }
1712 self.extra_env.push((
1715 EnvVars::XDG_CONFIG_HOME.into(),
1716 self.user_config_dir.as_os_str().into(),
1717 ));
1718 self
1719 }
1720
1721 pub fn assert_command(&self, command: &str) -> Assert {
1723 self.python_command()
1724 .arg("-c")
1725 .arg(command)
1726 .current_dir(&self.temp_dir)
1727 .assert()
1728 }
1729
1730 pub fn assert_file(&self, file: impl AsRef<Path>) -> Assert {
1732 self.python_command()
1733 .arg(file.as_ref())
1734 .current_dir(&self.temp_dir)
1735 .assert()
1736 }
1737
1738 pub fn assert_installed(&self, package: &'static str, version: &'static str) {
1740 self.assert_command(
1741 format!("import {package} as package; print(package.__version__, end='')").as_str(),
1742 )
1743 .success()
1744 .stdout(version);
1745 }
1746
1747 pub fn assert_not_installed(&self, package: &'static str) {
1749 self.assert_command(format!("import {package}").as_str())
1750 .failure();
1751 }
1752
1753 pub fn path_patterns(path: impl AsRef<Path>) -> Vec<String> {
1755 let mut patterns = Vec::new();
1756
1757 if path.as_ref().exists() {
1759 patterns.push(Self::path_pattern(
1760 path.as_ref()
1761 .canonicalize()
1762 .expect("Failed to create canonical path"),
1763 ));
1764 }
1765
1766 patterns.push(Self::path_pattern(path));
1768
1769 patterns
1770 }
1771
1772 fn path_pattern(path: impl AsRef<Path>) -> String {
1774 format!(
1775 r"{}\\?/?",
1777 regex::escape(&path.as_ref().simplified_display().to_string())
1778 .replace(r"\\", r"(\\|\/)")
1781 )
1782 }
1783
1784 pub fn python_path(&self) -> OsString {
1785 if cfg!(unix) {
1786 env::join_paths(
1788 self.python_versions
1789 .iter()
1790 .map(|(version, _)| self.python_dir.join(version.to_string())),
1791 )
1792 .unwrap()
1793 } else {
1794 env::join_paths(
1796 self.python_versions
1797 .iter()
1798 .map(|(_, executable)| executable.parent().unwrap().to_path_buf()),
1799 )
1800 .unwrap()
1801 }
1802 }
1803
1804 pub fn filters(&self) -> Vec<(&str, &str)> {
1806 self.filters
1809 .iter()
1810 .map(|(p, r)| (p.as_str(), r.as_str()))
1811 .chain(INSTA_FILTERS.iter().copied())
1812 .collect()
1813 }
1814
1815 pub fn filters_without_standard_filters(&self) -> Vec<(&str, &str)> {
1817 self.filters
1818 .iter()
1819 .map(|(p, r)| (p.as_str(), r.as_str()))
1820 .collect()
1821 }
1822
1823 #[allow(clippy::unused_self)]
1825 pub fn python_kind(&self) -> &'static str {
1826 "python"
1827 }
1828
1829 pub fn site_packages(&self) -> PathBuf {
1831 site_packages_path(
1832 &self.venv,
1833 &format!(
1834 "{}{}",
1835 self.python_kind(),
1836 self.python_version.as_ref().expect(
1837 "A Python version must be provided to retrieve the test site packages path"
1838 )
1839 ),
1840 )
1841 }
1842
1843 pub fn reset_venv(&self) {
1845 self.create_venv();
1846 }
1847
1848 fn create_venv(&self) {
1850 let executable = get_python(
1851 self.python_version
1852 .as_ref()
1853 .expect("A Python version must be provided to create a test virtual environment"),
1854 );
1855 create_venv_from_executable(&self.venv, &self.cache_dir, &executable, &self.uv_bin);
1856 }
1857
1858 pub fn copy_ecosystem_project(&self, name: &str) {
1869 let project_dir = PathBuf::from(format!("../../test/ecosystem/{name}"));
1870 self.temp_dir.copy_from(project_dir, &["*"]).unwrap();
1871 if let Err(err) = fs_err::remove_file(self.temp_dir.join("uv.lock")) {
1873 assert_eq!(
1874 err.kind(),
1875 io::ErrorKind::NotFound,
1876 "Failed to remove uv.lock: {err}"
1877 );
1878 }
1879 }
1880
1881 pub fn diff_lock(&self, change: impl Fn(&Self) -> Command) -> String {
1890 static TRIM_TRAILING_WHITESPACE: std::sync::LazyLock<Regex> =
1891 std::sync::LazyLock::new(|| Regex::new(r"(?m)^\s+$").unwrap());
1892
1893 let lock_path = ChildPath::new(self.temp_dir.join("uv.lock"));
1894 let old_lock = fs_err::read_to_string(&lock_path).unwrap();
1895 let (snapshot, _, status) = run_and_format_with_status(
1896 change(self),
1897 self.filters(),
1898 "diff_lock",
1899 Some(WindowsFilters::Platform),
1900 None,
1901 );
1902 assert!(status.success(), "{snapshot}");
1903 let new_lock = fs_err::read_to_string(&lock_path).unwrap();
1904 diff_snapshot(&old_lock, &new_lock)
1905 }
1906
1907 pub fn read(&self, file: impl AsRef<Path>) -> String {
1909 fs_err::read_to_string(self.temp_dir.join(&file))
1910 .unwrap_or_else(|_| panic!("Missing file: `{}`", file.user_display()))
1911 }
1912
1913 fn new_command(&self) -> Command {
1916 Self::new_command_with(&self.uv_bin)
1917 }
1918
1919 fn new_command_with(bin: &Path) -> Command {
1925 let mut command = Command::new(bin);
1926
1927 let passthrough = [
1928 EnvVars::PATH,
1930 EnvVars::RUST_LOG,
1932 EnvVars::RUST_BACKTRACE,
1933 EnvVars::SYSTEMDRIVE,
1935 EnvVars::RUST_MIN_STACK,
1937 EnvVars::UV_STACK_SIZE,
1938 EnvVars::ALL_PROXY,
1940 EnvVars::HTTPS_PROXY,
1941 EnvVars::HTTP_PROXY,
1942 EnvVars::NO_PROXY,
1943 EnvVars::SSL_CERT_DIR,
1944 EnvVars::SSL_CERT_FILE,
1945 EnvVars::UV_NATIVE_TLS,
1946 ];
1947
1948 for env_var in EnvVars::all_names()
1949 .iter()
1950 .filter(|name| !passthrough.contains(name))
1951 {
1952 command.env_remove(env_var);
1953 }
1954
1955 command
1956 }
1957}
1958
1959pub fn diff_snapshot(old: &str, new: &str) -> String {
1962 static TRIM_TRAILING_WHITESPACE: std::sync::LazyLock<Regex> =
1963 std::sync::LazyLock::new(|| Regex::new(r"(?m)^\s+$").unwrap());
1964
1965 let diff = similar::TextDiff::from_lines(old, new);
1966 let unified = diff
1967 .unified_diff()
1968 .context_radius(10)
1969 .header("old", "new")
1970 .to_string();
1971 TRIM_TRAILING_WHITESPACE
1975 .replace_all(&unified, "")
1976 .into_owned()
1977}
1978
1979pub fn site_packages_path(venv: &Path, python: &str) -> PathBuf {
1980 if cfg!(unix) {
1981 venv.join("lib").join(python).join("site-packages")
1982 } else if cfg!(windows) {
1983 venv.join("Lib").join("site-packages")
1984 } else {
1985 unimplemented!("Only Windows and Unix are supported")
1986 }
1987}
1988
1989pub fn venv_bin_path(venv: impl AsRef<Path>) -> PathBuf {
1990 if cfg!(unix) {
1991 venv.as_ref().join("bin")
1992 } else if cfg!(windows) {
1993 venv.as_ref().join("Scripts")
1994 } else {
1995 unimplemented!("Only Windows and Unix are supported")
1996 }
1997}
1998
1999pub fn get_python(version: &PythonVersion) -> PathBuf {
2001 ManagedPythonInstallations::from_settings(None)
2002 .map(|installed_pythons| {
2003 installed_pythons
2004 .find_version(version)
2005 .expect("Tests are run on a supported platform")
2006 .next()
2007 .as_ref()
2008 .map(|python| python.executable(false))
2009 })
2010 .unwrap_or_default()
2013 .unwrap_or(PathBuf::from(version.to_string()))
2014}
2015
2016pub fn create_venv_from_executable<P: AsRef<Path>>(
2018 path: P,
2019 cache_dir: &ChildPath,
2020 python: &Path,
2021 uv_bin: &Path,
2022) {
2023 TestContext::new_command_with(uv_bin)
2024 .arg("venv")
2025 .arg(path.as_ref().as_os_str())
2026 .arg("--clear")
2027 .arg("--cache-dir")
2028 .arg(cache_dir.path())
2029 .arg("--python")
2030 .arg(python)
2031 .current_dir(path.as_ref().parent().unwrap())
2032 .assert()
2033 .success();
2034 ChildPath::new(path.as_ref()).assert(predicate::path::is_dir());
2035}
2036
2037pub fn python_path_with_versions(
2041 temp_dir: &ChildPath,
2042 python_versions: &[&str],
2043) -> anyhow::Result<OsString> {
2044 let download_list = ManagedPythonDownloadList::new_only_embedded().unwrap();
2045 Ok(env::join_paths(
2046 python_installations_for_versions(temp_dir, python_versions, &download_list)?
2047 .into_iter()
2048 .map(|path| path.parent().unwrap().to_path_buf()),
2049 )?)
2050}
2051
2052pub fn python_installations_for_versions(
2056 temp_dir: &ChildPath,
2057 python_versions: &[&str],
2058 download_list: &ManagedPythonDownloadList,
2059) -> anyhow::Result<Vec<PathBuf>> {
2060 let cache = Cache::from_path(temp_dir.child("cache").to_path_buf())
2061 .init_no_wait()?
2062 .expect("No cache contention when setting up Python in tests");
2063 let selected_pythons = python_versions
2064 .iter()
2065 .map(|python_version| {
2066 if let Ok(python) = PythonInstallation::find(
2067 &PythonRequest::parse(python_version),
2068 EnvironmentPreference::OnlySystem,
2069 PythonPreference::Managed,
2070 download_list,
2071 &cache,
2072 Preview::default(),
2073 ) {
2074 python.into_interpreter().sys_executable().to_owned()
2075 } else {
2076 panic!("Could not find Python {python_version} for test\nTry `cargo run python install` first, or refer to CONTRIBUTING.md");
2077 }
2078 })
2079 .collect::<Vec<_>>();
2080
2081 assert!(
2082 python_versions.is_empty() || !selected_pythons.is_empty(),
2083 "Failed to fulfill requested test Python versions: {selected_pythons:?}"
2084 );
2085
2086 Ok(selected_pythons)
2087}
2088
2089#[derive(Debug, Copy, Clone)]
2090pub enum WindowsFilters {
2091 Platform,
2092 Universal,
2093}
2094
2095pub fn apply_filters<T: AsRef<str>>(mut snapshot: String, filters: impl AsRef<[(T, T)]>) -> String {
2097 for (matcher, replacement) in filters.as_ref() {
2098 let re = Regex::new(matcher.as_ref()).expect("Do you need to regex::escape your filter?");
2100 if re.is_match(&snapshot) {
2101 snapshot = re.replace_all(&snapshot, replacement.as_ref()).to_string();
2102 }
2103 }
2104 snapshot
2105}
2106
2107pub fn run_and_format<T: AsRef<str>>(
2111 command: impl BorrowMut<Command>,
2112 filters: impl AsRef<[(T, T)]>,
2113 function_name: &str,
2114 windows_filters: Option<WindowsFilters>,
2115 input: Option<&str>,
2116) -> (String, Output) {
2117 let (snapshot, output, _) =
2118 run_and_format_with_status(command, filters, function_name, windows_filters, input);
2119 (snapshot, output)
2120}
2121
2122#[expect(clippy::print_stderr)]
2126pub fn run_and_format_with_status<T: AsRef<str>>(
2127 mut command: impl BorrowMut<Command>,
2128 filters: impl AsRef<[(T, T)]>,
2129 function_name: &str,
2130 windows_filters: Option<WindowsFilters>,
2131 input: Option<&str>,
2132) -> (String, Output, ExitStatus) {
2133 let program = command
2134 .borrow_mut()
2135 .get_program()
2136 .to_string_lossy()
2137 .to_string();
2138
2139 if let Ok(root) = env::var(EnvVars::TRACING_DURATIONS_TEST_ROOT) {
2141 #[allow(clippy::assertions_on_constants)]
2143 {
2144 assert!(
2145 cfg!(feature = "tracing-durations-export"),
2146 "You need to enable the tracing-durations-export feature to use `TRACING_DURATIONS_TEST_ROOT`"
2147 );
2148 }
2149 command.borrow_mut().env(
2150 EnvVars::TRACING_DURATIONS_FILE,
2151 Path::new(&root).join(function_name).with_extension("jsonl"),
2152 );
2153 }
2154
2155 let output = if let Some(input) = input {
2156 let mut child = command
2157 .borrow_mut()
2158 .stdin(Stdio::piped())
2159 .stdout(Stdio::piped())
2160 .stderr(Stdio::piped())
2161 .spawn()
2162 .unwrap_or_else(|err| panic!("Failed to spawn {program}: {err}"));
2163 child
2164 .stdin
2165 .as_mut()
2166 .expect("Failed to open stdin")
2167 .write_all(input.as_bytes())
2168 .expect("Failed to write to stdin");
2169
2170 child
2171 .wait_with_output()
2172 .unwrap_or_else(|err| panic!("Failed to read output from {program}: {err}"))
2173 } else {
2174 command
2175 .borrow_mut()
2176 .output()
2177 .unwrap_or_else(|err| panic!("Failed to spawn {program}: {err}"))
2178 };
2179
2180 eprintln!("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Unfiltered output ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
2181 eprintln!(
2182 "----- stdout -----\n{}\n----- stderr -----\n{}",
2183 String::from_utf8_lossy(&output.stdout),
2184 String::from_utf8_lossy(&output.stderr),
2185 );
2186 eprintln!("────────────────────────────────────────────────────────────────────────────────\n");
2187
2188 let mut snapshot = apply_filters(
2189 format!(
2190 "success: {:?}\nexit_code: {}\n----- stdout -----\n{}\n----- stderr -----\n{}",
2191 output.status.success(),
2192 output.status.code().unwrap_or(!0),
2193 String::from_utf8_lossy(&output.stdout),
2194 String::from_utf8_lossy(&output.stderr),
2195 ),
2196 filters,
2197 );
2198
2199 if cfg!(windows) {
2204 if let Some(windows_filters) = windows_filters {
2205 let windows_only_deps = [
2207 (r"( ?[-+~] ?)?colorama==\d+(\.\d+)+( [\\]\n\s+--hash=.*)?\n(\s+# via .*\n)?"),
2208 (r"( ?[-+~] ?)?colorama==\d+(\.\d+)+(\s+[-+~]?\s+# via .*)?\n"),
2209 (r"( ?[-+~] ?)?tzdata==\d+(\.\d+)+( [\\]\n\s+--hash=.*)?\n(\s+# via .*\n)?"),
2210 (r"( ?[-+~] ?)?tzdata==\d+(\.\d+)+(\s+[-+~]?\s+# via .*)?\n"),
2211 ];
2212 let mut removed_packages = 0;
2213 for windows_only_dep in windows_only_deps {
2214 let re = Regex::new(windows_only_dep).unwrap();
2216 if re.is_match(&snapshot) {
2217 snapshot = re.replace(&snapshot, "").to_string();
2218 removed_packages += 1;
2219 }
2220 }
2221 if removed_packages > 0 {
2222 for i in 1..20 {
2223 for verb in match windows_filters {
2224 WindowsFilters::Platform => [
2225 "Resolved",
2226 "Prepared",
2227 "Installed",
2228 "Audited",
2229 "Uninstalled",
2230 ]
2231 .iter(),
2232 WindowsFilters::Universal => {
2233 ["Prepared", "Installed", "Audited", "Uninstalled"].iter()
2234 }
2235 } {
2236 snapshot = snapshot.replace(
2237 &format!("{verb} {} packages", i + removed_packages),
2238 &format!("{verb} {} package{}", i, if i > 1 { "s" } else { "" }),
2239 );
2240 }
2241 }
2242 }
2243 }
2244 }
2245
2246 let status = output.status;
2247 (snapshot, output, status)
2248}
2249
2250pub fn copy_dir_ignore(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> anyhow::Result<()> {
2252 for entry in ignore::Walk::new(&src) {
2253 let entry = entry?;
2254 let relative = entry.path().strip_prefix(&src)?;
2255 let ty = entry.file_type().unwrap();
2256 if ty.is_dir() {
2257 fs_err::create_dir(dst.as_ref().join(relative))?;
2258 } else {
2259 fs_err::copy(entry.path(), dst.as_ref().join(relative))?;
2260 }
2261 }
2262 Ok(())
2263}
2264
2265pub fn make_project(dir: &Path, name: &str, body: &str) -> anyhow::Result<()> {
2267 let pyproject_toml = formatdoc! {r#"
2268 [project]
2269 name = "{name}"
2270 version = "0.1.0"
2271 requires-python = ">=3.11,<3.13"
2272 {body}
2273
2274 [build-system]
2275 requires = ["uv_build>=0.9.0,<10000"]
2276 build-backend = "uv_build"
2277 "#
2278 };
2279 fs_err::create_dir_all(dir)?;
2280 fs_err::write(dir.join("pyproject.toml"), pyproject_toml)?;
2281 fs_err::create_dir_all(dir.join("src").join(name))?;
2282 fs_err::write(dir.join("src").join(name).join("__init__.py"), "")?;
2283 Ok(())
2284}
2285
2286pub const READ_ONLY_GITHUB_TOKEN: &[&str] = &[
2288 "Z2l0aHViCg==",
2289 "cGF0Cg==",
2290 "MTFBQlVDUjZBMERMUTQ3aVphN3hPdV9qQmhTMkZUeHZ4ZE13OHczakxuZndsV2ZlZjc2cE53eHBWS2tiRUFwdnpmUk8zV0dDSUhicDFsT01aago=",
2291];
2292
2293#[cfg(not(windows))]
2295pub const READ_ONLY_GITHUB_TOKEN_2: &[&str] = &[
2296 "Z2l0aHViCg==",
2297 "cGF0Cg==",
2298 "MTFBQlVDUjZBMDJTOFYwMTM4YmQ0bV9uTXpueWhxZDBrcllROTQ5SERTeTI0dENKZ2lmdzIybDFSR2s1SE04QW8xTUVYQ1I0Q1YxYUdPRGpvZQo=",
2299];
2300
2301pub const READ_ONLY_GITHUB_SSH_DEPLOY_KEY: &str = "LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0KYjNCbGJuTnphQzFyWlhrdGRqRUFBQUFBQkc1dmJtVUFBQUFFYm05dVpRQUFBQUFBQUFBQkFBQUFNd0FBQUF0emMyZ3RaVwpReU5UVXhPUUFBQUNBeTF1SnNZK1JXcWp1NkdIY3Z6a3AwS21yWDEwdmo3RUZqTkpNTkRqSGZPZ0FBQUpqWUpwVnAyQ2FWCmFRQUFBQXR6YzJndFpXUXlOVFV4T1FBQUFDQXkxdUpzWStSV3FqdTZHSGN2emtwMEttclgxMHZqN0VGak5KTU5EakhmT2cKQUFBRUMwbzBnd1BxbGl6TFBJOEFXWDVaS2dVZHJyQ2ptMDhIQm9FenB4VDg3MXBqTFc0bXhqNUZhcU83b1lkeS9PU25RcQphdGZYUytQc1FXTTBrdzBPTWQ4NkFBQUFFR3R2Ym5OMGFVQmhjM1J5WVd3dWMyZ0JBZ01FQlE9PQotLS0tLUVORCBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0K";
2302
2303pub fn decode_token(content: &[&str]) -> String {
2306 content
2307 .iter()
2308 .map(|part| base64.decode(part).unwrap())
2309 .map(|decoded| {
2310 std::str::from_utf8(decoded.as_slice())
2311 .unwrap()
2312 .trim_end()
2313 .to_string()
2314 })
2315 .join("_")
2316}
2317
2318#[tokio::main(flavor = "current_thread")]
2321pub async fn download_to_disk(url: &str, path: &Path) {
2322 let trusted_hosts: Vec<_> = env::var(EnvVars::UV_INSECURE_HOST)
2323 .unwrap_or_default()
2324 .split(' ')
2325 .map(|h| uv_configuration::TrustedHost::from_str(h).unwrap())
2326 .collect();
2327
2328 let client = uv_client::BaseClientBuilder::default()
2329 .allow_insecure_host(trusted_hosts)
2330 .build();
2331 let url = url.parse().unwrap();
2332 let response = client
2333 .for_host(&url)
2334 .get(reqwest::Url::from(url))
2335 .send()
2336 .await
2337 .unwrap();
2338
2339 let mut file = fs_err::tokio::File::create(path).await.unwrap();
2340 let mut stream = response.bytes_stream();
2341 while let Some(chunk) = stream.next().await {
2342 file.write_all(&chunk.unwrap()).await.unwrap();
2343 }
2344 file.sync_all().await.unwrap();
2345}
2346
2347#[cfg(unix)]
2352pub struct ReadOnlyDirectoryGuard {
2353 path: PathBuf,
2354 original_mode: u32,
2355}
2356
2357#[cfg(unix)]
2358impl ReadOnlyDirectoryGuard {
2359 pub fn new(path: impl Into<PathBuf>) -> std::io::Result<Self> {
2362 use std::os::unix::fs::PermissionsExt;
2363 let path = path.into();
2364 let metadata = fs_err::metadata(&path)?;
2365 let original_mode = metadata.permissions().mode();
2366 let readonly_mode = original_mode & !0o222;
2368 fs_err::set_permissions(&path, std::fs::Permissions::from_mode(readonly_mode))?;
2369 Ok(Self {
2370 path,
2371 original_mode,
2372 })
2373 }
2374}
2375
2376#[cfg(unix)]
2377impl Drop for ReadOnlyDirectoryGuard {
2378 fn drop(&mut self) {
2379 use std::os::unix::fs::PermissionsExt;
2380 let _ = fs_err::set_permissions(
2381 &self.path,
2382 std::fs::Permissions::from_mode(self.original_mode),
2383 );
2384 }
2385}
2386
2387#[doc(hidden)]
2391#[macro_export]
2392macro_rules! function_name {
2393 () => {{
2394 fn f() {}
2395 fn type_name_of_val<T>(_: T) -> &'static str {
2396 std::any::type_name::<T>()
2397 }
2398 let mut name = type_name_of_val(f).strip_suffix("::f").unwrap_or("");
2399 while let Some(rest) = name.strip_suffix("::{{closure}}") {
2400 name = rest;
2401 }
2402 name
2403 }};
2404}
2405
2406#[macro_export]
2411macro_rules! uv_snapshot {
2412 ($spawnable:expr, @$snapshot:literal) => {{
2413 uv_snapshot!($crate::INSTA_FILTERS.to_vec(), $spawnable, @$snapshot)
2414 }};
2415 ($filters:expr, $spawnable:expr, @$snapshot:literal) => {{
2416 let (snapshot, output) = $crate::run_and_format($spawnable, &$filters, $crate::function_name!(), Some($crate::WindowsFilters::Platform), None);
2418 ::insta::assert_snapshot!(snapshot, @$snapshot);
2419 output
2420 }};
2421 ($filters:expr, $spawnable:expr, input=$input:expr, @$snapshot:literal) => {{
2422 let (snapshot, output) = $crate::run_and_format($spawnable, &$filters, $crate::function_name!(), Some($crate::WindowsFilters::Platform), Some($input));
2424 ::insta::assert_snapshot!(snapshot, @$snapshot);
2425 output
2426 }};
2427 ($filters:expr, windows_filters=false, $spawnable:expr, @$snapshot:literal) => {{
2428 let (snapshot, output) = $crate::run_and_format($spawnable, &$filters, $crate::function_name!(), None, None);
2430 ::insta::assert_snapshot!(snapshot, @$snapshot);
2431 output
2432 }};
2433 ($filters:expr, universal_windows_filters=true, $spawnable:expr, @$snapshot:literal) => {{
2434 let (snapshot, output) = $crate::run_and_format($spawnable, &$filters, $crate::function_name!(), Some($crate::WindowsFilters::Universal), None);
2436 ::insta::assert_snapshot!(snapshot, @$snapshot);
2437 output
2438 }};
2439}