Files
wehub-resource-sync b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
Build Skills Index / trigger-deploy (push) Waiting to run
CI / Deny unrelated histories (push) Has been skipped
CI / CI timing report (push) Blocked by required conditions
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / All required checks pass (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

71 lines
2.5 KiB
Python

"""Contract for the headless ``hermes serve`` backend command.
``serve`` is what the desktop app and remote backends launch — the same gateway
as ``dashboard`` (shared handler) but always headless, and decoupled in name so
the desktop never invokes ``dashboard``. These tests pin that contract:
- ``serve`` routes to the same handler as ``dashboard``;
- ``serve`` is headless by default, ``dashboard`` is not;
- both expose the identical server-runtime flag surface.
"""
from __future__ import annotations
import argparse
from hermes_cli.subcommands.dashboard import build_dashboard_parser
def _dash(args): # sentinel handler — identity-compared, never invoked
return args
def _register(args):
return args
def _parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
build_dashboard_parser(
parser.add_subparsers(dest="command"),
cmd_dashboard=_dash,
cmd_dashboard_register=_register,
)
return parser
def test_serve_routes_to_the_shared_dashboard_handler():
args = _parser().parse_args(["serve"])
assert args.func is _dash
def test_serve_is_headless_by_default_but_dashboard_is_not():
assert _parser().parse_args(["serve"]).no_open is True
assert _parser().parse_args(["dashboard"]).no_open is False
def test_serve_accepts_the_legacy_no_open_flag_as_a_noop():
# The desktop backend spawn (and old shells) may still pass --no-open;
# serve must tolerate it rather than erroring on an unknown argument.
assert _parser().parse_args(["serve", "--no-open"]).no_open is True
def test_serve_takes_the_same_runtime_flags_as_dashboard():
argv = ["--host", "0.0.0.0", "--port", "0", "--insecure", "--skip-build", "--isolated"]
serve = _parser().parse_args(["serve", *argv])
dash = _parser().parse_args(["dashboard", *argv])
for field in ("host", "port", "insecure", "skip_build", "isolated"):
assert getattr(serve, field) == getattr(dash, field)
def test_serve_supports_the_lifecycle_flags():
for flag in ("--stop", "--status"):
assert getattr(_parser().parse_args(["serve", flag]), flag.lstrip("-")) is True
def test_serve_is_a_headless_backend_but_dashboard_is_not():
# `headless_backend` is the flag cmd_dashboard reads to skip the web UI
# build; only `serve` carries it.
assert getattr(_parser().parse_args(["serve"]), "headless_backend", False) is True
assert getattr(_parser().parse_args(["dashboard"]), "headless_backend", False) is False