Files
pplus-web/core/tests/tasks.test.mjs
T
alexmandClaude 82e18f7966 Move the engine core into core/, a project of its own (pplus-core)
What programs mean (the languages, translators, Mojo checker and
interpreter, prover, fuzzer, machine model, catalog problems and the Mojo
corpus with godbolt's stored answers) was mixed into the site's tree, so a
change to the prover and a change to a button went through the same gate
and the same docs. This moves all of it under core/, laid out as its own
repository, ready to be extracted with its history and pinned here as a
git submodule.

- core/: src/{engines,services,sync,mojo,exercises,curriculum,common},
  mojo/, syntax/mojo.xml, its tests (with Workspace and workForProblem in
  place of the site's Session), scripts (corpus pipeline, play, the
  exercise and probe starters, engines export/diff), and its docs
  (engines, trust, mojo-corpus, exercises, coverage). Its own pixi.toml,
  package.json, README, AGENTS.md and CI workflow.
- core/tests/boundary.test.mjs: library modules use no DOM, import no
  page widget, and import nothing outside src/.
- core/scripts/cli.mjs: pixi run cli check|run|prove|fuzz|translate.
- core/scripts/dafny.py: Dafny 4.11.0 pinned by version and SHA-256 per
  platform, fetched into .tools/ (pixi run dafny-fetch, pixi run dafny).
- The site imports core only as #core/<path>.js: an import map in
  index.html, "imports" in package.json for node, core's declarations for
  tsc. The site's TypeScript builds core first (npm run build).
- assemble.sh, the Quarto engine copy, the render cache key, check-pages,
  quarto-export and quarto-css read core/dist and core/mojo; quarto-css
  copies core's syntax/mojo.xml into the extension.
- Site tests that covered engines moved to core; the rest keep Session.
- README, AGENTS.md, docs/app.md, docs/deploy.md and the CI workflow
  describe the split (checkout with submodules; core's tests and corpus
  status run against the pinned commit).

Gate: site 110 pass; core 307 pass; corpus status --strict passes.
Manual check: the assembled site opens Bridge (count-base-proved),
Developer and Hardware (count-base) with the editor, the stepper and the
board, and no module errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FgvbRdoEheAHqsRmr2WuKZ
2026-10-05 05:43:58 +00:00

68 lines
3.0 KiB
JavaScript

// The commands people run live in pixi.toml; the README's table lists them. These tests keep the
// two in step, and keep every `pixi run <task>` mentioned anywhere pointing at a task that exists.
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
const ROOT = new URL('..', import.meta.url).pathname;
const read = (p) => fs.readFileSync(path.join(ROOT, p), 'utf8');
/** Task names in pixi.toml's [tasks] table: `name = {` at the start of a line, until the next table. */
function pixiTasks() {
const text = read('pixi.toml');
const body = text.slice(text.indexOf('\n[tasks]') + 1).split(/\n\[(?!tasks\])/)[0];
return [...body.matchAll(/^([a-z][a-z0-9-]*)\s*=\s*\{/gm)].map((m) => m[1]);
}
/** Task names in the README's Commands table: the first cell, a backticked name with optional arguments. */
function readmeTasks() {
const readme = read('README.md');
const section = readme.slice(readme.indexOf('## Commands'), readme.indexOf('\n## ', readme.indexOf('## Commands') + 1));
return [...section.matchAll(/^\| `([a-z][a-z0-9-]*)(?: [^`]*)?` \|/gm)].map((m) => m[1]);
}
test('the README lists every pixi task, once, and nothing else', () => {
const tasks = pixiTasks();
assert.ok(tasks.length > 20, `only ${tasks.length} tasks read from pixi.toml`);
const listed = readmeTasks();
assert.deepEqual([...listed].sort(), [...tasks].sort());
assert.equal(new Set(listed).size, listed.length, 'a task is listed twice');
});
test('every pixi task has a description', () => {
const text = read('pixi.toml');
for (const t of pixiTasks()) {
const line = text.split('\n').find((l) => l.startsWith(`${t} = {`));
assert.match(line, /description = "[^"]+"/, `${t} has no description`);
}
});
test('every `pixi run <task>` in the docs, scripts and sources names a real task', () => {
const tasks = new Set(pixiTasks());
const files = [];
const walk = (dir) => {
for (const e of fs.readdirSync(path.join(ROOT, dir), { withFileTypes: true })) {
const p = path.join(dir, e.name);
if (e.isDirectory()) { if (!['node_modules', 'dist', '.git', '.pixi', '.tools', 'corpus', 'golden', 'package'].includes(e.name)) walk(p); }
else if (/\.(md|mjs|ts|py|lua|yml|toml)$/.test(e.name)) files.push(p);
}
};
walk('.');
const unknown = [];
for (const f of files) {
for (const m of read(f).matchAll(/pixi run ([a-z][a-z0-9-]*)/g)) if (!tasks.has(m[1])) unknown.push(`${f}: pixi run ${m[1]}`);
}
assert.deepEqual(unknown, []);
});
test('package.json keeps only what CI and a machine without pixi need', () => {
const pkg = JSON.parse(read('package.json'));
assert.deepEqual(Object.keys(pkg.scripts).sort(), ['build', 'check', 'test', 'watch']);
});
test('every document the README points to exists', () => {
const readme = read('README.md');
for (const m of readme.matchAll(/\]\(((?:docs|mojo|scripts)\/[^)#]+)\)/g)) assert.ok(fs.existsSync(path.join(ROOT, m[1])), `${m[1]} is linked from the README but missing`);
});