Skip to content

Commit c4ef7ab

Browse files
groksrcclaude
andauthored
test(core): isolate XDG_CONFIG_HOME so host env can't leak into tests (#845)
Signed-off-by: Drew Cain <groksrc@gmail.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c75f45f commit c4ef7ab

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

test-int/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,22 @@ def clean_routing_env(monkeypatch) -> None:
149149
monkeypatch.delenv("BASIC_MEMORY_EXPLICIT_ROUTING", raising=False)
150150

151151

152+
@pytest.fixture(autouse=True)
153+
def isolate_data_dir_env(monkeypatch) -> None:
154+
"""Keep host data-dir env vars from leaking into integration tests.
155+
156+
Why: GitHub Actions Ubuntu runners set ``XDG_CONFIG_HOME=/home/runner/.config``,
157+
and ``resolve_data_dir()`` honors it ahead of ``Path.home() / ".basic-memory"``.
158+
Without clearing it, the MCP tool process reads config.json from the host XDG
159+
path instead of the tmp dir the ``config_manager`` fixture wrote to — so
160+
``test-project`` is missing from ``config.projects``, ``get_project_mode``
161+
falls through to its CLOUD default (#837), and every tool call fails with
162+
"Cloud routing requested but no credentials found."
163+
"""
164+
monkeypatch.delenv("BASIC_MEMORY_CONFIG_DIR", raising=False)
165+
monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)
166+
167+
152168
POSTGRES_EPHEMERAL_TABLES = [
153169
"search_vector_embeddings",
154170
"search_vector_chunks",

tests/conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,19 @@ def isolate_routing_env(monkeypatch) -> None:
225225
monkeypatch.delenv("BASIC_MEMORY_EXPLICIT_ROUTING", raising=False)
226226

227227

228+
@pytest.fixture(autouse=True)
229+
def isolate_data_dir_env(monkeypatch) -> None:
230+
"""Keep host data-dir env vars from leaking into tests.
231+
232+
Why: GitHub Actions Ubuntu runners set ``XDG_CONFIG_HOME=/home/runner/.config``,
233+
and ``resolve_data_dir()`` honors it ahead of ``Path.home() / ".basic-memory"``.
234+
Without clearing it, tests that monkeypatch HOME still see the host XDG path
235+
and assertions against the tmp home directory fail.
236+
"""
237+
monkeypatch.delenv("BASIC_MEMORY_CONFIG_DIR", raising=False)
238+
monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)
239+
240+
228241
@pytest_asyncio.fixture(autouse=True)
229242
async def cleanup_global_db_after_test() -> AsyncGenerator[None, None]:
230243
"""Close any module-level DB engine created outside fixture ownership."""

0 commit comments

Comments
 (0)