// Harness for the admin panel's page JS. Run through the skill's checker — // ~/.hermes/skills/research/inference-cooperative/scripts/check-page-js.sh \ // app/main.py admin-panel-chart-harness.js // which evals stub + page JS + this file in ONE node scope, so the assertions // below exercise the page's REAL functions (renderTrends, registerChartTips, // showChartTip, moveChartTip) against a fixture shaped like the portal's // /admin/metrics payload. Assert invariants, never the shape you happened to // observe; when a check fails here, suspect this file first. const assert = (cond, msg) => { if (!cond) { console.error("FAIL: " + msg); process.exit(1); } }; // Fixture: oldest-first daily rows, with a NULL day (unmeasured) to exercise // the gap rule (NULL renders as a gap, never a zero — and gets no tooltip). trendsData = [ { day: "2026-11-01", members_total: 71, spend_usd: 12.34, requests: 2900, energy_wh: 8400.5, co2e_g: 2100.25 }, { day: "2026-11-02", members_total: 72, spend_usd: null, requests: 3100, energy_wh: null, co2e_g: null }, { day: "2026-11-03", members_total: 74, spend_usd: 5.01, requests: 1204, energy_wh: 9100, co2e_g: 2300 }, { day: "2026-11-04", members_total: 75, spend_usd: 7.89, requests: 980, energy_wh: 6400, co2e_g: 1600 }, ]; // ---- Bars (spend): every measured day is hoverable, gaps are not ---- trendMetric = "spend"; trendDays = 30; renderTrends(); { const host = document.getElementById("trend-body"); const pts = chartTipData["trend-body"]; assert(Array.isArray(pts) && pts.length === 4, "registry: one point per row (got " + (pts && pts.length) + ")"); assert(pts[0].label === "2026-11-01", "registry label is the row's exact day"); assert(pts[0].series[0][0] === "Spend per day", "registry series name is the chart title"); // EXACT values: the tooltip string must be the data value through the // panel's own formatter — never a pixel-derived estimate. assert(pts[0].series[0][1] === "$12.34", "exact spend for 11-01 (got " + pts[0].series[0][1] + ")"); assert(pts[2].series[0][1] === "$5.01", "exact spend for 11-03 (got " + pts[2].series[0][1] + ")"); assert(pts[3].series[0][1] === "$7.89", "exact spend for 11-04 (got " + pts[3].series[0][1] + ")"); assert(pts[1].series[0][1] === "not measured", "NULL day registers as not measured"); const marks = host.innerHTML.match(/data-tip-i="(\d+)"/g) || []; const idxs = marks.map(s => parseInt(s.match(/\d+/)[0], 10)).sort((a, b) => a - b); assert(JSON.stringify(idxs) === "[0,2,3]", "bars stamped only on measured days (got " + JSON.stringify(idxs) + ")"); assert((host.innerHTML.match(/data-tip-host="trend-body"/g) || []).length === 3, "every bar carries its host id"); assert(!/