Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

test: point the whole suite at a temp data dir (#1095)

Ruben Lütke24f54d123852
diff --git a/tests/conftest.py b/tests/conftest.py
index 830f3d10cf..be80223e0a 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,7 +1,11 @@
"""Shared pytest fixtures for all test suites."""
from __future__ import annotations
+import atexit
+import os
+import shutil
import sys
+import tempfile
from pathlib import Path
from urllib.parse import urlsplit
@@ -11,6 +15,27 @@ _REPO_ROOT = Path(__file__).resolve().parent.parent
if str(_REPO_ROOT) not in sys.path:
sys.path.insert(0, str(_REPO_ROOT))
+# Hermetic data dir (#458). ``dodaios.core.config.DATA_DIR`` is resolved once,
+# at import, from ``JARVIS_DATA_DIR`` or ``<repo>/data``. In an installer-managed
+# checkout ``<repo>/data`` is the user's live data, so any store without its own
+# test redirect (the cost ledger, the society databases, ...) would write there.
+# Point the whole session at a fresh temp dir before the first dodaios import.
+# A value inherited from the caller is overridden on purpose: a shell or an app
+# pane may carry the user's real data dir. Tests that need a specific value
+# still monkeypatch it themselves; subprocesses inherit the temp dir.
+_TEST_DATA_DIR = Path(tempfile.mkdtemp(prefix="dodaios-test-data-"))
+os.environ["JARVIS_DATA_DIR"] = str(_TEST_DATA_DIR)
+atexit.register(shutil.rmtree, _TEST_DATA_DIR, ignore_errors=True)
+
+# ``memory.data_dir`` (the anchor for the session, chat, society and
+# self-build stores) defaults to the cwd-relative "./data", which is the
+# checkout's data dir when pytest runs from the repo root. Default it to the
+# same temp dir; a test or TOML that sets the field explicitly still wins.
+from dodaios.core.config import MemoryConfig # noqa: E402
+
+MemoryConfig.model_fields["data_dir"].default = str(_TEST_DATA_DIR)
+MemoryConfig.model_rebuild(force=True)
+
import pytest # noqa: E402
import pytest_asyncio # noqa: E402
diff --git a/tests/unit/core/test_headless_keyring_fallback.py b/tests/unit/core/test_headless_keyring_fallback.py
index 5e64e9f9cf..0f6f8f97f2 100644
--- a/tests/unit/core/test_headless_keyring_fallback.py
+++ b/tests/unit/core/test_headless_keyring_fallback.py
@@ -113,6 +113,7 @@ def test_resolve_writable_data_dir_honors_env_override(monkeypatch, tmp_path):
def test_resolve_writable_data_dir_default_unchanged_when_writable(monkeypatch, tmp_path):
writable_dir = tmp_path / "data"
+ monkeypatch.delenv("JARVIS_DATA_DIR", raising=False) # the default path, no override
monkeypatch.setattr(cfg, "DATA_DIR", writable_dir)
monkeypatch.setattr(cfg, "_data_dir_cache", None, raising=False)
@@ -123,6 +124,7 @@ def test_resolve_writable_data_dir_default_unchanged_when_writable(monkeypatch,
def test_resolve_writable_data_dir_falls_back_when_project_dir_unwritable(monkeypatch, tmp_path):
unwritable_dir = tmp_path / "readonly_data"
fallback_dir = tmp_path / "user_data_dir"
+ monkeypatch.delenv("JARVIS_DATA_DIR", raising=False) # the default path, no override
monkeypatch.setattr(cfg, "DATA_DIR", unwritable_dir)
monkeypatch.setattr(cfg, "_data_dir_cache", None, raising=False)
monkeypatch.setattr("dodaios.core.paths.user_data_dir", lambda: fallback_dir)
diff --git a/tests/unit/core/test_hermetic_test_data_dir.py b/tests/unit/core/test_hermetic_test_data_dir.py
new file mode 100644
index 0000000000..d037182f68
--- /dev/null
+++ b/tests/unit/core/test_hermetic_test_data_dir.py
@@ -0,0 +1,29 @@
+"""The test session never resolves the repo's own data dir (#458)."""
+from __future__ import annotations
+
+import os
+from pathlib import Path
+
+from dodaios.core import config
+
+_REPO_ROOT = Path(__file__).resolve().parents[3]
+
+
+def test_session_data_dir_is_a_temp_dir_outside_the_checkout() -> None:
+ env_dir = Path(os.environ["JARVIS_DATA_DIR"]).resolve()
+ assert env_dir.name.startswith("dodaios-test-data-")
+ assert not env_dir.is_relative_to(_REPO_ROOT)
+
+
+def test_config_data_dir_follows_the_session_temp_dir() -> None:
+ assert Path(config.DATA_DIR).resolve() == Path(os.environ["JARVIS_DATA_DIR"]).resolve()
+ assert not Path(config.DATA_DIR).resolve().is_relative_to(_REPO_ROOT / "data")
+
+
+def test_memory_data_dir_defaults_to_the_session_temp_dir() -> None:
+ from dodaios.core.config import JarvisConfig, MemoryConfig
+
+ expected = Path(os.environ["JARVIS_DATA_DIR"]).resolve()
+ assert Path(MemoryConfig().data_dir).resolve() == expected
+ assert Path(JarvisConfig().memory.data_dir).resolve() == expected
+ assert MemoryConfig(data_dir="./elsewhere").data_dir == "./elsewhere"
diff --git a/tests/unit/core/test_secret_locked_keyring.py b/tests/unit/core/test_secret_locked_keyring.py
index e09c813293..422d87a48d 100644
--- a/tests/unit/core/test_secret_locked_keyring.py
+++ b/tests/unit/core/test_secret_locked_keyring.py
@@ -59,6 +59,8 @@ def locked_os_keyring(monkeypatch, tmp_path):
"""Install a locked (non-fail) OS keyring; file store writes under tmp."""
original = keyring.get_keyring()
keyring.set_keyring(_LockedKeyring())
+ # The suite-wide JARVIS_DATA_DIR would win over DATA_DIR for the file store.
+ monkeypatch.delenv("JARVIS_DATA_DIR", raising=False)
monkeypatch.setattr(c, "DATA_DIR", tmp_path)
monkeypatch.setattr(c, "_KEYRING_BACKEND_READY", False)
if hasattr(c, "_FILE_BACKEND_ACTIVE"):
diff --git a/tests/unit/ui/test_launcher_boot_trace.py b/tests/unit/ui/test_launcher_boot_trace.py
index 662fe97bc6..b8cd8d66bc 100644
--- a/tests/unit/ui/test_launcher_boot_trace.py
+++ b/tests/unit/ui/test_launcher_boot_trace.py
@@ -25,7 +25,9 @@ def test_early_log_path_matches_the_data_dir_the_app_uses(monkeypatch):
from dodaios.ui.desktop_log import desktop_log_path
monkeypatch.delenv("JARVIS_DATA_DIR", raising=False)
- assert desktop_log_path() == config.DATA_DIR / "jarvis_desktop.log"
+ # config.DATA_DIR was resolved at import under the suite's JARVIS_DATA_DIR;
+ # resolve config's own rule again without the override.
+ assert desktop_log_path() == config._resolve_data_dir() / "jarvis_desktop.log"
def test_early_log_path_honours_the_env_override(monkeypatch, tmp_path: Path):