test(safety): make updater restart tests hermetic across platforms - #68988
Closed
hehehe0803 wants to merge 1 commit into
Closed
hehehe0803 wants to merge 1 commit into
hehehe0803 wants to merge 1 commit into
Conversation
cmd_update discovers and restarts running gateways after its git and dependency work. The autouse live-system guard blocked os.kill and systemctl mutations but left gateway/service discovery live: on a developer machine with a running gateway, an updater test whose mocks miss discovery could find it and schedule a detached restart watcher that rewrites the real user systemd unit. Prior PRs NousResearch#23397, NousResearch#22900, NousResearch#44267 closed narrower slices of this class. While cmd_update/_cmd_update_impl is on the stack, gateway/service/ platform discovery and the restart, terminate, and unit-write boundaries now return inert values. The command classifiers are hardened: a read-only allowlist for protected service targets; recursion through shell wrappers (sh/bash -c/-lc, cmd /c, powershell -Command/-EncodedCommand); blocking of foreign and negative/process- group kill targets; and blocking of detached gateway spawns and launchctl/taskkill of a Hermes gateway. The guard stays strictly additive: read-only probes, benign kills, and git pass through. Updater-frame detection is by name only (no hermes_cli.main import), so non-updater test processes are unaffected. Test-only; no product code. Adds synthetic classifier, wrapper-level wiring, and load-bearing canary tests that never discover, signal, spawn, or rewrite a real process or unit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015cwEx8CjYtTEvrnmCfp6Hw
Collaborator
|
Thanks @hehehe0803 — closing after review: main's updater-restart guard already blocks all damage primitives this targets (kill/systemctl/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Make the updater restart tests hermetic. This extends the autouse live-system guard in
tests/conftest.pyso that whilecmd_update/_cmd_update_implis on the call stack, gateway/service/platform discovery, the restart/terminate boundaries, and the systemd/launchd unit-write boundary all return inert values. It also hardens the guard's command classifiers. Test-only — no production code changes.Why
cmd_updatediscovers and restarts running gateways after its git and dependency work. The guard already blockedos.killand systemctl mutations, but left discovery live. On a developer machine with a running gateway, an updater test whose mocks miss discovery can find that real gateway, classify it, and schedule a detached restart watcher that rewrites the developer's real user systemd unit to the test checkout's interpreter. Prior PRs closed narrower slices of this class: #23397 (block direct signals/systemd mutations), #22900 (stoprun_gateway()tests rewriting the installed unit), #44267 (unit-generation test safety belt).How it works — strictly additive, low overhead
cmd_update/_cmd_update_implinhermes_cli.main) — the fixture does not importhermes_cli.main, so non-updater test processes are unaffected (verified: a plain test process does not importhermes_cli.main).sh/bash -c/-lc/-ic,cmd /c|/k,powershell -Command/-EncodedCommand); blocking of foreign, negative, and process-group (kill -9 -1) kill targets; and blocking of detached Hermes gateway spawns andlaunchctl kickstart/bootout/taskkillof a Hermes gateway.systemctl/launchctlprobes, benign own-subtree kills, unrelatedpkill, benigntaskkill /IM, and allgitcommands pass through unchanged.How to test
From a clean checkout (Linux, Python 3.11):
Results on this branch:
test_live_system_guard_self_test.pyandtest_update_autostash.pyare unchanged from the pristine baseline (proving the change is strictly additive), and the new modules pass. The canary is load-bearing: disabling only the updaterterminate_pidinert wrapper makes two tests fail.scripts/run_tests.sh(per-file isolation, matching CI) is the authoritative full-suite gate.New synthetic tests (never discover, signal, spawn, or rewrite a real process/unit):
tests/test_live_system_guard_classifiers.py— pure classifier tests incl. shell-wrapper, negative-PID, and verb-allowlist edge cases.tests/test_live_system_guard_self_test.py— assert launchctl/detached-spawn/taskkill are rejected before native execution, with pass-through cases.tests/test_live_system_guard_update_hermetic.py— asserts no discovery/restart/unit-write boundary executes duringcmd_update, plus the load-bearing terminate canary.Platforms tested
Linux (Python 3.11). The launchd (macOS) and Windows
taskkill/cmd/powershellclassifiers are exercised as pure string tests; no native launchd/taskkill command is invoked by any test.