Repository navigation
fix(gamification): use canonical getRank for rank badge criterion - #15742
Merged
diegosouzapw merged 1 commit intoOct 8, 2026
Merged
diegosouzapw merged 1 commit into
diegosouzapw merged 1 commit into
Conversation
badges.ts carried its own copy of the leaderboard rank query, duplicating db/gamification getRank() but returning Infinity for unranked keys instead of 0. Drop the local copy and call the canonical function, treating 0 as unranked so `0 <= threshold` cannot award rank badges to keys that never scored. Adds tests/unit/gamification/badge-rank-criteria.test.ts covering both the unranked and ranked-within-threshold cases.
Contributor
Author
|
Hi @diegosouzapw — this is my first PR from a fork, so the CI, Quality Gates, semgrep and API Route Typecheck workflows are waiting on maintainer approval ( |
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.
Summary
src/lib/gamification/badges.tscarried a private copy of the leaderboard rank query that duplicatedgetRank()insrc/lib/db/gamification.ts, with one behavioral difference: the local copy returnedInfinityfor a key with no leaderboard entry, while the canonical function returns0.This PR drops the local copy and has the
rankbadge criterion call the canonicalgetRank(). Because the canonical function reports "unranked" as0, the criterion now checksrank > 0 && rank <= threshold— a straight swap would have let0 <= thresholdaward rank badges (e.g.community-leader) to every key that never scored.Tests
New:
tests/unit/gamification/badge-rank-criteria.test.tsgetRank() === 0andcommunity-leaderis not unlockedcommunity-leaderis unlockedValidation (Hard Rule #18):
node --import tsx/esm --test tests/unit/gamification/badge-rank-criteria.test.ts→ 2/2 passrank > 0 &&guard makes the unranked test fail (1 fail / 1 pass); guard restorednode --import tsx/esm --test tests/unit/gamification/*.test.ts→ 120/120 pass (18 files, incl.leaderboard.test.ts,badges.test.ts)