hermes - ✅(Solved) Fix [Bug]: test_gateway_service systemd refresh tests fail in non-systemd environments after user D-Bus preflight [2 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#15187Fetched 2026-04-25 06:23:59
View on GitHub
Comments
0
Participants
1
Timeline
7
Reactions
0
Author
Participants
Timeline (top)
labeled ×3cross-referenced ×2referenced ×2

Error Message

hermes_cli.gateway.UserSystemdUnavailableError: User D-Bus session is not available (...)

Root Cause

Bug Description

tests/hermes_cli/test_gateway_service.py has refresh tests that now fail in non-systemd environments because systemd_start() / systemd_restart() call _preflight_user_systemd() before the tests' mocked subprocess.run path.

Fix Action

Fix / Workaround

Proposed Fix (optional)

Keep the runtime preflight behavior, but patch tests to be explicit about this dependency, e.g. monkeypatch _preflight_user_systemd to a no-op in the affected test cases (or a fixture used by this class), then keep existing assertions on daemon-reload/start/restart command ordering.

PR fix notes

PR #15190: test(gateway): make systemd refresh tests hermetic with user D-Bus preflight

Description (problem / solution / changelog)

Summary

Fixes a test regression introduced by user D-Bus preflight checks in systemd user-scope commands.

This keeps runtime behavior unchanged and makes the affected unit tests hermetic again by stubbing _preflight_user_systemd where tests are specifically validating command sequencing / refresh behavior.

Changes

  • Add monkeypatch.setattr(gateway_cli, "_preflight_user_systemd", lambda: None) in:
    • TestSystemdServiceRefresh::test_systemd_start_refreshes_outdated_unit
    • TestSystemdServiceRefresh::test_systemd_restart_refreshes_outdated_unit
    • TestGatewaySystemServiceRouting::test_systemd_restart_self_requests_graceful_restart_and_waits
    • TestGatewaySystemServiceRouting::test_systemd_restart_recovers_failed_planned_restart

Why

systemd_start() and systemd_restart() now call _preflight_user_systemd() before the mocked subprocess.run path. In non-systemd environments, those tests fail early with UserSystemdUnavailableError and never reach their intended assertions.

Validation

  • pytest -q -n 0 tests/hermes_cli/test_gateway_service.py::TestSystemdServiceRefresh::test_systemd_start_refreshes_outdated_unit tests/hermes_cli/test_gateway_service.py::TestSystemdServiceRefresh::test_systemd_restart_refreshes_outdated_unit tests/hermes_cli/test_gateway_service.py::TestGatewaySystemServiceRouting::test_systemd_restart_self_requests_graceful_restart_and_waits tests/hermes_cli/test_gateway_service.py::TestGatewaySystemServiceRouting::test_systemd_restart_recovers_failed_planned_restart
  • pytest -q -n 0 tests/hermes_cli/test_gateway_service.py

Closes #15187

Changed files

  • tests/hermes_cli/test_gateway_service.py (modified, +4/-0)

PR #15435: fix(cli): mock systemd preflight in gateway service tests for non-systemd environments (#15187)

Description (problem / solution / changelog)

Summary

Fixes #15187.

test_systemd_start_refreshes_outdated_unit and test_systemd_restart_refreshes_outdated_unit in test_gateway_service.py call gateway_cli.systemd_start() and gateway_cli.systemd_restart() without mocking _preflight_user_systemd(). These functions call the preflight check before reaching the mocked subprocess.run path. On non-systemd environments (macOS, WSL, Docker), the preflight raises UserSystemdUnavailableError, failing the tests.

Changes

  • tests/hermes_cli/test_gateway_service.py: Added monkeypatch.setattr for _preflight_user_systemd (no-op lambda) and _select_systemd_scope (returns False for user scope) to both affected test methods. The install test was already unaffected because systemd_install() does not call _preflight_user_systemd.

Validation

All 3 tests in TestSystemdServiceRefresh now pass on macOS. No new test files — this fixes existing tests.

Tested on macOS (Python 3.11).

Changed files

  • tests/hermes_cli/test_gateway_service.py (modified, +8/-0)

Code Example

uv venv .venv --python 3.11
   source .venv/bin/activate
   uv pip install -e ".[all,dev]"

---

pytest -q -n 0 \
     tests/hermes_cli/test_gateway_service.py::TestSystemdServiceRefresh::test_systemd_start_refreshes_outdated_unit \
     tests/hermes_cli/test_gateway_service.py::TestSystemdServiceRefresh::test_systemd_restart_refreshes_outdated_unit

---

hermes_cli.gateway.UserSystemdUnavailableError:
User D-Bus session is not available (...)

---

FAILED tests/hermes_cli/test_gateway_service.py::TestSystemdServiceRefresh::test_systemd_start_refreshes_outdated_unit
FAILED tests/hermes_cli/test_gateway_service.py::TestSystemdServiceRefresh::test_systemd_restart_refreshes_outdated_unit
E hermes_cli.gateway.UserSystemdUnavailableError: User D-Bus session is not available (...)
RAW_BUFFERClick to expand / collapse

Bug Description

tests/hermes_cli/test_gateway_service.py has refresh tests that now fail in non-systemd environments because systemd_start() / systemd_restart() call _preflight_user_systemd() before the tests' mocked subprocess.run path.

This appears to be a test regression introduced after adding user D-Bus preflight in hermes_cli/gateway.py.

Steps to Reproduce

  1. Fresh checkout of main.
  2. Create env and install deps:
    uv venv .venv --python 3.11
    source .venv/bin/activate
    uv pip install -e ".[all,dev]"
  3. Run targeted tests:
    pytest -q -n 0 \
      tests/hermes_cli/test_gateway_service.py::TestSystemdServiceRefresh::test_systemd_start_refreshes_outdated_unit \
      tests/hermes_cli/test_gateway_service.py::TestSystemdServiceRefresh::test_systemd_restart_refreshes_outdated_unit

Expected Behavior

These unit tests should stay hermetic and pass by exercising mocked systemctl/unit-refresh logic without requiring a real user D-Bus/systemd session.

Actual Behavior

Both tests fail before assertions with:

hermes_cli.gateway.UserSystemdUnavailableError:
User D-Bus session is not available (...)

Affected Component

  • CLI (gateway service management test path)
  • Test suite

Messaging Platform (if gateway-related)

  • N/A (CLI/test path)

Debug Report

Not applicable for this unit-test regression report.

Operating System

macOS (arm64)

Python Version

3.11.15

Hermes Version

Source checkout of main at commit a0d8dd7b (pyproject.toml version 0.10.0).

Additional Logs / Traceback (optional)

Minimal failure signal:

FAILED tests/hermes_cli/test_gateway_service.py::TestSystemdServiceRefresh::test_systemd_start_refreshes_outdated_unit
FAILED tests/hermes_cli/test_gateway_service.py::TestSystemdServiceRefresh::test_systemd_restart_refreshes_outdated_unit
E hermes_cli.gateway.UserSystemdUnavailableError: User D-Bus session is not available (...)

Root Cause Analysis (optional)

Likely regression from commit d45c738a (fix(gateway): preflight user D-Bus before systemctl --user start (#14531)).

systemd_start() and systemd_restart() now call _preflight_user_systemd():

  • hermes_cli/gateway.py:1826
  • hermes_cli/gateway.py:1847

The affected tests (tests/hermes_cli/test_gateway_service.py, lines ~41-87) stub subprocess.run but do not stub _preflight_user_systemd(), so they now fail on non-systemd/non-user-DBus environments before hitting their intended assertions.

Proposed Fix (optional)

Keep the runtime preflight behavior, but patch tests to be explicit about this dependency, e.g. monkeypatch _preflight_user_systemd to a no-op in the affected test cases (or a fixture used by this class), then keep existing assertions on daemon-reload/start/restart command ordering.

Are you willing to submit a PR for this?

Open to submit a PR after maintainer confirmation on preferred test strategy.

extent analysis

TL;DR

The most likely fix is to patch the affected tests to stub _preflight_user_systemd() to a no-op, allowing the tests to run without requiring a real user D-Bus/systemd session.

Guidance

  • Identify the tests that need to be patched: TestSystemdServiceRefresh::test_systemd_start_refreshes_outdated_unit and TestSystemdServiceRefresh::test_systemd_restart_refreshes_outdated_unit.
  • Use a monkeypatch or a fixture to stub _preflight_user_systemd() to a no-op in the affected test cases.
  • Verify that the tests pass after patching by re-running the targeted tests using pytest.
  • Consider adding a comment or docstring to explain the reasoning behind the patch, to ensure future maintainers understand the dependency on _preflight_user_systemd().

Example

import pytest

@pytest.fixture
def mock_preflight_user_systemd(monkeypatch):
    def no_op():
        pass
    monkeypatch.setattr('hermes_cli.gateway._preflight_user_systemd', no_op)

class TestSystemdServiceRefresh:
    @pytest.mark.usefixtures('mock_preflight_user_systemd')
    def test_systemd_start_refreshes_outdated_unit(self):
        # existing test code
        pass

    @pytest.mark.usefixtures('mock_preflight_user_systemd')
    def test_systemd_restart_refreshes_outdated_unit(self):
        # existing test code
        pass

Notes

This fix assumes that the tests are intended to be hermetic and should not require a real user D-Bus/systemd session. If the tests are intended to interact with a real systemd session, a different approach may be necessary.

Recommendation

Apply the workaround by patching the affected tests to stub _preflight_user_systemd() to a no-op, as this allows the tests to run without requiring a real user D-Bus/systemd session, while

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