Commit Graph

12 Commits

Author SHA1 Message Date
Maciej Lisiewski
f3b1768b19 fix: cause of failing test_cancelled_start_hard_kills_sigterm_ignoring_descendant 2026-10-16 07:16:54 +02:00
unsupportedpastels
450ad5055e test: decode shell escapes in the systemctl guard and exempt only test-owned units
The punctuation splitter that let the guard see units inside `bash -c`
payloads dropped shlex's escape handling, so `systemctl rest\art
hermes-dashboard` (which bash runs as `restart`) got through. The guard now
reads words both ways: the punctuation split with backslashes removed,
plus shlex tokens, recursing into nested `-c` payloads.

Widening the guard to every hermes-* unit also refused
test_real_user_systemd_scope_preserves_worker_context's cleanup of the
transient scope it created. A test can now name the exact units it owns in
`request.node.live_system_guard_owned_units`; that test registers only its
freshly named scope, and every other Hermes unit stays refused.

test_update_cleanup_spares_backend_owned_by_valid_ssh_lock required a
systemctl probe on every host, but the managed-unit probe returns before
running anything on Windows; the assertion is now platform-aware.

Refs: #138734 (Greptile review and independent review)
2026-10-15 12:06:51 +05:30
unsupportedpastels
fca14bc283 test: keep the live-system guard from letting tests restart a real hermes-dashboard
The autouse guard refused mutating systemctl verbs only when the command
named the gateway, so hermes-dashboard*, hermes-serve* and every other
Hermes unit fell through. Two update tests restarted the developer's real
units:

- test_update_cleanup_spares_backend_owned_by_valid_ssh_lock drove
  _kill_stale_dashboard_processes(restart_managed=True) with only the PID
  scan stubbed; _restart_managed_dashboard_service found the real
  hermes-dashboard.service and ran `systemctl --user restart` on it.
- test_recovery_module_reports_serve_units_in_a_real_process ran
  update_restart_recovery in a fresh interpreter (outside the in-process
  guard) that resolved the real systemctl and restarted hermes-serve and
  hermes-dashboard in both scopes.

The guard now refuses a mutating verb against any `hermes`/`hermes-*`
unit (path and .service/.timer/.socket stripped), including inside a
quoted `bash -c` string. The first test stubs subprocess.run like its
siblings; the second puts a recording fake systemctl first on the child's
PATH and asserts the serve unit it restarted and verified, with a
separate non-Linux arm for the empty-coverage round trip.
2026-10-15 12:06:51 +05:30
Teknium
b1ccce898b Merge origin/main (#38: 70 commits to c57331677d) into feat/unified-gateway-runtime
Conflicts: tests/hermes_cli/test_finite_chat_delegation.py and
tests/tools/test_completed_process_results.py, where main's lint sweep (0006a5e229) added
check=False to subprocess.run calls this branch had rewritten. Kept the branch's test bodies
and carried check=False onto their subprocess.run calls.
2026-10-10 17:47:35 -07:00
Maciej Lisiewski
bda3aea496 ci: remove unused variables (linter) 2026-10-10 15:20:14 +02:00
Teknium
1bb193c327 test: share re-imported fixtures through conftest instead of imports
Test files received fixtures by importing them from a sibling test module
(`from tests.x.test_y import daemon, owner  # noqa: F401`). Every test that
then takes the fixture as a parameter is a ruff F811 redefinition, which
main's code-health ratchet blocks (it ignores noqa), and it couples test
modules to each other.

Move each shared fixture to where pytest resolves it by name, scopes
unchanged (all function-scoped):
- model_peer -> tests/_fixtures/model_peer.py, registered in tests/conftest.py
  (used by gateway, acp_adapter and hermes_cli tests)
- daemon, server_spec -> tests/acp_adapter/conftest.py
- owner, api -> tests/gateway/conftest.py
- worker -> new tests/hermes_state/conftest.py
- test_session_hosted_rpc's `owner` (a different object: hosted-room
  authority on its own loop) -> tests/gateway/conftest.py as `hosted_owner`,
  so it does not collide with the API `owner`; its three user files rename
  the parameter.
Conftest fixtures import lazily so the gateway conftest still installs its
telegram/discord mocks before any gateway module loads. Plain helpers
(viewer, editor, control, policy) stay imported from their modules.

Also drop an unused HostedRoomAttachmentStore local in
test_hosted_attachment_bridge (F841) while that file is touched.

Same tests collected and passing in every touched file.

