Files
vyndr/tests/unit/statAbbrev.test.js
builtbykev 77e8937a56 P2-9: leaderboard stat labels (SB/ER/TB) + FLAG the grade-degradation root cause
DISPLAY FIX (shipped): the league leaderboard rendered raw snake_case
("stolen_bases U0.5", "earned_runs U2.5"). New canonical short-label lib
web/src/lib/statAbbrev.js (one source, CommonJS + unit-tested) maps stat_type
to SB/ER/TB/HR/K/PTS/… and ExploreHub routes through it. Unknown ids upper-case
their words so raw snake_case can never leak again.

FLAG (reported, NOT silently changed — per the audit's instruction): the "B at
45% confidence" is a BACKEND grading issue, diagnosed against live snapshot:
- 25/25 grades mismatch their own confidence vs grade_thresholds.json (B shown
  at conf 55 = the B- band; a systematic one-sub-tier gap on every prop). The
  surfaced `confidence` is not the probability that derived the letter (likely
  the data-sufficiency penalty applied to display-only).
- 9/25 have projection=0 — the MLB feature path feeds 0 instead of refusing
  (S58 insufficient_data), which also produces the P1-7 broken edge_pct.
Full write-up + do-not list: specs/audit-data/mlb-grade-degradation.md. NOT
re-lettering or shifting thresholds on the frontend — that would hide the bug.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-17 01:42:03 -04:00

37 lines
1.3 KiB
JavaScript

'use strict';
// P2-9 — the canonical SHORT stat label. Raw snake_case ("stolen_bases U0.5")
// on the leaderboard was the display bug; lock the abbreviations the audit named.
const { statAbbrev, STAT_ABBREV } = require('../../web/src/lib/statAbbrev');
describe('statAbbrev', () => {
test('the audit-named MLB stats map to short labels', () => {
expect(statAbbrev('stolen_bases')).toBe('SB');
expect(statAbbrev('earned_runs')).toBe('ER');
expect(statAbbrev('total_bases')).toBe('TB');
expect(statAbbrev('home_runs')).toBe('HR');
expect(statAbbrev('strikeouts')).toBe('K');
});
test('NBA stats too', () => {
expect(statAbbrev('points')).toBe('PTS');
expect(statAbbrev('rebounds')).toBe('REB');
expect(statAbbrev('assists')).toBe('AST');
});
test('an unknown id upper-cases its words (never leaks raw snake_case)', () => {
expect(statAbbrev('some_new_stat')).toBe('SOME NEW STAT');
expect(statAbbrev('some_new_stat')).not.toContain('_');
});
test('null / empty is safe', () => {
expect(statAbbrev(null)).toBe('');
expect(statAbbrev('')).toBe('');
});
test('no label contains an underscore (all are real abbreviations)', () => {
for (const v of Object.values(STAT_ABBREV)) expect(v).not.toContain('_');
});
});