Files
hermes-agent/tests/hermes_cli/test_venv_holder_classifier.py
teknium1 7627eb466f fix(review): all-external fleet proves nothing for a SHA-less marker; holder argv strips both quote kinds
Review minors on #126179:

(a) update_cmd_fleet._marker_only_restart_obsolete: a fleet whose every
    row is EXTERNAL (served from another checkout root) fell through the
    row loop and cleared the marker with zero evidence about this checkout.
    For the SHA-less, inventory-less record it is now treated like an empty
    fleet and stays armed.

(b) update_cmd_windows._hermes_holder_subcommand stripped only double
    quotes before the inline-bootstrap check, so a shlex.join'ed
    runtime_command (`python -I -c '<bootstrap>' dashboard`, the shape
    launchd ProgramArguments take through main_dashboard) was never
    inventoried. Strip both quote kinds, as _is_entry already does.
2026-09-28 04:44:29 -07:00

51 lines
2.5 KiB
Python

"""Cross-platform unit tests for the venv-holder message classifier (#90778)."""
import pytest
from hermes_cli.update_cmd import (
_hermes_holder_subcommand,
)
class TestHolderSubcommand:
@pytest.mark.parametrize(
("cmdline", "expected"),
[
(r"C:\x\venv\Scripts\python.exe -m hermes_cli.main serve --host 127.0.0.1", "serve"),
(r"C:\x\venv\Scripts\python.exe -m hermes_cli.main dashboard", "dashboard"),
(r"python.exe -m hermes_cli.main gateway run", "gateway"),
# profile selector skipped; its VALUE must not become the subcommand
(r"python -m hermes_cli.main --profile serve gateway run", "gateway"),
(r"python -m hermes_cli.main -p work serve", "serve"),
# 90778: flags containing subcommand words are not subcommands
(r"python -m hermes_cli.main kanban --preserve-cache", "kanban"),
# 91869 review: EVERY top-level value flag must be skipped —
# a flag VALUE equal to a subcommand must not become the label
(r"python -m hermes_cli.main --reasoning high serve", "serve"),
(r"python -m hermes_cli.main -m dashboard serve", "serve"),
(r"python -m hermes_cli.main -t browser,files gateway run", "gateway"),
(r"python -m hermes_cli.main --model=dashboard serve", "serve"),
# -c consumes ONE value token; later bare tokens are (harmless,
# unhinted) subcommand candidates — pin that shape honestly
(r"python -m hermes_cli.main -c mysession serve", "serve"),
(r"C:\bin\hermes.exe dashboard", "dashboard"),
(r"/usr/local/bin/hermes serve", "serve"),
# no hermes entry at all
(r"python -c import time; time.sleep(3)", None),
# entry but no subcommand
(r"python -m hermes_cli.main", None),
],
)
def test_parses_subcommand(self, cmdline, expected):
assert _hermes_holder_subcommand(cmdline) == expected
def test_shlex_joined_store_launcher_bootstrap_is_inventoried(self):
"""launchd ProgramArguments arrive ``shlex.join``ed (single-quoted source); the dashboard
inventory must still read the subcommand behind the bootstrap."""
import shlex
from pathlib import Path
from hermes_cli._launchers import runtime_command
cmdline = shlex.join(runtime_command(Path("/opt/hermes-agent"), ["dashboard"], python="/opt/store/python"))
assert _hermes_holder_subcommand(cmdline) == "dashboard"