Session 43: Data pipeline + audit fixes + depth chart foundation (2045 tests)
P0 fixes + wiring real data into the S42 Player Intelligence architecture. - P0 dropdown z-index: the nav's backdrop-filter stacking context let the Ticker/HeartbeatBar paint over the avatar/More dropdowns and eat clicks. nav now position:relative zIndex:2; menus zIndex:100. Avatar Settings -> /settings. - Real MLB stats: mlbStatsAdapter.searchPlayer + getPlayerStats (name->id-> season+gamelog). playerIntelService.resolvePlayerStats normalizes into the archetype classifier; getPlayerIntel returns found:true + real season + archetype classified from real stats. NBA via nbaStatsClient (degrades). - Game cards: slateAdapter.groupPropsByPlayer (playerStrips, name once) + mapPitchers (MLB probables), folded into mapScheduleToGameCards. Legacy GameCard line grid renders BookChip (brand colors) not grey text. - Grade card intel: analyzeViaEngine1.buildIntelFields computes stat-context + form/usage/matchup/rest from the existing feature vector (zero extra I/O); gradeAdapter lights up the card sections. Archetype deferred (needs season line at grade time). - Depth chart foundation: depthChartService (getLineup/getDepthChart/ getCascadeProjection) + /api/stats/lineup|depth|cascade, graceful + injectable. - Mobile: player hero name overflow-wrap + 24px on <=640px (was clipping). Backend 2011 -> 2045 tests (+34), 163 suites. Web build clean (exit 0). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
// Session 43 — depth chart / lineup / cascade foundation. Sources injected.
|
||||
|
||||
const svc = require('../../src/services/depthChartService');
|
||||
|
||||
describe('getLineup (MLB, injected schedule)', () => {
|
||||
const mlbAdapter = {
|
||||
async getScheduleWithPitchers() {
|
||||
return [{
|
||||
home: { team: 'Atlanta Braves', probablePitcher: { name: 'Spencer Strider' } },
|
||||
away: { team: 'Philadelphia Phillies', probablePitcher: { name: 'Zack Wheeler' } },
|
||||
}];
|
||||
},
|
||||
};
|
||||
|
||||
it('returns the probable starting pitcher for the team', async () => {
|
||||
const r = await svc.getLineup('mlb', 'Atlanta', { mlbAdapter, date: '2026-06-18' });
|
||||
expect(r).toHaveLength(1);
|
||||
expect(r[0]).toMatchObject({ player: 'Spencer Strider', position: 'SP' });
|
||||
});
|
||||
|
||||
it('returns [] when the team is not playing / unknown', async () => {
|
||||
expect(await svc.getLineup('mlb', 'Seattle', { mlbAdapter, date: '2026-06-18' })).toEqual([]);
|
||||
expect(await svc.getLineup('mlb', '', { mlbAdapter })).toEqual([]);
|
||||
});
|
||||
|
||||
it('degrades to [] when the adapter throws', async () => {
|
||||
const bad = { async getScheduleWithPitchers() { throw new Error('down'); } };
|
||||
expect(await svc.getLineup('mlb', 'Atlanta', { mlbAdapter: bad })).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDepthChart', () => {
|
||||
it('builds positions with starter/backup/third from an injected roster', async () => {
|
||||
const chart = await svc.getDepthChart('nba', 'SA', {
|
||||
roster: [
|
||||
{ player: 'Wembanyama', position: 'C', depth: 1 },
|
||||
{ player: 'Backup Big', position: 'C', depth: 2 },
|
||||
{ player: 'Vassell', position: 'SG', depth: 1 },
|
||||
],
|
||||
});
|
||||
const center = chart.positions.find((p) => p.position === 'C');
|
||||
expect(center.starter).toBe('Wembanyama');
|
||||
expect(center.backup).toBe('Backup Big');
|
||||
});
|
||||
|
||||
it('returns a valid empty structure when no roster source', async () => {
|
||||
const chart = await svc.getDepthChart('mlb', 'ATL');
|
||||
expect(chart).toEqual({ sport: 'mlb', team: 'ATL', positions: [] });
|
||||
});
|
||||
});
|
||||
|
||||
describe('getCascadeProjection', () => {
|
||||
it('distributes usage to teammates, weighting usage sponges heaviest', async () => {
|
||||
const r = await svc.getCascadeProjection('nba', 'Keldon Murray', 'SA', {
|
||||
teammates: [
|
||||
{ player: 'Wembanyama', archetype: 'VOLUME SCORER' },
|
||||
{ player: 'Bench Spark', archetype: 'USAGE SPONGE' },
|
||||
{ player: 'Glue Guy', archetype: 'ROLE GLUE' },
|
||||
],
|
||||
});
|
||||
expect(r).toHaveLength(3);
|
||||
// usage sponge gets the biggest bump
|
||||
expect(r[0].player).toBe('Bench Spark');
|
||||
expect(r[0].delta.startsWith('+')).toBe(true);
|
||||
expect(r[0].reason).toContain('OUT');
|
||||
});
|
||||
|
||||
it('returns [] with no teammates / no player', async () => {
|
||||
expect(await svc.getCascadeProjection('nba', 'X', 'SA', { teammates: [] })).toEqual([]);
|
||||
expect(await svc.getCascadeProjection('nba', '', 'SA')).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
// Session 43 — engine attaches grade-card intelligence fields (stat context +
|
||||
// VYNDR intelligence) from the feature vector, and gradeAdapter maps them.
|
||||
|
||||
const { __internals } = require('../../src/services/intelligence/analyzeViaEngine1');
|
||||
const { buildIntelFields, computeFormScore, matchupGradeFromRank } = __internals;
|
||||
const { mapScanToGradeResult } = require('../../web/src/lib/gradeAdapter');
|
||||
|
||||
describe('computeFormScore', () => {
|
||||
it('trends above 70 when recent > baseline (hot)', () => {
|
||||
expect(computeFormScore({ l5_avg: 30, l20_avg: 24 })).toBeGreaterThan(70);
|
||||
});
|
||||
it('trends below 70 when recent < baseline (cold)', () => {
|
||||
expect(computeFormScore({ l5_avg: 18, l20_avg: 26 })).toBeLessThan(70);
|
||||
});
|
||||
it('undefined when there is no recent average', () => {
|
||||
expect(computeFormScore({})).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('matchupGradeFromRank', () => {
|
||||
it('maps normalized opponent rank to a letter grade', () => {
|
||||
expect(matchupGradeFromRank(0.9)).toBe('A');
|
||||
expect(matchupGradeFromRank(0.55)).toBe('B+');
|
||||
expect(matchupGradeFromRank(0.1)).toBe('C');
|
||||
expect(matchupGradeFromRank(undefined)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildIntelFields', () => {
|
||||
it('builds stat context + form/usage/matchup/rest from features', () => {
|
||||
const f = buildIntelFields({ l20_avg: 26.9, l10_avg: 28.4, l5_avg: 30.1, usage_rate: 31.2, opp_rank_stat: 0.7, rest_days: 2 });
|
||||
expect(f.season_avg).toBe(26.9);
|
||||
expect(f.last10_avg).toBe(28.4);
|
||||
expect(f.form).toBeGreaterThan(70);
|
||||
expect(f.usage).toBe('31.2%');
|
||||
expect(f.matchup_grade).toBe('A');
|
||||
expect(f.rest).toBe('2d rest');
|
||||
});
|
||||
|
||||
it('omits fields with no data (so the card sections self-hide)', () => {
|
||||
expect(buildIntelFields({})).toEqual({});
|
||||
});
|
||||
|
||||
it('feeds straight into the grade card via gradeAdapter', () => {
|
||||
const engineLike = { player: 'Wemby', stat: 'points', line: 26.5, grade: 'A', ...buildIntelFields({ l20_avg: 26.9, l10_avg: 28.4, l5_avg: 30, usage_rate: 31.2, opp_rank_stat: 0.7 }) };
|
||||
const card = mapScanToGradeResult(engineLike);
|
||||
expect(card.statContext).toMatchObject({ season: '26.9', last10: '28.4' });
|
||||
expect(card.vyndrIntel.matchup).toBe('A');
|
||||
expect(card.vyndrIntel.usage).toBe('31.2%');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
// Session 43 — P0: avatar/More dropdowns must be clickable above the living-layer
|
||||
// bars (Ticker + HeartbeatBar). Asserted in source: the nav floats above them
|
||||
// and the menus carry an explicit z-index.
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const WEB = path.join(__dirname, '..', '..', 'web', 'src');
|
||||
const nav = fs.readFileSync(path.join(WEB, 'components', 'Nav.tsx'), 'utf8');
|
||||
|
||||
describe('Nav dropdown z-index (P0 fix)', () => {
|
||||
it('the nav element floats above the ticker/heartbeat (position+zIndex on the stacking-context nav)', () => {
|
||||
// The nav block carries backdrop-filter; it must also set position+zIndex.
|
||||
const navBlock = nav.slice(nav.indexOf('<nav'), nav.indexOf('backdropFilter') + 200);
|
||||
expect(navBlock).toMatch(/position: 'relative'/);
|
||||
expect(navBlock).toMatch(/zIndex: 2/);
|
||||
});
|
||||
|
||||
it('the dropdown menus declare a high z-index', () => {
|
||||
const menuZ = (nav.match(/zIndex: 100/g) || []).length;
|
||||
expect(menuZ).toBeGreaterThanOrEqual(2); // More + avatar menus
|
||||
});
|
||||
});
|
||||
|
||||
describe('Nav links (Session 42/43)', () => {
|
||||
it('MORE includes Explore and Settings -> /settings', () => {
|
||||
expect(nav).toContain("label: 'Explore', href: '/explore'");
|
||||
expect(nav).toContain("label: 'Settings', href: '/settings'");
|
||||
});
|
||||
it('avatar dropdown Settings links to /settings (not /settings/security)', () => {
|
||||
expect(nav).toContain('href="/settings" role="menuitem"');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
// Session 43 — real-stats wiring into playerIntelService. Adapters are injected
|
||||
// so these run pure (no statsapi.mlb.com, no Python NBA service).
|
||||
|
||||
const svc = require('../../src/services/playerIntelService');
|
||||
|
||||
// A fake mlbStatsAdapter.getPlayerStats returning a power-pull hitter line.
|
||||
const judgeAdapter = {
|
||||
async getPlayerStats() {
|
||||
return {
|
||||
found: true, id: 592450, name: 'Aaron Judge', team: 'New York Yankees', position: 'RF', group: 'hitting',
|
||||
season: { avg: '.288', homeRuns: 34, rbi: 87, ops: '1.012', gamesPlayed: 92, stolenBases: 9, runs: 80, doubles: 18, strikeOuts: 120, plateAppearances: 400, atBats: 330 },
|
||||
last10: [
|
||||
{ date: '2026-06-15', opponent: 'Boston Red Sox', stat: { hits: 2, atBats: 4, homeRuns: 1 } },
|
||||
{ date: '2026-06-16', opponent: 'Tampa Bay Rays', stat: { hits: 1, atBats: 3, homeRuns: 0 } },
|
||||
],
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
const aceAdapter = {
|
||||
async getPlayerStats() {
|
||||
return {
|
||||
found: true, id: 1, name: 'Tarik Skubal', team: 'Detroit Tigers', position: 'P', group: 'pitching',
|
||||
season: { era: '2.41', strikeOuts: 130, inningsPitched: '110.0', whip: '0.92', gamesStarted: 17, strikeoutsPer9Inn: '10.6', saves: 0 },
|
||||
last10: [{ date: '2026-06-14', opponent: 'Chicago White Sox', stat: { inningsPitched: '7.0', strikeOuts: 9 } }],
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
describe('resolvePlayerStats (MLB, injected adapter)', () => {
|
||||
it('normalizes a hitter into classifier input + display rows + last10', async () => {
|
||||
const r = await svc.resolvePlayerStats('Aaron Judge', 'mlb', { mlbAdapter: judgeAdapter });
|
||||
expect(r.found).toBe(true);
|
||||
expect(r.team).toBe('New York Yankees');
|
||||
expect(r.classifierInput.hr).toBe(34);
|
||||
expect(r.classifierInput.k_rate).toBeGreaterThan(0);
|
||||
expect(r.season.find((s) => s.k === 'HR').v).toBe('34');
|
||||
expect(r.season.find((s) => s.k === 'AVG').v).toBe('.288');
|
||||
expect(r.last10.length).toBe(2);
|
||||
expect(r.last10[0].stat).toContain('HR'); // most-recent-first summary
|
||||
});
|
||||
|
||||
it('normalizes a pitcher (group=pitching) into ERA/K9/role', async () => {
|
||||
const r = await svc.resolvePlayerStats('Tarik Skubal', 'mlb', { mlbAdapter: aceAdapter });
|
||||
expect(r.classifierInput.era).toBeCloseTo(2.41, 2);
|
||||
expect(r.classifierInput.k9).toBeCloseTo(10.6, 1);
|
||||
expect(r.classifierInput.role).toBe('SP');
|
||||
expect(r.season.find((s) => s.k === 'ERA').v).toBe('2.41');
|
||||
});
|
||||
|
||||
it('returns found:false when the adapter has no data', async () => {
|
||||
const r = await svc.resolvePlayerStats('Nobody', 'mlb', { mlbAdapter: { async getPlayerStats() { return { found: false }; } } });
|
||||
expect(r.found).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPlayerIntel with real stats (Session 43)', () => {
|
||||
it('returns found:true + real season + an archetype classified from real stats', async () => {
|
||||
const r = await svc.getPlayerIntel('Aaron Judge', 'mlb', {
|
||||
cacheGet: async () => null,
|
||||
resolveStats: (name, sport) => svc.resolvePlayerStats(name, sport, { mlbAdapter: judgeAdapter }),
|
||||
});
|
||||
expect(r.found).toBe(true);
|
||||
expect(r.team).toBe('New York Yankees');
|
||||
expect(r.season.length).toBeGreaterThan(0);
|
||||
// 34 HR + high K-rate → POWER PULL, not the empty-stats fallback.
|
||||
expect(['POWER PULL', 'POWER SLUGGER', 'RUN PRODUCER']).toContain(r.archetype.primary.name);
|
||||
expect(r.archetype.primary.name).not.toBe('UTILITY PLAYER');
|
||||
});
|
||||
|
||||
it('classifies an ace pitcher from real stats', async () => {
|
||||
const r = await svc.getPlayerIntel('Tarik Skubal', 'mlb', {
|
||||
cacheGet: async () => null,
|
||||
resolveStats: (name, sport) => svc.resolvePlayerStats(name, sport, { mlbAdapter: aceAdapter }),
|
||||
});
|
||||
expect(r.archetype.primary.name).toBe('ACE');
|
||||
expect(r.found).toBe(true);
|
||||
});
|
||||
|
||||
it('still degrades gracefully when no stats and no props (found:false)', async () => {
|
||||
const r = await svc.getPlayerIntel('Ghost Player', 'mlb', {
|
||||
cacheGet: async () => null,
|
||||
resolveStats: async () => ({ found: false }),
|
||||
});
|
||||
expect(r.found).toBe(false);
|
||||
expect(r.archetype.primary).toBeTruthy(); // fallback archetype still present
|
||||
expect(r.season).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
// Session 43 — Phase 6 mobile + cosmetics.
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const WEB = path.join(__dirname, '..', '..', 'web', 'src');
|
||||
const read = (rel) => fs.readFileSync(path.join(WEB, rel), 'utf8');
|
||||
|
||||
describe('Player profile hero name (mobile truncation fix)', () => {
|
||||
const page = read('app/player/[name]/page.tsx');
|
||||
const css = read('app/globals.css');
|
||||
it('hero name uses overflow-safe wrapping (no clipping)', () => {
|
||||
expect(page).toContain('player-hero-name');
|
||||
expect(page).toContain("overflowWrap: 'anywhere'");
|
||||
});
|
||||
it('mobile CSS shrinks + wraps the hero name', () => {
|
||||
expect(css).toMatch(/\.player-hero-name\s*\{[^}]*font-size: 24px/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('No runtime font CDN (Session 41 fix still holds)', () => {
|
||||
it('layout has no fonts.googleapis.com stylesheet link', () => {
|
||||
const layout = read('app/layout.tsx');
|
||||
expect(layout).not.toMatch(/href=["'][^"']*fonts\.googleapis\.com/);
|
||||
expect(layout).toContain("from 'next/font/google'");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
// Session 43 — slate adapter: player-grouped strips + MLB pitchers + BookChip.
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const WEB = path.join(__dirname, '..', '..', 'web', 'src');
|
||||
const adapter = require('../../web/src/lib/slateAdapter');
|
||||
|
||||
describe('groupPropsByPlayer', () => {
|
||||
it('groups props so each player appears once (name not repeated)', () => {
|
||||
const out = adapter.groupPropsByPlayer([
|
||||
{ player: 'Austin Riley', team: 'ATL', stat: 'Hits', line: 1.5, side: 'Over', grade: 'A' },
|
||||
{ player: 'Austin Riley', team: 'ATL', stat: 'Total Bases', line: 1.5, side: 'Over', grade: 'B+' },
|
||||
{ player: 'Bryce Harper', team: 'PHI', stat: 'TB', line: 1.5, side: 'Over', grade: 'A' },
|
||||
]);
|
||||
expect(out).toHaveLength(2);
|
||||
expect(out[0].player).toBe('Austin Riley');
|
||||
expect(out[0].props).toHaveLength(2);
|
||||
expect(out[0].props[0].side).toBe('O');
|
||||
expect(out[1].player).toBe('Bryce Harper');
|
||||
});
|
||||
|
||||
it('attaches an archetype when a lookup is provided', () => {
|
||||
const out = adapter.groupPropsByPlayer(
|
||||
[{ player: 'Riley', stat: 'Hits', line: 1.5, side: 'Over', grade: 'A' }],
|
||||
() => ({ primary: 'POWER PULL' }),
|
||||
);
|
||||
expect(out[0].archetype).toEqual({ primary: 'POWER PULL' });
|
||||
});
|
||||
|
||||
it('returns [] for empty / non-array input', () => {
|
||||
expect(adapter.groupPropsByPlayer(null)).toEqual([]);
|
||||
expect(adapter.groupPropsByPlayer([])).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mapPitchers', () => {
|
||||
it('maps MLB probable pitchers to the GameCard shape', () => {
|
||||
const p = adapter.mapPitchers({
|
||||
sport: 'mlb',
|
||||
away: { probablePitcher: { name: 'Spencer Strider' } },
|
||||
home: { probablePitcher: { name: 'Zack Wheeler' } },
|
||||
awayPitcherERA: 3.21, homePitcherERA: 2.89,
|
||||
});
|
||||
expect(p.away.name).toBe('Spencer Strider');
|
||||
expect(p.away.era).toBe('3.21');
|
||||
expect(p.home.name).toBe('Zack Wheeler');
|
||||
});
|
||||
it('returns undefined for non-MLB or no probables', () => {
|
||||
expect(adapter.mapPitchers({ sport: 'nba' })).toBeUndefined();
|
||||
expect(adapter.mapPitchers({ sport: 'mlb' })).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('mapScheduleToGameCards includes the new fields', () => {
|
||||
it('builds playerStrips + pitchers on each card', () => {
|
||||
const cards = adapter.mapScheduleToGameCards(
|
||||
[{ id: 'ATL-PHI', sport: 'mlb', awayTeam: { abbreviation: 'ATL', name: 'Braves' }, homeTeam: { abbreviation: 'PHI', name: 'Phillies' }, away: { probablePitcher: { name: 'Strider' } }, home: { probablePitcher: { name: 'Wheeler' } } }],
|
||||
{},
|
||||
[],
|
||||
[{ player: 'Austin Riley', team: 'ATL', stat: 'Hits', line: 1.5, grade: 'A', side: 'Over' }],
|
||||
);
|
||||
expect(cards[0].playerStrips[0].player).toBe('Austin Riley');
|
||||
expect(cards[0].pitchers.away.name).toBe('Strider');
|
||||
});
|
||||
});
|
||||
|
||||
describe('legacy GameCard uses BookChip (brand colors)', () => {
|
||||
it('renders book chips instead of plain grey text', () => {
|
||||
const src = fs.readFileSync(path.join(WEB, 'components', 'GameCard.tsx'), 'utf8');
|
||||
expect(src).toContain('BookChip');
|
||||
expect(src).toContain('book={r.book}');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user