import assert from 'node:assert/strict';
import { readFileSync, readdirSync, statSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { resolve, dirname } from 'node:path';
import { gzipSync } from 'node:zlib';
const root = dirname(fileURLToPath(import.meta.url));
const dist = resolve(root, 'assets');
const project = resolve(root, '..');
const read = (name) => readFileSync(resolve(dist, name), 'utf8');
const html = readFileSync(resolve(project, 'index.html'), 'utf8');
const css = read('styles.css');
const js = read('app.js');
const data = JSON.parse(read('results.json'));
const ids = [...html.matchAll(/\bid="([^"]+)"/g)].map((match) => match[1]);
assert.equal(new Set(ids).size, ids.length, 'Duplicate HTML IDs');
assert.equal((html.match(/
Receiver-Conditioned Latent Communication gives/);
assert.equal((html.match(//g) || []).length, 4, 'Explain each static paper figure');
assert.match(html, //);
assert.match(html, /name="viewport"/);
assert.match(html, /Receiver-Conditioned Latent Communication gives 94% CacheBack<\/title>/);
const sectionOrder = ['result-summary', 'abstract', 'demo', 'results', 'booking-demo', 'code', 'paper'];
sectionOrder.slice(1).forEach((id, i) => {
assert.ok(html.indexOf(`id="${sectionOrder[i]}"`) < html.indexOf(`id="${id}"`), `Section order: ${id}`);
});
assert.equal((html.match(/
= 2 && Number.isInteger(model.ratio));
for (const arm of [model.text, model.cache]) {
assert.ok(arm.accuracy >= 0 && arm.accuracy <= 1);
assert.ok(arm.seconds > 0 && Number.isFinite(arm.seconds));
}
}
// The displayed bar lengths must encode the published data on shared zero-based scales.
const plottedWidths = [...html.matchAll(/ Number(match[1]));
const expectedWidths = Object.values(data.models).flatMap(model => [
model.text.accuracy * 100, model.cache.accuracy * 100,
model.text.seconds / 1600 * 100, model.cache.seconds / 1600 * 100,
]);
assert.equal(plottedWidths.length, 16);
plottedWidths.forEach((width, i) => assert.ok(Math.abs(width - expectedWidths[i]) < 0.0001));
const gains = [...html.matchAll(/class="accuracy-gain">\+([\d.]+) Number(match[1]));
const speedups = [...html.matchAll(/([\d.]+)× faster<\/strong>/g)].map(match => Number(match[1]));
assert.deepEqual(gains, Object.values(data.models).map(m => Number(((m.cache.accuracy - m.text.accuracy) * 100).toFixed(1))));
assert.deepEqual(speedups, Object.values(data.models).map(m => Number((m.text.seconds / m.cache.seconds).toFixed(1))));
assert.doesNotMatch(html, /name="model"/);
assert.match(html, /loading="lazy" sandbox="allow-scripts allow-same-origin"/);
assert.match(css, /prefers-reduced-motion:reduce/);
assert.match(css, /:focus-visible/);
assert.match(html, /id="bibtex"/);
assert.match(html, /