3.8 KiB
MACP Phase 2A — Test Suite
Branch: feat/macp-phase2a (commit on top of existing)
Repo worktree: ~/src/mosaic-bootstrap-worktrees/macp-phase2a
Objective
Write a comprehensive test suite for the Phase 2A event bridge code using Python unittest (stdlib only). Tests must be runnable with python3 -m pytest tests/ or python3 -m unittest discover tests/.
Task 1: Test infrastructure (tests/conftest.py + tests/run_tests.sh)
Create tests/ directory at repo root with:
conftest.py— shared fixtures: temp directories, sample events, sample configrun_tests.sh— simple runner:python3 -m unittest discover -s tests -p 'test_*.py' -v__init__.py— empty, makes tests a package
Sample events fixture should include one of each type: task.assigned, task.started, task.completed, task.failed, task.escalated, task.gated, task.retry.scheduled
Task 2: Event watcher tests (tests/test_event_watcher.py)
Test the EventWatcher class from tools/orchestrator-matrix/events/event_watcher.py.
Test cases:
test_poll_empty_file— No events file exists → returns empty listtest_poll_new_events— Write 3 events to ndjson, poll → returns all 3test_cursor_persistence— Poll once (reads 3), poll again → returns 0 (cursor saved)test_cursor_survives_restart— Poll, create new watcher instance, poll → no duplicatestest_corrupt_line_skipped— Insert a corrupt JSON line between valid events → valid events returned, corrupt skippedtest_callback_filtering— Register callback fortask.completedonly → only completed events trigger ittest_callback_receives_events— Register callback, poll → callback called with correct event dictstest_file_grows_between_polls— Poll (gets 2), append 3 more, poll → gets 3
Task 3: Webhook adapter tests (tests/test_webhook_adapter.py)
Test send_webhook and create_webhook_callback from tools/orchestrator-matrix/events/webhook_adapter.py.
Test cases:
test_send_webhook_success— Mock HTTP response 200 → returns Truetest_send_webhook_failure— Mock HTTP response 500 → returns Falsetest_send_webhook_timeout— Mock timeout → returns False, no crashtest_send_webhook_retry— Mock 500 then 200 → retries and succeedstest_event_filter— Config with filter["task.completed"]→ callback ignorestask.startedtest_webhook_disabled— Config withenabled: false→ no HTTP call madetest_ssrf_blocked— URL with private IP (127.0.0.1, 10.x) → blocked, returns False
Use unittest.mock.patch to mock urllib.request.urlopen.
Task 4: Discord formatter tests (tests/test_discord_formatter.py)
Test format_event and format_summary from tools/orchestrator-matrix/events/discord_formatter.py.
Test cases:
test_format_completed— Completed event → contains "✅" and task IDtest_format_failed— Failed event → contains "❌" and error messagetest_format_escalated— Escalated event → contains "🚨" and escalation reasontest_format_gated— Gated event → contains "🔍"test_format_started— Started event → contains "⚙️" and runtime infotest_format_unknown_type— Unknown event type → returns Nonetest_sanitize_control_chars— Event with control characters in message → stripped in outputtest_sanitize_mentions— Event with@everyonein message → neutralized in outputtest_format_summary— List of mixed events → summary with counts
Verification
After writing tests:
cd ~/src/mosaic-bootstrap-worktrees/macp-phase2a && python3 -m unittest discover -s tests -p 'test_*.py' -v— ALL tests must pass- Fix any failures before committing
Commit: test: add comprehensive test suite for Phase 2A event bridge