test: mock-based integration tests for post-game refractor hook #148

Closed
opened 2026-04-08 00:23:47 +00:00 by cal · 1 comment
Owner

Problem

Post-game hook tests (REF-50+) and tier-up notification tests (REF-60+) require a live game to test end-to-end. No automated tests cover the actual post-game flow: season-stats update → evaluate-game call → notification dispatch → variant render trigger.

The hook at logic_gameplay.py:4374-4387 is wrapped in try/except with a warning log, so failures are silent in production.

Proposed Approach

Create mock-based integration tests that simulate the post-game flow:

  1. Mock db_post("season-stats/update-game/...") returning success
  2. Mock db_post("refractor/evaluate-game/...") returning tier-up data
  3. Verify notify_tier_completion is called with correct arguments
  4. Verify _trigger_variant_renders is called for tier-ups with variant_created

This can run in CI without a live game and catches regressions in the orchestration logic.

## Problem Post-game hook tests (REF-50+) and tier-up notification tests (REF-60+) require a live game to test end-to-end. No automated tests cover the actual post-game flow: season-stats update → evaluate-game call → notification dispatch → variant render trigger. The hook at `logic_gameplay.py:4374-4387` is wrapped in try/except with a warning log, so failures are silent in production. ## Proposed Approach Create mock-based integration tests that simulate the post-game flow: 1. Mock `db_post("season-stats/update-game/...")` returning success 2. Mock `db_post("refractor/evaluate-game/...")` returning tier-up data 3. Verify `notify_tier_completion` is called with correct arguments 4. Verify `_trigger_variant_renders` is called for tier-ups with `variant_created` This can run in CI without a live game and catches regressions in the orchestration logic.
Claude added the
ai-working
label 2026-04-08 13:31:18 +00:00
Claude added the
ai-working
label 2026-04-08 13:33:26 +00:00
Claude added the
ai-pr-opened
label 2026-04-08 13:35:14 +00:00
Collaborator

PR #158 opened: #158

Approach: Extracted the inline try/except block from complete_game() (lines 4374–4387) into _run_post_game_refractor_hook(db_game_id, channel). This makes the hook directly testable without wiring up a full game session.

Added 13 tests in tests/test_post_game_refractor_hook.py covering:

  • Endpoint ordering (season-stats before evaluate)
  • notify_tier_completion called once per tier-up with correct channel
  • _trigger_variant_renders called with full tier_ups list
  • No notifications/renders on empty or absent tier_ups
  • Non-fatal: exceptions from any step don't propagate
PR #158 opened: https://git.manticorum.com/cal/paper-dynasty-discord/pulls/158 **Approach**: Extracted the inline `try/except` block from `complete_game()` (lines 4374–4387) into `_run_post_game_refractor_hook(db_game_id, channel)`. This makes the hook directly testable without wiring up a full game session. Added 13 tests in `tests/test_post_game_refractor_hook.py` covering: - Endpoint ordering (season-stats before evaluate) - notify_tier_completion called once per tier-up with correct channel - _trigger_variant_renders called with full tier_ups list - No notifications/renders on empty or absent tier_ups - Non-fatal: exceptions from any step don't propagate
Claude removed the
ai-working
label 2026-04-08 13:35:23 +00:00
cal closed this issue 2026-04-08 14:26:08 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/paper-dynasty-discord#148
No description provided.