Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(config): make app_state resolver tests panic-safe + host-independent

shanu9e2029ff4a99
diff --git a/src/openhuman/config/mod.rs b/src/openhuman/config/mod.rs
index 6dfa5e7266..8a59aeb613 100644
--- a/src/openhuman/config/mod.rs
+++ b/src/openhuman/config/mod.rs
@@ -34,6 +34,12 @@ pub use schema::{
pub use workspace_handle::workspace_handle;
// Crate-internal: workspace→config-dir resolver reused by the cloud embedder.
pub(crate) use schema::resolve_config_dir_for_workspace;
+// Test-only: the `.openhuman` (or `.openhuman-staging`) root dir name the modern
+// layout keys on. The `desktop::app_state` resolver tests build tempdir
+// workspaces named after it so the modern-layout arm fires regardless of the
+// ambient `OPENHUMAN_APP_ENV`.
+#[cfg(test)]
+pub(crate) use schema::default_root_dir_name;
pub(crate) use schema::set_cli_inference_overrides;
#[allow(unused_imports)]
pub use schema::{
diff --git a/src/openhuman/config/schema/mod.rs b/src/openhuman/config/schema/mod.rs
index 441042b225..18e128eb72 100644
--- a/src/openhuman/config/schema/mod.rs
+++ b/src/openhuman/config/schema/mod.rs
@@ -46,6 +46,12 @@ pub(crate) use load::invalidate_active_workspace;
// Crate-internal: the workspace→config-dir resolver, reused by the cloud
// embedder's keyless credential-scope resolution (mirrors `config::load`).
pub(crate) use load::resolve_config_dir_for_workspace;
+// Test-only: the `.openhuman` (or `.openhuman-staging`) root dir name the modern
+// layout keys on. The `desktop::app_state` resolver tests build tempdir
+// workspaces named after it so the modern-layout arm fires regardless of the
+// ambient `OPENHUMAN_APP_ENV`, instead of hardcoding `.openhuman`.
+#[cfg(test)]
+pub(crate) use load::default_root_dir_name;
// Contract shared with `core::observability::expected_error_kind`: the loader
// appends this marker to a config-read failure when the file's owner differs
// from the reading process, and the classifier keys on it to keep that case
diff --git a/src/openhuman/desktop/app_state/ops_tests.rs b/src/openhuman/desktop/app_state/ops_tests.rs
index 7f0f004e12..107509733b 100644
--- a/src/openhuman/desktop/app_state/ops_tests.rs
+++ b/src/openhuman/desktop/app_state/ops_tests.rs
@@ -491,23 +491,73 @@ async fn current_user_fetch_carries_the_product_identity() {
// can't race each other on the process-global var.
static WORKSPACE_ENV_TEST_LOCK: TestLazy<TestMutex<()>> = TestLazy::new(|| TestMutex::new(()));
-/// The #6079 twin: `config_dir_for_workspace_env` must resolve
-/// `~/.openhuman/workspace` to `~/.openhuman` (the real config dir), NOT the
-/// doubled `~/.openhuman/.openhuman`. The private reimplementation this replaced
-/// produced the doubled path, so `config_is_workspace_env_scoped` disagreed with
-/// the loader and mis-scoped credentials on session revalidation. Delegating to
-/// the shared `resolve_config_dir_for_workspace` keeps the two in lockstep.
+/// RAII guard for `OPENHUMAN_WORKSPACE`. Captures the prior value on
+/// construction and restores it (set or remove) on drop, so a test that panics
+/// between the mutation and the end of the test can't leak the override into a
+/// sibling test. Must be constructed while holding `WORKSPACE_ENV_TEST_LOCK`:
+/// mutating a process env var while another thread reads it is unsafe, and the
+/// lock serialises every test in this group.
+struct WorkspaceEnvGuard {
+ prior: Option<std::ffi::OsString>,
+}
+
+impl WorkspaceEnvGuard {
+ fn set(value: &std::path::Path) -> Self {
+ let prior = std::env::var_os("OPENHUMAN_WORKSPACE");
+ std::env::set_var("OPENHUMAN_WORKSPACE", value);
+ Self { prior }
+ }
+
+ fn set_empty() -> Self {
+ let prior = std::env::var_os("OPENHUMAN_WORKSPACE");
+ std::env::set_var("OPENHUMAN_WORKSPACE", "");
+ Self { prior }
+ }
+
+ fn unset() -> Self {
+ let prior = std::env::var_os("OPENHUMAN_WORKSPACE");
+ std::env::remove_var("OPENHUMAN_WORKSPACE");
+ Self { prior }
+ }
+}
+
+impl Drop for WorkspaceEnvGuard {
+ fn drop(&mut self) {
+ match &self.prior {
+ Some(value) => std::env::set_var("OPENHUMAN_WORKSPACE", value),
+ None => std::env::remove_var("OPENHUMAN_WORKSPACE"),
+ }
+ }
+}
+
+/// The #6079 twin: `config_dir_for_workspace_env` must resolve the modern
+/// `<root>/.openhuman/workspace` layout to its parent `<root>/.openhuman` (the
+/// real config dir), NOT the doubled `<root>/.openhuman/.openhuman`. The private
+/// reimplementation this replaced produced the doubled path, so
+/// `config_is_workspace_env_scoped` disagreed with the loader and mis-scoped
+/// credentials on session revalidation. Delegating to the shared
+/// `resolve_config_dir_for_workspace` keeps the two in lockstep.
+///
+/// The workspace root is named `default_root_dir_name()` (`.openhuman` /
+/// `.openhuman-staging`) so the modern-layout arm — which keys on that name —
+/// fires regardless of the ambient `OPENHUMAN_APP_ENV`, and a temp dir isolates
+/// it from any real `.openhuman` on the host.
#[test]
fn config_dir_for_workspace_env_modern_layout_does_not_double_openhuman() {
let _g = WORKSPACE_ENV_TEST_LOCK.lock();
- std::env::set_var("OPENHUMAN_WORKSPACE", "/home/test/.openhuman/workspace");
+ let tmp = tempdir().unwrap();
+ let root = tmp
+ .path()
+ .join(crate::openhuman::config::default_root_dir_name());
+ let workspace = root.join("workspace");
+ let _env = WorkspaceEnvGuard::set(&workspace);
+
let resolved = config_dir_for_workspace_env();
- std::env::remove_var("OPENHUMAN_WORKSPACE");
- assert_eq!(resolved, Some(PathBuf::from("/home/test/.openhuman")));
+ assert_eq!(resolved, Some(root.clone()));
assert_ne!(
resolved,
- Some(PathBuf::from("/home/test/.openhuman/.openhuman")),
+ Some(root.join(crate::openhuman::config::default_root_dir_name())),
"must never return the doubled .openhuman/.openhuman path"
);
}
@@ -519,13 +569,16 @@ fn config_dir_for_workspace_env_modern_layout_does_not_double_openhuman() {
#[test]
fn config_dir_for_workspace_env_fresh_legacy_resolves_to_sibling() {
let _g = WORKSPACE_ENV_TEST_LOCK.lock();
- std::env::set_var("OPENHUMAN_WORKSPACE", "/home/test/some-project/workspace");
+ let tmp = tempdir().unwrap();
+ let project = tmp.path().join("some-project");
+ let workspace = project.join("workspace");
+ let _env = WorkspaceEnvGuard::set(&workspace);
+
let resolved = config_dir_for_workspace_env();
- std::env::remove_var("OPENHUMAN_WORKSPACE");
assert_eq!(
resolved,
- Some(PathBuf::from("/home/test/some-project/.openhuman")),
+ Some(project.join(".openhuman")),
"a fresh legacy workspace must resolve to its sibling .openhuman"
);
}
@@ -535,14 +588,15 @@ fn config_dir_for_workspace_env_fresh_legacy_resolves_to_sibling() {
#[test]
fn config_dir_for_workspace_env_none_when_unset_or_empty() {
let _g = WORKSPACE_ENV_TEST_LOCK.lock();
- std::env::remove_var("OPENHUMAN_WORKSPACE");
- assert_eq!(config_dir_for_workspace_env(), None);
+ {
+ let _env = WorkspaceEnvGuard::unset();
+ assert_eq!(config_dir_for_workspace_env(), None);
+ }
- std::env::set_var("OPENHUMAN_WORKSPACE", "");
- let resolved = config_dir_for_workspace_env();
- std::env::remove_var("OPENHUMAN_WORKSPACE");
+ let _env = WorkspaceEnvGuard::set_empty();
assert_eq!(
- resolved, None,
+ config_dir_for_workspace_env(),
+ None,
"an empty override must not be treated as a path"
);
}