fix(tests): align systemd unit + service tests with current production shape (partial close #9) #15
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/systemd-tests-drift-9"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes 8 of the systemd-cluster failures in #9 by aligning the test fixtures with three production shifts that landed since the tests were written.
Sub-shape A —
TimeoutStopSecliteral drift (2 tests)generate_systemd_unit()computesrestart_timeout = max(60, drain_timeout) + 30.DEFAULT_GATEWAY_RESTART_DRAIN_TIMEOUTwas bumped from60to180inhermes_cli/config.py, so the emittedTimeoutStopSecwent from90→210. Tests pinned the literal90.Fix: replace the literal with a
TestGeneratedSystemdUnits._expected_timeout_stop_sec()helper that mirrors the production formula via_get_restart_drain_timeout(). Future config-default bumps no longer silently regress the assertion — the relationship is what matters.Sub-shape B — production preflight not stubbed (4 tests)
PR #14531 ("preflight user D-Bus before systemctl --user start") added
_preflight_user_systemd()ahead of the systemctl call sequence in bothsystemd_start()andsystemd_restart(). The preflight invokesloginctl enable-lingerand waits for the D-Bus socket — neither of which the unit tests' fake subprocess runner answers, so they raiseUserSystemdUnavailableErrorbefore the systemctl asserts run.These tests assert the systemctl call sequence, not the preflight; preflight has dedicated coverage in
TestUserSystemdPrivateSocketPreflight. Stub_preflight_user_systemdas a no-op in:TestSystemdServiceRefresh::test_systemd_start_refreshes_outdated_unitTestSystemdServiceRefresh::test_systemd_restart_refreshes_outdated_unitTestGatewaySystemServiceRouting::test_systemd_restart_self_requests_graceful_restart_and_waitsTestGatewaySystemServiceRouting::test_systemd_restart_recovers_failed_planned_restartSub-shape B —
supports_systemd_servicescontainer branch (2 tests)supports_systemd_services()now branches onis_container()to decide whether to probesystemctl is-system-running. Tests asserting the native-Linux True path didn't stubis_container, so a containerized CI runner inherited a real probe of the runner image's systemd.Fix: stub
is_container()False in both:TestGatewayServiceDetection::test_supports_systemd_services_returns_true_when_systemctl_presentTestSupportsSystemdServicesWSL::test_native_linuxAlso stub
shutil.which()in the WSL one so it isn't implicitly Linux-only viasystemctl-on-PATH.Verification
Local run on darwin py3.13:
One unrelated macOS-only failure remains in this file (
test_wsl_with_systemd) — its body relies on the host havingsystemctlon$PATH. Not in this PR's scope (not in #9's failing-list); will be Linux-green on CI.Skipped
None. All 8 tests originally listed as failing in the systemd cluster are addressed here.
Test plan
tests/hermes_cli/test_gateway_service.pyortests/hermes_cli/test_gateway_wsl.pytotals🤖 Generated with Claude Code
LGTM. Pure test-side alignment with already-shipped production behavior. 3 distinct sub-shapes correctly traced: TimeoutStopSec helper formula (DEFAULT_GATEWAY_RESTART_DRAIN_TIMEOUT 60→180 cascade), _preflight_user_systemd stub (covered separately by TestUserSystemdPrivateSocketPreflight), is_container False stub (matches native-Linux test contract). 7 named + 1 adjacent. No production code touched.