Skip to content

fix: use rounds_played directly in handle_info for finished games#2558

Open
immortal71 wants to merge 2 commits intoOWASP:masterfrom
immortal71:fix/2548-game-finished-round
Open

fix: use rounds_played directly in handle_info for finished games#2558
immortal71 wants to merge 2 commits intoOWASP:masterfrom
immortal71:fix/2548-game-finished-round

Conversation

@immortal71
Copy link
Contributor

Summary

Fixes #2548.

handle_info/2 in GameLive.Show always set requested_round = updated_game.rounds_played + 1 when a game:updated broadcast was received, even for games that are already finished. This caused the finished-game summary page to show a non-existent round.

handle_params/3 already handled this correctly with a finished_at check. This PR applies the same logic to handle_info/2.

Changes

  • copi.owasp.org/lib/copi_web/live/game_live/show.ex: mirror handle_params finished-game check inside handle_info
  • copi.owasp.org/test/copi_web/live/game_live/show_test.exs: add test verifying requested_round stays at rounds_played (not +1) after a broadcast for a finished game

Copilot AI review requested due to automatic review settings March 7, 2026 14:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/2 in GameLive.Show to mirror handle_params/3's finished_at check when computing requested_round
  • Fixed createlink() in convert_capec.py to 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

)
for subitem in item["Items"]:
if shortcode in subitem["Shortcode"]:
if shortcode.removeprefix("V") == subitem["Shortcode"].removeprefix("V"):
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@immortal71 immortal71 force-pushed the fix/2548-game-finished-round branch 2 times, most recently from fc3d3dc to 18a9847 Compare March 7, 2026 17:56
@immortal71 immortal71 force-pushed the fix/2548-game-finished-round branch from 18a9847 to 96884a3 Compare March 7, 2026 18:58
@immortal71
Copy link
Contributor Author

@sydseter is this good to go ???

@Suresh-Krishna-P
Copy link
Contributor

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.

@immortal71
Copy link
Contributor Author

@sydseter just here for follow up,..... is this good to go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: handle_info in game_live/show.ex always sets requested_round = rounds_played + 1, breaking finished game summary view

3 participants