Files
vyndr/tests/unit/playerIntelWiring.test.js
T
builtbykev 7ac6aa73e3 Layer 2: multi-axis archetype classifier; the FLEX fallback is gone
A player is a blend across independent axes, not one label. Skubal is a STARTER
and a strikeout arm and a ground-ball arm and a control arm — four true things
at once, and single-label classification threw three of them away.

AXIS INDEPENDENCE WAS MEASURED, NOT ASSUMED. Correlations over the live store
(467 batters, 531 pitchers); anything |r| >= 0.70 is one underlying trait and
was collapsed so we never show one trait as two archetypes. Batter k% ~ whiff%
+0.89, hard-hit% ~ exit velo +0.88, chase% ~ swing% +0.87, chase% ~ bb% -0.72;
pitcher k% ~ whiff% +0.76, gb% ~ fb% -0.73 — all collapsed.

The survivors are genuinely orthogonal, and one result is worth stating: pitcher
velocity correlates +0.14 with K%, +0.07 with whiff% and +0.07 with GB%.
Velocity is NOT a proxy for missing bats — a hard thrower who misses no bats is
a real distinct type, so CANNON earns its own axis rather than being folded into
STRIKEOUT. Pitcher K% ~ GB% is -0.10, so PUNCHOUT and SINKER are independent,
which is exactly the multi-axis thesis.

Cut-lines are the measured p75 (distinctive) and p90 (elite), per role where the
tails differ even when the medians agree: reliever GB% p90 is 54.1 against a
starter's 48.9, both with a median of 42.5.

THE FALLBACK IS DELETED. classify() used to return FLEX (mlb) / SHIELD (wnba) /
CONNECTOR (nba) at weight 1.0 when nothing scored — "could not classify"
rendered as a fully-confident classification of a real archetype, with
descriptive education copy attached. 8 of 18 MLB players carried it, and FLEX
could never be earned because its only scoring input had zero writers. Every
sport now does what MMA already did: unclassified is absent.

Induced on real players. Skubal: STARTER, throws L, WHIFF + SEAM + PINPOINT, all
elite. Judge: BOMBER + GRINDER + WHIFF RISK — elite power, patient, strikes out,
three true things. Kwan: SURGEON + SNIPER + SLASH with NO power claimed (0.4
barrel% is absent, not "low power"). Josh Bell, who used to classify as DRIVER:
empty blend, "No standout profile — league-average across every measured axis."
Alan Roden, who was FLEX at weight 1.0 on 21 PA: every axis absent, "Not enough
plate appearances yet — no profile claimed."

Per-axis honest-absence holds: a velo-less pitcher keeps every other axis, and
NO DATA is distinguishable from LEAGUE-AVERAGE rather than collapsing into one
shrug. The full vector is stored for Layer 3; only the top three distinctive
traits surface.

Three existing tests asserted the fallback and were updated to assert absence.
One of them surfaced a real robustness gap: classify(sport, null) threw, because
an explicit null does not trigger a default parameter and every scorer
dereferences its argument. Guarded.

Every baseball name is accounted for in docs/ARCHETYPE-AXES.md — built, alias,
tier, or shelved with its unlock condition. Zero orphans; cross-sport names left
for their sport.

Tests 3601 passed / 293 suites.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VCNgGSt5qvcLxaeQqa7Zpj
2026-07-20 22:38:32 -04:00

91 lines
4.1 KiB
JavaScript

// 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(['BOMBER', 'BOMBER', 'DRIVER']).toContain(r.archetype.primary.name);
expect(r.archetype.primary.name).not.toBe('FLEX');
});
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('ALPHA');
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);
// Session 69 — no fallback archetype: unclassified is ABSENT, not a bucket.
expect(r.archetype.primary).toBeNull();
expect(r.season).toEqual([]);
});
});