mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
Second, deeper pass over tools/gateway/hermes_cli plus first pass over the trees wave 1 missed (acp, acp_adapter, skills, computer_use, docker, dashboard, conformance, monitoring, secret_sources, hermes_state, providers). Same rubric as wave 1 (AGENTS.md test policy); security, alternation/caching invariants, issue-number regressions, and E2E kept. Real test-quality fixes found and rooted out along the way: - tests/tools/test_command_guards.py made real auxiliary-LLM HTTPS calls (DEFAULT_CONFIG smart-approval leaked in) — pinned approval mode=manual via autouse fixture: 17.4s → 0.4s. - test_model_switch_custom_providers.py / test_user_providers_model_switch.py silently probed live provider catalogs (~2s/test) — stubbed cached_provider_model_ids/provider_model_ids/fetch_api_models. - test_telegram_noise_filter.py: 15-platform copy-paste matrix over shared gateway.run logic → 3 representative platforms (55s → 3.9s). - test_gateway_shutdown.py: stop()'s 5s interrupt-deadline loop spun on MagicMock agents — interrupt.side_effect now clears _running_agents (22s → 1.0s). - test_gateway_inactivity_timeout.py poll-harness timings shrunk 3-5x (24s → 1.1s); test_mcp_stability.py backoff/SIGTERM-grace sleeps patched (15.4s → 2.5s); test_async_delegation.py negative-drain wait 5s → 0.5s. - test_telegram_init_deadline.py: loop-block margin restored to 1.0s with rationale comment — the watchdog-dump assertion needs the loop blocked well past deadline+grace under parallel load (flaked once in the 40-worker verification run at a 0.2s margin). Verification: full hermetic suite via scripts/run_tests.sh — 2,438 files, 21,718 tests passed, 0 failed, 293.9s wall. Suite totals vs original baseline: 46,820 → 19,757 test functions (−57.8%), wall 583.5s → 293.9s (−50%), subprocess CPU 13,564s → 11,623s.
107 lines
3 KiB
Python
107 lines
3 KiB
Python
"""Tests for the kanban `promote` verb (issue #28822).
|
|
|
|
The realistic bug scenario from #28822 is: a child task ends up in
|
|
``todo`` with all its parents already ``done`` (because the
|
|
auto-promote daemon hasn't run, or a manual close raced it).
|
|
Direct-SQL setup is used to construct that state deterministically.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from hermes_cli import kanban as kb_cli
|
|
from hermes_cli import kanban_db as kb
|
|
|
|
|
|
@pytest.fixture
|
|
def kanban_home(tmp_path, monkeypatch):
|
|
home = tmp_path / ".hermes"
|
|
home.mkdir()
|
|
monkeypatch.setenv("HERMES_HOME", str(home))
|
|
monkeypatch.setattr(Path, "home", lambda: tmp_path)
|
|
db_path = kb.kanban_db_path(board="default")
|
|
kb._INITIALIZED_PATHS.discard(str(db_path.resolve()))
|
|
kb.init_db()
|
|
return home
|
|
|
|
|
|
@pytest.fixture
|
|
def conn(kanban_home):
|
|
with kb.connect() as c:
|
|
yield c
|
|
|
|
|
|
def _stuck_todo(conn, *, parents_done=True, n_parents=1):
|
|
"""Build the #28822 scenario: child in 'todo' whose parents may
|
|
have closed as 'done' without the auto-promote logic firing.
|
|
"""
|
|
parent_ids = [
|
|
kb.create_task(conn, title=f"parent{i}", assignee="setup")
|
|
for i in range(n_parents)
|
|
]
|
|
child_id = kb.create_task(
|
|
conn, title="child", parents=parent_ids, assignee="setup"
|
|
)
|
|
assert kb.get_task(conn, child_id).status == "todo"
|
|
if parents_done:
|
|
for pid in parent_ids:
|
|
conn.execute(
|
|
"UPDATE tasks SET status='done' WHERE id=?", (pid,)
|
|
)
|
|
return child_id, parent_ids
|
|
|
|
|
|
def test_promote_stuck_todo_succeeds(conn):
|
|
child, _ = _stuck_todo(conn, parents_done=True)
|
|
ok, err = kb.promote_task(conn, child, actor="tester")
|
|
assert ok and err is None
|
|
assert kb.get_task(conn, child).status == "ready"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# CLI `_cmd_promote` — bulk via `--ids` (the issue's anti-respawn use case:
|
|
# promote all children of a closed parent in one command).
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def _promote_ns(task_id, *, ids=None, reason=None, force=False,
|
|
dry_run=False, as_json=False):
|
|
return argparse.Namespace(
|
|
task_id=task_id,
|
|
reason=list(reason or []),
|
|
ids=list(ids or []) or None,
|
|
force=force,
|
|
dry_run=dry_run,
|
|
json=as_json,
|
|
)
|
|
|
|
|
|
def test_cli_promote_bulk_ids_promotes_all(kanban_home, capsys):
|
|
with kb.connect() as conn:
|
|
parent = kb.create_task(conn, title="parent")
|
|
children = [
|
|
kb.create_task(conn, title=f"c{i}", parents=[parent])
|
|
for i in range(3)
|
|
]
|
|
conn.execute("UPDATE tasks SET status='done' WHERE id=?", (parent,))
|
|
rc = kb_cli._cmd_promote(_promote_ns(children[0], ids=children[1:]))
|
|
assert rc == 0
|
|
out = capsys.readouterr().out
|
|
for c in children:
|
|
assert c in out
|
|
with kb.connect() as conn:
|
|
for c in children:
|
|
assert kb.get_task(conn, c).status == "ready"
|
|
|
|
|