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).
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
import asyncio
|
|
from unittest.mock import AsyncMock
|
|
|
|
import pytest
|
|
|
|
from gateway.config import PlatformConfig
|
|
from plugins.platforms.discord.adapter import DiscordAdapter
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_discord_bot_task_runtime_exit_notifies_gateway_for_reconnect(monkeypatch):
|
|
"""A post-ready discord.py websocket task crash must not leave the gateway split-brained.
|
|
|
|
Regression: producers stayed systemd-active while Discord stopped responding after
|
|
a runtime ClientOSError/ConnectionResetError. The adapter must mark Discord as a
|
|
retryable fatal platform error and notify the gateway supervisor so the existing
|
|
reconnect watcher can replace the dead adapter.
|
|
"""
|
|
adapter = DiscordAdapter(PlatformConfig(enabled=True, token="token"))
|
|
adapter._running = True
|
|
adapter._ready_event.set()
|
|
adapter._notify_fatal_error = AsyncMock()
|
|
|
|
async def crash():
|
|
raise ConnectionResetError("Cannot write to closing transport")
|
|
|
|
task = asyncio.create_task(crash())
|
|
await asyncio.sleep(0)
|
|
|
|
adapter._handle_bot_task_done(task)
|
|
await asyncio.sleep(0)
|
|
|
|
assert adapter.has_fatal_error is True
|
|
assert adapter.fatal_error_retryable is True
|
|
assert adapter.fatal_error_code == "discord_gateway_task_exited"
|
|
assert adapter.fatal_error_message is not None
|
|
assert "Cannot write to closing transport" in adapter.fatal_error_message
|
|
adapter._notify_fatal_error.assert_awaited_once()
|
|
|
|
|