Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tests/lib/dashboard/dashboard.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { rollupStatus, fmtDuration, fmtBytes, pct, decodeMungedName, esc, STATUS
import { niceMax, bounds, lineChart, statusBar, sparkline } from './charts.mjs';
import { isUnifiedReport, runIdFor, summarize, mediaCount, safeId } from './ingest.mjs';
import { reportMetrics, scaleSweepMetrics, largeGraphMetrics, physicsMetrics, vlmMetrics, pointKey } from './metrics.mjs';
import { mergeRuns, mergeMetrics, readJsonl, appendJsonl, snapshotRun, pruneSnapshots, pickLatest } from './history.mjs';
import { mergeRuns, mergeMetrics, liveMetrics, readJsonl, appendJsonl, snapshotRun, pruneSnapshots, pickLatest } from './history.mjs';

// ── format ────────────────────────────────────────────────────────────────
test('rollupStatus: worst-of precedence', () => {
Expand Down Expand Up @@ -213,6 +213,19 @@ test('mergeMetrics dedupes by key', () => {
assert.equal(merged.length, 2);
assert.deepEqual(added.map((m) => m.key), ['b']);
});
test('liveMetrics drops stale -1 sentinels and non-finite values from stored history', () => {
const m = liveMetrics([
{ metric: 'graph.driftPx', value: -1 },
{ metric: 'graph.avgTickMs', value: -1 },
{ metric: 'graph.driftPx', value: 85.77 },
{ metric: 'graph.idleFps', value: 0 },
{ metric: 'graph.loadMs', value: NaN },
{ metric: 'suite.passRate', value: 100 },
null,
]);
assert.equal(m.length, 3);
assert.deepEqual(m.map((x) => x.value), [85.77, 0, 100]);
});

// ── history fs round-trip ───────────────────────────────────────────────────
test('jsonl append/read round-trip tolerates blank lines', () => {
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/dashboard/history.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ export function pickLatest(runs) {
return (available || runs[0]).runId;
}

/**
* Drop not-measured sentinels from a stored metric series before it reaches the
* charts. Ingestion (metrics.mjs) already filters -1 sentinels, but the
* append-only metrics.jsonl retains points written before that fix landed; a -1
* on a lower-is-better metric (driftPx, avgTickMs) otherwise reads as a perfect
* score and distorts the trend. Every GraphDone metric is non-negative, so a
* non-finite or negative value is always a sentinel.
*/
export function liveMetrics(metrics) {
return metrics.filter((m) => m && typeof m.value === 'number' && isFinite(m.value) && m.value >= 0);
}

export function mergeMetrics(existing, incoming) {
const seen = new Set(existing.map((m) => m.key));
const added = [];
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/dashboard/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { resolve, join, sep, extname } from 'node:path';
import { spawn } from 'node:child_process';
import { discover, signature, safeId, summarize } from './ingest.mjs';
import { reportMetrics, scanPerfArtifacts } from './metrics.mjs';
import { mergeRuns, mergeMetrics, readJsonl, appendJsonl, snapshotRun, pruneSnapshots, pickLatest } from './history.mjs';
import { mergeRuns, mergeMetrics, liveMetrics, readJsonl, appendJsonl, snapshotRun, pruneSnapshots, pickLatest } from './history.mjs';
import { renderShell } from './page.mjs';

const args = process.argv.slice(2);
Expand Down Expand Up @@ -101,7 +101,7 @@ function reindex() {

if (existsSync(join(STORE, 'runs'))) pruneSnapshots(STORE, KEEP);

const allMetrics = readJsonl(METRICS_JSONL);
const allMetrics = liveMetrics(readJsonl(METRICS_JSONL));
state = {
generatedAt: Date.now(),
latest: pickLatest(merged),
Expand Down
Loading