From f8a6db68ca7aaafbbc4c952ac96c483d2b5399ca Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Tue, 5 May 2026 04:36:38 -0700 Subject: [PATCH] test(kanban): isolate HERMES_KANBAN_BOARD writes in pin-env tests The helper under test writes to os.environ directly, bypassing monkeypatch tracking. Without an explicit snapshot/restore fixture, the mutation leaks into subsequent tests and breaks TestSharedBoardPaths (kanban path resolution reads HERMES_KANBAN_BOARD and routes through boards// instead of the test's own HERMES_HOME). Add an autouse fixture that snapshots the env var before the test and restores (or pops) it after, regardless of what the helper did. --- tests/hermes_cli/test_pin_kanban_board_env.py | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/hermes_cli/test_pin_kanban_board_env.py b/tests/hermes_cli/test_pin_kanban_board_env.py index c4965ecf4d..1f6b2fc6ed 100644 --- a/tests/hermes_cli/test_pin_kanban_board_env.py +++ b/tests/hermes_cli/test_pin_kanban_board_env.py @@ -8,10 +8,32 @@ can flip the global current-board file mid-turn and silently divert the shell calls to a different DB. """ import importlib +import os + +import pytest + + +@pytest.fixture(autouse=True) +def _isolate_kanban_board_env(): + """Snapshot `HERMES_KANBAN_BOARD` and restore it after the test. + + `_pin_kanban_board_env()` writes to ``os.environ`` directly, bypassing + any ``monkeypatch.setenv`` tracking. Without this fixture the mutation + leaks into subsequent tests and breaks anything that resolves a kanban + path from the env (e.g. ``TestSharedBoardPaths`` in test_kanban_db.py). + """ + prev = os.environ.get("HERMES_KANBAN_BOARD") + os.environ.pop("HERMES_KANBAN_BOARD", None) + try: + yield + finally: + if prev is None: + os.environ.pop("HERMES_KANBAN_BOARD", None) + else: + os.environ["HERMES_KANBAN_BOARD"] = prev def test_pin_writes_resolved_board_when_env_unset(monkeypatch): - monkeypatch.delenv("HERMES_KANBAN_BOARD", raising=False) main_mod = importlib.import_module("hermes_cli.main") import hermes_cli.kanban_db as kdb @@ -39,7 +61,6 @@ def test_pin_does_not_overwrite_existing_env(monkeypatch): def test_pin_swallows_resolution_failures(monkeypatch): - monkeypatch.delenv("HERMES_KANBAN_BOARD", raising=False) main_mod = importlib.import_module("hermes_cli.main") import hermes_cli.kanban_db as kdb