forked from 1b-agent/opencadstudio-upstream
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
163763c42a
commit
eae5662099
2 files changed
+12
No files matched your search
@@ -35,6 +35,11 @@ const DEFAULT_ALIASES_PGP: &str = include_str!("../../assets/ocad.pgp");
|
|||||||
/// config base can't be resolved (headless, no `HOME`).
|
/// config base can't be resolved (headless, no `HOME`).
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
fn alias_file_path() -> Option<PathBuf> {
|
fn alias_file_path() -> Option<PathBuf> {
|
||||||
|
// 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"))
|
Some(crate::config::config_dir()?.join("ocad.pgp"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,13 @@ use std::path::PathBuf;
|
|||||||
/// file name onto it and `create_dir_all` its parent before writing.
|
/// file name onto it and `create_dir_all` its parent before writing.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub fn config_dir() -> Option<PathBuf> {
|
pub fn config_dir() -> Option<PathBuf> {
|
||||||
|
// 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") {
|
let base: PathBuf = if cfg!(target_os = "windows") {
|
||||||
std::env::var_os("APPDATA").map(PathBuf::from)?
|
std::env::var_os("APPDATA").map(PathBuf::from)?
|
||||||
} else if cfg!(target_os = "macos") {
|
} else if cfg!(target_os = "macos") {
|
||||||
|
|||||||
Reference in new issue
Block a user