Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(tests): sandbox the config root on one knob, and guard the outcome

Haozhe Wue181523fa3a2
diff --git a/agent/tests/conftest.py b/agent/tests/conftest.py
index 8d2616c39..cd8b06679 100644
--- a/agent/tests/conftest.py
+++ b/agent/tests/conftest.py
@@ -5,6 +5,7 @@ from __future__ import annotations
import atexit
import os
import shutil
+import site
import sys
import tempfile
from pathlib import Path
@@ -36,24 +37,95 @@ if str(AGENT_DIR) not in sys.path:
# sandbox cannot be a pytest fixture (fixtures run AFTER collection); it has to
# be installed at conftest import time, before pytest imports any test module.
#
-# TEST DISCIPLINE: a test that asserts the DEFAULT config-root fallback (e.g.
-# ``get_runtime_root() == Path.home()/".vibe-trading"``) MUST call
-# ``monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)`` first, so it
-# exercises the real fallback instead of silently passing green against this
-# sandbox.
+# The sandbox owns exactly ONE knob: the home directory. ``get_runtime_root()``
+# consults ``VIBE_TRADING_HOME`` first and only falls back to
+# ``Path.home()/".vibe-trading"`` (src/config/paths.py:27-34), so the override is
+# DELETED rather than pointed at the sandbox. Two reasons, both load-bearing:
#
-# On Windows Path.home() ignores $HOME and reads %USERPROFILE%, so we set all
-# three knobs: VIBE_TRADING_HOME (the project's documented Windows-safe
-# override, src/config/paths.py:27-33), HOME (POSIX) and USERPROFILE (Windows).
+# * A developer with ``VIBE_TRADING_HOME`` exported in their shell would
+# otherwise keep resolving to it — the leak this sandbox exists to close.
+# * Setting it would outrank every per-test ``monkeypatch.setenv("HOME")`` /
+# ``monkeypatch.setattr(Path, "home", ...)``, silently collapsing per-test
+# roots into one shared directory. That is not hypothetical: it made
+# test_shadow_account's "returns latest" read a profile another test in the
+# same file had saved.
+#
+# With the override gone, ``Path.home()`` is the single point of control, so a
+# test redirecting home gets its own root on every platform and needs no
+# knowledge of this sandbox. On Windows ``Path.home()`` ignores $HOME and reads
+# %USERPROFILE%, so both spellings are set.
_PRIOR_SANDBOX_ENV = {
- key: os.environ.get(key) for key in ("VIBE_TRADING_HOME", "HOME", "USERPROFILE")
+ key: os.environ.get(key)
+ for key in ("VIBE_TRADING_HOME", "HOME", "USERPROFILE", "PYTHONPATH")
}
-_SANDBOX_HOME = Path(tempfile.mkdtemp(prefix="vibe-trading-test-home-"))
-os.environ["VIBE_TRADING_HOME"] = str(_SANDBOX_HOME / ".vibe-trading")
+
+# Outcome guard, armed BEFORE the redirect so it reuses the app's own resolution
+# rather than restating it. The assertions in _sandbox_runtime_root check that
+# the redirect is INSTALLED, which is a proxy; this checks what #1116 is actually
+# about — that nothing reached the user's own state — so a path the redirect does
+# not cover fails the run with the artefact named, instead of quietly appending to
+# a live audit ledger for another release. The ledgers are the headline harm
+# (fabricated order_rejected records in an append-only, tamper-evident chain) and
+# they move only on a real live action, so they cannot produce noise.
+from src.config.paths import get_runtime_root # noqa: E402 — needs AGENT_DIR above
+
+_REAL_LEDGERS = tuple(
+ get_runtime_root() / "live" / name for name in ("audit.jsonl", "audit_chain.jsonl")
+)
+# The sandbox root is RESOLVED. On macOS ``tempfile.mkdtemp()`` returns a path
+# under ``/var/folders/...``, which is a symlink to ``/private/var/folders/...``.
+# Handing the unresolved form to HOME breaks every guard that compares a
+# ``Path.resolve()``d path against a ``Path.home()``-derived prefix: the two
+# spellings of the same directory do not compare equal, the guard reads it as an
+# escape attempt and refuses. Resolving here keeps one spelling everywhere.
+_SANDBOX_HOME = Path(tempfile.mkdtemp(prefix="vibe-trading-test-home-")).resolve()
+os.environ.pop("VIBE_TRADING_HOME", None)
os.environ["HOME"] = str(_SANDBOX_HOME)
os.environ["USERPROFILE"] = str(_SANDBOX_HOME)
(_SANDBOX_HOME / ".vibe-trading").mkdir(parents=True, exist_ok=True)
+# Tests that spawn a subprocess hand it this environment, HOME included. On a
+# machine whose dependencies live in the per-user site directory -- what
+# ``pip install --user`` does, and the default when no virtualenv is active --
+# that directory is derived FROM HOME, so redirecting HOME hides numpy, pandas
+# and pytest itself from every child. The child then comes up with a partial
+# tool registry rather than an error (tool auto-discovery logs an import failure
+# and moves on), which surfaces as a baffling "Tool 'x' not found" far from the
+# cause. ``site.USER_SITE`` was computed at interpreter startup, before this
+# redirect, so it still names the real directory: pin it for children.
+if site.ENABLE_USER_SITE and site.USER_SITE and Path(site.USER_SITE).is_dir():
+ _prior_path = os.environ.get("PYTHONPATH", "")
+ if site.USER_SITE not in _prior_path.split(os.pathsep):
+ os.environ["PYTHONPATH"] = os.pathsep.join(
+ part for part in (site.USER_SITE, _prior_path) if part
+ )
+
+
+def _ledger_state() -> dict[str, tuple[int, int] | None]:
+ """Return (size, mtime_ns) per real live ledger; None where absent."""
+ state: dict[str, tuple[int, int] | None] = {}
+ for path in _REAL_LEDGERS:
+ try:
+ stat = path.stat()
+ except OSError:
+ state[str(path)] = None
+ else:
+ state[str(path)] = (stat.st_size, stat.st_mtime_ns)
+ return state
+
+
+_REAL_LEDGER_BASELINE = _ledger_state()
+
+
+def _assert_real_root_untouched() -> None:
+ """Raise if the user's own live ledgers moved during the run."""
+ if changed := [p for p, now in _ledger_state().items() if _REAL_LEDGER_BASELINE[p] != now]:
+ raise AssertionError(
+ f"The suite wrote into the REAL config root (#1116): {changed}. "
+ f"Something resolved outside the sandbox at {_SANDBOX_HOME}. Route "
+ "the write through get_runtime_root(); do not widen this guard."
+ )
+
def _teardown_sandbox() -> None:
shutil.rmtree(_SANDBOX_HOME, ignore_errors=True)
@@ -68,20 +140,22 @@ def _teardown_sandbox() -> None:
atexit.register(_teardown_sandbox)
+def pytest_sessionfinish(session, exitstatus): # noqa: ARG001 - pytest hook
+ """Fail the run if anything escaped the sandbox into the user's own state."""
+ _assert_real_root_untouched()
+
+
@pytest.fixture(autouse=True, scope="session")
def _sandbox_runtime_root():
"""Guard the import-time sandbox and tear it down at session end.
- The environment (VIBE_TRADING_HOME/HOME/USERPROFILE) is installed at
- conftest import time above — before collection — so both import-time-baked
- constants and runtime ``Path.home()`` calls resolve to the temp sandbox,
- never the real ``~/.vibe-trading``. This fixture only asserts that the
- invariant is still active and removes the temp dir at session end. The
+ Home is redirected at conftest import time above — before collection, so
+ constants baked at module import resolve there too. This fixture only asserts
+ the invariant is still active and removes the temp dir at session end. The
function-scoped ``_reset_env_config`` fixture snapshots the environment each
- test, so the sandbox values survive every test while per-test monkeypatches
- still work.
+ test, so the sandbox survives every test while per-test monkeypatches keep
+ working.
"""
- assert os.environ["VIBE_TRADING_HOME"] == str(_SANDBOX_HOME / ".vibe-trading")
assert os.environ["HOME"] == str(_SANDBOX_HOME)
assert os.environ["USERPROFILE"] == str(_SANDBOX_HOME)
yield _SANDBOX_HOME / ".vibe-trading"
diff --git a/agent/tests/test_agent_config.py b/agent/tests/test_agent_config.py
index d0d877777..c0a29eca8 100644
--- a/agent/tests/test_agent_config.py
+++ b/agent/tests/test_agent_config.py
@@ -340,14 +340,11 @@ def test_runtime_overrides_fall_back_to_base_config_when_merge_is_invalid(tmp_pa
assert config.mcp_servers["demo"].args == ["--base"]
-def test_explicit_config_path_does_not_mutate_default_runtime_root(
- monkeypatch: pytest.MonkeyPatch, tmp_path: Path
-) -> None:
+def test_explicit_config_path_does_not_mutate_default_runtime_root(tmp_path: Path) -> None:
config_path = tmp_path / "nested" / "agent.json"
load_agent_config(config_path)
assert get_runtime_root(config_path) == config_path.parent
- monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)
assert get_runtime_root() == Path.home() / ".vibe-trading"
assert get_config_path(config_path) == config_path
@@ -415,7 +412,6 @@ def test_live_authorize_missing_robinhood_config_prints_safe_seed(
) -> None:
from cli._legacy import EXIT_USAGE_ERROR, cmd_live_authorize
- monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)
monkeypatch.setattr(Path, "home", lambda: tmp_path)
assert cmd_live_authorize("robinhood") == EXIT_USAGE_ERROR
@@ -436,7 +432,6 @@ def test_live_authorize_wildcard_robinhood_config_prints_safe_seed(
) -> None:
from cli._legacy import EXIT_USAGE_ERROR, cmd_live_authorize
- monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)
monkeypatch.setattr(Path, "home", lambda: tmp_path)
config_path = tmp_path / ".vibe-trading" / "agent.json"
config_path.parent.mkdir(parents=True)
diff --git a/agent/tests/test_api_live_runtime.py b/agent/tests/test_api_live_runtime.py
index 3a7d3cfe1..f000c7d76 100644
--- a/agent/tests/test_api_live_runtime.py
+++ b/agent/tests/test_api_live_runtime.py
@@ -26,7 +26,6 @@ def _client(tmp_path: Path, monkeypatch) -> TestClient:
# Redirect the runtime root (``~/.vibe-trading``) at the home boundary so the
# live tree, HALT sentinel, mandate store, and proposal store all resolve
# under tmp_path. get_runtime_root() == Path.home() / ".vibe-trading".
- monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path), raising=False)
monkeypatch.setattr(api_server, "_runner_tasks", {}, raising=False)
monkeypatch.setattr(api_server, "_runner_factory", None, raising=False)
@@ -261,7 +260,6 @@ def _seed_proposal(tmp_path: Path, proposal_id: str, broker: str = "robinhood")
def test_c1_relay_builds_mandate_proposal_frame(tmp_path: Path, monkeypatch) -> None:
- monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path), raising=False)
proposal_id = "mp_" + "1" * 32
_seed_proposal(tmp_path, proposal_id)
@@ -284,7 +282,6 @@ def test_c1_relay_builds_mandate_proposal_frame(tmp_path: Path, monkeypatch) ->
def test_c1_relay_ignores_non_propose_events(tmp_path: Path, monkeypatch) -> None:
- monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path), raising=False)
# A different tool's result: no relay.
@@ -301,7 +298,6 @@ def test_c1_relay_ignores_non_propose_events(tmp_path: Path, monkeypatch) -> Non
def test_c1_relay_returns_none_when_proposal_missing(tmp_path: Path, monkeypatch) -> None:
- monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path), raising=False)
# Preview references an id with no persisted proposal on disk.
event = SimpleNamespace(
@@ -322,7 +318,6 @@ def test_c1_relay_returns_none_when_proposal_missing(tmp_path: Path, monkeypatch
def test_build_live_runner_no_broker_configured_raises_unavailable(tmp_path, monkeypatch) -> None:
- monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path), raising=False)
monkeypatch.setattr(api_server, "_runner_factory", None, raising=False)
# No robinhood MCP server in the default config → clean 503-class error,
@@ -334,7 +329,6 @@ def test_build_live_runner_no_broker_configured_raises_unavailable(tmp_path, mon
def test_build_live_runner_wires_a_real_runner(tmp_path, monkeypatch) -> None:
- monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path), raising=False)
monkeypatch.setattr(api_server, "_runner_factory", None, raising=False)
@@ -394,7 +388,6 @@ def _seed_ledger(tmp_path: Path, record: dict) -> None:
def test_live_action_relay_builds_frame_from_guard_result(tmp_path: Path, monkeypatch) -> None:
- monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path), raising=False)
audit_id = "la_01abcDEF"
_seed_ledger(tmp_path, {"audit_id": audit_id, "kind": "order_placed", "outcome": "accepted",
@@ -417,7 +410,6 @@ def test_live_action_relay_builds_frame_from_guard_result(tmp_path: Path, monkey
def test_live_action_relay_ignores_non_live_results(tmp_path: Path, monkeypatch) -> None:
- monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path), raising=False)
# A normal tool_result with no live_action marker → no relay.
event = SimpleNamespace(
diff --git a/agent/tests/test_channel_media_roots.py b/agent/tests/test_channel_media_roots.py
index 9916338a7..8208a7e04 100644
--- a/agent/tests/test_channel_media_roots.py
+++ b/agent/tests/test_channel_media_roots.py
@@ -6,7 +6,6 @@ from pathlib import Path
def test_media_dir_lives_under_uploads_root(tmp_path, monkeypatch):
- monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path), raising=False)
from src.channels.utils import get_media_dir
@@ -17,7 +16,6 @@ def test_media_dir_lives_under_uploads_root(tmp_path, monkeypatch):
def test_media_dir_is_within_allowed_file_roots(tmp_path, monkeypatch):
- monkeypatch.delenv("VIBE_TRADING_HOME", raising=False)
monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path), raising=False)
from src.channels.utils import get_media_dir
diff --git a/agent/tests/test_config_root_sandbox.py b/agent/tests/test_config_root_sandbox.py
index 1c7caef9b..38947a69f 100644
--- a/agent/tests/test_config_root_sandbox.py
+++ b/agent/tests/test_config_root_sandbox.py
@@ -1,23 +1,24 @@
"""Regression tests for the sandboxed runtime root (issue #1116).
-The test suite must never resolve its config root against the real home
-directory. On Windows, ``Path.home()`` ignores ``$HOME`` and reads
-``%USERPROFILE%``, so the suite's historical ``HOME``-based isolation idiom is
-inert there and tests leaked into the real ``~/.vibe-trading`` (including the
-live audit ledger). ``conftest.py`` installs ``VIBE_TRADING_HOME``/``HOME``/
-``USERPROFILE`` at import time (before collection, so import-time-baked
-constants also resolve there) to a temp sandbox root — the project's documented
-Windows-safe override — and these tests pin that contract.
-
-NOTE: the base-failure signature of these tests depends on ``VIBE_TRADING_HOME``
-being unset in the ambient environment. A CI runner that pre-sets it (rather
-than letting ``conftest.py`` install the sandbox) would not see the red/green
-regression signal this file is meant to produce.
+The suite must never resolve its config root against the real home directory.
+It used to: tests isolated themselves by monkeypatching ``HOME``, which
+``Path.home()`` ignores on Windows in favour of ``%USERPROFILE%``, so on Windows
+the redirect was inert and runs appended fabricated ``order_rejected`` records to
+the real, tamper-evident live audit ledger. ``conftest.py`` now redirects home at
+import time — before collection, so constants baked at module import resolve
+there too — and these tests pin that contract.
+
+The sandbox controls ``Path.home()`` only, and deliberately DELETES
+``VIBE_TRADING_HOME`` rather than setting it, so a single knob decides the root
+and per-test home redirection still wins. Both halves are asserted below.
"""
from __future__ import annotations
+import json
import os
+import subprocess
+import sys
import tempfile
from pathlib import Path
@@ -25,54 +26,124 @@ import pytest
from src.config.paths import get_runtime_root
from src.live.audit import audit_ledger_path
-from src.live.paths import live_root
+from tests import conftest
+
+AGENT_DIR = Path(__file__).resolve().parent.parent
-def test_sandbox_runtime_root_is_active() -> None:
- """The import-time sandbox must have pointed the runtime root at a sandbox."""
- sandbox_root = os.environ.get("VIBE_TRADING_HOME")
- assert sandbox_root, (
- "VIBE_TRADING_HOME is unset — the conftest sandbox is not active; "
- "without it tests resolve the real ~/.vibe-trading (issue #1116)"
+def test_runtime_root_resolves_into_a_temp_sandbox() -> None:
+ """The default root must be a temp sandbox, never the user's own."""
+ root = get_runtime_root()
+
+ assert root.is_absolute()
+ # Resolve gettempdir() too: on macOS it reports /var/folders/... while the
+ # sandbox root is the resolved /private/var/folders/... spelling, and the
+ # unresolved form is not a prefix of the resolved one.
+ assert root.is_relative_to(Path(tempfile.gettempdir()).resolve()), (
+ f"the runtime root is {root}, outside the temp sandbox — the conftest "
+ "redirect is not active and tests are writing to a real home (#1116)"
)
- sandbox_root = Path(sandbox_root)
+ # The headline harm: the live audit ledger must resolve here too.
+ assert audit_ledger_path() == root / "live" / "audit.jsonl"
+
+
+def test_sandbox_sets_both_home_spellings_and_no_root_override() -> None:
+ """One knob, two spellings — and the override must stay unset.
+
+ ``USERPROFILE`` is what ``Path.home()`` reads on Windows, so setting only the
+ POSIX ``HOME`` is the original bug. ``VIBE_TRADING_HOME`` must be absent: it
+ outranks ``Path.home()``, so setting it would both preserve a developer's
+ exported value and override every per-test home redirect.
+ """
+ sandbox = str(conftest._SANDBOX_HOME)
- # The root must live under the system temp dir — a temp sandbox, not a
- # non-temp value a broken setup could otherwise point VIBE_TRADING_HOME at.
- assert sandbox_root.is_relative_to(Path(tempfile.gettempdir()))
- assert sandbox_root.is_absolute()
- assert get_runtime_root() == sandbox_root
+ assert os.environ["HOME"] == sandbox
+ assert os.environ["USERPROFILE"] == sandbox
+ assert "VIBE_TRADING_HOME" not in os.environ
-def test_windows_home_semantics_still_resolve_under_sandbox_root(
- monkeypatch: pytest.MonkeyPatch,
- tmp_path: Path,
+def test_per_test_home_redirect_still_wins(
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
- """Windows ``Path.home()`` ignores ``HOME``; it must not escape the sandbox.
+ """A test redirecting home must get its OWN root, not the shared sandbox.
+
+ This is the property a ``VIBE_TRADING_HOME``-based sandbox silently broke:
+ every test that redirected home kept resolving to the one session directory,
+ so state saved by one test was visible to the next. It is what made
+ test_shadow_account's "returns latest" read another test's saved profile.
+ """
+ own_home = tmp_path / "own-home"
+ monkeypatch.setenv("HOME", str(own_home))
+ monkeypatch.setenv("USERPROFILE", str(own_home)) # Windows Path.home()
+
+ assert get_runtime_root() == own_home / ".vibe-trading"
+ assert get_runtime_root() != conftest._SANDBOX_HOME / ".vibe-trading"
+
+
+def test_real_ledger_guard_fires_when_the_ledger_changes() -> None:
+ """The outcome guard must reject a changed real ledger, not just a bad env.
+
+ Mutating the baseline is the only way to exercise the positive branch without
+ writing to the user's own ledger, which is the thing under guard.
+ """
+ conftest._assert_real_root_untouched() # clean state: silent
+
+ guarded = str(conftest._REAL_LEDGERS[0])
+ original = conftest._REAL_LEDGER_BASELINE[guarded]
+ conftest._REAL_LEDGER_BASELINE[guarded] = (1, 1)
+ try:
+ with pytest.raises(AssertionError, match="REAL config root"):
+ conftest._assert_real_root_untouched()
+ finally:
+ conftest._REAL_LEDGER_BASELINE[guarded] = original
+
+ conftest._assert_real_root_untouched() # tracks state, does not latch
+
- Simulates the Windows failure from issue #1116: a fake "real home" is
- installed into BOTH ``HOME`` and ``USERPROFILE`` (Windows ``Path.home()``
- reads the latter). The runtime root must still resolve under the sandbox
- ``VIBE_TRADING_HOME``, never under the fake real home.
+def test_guarded_ledgers_are_outside_the_sandbox() -> None:
+ """The guard must watch the user's root, not the sandbox it created.
+
+ Closes the mutation "resolve the guarded paths after the redirect": that
+ guard would pass unconditionally.
"""
- fake_real_home = tmp_path / "real-home"
- monkeypatch.setenv("HOME", str(fake_real_home))
- monkeypatch.setenv("USERPROFILE", str(fake_real_home))
-
- sandbox_root = os.environ.get("VIBE_TRADING_HOME")
- assert sandbox_root, (
- "VIBE_TRADING_HOME is unset — the conftest sandbox is not active; "
- "without it get_runtime_root() falls back to Path.home()/.vibe-trading, "
- "which resolves to the fake real home under Windows HOME/USERPROFILE "
- "semantics (issue #1116)"
+ for ledger in conftest._REAL_LEDGERS:
+ assert not ledger.is_relative_to(conftest._SANDBOX_HOME)
+
+
+def test_sandbox_home_keeps_child_processes_importable() -> None:
+ """A subprocess spawned under the sandbox must still import its deps.
+
+ The suite hands its own environment, home included, to every subprocess it
+ spawns. Where dependencies live in the per-user site directory — what
+ ``pip install --user`` does, and the default outside a virtualenv — that
+ directory is derived from home, so redirecting home hides numpy/pandas from
+ the child. Tool auto-discovery logs the import failure and continues, so the
+ child comes up with a PARTIAL registry and the symptom surfaces later as an
+ unrelated "Tool 'x' not found".
+ """
+ code = (
+ "import json, pandas, numpy;"
+ "from src.tools import build_registry;"
+ "names = build_registry().tool_names;"
+ "print(json.dumps({'count': len(names), 'has': 'options_pricing' in names}))"
+ )
+ env = os.environ.copy()
+ env["PYTHONPATH"] = str(AGENT_DIR) + os.pathsep + env.get("PYTHONPATH", "")
+ result = subprocess.run(
+ [sys.executable, "-c", code],
+ capture_output=True,
+ cwd=str(AGENT_DIR),
+ env=env,
+ timeout=600,
+ )
+
+ assert result.returncode == 0, (
+ "a child process could not import its dependencies under the sandbox "
+ f"home: {result.stderr.decode()[-2000:]}"
+ )
+ payload = json.loads(result.stdout.decode().strip().splitlines()[-1])
+ assert payload["has"], (
+ f"the child built a partial tool registry ({payload['count']} tools, "
+ "options_pricing missing) — the sandbox home hid the per-user site "
+ "directory from it"
)
- sandbox_root = Path(sandbox_root)
-
- # Temp sandbox, not the real home — same mutation-gap closure as Test 1.
- assert sandbox_root.is_relative_to(Path(tempfile.gettempdir()))
- assert get_runtime_root() == sandbox_root
- assert get_runtime_root() != fake_real_home / ".vibe-trading"
- assert live_root() == sandbox_root / "live"
- # The issue's headline harm: the live audit ledger must also resolve under the
- # sandbox, never the real ~/.vibe-trading.
- assert audit_ledger_path() == sandbox_root / "live" / "audit.jsonl"
diff --git a/agent/tests/test_daily_count.py b/agent/tests/test_daily_count.py
index 0463a2923..e1ca48a3c 100644
--- a/agent/tests/test_daily_count.py
+++ b/agent/tests/test_daily_count.py
@@ -26,7 +26,7 @@ except DailyOrderLockUnavailable:
"""
env = os.environ.copy()
env["HOME"] = str(home)
- env["VIBE_TRADING_HOME"] = str(home / ".vibe-trading")
+ env["USERPROFILE"] = str(home) # Windows Path.home()
env["PYTHONPATH"] = str(repo_root / "agent")
return subprocess.run(
[sys.executable, "-c", script],