Skip to content

test(gamification): pin aggregate level to #11604 XP-derived semantics - #11676

Merged
diegosouzapw merged 1 commit into
diegosouzapw:release/v3.8.51from
jonlwheat2-gif:fix/gamification-aggregate-level-pin
Aug 26, 2026
Merged

diegosouzapw merged 1 commit into
diegosouzapw:release/v3.8.51from
jonlwheat2-gif:fix/gamification-aggregate-level-pin

Conversation

@jonlwheat2-gif

Copy link
Copy Markdown
Contributor

What was broken

tests/unit/gamification/aggregate-profile-3484.test.ts failed on release/v3.8.51 (and PR #11644's CI):

✖ #3484 getAggregateXp sums XP across keys and takes the highest level
  AssertionError: 2 !== 5   (agg.currentLevel)

Root cause

#11604 (fix(dashboard): keep Profile XP and level consistent) deliberately changed getAggregateXp() in src/lib/db/gamification.ts:

- SELECT COALESCE(SUM(total_xp), 0) AS total_xp,
-        COALESCE(MAX(current_level), 1) AS current_level,
+ SELECT COALESCE(SUM(total_xp), 0) AS total_xp,
   MAX(updated_at) AS updated_at
...
- currentLevel: row?.current_level ?? 1,
+ currentLevel: calculateLevel(totalXp),

The aggregate level must be derived from the same summed XP the profile displays. The #3484 test still asserted the old MAX(stored level) semantics — and its fixtures were off-curve anyway (100 XP → level 2 and 250 XP → level 5 are impossible on the XP curve where level 2 requires 282 XP).

Fix

tests/unit/gamification/aggregate-profile-3484.test.ts (lines 50–65):

  • Test renamed: "sums XP across keys and takes the highest level" → "…derives the level from the summed XP".
  • Fixtures aligned to the XP curve: key-a: 100 XP / level 1, key-b: 250 XP / level 1 (both individually level 1; sum 350 crosses the level-2 threshold of 282).
  • Assertion: currentLevel === 2 (calculateLevel(350)), pinning the fix(dashboard): keep Profile XP and level consistent #11604 semantics.

Green evidence (after)

ℹ tests 4
ℹ pass 4
ℹ fail 0

Files: tests/unit/gamification/aggregate-profile-3484.test.ts, changelog.d/fixes/11604-aggregate-profile-level-pin.md.

…ved semantics

diegosouzapw#11604 changed getAggregateXp() to derive currentLevel from the summed XP
(calculateLevel(SUM(total_xp))) instead of MAX(stored current_level), so the
operator-wide profile level is consistent with the XP it displays. The diegosouzapw#3484
test still asserted the old semantics and used fixture levels that don't match
the XP curve (100 XP -> level 2, 250 XP -> level 5 are impossible). Align the
fixtures to the curve (both keys level 1) and assert the derived level (350 XP
-> level 2).
@jonlwheat2-gif

Copy link
Copy Markdown
Contributor Author

Superseded by consolidated PR #11679, which includes this fix alongside the other five failing-test root causes (per the requested PR organization: one PR for docs drifts #11673, one consolidated PR for all failing tests).

@diegosouzapw
diegosouzapw merged commit 146897d into diegosouzapw:release/v3.8.51 Aug 26, 2026
13 of 29 checks passed
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…ved semantics (diegosouzapw#11676)

Merged via /merge-batch (2026-08-26, v3.8.51). Boarded no worktree combinado; validação única: typecheck/complexity/cognitive-complexity/file-size/changelog verdes, lint nos mesmos 228 achados pré-existentes confirmados contra o tip puro, testes focados passando. Obrigado pela contribuição.
@jonlwheat2-gif
jonlwheat2-gif deleted the fix/gamification-aggregate-level-pin branch September 30, 2026 15: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.

2 participants