(cherry picked from commit 463102382f8cd9bbc9e0c605be7e1345165efda4)
2026-10-07 10:57:32 -07:00
Teknium
d06e35693e test: live-system guard admits a sandboxed gateway.run whose home sits under the account home
The disposable-daemon exemption refused any child whose HERMES_HOME lived anywhere under the
developer's account home. On Windows pytest's tmp root is %TEMP% = %USERPROFILE%\AppData\Local\Temp,
so every sandboxed `python -m gateway.run` (native live suite, managed worker lineage/images,
API pending daemon, the Desktop ticket bridge probe) was blocked as a real gateway spawn.
The protected thing is the real Hermes root (_real_platform_state_root: %LOCALAPPDATA%\hermes or
~/.hermes), so compare against that; HOME must still differ from the real account home.

Proved on windows-latest (wine2e/106742-merged): 17 guard refusals before.

(cherry picked from commit e85c3c770578d288a3430d8e3927f9da38ccf97c)
2026-10-06 18:52:44 -07:00
Teknium
1e500ebce2 Merge origin/main (#16: 4,465 commits to 9dcab1e440) into feat/unified-gateway-runtime
99 conflicted files resolved in nine area lanes (Desktop composer, Desktop renderer/shared
client, Electron main, Ink, tui_gateway, gateway, state, CLI/config, cron/tools/CI). The
unified runtime's architecture wins where it deliberately replaced a mechanism (pool,
fallback lanes, claim poller, renderer queue); every orthogonal main change is kept, ported
into the <stem>_<topic> sibling that now owns relocated code.

