hermes - ✅(Solved) Fix test_branch_command fixture leaks HERMES_HOME across tests [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#14997Fetched 2026-04-24 10:43:41
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×3cross-referenced ×1

Root Cause

Why this is a bug

The session_db fixture mutates os.environ["HERMES_HOME"] directly and never restores it. Because environment variables are process-global, any test that runs after this module can inherit a stale temporary Hermes home instead of the caller's/default Hermes home. That makes order-dependent failures more likely, especially for tests that use get_hermes_home() or profile-aware paths without their own monkeypatch isolation.

Fix Action

Fix / Workaround

Why this is a bug

The session_db fixture mutates os.environ["HERMES_HOME"] directly and never restores it. Because environment variables are process-global, any test that runs after this module can inherit a stale temporary Hermes home instead of the caller's/default Hermes home. That makes order-dependent failures more likely, especially for tests that use get_hermes_home() or profile-aware paths without their own monkeypatch isolation.

Expected vs actual

  • Expected: tests that need a fake Hermes home isolate it with monkeypatch.setenv(...) or restore the old value in fixture teardown.
  • Actual: HERMES_HOME leaks beyond the fixture lifetime.

Suggested investigation direction

Change the fixture to use monkeypatch.setenv("HERMES_HOME", ...) (add monkeypatch as a fixture argument) or explicitly save/restore the prior env var in finally.

PR fix notes

PR #15014: fix(tests): restore HERMES_HOME after branch fixture teardown

Description (problem / solution / changelog)

Summary

  • restore the previous HERMES_HOME value in session_db fixture teardown
  • add a regression test that proves the fixture no longer leaks its temp Hermes home

Root cause

tests/cli/test_branch_command.py mutated os.environ["HERMES_HOME"] directly and only closed the SQLite DB in teardown. Because the env var was never restored, later tests could inherit the fixture's temp Hermes home.

Fix

Save the prior HERMES_HOME value before overriding it, then restore or remove it in a finally block after the fixture closes the DB.

Regression coverage

  • added test_session_db_fixture_restores_hermes_home_after_teardown

Testing

  • scripts/run_tests.sh tests/cli/test_branch_command.py -k restores_hermes_home_after_teardown
  • scripts/run_tests.sh tests/cli/test_branch_command.py

Closes #14997

Changed files

  • tests/cli/test_branch_command.py (modified, +28/-5)

Code Example

os.environ["HERMES_HOME"] = str(tmp_path / ".hermes")
...
yield db
# only db.close(); HERMES_HOME is left set
RAW_BUFFERClick to expand / collapse

Affected files/lines

  • tests/cli/test_branch_command.py:21-29

Why this is a bug

The session_db fixture mutates os.environ["HERMES_HOME"] directly and never restores it. Because environment variables are process-global, any test that runs after this module can inherit a stale temporary Hermes home instead of the caller's/default Hermes home. That makes order-dependent failures more likely, especially for tests that use get_hermes_home() or profile-aware paths without their own monkeypatch isolation.

Minimal reasoning / reproduction

The fixture does:

os.environ["HERMES_HOME"] = str(tmp_path / ".hermes")
...
yield db
# only db.close(); HERMES_HOME is left set

A simple inspection after invoking the fixture path shows HERMES_HOME remains pointed at the test temp directory until another test overwrites it.

Expected vs actual

  • Expected: tests that need a fake Hermes home isolate it with monkeypatch.setenv(...) or restore the old value in fixture teardown.
  • Actual: HERMES_HOME leaks beyond the fixture lifetime.

Suggested investigation direction

Change the fixture to use monkeypatch.setenv("HERMES_HOME", ...) (add monkeypatch as a fixture argument) or explicitly save/restore the prior env var in finally.

extent analysis

TL;DR

The session_db fixture should be modified to use monkeypatch.setenv("HERMES_HOME", ...) or save and restore the original HERMES_HOME environment variable to prevent it from being overwritten.

Guidance

  • Modify the session_db fixture to accept a monkeypatch fixture argument and use monkeypatch.setenv("HERMES_HOME", ...).
  • Alternatively, save the original value of os.environ["HERMES_HOME"] before overwriting it and restore it in a finally block to ensure it is always cleaned up.
  • Verify the fix by checking the value of os.environ["HERMES_HOME"] after the fixture has been used.
  • Consider adding tests to ensure that the HERMES_HOME environment variable is properly isolated for each test.

Example

import os
import pytest

@pytest.fixture
def session_db(monkeypatch, tmp_path):
    original_hermes_home = os.environ.get("HERMES_HOME")
    monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))
    yield db
    if original_hermes_home is not None:
        os.environ["HERMES_HOME"] = original_hermes_home
    else:
        del os.environ["HERMES_HOME"]

Notes

This solution assumes that the monkeypatch fixture is available and properly configured. If not, an alternative approach would be to save and restore the original environment variable manually.

Recommendation

Apply the workaround by modifying the session_db fixture to use monkeypatch.setenv("HERMES_HOME", ...), as this provides a clean and isolated way to manage the environment variable.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix test_branch_command fixture leaks HERMES_HOME across tests [1 pull requests, 1 participants]