fix: remove sentinel-player dependency in teams-left#54
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the hardcoded dependency on a sentinel player = 24 for computing “teams left” leaderboard metrics, making the calculation resilient when that player row/picks are missing.
Changes:
- Reworked
count_player_teams_leftandcount_player_final4_teams_leftto derivegames_remainingfromgamerows not present in “played games” (player 1 picks), rather than from a sentinel player’s picks. - Added safer
max_lefthandling when there are no non-admin players in the computed result set. - Updated/extended regression tests to ensure sentinel-free behavior for both teams-left methods.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
lib/Bracket/Model/DBIC.pm |
Removes sentinel-player CTE dependency and adds empty-set-safe max_left computation for both teams-left queries. |
t/model_round_based_final4_counts.t |
Updates fixture to omit player 24 and adds assertions covering sentinel-free behavior. |
| my @players = grep { $_ != 1 } keys %{$teams_left_per_player}; | ||
| my $max_left = @players | ||
| ? max(map { $teams_left_per_player->{$_} } @players) | ||
| : 0; |
There was a problem hiding this comment.
The new empty-non-admin-player branch for $max_left (returning 0 when there are no players other than player 1 in the result map) isn’t covered by tests. Add a regression case where only the admin/perfect player exists (or where no non-admin players have remaining teams) and assert $max_left is 0, to prevent reintroducing the previous max-on-empty behavior.
| my @players = grep { $_ != 1 } keys %{$final4_teams_left_per_player}; | ||
| my $max_left = @players | ||
| ? max(map { $final4_teams_left_per_player->{$_} } @players) | ||
| : 0; |
There was a problem hiding this comment.
Similar to count_player_teams_left: the new $max_left fallback to 0 when there are no non-admin players in the computed map is not exercised by the current test. Add a regression test for count_player_final4_teams_left where no non-admin players are present (or none have remaining final4 teams) and assert $max_left is 0.
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/mateu/Bracket/sessions/b848ae71-fd76-4442-9e98-becdbdd83e5d Co-authored-by: mateu <31550+mateu@users.noreply.github.com>
Done in adeaa51. Added two regression tests right after the UDFs are registered and before any non-admin player picks are created — at that point the result map is empty, |
What
Remove hardcoded
player = 24dependency from teams-left leaderboard metrics.Why
count_player_teams_leftandcount_player_final4_teams_leftinferred remaining games from one sentinel player's picks, which silently breaks when that player row is missing or incomplete.How
gamerows not present in played games (player = 1) instead of a sentinel player's picks.max_lefthandling for empty non-admin player sets.Testing
script/test-env.sh prove -lv t/model_round_based_final4_counts.tscript/test-env.sh prove -lr tQuality Report
Changes: 2 files changed, 30 insertions(+), 25 deletions(-)
Code scan: clean
Tests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline