fix: use rounds_played directly in handle_info for finished games#2558
fix: use rounds_played directly in handle_info for finished games#2558immortal71 wants to merge 2 commits intoOWASP:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug (#2548) where handle_info/2 in GameLive.Show always computed requested_round = rounds_played + 1, even for finished games, causing the game summary view to break when a game:updated broadcast was received. Additionally, it fixes a prefix collision bug in convert_capec.py's shortcode matching and adds extensive test coverage across the Elixir and Python codebases.
Changes:
- Fixed
handle_info/2inGameLive.Showto mirrorhandle_params/3'sfinished_atcheck when computingrequested_round - Fixed
createlink()inconvert_capec.pyto use exact equality instead of substring matching (in), preventing false matches like V1.1.1 matching V1.1.10 - Added comprehensive test coverage across multiple test files for game logic, player actions, rate limiting, IP helpers, card controllers, and CAPEC link generation
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
copi.owasp.org/lib/copi_web/live/game_live/show.ex |
Core bug fix: added finished_at check in handle_info/2 |
copi.owasp.org/test/copi_web/live/game_live/show_test.exs |
Tests for finished game handling, non-matching topic, error redirect |
scripts/convert_capec.py |
Fixed shortcode matching from substring to exact equality |
tests/scripts/convert_capec_utest.py |
Tests for prefix collision, exact match, and empty shortcode |
copi.owasp.org/test/copi_web/live/player_live/show_test.exs |
Tests for player helper functions, next_round, voting |
copi.owasp.org/test/copi_web/live/player_live/form_component_test.exs |
Test for topic function, whitespace cleanup |
copi.owasp.org/test/copi_web/live/game_live/create_game_form_test.exs |
Test for invalid name changeset error path |
copi.owasp.org/test/copi_web/controllers/card_controller_test.exs |
Tests for format_capec/1 |
copi.owasp.org/test/copi_web/controllers/api_controller_test.exs |
Test for 404 on missing game in play_card |
copi.owasp.org/test/copi/rate_limiter_test.exs |
Tests for production bypass, cleanup, normalize_ip |
copi.owasp.org/test/copi/ip_helper_test.exs |
Tests for various IP extraction edge cases |
copi.owasp.org/test/copi/cornucopia_test.exs |
Tests for Game.find, continue_vote_count, majority votes |
copi.owasp.org/test/copi/cornucopia_logic_test.exs |
Tests for scoring edge cases, whitespace cleanup |
copi.owasp.org/test/copi_web/plugs/rate_limiter_plug_test.exs |
Test for nil remote_ip handling |
scripts/convert_capec.py
Outdated
| ) | ||
| for subitem in item["Items"]: | ||
| if shortcode in subitem["Shortcode"]: | ||
| if shortcode.removeprefix("V") == subitem["Shortcode"].removeprefix("V"): |
There was a problem hiding this comment.
The PR description mentions only two files (game_live/show.ex and game_live/show_test.exs), but this PR also includes a bug fix in scripts/convert_capec.py (prefix collision fix for shortcode matching), new tests in convert_capec_utest.py, and substantial test coverage additions across many Elixir test files (rate limiter, IP helper, cornucopia logic, player/game controllers, etc.). The PR description should be updated to reflect all these changes.
fc3d3dc to
18a9847
Compare
18a9847 to
96884a3
Compare
|
@sydseter is this good to go ??? |
|
Hello @immortal71, This is a solid PR that addresses a specific UI bug where finished games would incorrectly show a non-existent round number when receiving game update broadcasts. The fix is straightforward and follows the existing pattern already implemented in handle_params/3, making it a clean and consistent solution. You also took the opportunity to significantly improve test coverage across the codebase, which is always valuable. However, the PR description is misleading as it only mentions two files but actually includes additional bug fixes in convert_capec.py and extensive test additions across multiple modules. The description should be updated to accurately reflect all the changes being introduced. |
|
@sydseter just here for follow up,..... is this good to go |
Summary
Fixes #2548.
handle_info/2inGameLive.Showalways setrequested_round = updated_game.rounds_played + 1when agame:updatedbroadcast was received, even for games that are already finished. This caused the finished-game summary page to show a non-existent round.handle_params/3already handled this correctly with afinished_atcheck. This PR applies the same logic tohandle_info/2.Changes
copi.owasp.org/lib/copi_web/live/game_live/show.ex: mirrorhandle_paramsfinished-game check insidehandle_infocopi.owasp.org/test/copi_web/live/game_live/show_test.exs: add test verifyingrequested_roundstays atrounds_played(not+1) after a broadcast for a finished game