test: mock-based integration tests for post-game refractor hook (#148) #158
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
ai-working
bug
enhancement
feature
in-queue
performance
security
tech-debt
todo
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-discord#158
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "issue/148-test-mock-based-integration-tests-for-post-game-re"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #148
Summary
Extracted the post-game refractor block from
complete_game()into a standalone_run_post_game_refractor_hook(db_game_id, channel)helper, then added 13 mock-based integration tests that exercise the real production code path without requiring a live game.Changes
command_logic/logic_gameplay.py_run_post_game_refractor_hook(db_game_id, channel)— contains thetry/exceptblock that was previously inline incomplete_game()at lines 4374–4387complete_game()now calls the helper (await _run_post_game_refractor_hook(db_game["id"], interaction.channel)) — no behaviour changetests/test_post_game_refractor_hook.py(new, 13 tests)TestEndpointOrder— both endpoints called, season-stats before evaluate, game ID interpolated correctlyTestTierUpNotifications— one call per tier-up, correct channel forwarded, no calls on empty/absent tier_upsTestVariantRenderTriggers— full tier_ups list passed to_trigger_variant_renders, not called on empty list, notifications fire before render triggerTestNonFatalErrors— season-stats raise, evaluate raise, None evaluate response — all non-fatalTest results
Other observations
tests/test_complete_game_hook.pycontains an_run_hookhelper that duplicates the hook code inline rather than calling the production function. Now that_run_post_game_refractor_hookis extractable, those tests could be simplified to call it directly — but that's out of scope for this issue.AI Code Review
Files Reviewed
command_logic/logic_gameplay.py(modified — extraction + call site update)tests/test_post_game_refractor_hook.py(added — 13 tests)Findings
Correctness
No issues found. The extraction is mechanical — the try/except block is moved verbatim into
_run_post_game_refractor_hook, withdb_game['id']→db_game_idandinteraction.channel→channelas expected parameter substitutions. Call site passes the same values.loggeris in scope at module level (line 80).notify_tier_completionis already imported fromhelpers.refractor_notifs. No behavior change.Security
No issues found.
Style & Conventions
_run_post_game_refractor_hookcorrectly signals a private module-level function, consistent with the existing_trigger_variant_renderspattern.db_game_id: intadded;channelleft unannotated (consistent with surrounding code).Test quality
asyncio_mode = autoinpytest.inihandles async test methods — no@pytest.mark.asynciodecorators needed. ✓patch()on async targets (notify_tier_completion,_trigger_variant_renders) auto-selectsAsyncMockin Python 3.8+ — the two tests inTestVariantRenderTriggersthat use barepatch(..., side_effect=async_fn)are correct. ✓test_no_notify_when_tier_ups_key_absentcorrectly exercises theif evo_result and ...guard —{}is falsy, so the condition short-circuits. ✓test_nonfatal_when_season_stats_raisesusesside_effect=Exception(...)(an instance, not a callable) —AsyncMockraises it on the first await, which the outer try/except catches. ✓test_notifications_before_render_trigger) tracks execution sequence via a shared list — solid approach for ordering assertions.Suggestions
tests/test_complete_game_hook.py's inline_run_hookhelper could eventually be replaced with a direct call to_run_post_game_refractor_hook, but that's a separate cleanup and not a blocker.Verdict: APPROVED
Clean extraction with no behavior change, comprehensive test coverage, and correct mock usage throughout. Ready to merge.
Automated review by Claude PR Reviewer
Approved via pd-pr