fix: use card_type field instead of track_name string in variant renders (#149) #153
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#153
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "issue/149-fix-variant-render-uses-fragile-track-name-string"
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 #149
What changed
Replaced fragile
track_namestring matching in_trigger_variant_renders()with the structuredcard_typefield already present in refractor API data.Before:
After:
The old code would silently render batting cards for pitchers if the API ever returned "Starting Pitcher", "SP", or any string other than exactly "Pitcher". The
card_typefield (sp/rp/batter) is the authoritative structured value from the refractor API.Files changed
command_logic/logic_gameplay.py— 2-line fix in_trigger_variant_renders()tests/test_post_game_render.py— updated fixtures to usecard_typefield; strengthened assertions to verify correct card type in URLTests
All 4 tests pass. Assertions now verify that
battingcard/pitchingcardappears in the render URL, which would have caught the original bug.AI Code Review
Files Reviewed
command_logic/logic_gameplay.py(modified — 2-line fix in_trigger_variant_renders)tests/test_post_game_render.py(modified — fixture fields and assertions)Findings
Correctness
Concern — unverified API field path (potential silent regression):
The fix assumes
card_typeis a top-level field in therefractor/evaluate-gametier_up objects (tier_up.get("card_type", "batter")). Two pieces of evidence suggest this may not be the case:tests/test_complete_game_hook.py:190–199— the comment there explicitly says "Full API response shape — the evaluate-game endpoint returns all these keys" and the fixture contains:player_id,team_id,player_name,old_tier,new_tier,current_value,track_name. Nocard_type.cogs/players.py:513— the analogouscard_typelookup from therefractor/cardsendpoint accesses it nested inside atrackdict:If
evaluate-gamehas the same nesting,tier_up.get("card_type", "batter")always returns"batter"regardless of pitcher status.Risk: If
card_typeis not a top-level field inevaluate-gameresponses, this change is a silent regression — the original code at least correctly handledtrack_name == "Pitcher"(the common case). The new code would silently render all pitchers as batting cards, with no error or warning.The fix is logically correct if the API does return
card_typeat the top level. But that contract isn't documented or validated in this codebase.Recommendation: Verify against the actual
refractor/evaluate-gameresponse shape. If the field exists at the top level, updatetest_complete_game_hook.py:190–199to includecard_typein the documented shape. If it's nested (likerefractor/cards), use:tier_up.get("track", {}).get("card_type", "batter").Security
No issues found.
Style & Conventions
in ("sp", "rp")pattern mirrorscogs/players.py:514exactly. Consistent with existing conventions.ctas a variable name is acceptable butcard_type_raworctin context is fine — not a blocker.Suggestions
"card_type"key to thetest_complete_game_hook.py:191fixture and update the "Full API response shape" comment. That fixture is now stale documentation of the tier_up shape.Verdict: COMMENT
The logic is correct in principle —
card_typeas a structured field is strictly better than string-matchingtrack_name. Thein ("sp", "rp")pattern is consistent with the rest of the codebase. However, the API contract for thecard_typefield's location inevaluate-gametier_up objects is not verified within this codebase. Confirm the field is top-level (not nested intrack) before merging. If it is, this is a clean APPROVE.Automated review by Claude PR Reviewer
a56004fbd4to9eb9669151