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.
This commit is contained in:
teknium1
2026-09-12 23:59:30 -07:00
committed by Teknium
parent c764d6d354
commit e06efbcff0
2 changed files with 48 additions and 2 deletions
+25 -2
View File
@@ -2,7 +2,10 @@
"""Regenerate apps/desktop/src/lib/desktop-slash-registry.json from COMMAND_REGISTRY.
Run after changing any ``desktop=`` value or alias in ``hermes_cli/commands.py``;
``tests/hermes_cli/test_commands.py`` fails until the committed copy matches.
``tests/hermes_cli/test_desktop_slash_registry.py`` fails until the committed
copy matches. ``--check`` writes nothing and exits 1 when the committed JSON
differs from what the registry renders (the same verdict the pytest gives,
usable from any shell or CI step without pytest).
"""
from __future__ import annotations
@@ -22,6 +25,26 @@ def render() -> str:
return json.dumps(desktop_surface_registry(), indent=2, sort_keys=True) + "\n"
if __name__ == "__main__":
def check(out: Path = OUT) -> int:
"""0 when ``out`` matches the registry byte-for-byte, else 1 with a hint on stderr."""
committed = out.read_text(encoding="utf-8") if out.exists() else ""
if committed == render():
return 0
rel = out.relative_to(ROOT) if out.is_relative_to(ROOT) else out
print(f"{rel} is stale — run scripts/dump_desktop_slash_registry.py", file=sys.stderr)
return 1
def main(argv: list[str]) -> int:
if argv == ["--check"]:
return check()
if argv:
print(f"usage: {Path(__file__).name} [--check]", file=sys.stderr)
return 2
OUT.write_text(render(), encoding="utf-8")
print(f"wrote {OUT.relative_to(ROOT)}")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
@@ -1,12 +1,16 @@
"""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():
@@ -25,3 +29,22 @@ def test_desktop_surface_registry_covers_every_alias_with_its_canonical_value():
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