Files
vyndr/tests/unit/valueEngine.test.js
builtbykev 3591c7626e Total grade cutover + the ceiling stated as a position
PHASE 0 caught my own repeat of the failure I diagnosed one order ago.
91927a4 attached `served_grade` BESIDE the old letter and left `grade`
alone -- so the honest grade reached nobody, exactly as gradeBands had
been built-correct-and-unread. grep showed served_grade appearing in one
file (where I set it) and all 14+ consumers -- scan route, dashboard,
parlay, newsletter, desk, content templates, retention -- still reading
`.grade`, i.e. still the dishonest letter.

CUTOVER IS NOW TOTAL: legacy.grade IS the honest letter. Overwriting the
one field every consumer already reads cuts every surface over at once
instead of editing fourteen call sites and missing one. engine1's index is
preserved as `engine_grade` and verified read by ZERO serving code.

Confidence follows the letter: it came from a grade-band midpoint of the
OLD letter, so leaving it would have paired a served B+ with a C's
confidence. Both now derive from p_win, kept on the existing 0-100 scale.

MEASURED BLAST RADIUS before shipping: 303 of 47,991 non-refused
snapshots (0.6%) have a grade but no p_win, and now render NO READ instead
of a letter. That is correct -- their old letter came from the retired
index carrying 0.48% resolution, i.e. noise -- and NO READ is a rendered
state with a reason, so never-blank holds.

PHASE 1 — the ceiling is now a STATED POSITION, not a confusing absence.
servedGrade.SCALE_LEGEND plus web GradeScaleLegend.tsx say it plainly: we
do not issue A grades, no band has hit at a rate that would justify one,
our honest ceiling is a strong B+ (~66% realized vs ~60% baseline), and if
the model earns an A the legend changes and we say why. The
separates_from_base_rate flag renders per band -- C+/C/C- are labelled
"we cannot separate this from the baseline", which is most of any slate.

PHASE 3 hand-verified across every state: B+ with 3 factors (basis
forecast_plus_matchup_factors), B+ with none (forecast_only), C flagged
not-separable, F, and three refusal states rendering NO READ with reasons.
never-blank PASS, no-manufactured-A PASS.

Test fallout was real and is documented rather than papered over: engine
BEHAVIOUR assertions moved to engine_grade, suppression assertions stayed
on grade (a suppressed prop has no letter either way), and the confidence
78 -> 95 change is the grade-band midpoint being replaced by p_win.

No A-threshold loosening. No calibrated number leaks (deployed set empty).
p_win never mutated. Ten frozen modules verified unchanged including
engine1 and probabilityEstimator. No Bonferroni slot.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W1sivYNqY2TS5ftykmHBU9
2026-08-07 14:07:02 -04:00

94 lines
4.3 KiB
JavaScript

/**
* NOTE ON `engine_grade` (2026-08-07 grade cutover).
*
* The user-facing `grade` now derives from `p_win`, not engine1's additive
* factor index -- that index carried 0.16x the information of p_win on 3,417
* settled props and its A hit worse than its F. The engine's OWN decision
* (graded vs suppressed) is preserved as `engine_grade`, so behaviour
* assertions read that; suppression assertions still read `grade`, since a
* suppressed prop has no letter either way.
*/
'use strict';
// Model Train — value engine: takeable gate, value flag, and the end-to-end
// wiring in analyzeViaEngine1 (de-vig + EV + triplet + flags).
const ve = require('../../src/config/valueEngine');
describe('valueEngine config (steps 3-4)', () => {
test('takeable band is -160..+200 by default', () => {
expect(ve.isTakeable(-110)).toBe(true);
expect(ve.isTakeable(-160)).toBe(true); // ceiling inclusive
expect(ve.isTakeable(+200)).toBe(true); // max inclusive
expect(ve.isTakeable(-200)).toBe(false); // too chalky
expect(ve.isTakeable(+250)).toBe(false); // too long
expect(ve.isTakeable(null)).toBe(false);
});
test('value = takeable AND ev above threshold', () => {
expect(ve.isValue(-120, 5)).toBe(true); // takeable + 5% EV
expect(ve.isValue(-120, 1)).toBe(false); // takeable but EV below 2%
expect(ve.isValue(-900, 20)).toBe(false); // huge EV but not takeable
});
});
// ── analyzeViaEngine1 value fields ──────────────────────────────────────────
const mockCompute = { current: null };
jest.mock('../../src/services/intelligence/computeFeatures', () => ({
computeFeaturesForProp: async () => mockCompute.current,
}));
jest.mock('../../src/services/intelligence/engine1', () => ({
gradeProp: () => ({ grade: 'B', confidence: 0.55, top_factors: [], all_factors: [] }),
}));
const mockPOver = { current: 0.6 };
jest.mock('../../src/services/intelligence/probabilityEstimator', () => ({
estimateProbability: () => ({ p_over: mockPOver.current }),
}));
const { analyzeViaEngine1 } = require('../../src/services/intelligence/analyzeViaEngine1');
beforeEach(() => {
mockCompute.current = {
features: { l5_avg: 1.4, l20_avg: 1.3 }, trap: {}, consistency: { consistency: 'reliable', score: 0.7 },
prop: { line: 0.5, direction: 'over' }, meta: { sport: 'mlb', gameLogs: [{ hits: 1 }], errors: [] },
};
mockPOver.current = 0.6; // model P(over) = 60%
});
describe('analyzeViaEngine1 — de-vig + EV + triplet (steps 1,2,6)', () => {
test('computes the value triplet, EV, and flags from both-sided odds', async () => {
// book: over -130 / under +110. model P(over) 0.60.
const out = await analyzeViaEngine1({
player: 'X', stat_type: 'hits', line: 0.5, direction: 'over', over_odds: -130, under_odds: 110,
});
expect(out.engine_grade).toBe('B'); // still a real read
expect(out.book_odds).toBe(-130); // book price
expect(typeof out.fair_odds).toBe('number'); // de-vigged fair price present (both sides)
expect(out.model_odds).toBe(-150); // impliedProbToAmerican(0.60)
expect(out.p_win).toBe(0.6);
// EV at -130 with p 0.60: 0.60*(1+100/130) - 1 = +6.15%
expect(out.ev_pct).toBeGreaterThan(5);
expect(out.takeable).toBe(true); // -130 in band
expect(out.value).toBe(true); // takeable + EV > 2%
expect(out.devig_method).toBe('multiplicative');
});
test('one-sided odds → fair UNAVAILABLE, but book price + EV still ship', async () => {
const out = await analyzeViaEngine1({
player: 'X', stat_type: 'hits', line: 0.5, direction: 'over', over_odds: -130, // no under_odds
});
expect(out.book_odds).toBe(-130);
expect(out.fair_odds).toBeUndefined(); // never faked from one side
expect(out.ev_pct).toBeGreaterThan(0); // EV from model + actual price
expect(out.takeable).toBe(true);
});
test('a chalky price is not takeable → not value even at positive EV', async () => {
mockPOver.current = 0.92;
const out = await analyzeViaEngine1({
player: 'X', stat_type: 'hits', line: 0.5, direction: 'over', over_odds: -600, under_odds: 400,
});
// -600 is past the JUICE_ODDS_FLOOR (-400) → refused before we even get here
expect(out.grade).toBeNull();
expect(out.suppressed_reason).toBe('juiced_no_edge');
});
});