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.

fix: keep the test suite out of the checkout's data dir (#1119)

Ruben Lütke23b5b975ea61
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 32e0eaa2c7..fd43fde340 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -526,6 +526,15 @@ jobs:
env:
SHARD: ${{ matrix.shard }}
run: python scripts/ci/ratchet_tests.py check --baseline scripts/ci/test-baseline-linux.json "out/test-report-linux-$SHARD.json"
+ - name: The suite left the checkout's data dir alone (#458)
+ run: |
+ # Every store follows JARVIS_DATA_DIR, which tests/conftest.py points
+ # at a temp dir. A data/ in the checkout is a path that ignores it.
+ if [ -e data ]; then
+ echo "::error title=Tests wrote into data/::The test suite created entries under the checkout's data/ (#458). Derive the path from the configured data dir."
+ find data | head -50
+ exit 1
+ fi
- name: Upload shard report
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
@@ -582,6 +591,15 @@ jobs:
env:
SHARD: ${{ matrix.shard }}
run: python scripts/ci/ratchet_tests.py check --baseline scripts/ci/test-baseline-windows.json "out/test-report-windows-$SHARD.json"
+ - name: The suite left the checkout's data dir alone (#458)
+ run: |
+ # Every store follows JARVIS_DATA_DIR, which tests/conftest.py points
+ # at a temp dir. A data/ in the checkout is a path that ignores it.
+ if [ -e data ]; then
+ echo "::error title=Tests wrote into data/::The test suite created entries under the checkout's data/ (#458). Derive the path from the configured data dir."
+ find data | head -50
+ exit 1
+ fi
- name: Upload shard report
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
diff --git a/dodaios/core/config.py b/dodaios/core/config.py
index 7d3a812823..a4bb092d33 100644
--- a/dodaios/core/config.py
+++ b/dodaios/core/config.py
@@ -89,6 +89,17 @@ DATA_DIR_SOURCE = data_dir_source()
_data_dir_logged = False
+def memory_data_dir(cfg: Any) -> Path:
+ """``cfg.memory.data_dir``, or :data:`DATA_DIR` when ``cfg`` carries none.
+
+ For callers that may run without a config (a runtime built without one,
+ a stub in a test): the fallback is the runtime data dir, never a
+ cwd-relative ``data/`` (#458).
+ """
+ raw = getattr(getattr(cfg, "memory", None), "data_dir", None)
+ return Path(raw) if raw else DATA_DIR
+
+
def data_dir_info() -> dict[str, str]:
"""The active data directory and where it came from, for diagnostics."""
return {"path": str(DATA_DIR), "source": DATA_DIR_SOURCE}
diff --git a/dodaios/core/paths.py b/dodaios/core/paths.py
index 98c117cada..fc73789c16 100644
--- a/dodaios/core/paths.py
+++ b/dodaios/core/paths.py
@@ -138,6 +138,25 @@ def repo_root() -> Path:
return Path(__file__).resolve().parents[2]
+def runtime_data_dir() -> Path:
+ """The runtime data dir: ``JARVIS_DATA_DIR``, else the checkout's instance dir.
+
+ The same rule as ``dodaios.core.config.DATA_DIR`` (both resolve through
+ ``dodaios.core.instance.resolve_data_dir``), for modules that must not
+ import the config. Read on every call. The app runs from the checkout, so
+ without an override this is the ``data/`` a bare relative path meant;
+ unlike one, it does not depend on the process cwd (#458).
+ """
+ from dodaios.core.instance import resolve_data_dir
+
+ return resolve_data_dir(repo_root())
+
+
+def flight_recorder_dir() -> Path:
+ """``<data dir>/flight_recorder``: the event JSONL files and their ``blobs/``."""
+ return runtime_data_dir() / "flight_recorder"
+
+
def default_doc_roots() -> list[Path]:
"""Default discovery roots for the documentation registry.
@@ -276,6 +295,8 @@ __all__ = [
"skill_prefs_path",
"docs_index_db_path",
"repo_root",
+ "runtime_data_dir",
+ "flight_recorder_dir",
"default_doc_roots",
"board_db_path",
"ensure_user_dirs",
diff --git a/dodaios/core/review/audit.py b/dodaios/core/review/audit.py
index 3043887326..44d7252f51 100644
--- a/dodaios/core/review/audit.py
+++ b/dodaios/core/review/audit.py
@@ -87,19 +87,27 @@ class AuditRecord(BaseModel):
class ReviewAudit:
"""Append-only JSON-Lines logger for review iterations.
- Default path: `data/review.log` relative to the current working
- directory. Overridable via the `path` constructor argument — e.g.
- for tests via `tmp_path`.
+ Default path: `review.log` in the runtime data directory
+ (`dodaios.core.config.DATA_DIR`), so `JARVIS_DATA_DIR` moves it with
+ every other store (#458). Overridable via the `path` constructor
+ argument — e.g. for tests via `tmp_path`.
"""
- DEFAULT_PATH: ClassVar[Path] = Path("data") / "review.log"
+ DEFAULT_FILENAME: ClassVar[str] = "review.log"
def __init__(self, path: Path | str | None = None) -> None:
self._path: Path = (
- Path(path) if path is not None else self.DEFAULT_PATH
+ Path(path) if path is not None else self.default_path()
)
self._lock = threading.Lock()
+ @classmethod
+ def default_path(cls) -> Path:
+ """`<data dir>/review.log`, read when the logger is built."""
+ from dodaios.core import config # lazy: config imports half the app
+
+ return Path(config.DATA_DIR) / cls.DEFAULT_FILENAME
+
@property
def path(self) -> Path:
return self._path
diff --git a/dodaios/core/self_mod/audit.py b/dodaios/core/self_mod/audit.py
index 3290ba812e..91ce65cb96 100644
--- a/dodaios/core/self_mod/audit.py
+++ b/dodaios/core/self_mod/audit.py
@@ -48,17 +48,25 @@ def _is_sensitive_path(path: str | None) -> bool:
class SelfModAudit:
"""Append-only JSON-Lines logger.
- Default path: `data/self_mod.log` relative to the current working
- directory (Plan-§AD-6). Overridable via the `path` constructor argument —
- e.g. in tests via `tmp_path`.
+ Default path: `self_mod.log` in the runtime data directory
+ (`dodaios.core.config.DATA_DIR`, Plan-§AD-6), so `JARVIS_DATA_DIR` moves it
+ with every other store (#458). Overridable via the `path` constructor
+ argument — e.g. in tests via `tmp_path`.
"""
- DEFAULT_PATH: ClassVar[Path] = Path("data") / "self_mod.log"
+ DEFAULT_FILENAME: ClassVar[str] = "self_mod.log"
def __init__(self, path: Path | str | None = None) -> None:
- self._path: Path = Path(path) if path is not None else self.DEFAULT_PATH
+ self._path: Path = Path(path) if path is not None else self.default_path()
self._lock = threading.Lock()
+ @classmethod
+ def default_path(cls) -> Path:
+ """`<data dir>/self_mod.log`, read when the logger is built."""
+ from dodaios.core import config # lazy: config imports half the app
+
+ return Path(config.DATA_DIR) / cls.DEFAULT_FILENAME
+
@property
def path(self) -> Path:
return self._path
diff --git a/dodaios/cu/engine.py b/dodaios/cu/engine.py
index bd8e9b8eb7..1de011a00c 100644
--- a/dodaios/cu/engine.py
+++ b/dodaios/cu/engine.py
@@ -44,6 +44,7 @@ from dataclasses import dataclass
from pathlib import Path
from typing import Any
+from dodaios.core.paths import flight_recorder_dir
from dodaios.core.protocols import CancelToken, HarnessResult, HarnessTask, ImageBlock
from dodaios.cu import conventions as conv_mod
from dodaios.cu.brain_call import (
@@ -1028,7 +1029,7 @@ async def run_cu_loop(
# tests, isolated rigs, headless embeddings). Synchronously writing a
# never-referenced JPEG there only adds disk/antivirus latency. Live
# app contexts keep the exact existing recorder path and semantics.
- blob_dir=(Path("data") / "flight_recorder" / "blobs" if bus is not None else None),
+ blob_dir=(flight_recorder_dir() / "blobs" if bus is not None else None),
)
consecutive_failures = 0
diff --git a/dodaios/memory/wiki/cli.py b/dodaios/memory/wiki/cli.py
index 233a86b641..9432758ed5 100644
--- a/dodaios/memory/wiki/cli.py
+++ b/dodaios/memory/wiki/cli.py
@@ -30,6 +30,8 @@ import logging
import sys
from pathlib import Path
+from dodaios.core.paths import runtime_data_dir
+
from .vault_root import resolve_vault_root
# Windows console encoding (cp1252 by default) breaks on em-dashes and
@@ -47,8 +49,11 @@ REPO_ROOT = Path(__file__).resolve().parents[3]
# The legacy "data/workspace" tree is the soft-disabled B4 Curator snapshot
# and is NOT the search vault.
DEFAULT_VAULT = resolve_vault_root(None).path
-DEFAULT_BACKUP_DIR = REPO_ROOT / "data" / "backups"
-DEFAULT_DB = REPO_ROOT / "data" / "jarvis.db"
+# The runtime data dir (``JARVIS_DATA_DIR`` or ``<checkout>/data``), the same
+# rule as ``dodaios.core.config.DATA_DIR``, not a hard-coded ``data/`` (#458).
+_DATA_DIR = runtime_data_dir()
+DEFAULT_BACKUP_DIR = _DATA_DIR / "backups"
+DEFAULT_DB = _DATA_DIR / "jarvis.db"
def _build_curator(vault_root: Path):
diff --git a/dodaios/memory/wiki/db_path.py b/dodaios/memory/wiki/db_path.py
index dddfe35925..4018d53750 100644
--- a/dodaios/memory/wiki/db_path.py
+++ b/dodaios/memory/wiki/db_path.py
@@ -3,12 +3,16 @@ from __future__ import annotations
from pathlib import Path
-from dodaios.core.paths import repo_root
+from dodaios.core.paths import repo_root, runtime_data_dir
def resolve_wiki_db_path(data_dir: str | Path | None = None) -> Path:
- """Return one absolute ``jarvis.db`` path independent of process CWD."""
- raw = Path(data_dir) if data_dir is not None else Path("data")
+ """Return one absolute ``jarvis.db`` path independent of process CWD.
+
+ A relative ``data_dir`` is anchored at the checkout. Without one, the
+ runtime data dir (``JARVIS_DATA_DIR`` or ``<checkout>/data``, #458).
+ """
+ raw = Path(data_dir) if data_dir is not None else runtime_data_dir()
directory = raw if raw.is_absolute() else repo_root() / raw
return (directory / "jarvis.db").resolve(strict=False)
diff --git a/dodaios/memory/wiki/search.py b/dodaios/memory/wiki/search.py
index b0a3ba61f1..82e692a217 100644
--- a/dodaios/memory/wiki/search.py
+++ b/dodaios/memory/wiki/search.py
@@ -375,12 +375,7 @@ def _normalise_bm25(raw: float) -> float:
def _default_db_path() -> Path:
- """Resolve ``data/jarvis.db`` relative to the project root.
-
- Walks upward from this file's location to find the directory
- containing ``dodaios/`` as a package, then appends ``data/jarvis.db``.
- Falls back to a sibling ``data/`` if the walk fails.
- """
+ """``jarvis.db`` in the runtime data dir (see ``resolve_wiki_db_path``)."""
from dodaios.memory.wiki.db_path import resolve_wiki_db_path
return resolve_wiki_db_path()
diff --git a/dodaios/plugins/stt/__init__.py b/dodaios/plugins/stt/__init__.py
index 5bb0f13629..88d049273a 100644
--- a/dodaios/plugins/stt/__init__.py
+++ b/dodaios/plugins/stt/__init__.py
@@ -812,16 +812,28 @@ def _build_local_fallback(stt_cfg: Any, language: str | None) -> Any:
)
+def _probe_cache_dir() -> Path:
+ """Directory of the persisted wake probe results.
+
+ ``JARVIS__MEMORY__DATA_DIR`` (the memory-data override) wins; otherwise the
+ runtime data dir (``JARVIS_DATA_DIR`` or ``<checkout>/data``), resolved the
+ same way as ``wake_constants._vosk_models_root`` — never the cwd (#458).
+ """
+ base = os.environ.get("JARVIS__MEMORY__DATA_DIR")
+ if base:
+ return Path(base)
+ from dodaios.core.paths import runtime_data_dir
+
+ return runtime_data_dir()
+
+
def _wake_cuda_cache_path() -> Path:
"""Location of the persisted CUDA-availability probe result.
CUDA presence is a stable hardware fact, so the probe result is cached ACROSS
- process restarts (not just in-process). Honours the same data-dir env seam the
- rest of the app uses (``JARVIS__MEMORY__DATA_DIR``); defaults to ``./data``
- relative to the project-root CWD.
+ process restarts (not just in-process). Lives in :func:`_probe_cache_dir`.
"""
- base = os.environ.get("JARVIS__MEMORY__DATA_DIR") or "data"
- return Path(base) / "wake_cuda_probe.json"
+ return _probe_cache_dir() / "wake_cuda_probe.json"
@lru_cache(maxsize=1)
@@ -895,8 +907,7 @@ def _wake_gpu_probe_cache_path() -> Path:
CUDA but every CTranslate2 inference hung under the then-current runtime).
Delete the file to force a re-probe after a GPU/driver change.
"""
- base = os.environ.get("JARVIS__MEMORY__DATA_DIR") or "data"
- return Path(base) / "wake_gpu_probe.json"
+ return _probe_cache_dir() / "wake_gpu_probe.json"
# Success marker the probe subprocess prints AFTER its real CUDA inferences.
diff --git a/dodaios/society/chat_binding.py b/dodaios/society/chat_binding.py
index 4b78356f41..5518a13d54 100644
--- a/dodaios/society/chat_binding.py
+++ b/dodaios/society/chat_binding.py
@@ -22,7 +22,6 @@ from __future__ import annotations
import logging
from collections.abc import Callable
-from pathlib import Path
from typing import Any, Final
from .communication import response_instruction
@@ -75,7 +74,9 @@ def pair_for(cfg: Any, agent: AgentRecord) -> tuple[str, str, str]:
def _workspace(cfg: Any, agent: AgentRecord) -> str:
- data_dir = Path(getattr(getattr(cfg, "memory", None), "data_dir", None) or "data")
+ from dodaios.core.config import memory_data_dir
+
+ data_dir = memory_data_dir(cfg)
folder = data_dir / (agent.workspace_dir or f"society/{agent.agent_id}/workspace")
try:
folder.mkdir(parents=True, exist_ok=True)
diff --git a/dodaios/society/surface.py b/dodaios/society/surface.py
index 7f928c01df..df13b0fb92 100644
--- a/dodaios/society/surface.py
+++ b/dodaios/society/surface.py
@@ -673,8 +673,9 @@ def _contained_folder_tools(workspace: Path, permission_mode: str) -> dict[str,
def _workspace_fallback(cfg: Any, agent_id: str) -> Path:
- data_dir = Path(getattr(getattr(cfg, "memory", None), "data_dir", None) or "data")
- return data_dir / "society" / agent_id / "workspace"
+ from dodaios.core.config import memory_data_dir
+
+ return memory_data_dir(cfg) / "society" / agent_id / "workspace"
def _permission_override(runtime: Any, session: Any) -> str:
diff --git a/dodaios/speech/local_models.py b/dodaios/speech/local_models.py
index 19a96a1ab2..048ccd5943 100644
--- a/dodaios/speech/local_models.py
+++ b/dodaios/speech/local_models.py
@@ -319,8 +319,14 @@ def models_root(data_dir: str | None = None) -> Path:
Honours the same ``JARVIS__MEMORY__DATA_DIR`` seam as the wake-model
fetcher, so a headless install that relocated its data dir (ADR-0027) keeps
every model in one place instead of scattering them across two conventions.
+ Without either, the runtime data dir (``JARVIS_DATA_DIR`` or
+ ``<checkout>/data``), never the cwd (#458).
"""
- base = data_dir or os.environ.get("JARVIS__MEMORY__DATA_DIR") or "data"
+ base = data_dir or os.environ.get("JARVIS__MEMORY__DATA_DIR")
+ if not base:
+ from dodaios.core.paths import runtime_data_dir
+
+ base = str(runtime_data_dir())
return Path(base) / "models"
diff --git a/dodaios/telemetry/recorder.py b/dodaios/telemetry/recorder.py
index 30bdd89904..afebf3b945 100644
--- a/dodaios/telemetry/recorder.py
+++ b/dodaios/telemetry/recorder.py
@@ -224,6 +224,10 @@ def attach_flight_recorder(
"""
if not enabled:
return None
- rec = FlightRecorder(data_dir=data_dir or (Path("data") / "flight_recorder"))
+ if data_dir is None:
+ from dodaios.core.paths import flight_recorder_dir
+
+ data_dir = flight_recorder_dir()
+ rec = FlightRecorder(data_dir=data_dir)
rec.attach(bus)
return rec
diff --git a/dodaios/telemetry/tool_usage.py b/dodaios/telemetry/tool_usage.py
index 2d9d793826..15bb3e47cf 100644
--- a/dodaios/telemetry/tool_usage.py
+++ b/dodaios/telemetry/tool_usage.py
@@ -23,12 +23,14 @@ from datetime import date, datetime, timedelta
from pathlib import Path
from typing import Any
+from dodaios.core.paths import flight_recorder_dir
+
log = logging.getLogger(__name__)
__all__ = ["DEFAULT_DATA_DIR", "tool_usage"]
#: Where the desktop app's flight recorder writes (``server._init_flight_recorder``).
-DEFAULT_DATA_DIR = Path("data") / "flight_recorder"
+DEFAULT_DATA_DIR = flight_recorder_dir()
_EVENT = "ActionExecuted"
#: Shares of all calls for which ``coverage`` says how many tools carry them.
diff --git a/dodaios/ui/web/deck_routes.py b/dodaios/ui/web/deck_routes.py
index 0bf0a95bc8..b769911a4d 100644
--- a/dodaios/ui/web/deck_routes.py
+++ b/dodaios/ui/web/deck_routes.py
@@ -29,11 +29,11 @@ from __future__ import annotations
import logging
import re
-from pathlib import Path
from typing import Any
from fastapi import APIRouter, HTTPException, Response
+from dodaios.core.paths import flight_recorder_dir
from dodaios.screen_context.last_frame import get_last_frame_mirror
log = logging.getLogger(__name__)
@@ -43,7 +43,7 @@ router = APIRouter(prefix="/api/deck", tags=["deck"])
#: The Computer-Use harness writes here (``dodaios/cu/engine.py``) — the same
#: constant, not a lookup, so a moved recorder shows up as a test failure
#: rather than a route that silently serves nothing.
-CU_BLOB_DIR = Path("data") / "flight_recorder" / "blobs"
+CU_BLOB_DIR = flight_recorder_dir() / "blobs"
_SHA256_RE = re.compile(r"^[0-9a-f]{64}$")
_NO_STORE = {"Cache-Control": "no-store"}
diff --git a/dodaios/ui/web/self_mod_routes.py b/dodaios/ui/web/self_mod_routes.py
index d2bd3dbe4e..69b9e68949 100644
--- a/dodaios/ui/web/self_mod_routes.py
+++ b/dodaios/ui/web/self_mod_routes.py
@@ -87,7 +87,7 @@ def _redact_audit_event(event: dict[str, Any]) -> dict[str, Any]:
def _get_audit(request: Request) -> SelfModAudit:
audit = getattr(request.app.state, "self_mod_audit", None)
if audit is None:
- # Fallback: SelfModAudit() uses the default path data/self_mod.log.
+ # Fallback: SelfModAudit() writes self_mod.log in the data dir.
audit = SelfModAudit()
return audit
diff --git a/dodaios/ui/web/server.py b/dodaios/ui/web/server.py
index 8b630623c8..c76c026db8 100644
--- a/dodaios/ui/web/server.py
+++ b/dodaios/ui/web/server.py
@@ -3254,15 +3254,16 @@ class WebServer:
)
return
- # Relative path on purpose — it must match what the writers actually
- # use, NOT cfg.memory.data_dir. The production writer is the Vision
- # ScreenshotSource (dodaios/vision/engine.py constructs it with no
- # blob_dir → falls back to the relative _DEFAULT_BLOB_DIR in
- # dodaios/vision/screenshot.py = data/flight_recorder/blobs). It ignores
- # cfg.memory.data_dir, so deriving from that key would make the sweep a
- # silent no-op whenever data_dir is overridden. Same process → same cwd
- # → same directory as the writer.
- flight_recorder_dir = Path("data") / "flight_recorder"
+ # The same directory the writers use, NOT cfg.memory.data_dir. The
+ # production writer is the Vision ScreenshotSource
+ # (dodaios/vision/engine.py constructs it with no blob_dir → falls back
+ # to _DEFAULT_BLOB_DIR in dodaios/vision/screenshot.py =
+ # flight_recorder_dir()/blobs). It ignores cfg.memory.data_dir, so
+ # deriving from that key would make the sweep a silent no-op whenever
+ # data_dir is overridden.
+ from dodaios.core.paths import flight_recorder_dir as _flight_recorder_dir
+
+ flight_recorder_dir = _flight_recorder_dir()
# The one-shot boot sweep is pure cleanup of old blobs — nothing
# downstream consumes its stats (they are only logged). Awaiting it sat
@@ -3307,12 +3308,13 @@ class WebServer:
auto-flushes every second, and oversized event blobs land under
``blobs/`` which the screenshot-retention task already prunes.
"""
+ from dodaios.core.paths import flight_recorder_dir
from dodaios.telemetry.recorder import attach_flight_recorder
rec = attach_flight_recorder(
self.bus,
enabled=self.cfg.telemetry.flight_recorder,
- data_dir=Path("data") / "flight_recorder",
+ data_dir=flight_recorder_dir(),
)
if rec is None:
logger.info("Flight recorder disabled (telemetry.flight_recorder=false)")
diff --git a/dodaios/ui/web/setup_routes.py b/dodaios/ui/web/setup_routes.py
index b65c4c46d8..1362ec4ab9 100644
--- a/dodaios/ui/web/setup_routes.py
+++ b/dodaios/ui/web/setup_routes.py
@@ -202,10 +202,10 @@ def _reindex_vault_fts(request: Request, jarvis_root: Path) -> None:
try:
config = getattr(request.app.state, "config", None)
+ from dodaios.core.config import memory_data_dir
from dodaios.memory.wiki.db_path import resolve_wiki_db_path
- data_dir = getattr(getattr(config, "memory", None), "data_dir", "./data")
- db_path = resolve_wiki_db_path(data_dir)
+ db_path = resolve_wiki_db_path(memory_data_dir(config))
db_path.parent.mkdir(parents=True, exist_ok=True)
conn = sqlite3.connect(str(db_path), check_same_thread=False)
try:
diff --git a/dodaios/vision/screenshot.py b/dodaios/vision/screenshot.py
index 193e761e31..f4672865ad 100644
--- a/dodaios/vision/screenshot.py
+++ b/dodaios/vision/screenshot.py
@@ -30,6 +30,7 @@ from pathlib import Path
from typing import Literal
from uuid import uuid4
+from dodaios.core.paths import flight_recorder_dir
from dodaios.core.protocols import CancelToken, Observation
from dodaios.core.win32_dpi import (
ensure_dpi_awareness as _ensure_dpi_awareness,
@@ -42,7 +43,7 @@ logger = logging.getLogger(__name__)
# Default blob directory — lives under repo-root/data. Can be overridden via
# the constructor (e.g. for tests).
-_DEFAULT_BLOB_DIR = Path("data") / "flight_recorder" / "blobs"
+_DEFAULT_BLOB_DIR = flight_recorder_dir() / "blobs"
# H1 (DEEP-DIVE-AUDIT-2026-06-19): on macOS, screen capture is gated behind a
# TCC "Screen Recording" grant. Without it mss returns ONLY the desktop
diff --git a/scripts/check-working-tree.ps1 b/scripts/check-working-tree.ps1
index c426f43702..75605bf0a4 100644
--- a/scripts/check-working-tree.ps1
+++ b/scripts/check-working-tree.ps1
@@ -7,7 +7,7 @@
on disk. For every file listed in HEAD that does NOT exist on disk,
runs ``git checkout HEAD -- <file>`` to bring it back, logs a banner
line per restored file, and writes a structured log block to
- ``data/working-tree-check.log``.
+ ``data/working-tree-check.log`` (``$env:JARVIS_DATA_DIR`` when set).
Design contract:
@@ -87,7 +87,14 @@ if (-not (Test-Path -LiteralPath $RepoRoot)) {
Set-Location -LiteralPath $RepoRoot
-$dataDir = Join-Path $RepoRoot "data"
+# The log lives in the app's data dir: JARVIS_DATA_DIR when set (the same
+# override the app honours; the test suite points it at a temp dir, #458),
+# else <RepoRoot>/data.
+if (-not [string]::IsNullOrWhiteSpace($env:JARVIS_DATA_DIR)) {
+ $dataDir = $env:JARVIS_DATA_DIR.Trim()
+} else {
+ $dataDir = Join-Path $RepoRoot "data"
+}
if (-not (Test-Path -LiteralPath $dataDir)) {
try { New-Item -ItemType Directory -Path $dataDir -Force | Out-Null } catch { }
}
diff --git a/tests/conftest.py b/tests/conftest.py
index be80223e0a..cce3169b62 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -15,6 +15,10 @@ _REPO_ROOT = Path(__file__).resolve().parent.parent
if str(_REPO_ROOT) not in sys.path:
sys.path.insert(0, str(_REPO_ROOT))
+# Taken before the first dodaios import, which could already write there.
+_REPO_DATA_DIR = _REPO_ROOT / "data"
+_REPO_DATA_DIR_EXISTED = _REPO_DATA_DIR.exists()
+
# 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
@@ -49,6 +53,50 @@ def pytest_configure(config) -> None: # noqa: ANN001
)
+def _repo_data_dir_leftovers() -> list[str]:
+ """What a session left in ``<repo>/data`` when it started without one.
+
+ Only a checkout that had no ``data/`` at session start is judged: there any
+ entry is the suite's own. A checkout that runs the app owns a live
+ ``data/`` that the app writes to while the tests run, so it is skipped.
+ """
+ if _REPO_DATA_DIR_EXISTED or not _REPO_DATA_DIR.exists():
+ return []
+ entries = sorted(
+ p.relative_to(_REPO_ROOT).as_posix() for p in _REPO_DATA_DIR.rglob("*")
+ )
+ return entries or [_REPO_DATA_DIR.relative_to(_REPO_ROOT).as_posix() + "/"]
+
+
+def pytest_sessionfinish(session, exitstatus) -> None: # noqa: ANN001, ARG001
+ """Fail the session when the suite wrote into ``<repo>/data`` (#458).
+
+ Every store must follow the session temp dir above. Checked once, by the
+ controlling process (an xdist worker would see its siblings' writes).
+ """
+ if hasattr(session.config, "workerinput"):
+ return
+ leftovers = _repo_data_dir_leftovers()
+ if not leftovers:
+ return
+ lines = [f" {entry}" for entry in leftovers[:20]]
+ if len(leftovers) > 20:
+ lines.append(f" ... and {len(leftovers) - 20} more")
+ message = "\n".join([
+ "The test session wrote into the checkout's data dir, which every store "
+ "must leave alone (#458). Derive the path from the configured data dir:",
+ *lines,
+ ])
+ reporter = session.config.pluginmanager.get_plugin("terminalreporter")
+ if reporter is not None:
+ reporter.ensure_newline()
+ reporter.write_sep("=", "stray writes into <repo>/data", red=True)
+ reporter.write_line(message)
+ else:
+ sys.stderr.write(message + "\n")
+ session.exitstatus = pytest.ExitCode.TESTS_FAILED
+
+
@pytest.fixture(autouse=True)
def _not_the_main_instance(monkeypatch): # noqa: ANN001
"""No test inherits the desktop app's main-instance flag.
diff --git a/tests/review/test_audit.py b/tests/review/test_audit.py
index 3adb46f544..88b3acaff4 100644
--- a/tests/review/test_audit.py
+++ b/tests/review/test_audit.py
@@ -52,9 +52,12 @@ def test_constructor_path_override(tmp_path: Path) -> None:
assert audit.path == custom
-def test_default_path_is_data_review_log() -> None:
- audit = ReviewAudit()
- assert audit.path == Path("data") / "review.log"
+def test_default_path_is_review_log_in_the_data_dir(monkeypatch, tmp_path: Path) -> None:
+ """The default follows the runtime data dir, not the cwd (#458)."""
+ from dodaios.core import config
+
+ monkeypatch.setattr(config, "DATA_DIR", tmp_path)
+ assert ReviewAudit().path == tmp_path / "review.log"
def test_constructor_accepts_string_path(tmp_path: Path) -> None:
diff --git a/tests/unit/core/test_data_dir_defaults.py b/tests/unit/core/test_data_dir_defaults.py
new file mode 100644
index 0000000000..82a1cda87f
--- /dev/null
+++ b/tests/unit/core/test_data_dir_defaults.py
@@ -0,0 +1,95 @@
+"""Stores without an explicit path follow the runtime data dir, not the cwd (#458).
+
+``JARVIS_DATA_DIR`` (the test session points it at a temp dir) and
+``dodaios.core.config.DATA_DIR`` name the data dir; a default that is a bare
+``data/`` lands in whatever directory the process runs from instead.
+"""
+from __future__ import annotations
+
+from pathlib import Path
+from types import SimpleNamespace
+
+import pytest
+
+from dodaios.core import config
+
+
+def runtime_dir(monkeypatch, tmp_path: Path) -> Path: # noqa: ANN001
+ """A runtime data dir that differs from the cwd."""
+ target = tmp_path / "runtime"
+ monkeypatch.setenv("JARVIS_DATA_DIR", str(target))
+ monkeypatch.delenv("JARVIS__MEMORY__DATA_DIR", raising=False)
+ monkeypatch.setattr(config, "DATA_DIR", target)
+ work = tmp_path / "cwd"
+ work.mkdir()
+ monkeypatch.chdir(work)
+ return target
+
+
+def test_memory_data_dir_prefers_the_config_value(runtime_dir: Path, tmp_path: Path) -> None:
+ cfg = SimpleNamespace(memory=SimpleNamespace(data_dir=str(tmp_path / "configured")))
+ assert config.memory_data_dir(cfg) == tmp_path / "configured"
+
+
[email protected]("cfg", [None, SimpleNamespace(), SimpleNamespace(memory=None)])
+def test_memory_data_dir_without_a_value_is_the_runtime_dir(runtime_dir: Path, cfg) -> None: # noqa: ANN001
+ assert config.memory_data_dir(cfg) == runtime_dir
+
+
+def test_wiki_db_without_a_data_dir_is_in_the_runtime_dir(runtime_dir: Path) -> None:
+ from dodaios.memory.wiki.db_path import resolve_wiki_db_path
+
+ assert resolve_wiki_db_path() == (runtime_dir / "jarvis.db").resolve()
+
+
+def test_wiki_db_with_a_relative_data_dir_is_anchored_at_the_checkout(runtime_dir: Path) -> None:
+ from dodaios.core.paths import repo_root
+ from dodaios.memory.wiki.db_path import resolve_wiki_db_path
+
+ assert resolve_wiki_db_path("./data") == (repo_root() / "data" / "jarvis.db").resolve()
+
+
+def test_speech_models_without_an_override_are_in_the_runtime_dir(runtime_dir: Path) -> None:
+ from dodaios.speech.local_models import models_root
+
+ assert models_root() == runtime_dir / "models"
+
+
+def test_wake_gpu_probe_without_an_override_is_in_the_runtime_dir(runtime_dir: Path) -> None:
+ from dodaios.plugins.stt import _wake_gpu_probe_cache_path
+
+ assert _wake_gpu_probe_cache_path() == runtime_dir / "wake_gpu_probe.json"
+
+
+def test_society_workspace_without_a_config_is_in_the_runtime_dir(runtime_dir: Path) -> None:
+ from dodaios.society.surface import _workspace_fallback
+
+ assert _workspace_fallback(None, "scout") == runtime_dir / "society" / "scout" / "workspace"
+
+
+def test_wiki_cli_defaults_follow_the_session_data_dir() -> None:
+ """Resolved at import, under the session's temp ``JARVIS_DATA_DIR``."""
+ import os
+
+ from dodaios.memory.wiki import cli
+
+ session_dir = Path(os.environ["JARVIS_DATA_DIR"])
+ assert cli.DEFAULT_DB == session_dir / "jarvis.db"
+ assert cli.DEFAULT_BACKUP_DIR == session_dir / "backups"
+
+
+def test_flight_recorder_dir_is_in_the_runtime_dir(runtime_dir: Path) -> None:
+ from dodaios.core.paths import flight_recorder_dir, runtime_data_dir
+
+ assert runtime_data_dir() == runtime_dir
+ assert flight_recorder_dir() == runtime_dir / "flight_recorder"
+
+
+def test_attached_flight_recorder_writes_into_the_runtime_dir(runtime_dir: Path) -> None:
+ from dodaios.core.bus import EventBus
+ from dodaios.telemetry.recorder import attach_flight_recorder
+
+ rec = attach_flight_recorder(EventBus(), enabled=True)
+ assert rec is not None
+ assert rec._data_dir == runtime_dir / "flight_recorder"
diff --git a/tests/unit/core/test_repo_data_dir_guard.py b/tests/unit/core/test_repo_data_dir_guard.py
new file mode 100644
index 0000000000..a92bfa37e5
--- /dev/null
+++ b/tests/unit/core/test_repo_data_dir_guard.py
@@ -0,0 +1,38 @@
+"""The session-end guard against writes into ``<repo>/data`` (#458)."""
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+import pytest
+
+
+def guard(monkeypatch, tmp_path: Path): # noqa: ANN001, ANN201
+ conftest = sys.modules["tests.conftest"]
+ monkeypatch.setattr(conftest, "_REPO_ROOT", tmp_path)
+ monkeypatch.setattr(conftest, "_REPO_DATA_DIR", tmp_path / "data")
+ return conftest
+
+
+def test_a_fresh_checkout_left_alone_passes(guard, monkeypatch) -> None: # noqa: ANN001
+ monkeypatch.setattr(guard, "_REPO_DATA_DIR_EXISTED", False)
+ assert guard._repo_data_dir_leftovers() == []
+
+
+def test_a_fresh_checkout_with_a_new_data_dir_is_reported(
+ guard, monkeypatch, tmp_path: Path # noqa: ANN001
+) -> None:
+ monkeypatch.setattr(guard, "_REPO_DATA_DIR_EXISTED", False)
+ (tmp_path / "data").mkdir()
+ assert guard._repo_data_dir_leftovers() == ["data/"]
+ (tmp_path / "data" / "society").mkdir()
+ (tmp_path / "data" / "self_mod.log").write_text("{}\n", encoding="utf-8")
+ assert guard._repo_data_dir_leftovers() == ["data/self_mod.log", "data/society"]
+
+
+def test_a_live_data_dir_is_not_judged(guard, monkeypatch, tmp_path: Path) -> None: # noqa: ANN001
+ monkeypatch.setattr(guard, "_REPO_DATA_DIR_EXISTED", True)
+ (tmp_path / "data").mkdir()
+ (tmp_path / "data" / "jarvis.db").write_bytes(b"")
+ assert guard._repo_data_dir_leftovers() == []
diff --git a/tests/unit/plugins/stt/test_wake_whisper_build.py b/tests/unit/plugins/stt/test_wake_whisper_build.py
index 8bea1b77b0..3521e43fd6 100644
--- a/tests/unit/plugins/stt/test_wake_whisper_build.py
+++ b/tests/unit/plugins/stt/test_wake_whisper_build.py
@@ -218,6 +218,16 @@ def test_wake_cuda_cache_path_honours_data_dir_env(tmp_path, monkeypatch) -> Non
assert _wake_cuda_cache_path() == tmp_path / "wake_cuda_probe.json"
+def test_wake_cuda_cache_path_follows_the_runtime_data_dir_not_the_cwd(
+ tmp_path, monkeypatch
+) -> None:
+ """Without the memory override the probe lands in JARVIS_DATA_DIR (#458)."""
+ monkeypatch.delenv("JARVIS__MEMORY__DATA_DIR", raising=False)
+ monkeypatch.setenv("JARVIS_DATA_DIR", str(tmp_path / "runtime"))
+ monkeypatch.chdir(tmp_path)
+ assert _wake_cuda_cache_path() == tmp_path / "runtime" / "wake_cuda_probe.json"
+
+
def test_wake_cuda_available_returns_persisted_value_without_probing(
tmp_path, monkeypatch
) -> None:
diff --git a/tests/unit/scripts/test_check_working_tree.py b/tests/unit/scripts/test_check_working_tree.py
index 33fc58b4d9..55edbc3132 100644
--- a/tests/unit/scripts/test_check_working_tree.py
+++ b/tests/unit/scripts/test_check_working_tree.py
@@ -78,6 +78,13 @@ def _init_repo(repo: Path) -> None:
assert commit.returncode == 0, f"git commit failed: {commit.stderr}"
+def _env_without_data_dir() -> dict[str, str]:
+ """The test env minus ``JARVIS_DATA_DIR``, so the log lands in <repo>/data."""
+ env = dict(os.environ)
+ env.pop("JARVIS_DATA_DIR", None)
+ return env
+
+
def _run_script(repo: Path, *extra_args: str) -> subprocess.CompletedProcess[str]:
"""Invoke check-working-tree.ps1 against ``repo`` and return the result."""
return subprocess.run(
@@ -94,6 +101,7 @@ def _run_script(repo: Path, *extra_args: str) -> subprocess.CompletedProcess[str
encoding="utf-8",
errors="replace",
check=False,
+ env=_env_without_data_dir(),
)
@@ -268,14 +276,17 @@ def test_log_rotation_keeps_last_n_runs(tmp_path: Path) -> None:
# ---------------------------------------------------------------------------
-def test_no_repo_root_arg_uses_script_parent_directory() -> None:
+def test_no_repo_root_arg_uses_script_parent_directory(tmp_path: Path) -> None:
"""Invocation without -RepoRoot must succeed and operate on the real repo.
This mirrors run.bat's call shape exactly. The script's own parent
directory is the live repo on disk; the test asserts a clean exit
- code and a non-empty log block, which is the strongest evidence
- that the param-default fallback works.
+ code and a log block, which is the strongest evidence that the
+ param-default fallback works. ``JARVIS_DATA_DIR`` sends the log to a
+ temp dir, so the checkout's own data dir is never written (#458).
"""
+ env = _env_without_data_dir()
+ env["JARVIS_DATA_DIR"] = str(tmp_path)
result = subprocess.run(
[
"powershell",
@@ -288,15 +299,14 @@ def test_no_repo_root_arg_uses_script_parent_directory() -> None:
encoding="utf-8",
errors="replace",
check=False,
+ env=env,
)
assert result.returncode == 0, (
f"no-arg invocation must not crash. stdout={result.stdout!r} "
f"stderr={result.stderr!r}"
)
- # The live repo has its own data/working-tree-check.log; the run
- # block landed there. We do not assert on that path because it is
- # state outside the test's control, but a clean exit + no stderr
- # noise is enough to pin the regression.
+ log = (tmp_path / "working-tree-check.log").read_text(encoding="utf-8")
+ assert _count_blocks(log) == 1
assert "ParameterArgumentValidationError" not in result.stderr, (
"regression: param-default Split-Path call must not throw"
)
diff --git a/tests/unit/self_mod/test_audit.py b/tests/unit/self_mod/test_audit.py
index c7ba2742f0..f5c42641d7 100644
--- a/tests/unit/self_mod/test_audit.py
+++ b/tests/unit/self_mod/test_audit.py
@@ -109,9 +109,12 @@ class TestRecord:
parsed = json.loads(audit.path.read_text(encoding="utf-8").strip())
assert UUID(parsed["audit_id"]).version == 4
- def test_default_path_is_data_self_mod_log(self) -> None:
- """Plan-§AD-6: `data/self_mod.log`."""
- assert SelfModAudit.DEFAULT_PATH == Path("data") / "self_mod.log"
+ def test_default_path_is_self_mod_log_in_the_data_dir(self, monkeypatch, tmp_path) -> None:
+ """Plan-§AD-6: `self_mod.log` in the runtime data dir, not the cwd (#458)."""
+ from dodaios.core import config
+
+ monkeypatch.setattr(config, "DATA_DIR", tmp_path)
+ assert SelfModAudit().path == tmp_path / "self_mod.log"
# --- Concurrent writes (Plan-AC §7.1) ---