Skip to content

Fix: a player still on the holding team ("White") shows a false loss - #17

Open
jbob06 wants to merge 1 commit into
warcon-app:mainfrom
jbob06:fix-white-faction-match-result
Open

jbob06 wants to merge 1 commit into
warcon-app:mainfrom
jbob06:fix-white-faction-match-result

Conversation

@jbob06

@jbob06 jbob06 commented Sep 19, 2026

Copy link
Copy Markdown

What's broken

matchResult() only checks whether a player has a faction, not whether that
faction was actually one of the match's competing teams. A player's
player_sessions.faction is overwritten on every poll tick, so it only ever
reflects their most recent observed faction — including the game's own
holding-team value, "White", for a player who hasn't been put on a side yet
(between matches, or mid-pick for the one in progress).

Since "White" is a truthy string, it sails past the !faction check and
gets compared directly against the match winner, which it never equals — so
it always resolves to a loss.

Caught on a live server: a player who won every match that night saw every
one of them recorded as a loss on their career page, because their session
happened to read "White" (mid-pick for the current, in-progress match) at
the moment the career query ran — and that one current value gets joined to
every match the session spans, including ones from earlier the same night
that they actually played and won.

This isn't just a career-page cosmetic bug: src/lib/server/leaderboards.ts
duplicates the same CASE for the board aggregates (explicitly commented as
mirroring matchResult()), so it was silently corrupting the win-rate
leaderboard too, for anyone who has ever had a "White" tick land as their
session's latest value.

Fix

Treat the holding team the same way the public live page already does (see
its "Unassigned" row / isTeam check): never a competitor, so never a winner
or a loss. Added HOLDING_TEAM in src/lib/leaderboard.ts and mirrored the
same exclusion into the SQL CASE in leaderboards.ts, plus a test case
reproducing the exact scenario.

Testing

bun test src/lib/leaderboard.test.ts — 15 pass, including the new case.
Full suite: 392 pass, 213 skip (DB-dependent), 16 fail — all 16 are
pre-existing Windows path-separator mismatches in page-loads.test.ts /
api-matrix.test.ts / load-matrix.test.ts, unrelated to this change and
present before it on a clean checkout.


🤖 Generated with Claude Code

…eir career page

matchResult() only checked for a missing faction, so a session's most recent poll
landing on the game's own pre-pick value sailed through as a real competitor and
lost against whatever team actually won. Caught on a live server: a player who won
every match that night had every one of them recorded as a loss under faction
"White", because their session was mid-pick for the current match when the career
page's query ran. The same CASE is duplicated in leaderboards.ts for the board
aggregates, so this was silently wrong there too, not just on the career page.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J3PtgLmN9qBFjAk1LwsnfM
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.

1 participant