74a95a3ddf
/bg (formerly /background, which is retired) keeps the existing semantics: spawn a fresh, independent agent session in the background. /btw is now its own command matching the convention other harnesses use: ask a quick side question ABOUT the current conversation without interrupting it. A one-shot auxiliary LLM call (main model by default, overridable via auxiliary.side_question.* in config.yaml) answers from a read-only transcript snapshot — the live session's history, role alternation, and prompt cache are untouched, and the current turn keeps running. Surfaces wired: CLI (inline mid-run dispatch), gateway (all messengers, busy-dispatch table + idle dispatch, i18n across all 17 locales), TUI (prompt.btw RPC + btw.complete event), Discord native slash, relay command manifest, desktop exec routing, docs (EN + zh-Hans).
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
"""Invariant tests for the declarative busy_policy on CommandDef.
|
|
|
|
Guards the contract introduced by the Guard-2 refactor (gateway/run.py):
|
|
every command's mid-run behavior is declared on its CommandDef via
|
|
``busy_policy`` / ``busy_handler`` and the historical
|
|
``ACTIVE_SESSION_BYPASS_COMMANDS`` frozenset is DERIVED from the registry
|
|
rather than hand-maintained.
|
|
"""
|
|
|
|
from hermes_cli.commands import (
|
|
ACTIVE_SESSION_BYPASS_COMMANDS,
|
|
COMMAND_REGISTRY,
|
|
VALID_BUSY_POLICIES,
|
|
is_interrupt_then_dispatch,
|
|
should_bypass_active_session,
|
|
)
|
|
|
|
# The hand-written frozenset as it existed before the busy_policy refactor.
|
|
# This is a behavior contract, not a snapshot: the derived set must remain a
|
|
# SUPERSET of these names (each had an explicit mid-run handler in the old
|
|
# Guard-2 if-chain and must keep bypassing the busy-reject catch-all).
|
|
_HISTORICAL_BYPASS_NAMES = frozenset(
|
|
{
|
|
"agents",
|
|
"approve",
|
|
"bg",
|
|
"btw",
|
|
"commands",
|
|
"deny",
|
|
"help",
|
|
"new",
|
|
"profile",
|
|
"queue",
|
|
"restart",
|
|
"status",
|
|
"steer",
|
|
"stop",
|
|
"update",
|
|
"version",
|
|
}
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_bypass_set_is_derived_from_registry():
|
|
expected = frozenset(
|
|
cmd.name for cmd in COMMAND_REGISTRY if cmd.busy_policy != "reject"
|
|
)
|
|
assert ACTIVE_SESSION_BYPASS_COMMANDS == expected
|
|
|
|
|
|
def test_interrupt_then_dispatch_class():
|
|
# The cancel-handoff class (Guard 1, gateway/platforms/base.py) must
|
|
# contain exactly the /stop and /new (alias /reset) commands today.
|
|
assert is_interrupt_then_dispatch("stop")
|
|
assert is_interrupt_then_dispatch("new")
|
|
assert is_interrupt_then_dispatch("reset") # alias of /new
|
|
assert not is_interrupt_then_dispatch("model")
|
|
assert not is_interrupt_then_dispatch("status")
|
|
assert not is_interrupt_then_dispatch(None)
|
|
assert not is_interrupt_then_dispatch("not-a-command")
|
|
|
|
|