diff --git a/crates/ty/tests/cli/main.rs b/crates/ty/tests/cli/main.rs index a741f4ef29897..a9e735fd5b788 100644 --- a/crates/ty/tests/cli/main.rs +++ b/crates/ty/tests/cli/main.rs @@ -383,12 +383,8 @@ fn user_configuration() -> anyhow::Result<()> { ), ])?; - let config_directory = case.root().join("home/.config"); - let config_env_var = if cfg!(windows) { - "APPDATA" - } else { - "XDG_CONFIG_HOME" - }; + let config_directory = case.user_config_directory(); + let config_env_var = user_config_directory_env_var(); assert_cmd_snapshot!( case.command().current_dir(case.root().join("project")).env(config_env_var, config_directory.as_os_str()), @@ -888,13 +884,16 @@ impl CliTest { // Canonicalize the tempdir path because macos uses symlinks for tempdirs // and that doesn't play well with our snapshot filtering. // Simplify with dunce because otherwise we get UNC paths on Windows. - let project_dir = dunce::simplified( + let temp_dir_path = dunce::simplified( &temp_dir .path() .canonicalize() - .context("Failed to canonicalize project path")?, + .context("Failed to canonicalize temporary directory path")?, ) .to_path_buf(); + let project_dir = temp_dir_path.join("project"); + std::fs::create_dir_all(&project_dir) + .with_context(|| format!("Failed to create directory `{}`", project_dir.display()))?; let mut settings = insta::Settings::clone_current(); settings.add_filter(&tempdir_filter(&project_dir), "/"); @@ -1016,9 +1015,21 @@ impl CliTest { // Unset all environment variables because they can affect test behavior. command.env_clear(); + // Point user config discovery at a test-local directory to avoid picking up host config. + command.env( + user_config_directory_env_var(), + self.user_config_directory(), + ); command } + + fn user_config_directory(&self) -> PathBuf { + self.project_dir + .parent() + .expect("project directory always has a parent") + .join("home/.config") + } } fn tempdir_filter(path: &Path) -> String { @@ -1032,3 +1043,11 @@ fn site_packages_filter(python_version: &str) -> String { format!("lib/python{}/site-packages", regex::escape(python_version)) } } + +fn user_config_directory_env_var() -> &'static str { + if cfg!(windows) { + "APPDATA" + } else { + "XDG_CONFIG_HOME" + } +}