hermes-agent/tests/hermes_cli/test_kanban_cli_dispatch_passthrough.py
Teknium 6b81590c55
test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions
Systematic prune per AGENTS.md test policy, one pass over every major
test tree (gateway, hermes_cli, tools, agent, run_agent, plugins, cli,
cron, tui_gateway, honcho/openviking, root-level):

- DELETE: source-reading tests (read_text/getsource on prod files),
  change-detector tests (exact catalog counts, model-name snapshots,
  config version literals), mock-echo tests (assert a mock returns what
  it was told), assertion-free/trivial tests, near-duplicate
  parametrizations (boundaries + one representative kept), async/sync
  twin duplicates, cosmetic within-file variations.
- KEEP (mandatory): security/redaction/approval guards, message-role
  alternation invariants, prompt-caching/deterministic-call-id
  invariants, issue-number regression tests (deduped), E2E tests.
- 6 test files deleted outright (script-style/no-assert or fully
  redundant); conftest.py, fakes/, fixtures/ untouched.
- tests/acp/conftest.py added: autouse fixture stubs the live
  models.dev/GitHub/Copilot/Anthropic inventory fetches that ACP server
  tests performed on every session create — test_server.py 147s → 3.4s,
  and the tests are now genuinely hermetic.
- Sleep-based slowness shrunk where safe (codex_ttfb_watchdog,
  compression_concurrent_fork, etc.); no wall-clock assertion tightened.

Verification: full hermetic suite via scripts/run_tests.sh —
2439 files, 31,130 tests passed, 0 failed, 0 flaky retries, 315s wall
(baseline: 583s wall, 13,564s subprocess CPU).
2026-07-29 13:10:23 -07:00

96 lines
3.4 KiB
Python

"""Regression tests for #33488 (CLI max_in_progress / max_spawn / per-profile
config passthrough) and #29415 (kanban_swarm humanizer skill ref).
These two fixes are bundled because they're both small, both touch the
kanban dispatcher's CLI surface, and they each guard against a silent
operator footgun that only manifests in long-running setups.
"""
from __future__ import annotations
import argparse
import os
import sys
import tempfile
from types import SimpleNamespace
from unittest.mock import MagicMock, patch
import pytest
@pytest.fixture()
def isolated_kanban_home(monkeypatch):
"""Spin up a fresh HERMES_HOME with a clean kanban DB."""
test_home = tempfile.mkdtemp(prefix="kanban_cli_passthrough_")
os.makedirs(os.path.join(test_home, "profiles", "default"), exist_ok=True)
monkeypatch.setenv("HERMES_HOME", test_home)
for mod in list(sys.modules.keys()):
if mod.startswith("hermes_cli") or mod.startswith("hermes_state") or mod == "hermes_constants":
del sys.modules[mod]
yield test_home
def test_cli_dispatch_passes_max_in_progress_from_config(isolated_kanban_home, monkeypatch):
"""#33488: hermes kanban dispatch must pass kanban.max_in_progress from
config to dispatch_once. Without this, the global concurrency cap is
unreachable from the CLI even though it works from the gateway."""
from hermes_cli import kanban as kb_cli
from hermes_cli import kanban_db
# Configure max_in_progress in the loaded config.
fake_config = {
"kanban": {
"max_in_progress": 3,
"max_spawn": 5,
"default_assignee": "default",
"max_in_progress_per_profile": 2,
}
}
monkeypatch.setattr(
"hermes_cli.config.load_config", lambda: fake_config
)
captured = {}
def fake_dispatch_once(conn, **kwargs):
captured.update(kwargs)
return kanban_db.DispatchResult()
monkeypatch.setattr(kanban_db, "dispatch_once", fake_dispatch_once)
args = argparse.Namespace(dry_run=True, max=None, failure_limit=2, json=False)
kb_cli._cmd_dispatch(args)
# Every config value must have reached dispatch_once.
assert captured.get("max_in_progress") == 3, (
f"CLI must pass kanban.max_in_progress from config; got {captured.get('max_in_progress')!r}"
)
assert captured.get("max_spawn") == 5, (
f"CLI must pass kanban.max_spawn from config when --max is not provided; got {captured.get('max_spawn')!r}"
)
assert captured.get("default_assignee") == "default"
assert captured.get("max_in_progress_per_profile") == 2
def test_cli_max_flag_overrides_config_max_spawn(isolated_kanban_home, monkeypatch):
"""--max on the CLI takes precedence over kanban.max_spawn in config.
The CLI flag is the explicit operator signal; config is the default."""
from hermes_cli import kanban as kb_cli
from hermes_cli import kanban_db
fake_config = {"kanban": {"max_spawn": 10}}
monkeypatch.setattr("hermes_cli.config.load_config", lambda: fake_config)
captured = {}
monkeypatch.setattr(
kanban_db, "dispatch_once",
lambda conn, **kw: (captured.update(kw), kanban_db.DispatchResult())[1],
)
args = argparse.Namespace(dry_run=True, max=2, failure_limit=2, json=False)
kb_cli._cmd_dispatch(args)
assert captured.get("max_spawn") == 2, (
f"CLI --max=2 must override config kanban.max_spawn=10; got {captured.get('max_spawn')!r}"
)