Notable ports and repairs in this merge:
- tui_gateway/server.py relocated regions: atomic _attach_built_agent (#49852), slash ranking
  registry names, minted-key helpers methods_session.py calls, request_overrides, service tier.
- gateway/run_turn*.py: i18n accessors for the removed reply constants, first-contact
  internal/DM rule, rotated-compression persist, fast-mode tiers, prompt-pin rehydration.
- webhook: route_from_chat_id decodes main's opaque webhook:v2 chat ids (old ids still read).
- ws.py: main's per-connection dispatch queue with authority-first dispatch inside it.
- state: schema event for runtime revision renumbered to 31; worker mirrors updated for
  main's message uid/merge fields, on_contended lease arg, compression columns.
- config: branch's bot_chat_delivery_timeout removal renumbered v47 -> v50.
- Electron: primary-profile pin, redirect header scoping, remote fetchJsonForBackend, SSH
  teardown on profile delete, held-update dial gate restored (lost in earlier merges).
- Desktop: canonical clarify.request mapped to main's questions[] card; replay truncation vs
  snapshot_required; periodic secondary prune tick restored; DELETE already_absent restored.
- cron/tools: diagnostic category on cron failure notices restored; owner_holds_delivery
  ported onto the authority; admitted receipts can no longer be cancelled locally.
2026-10-06 14:24:24 -07:00
Alex Fournier
f5448560e9 Merge origin/main into chore/relay-0.9
Signed-off-by: Alex Fournier <afournier@nvidia.com>
2026-09-27 11:52:04 -04:00
teknium1
c6dc7ab120 Merge remote-tracking branch 'origin/main' into feat/unified-gateway-runtime
Merge #8: 2,771 commits from main (4b05f764fa). Ports main's moved code into the
unified runtime (run.py/run_turn.py splits, tui_gateway server, backup/restore
split), keeps the detached-daemon Desktop lifecycle, and adapts main's new tests
to the owner/authority contracts (canonical session deletes, retired-id
tombstones, zero-writer browsing, hermes_yaml, platforms() markers).
2026-09-27 02:30:04 -07:00
Austin Pickett
fae9e5677a fix(update): stop reading gateway identity off the Windows restart watcher's argv (#107002) (#121635)
* fix(update): stop reading gateway identity off the restart watcher's argv (#107002)

The detached restart watcher is spawned as
`python -c <watcher source> <old_pid> <python> -m hermes_cli.main gateway run`.
Its trailing argv is the command it will spawn LATER, but the canonical matchers
read identity straight off the joined command line, so the watcher itself was
classified as a live `gateway run` process — the documented "never infer process
identity from argv substrings" bug class, on the exact surface `hermes update`
uses to verify a post-update relaunch.

Also budget the post-relaunch liveness poll against the watcher's own deadline:
the watcher respawns the gateway only after the PID it was handed exits, so a
30 s window can expire before the relaunch it verifies was scheduled to start.

* test(windows-live): run the gateway-ancestor harness parent from a script file

A `python -c <src>` parent is an interpreter running inline source and carries
no readable Hermes identity, so it is no longer a gateway to any classifier —
the harness's own comment already said a realistic gateway argv is not a -c blob.

* test(windows-live): share one sleeper SCRIPT across the live process-topology fixtures

Four live Windows E2E files stood processes up as `python -c "sleep" <hermes argv tail>`.
That shape no longer carries a readable Hermes identity, so the fixtures stopped standing
in for the gateways they simulate. One shared sleeper script replaces the -c spelling.

* fix(gateway): drop the duplicated _INLINE_SOURCE_FLAG_RE definition

The constant was emitted twice around command_line_runs_inline_source. Same
pattern both times, so behaviour is unchanged — but one definition is enough.

* test(stderr-timestamp): run the gateway-lookalike children from script files

Both lookalikes stood a gateway child up as `python -c <src> <gateway tail>`.
That shape no longer carries a readable Hermes identity (#107002), so the
wrapper correctly stopped treating them as gateway spawns and the tests failed.
A `-c` tail is data for a program the inline source may spawn LATER, never the
child's own identity — the real wrapper child is `python -m hermes_cli.main
gateway run`, which has no `-c`. Running the stand-ins from a real script file
restores what the tests mean to assert without depending on the misread.

* test(windows-live): restore the tempfile import dropped with the local sleeper helper

* test(windows-live): wait on the sleeper SCRIPT name, not its source text

The live fixtures proved argv visibility by waiting for `time.sleep(120)` in the
spawned process's command line. That string only ever appeared there because the
sleeper was spelled `python -c "import time; time.sleep(120)"`; now that it runs
from a file the source is in the file, so the probe timed out ("sleeper argv
never visible") even though the argv was perfectly visible.

Wait on the script name instead, exported as SLEEPER_MARKER next to the script
so the probe and the spelling cannot drift apart again.

* fix(tests,gateway): keep the live-system guard blocking -c-wrapped gateway spawns

The #107002 identity fix made _gateway_command_subcommand return None for
'python -c <src> … -m hermes_cli.main gateway run'. tests/_fixtures/live_system_guard.py
shares that matcher, so the autouse guard stopped blocking the detached restart
watcher: real gateways leaked out of the e2e run and squatted the webhook port.

Add gateway.status.gateway_spawn_intent_subcommand — the spawn-intent mirror of the
identity matcher, peeling the inline-source wrapper token-wise and re-running the same
canonical matcher on each suffix (still no substring matching) — and point the guard at
it. Read-only subcommands stay spawnable.

* fix(gateway): make the inline-source option walk value-aware so -X utf8 -c is not read as a gateway

The walk that decides whether a command line is an interpreter running inline
source (`python -c <src> ...`) treated every token starting with `-` as a flag
and the first non-flag token as the end of the option block. CPython options
that take a SEPARATE operand (-X/-W/-Q, --check-hash-based-pycs, --jit) break
that model: the operand was mistaken for the end of the block, so the walk
never reached the -c behind it and the watcher was read as a live gateway
again -- exactly the #107002 misclassification, one shape further out.

- Reuse the canonical operand sets from hermes_state_holders rather than
  hand-rolling a second copy (AGENTS.md: parser-derived flag sets).
- Walk case-preserving tokens: operand-taking -Q/-W/-X must not be conflated
  with operand-less -q/-b, so callers no longer lowercase before the walk.
- Handle clustered short options precisely (-uc is inline source, -Xc is -X c).
- Replace the ad-hoc _INLINE_SOURCE_FLAG_RE rescan in
  gateway_spawn_intent_subcommand with the index the same walk returns; the
  regex could not find spellings the walk accepts and would raise
  StopIteration.

Reported by an automated review on PR #121635 and reproduced here.

Refs #107002

---------

Co-authored-by: Austin Pickett <austinpickett@users.noreply.github.com>
2026-09-25 14:15:22 -04:00
ethernet
07b39f1e8a test: split tests/conftest.py into topic modules under tests/_fixtures
tests/conftest.py had grown to 2,343 lines, past the 2,000-line gate. Move
three self-contained topics out, unchanged:

- env_filter.py: the credential / behavioral env-var name tables the
  hermetic fixture blanks;
- live_system_guard.py: the autouse live-system guard fixture, its marks
  and the protected checkout roots;
- platform_gating.py: the platforms() marker evaluation used by the
  collection hook.

conftest imports them instead of listing them in pytest_plugins: it is not
the rootdir conftest, and pytest fails a run that loads a non-root conftest
carrying pytest_plugins after startup. Imported fixtures register on the
conftest module under their old names, so autouse order is unchanged.
Tests that reached into the moved symbols now import the new modules.
2026-09-24 14:08:22 -04:00