Session 57: Phase 0 — Kill the Lies (2309 tests)

Work-order Phase 0 (Jul 10 live audit): every fabricated UI element deleted
or rewired to real data. Deletion sprint — no new product features.

0.1 Fake NBA game: root cause was scheduleService fetching the ESPN
    scoreboard with no ?dates= param or date filter — off-season ESPN
    returns the NEAREST slate (Jun 13 NYK@SA Finals rendered as tonight).
    Now pinned to the requested ET date + defensive filter; undated events
    dropped. Honest month-aware per-sport empty states (lib/emptyState.js).
0.2 Fake header counters: liveTick stripped to a bare 1s pulse (the
    auto-incrementing "247 graded", sin-driven brain-%, aPlus/cascades are
    dead). New GET /api/snapshot/summary (cache-only, before /:sport) +
    Next proxy; HeartbeatBar shows the real graded count and SYNC =
    elapsed since the last pipeline run (amber past 5 min).
0.3 Ticker: hardcoded fallback items deleted (real snapshot exhaust only);
    MOVE kept — computeLineDeltas is real movement. <4 real items → no
    ticker; bar publishes --ticker-h so the fixed header collapses cleanly.
0.4 /terminal retired: route redirects to /dashboard; VVI/injury-wire/
    leaders layouts preserved unrouted as §12 content-engine templates.
    Nav PRIMARY = Slate/Scan/Ledger; BottomTabBar Terminal→Explore; PWA
    shortcut Terminal→Ledger; #terminal alias → /dashboard.
0.5 ›Query nav pill deleted (duplicate /scan link).

Backend 2289 → 2309 tests (199 suites), web build exit 0.
Spec: specs/phase-0-kill-the-lies.md. Next: work-order Phase 1 (ledger
persistence + settlement).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Kev
2026-07-10 20:17:49 -04:00
parent 2ae8a5697e
commit c8790fde55
27 changed files with 891 additions and 311 deletions
+33
View File
@@ -36,6 +36,39 @@ function attachOutcomes(grades, index) {
});
}
// Session 57 (Phase 0) — GET /api/snapshot/summary: the HeartbeatBar's honest
// data source. Cheap cache-only Redis reads; total graded props in the current
// snapshots + the latest pipeline run time. Registered BEFORE /:sport or
// Express captures "summary" as a sport.
const SUMMARY_SPORTS = ['nba', 'wnba', 'mlb', 'soccer'];
router.get('/summary', async (req, res) => {
try {
const reads = await Promise.all(SUMMARY_SPORTS.map(async (sp) => {
const snap = await cacheGet(`snapshot:${sp}:latest`);
if (snap && Array.isArray(snap.grades)) {
return { sport: sp, graded: snap.grades.length, updated_at: snap.updated_at || null };
}
const env = await cacheGet(`grades:${sp}`);
return {
sport: sp,
graded: env && Array.isArray(env.grades) ? env.grades.length : 0,
updated_at: (env && env.updated_at) || null,
};
}));
const graded = reads.reduce((n, r) => n + r.graded, 0);
// ISO timestamps sort lexicographically — the max is the latest run.
const updated_at = reads.map((r) => r.updated_at).filter(Boolean).sort().pop() || null;
const sports = {};
for (const r of reads) sports[r.sport] = r.graded;
res.set('Cache-Control', 'public, max-age=30');
return res.json({ graded, updated_at, sports });
} catch (err) {
console.error('[snapshot/summary]', err.message);
return res.status(200).json({ graded: 0, updated_at: null, sports: {} });
}
});
router.get('/:sport', async (req, res) => {
const sport = String(req.params.sport || '').toLowerCase();
try {
+31 -5
View File
@@ -87,14 +87,40 @@ function normalizeEvent(ev) {
}
/**
* Fetch + normalize the ESPN scoreboard for a sport. Free endpoint.
* A game's ET date (YYYY-MM-DD) from its ISO start time, or null when the
* timestamp is missing/unparseable.
*/
async function fetchScheduleFromEspn(sport) {
function gameDateET(iso) {
if (!iso) return null;
const t = new Date(iso);
if (Number.isNaN(t.getTime())) return null;
return new Intl.DateTimeFormat('en-CA', {
timeZone: 'America/New_York',
year: 'numeric', month: '2-digit', day: '2-digit',
}).format(t);
}
/**
* Fetch + normalize the ESPN scoreboard for a sport. Free endpoint.
*
* Session 57 (Phase 0) — MUST be pinned to the requested date. Without a
* `?dates=` param ESPN returns the NEAREST slate in the off-season (the Jun 13
* NYK@SA Finals game kept rendering as "tonight" all July). We pass the param
* AND filter defensively: only events whose ET date matches `date` survive;
* events with no parseable date are dropped — the slate derives from the live
* feed only, never from whatever ESPN felt like returning.
*/
async function fetchScheduleFromEspn(sport, date) {
const cfg = getSportConfig(sport);
if (!cfg || !cfg.espnScoreboard) return null;
const res = await axios.get(cfg.espnScoreboard, { timeout: HTTP_TIMEOUT_MS });
const sep = cfg.espnScoreboard.includes('?') ? '&' : '?';
const url = date
? `${cfg.espnScoreboard}${sep}dates=${String(date).replace(/-/g, '')}`
: cfg.espnScoreboard;
const res = await axios.get(url, { timeout: HTTP_TIMEOUT_MS });
const events = res.data?.events || [];
return events.map(normalizeEvent).filter(Boolean);
const games = events.map(normalizeEvent).filter(Boolean);
return date ? games.filter((g) => gameDateET(g.gameTime) === date) : games;
}
/**
@@ -111,7 +137,7 @@ async function getSchedule(sport, date) {
if (cached !== null) return cached;
try {
const games = await fetchScheduleFromEspn(sport);
const games = await fetchScheduleFromEspn(sport, date);
if (Array.isArray(games)) {
await cacheSet(key, games, SCHEDULE_TTL);
await cacheSet(`${key}:stale`, games, STALE_TTL);