From eae5662099a7c4ff93772723d57cd662e45b79e1 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Thu, 24 Sep 2026 15:37:00 +0300 Subject: [PATCH] fix(test): keep tests out of the user's config folder Tests resolved the real per-user config dir. When the alias table version moved, parallel tests migrated and rewrote the user's alias file concurrently and one left it holding a single alias. Under test, config_dir() is a per-process temp folder and the alias table comes from the shipped defaults with no file I/O. Co-Authored-By: Claude Opus 5.5 --- src/app/alias.rs | 5 +++++ src/config.rs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/app/alias.rs b/src/app/alias.rs index 350c95c67..0f47f5b1e 100644 --- a/src/app/alias.rs +++ b/src/app/alias.rs @@ -35,6 +35,11 @@ const DEFAULT_ALIASES_PGP: &str = include_str!("../../assets/ocad.pgp"); /// config base can't be resolved (headless, no `HOME`). #[cfg(not(target_arch = "wasm32"))] fn alias_file_path() -> Option { + // Tests read the shipped defaults: parallel tests seeding and migrating one + // shared file race, and a half-written table fails unrelated alias tests. + if cfg!(test) { + return None; + } Some(crate::config::config_dir()?.join("ocad.pgp")) } diff --git a/src/config.rs b/src/config.rs index e8f907441..6d1e60962 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,6 +10,13 @@ use std::path::PathBuf; /// file name onto it and `create_dir_all` its parent before writing. #[cfg(not(target_arch = "wasm32"))] pub fn config_dir() -> Option { + // Tests must never read or write the person's real settings: a test run + // once raced dozens of tests through an alias-table migration and left the + // user's alias file holding a single line. Every store routes through here, + // so one per-process scratch folder isolates them all. + if cfg!(test) { + return Some(std::env::temp_dir().join(format!("ocs-test-config-{}", std::process::id()))); + } let base: PathBuf = if cfg!(target_os = "windows") { std::env::var_os("APPDATA").map(PathBuf::from)? } else if cfg!(target_os = "macos") {