Files
hermes-agent/tests/hermes_cli/test_desktop_slash_registry.py
T
teknium1 e06efbcff0 fix(ci): desktop slash-registry dump gets --check; apps/ contract JSON edits run the Python lane
scripts/dump_desktop_slash_registry.py --check exits 1 (no write) when the
committed apps/desktop/src/lib/desktop-slash-registry.json differs from
desktop_surface_registry(); the docstring now cites the test that actually
fails (test_desktop_slash_registry.py, not test_commands.py). The pytest
runs --check as a subprocess (green on the committed file) and calls
check() on a hand-edited copy (red).

scripts/ci/classify_changes.py: _PY_SKIP includes apps/, so an apps-only
edit of that JSON (or apps/shared/src/gateway-events.json) skipped the
Python lane and the only equality check never ran in CI. A table of
cross-language contract files now forces python:true; two classifier rows
pin it.
2026-09-13 06:50:57 -07:00

51 lines
2.2 KiB
Python

"""The desktop's offline slash block-list is a dump of COMMAND_REGISTRY, never hand-authored."""
import importlib.util
import json
import subprocess
import sys
from pathlib import Path
from hermes_cli.commands import COMMAND_REGISTRY, desktop_surface_registry, resolve_command
ROOT = Path(__file__).resolve().parents[2]
DUMP = ROOT / "apps" / "desktop" / "src" / "lib" / "desktop-slash-registry.json"
DUMP_SCRIPT = ROOT / "scripts" / "dump_desktop_slash_registry.py"
def test_committed_desktop_dump_matches_registry():
"""Editing a ``desktop=`` value or alias without re-running the dump script is a drift."""
committed = json.loads(DUMP.read_text(encoding="utf-8"))
assert committed == desktop_surface_registry(), (
"apps/desktop/src/lib/desktop-slash-registry.json is stale — run "
"scripts/dump_desktop_slash_registry.py"
)
def test_desktop_surface_registry_covers_every_alias_with_its_canonical_value():
registry = desktop_surface_registry()
for cmd in COMMAND_REGISTRY:
for key in (cmd.name, *cmd.aliases):
assert registry.get(f"/{key}") == cmd.desktop, key
for key in registry:
assert resolve_command(key) is not None, key
def test_dump_script_check_mode_is_green_on_the_committed_json_and_red_on_drift(tmp_path):
"""``--check`` is the shell-usable twin of the equality test: 0 on the committed file, 1 on a stale copy."""
proc = subprocess.run(
[sys.executable, str(DUMP_SCRIPT), "--check"], cwd=ROOT, capture_output=True, text=True, timeout=120,
)
assert proc.returncode == 0, proc.stderr
# Negative case in-process against a hand-edited copy: flipping one value must be caught.
spec = importlib.util.spec_from_file_location("dump_desktop_slash_registry", DUMP_SCRIPT)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
stale = tmp_path / "desktop-slash-registry.json"
payload = json.loads(DUMP.read_text(encoding="utf-8"))
payload[next(iter(payload))] = {"desktop": "hand-edited"}
stale.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n", encoding="utf-8")
assert mod.check(stale) == 1
assert mod.check(DUMP) == 0