// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC // SPDX-License-Identifier: Apache-2.0 // Every badge and chip the site shows makes a claim, and core's docs/trust.md is where each claim says what earned // it, what it means and what it does not mean. This test holds the two together: the words a badge can show are // listed here with the row of trust.md that covers them, the words must still be in the source that draws them, the // row must still be in trust.md, and a badge drawn in a new place fails the count until it is listed. import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; const trust = fs.readFileSync('core/docs/trust.md', 'utf8'); /** The first cell ("Shown") of every row of every table in trust.md. */ const shown = trust.split('\n').filter((l) => l.startsWith('| ') && !/^\| (Shown|---)/.test(l)).map((l) => l.slice(2).split(' | ')[0]); const read = (f) => fs.readFileSync(f, 'utf8'); const walk = (dir) => fs.readdirSync(dir, { withFileTypes: true }).flatMap((e) => (e.isDirectory() ? walk(path.join(dir, e.name)) : e.name.endsWith('.ts') ? [path.join(dir, e.name)] : [])); /** [the words on the badge, the file that draws it, the words of trust.md's "Shown" cell that cover it] */ const BADGES = [ ['Generated from pseudo', 'src/ui/provenance.ts', '**Generated from pseudo**'], ['best-practice rewrite', 'src/ui/provenance.ts', '**Generated from pseudo, with N best-practice rewrites**'], ['Started from generated Mojo', 'src/ui/provenance.ts', '**Started from generated Mojo**'], ['Compiled on godbolt', 'src/ui/provenance.ts', '**Compiled on godbolt**'], ['Edited since compile', 'src/ui/provenance.ts', '**Edited since compile**'], ...['compiling', 'ran, exit 0', 'exited with', 'compiled, did not run', 'did not compile', 'timed out', 'no answer'] .map((w) => [w, 'src/ui/views/compiler.ts', `**${w}`]), ['verified on Mojo', 'src/ui/shell.ts', '**verified on Mojo'], ['not verified', 'src/ui/shell.ts', '**not verified**'], ['your edits', 'src/ui/shell.ts', '**your edits**'], ['`Mojo ${MOJO_VERSION}`', 'src/ui/shell.ts', '(no other word)'], ["'verified'", 'src/ui/home.ts', 'The home page\'s **verified** chip'], ['your edits saved', 'src/ui/home.ts', '**your edits saved** chip'], ['proved', 'src/ui/views/panels.ts', '**Proved**'], ['broken by a run', 'src/ui/views/panels.ts', '**Broken**'], ['open', 'src/ui/views/panels.ts', '**Open**'], ['partial: not every path was examined', 'src/ui/views/panels.ts', '**partial: not every path was examined**'], ['no failures', 'src/ui/views/tests.ts', '**no failures**'], ['of failing', 'src/ui/views/tests.ts', '**N ways of failing**'], ['not tested', 'src/ui/views/tests.ts', '**not tested**'], // the home page's sample cards show the same three kinds of answer on a fixed example ['no failures', 'src/ui/home.ts', '**no failures**'], ['to fail', 'src/ui/home.ts', '**N ways of failing**'], ['proved', 'src/ui/home.ts', '**Proved**'], ['ran, exit 0', 'src/ui/home.ts', '**ran, exit 0**'], ]; /** The library page's chips are a check's name and one of five words; trust.md has a row for each kind of check. */ const LIBRARY_ROWS = ['**Cases pass**', '**Prover: pass**', '**Prover: open**', '**A reference agrees**', '**Mojo: unverified**', '**Proof: pass**']; test('every badge the site can show is drawn where this test says, and has a row in core\'s docs/trust.md', () => { assert.ok(shown.length >= 30, `${shown.length} rows read from core/docs/trust.md`); for (const [words, file, row] of BADGES) { assert.ok(read(file).includes(words), `${file} no longer shows "${words}": take it off this list, or say what replaced it`); assert.ok(shown.some((c) => c.includes(row)), `core/docs/trust.md has no row for ${row} (shown by ${file} as "${words}")`); } for (const row of LIBRARY_ROWS) assert.ok(shown.some((c) => c.includes(row)), `core/docs/trust.md has no row for ${row}`); }); test('a badge drawn in a new place is listed here, with its row in trust.md, before it ships', () => { const sites = new Map(); for (const f of walk('src')) { const n = (read(f).match(/class: [`'](?:badge[ `'$]|chip chip-verified|chip chip-saved|lib-chip[ `'$])/g) || []).length; if (n) sites.set(f, n); } assert.deepEqual(Object.fromEntries(sites), { 'src/ui/home.ts': 9, 'src/ui/library.ts': 2, 'src/ui/provenance.ts': 3, 'src/ui/shell.ts': 3, 'src/ui/views/compiler.ts': 2, 'src/ui/views/panels.ts': 5, 'src/ui/views/tests.ts': 3, }, 'a badge was added or removed: update BADGES above and core\'s docs/trust.md, then this count'); });