Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions tests/test_bash_tool_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import subprocess
import sys
import tempfile
from pathlib import Path

import pytest

Expand Down Expand Up @@ -734,10 +735,18 @@ def test_workspace_write_allows_evolution_memory(monkeypatch, tmp_path):
module's own data root) even though it is outside the repo workspace."""
import emrg.tools.bash_tool as bt
# Pin the user home + evolution data root so the test is hermetic and does
# not depend on this host's real ~/.emrg layout.
# not depend on this host's real ~/.emrg layout. Pin both spellings:
# expanduser reads USERPROFILE on Windows and HOME elsewhere, so HOME alone
# left the path resolving to the reading host's real root — a pure predicate
# here, a real write in tests/test_write_tool.py's sibling test.
monkeypatch.setenv("HOME", str(tmp_path / "home"))
# Recompute the trusted zone against the pinned HOME.
monkeypatch.setenv("USERPROFILE", str(tmp_path / "home"))
# Recompute the trusted zone against the pinned home.
evo_data = os.path.realpath(os.path.expanduser("~/.emrg/evolution/.emrg"))
assert Path(evo_data).is_relative_to(Path(os.path.realpath(str(tmp_path)))), (
"the fixture home did not take: this test would measure the reading "
f"host's real data root ({evo_data})"
)
ws = str(tmp_path / "ws")
# check_workspace_write (write/edit tools)
meta = evo_data + "/memory/cycle-20260901-000000.md"
Expand All @@ -754,7 +763,12 @@ def test_workspace_write_allows_evolution_session_scratch(monkeypatch, tmp_path)
per the _trusted_write_zones() docstring — lock it in so a future narrowing
of the zone to memory/ alone cannot silently break session writes."""
monkeypatch.setenv("HOME", str(tmp_path / "home"))
monkeypatch.setenv("USERPROFILE", str(tmp_path / "home"))
evo_data = os.path.realpath(os.path.expanduser("~/.emrg/evolution/.emrg"))
assert Path(evo_data).is_relative_to(Path(os.path.realpath(str(tmp_path)))), (
"the fixture home did not take: this test would measure the reading "
f"host's real data root ({evo_data})"
)
ws = str(tmp_path / "ws")
# check_workspace_write (write/edit tools)
session = evo_data + "/sessions/emrg-evolution-emrg-task/history.jsonl"
Expand Down
18 changes: 17 additions & 1 deletion tests/test_write_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,26 @@ def test_write_workspace_write_allows_evolution_memory(tmp_path, monkeypatch):
"""Issue #1093 self-regression: the evolution module writes its cycle records
to ~/.emrg/evolution/.emrg/memory/, which is OUTSIDE the repo checkout
workspace. The workspace-write boundary must trust that data root so the
evolution module can still record its own history (positive state)."""
evolution module can still record its own history (positive state).

Both spellings of the home are pinned, because ``os.path.expanduser("~")``
reads ``USERPROFILE`` on Windows and ``HOME`` elsewhere: with only ``HOME``
set the resolved root stayed this host's real one, so this test — the one of
the three that *executes* the write instead of handing the path to a pure
predicate — wrote a fixture file into the host's
``~/.emrg/evolution/.emrg/memory/`` on every suite run. Measured
2026-09-28: it was the single file under that 230-file root whose mtime
moved. The assertion below makes the fixture home a premise the test checks
rather than one it assumes.
"""
import os
monkeypatch.setenv("HOME", str(tmp_path / "home"))
monkeypatch.setenv("USERPROFILE", str(tmp_path / "home"))
evo_data = Path(os.path.realpath(os.path.expanduser("~/.emrg/evolution/.emrg")))
assert evo_data.is_relative_to(Path(os.path.realpath(str(tmp_path)))), (
"the fixture home did not take: this test would write into the reading "
f"host's real data root ({evo_data})"
)
evo_data.mkdir(parents=True, exist_ok=True)
ws = tmp_path / "ws"
ws.mkdir()
Expand Down
Loading