Skip to content

Commit d1e437d

Browse files
author
codejunkie99
committed
test: isolate hook memory fixtures
1 parent 1066cc8 commit d1e437d

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

tests/test_claude_code_hook.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,34 @@ def _load_hook():
118118
pytest = None
119119

120120
if pytest is not None:
121+
@pytest.fixture(scope="session", autouse=True)
122+
def isolated_agent_tree(tmp_path_factory):
123+
global PROJECT_ROOT, AGENT_DIR, HOOK_SCRIPT, EPISODIC
124+
source_root = PROJECT_ROOT
125+
isolated_root = str(tmp_path_factory.mktemp("claude-hook-project"))
126+
shutil.copytree(
127+
os.path.join(source_root, ".agent"),
128+
os.path.join(isolated_root, ".agent"),
129+
)
130+
PROJECT_ROOT = isolated_root
131+
AGENT_DIR = os.path.join(PROJECT_ROOT, ".agent")
132+
HOOK_SCRIPT = os.path.join(AGENT_DIR, "harness", "hooks", "claude_code_post_tool.py")
133+
EPISODIC = os.path.join(AGENT_DIR, "memory", "episodic", "AGENT_LEARNINGS.jsonl")
134+
for rel in ("harness", "memory", "tools"):
135+
path = os.path.join(AGENT_DIR, rel)
136+
if path not in sys.path:
137+
sys.path.insert(0, path)
138+
yield
139+
140+
def test_pytest_uses_isolated_agent_tree():
141+
import tempfile
142+
143+
actual = os.path.realpath(PROJECT_ROOT)
144+
repository_root = os.path.realpath(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
145+
expected = os.path.realpath(tempfile.gettempdir())
146+
assert actual != repository_root
147+
assert os.path.commonpath([actual, expected]) == expected
148+
121149
@pytest.fixture
122150
def mod():
123151
return _load_hook()

0 commit comments

Comments
 (0)