Skip to content

fix: remove sentinel-player dependency in teams-left#54

Merged
mateu merged 2 commits into
masterfrom
koan/fix-teams-left-without-player24
Apr 6, 2026
Merged

fix: remove sentinel-player dependency in teams-left#54
mateu merged 2 commits into
masterfrom
koan/fix-teams-left-without-player24

Conversation

@mateu
Copy link
Copy Markdown
Owner

@mateu mateu commented Apr 6, 2026

What

Remove hardcoded player = 24 dependency from teams-left leaderboard metrics.

Why

count_player_teams_left and count_player_final4_teams_left inferred remaining games from one sentinel player's picks, which silently breaks when that player row is missing or incomplete.

How

  • Reworked both SQL CTEs to derive remaining games from game rows not present in played games (player = 1) instead of a sentinel player's picks.
  • Kept existing loss-elimination logic intact.
  • Added safe max_left handling for empty non-admin player sets.
  • Updated regression coverage to assert sentinel-free behavior and added explicit checks for both teams-left methods.

Testing

  • script/test-env.sh prove -lv t/model_round_based_final4_counts.t
  • script/test-env.sh prove -lr t

Quality 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

@mateu mateu marked this pull request as ready for review April 6, 2026 21:56
@mateu mateu requested a review from Copilot April 6, 2026 21:56
Copy link
Copy Markdown
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 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_left and count_player_final4_teams_left to derive games_remaining from game rows not present in “played games” (player 1 picks), rather than from a sentinel player’s picks.
  • Added safer max_left handling 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.

Comment thread lib/Bracket/Model/DBIC.pm
Comment on lines +531 to +534
my @players = grep { $_ != 1 } keys %{$teams_left_per_player};
my $max_left = @players
? max(map { $teams_left_per_player->{$_} } @players)
: 0;
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread lib/Bracket/Model/DBIC.pm
Comment on lines +598 to +601
my @players = grep { $_ != 1 } keys %{$final4_teams_left_per_player};
my $max_left = @players
? max(map { $final4_teams_left_per_player->{$_} } @players)
: 0;
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

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 uses AI. Check for mistakes.
@mateu
Copy link
Copy Markdown
Owner Author

mateu commented Apr 6, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

@copilot apply changes based on the comments in this thread

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, @players is an empty list, and both count_player_teams_left and count_player_final4_teams_left must return $max_left = 0, directly exercising the new fallback branch in each function.

Copilot finished work on behalf of mateu April 6, 2026 22:35
@mateu mateu merged commit a3124cd into master Apr 6, 2026
1 check passed
@mateu mateu deleted the koan/fix-teams-left-without-player24 branch April 6, 2026 22:38
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.

3 participants