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

108 lines
3.3 KiB
Python

"""Regression tests for live Codex app-server events.
The history projector is completion-only. These tests protect the parallel
display bridge (make_codex_app_server_event_bridge) that makes deltas and
tool cards visible before resume: it fires both the tool_progress bubbles
AND the authoritative stable-ID tool_start/tool_complete callbacks the TUI
tool cards depend on.
Grafted from PR #65412 (@HaiderSultanArc) onto the merged bridge.
"""
from types import SimpleNamespace
from agent.codex_runtime import (
_codex_item_completion_payload,
make_codex_app_server_event_bridge,
)
from agent.transports.codex_event_projector import _deterministic_call_id
def _recording_agent():
calls = {
"stream": [],
"reasoning": [],
"tool_progress": [],
"tool_start": [],
"tool_complete": [],
}
agent = SimpleNamespace(
_fire_stream_delta=lambda text: calls["stream"].append(text),
_fire_reasoning_delta=lambda text: calls["reasoning"].append(text),
tool_progress_callback=lambda *args, **kwargs: calls["tool_progress"].append((
args,
kwargs,
)),
tool_start_callback=lambda call_id, name, args: calls["tool_start"].append((
call_id,
name,
args,
)),
tool_complete_callback=lambda call_id, name, args, result: calls[
"tool_complete"
].append((call_id, name, args, result)),
_emit_interim_assistant_message=None,
show_commentary=True,
)
return agent, calls
def test_stable_ids_match_history_projector():
"""The bridge's stable call ids mirror CodexEventProjector so a live
TUI tool card correlates with the projected history entry after
resume."""
agent, calls = _recording_agent()
bridge = make_codex_app_server_event_bridge(agent)
mcp = {
"type": "mcpToolCall",
"id": "m1",
"server": "filesystem",
"tool": "read",
"arguments": {"path": "a.py"},
}
bridge({"method": "item/started", "params": {"item": mcp}})
call_id, name, args = calls["tool_start"][0]
assert call_id == _deterministic_call_id("mcp__filesystem__read", "m1")
assert name == "mcp.filesystem.read"
assert args == {"path": "a.py"}
calls["tool_start"].clear()
patch = {
"type": "fileChange",
"id": "p1",
"changes": [{"kind": {"type": "add"}, "path": "a.py"}],
}
bridge({"method": "item/started", "params": {"item": patch}})
call_id, name, args = calls["tool_start"][0]
assert call_id == _deterministic_call_id("apply_patch", "p1")
assert name == "apply_patch"
assert args == {"changes": [{"kind": "add", "path": "a.py"}]}
def test_failed_command_result_and_error_flag_are_preserved():
agent, calls = _recording_agent()
bridge = make_codex_app_server_event_bridge(agent)
item = {
"type": "commandExecution",
"id": "failed",
"command": "false",
"aggregatedOutput": "boom",
"exitCode": 2,
}
bridge({"method": "item/completed", "params": {"item": item}})
result, is_error = _codex_item_completion_payload(item)
assert result == "[exit 2]\nboom"
assert is_error is True
assert calls["tool_progress"][0][1]["is_error"] is True
assert calls["tool_complete"][0][3] == "[exit 2]\nboom"