Skip to content

Commit bdda7f3

Browse files
authored
Normalize catalogs for existing preview clients (#36)
Normalize each compatible benchmark history to one merged catalog when assembling site data. This lets PR #30's existing preview bundle load additive runtime results without changing its head or rerunning benchmarks. Stored result bundles remain immutable, and conflicting definitions still fail validation. Validation: `npm run build`; editor diagnostics; `git diff --check`. Tests were not run. Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 530d5d0 commit bdda7f3

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎scripts/assemble-site.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { cpSync, existsSync, lstatSync, mkdirSync, readdirSync, rmSync } from 'node:fs'
22
import { resolve } from 'node:path'
33
import { z } from 'zod'
4-
import { historyIndexSchema, historyRunPath, parseHistoryRun, runKey, groupHistories, validatePublication } from '../shared/results.ts'
4+
import { historyIndexSchema, historyRunPath, parseHistoryRun, runKey, groupHistories, validateHistory, validatePublication } from '../shared/results.ts'
55
import type { RunBundle } from '../shared/results.ts'
66
import { readJson, readOptionalJson, writeJson } from './result-store.ts'
77

@@ -54,7 +54,11 @@ export function assembleSite(options: {
5454
const published = index.runs.map(entry => parseHistoryRun(readJson(resolve(options.store, historyRunPath(entry))), entry))
5555
const seen = new Set<number>()
5656
function serveData(destination: string, bundles: RunBundle[], preview?: { number: number, head: string, pending: { id: string, attempt: number } | null }) {
57-
groupHistories(bundles)
57+
const catalogs = new Map(groupHistories(bundles).flatMap(history => {
58+
const { runtimes, platforms, metrics } = validateHistory(history)
59+
const catalog = { runtimes, platforms, metrics }
60+
return history.map(bundle => [runKey(bundle), catalog] as const)
61+
}))
5862
const runs = bundles.map(bundle => {
5963
const entry = { id: bundle.run.id, attempt: bundle.run.attempt }
6064
if (!index.runs.some(run => run.id === entry.id && run.attempt === entry.attempt)) return entry
@@ -69,7 +73,7 @@ export function assembleSite(options: {
6973
} }
7074
})
7175
const history = historyIndexSchema.parse({ schemaVersion: 1, runs, ...(preview ? { preview } : {}) })
72-
for (const bundle of bundles) writeJson(resolve(destination, 'data', historyRunPath(bundle.run)), bundle, true)
76+
for (const bundle of bundles) writeJson(resolve(destination, 'data', historyRunPath(bundle.run)), { ...bundle, catalog: catalogs.get(runKey(bundle))! }, true)
7377
writeJson(resolve(destination, 'data/index.json'), history, true)
7478
}
7579
try {

‎scripts/publication.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,16 @@ test('benchmark definition changes retain selectable histories and pending previ
262262
const production = resolve(temporary, 'build')
263263
mkdirSync(production)
264264
writeFileSync(resolve(production, 'index.html'), '<!doctype html><title>Fixture</title>')
265+
const compatibilityStore = resolve(temporary, 'compatibility-store')
266+
writeJson(resolve(compatibilityStore, historyRunPath(first.run)), first, true)
267+
writeJson(resolve(compatibilityStore, historyRunPath(expanded.run)), expanded, true)
268+
writeJson(resolve(compatibilityStore, 'index.json'), { schemaVersion: 1, runs: [first.run, expanded.run].map(({ id, attempt }) => ({ id, attempt })) }, true)
269+
const compatibilitySite = resolve(temporary, 'compatibility-site')
270+
assembleSite({ production, store: compatibilityStore, output: compatibilitySite, repository, previews: [] })
271+
const servedFirst = readJson(resolve(compatibilitySite, 'data', historyRunPath(first.run))) as any
272+
const servedExpanded = readJson(resolve(compatibilitySite, 'data', historyRunPath(expanded.run))) as any
273+
assert.deepEqual(servedFirst.catalog, servedExpanded.catalog)
274+
assert.equal(servedFirst.catalog.runtimes.length, first.catalog.runtimes.length + 1)
265275
const pending = fixture()
266276
pending.run.id = 'pending'
267277
pending.run.createdAt = '2026-09-05T00:00:00Z'

0 commit comments

Comments
 (0)