fix(race): make challenge-link races unrated (no Elo) - #304
Merged
Conversation
finishRace now reads rated = race.challengeToken === null off the atomic claim's RETURNING row and gates the Elo block on it. Challenge races still finish and publish race_finished normally, but skip the user load, applyResult, and the entire db.batch (Elo updates, racesPlayed increments, elo_history inserts, eloDeltaP1/P2 write) -- deltas stay NULL in the DB. Matchmade races are unaffected since they always have challengeToken null. Closes #302 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #302
What changed
src/lib/race/finish.tsonly:const rated = race.challengeToken === null;read off the atomic claim'sRETURNINGrow (right after the claim, before the Elo block).if (p2Id)→if (rated && p2Id). Challenge-link races (challengeToken !== null) still finish (claim update runs, outcome/winner recorded,race_finishedpublished), but skip the user load,applyResult, and the entiredb.batch— no user Elo/racesPlayedupdates, noelo_historyinserts, noeloDeltaP1/eloDeltaP2write. Deltas stay NULL in the DB;d1/d2stay0, so the publish carrieseloDeltas: {p1: 0, p2: 0}(fine — clients treat the event as a refetch hint and read real, possibly-NULL, deltas from the snapshot; already null-safe per the issue).FinishRaceInput.outcomedoc to state Elo only applies to rated races.readyWalkoverclaim requires non-nullreadyDeadlineAt(always matchmade ⇒ always rated, since matchmade races always havechallengeToken === null), so it's unaffected — added a contrast test proving this.How verified
pnpm exec eslint .— clean.pnpm exec tsc --noEmit— clean.pnpm exec vitest run— 997/997 tests passed across 85 files (full suite, not just this file).tests/race-finish.test.ts: all pre-existing fixtures (makeRace()defaultschallengeToken: null) pass unchanged (still rated). Addeddescribe("finishRace — unrated challenge races (issue #302)")with:challengeToken: "abc123"+p1_win⇒ finished (claim ran, outcome/winner set), zerodb.batchcalls, zero inserts, zero user selects, publish called exactly once witheloDeltas: {"user-p1": 0, "user-p2": 0}.draw.challengeToken: null+readyDeadlineAtnon-null (matchmade shape) still applies full Elo (batch of 4, 1 insert, 1 select) — pins that the discriminator is the token, not the deadline.Notes for reviewers
racesPlayedis deliberately not incremented for unrated races (it drives provisional K-factor insrc/lib/elo.tsand leaderboard inclusion insrc/lib/leaderboard.ts) — this falls out naturally from skipping the whole batch, no separate logic needed.ResultCard.tsx:295,RaceEndOverlay.tsx:119) are already null-safe for missing deltas.Deviations
None from the issue spec.