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
9 changes: 8 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 } from './history.mjs';
import { mergeRuns, mergeMetrics, readJsonl, appendJsonl, snapshotRun, pruneSnapshots, pickLatest } from './history.mjs';

// ── format ────────────────────────────────────────────────────────────────
test('rollupStatus: worst-of precedence', () => {
Expand Down Expand Up @@ -186,6 +186,13 @@ test('mergeRuns tie-breaks equal finishedAt deterministically by runId', () => {
const { merged } = mergeRuns([], [{ runId: 'b', finishedAt: 5 }, { runId: 'a', finishedAt: 5 }]);
assert.deepEqual(merged.map((r) => r.runId), ['a', 'b']);
});
test('pickLatest prefers newest available run, skips re-stamped/unavailable headline', () => {
assert.equal(pickLatest([]), null);
assert.equal(pickLatest(null), null);
assert.equal(pickLatest([{ runId: 'r2', available: false }, { runId: 'r1', available: true }]), 'r1');
assert.equal(pickLatest([{ runId: 'r2', available: true }, { runId: 'r1', available: true }]), 'r2');
assert.equal(pickLatest([{ runId: 'r2', available: false }, { runId: 'r1', available: false }]), 'r2');
});
test('mergeMetrics dedupes by key', () => {
const { merged, added } = mergeMetrics([{ key: 'a' }], [{ key: 'a' }, { key: 'b' }, { key: 'b' }]);
assert.equal(merged.length, 2);
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 @@ -24,6 +24,18 @@ export function mergeRuns(existing, incoming) {
return { merged, added };
}

/**
* Pick the headline "latest" run for the dashboard. Runs come in newest-first
* (as mergeRuns sorts them). Prefer the newest run whose report is actually on
* disk (available) so the headline never points at a re-stamped/cached entry
* that 404s on drill-down; fall back to the newest run overall, else null.
*/
export function pickLatest(runs) {
if (!Array.isArray(runs) || !runs.length) return null;
const available = runs.find((r) => r && r.available);
return (available || runs[0]).runId;
}

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 } from './history.mjs';
import { mergeRuns, mergeMetrics, readJsonl, appendJsonl, snapshotRun, pruneSnapshots, pickLatest } from './history.mjs';
import { renderShell } from './page.mjs';

const args = process.argv.slice(2);
Expand Down Expand Up @@ -104,7 +104,7 @@ function reindex() {
const allMetrics = readJsonl(METRICS_JSONL);
state = {
generatedAt: Date.now(),
latest: merged[0] ? merged[0].runId : null,
latest: pickLatest(merged),
runs: merged,
metrics: allMetrics.slice(-6000),
roots: ROOTS.map((r) => ({ name: r.name, label: r.label, mode: r.mode, exists: existsSync(r.path), count: discovered.filter((d) => d.source === r.name).length })),
Expand Down
Loading