hermes-agent/tests/hermes_cli/test_kanban_project_link.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

66 lines
2 KiB
Python

"""Kanban <-> Projects integration: project-linked tasks get a deterministic
worktree path + branch instead of the random ``wt/<task-id>`` fallback."""
from __future__ import annotations
import os
import pytest
from hermes_cli import kanban_db as kb
from hermes_cli import projects_db as pdb
@pytest.fixture
def kanban_conn(tmp_path):
c = kb.connect(db_path=tmp_path / "kanban.db")
try:
yield c
finally:
c.close()
def _make_project(name="Web App", repo="/tmp/webapp"):
with pdb.connect_closing() as pc:
pid = pdb.create_project(pc, name=name, folders=[repo])
return pdb.get_project(pc, pid)
def test_project_linked_task_gets_deterministic_worktree_and_branch(kanban_conn):
proj = _make_project()
tid = kb.create_task(kanban_conn, title="Add login", project_id=proj.slug)
task = kb.get_task(kanban_conn, tid)
assert task.project_id == proj.id
assert task.workspace_kind == "worktree"
# Worktree dir anchored under the project's primary repo, keyed on task id.
assert task.workspace_path == os.path.join(proj.primary_path, ".worktrees", tid)
# Deterministic branch: <slug>/<task-id>-<title-slug>. NOT a random wt/...
assert task.branch_name == f"{proj.slug}/{tid}-add-login"
assert not task.branch_name.startswith("wt/")
def test_explicit_branch_overrides_project_default(kanban_conn):
proj = _make_project()
tid = kb.create_task(
kanban_conn,
title="x",
project_id=proj.slug,
workspace_kind="worktree",
branch_name="feature/custom",
)
task = kb.get_task(kanban_conn, tid)
assert task.branch_name == "feature/custom"
def test_unlinked_task_unchanged(kanban_conn):
tid = kb.create_task(kanban_conn, title="plain")
task = kb.get_task(kanban_conn, tid)
assert task.project_id is None
assert task.workspace_kind == "scratch"
# No branch is persisted — the worker still owns the wt/<id> fallback for
# genuinely ad-hoc worktree tasks, but unlinked scratch tasks have none.
assert task.branch_name is None