test(dev_tools): fix dead render mock in test_successful_batter_flow (#169) #170
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
autonomous
bug
enhancement
feature
in-queue
performance
security
size:M
size:S
tech-debt
tests
todo
type:feature
type:stability
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-discord#170
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "issue/169-test-dev-tools-refractor-test-render-step-mock-is"
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 #169
What
test_successful_batter_flowpatcheddb_getto stub the card-render step, but the render call in_execute_refractor_testusesaiohttp.ClientSessiondirectly — notdb_get. The mock was never consumed; the test silently hit the non-fatalexceptbranch (⚠️ Card render failed) instead of the happy path.Fix
patch("cogs.dev_tools.db_get")and unusedmock_get.return_valueaiohttp.ClientSessionmock (status 200) using explicit__aenter__/__aexit__onMagicMock(required becausesess.get(url)must return an async context manager, not a coroutine)assert "✅ Card rendered + S3 upload triggered" in result_textFiles changed
tests/test_dev_tools.py—TestRefractorTestExecute::test_successful_batter_flowTests
14/14 pass (
python -m pytest tests/test_dev_tools.py -v)AI Code Review
Files Reviewed
tests/test_dev_tools.py(modified —TestRefractorTestExecute::test_successful_batter_flow)Findings
Correctness
No issues found. The mock structure correctly mirrors production usage:
aiohttp.ClientSession(headers=AUTH_TOKEN)returnsmock_sessviareturn_value=mock_sesson the patched class ✓async with mock_sess as sess→mock_sess.__aenter__returnsmock_sessitself ✓sess.get(render_url)→get_cm(a proper async context manager) ✓async with get_cm as r→mock_render_respwithstatus = 200✓r.status == 200→ branch appends"✅ Card rendered + S3 upload triggered"✓The removed
patch("cogs.dev_tools.db_get")was genuinely dead —_execute_refractor_testmakes nodb_getcalls (onlydb_post+ directaiohttp). Removal is safe.The new assertion
assert "✅ Card rendered + S3 upload triggered" in result_textcloses the gap flagged in the PR #168 review: previously only"✅"and"game"were checked, which passed even while the render step silently failed.Security
No issues found. Test file only.
Style & Conventions
No issues found. Docstring accurately documents the historical bug and fix. Mock setup is idiomatic
unittest.mock.Suggestions
None.
Verdict: APPROVED
Directly addresses the dead-mock issue flagged in the PR #168 review. Mock wiring is correct for the double async context manager pattern (
ClientSession→sess.get). Happy-path assertion is now meaningful.Automated review by Claude PR Reviewer (posted as COMMENT — Gitea blocks self-approval)
AI Code Review
Files Reviewed
tests/test_dev_tools.py(modified —TestRefractorTestExecute::test_successful_batter_flowonly)Findings
Correctness
No issues found.
Mock wiring is correct for the double async context manager pattern at
dev_tools.py:375-376:patch("cogs.dev_tools.aiohttp.ClientSession", return_value=mock_sess)— correct patch target;aiohttpis imported as a module indev_tools.pysocogs.dev_tools.aiohttp.ClientSessionis the right pathaiohttp.ClientSession(headers=AUTH_TOKEN)→ returnsmock_sess✓async with mock_sess as sess:→mock_sess.__aenter__returnsmock_sess→sess = mock_sess✓sess.get(render_url)→ returnsget_cm✓async with get_cm as r:→get_cm.__aenter__returnsmock_render_respwithstatus=200✓r.status == 200→ True → appends"✅ Card rendered + S3 upload triggered"✓Dead mock removal is correct:
_execute_refractor_testmakes zerodb_getcalls (all API calls usedb_post; render uses rawaiohttp). The old mock was silently dropping into theexceptbranch atdev_tools.py:384.New assertion
assert "✅ Card rendered + S3 upload triggered" in result_textcloses the coverage gap from PR #168 suggestion #1.Security
No issues found.
Style & Conventions
No issues found. Mock setup follows the existing pattern in the test file. Docstring updated to explain the bug and fix inline.
Suggestions
None.
Verdict: APPROVED
Mock wiring is correct, dead mock removed, assertion added. Closes the silent test regression identified in PR #168. Clean.
Automated review by Claude PR Reviewer