mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 11:22:02 +03:00
b81e71addd
The catch-up window (how late a missed cron occurrence may run instead of being skipped) was
half the job's period, clamped to 120s-2h, for every job. A job can now override it outright:
0-1440 minutes, `0` meaning never catch up.
`grace_minutes` is a real 0, not "unset" — and the obvious write pattern would eat it:
`v in {None, "", False}` (the `workdir` update lambda) and `if value:` both treat `0` as
False in Python. Both doors therefore share `jobs_time.normalize_grace_minutes`, reads test
`is None`, and the renderer formats before testing truthiness.
The override moves the dispatch stamp too: `_classify_dispatch_lateness` and the dispatch
health metric read the same window, so a job the scheduler calls "late" is never reported
overdue by the dashboard.
Refused on `once`/`interval` schedules: the window describes a missed wall clock, and a
duration has none.
Split from the timezone commit so it can be reverted alone.
58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
"""Unit tests for the extracted ``hermes cron`` parser builder.
|
|
|
|
Confirms ``build_cron_parser`` wires up the same subactions, aliases, options,
|
|
and ``func=cmd_cron`` dispatch that lived inline in ``main()`` before the
|
|
god-file Phase 2 extraction.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
|
|
from hermes_cli.subcommands.cron import build_cron_parser
|
|
|
|
|
|
def _sentinel_handler(args): # pragma: no cover - only identity is asserted
|
|
return "cron-handler"
|
|
|
|
|
|
def _build():
|
|
parser = argparse.ArgumentParser(prog="hermes")
|
|
subparsers = parser.add_subparsers(dest="command")
|
|
build_cron_parser(subparsers, cmd_cron=_sentinel_handler)
|
|
return parser
|
|
|
|
|
|
|
|
|
|
def test_cron_edit_no_agent_tristate():
|
|
parser = _build()
|
|
# --no-agent -> True, --agent -> False, neither -> None
|
|
assert parser.parse_args(["cron", "edit", "j", "--no-agent"]).no_agent is True
|
|
assert parser.parse_args(["cron", "edit", "j", "--agent"]).no_agent is False
|
|
assert parser.parse_args(["cron", "edit", "j"]).no_agent is None
|
|
|
|
|
|
def test_cron_accept_hooks_flag_on_run_and_tick():
|
|
parser = _build()
|
|
# --accept-hooks is suppressed-default; present only when passed.
|
|
ns = parser.parse_args(["cron", "run", "jid", "--accept-hooks"])
|
|
assert ns.accept_hooks is True
|
|
ns2 = parser.parse_args(["cron", "tick", "--accept-hooks"])
|
|
assert ns2.accept_hooks is True
|
|
|
|
|
|
def test_cron_timezone_and_grace_flags():
|
|
parser = _build()
|
|
created = parser.parse_args(
|
|
["cron", "create", "0 9 * * *", "hi", "--timezone", "Asia/Hong_Kong",
|
|
"--grace-minutes", "0"])
|
|
assert created.timezone == "Asia/Hong_Kong"
|
|
assert created.grace_minutes == "0", "an int-ish string must survive to the normalizer"
|
|
|
|
edited = parser.parse_args(["cron", "edit", "j", "--timezone", "", "--grace-minutes", ""])
|
|
assert edited.timezone == "", "an empty value is the documented clear"
|
|
assert edited.grace_minutes == ""
|
|
|
|
assert parser.parse_args(["cron", "edit", "j"]).timezone is None
|