verify.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """``hermes verify`` subcommand parser.
  2. Follows the pattern of ``hermes_cli/subcommands/doctor.py``: parser built
  3. here, handler injected to avoid importing ``main``.
  4. """
  5. from __future__ import annotations
  6. from typing import Callable
  7. from hermes_cli.subcommands._shared import add_json_flag
  8. # Keep in sync with agent/verify/runner.py defaults; not imported here to
  9. # avoid paying an extra module import on every `hermes` invocation.
  10. DEFAULT_PHASE_TIMEOUT = 600.0
  11. DEFAULT_READY_TIMEOUT = 60.0
  12. def build_verify_parser(subparsers, *, cmd_verify: Callable) -> None:
  13. """Attach the ``verify`` subcommand to ``subparsers``."""
  14. verify_parser = subparsers.add_parser(
  15. "verify", help="Detect a project's run recipe and smoke-test it",
  16. description="Detect how the current project is built, tested, and started "
  17. "(or load the saved manifest at .hermes/environment.json), then "
  18. "run a verification pass: bootstrap -> build -> test -> start in "
  19. "background -> poll readiness -> teardown.")
  20. verify_parser.add_argument(
  21. "path", nargs="?", default=None, help="Project root to verify (default: current directory)")
  22. verify_parser.add_argument(
  23. "--detect-only", action="store_true",
  24. help="Only detect and print the recipe as JSON; run nothing")
  25. verify_parser.add_argument(
  26. "--save", action="store_true",
  27. help="Save the recipe as .hermes/environment.json in the project")
  28. verify_parser.add_argument(
  29. "--skip-start", action="store_true",
  30. help="Run command phases but skip starting the app / readiness poll")
  31. verify_parser.add_argument(
  32. "--phase", action="append", choices=["bootstrap", "build", "test", "start"], default=None,
  33. help="Run only the given phase(s); repeatable")
  34. verify_parser.add_argument(
  35. "--port", type=int, default=None, help="Override the port used for the readiness poll")
  36. verify_parser.add_argument(
  37. "--timeout", type=float, default=DEFAULT_PHASE_TIMEOUT,
  38. help=f"Per-phase timeout in seconds (default: {DEFAULT_PHASE_TIMEOUT:.0f})")
  39. verify_parser.add_argument(
  40. "--ready-timeout", type=float, default=DEFAULT_READY_TIMEOUT,
  41. help=f"Readiness poll timeout in seconds (default: {DEFAULT_READY_TIMEOUT:.0f})")
  42. add_json_flag(verify_parser, "Emit a machine-readable JSON result")
  43. verify_parser.set_defaults(func=cmd_verify)