hermes - ✅(Solved) Fix Stabilize gateway service tests in container/root environments [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#18630Fetched 2026-05-03 04:55:22
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Author
Participants
Timeline (top)
labeled ×5cross-referenced ×1

Error Message

  • Tests still cover the intended systemd unavailable error path.

Root Cause

The failing path raises UserSystemdUnavailableError because user D-Bus / loginctl is unavailable in the containerized root test environment.

Fix Action

Fix / Workaround

  • Audit tests/hermes_cli/test_gateway_service.py assumptions around root, systemctl --user, loginctl, and user D-Bus availability.
  • Add focused monkeypatching or environment guards so unit tests for service logic do not depend on host user-systemd availability unless explicitly testing that failure mode.
  • Keep explicit tests for UserSystemdUnavailableError behavior where appropriate.

PR fix notes

PR #18634: fix(cron): report shared gateway runtime owner

Description (problem / solution / changelog)

Summary

  • Adds container-aware gateway owner detection via gateway.status.get_gateway_owner_status().
  • Updates hermes cron status / hermes cron list so an active shared runtime lock is treated as a scheduler owner even when the gateway PID is not visible from the current namespace/container.
  • Preserves gateway PID/lock metadata when a shared runtime lock is active but local PID inspection fails.
  • Adds regression tests, troubleshooting docs, an ADR, implementation plan, and devlog.

Test plan

  • RED: python -m pytest tests/hermes_cli/test_cron.py tests/hermes_cli/test_gateway_runtime_health.py -q failed before production changes because get_gateway_owner_status did not exist. Evidence: /work/.hermes-data/tdd-evidence/2026-05-01-cron-health-red.txt
  • GREEN/relevant regression: python -m pytest tests/hermes_cli/test_cron.py tests/hermes_cli/test_gateway_runtime_health.py tests/hermes_cli/test_gateway.py -q — 34 passed. Evidence: /work/.hermes-data/tdd-evidence/2026-05-01-cron-health-green-regression-final2.txt
  • python -m py_compile gateway/status.py hermes_cli/cron.py
  • python /work/.hermes-data/skills/software-development/requesting-code-review/scripts/static_scan_diff.py --unstagedSTATIC_SCAN_PASS True
  • Final guard passed with HERMES_TDD_EVIDENCE populated.

Review

  • Independent delegate review passed with no security concerns or logic errors.
  • Reviewer suggestions for metadata preservation and branch coverage were addressed with additional tests.

Follow-ups filed

Notes

A broader adjacent regression including tests/hermes_cli/test_gateway_service.py had 130 passing tests and 7 failures in environment-sensitive systemd/root paths outside this branch's touched code. Those failures are tracked in #18630.

Changed files

  • .devlogs/2026-05-01-cron-container-health.md (added, +85/-0)
  • .hermes/plans/2026-05-01-cron-container-health.md (added, +79/-0)
  • docs/adr/2026-05-01-container-aware-cron-health.md (added, +46/-0)
  • gateway/status.py (modified, +79/-4)
  • hermes_cli/cron.py (modified, +43/-19)
  • tests/hermes_cli/test_cron.py (modified, +35/-0)
  • tests/hermes_cli/test_gateway_runtime_health.py (modified, +103/-0)
  • website/docs/guides/cron-troubleshooting.md (modified, +23/-0)

Code Example

python -m pytest tests/hermes_cli/test_cron.py tests/hermes_cli/test_gateway_runtime_health.py tests/hermes_cli/test_gateway.py tests/hermes_cli/test_gateway_service.py -q
130 passed, 7 failed
RAW_BUFFERClick to expand / collapse

Problem / Opportunity

tests/hermes_cli/test_gateway_service.py currently has environment-sensitive failures when run in a containerized root environment without user systemd / D-Bus. During the cron/gateway health work, the relevant regression suite passed, but adding tests/hermes_cli/test_gateway_service.py produced 7 failures unrelated to the touched cron/gateway-owner paths.

Evidence

Observed in worktree /work/.hermes-data/worktrees/hermes-agent-cron-health-20260501223311:

python -m pytest tests/hermes_cli/test_cron.py tests/hermes_cli/test_gateway_runtime_health.py tests/hermes_cli/test_gateway.py tests/hermes_cli/test_gateway_service.py -q
130 passed, 7 failed

Representative failures:

  • TestGatewayServiceDetection.test_supports_systemd_services_returns_true_when_systemctl_present
  • TestSystemdServiceRefresh.test_systemd_start_refreshes_outdated_unit
  • TestSystemdServiceRefresh.test_systemd_restart_refreshes_outdated_unit

The failing path raises UserSystemdUnavailableError because user D-Bus / loginctl is unavailable in the containerized root test environment.

Goal

Make gateway service tests distinguish real regressions from expected environment limitations in containerized/root CI or agent sandboxes.

Proposed Scope

  • Audit tests/hermes_cli/test_gateway_service.py assumptions around root, systemctl --user, loginctl, and user D-Bus availability.
  • Add focused monkeypatching or environment guards so unit tests for service logic do not depend on host user-systemd availability unless explicitly testing that failure mode.
  • Keep explicit tests for UserSystemdUnavailableError behavior where appropriate.

Acceptance Criteria

  • The gateway service test module can run deterministically in a container/root environment without user systemd.
  • Tests still cover the intended systemd unavailable error path.
  • The broader gateway/cron regression command no longer reports unrelated environment-sensitive failures.

extent analysis

TL;DR

Modify tests/hermes_cli/test_gateway_service.py to use monkeypatching or environment guards to handle the absence of user systemd and D-Bus in containerized root environments.

Guidance

  • Audit the test module's assumptions about the availability of systemctl --user, loginctl, and user D-Bus to identify areas where environment-sensitive failures occur.
  • Implement focused monkeypatching to simulate the presence or absence of user systemd and D-Bus, allowing unit tests to run deterministically in containerized root environments.
  • Add explicit tests to cover the UserSystemdUnavailableError behavior, ensuring that the test module still exercises the intended error path.
  • Review the test module's use of pytest fixtures and markers to ensure that environment-sensitive tests are properly isolated or skipped in containerized root environments.

Example

import pytest
from unittest.mock import patch

@pytest.mark.skipif(not has_user_systemd(), reason="User systemd not available")
def test_supports_systemd_services_returns_true_when_systemctl_present():
    # Test implementation
    pass

def has_user_systemd():
    # Implementation to check for user systemd availability
    pass

Notes

The proposed solution requires careful consideration of the test module's dependencies and assumptions about the environment. The use of monkeypatching and environment guards should be targeted and minimal to avoid introducing unnecessary complexity.

Recommendation

Apply workaround by modifying the test module to use monkeypatching and environment guards, as this approach allows for targeted testing of the gateway service logic while accommodating the limitations of containerized root environments.

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