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
This commit is contained in:
1 parent
961a59054d
commit
c5157fcad5
56 files changed
+3386
-66
No files matched your search
@@ -0,0 +1,57 @@
|
||||
// pplus-core has no DOM: what a program means is decided without a browser. Its library modules never touch the
|
||||
// document, the window or browser storage, and never import the course's page widgets, which live beside the
|
||||
// engines only so the course and pplus-web can take them from one place (docs/engines.md).
|
||||
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 SRC = path.join(ROOT, 'src');
|
||||
|
||||
/** The course's page widgets: they draw into a page, and only pages (the course's, pplus-web's) import them. */
|
||||
export const WIDGETS = new Set([
|
||||
'engines/pseudo/dom.js', 'engines/pseudo/views.js', 'engines/pseudo/views-analysis.js', 'engines/pseudo/lab.js',
|
||||
'engines/pseudo/editor.js', 'engines/pseudo/exercise.js', 'engines/pseudo/sharpen.js', 'engines/pseudo/plan.js',
|
||||
'engines/pseudo/planner.js', 'engines/pseudo/highlight.js',
|
||||
'engines/asm86/views.js', 'engines/asm86/hwviews.js', 'engines/asm86/dom.js', 'engines/asm86/sandbox.js', 'engines/asm86/specs-hw.js',
|
||||
'engines/shared/dom.js', 'engines/shared/share.js', 'engines/shared/viz.js',
|
||||
]);
|
||||
|
||||
function walk(dir, out = []) {
|
||||
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const p = path.join(dir, e.name);
|
||||
if (e.isDirectory()) walk(p, out); else if (/\.(ts|js)$/.test(e.name)) out.push(path.relative(SRC, p));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
const asJs = (p) => p.replace(/\.ts$/, '.js');
|
||||
const files = walk(SRC);
|
||||
const library = files.filter((f) => !WIDGETS.has(asJs(f)));
|
||||
|
||||
test('every widget named here exists, so the list cannot rot', () => {
|
||||
for (const w of WIDGETS) assert.ok(files.some((f) => asJs(f) === w), `${w} is not in src/`);
|
||||
});
|
||||
|
||||
test('no library module touches the document, the window or browser storage', () => {
|
||||
const bad = [];
|
||||
for (const f of library) {
|
||||
const code = fs.readFileSync(path.join(SRC, f), 'utf8').replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '');
|
||||
for (const w of ['document.', 'window.', 'localStorage', 'sessionStorage', 'navigator.', 'HTMLElement']) if (code.includes(w)) bad.push(`${f}: ${w}`);
|
||||
}
|
||||
assert.deepEqual(bad, []);
|
||||
});
|
||||
|
||||
test('no library module imports a widget, and nothing imports from outside core', () => {
|
||||
const bad = [];
|
||||
for (const f of library) {
|
||||
const code = fs.readFileSync(path.join(SRC, f), 'utf8');
|
||||
for (const m of code.matchAll(/(?:from|import)\s*\(?\s*['"](\.{1,2}\/[^'"]+)['"]/g)) {
|
||||
const target = path.normalize(path.join(path.dirname(f), m[1]));
|
||||
if (target.startsWith('..')) bad.push(`${f} imports ${m[1]}, outside src/`);
|
||||
else if (WIDGETS.has(asJs(target))) bad.push(`${f} imports the widget ${m[1]}`);
|
||||
}
|
||||
if (/['"]#core\//.test(code)) bad.push(`${f} uses #core/, which is how pplus-web reaches core`);
|
||||
}
|
||||
assert.deepEqual(bad, []);
|
||||
});
|
||||
@@ -3,7 +3,7 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { LESSONS, CONCEPTS, CONCEPT_BY_ID, FLAVORS, teacherOf, prerequisitesOf, depthOf, allPrerequisitesOf, statusOf, solutionOf, starterOf } from '../dist/curriculum/index.js';
|
||||
import { studyOf, runPseudo } from '../dist/services/pseudo.js';
|
||||
import { problemById } from '../dist/core/problems.js';
|
||||
import { problemById } from '../dist/common/problems.js';
|
||||
|
||||
const conceptIds = new Set(CONCEPTS.map((c) => c.id));
|
||||
const flavorIds = new Set(FLAVORS.map((f) => f.id));
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// The pinned Dafny (scripts/dafny.py): its offline tests, and, when it has been fetched, that it is the pinned
|
||||
// version and verifies a program.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
|
||||
const py = spawnSync('python3', ['--version']);
|
||||
const ROOT = new URL('..', import.meta.url).pathname;
|
||||
|
||||
test('the Dafny pin\'s own tests pass (python3)', { skip: py.status !== 0 ? 'python3 is not installed' : false }, () => {
|
||||
const r = spawnSync('python3', ['-m', 'unittest', 'discover', '-s', 'scripts/tests'], { encoding: 'utf8', cwd: ROOT });
|
||||
assert.equal(r.status, 0, r.stderr);
|
||||
});
|
||||
|
||||
const exe = ROOT + '.tools/dafny-4.11.0/dafny/dafny';
|
||||
test('the fetched Dafny is the pinned one, and verifies a program', { skip: fs.existsSync(exe) ? false : 'Dafny has not been fetched (pixi run dafny-fetch)' }, () => {
|
||||
const v = spawnSync(exe, ['--version'], { encoding: 'utf8' });
|
||||
assert.match(v.stdout, /^4\.11\.0\+/);
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'pplus-dafny-'));
|
||||
fs.writeFileSync(dir + '/max.dfy', 'method Max(a: int, b: int) returns (m: int) ensures m >= a && m >= b { if a > b { m := a; } else { m := b; } }\n');
|
||||
const r = spawnSync(exe, ['verify', dir + '/max.dfy'], { encoding: 'utf8' });
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
assert.equal(r.status, 0, r.stdout + r.stderr);
|
||||
assert.match(r.stdout, /1 verified, 0 errors/);
|
||||
});
|
||||
@@ -2,11 +2,10 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { EXERCISES } from '../dist/exercises/index.js';
|
||||
import { PROBLEMS, stateForProblem } from '../dist/core/catalog.js';
|
||||
import { Session } from '../dist/core/session.js';
|
||||
import template from '../dist/exercises/_template.js';
|
||||
import { Workspace } from '../dist/common/workspace.js';
|
||||
import { PROBLEMS, problemById, workForProblem } from '../dist/common/problems.js';
|
||||
|
||||
globalThis.localStorage = { getItem() { return null; }, setItem() { }, removeItem() { } };
|
||||
|
||||
test('exercise ids are unique, URL-safe, and the template is not registered', () => {
|
||||
const ids = EXERCISES.map((e) => e.id);
|
||||
@@ -18,9 +17,9 @@ test('exercise ids are unique, URL-safe, and the template is not registered', ()
|
||||
test('every exercise with an expected answer produces it', () => {
|
||||
for (const p of PROBLEMS) {
|
||||
if (!p.expect) continue;
|
||||
const st = stateForProblem(p);
|
||||
const st = workForProblem(p);
|
||||
if (st.sources.pseudo) st.lang = 'pseudo';
|
||||
const s = new Session(st);
|
||||
const s = new Workspace(st);
|
||||
const tr = s.trace();
|
||||
assert.ok(tr && !tr.error, `${p.id}: ${s.runError || tr?.error?.message}`);
|
||||
const last = tr.output.at(-1);
|
||||
@@ -29,7 +28,7 @@ test('every exercise with an expected answer produces it', () => {
|
||||
});
|
||||
|
||||
test('the template itself is a valid exercise', () => {
|
||||
const s = new Session(stateForProblem({ ...template, lang: 'pseudo' }));
|
||||
const s = new Workspace(workForProblem({ ...template, lang: 'pseudo' }));
|
||||
const tr = s.trace();
|
||||
assert.ok(tr && !tr.error, s.runError || tr?.error?.message);
|
||||
assert.ok(tr.output.at(-1).endsWith(`returned ${template.expect}`));
|
||||
|
||||
+5
-6
@@ -2,13 +2,12 @@
|
||||
// is what the engines do. Run on every exercise, in pseudo and in Mojo.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { Session } from '../dist/core/session.js';
|
||||
import { PROBLEMS, stateForProblem, problemById } from '../dist/core/catalog.js';
|
||||
import { STRATEGY } from '../dist/core/fuzz.js';
|
||||
import { STRATEGY } from '../dist/common/fuzz.js';
|
||||
import { Workspace } from '../dist/common/workspace.js';
|
||||
import { PROBLEMS, problemById, workForProblem } from '../dist/common/problems.js';
|
||||
|
||||
globalThis.localStorage = { getItem() { return null; }, setItem() { }, removeItem() { } };
|
||||
|
||||
const open = (p, lang, call) => { const st = stateForProblem(p); st.lang = lang; if (call) st.call = call; return new Session(st, { area: lang === 'mojo' ? 'dev' : 'bridge', storageId: null }); };
|
||||
const open = (p, lang, call) => { const st = workForProblem(p); st.lang = lang; if (call) st.call = call; return new Workspace(st); };
|
||||
const ALL = [];
|
||||
for (const p of PROBLEMS) for (const lang of ['pseudo', 'mojo']) if ((p.sources?.[lang] ?? '').trim()) ALL.push({ p, lang, s: open(p, lang) });
|
||||
|
||||
@@ -44,7 +43,7 @@ test('every report says what it tried, what it checked, and what happened, and a
|
||||
test('the same seed makes the same inputs; another seed makes others', () => {
|
||||
const s = open(problemById('count-base'), 'pseudo');
|
||||
const a = s.fuzz({ seed: 7, budget: 100 })[0].cases.map((c) => c.call);
|
||||
const b = new Session(s.state, { storageId: null }).fuzz({ seed: 7, budget: 100 })[0].cases.map((c) => c.call);
|
||||
const b = new Workspace(s.state).fuzz({ seed: 7, budget: 100 })[0].cases.map((c) => c.call);
|
||||
const c = s.fuzz({ seed: 8, budget: 100 })[0].cases.map((c) => c.call);
|
||||
assert.deepEqual(a, b);
|
||||
assert.notDeepEqual(a, c);
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
// The x86-64 model machine: for every problem that has assembly, on every machine, the hardware model runs, the
|
||||
// machine presets reach it, and the pipeline, micro-op, out-of-order and encoding data hold together. The app's
|
||||
// board, which decides what the course views are given, is tested in pplus-web.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { stageOccupancy, STAGES } from '../dist/engines/asm86/pipeline.js';
|
||||
import { coreAt } from '../dist/engines/asm86/ooo.js';
|
||||
import { decompose } from '../dist/engines/asm86/uops.js';
|
||||
import fs from 'node:fs';
|
||||
import { stripHeader, buildListing } from '../scripts/mojo/listings.mjs';
|
||||
import { forSimulator, simulatorSetup } from '../dist/mojo/att.js';
|
||||
import { listingFunctions } from '../dist/services/godbolt.js';
|
||||
import { hardwareFor, resolveMachine } from '../dist/engines/asm86/machine.js';
|
||||
import { viewNames } from '../dist/engines/asm86/views.js';
|
||||
import { SERVICES } from '../dist/services/index.js';
|
||||
import { MACHINE_PRESETS, parseMachine, machineName, machineSpec, machineLabel } from '../dist/common/machine.js';
|
||||
import { Workspace } from '../dist/common/workspace.js';
|
||||
import { PROBLEMS, problemById, workForProblem } from '../dist/common/problems.js';
|
||||
|
||||
|
||||
/** Every catalog problem with an x86-64 pane, run as the Hardware area runs it. */
|
||||
const WITH_ASM = PROBLEMS.filter((p) => (p.sources?.asm ?? '').trim());
|
||||
const traceOf = (p, machine) => {
|
||||
const st = workForProblem(p);
|
||||
if (machine) st.machine = machine;
|
||||
st.lang = 'asm';
|
||||
const s = new Workspace(st);
|
||||
const tr = s.trace();
|
||||
assert.ok(tr && tr.lang === 'asm', `${p.id}: the x86-64 pane runs`);
|
||||
return { session: s, tr, raw: tr.raw.trace };
|
||||
};
|
||||
|
||||
test('the hardware model runs on every problem with assembly, on both machines, with and without virtual memory', () => {
|
||||
for (const p of WITH_ASM) for (const machine of ['teaching', 'realistic', 'teaching+paging', 'realistic+paging']) {
|
||||
const { raw, tr } = traceOf(p, machine);
|
||||
const hw = hardwareFor(raw);
|
||||
assert.doesNotThrow(() => { hw.memory(); hw.pipeline(); hw.core(); }, `${p.id} on ${machine}`);
|
||||
const perf = tr.raw.hardware().perf();
|
||||
assert.equal(perf.instructions, raw.stats.instructions, `${p.id} on ${machine}: the counters read the same run`);
|
||||
for (const t of [0, 1, Math.floor(raw.count / 2), raw.count]) assert.ok(hw.memory().stateAt(t).h, `${p.id}: caches at step ${t}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('a machine is a preset with virtual memory on or off, and the run carries it to the hardware model', () => {
|
||||
assert.deepEqual(MACHINE_PRESETS.slice(0, 2), ['teaching', 'realistic']);
|
||||
for (const preset of MACHINE_PRESETS) for (const paging of [false, true]) {
|
||||
const name = machineName({ preset, paging });
|
||||
assert.deepEqual(parseMachine(name), { preset, paging }, name);
|
||||
assert.equal(resolveMachine(machineSpec(name)).paging.enabled, paging, `${name}: paging`);
|
||||
assert.match(machineLabel(name), new RegExp(`^${preset}`));
|
||||
}
|
||||
assert.deepEqual(parseMachine(undefined), { preset: 'teaching', paging: false });
|
||||
assert.deepEqual(parseMachine('warp'), { preset: 'teaching', paging: false }, 'an unknown machine is the teaching one');
|
||||
const p = PROBLEMS.find((x) => x.id === 'asm-two-pointers');
|
||||
const { session, tr, raw } = traceOf(p, 'realistic+paging');
|
||||
assert.equal(tr.raw.machine, 'realistic+paging');
|
||||
const hw = hardwareFor(raw);
|
||||
assert.equal(hw.config.caches.l1d.line, 64, 'the views see the realistic machine');
|
||||
assert.ok(hw.config.paging.enabled, 'and its virtual memory');
|
||||
assert.ok(hw.memory().steps.some((r) => r.translations.length), 'addresses are translated');
|
||||
session.state.machine = 'teaching';
|
||||
assert.notEqual(session.trace(), tr, 'a new machine is a new run');
|
||||
assert.equal(hardwareFor(session.trace().raw.trace).config.paging.enabled, false);
|
||||
});
|
||||
|
||||
test('time: the pipeline, micro-op, out-of-order and encoding data the Pipeline and Whole chip presets draw', () => {
|
||||
for (const p of WITH_ASM) for (const machine of ['teaching', 'realistic']) {
|
||||
const { raw } = traceOf(p, machine);
|
||||
const hw = hardwareFor(raw);
|
||||
const pipe = hw.pipeline();
|
||||
const core = hw.core();
|
||||
assert.equal(pipe.rows.length >= raw.count, true, `${p.id}: a pipeline row per instruction run (and any wrong-path fetches)`);
|
||||
for (const r of pipe.rows.slice(0, 200)) {
|
||||
for (const st of STAGES) assert.equal(stageOccupancy(pipe, r.E[st])[st] != null, true, `${p.id}: ${st} is occupied when a row enters it`);
|
||||
}
|
||||
for (let c = 0; c <= core.cycles; c += Math.max(1, Math.floor(core.cycles / 50))) {
|
||||
const at = coreAt(core, c);
|
||||
assert.ok(at.rob.length <= hw.config.core.rob, `${p.id} cycle ${c}: the reorder buffer never holds more than it has room for`);
|
||||
}
|
||||
for (const ins of raw.program.instrs) { const u = decompose(ins); assert.ok(Array.isArray(u) && u.length >= 1, `${p.id}: ${ins.text} splits into micro-ops`); }
|
||||
// the encoding view and the listing's bytes need the program laid out in memory
|
||||
if (raw.layout?.ok) for (const ins of raw.program.instrs) assert.ok(raw.layout.len[ins.index] >= 1 && raw.layout.len[ins.index] <= 15, `${p.id}: ${ins.text} is 1 to 15 bytes`);
|
||||
}
|
||||
assert.ok(WITH_ASM.some((p) => traceOf(p).raw.layout?.ok), 'the problems encode');
|
||||
});
|
||||
@@ -0,0 +1,269 @@
|
||||
// The Mojo corpus as the app sees it: the generated modules agree with mojo/pin.json
|
||||
// and the harvested corpus, and the Python pipeline's own tests pass.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { MOJO_VERSION, GODBOLT_BASE, GODBOLT_COMPILER, MOJO_SOURCES } from '../dist/mojo/generated/pin.js';
|
||||
import { MOJO_KEYWORDS, MOJO_SOFT_KEYWORDS, MOJO_REMOVED_WORDS, MOJO_DECORATORS, MOJO_PRELUDE, MOJO_PUNCTUATION } from '../dist/mojo/generated/tokens.js';
|
||||
import { Workspace } from '../dist/common/workspace.js';
|
||||
import { PROBLEMS, problemById, workForProblem } from '../dist/common/problems.js';
|
||||
|
||||
const pin = JSON.parse(fs.readFileSync(new URL('../mojo/pin.json', import.meta.url), 'utf8'));
|
||||
|
||||
test('the generated pin is mojo/pin.json', () => {
|
||||
assert.equal(MOJO_VERSION, pin.mojo.version);
|
||||
assert.equal(GODBOLT_BASE, pin.godbolt.base);
|
||||
assert.equal(GODBOLT_COMPILER, pin.godbolt.compiler);
|
||||
assert.deepEqual(Object.keys(MOJO_SOURCES).sort(), Object.keys(pin.sources).sort());
|
||||
});
|
||||
|
||||
test('the generated words are the 1.1.0 language', () => {
|
||||
for (const w of ['def', 'struct', 'trait', 'var', 'ref', 'comptime', 'raise', 'Self']) assert.ok(MOJO_KEYWORDS.includes(w), w);
|
||||
assert.ok(!MOJO_KEYWORDS.includes('fn'), 'fn is removed in 1.1.0, not a keyword to highlight as valid');
|
||||
assert.equal(MOJO_REMOVED_WORDS.fn, 'def');
|
||||
assert.equal(MOJO_REMOVED_WORDS.read, 'imm');
|
||||
for (const w of ['imm', 'mut', 'out', 'deinit']) assert.ok(MOJO_SOFT_KEYWORDS.includes(w), w);
|
||||
for (const d of ['fieldwise_init', 'always_inline', 'export']) assert.ok(MOJO_DECORATORS.includes(d), d);
|
||||
for (const n of ['Int', 'String', 'List', 'Dict', 'Optional', 'print', 'input', 'range', 'len']) assert.ok(MOJO_PRELUDE.includes(n), n);
|
||||
assert.ok(MOJO_PUNCTUATION.indexOf('**=') < MOJO_PUNCTUATION.indexOf('**'), 'longest spellings first');
|
||||
});
|
||||
|
||||
const py = spawnSync('python3', ['--version']);
|
||||
test('the corpus pipeline tests pass (python3)', { skip: py.status !== 0 ? 'python3 is not installed' : false }, () => {
|
||||
const r = spawnSync('python3', ['-m', 'unittest', 'discover', '-s', 'scripts/mojo/tests'], { encoding: 'utf8', cwd: new URL('..', import.meta.url).pathname });
|
||||
assert.equal(r.status, 0, r.stderr.split('\n').slice(-30).join('\n'));
|
||||
});
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
* Stage 1: the Mojo pane. Wherever possible these use godbolt's real answers
|
||||
* (mojo/golden), so they test against what the compiler said, not what we assume.
|
||||
* ------------------------------------------------------------------------- */
|
||||
import { tokenizeMojo } from '../dist/mojo/tokenize.js';
|
||||
import { removedSyntax } from '../dist/mojo/check.js';
|
||||
import { nextIndent } from '../dist/mojo/editing.js';
|
||||
import { mojoRequestBody, mojoRequestUrl, normaliseAnswer, compilerDiagnostics, listingFunctions, demangle, sourceOf as lineSource, BUILD_ARGS } from '../dist/services/godbolt.js';
|
||||
import { intelLine, labelMap, forSimulator } from '../dist/mojo/att.js';
|
||||
import { parseAsm, runAsmProgram } from '../dist/services/asm.js';
|
||||
import { runMojo } from '../dist/mojo/interp.js';
|
||||
import { parseModule } from '../dist/mojo/parse.js';
|
||||
import { MOJO_PROGRAMS } from '../dist/mojo/generated/programs.js';
|
||||
|
||||
const ROOT = new URL('..', import.meta.url).pathname;
|
||||
const goldens = fs.readdirSync(new URL('../mojo/golden/', import.meta.url)).filter((f) => /^[0-9a-f]{64}\.json$/.test(f))
|
||||
.map((f) => JSON.parse(fs.readFileSync(new URL(`../mojo/golden/${f}`, import.meta.url), 'utf8')));
|
||||
/** godbolt's answer for one corpus item, rebuilt as the raw JSON the browser receives. */
|
||||
function answerFor(item) {
|
||||
const g = goldens.find((x) => x.firstItem === item);
|
||||
assert.ok(g, `no golden for ${item}; run pixi run mojo-verify`);
|
||||
const source = (a) => a.line ? { line: a.line, ...('file' in a ? { file: a.file } : {}), ...('main' in a ? { mainsource: a.main } : {}) } : null;
|
||||
return { golden: g, raw: { ...g.raw, asm: (g.result.asm || []).map((a) => ({ text: a.text, source: source(a) })) } };
|
||||
}
|
||||
const sourceOf = (item) => fs.readFileSync(new URL(`../mojo/${item.replace('probes/', 'probes/')}.mojo`, import.meta.url), 'utf8');
|
||||
function applyFix(src, f) {
|
||||
const lines = src.split('\n'); const l = lines[f.line - 1];
|
||||
lines[f.line - 1] = l.slice(0, f.col - 1) + f.text + l.slice(f.endCol == null ? l.length : f.endCol - 1);
|
||||
return lines.join('\n');
|
||||
}
|
||||
const kinds = (line) => tokenizeMojo(line)[0].filter((t) => t.cls).map((t) => `${t.cls.replace('tok-', '')}:${t.text}`);
|
||||
|
||||
test('highlighting agrees with the Mojo grammar\'s own tests', () => {
|
||||
const { cases } = JSON.parse(fs.readFileSync(new URL('../mojo/corpus/syntax/cases.json', import.meta.url), 'utf8'));
|
||||
assert.ok(cases.length >= 20);
|
||||
for (const c of cases) {
|
||||
const toks = tokenizeMojo(c.text)[0];
|
||||
let at = 0; const hit = toks.find((t) => { const ok = c.start >= at && c.start < at + t.text.length; at += t.text.length; return ok; });
|
||||
const isKeyword = hit?.cls === 'tok-keyword';
|
||||
const wantsKeyword = c.scopes.some((x) => /^(keyword|storage)\./.test(x));
|
||||
// syntax 1.1.0 removed (alias) is not a keyword any more, whatever the grammar says
|
||||
const expected = c.dialect?.older ? false : wantsKeyword;
|
||||
assert.equal(isKeyword, expected, `${c.file}:${c.line} ${JSON.stringify(c.slice)} in ${JSON.stringify(c.text)} wants ${c.scopes.join(' ')}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('highlighting: docstrings span lines, ^ transfers or XORs, conventions are ownership words', () => {
|
||||
const doc = tokenizeMojo('def f():\n """One\n two."""\n return 1');
|
||||
assert.ok(doc[1].some((t) => t.cls === 'tok-string') && doc[2].every((t) => !t.text.trim() || t.cls === 'tok-string'));
|
||||
assert.ok(doc[3].some((t) => t.cls === 'tok-keyword' && t.text === 'return'));
|
||||
assert.ok(kinds('consume(b^, c)').includes('transfer:^'));
|
||||
assert.ok(kinds('var b = a^').includes('transfer:^'));
|
||||
assert.ok(kinds('var m = f ^ 0xFF').includes('op:^'));
|
||||
assert.deepEqual(kinds('def g(mut self, var x: Int, deinit other: T):').filter((k) => k.startsWith('convention')), ['convention:mut', 'convention:var', 'convention:deinit']);
|
||||
assert.ok(kinds(' var name: String').includes('keyword:var'), 'a field declaration is not a convention');
|
||||
assert.ok(kinds('def h(read x: Int):').includes('error:read'));
|
||||
assert.ok(kinds('var data = file.read()').includes('name:read'), 'read is only an error as a convention');
|
||||
assert.ok(kinds('fn old():').includes('error:fn'));
|
||||
assert.ok(kinds('@fieldwise_init').includes('label:fieldwise_init'));
|
||||
assert.ok(kinds('print(t"n={n * 2}")').includes('name:n'), 't-string interpolations highlight as code');
|
||||
});
|
||||
|
||||
test('removed syntax is caught before compiling, in the compiler\'s words, with its fix', () => {
|
||||
const src = 'fn main():\n show(1)\n\ndef show(read x: Int):\n print(x)\n';
|
||||
const ds = removedSyntax(src);
|
||||
assert.deepEqual(ds.map((d) => [d.line, d.message]), [[1, "'fn' has been removed; use 'def' instead"], [4, "'read' was removed; use 'imm'"]]);
|
||||
let fixed = src;
|
||||
for (const d of [...ds].reverse()) fixed = applyFix(fixed, d.fix);
|
||||
assert.equal(fixed, 'def main():\n show(1)\n\ndef show(imm x: Int):\n print(x)\n');
|
||||
assert.deepEqual(removedSyntax(fixed), []);
|
||||
// and it is exactly what the real compiler said about the fn probe
|
||||
const real = compilerDiagnostics(goldens.find((g) => g.firstItem === 'probes/dialect-fn').result.buildStderr);
|
||||
assert.equal(real[0].message, ds[0].message);
|
||||
const realRead = compilerDiagnostics(goldens.find((g) => g.firstItem === 'probes/dialect-read').result.buildStderr);
|
||||
assert.equal(realRead[0].message, ds[1].message);
|
||||
});
|
||||
|
||||
test('Enter indents after a block opener and dedents after return', () => {
|
||||
assert.equal(nextIndent('def f(x: Int) -> Int:', ' '), ' ');
|
||||
assert.equal(nextIndent(' comptime for i in range(3):', ' '), ' ');
|
||||
assert.equal(nextIndent(' return x # done', ' '), ' ');
|
||||
assert.equal(nextIndent(' var y = 1', ' '), ' ');
|
||||
});
|
||||
|
||||
test('the Compile button asks godbolt exactly what the corpus harness asks', () => {
|
||||
const src = 'def main():\n print(input())\n';
|
||||
const py = spawnSync('python3', ['-c', `import sys, json; sys.path.insert(0, 'scripts/mojo')\nfrom mojocorpus import godbolt\nprint(json.dumps(godbolt.request_body(${JSON.stringify(src)}, 'both', '7\\n', '-O0')))`], { encoding: 'utf8', cwd: ROOT });
|
||||
if (py.status !== 0) return; // no python3 here; the pipeline tests cover the Python side
|
||||
assert.deepEqual(mojoRequestBody(src, '7\n', '-O0'), JSON.parse(py.stdout));
|
||||
assert.equal(mojoRequestUrl(), `${pin.godbolt.base}/api/compiler/${pin.godbolt.compiler}/compile`);
|
||||
});
|
||||
|
||||
test('compiler errors land on their lines, and its fix-its become one-click fixes', () => {
|
||||
// The probes were asked in run mode, where errors come in buildResult; the button's mode puts them in stderr. Same text.
|
||||
const stderrOf = (item) => goldens.find((g) => g.firstItem === item).result.buildStderr;
|
||||
const fnDiag = compilerDiagnostics(stderrOf('probes/dialect-fn'));
|
||||
assert.equal(fnDiag[0].line, 3);
|
||||
assert.equal(applyFix(sourceOf('probes/dialect-fn'), fnDiag[0].fix).split('\n')[2], 'def main():');
|
||||
const copy = compilerDiagnostics(stderrOf('probes/check-implicit-copy'));
|
||||
const err = copy.find((d) => d.severity === 'error');
|
||||
assert.match(err.message, /cannot be implicitly copied/);
|
||||
assert.equal(err.origin, 'the Mojo 1.1.0 compiler');
|
||||
const fixes = err.question.options.map((o) => applyFix(sourceOf('probes/check-implicit-copy'), o).split('\n')[err.line - 1].trim());
|
||||
assert.deepEqual(fixes, ['var b = a^', 'var b = a.copy()']);
|
||||
const alias = compilerDiagnostics(stderrOf('probes/check-aliasing'));
|
||||
assert.match(alias[0].message, /aliasing values passed mutably to 's' argument/);
|
||||
assert.ok(alias.slice(1).every((d) => d.severity === 'note'));
|
||||
assert.deepEqual(compilerDiagnostics(stderrOf('probes/check-use-after-move')).map((d) => [d.severity, d.message]),
|
||||
[['error', "use of uninitialized value 'a'"], ['note', "'a' declared here"]]);
|
||||
});
|
||||
|
||||
test('the real listing of add, translated to Intel, runs on the model machine', () => {
|
||||
const ans = normaliseAnswer(answerFor('probes/godbolt-opt-O0').raw);
|
||||
const fns = listingFunctions(ans.asm);
|
||||
assert.deepEqual(fns.filter((f) => f.kind === 'user').map((f) => f.name), ['add(Int, Int)', 'main()']);
|
||||
assert.deepEqual(fns.filter((f) => f.kind === 'entry').map((f) => f.name), ['main']);
|
||||
const add = fns.find((f) => f.name === 'add(Int, Int)');
|
||||
const sim = forSimulator(fns, add);
|
||||
assert.deepEqual(sim.source.split('\n').filter((l) => l.trim() && !l.trim().endsWith(':') && !l.includes(';')).map((l) => l.trim()), ['mov rax, rdi', 'add rax, rsi', 'ret']);
|
||||
const run = runAsmProgram(parseAsm(sim.source), { setup: 'rdi = 2\nrsi = 3' });
|
||||
assert.ok(!run.error, run.error?.message);
|
||||
assert.equal(run.output.at(-1), 'rax = 5 (0x5)');
|
||||
// main calls print, which the model machine cannot run: it assembles with a stub for print, steps up to the call, and stops there saying so
|
||||
const main = forSimulator(fns, fns.find((f) => f.name === 'main()'));
|
||||
assert.ok(main.refusedCalls.some((c) => /print/.test(c)));
|
||||
const mp = parseAsm(main.source);
|
||||
assert.ok(mp.ok, mp.diagnostics.map((d) => d.message).join('; '));
|
||||
const mr = runAsmProgram(mp, { setup: main.data.join('\n') });
|
||||
assert.ok(mr.count > 5, 'main steps its own instructions before the call');
|
||||
assert.match(mr.error.message, /print: standard library, not on the model machine/);
|
||||
});
|
||||
|
||||
test('the optimized listing keeps no function of the user\'s, and one request returned listing and output', () => {
|
||||
const ans = normaliseAnswer(answerFor('probes/godbolt-asm-and-run').raw);
|
||||
assert.equal(ans.stdout, '5');
|
||||
assert.ok(ans.asm.length > 0 && ans.compiled && ans.executed && ans.exitCode === 0);
|
||||
assert.deepEqual(listingFunctions(ans.asm).filter((f) => f.kind === 'user'), []);
|
||||
});
|
||||
|
||||
test('AT&T to Intel: operands reverse, sizes become ptr, names become labels', () => {
|
||||
const m = labelMap([{ label: '"example::add(::SIMD[DType.int, 1],::SIMD[DType.int, 1])"', name: 'add(Int, Int)', kind: 'user', lines: [] }]);
|
||||
const cases = [
|
||||
['movq %rdi, 16(%rsp)', 'mov qword ptr [rsp + 16], rdi'],
|
||||
['movl $0, -4(%rbp)', 'mov dword ptr [rbp - 4], 0'],
|
||||
['movzbl (%rdi,%rcx), %eax', 'movzx eax, byte ptr [rdi + rcx*1]'],
|
||||
['movslq 8(%rsi,%rax,4), %rdx', 'movsxd rdx, dword ptr [rsi + rax*4 + 8]'],
|
||||
['leaq static_string_ab(%rip), %rax', 'lea rax, [rip + static_string_ab]'],
|
||||
['imulq $3, %rsi, %rax', 'imul rax, rsi, 3'],
|
||||
['cmovneq %rcx, %rax', 'cmovne rax, rcx'],
|
||||
['callq "example::add(::SIMD[DType.int, 1],::SIMD[DType.int, 1])"@PLT', 'call add'],
|
||||
['jne .LBB2_2', 'jne .LBB2_2'],
|
||||
['retq', 'ret'],
|
||||
['cqto', 'cqo'],
|
||||
['.cfi_startproc', null],
|
||||
];
|
||||
for (const [att, intel] of cases) assert.equal(intelLine(att, m), intel, att);
|
||||
assert.equal(demangle('"example::add(::SIMD[DType.int, 1],::SIMD[DType.float64, 1])"'), 'add(Int, Float64)');
|
||||
});
|
||||
|
||||
test('an exercise\'s Mojo is a verified program from the corpus', () => {
|
||||
assert.equal(MOJO_PROGRAMS['count-base'].verified, true);
|
||||
const p = PROBLEMS.find((x) => x.id === 'count-base');
|
||||
assert.equal(p.mojo.id, 'count-base');
|
||||
assert.equal(p.sources.mojo, MOJO_PROGRAMS['count-base'].source);
|
||||
assert.ok(workForProblem(p).sources.mojo, 'the state carries the exercise\'s Mojo');
|
||||
for (const q of PROBLEMS) if (q.mojo) assert.ok(MOJO_PROGRAMS[q.mojo.id], `${q.id} names a Mojo program that does not exist`);
|
||||
// every exercise with pseudo has its Mojo too, so the Mojo/pseudo switch always has both sides
|
||||
for (const q of PROBLEMS) if (q.sources.pseudo) assert.ok(q.mojo, `${q.id} has pseudo but no Mojo program`);
|
||||
});
|
||||
|
||||
test('each exercise\'s Mojo prints, in the interpreter, what the exercise expects of the pseudo', () => {
|
||||
const norm = (s) => s.trim().replace(/^"(.*)"$/, '$1').replace(/^TRUE$/, 'True').replace(/^FALSE$/, 'False');
|
||||
for (const q of PROBLEMS) {
|
||||
if (!q.mojo || !q.expect) continue;
|
||||
const r = runMojo(parseModule(q.mojo.source), q.mojo.source, { maxSteps: 200000, record: false });
|
||||
if (r.refused) continue; // the stepper says why; the compiler is the judge
|
||||
assert.equal(norm(r.stdout), norm(q.expect), `${q.id}: its Mojo printed ${JSON.stringify(r.stdout)}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('the Compile button builds with exactly the flags a passing probe verified', () => {
|
||||
const text = fs.readFileSync(new URL('../mojo/probes/godbolt-compile-button.mojo', import.meta.url), 'utf8');
|
||||
const args = /^# args: (.*)$/m.exec(text)[1].trim();
|
||||
assert.equal(BUILD_ARGS.O0, args, 'change the probe and re-verify before changing the button');
|
||||
const g = goldens.find((x) => x.firstItem === 'probes/godbolt-compile-button');
|
||||
if (!g) return; // a checkout without that golden; the corpus tests cover it
|
||||
assert.equal(g.result.compiled && g.result.executed && g.result.exitCode, 0);
|
||||
assert.equal(g.result.stdout.trim(), '5');
|
||||
});
|
||||
|
||||
test('a source line is the program\'s only when godbolt says it comes from the program\'s file', () => {
|
||||
assert.deepEqual(lineSource({ line: 10, file: null }), { line: 10 });
|
||||
assert.deepEqual(lineSource({ line: 10 }), { line: 10 });
|
||||
assert.deepEqual(lineSource({ line: 10, file: '/app/example.mojo' }), { line: 10 });
|
||||
assert.deepEqual(lineSource({ line: 10, file: 'other', mainsource: true }), { line: 10 });
|
||||
assert.deepEqual(lineSource({ line: 218, file: '/opt/mojo/lib/std/io/io.mojo' }), { line: null, from: { file: 'io.mojo', line: 218 } });
|
||||
assert.deepEqual(lineSource({ line: 218, file: null, mainsource: false }), { line: null, from: { file: '?', line: 218 } });
|
||||
assert.deepEqual(lineSource(null), { line: null });
|
||||
});
|
||||
|
||||
test('with line tables, the program\'s own instructions point at the program\'s own lines', (t) => {
|
||||
const g = goldens.find((x) => x.firstItem === 'probes/godbolt-compile-button');
|
||||
if (!g) return t.skip('no golden for probes/godbolt-compile-button');
|
||||
const marked = (g.result.asm || []).some((a) => 'file' in a || 'main' in a);
|
||||
if (!marked) return t.skip("this golden predates file marking; run: pixi run mojo-verify-item 'probes/godbolt-*'");
|
||||
const fns = listingFunctions(normaliseAnswer(answerFor('probes/godbolt-compile-button').raw).asm);
|
||||
const lines = (name) => [...new Set(fns.find((f) => f.name === name).lines.map((l) => l.line).filter((x) => x != null))];
|
||||
assert.deepEqual(lines('add(Int, Int)'), [5, 6]);
|
||||
assert.deepEqual(lines('main()').sort(), [10, 9].sort());
|
||||
assert.ok(fns.find((f) => f.name === 'main()').lines.some((l) => l.from && l.from.file.endsWith('.mojo')), 'print\'s inlined defaults are marked as library code');
|
||||
});
|
||||
|
||||
test('Stage 6: a function\'s calls into the standard library are named, from the real listing', async () => {
|
||||
const g = goldens.find((x) => x.firstItem === 'probes/godbolt-compile-button');
|
||||
if (!g) return;
|
||||
const { libraryCalls } = await import('../dist/ui/views/compiler.js').catch(() => ({ libraryCalls: null }));
|
||||
if (!libraryCalls) return; // the view needs a DOM to load; covered by the browser check
|
||||
const fns = listingFunctions(normaliseAnswer(answerFor('probes/godbolt-compile-button').raw).asm);
|
||||
assert.deepEqual(libraryCalls(fns.find((f) => f.name === 'main()')), ['print (std.io.io)']);
|
||||
assert.deepEqual(libraryCalls(fns.find((f) => f.name === 'add(Int, Int)')), []);
|
||||
});
|
||||
|
||||
test('Stage 6b: code sent to the x86-64 pane keeps each instruction\'s Mojo line', async () => {
|
||||
const g = goldens.find((x) => x.firstItem === 'probes/godbolt-compile-button');
|
||||
if (!g) return;
|
||||
const { forSimulator } = await import('../dist/mojo/att.js');
|
||||
const fns = listingFunctions(normaliseAnswer(answerFor('probes/godbolt-compile-button').raw).asm);
|
||||
const { source } = forSimulator(fns, fns.find((f) => f.name === 'add(Int, Int)'));
|
||||
const marks = source.split('\n').filter((l) => /; mojo line \d+/.test(l)).map((l) => Number(/; mojo line (\d+)/.exec(l)[1]));
|
||||
assert.deepEqual([...new Set(marks)], [5, 6], 'the instructions of add carry lines 5 and 6');
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@ import path from 'node:path';
|
||||
import { studyOf, runPseudo } from '../dist/services/pseudo.js';
|
||||
import { verify } from '../dist/engines/pseudo/vcgen.js';
|
||||
import { checkProperties } from '../dist/engines/pseudo/testing.js';
|
||||
import { PROBLEMS } from '../dist/core/problems.js';
|
||||
import { PROBLEMS } from '../dist/common/problems.js';
|
||||
import { LESSONS, solutionOf } from '../dist/curriculum/index.js';
|
||||
|
||||
const PROVER_DIR = 'tests/prover';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// The reference is only trustworthy if its examples run through the real parsers.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { REFERENCE, PSEUDO_REF, LINGO_REF, SPECO_REF, ASM_REF, MATHO_REF, explain, SPECO_SYMBOLS } from '../dist/core/reference.js';
|
||||
import { REFERENCE, PSEUDO_REF, LINGO_REF, SPECO_REF, ASM_REF, MATHO_REF, explain, SPECO_SYMBOLS } from '../dist/common/reference.js';
|
||||
import { parseMatho } from '../dist/services/matho.js';
|
||||
import { studyOf } from '../dist/services/pseudo.js';
|
||||
import { readLingo } from '../dist/services/lingo.js';
|
||||
|
||||
@@ -3,15 +3,14 @@
|
||||
// interpreters' own traces for every exercise, in pseudo and in Mojo.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { Session } from '../dist/core/session.js';
|
||||
import { PROBLEMS, stateForProblem, problemById } from '../dist/core/catalog.js';
|
||||
import { runColumns, runRows, defaultFollow, valuesAt, rulerCells, gridCells } from '../dist/core/runview.js';
|
||||
import { runColumns, runRows, defaultFollow, valuesAt, rulerCells, gridCells } from '../dist/common/runview.js';
|
||||
import { Workspace } from '../dist/common/workspace.js';
|
||||
import { PROBLEMS, problemById, workForProblem } from '../dist/common/problems.js';
|
||||
|
||||
globalThis.localStorage = { getItem() { return null; }, setItem() { }, removeItem() { } };
|
||||
|
||||
const traceOf = (p, lang) => {
|
||||
const st = stateForProblem(p); st.lang = lang;
|
||||
const s = new Session(st, { area: lang === 'mojo' ? 'dev' : null, storageId: null });
|
||||
const st = workForProblem(p); st.lang = lang;
|
||||
const s = new Workspace(st);
|
||||
return s.trace();
|
||||
};
|
||||
const RUNS = [];
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
// Runs against the compiled output: `npm test` builds first.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { toAscii, toMath, parseSpec, weave, extractSpec } from '../dist/services/speco.js';
|
||||
import { studyOf, runPseudo, provePseudo } from '../dist/services/pseudo.js';
|
||||
import { readLingo, runLingo } from '../dist/services/lingo.js';
|
||||
import { parseAsm, runAsmProgram, parseSetup } from '../dist/services/asm.js';
|
||||
import { Workspace } from '../dist/common/workspace.js';
|
||||
import { PROBLEMS, problemById, workForProblem } from '../dist/common/problems.js';
|
||||
|
||||
|
||||
test('every catalog problem parses, runs, and (where it has pseudocode) proves without throwing', () => {
|
||||
for (const p of PROBLEMS) {
|
||||
const s = new Workspace(workForProblem(p));
|
||||
s.allDiagnostics();
|
||||
const tr = s.trace();
|
||||
const empty = !Object.values(p.sources).some((src) => src && src.trim());
|
||||
if (p.id !== 'five-bugs' && !empty) assert.ok(tr, `${p.id} produced no trace: ${s.runError}`);
|
||||
if (p.sources.pseudo || p.sources.lingo) { s.proof(); s.tests(); }
|
||||
}
|
||||
});
|
||||
|
||||
test('the known-good examples give the lesson answers', () => {
|
||||
const by = Object.fromEntries(PROBLEMS.map((p) => [p.id, p]));
|
||||
const last = (id, lang) => { const st = workForProblem(by[id]); if (lang) st.lang = lang; const s = new Workspace(st); return s.trace().output.at(-1); };
|
||||
assert.equal(last('count-base', 'pseudo'), 'COUNT_BASE returned 3');
|
||||
assert.equal(last('count-base', 'lingo'), 'COUNT_BASES returned 3');
|
||||
assert.equal(last('match', 'pseudo'), 'MATCH returned [1]');
|
||||
assert.equal(last('revcomp', 'pseudo'), 'REVERSE_COMPLEMENT returned "TGTAATC"');
|
||||
assert.match(last('asm-first-instructions'), /^rax = 6/);
|
||||
});
|
||||
|
||||
test('the off-by-one bug is caught by the run, the tests, and the proof', () => {
|
||||
const st = workForProblem(PROBLEMS.find((p) => p.id === 'match-off-by-one')); st.lang = 'pseudo';
|
||||
const s = new Workspace(st);
|
||||
assert.equal(s.trace().error.kind, 'index');
|
||||
assert.ok(s.tests().some((t) => t.failures.length > 0));
|
||||
assert.ok(s.proof().report.counts.broken >= 1);
|
||||
});
|
||||
|
||||
test('speco: math notation lowers to the pseudocode spelling and back', () => {
|
||||
assert.equal(toAscii('result = |{ k ∈ [0, |T|) : T[k] = B }|'), 'RESULT == LENGTH({ k IN [0, LENGTH(T)) : T[k] == B })');
|
||||
assert.equal(toAscii('∀ K ∈ [0, M) : A[K] ≤ B ∧ ¬ (X ≠ Y)'), 'FORALL K IN [0, M) : A[K] <= B AND NOT (X != Y)');
|
||||
assert.equal(toMath('RESULT == LENGTH({ K IN [0, LENGTH(T)) : T[K] == B })'), 'result = |{ K ∈ [0, |T|) : T[K] = B }|');
|
||||
assert.equal(toAscii(toMath('FORALL K IN [0, J) : T[I + K] == P[K]')), 'FORALL K IN [0, J) : T[I + K] == P[K]');
|
||||
});
|
||||
|
||||
test('speco: a spec written separately weaves in, proves, and does not duplicate what is already there', () => {
|
||||
const pseudo = PROBLEMS.find((p) => p.id === 'count-base').sources.pseudo;
|
||||
const spec = parseSpec(`SPEC COUNT_BASE(B, T)\n ENSURE result = |{ K ∈ [0, |T|) : T[K] = B }|\n LOOP FOR I\n INVARIANT Total = |{ K ∈ [0, I) : T[K] = B }|`);
|
||||
assert.equal(spec.diagnostics.length, 0);
|
||||
const w = weave(pseudo, spec);
|
||||
assert.equal(w.diagnostics.length, 0);
|
||||
assert.match(w.source, /FUNCTION COUNT_BASE[^\n]*\n\s+ENSURE RESULT == LENGTH/);
|
||||
assert.match(w.source, /FOR I <- 0 TO N\n\s+INVARIANT Total == LENGTH/);
|
||||
const st = studyOf(w.source);
|
||||
assert.ok(st.ok, st.diagnostics.map((d) => d.message).join('; '));
|
||||
const pr = provePseudo(st);
|
||||
assert.equal(pr.counts.open + pr.counts.broken, 0, JSON.stringify(pr.counts));
|
||||
assert.ok(pr.counts.proved >= 3);
|
||||
// weaving the same spec again adds nothing
|
||||
const again = weave(w.source, spec);
|
||||
assert.equal(again.source, w.source);
|
||||
// and extracting it back gives a spec that round-trips
|
||||
const ex = extractSpec(w.source);
|
||||
assert.match(ex, /^SPEC COUNT_BASE\(B, T\)/);
|
||||
assert.equal(weave(pseudo, parseSpec(ex)).source, w.source);
|
||||
});
|
||||
|
||||
test('speco: a spec for a routine that does not exist is reported, not silently dropped', () => {
|
||||
const w = weave('FUNCTION F() RETURNS INTEGER\n RETURN 1\nENDFUNCTION', parseSpec('SPEC G()\n ENSURE RESULT == 1'));
|
||||
assert.equal(w.diagnostics.length, 1);
|
||||
assert.equal(w.diagnostics[0].id, 'no-routine');
|
||||
});
|
||||
|
||||
test('lingo: English steps lower, run, and report English line numbers', () => {
|
||||
const r = readLingo('To count the G bases in T:\n Start with Count at 0.\n For each letter b of T:\n If b is \'G\', add 1 to Count.\n The answer is Count.\n');
|
||||
assert.ok(r.ok, r.diagnostics.map((d) => d.message).join('; '));
|
||||
const tr = runLingo(r, { call: 'COUNT_BASE("GGA")' }); // a call aimed at another routine is re-aimed
|
||||
assert.equal(tr.output.at(-1), 'COUNT_G_BASES returned 2');
|
||||
assert.ok(tr.steps.every((s) => s.line == null || s.line <= 5), 'steps carry English lines');
|
||||
});
|
||||
|
||||
test('lingo: an ambiguous range asks a question with two rewrites', () => {
|
||||
const r = readLingo('To count in T:\n Start with Count at 0.\n For each i from 0 to the length of T:\n Add 1 to Count.\n The answer is Count.\n');
|
||||
const q = r.diagnostics.find((d) => d.id === 'range-ends');
|
||||
assert.ok(q && q.question && q.question.options.length === 2);
|
||||
assert.match(q.question.options[0].text, /up to but not including/);
|
||||
});
|
||||
|
||||
test('asm: setup lines, assembly errors, and a run', () => {
|
||||
const setup = parseSetup('rdi = 0x1000\nrsi = 7\ndl = \'A\'\nmemory 0x1000 "GATTACA"\nflags CF');
|
||||
assert.equal(setup.registers.rdi, 0x1000n); assert.equal(setup.registers.dl, 65n); assert.equal(setup.memory[0].text, 'GATTACA'); assert.equal(setup.flags.CF, true);
|
||||
const bad = parseAsm(' mov rax, [rbx], [rcx]\n');
|
||||
assert.equal(bad.ok, false); assert.equal(bad.diagnostics[0].line, 1);
|
||||
const good = parseAsm(' mov eax, 40\n add eax, 2\n ret\n');
|
||||
const tr = runAsmProgram(good, {});
|
||||
assert.equal(tr.count, 3);
|
||||
assert.match(tr.output.at(-1), /rax = 42/);
|
||||
});
|
||||
@@ -0,0 +1,242 @@
|
||||
// Stage 8: the sync hub (restructure plan, section 2.3), without any UI. Pseudo is the hub; the pane that is
|
||||
// edited is the authority and is never rewritten; an authority with errors changes nothing; a language that
|
||||
// cannot say the program goes stale rather than blank; contracts ride along; opening rewrites nothing; and the
|
||||
// whole cascade is fast enough that typing stays instant.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { SyncHub, LINKED, namesFromMatho } from '../dist/sync/hub.js';
|
||||
import { pseudoToLingo } from '../dist/sync/pseudo-to-lingo.js';
|
||||
import { checkMojo } from '../dist/mojo/check.js';
|
||||
import { studyOf } from '../dist/services/pseudo.js';
|
||||
import { EQUATIONS, FIXTURES } from './helpers/sync-programs.mjs';
|
||||
import { Workspace } from '../dist/common/workspace.js';
|
||||
import { PROBLEMS, problemById, workForProblem } from '../dist/common/problems.js';
|
||||
|
||||
|
||||
const sync = (r) => ({ authority: r.authority, stale: r.stale, names: r.names });
|
||||
const next = (r, lang, text) => new SyncHub(r.sources, sync(r)).edit(lang, text);
|
||||
|
||||
const COUNT = `FUNCTION COUNT_BASE(B : CHAR, T : STRING) RETURNS INTEGER
|
||||
DECLARE Total : INTEGER
|
||||
Total <- 0
|
||||
FOR EACH C IN T
|
||||
IF C == B THEN
|
||||
Total <- Total + 1
|
||||
ENDIF
|
||||
NEXT C
|
||||
RETURN Total
|
||||
ENDFUNCTION`;
|
||||
const SIMPLE = `FUNCTION SUMMED(N : INTEGER, X : LIST OF FLOAT) RETURNS FLOAT
|
||||
DECLARE S : FLOAT
|
||||
S <- 0.0
|
||||
FOR I <- 0 TO N
|
||||
S <- S + X[I]
|
||||
NEXT I
|
||||
RETURN S
|
||||
ENDFUNCTION`;
|
||||
const WHILE_PSEUDO = FIXTURES['fixture:div-mod'][0];
|
||||
|
||||
test('a lingo edit updates pseudo, matho and Mojo, and does not rewrite the lingo', () => {
|
||||
const mean = new SyncHub({}).edit('matho', EQUATIONS['mean'][0]);
|
||||
assert.ok(mean.sources.lingo.includes('Start with Total'), 'the equations also became English');
|
||||
const lingo = mean.sources.lingo.replace('The answer is 1 / N * Total.', 'The answer is 2 / N * Total.');
|
||||
const r = next(mean, 'lingo', lingo);
|
||||
assert.equal(r.authority, 'lingo');
|
||||
assert.equal(r.sources.lingo, lingo, 'the edited pane is exactly what was typed');
|
||||
assert.match(r.sources.pseudo, /RETURN 2 \/ N \* Total/);
|
||||
assert.match(r.sources.matho, /\\frac\{2\}\{n\}|2/, 'matho follows');
|
||||
assert.match(r.sources.matho, /\\sum/);
|
||||
assert.match(r.mojo.source, /Float64\(2\) \/ Float64\(n\) \* total/);
|
||||
assert.deepEqual(r.stale, {});
|
||||
assert.ok(r.changed.includes('pseudo') && r.changed.includes('matho') && !r.changed.includes('lingo'));
|
||||
});
|
||||
|
||||
test('a pseudo edit updates lingo', () => {
|
||||
const r0 = new SyncHub({}).edit('pseudo', SIMPLE);
|
||||
assert.match(r0.sources.lingo, /Start with S at 0\.0/);
|
||||
const r = next(r0, 'pseudo', SIMPLE.replace('S <- 0.0', 'S <- 2.0'));
|
||||
assert.match(r.sources.lingo, /Start with S at 2\.0/);
|
||||
assert.equal(r.sources.pseudo, SIMPLE.replace('S <- 0.0', 'S <- 2.0'));
|
||||
assert.equal(r.authority, 'pseudo');
|
||||
});
|
||||
|
||||
test('an edit in X never rewrites X, for every linked language', () => {
|
||||
const base = new SyncHub({}).edit('pseudo', SIMPLE);
|
||||
for (const lang of LINKED) {
|
||||
const text = base.sources[lang];
|
||||
if (!text) continue;
|
||||
const r = new SyncHub(base.sources, sync(base)).edit(lang, text + '\n');
|
||||
assert.equal(r.sources[lang], text + '\n', `${lang} is kept as typed, trailing blank line included`);
|
||||
}
|
||||
});
|
||||
|
||||
test('an error in the authority changes nothing: the others keep their last good text and say why', () => {
|
||||
const ok = new SyncHub({}).edit('pseudo', SIMPLE);
|
||||
const before = { ...ok.sources };
|
||||
const r = next(ok, 'lingo', 'Gibberish that is no sentence of lingo at all.');
|
||||
assert.equal(r.sources.lingo, 'Gibberish that is no sentence of lingo at all.');
|
||||
for (const l of ['pseudo', 'matho', 'speco']) assert.equal(r.sources[l] ?? '', before[l] ?? '', `${l} kept its text`);
|
||||
for (const l of ['pseudo', 'matho', 'speco']) assert.match(r.stale[l], /lingo line 1 does not read yet/);
|
||||
assert.equal(r.stale.lingo, undefined, 'the pane being typed in is not stale');
|
||||
// a pseudo with errors does the same
|
||||
const bad = next(ok, 'pseudo', 'FUNCTION BROKEN(\nRETURN');
|
||||
assert.match(bad.stale.lingo, /pseudo line \d+ does not read yet/);
|
||||
assert.equal(bad.sources.lingo, before.lingo);
|
||||
// and a good edit afterwards clears every mark
|
||||
const fixed = next(bad, 'pseudo', SIMPLE);
|
||||
assert.deepEqual(fixed.stale, {});
|
||||
});
|
||||
|
||||
test('matho goes stale, not blank, on a WHILE; a later expressible program brings it back', () => {
|
||||
const r0 = new SyncHub({}).edit('matho', EQUATIONS['mean'][0]);
|
||||
const matho = r0.sources.matho;
|
||||
const r = next(r0, 'pseudo', WHILE_PSEUDO);
|
||||
assert.equal(r.sources.matho, matho, 'matho keeps its last good text');
|
||||
assert.match(r.stale.matho, /matho has no form for a WHILE loop \(line \d+\)/);
|
||||
assert.equal(r.stale.lingo, undefined, 'lingo can say a WHILE');
|
||||
assert.match(r.sources.lingo, /\S/);
|
||||
const back = next(r, 'pseudo', SIMPLE);
|
||||
assert.equal(back.stale.matho, undefined);
|
||||
assert.notEqual(back.sources.matho, matho);
|
||||
});
|
||||
|
||||
test('contracts survive an edit in English or in equations', () => {
|
||||
const p = problemById('count-base-proved');
|
||||
const st = workForProblem(p);
|
||||
const filled = new SyncHub(st.sources).fill();
|
||||
const spec = filled.sources.speco;
|
||||
assert.match(spec, /ENSURE/);
|
||||
const r = next({ sources: filled.sources, authority: 'speco', stale: {}, names: {} }, 'lingo', filled.sources.lingo.replace('Add 1 to Total.', 'Add 2 to Total.'));
|
||||
assert.equal(r.sources.speco, spec, 'the speco is what it was');
|
||||
assert.match(r.sources.pseudo, /Total <- Total \+ 2/, 'the edit took');
|
||||
assert.match(r.sources.pseudo, /ENSURE RESULT == LENGTH/, 'the contract is woven into the pseudo the English lowered to');
|
||||
assert.match(r.sources.pseudo, /INVARIANT/);
|
||||
assert.match(r.mojo.source, /# ENSURE/, 'the translator carries the contract as a comment');
|
||||
// a claim about a routine the English no longer has is kept in the speco, not dropped
|
||||
const renamed = filled.sources.lingo.replace('To count base for B and T:', 'To tally base for B and T:');
|
||||
const r2 = next({ sources: filled.sources, authority: 'speco', stale: {}, names: {} }, 'lingo', renamed);
|
||||
assert.match(r2.sources.speco, /kept:/);
|
||||
assert.match(r2.sources.speco, /ENSURE/);
|
||||
});
|
||||
|
||||
test('an edit in speco puts its contracts into the pseudo, then lingo and matho follow', () => {
|
||||
const r0 = new SyncHub({}).edit('pseudo', SIMPLE);
|
||||
const spec = 'SPEC SUMMED(N, X)\n REQUIRE N >= 0\n';
|
||||
const r = next(r0, 'speco', spec);
|
||||
assert.equal(r.sources.speco, spec);
|
||||
assert.match(r.sources.pseudo, /REQUIRE N >= 0/);
|
||||
assert.equal(r.authority, 'speco');
|
||||
// replacing it replaces: the old REQUIRE is gone
|
||||
const r2 = next(r, 'speco', 'SPEC SUMMED(N, X)\n REQUIRE N >= 1\n');
|
||||
assert.match(r2.sources.pseudo, /REQUIRE N >= 1/);
|
||||
assert.doesNotMatch(r2.sources.pseudo, /REQUIRE N >= 0/);
|
||||
// a speco with a syntax error changes nothing
|
||||
const bad = next(r, 'speco', 'SPEC SUMMED(N, X\n REQUIRE ??\n');
|
||||
assert.equal(bad.sources.pseudo, r.sources.pseudo);
|
||||
assert.ok(bad.stale.pseudo);
|
||||
});
|
||||
|
||||
test('the student\'s spelling of equation names survives a trip through pseudo', () => {
|
||||
const r0 = new SyncHub({}).edit('matho', '\\overline{x} = \\frac{1}{n} \\sum_{i=0}^{n-1} x_i');
|
||||
assert.deepEqual(r0.names, { X_BAR: '\\overline{x}' });
|
||||
const r = next(r0, 'pseudo', r0.sources.pseudo.replace('RETURN 1 / N * Total', 'RETURN 2 / N * Total'));
|
||||
assert.match(r.sources.matho, /^\\overline\{x\} = /m);
|
||||
assert.deepEqual(namesFromMatho('f(x) = x + 1'), {}, 'a function written with its inputs is spelled by the generator');
|
||||
});
|
||||
|
||||
test('loading an authored exercise changes nothing until the first edit', () => {
|
||||
for (const p of PROBLEMS) {
|
||||
const st = workForProblem(p);
|
||||
const before = JSON.stringify(st.sources);
|
||||
const filled = new SyncHub(st.sources).fill();
|
||||
for (const l of [...LINKED, 'mojo', 'asm']) if ((st.sources[l] ?? '').trim()) assert.equal(filled.sources[l], st.sources[l], `${p.id}: authored ${l} is shown as written`);
|
||||
assert.equal(JSON.stringify(st.sources), before, `${p.id}: the state's own sources are untouched`);
|
||||
}
|
||||
// through the session: reading never writes, and nothing is saved or marked as edited
|
||||
const p = problemById('count-base');
|
||||
const s = new Workspace(workForProblem(p));
|
||||
const raw = JSON.stringify(s.state.sources);
|
||||
assert.match(s.source('lingo'), /\S/, 'a missing pane is shown, generated from the pseudo');
|
||||
s.parsedLingo(); s.derivedMojo(); s.lineMaps();
|
||||
assert.equal(JSON.stringify(s.state.sources), raw);
|
||||
assert.equal(s.state.sync, undefined);
|
||||
assert.equal(s.linkState('lingo').kind, 'authored');
|
||||
});
|
||||
|
||||
test('takeAuthority makes a stale pane the authority and regenerates the others from it', () => {
|
||||
const s = new Workspace(workForProblem(problemById('count-base')));
|
||||
s.edit('matho', 'x = '); // does not read: everything else is stale
|
||||
assert.equal(s.linkState('pseudo').kind, 'stale');
|
||||
s.edit('pseudo', COUNT);
|
||||
assert.equal(s.state.sync.authority, 'pseudo');
|
||||
assert.ok(s.linkState('matho').kind === 'stale' || s.linkState('matho').kind === 'sync');
|
||||
s.takeAuthority('lingo');
|
||||
assert.equal(s.state.sync.authority, 'lingo');
|
||||
});
|
||||
|
||||
test('line maps compose through the hub', () => {
|
||||
const r = new SyncHub({}).edit('pseudo', SIMPLE);
|
||||
// pseudo line 3 is `S <- 0.0`; its lingo and Mojo lines come back through the maps
|
||||
const lingoLines = SyncHub.relate(r.maps, 'pseudo', 3, 'lingo');
|
||||
assert.ok(lingoLines.length, 'a lingo line matches');
|
||||
assert.match(r.sources.lingo.split('\n')[lingoLines[0] - 1], /Start with S at 0\.0/);
|
||||
const mojoLines = SyncHub.relate(r.maps, 'pseudo', 3, 'mojo');
|
||||
assert.match(r.mojo.source.split('\n')[mojoLines[0] - 1], /s = 0\.0/);
|
||||
// from Mojo back to lingo, through the pseudo
|
||||
const back = SyncHub.relate(r.maps, 'mojo', mojoLines[0], 'lingo');
|
||||
assert.deepEqual(back, lingoLines);
|
||||
// an authority's own lowering is used the other way: lingo line -> pseudo line
|
||||
const l = new SyncHub({}).edit('lingo', pseudoToLingo(SIMPLE).source);
|
||||
const lingoLine = l.sources.lingo.split('\n').findIndex((t) => /Start with S at/.test(t)) + 1;
|
||||
const ps = SyncHub.relate(l.maps, 'lingo', lingoLine, 'pseudo');
|
||||
assert.ok(ps.some((n) => /S <- 0\.0/.test(l.sources.pseudo.split('\n')[n - 1])), 'the lingo line maps to the assignment');
|
||||
assert.ok(SyncHub.relate(l.maps, 'lingo', lingoLine, 'mojo').length);
|
||||
});
|
||||
|
||||
test('line maps stay right when contracts are woven into the pseudo an English edit produced', () => {
|
||||
const filled = new SyncHub(workForProblem(problemById('count-base-proved')).sources).fill();
|
||||
const r = new SyncHub(filled.sources).edit('lingo', filled.sources.lingo);
|
||||
const lingoLine = r.sources.lingo.split('\n').findIndex((t) => /Add 1 to Total/.test(t)) + 1;
|
||||
const ps = SyncHub.relate(r.maps, 'lingo', lingoLine, 'pseudo');
|
||||
assert.ok(ps.length);
|
||||
assert.match(r.sources.pseudo.split('\n')[ps[0] - 1], /Total <- Total \+ 1/);
|
||||
});
|
||||
|
||||
test('every exercise: an edit in any linked pane leaves the Mojo in step with the pseudo and checking clean', () => {
|
||||
let n = 0;
|
||||
for (const p of PROBLEMS) {
|
||||
const st = workForProblem(p);
|
||||
if (!(st.sources.pseudo ?? '').trim() || !st.call) continue;
|
||||
if (!studyOf(st.sources.pseudo).ok) continue;
|
||||
const r = new SyncHub(st.sources, undefined, { call: st.call }).edit('pseudo', st.sources.pseudo);
|
||||
assert.equal(r.sources.pseudo, st.sources.pseudo);
|
||||
assert.match(r.mojo.source, /Generated by Programming\+/, p.id);
|
||||
n++;
|
||||
}
|
||||
assert.ok(n >= 12, `${n} exercises went through the hub`);
|
||||
});
|
||||
|
||||
test('timing: a full cascade (lingo edit -> pseudo, matho, speco, Mojo) on the largest exercise stays under 50 ms', () => {
|
||||
let big = null;
|
||||
for (const p of PROBLEMS) {
|
||||
const st = workForProblem(p);
|
||||
const t = st.sources.pseudo ?? '';
|
||||
if (t.trim() && studyOf(t).ok && (!big || t.length > big.pseudo.length)) big = { id: p.id, pseudo: t, st };
|
||||
}
|
||||
assert.ok(big);
|
||||
const filled = new SyncHub(big.st.sources, undefined, { call: big.st.call }).fill();
|
||||
// a lingo that reads: whatever the English generator wrote, or, when it has no English, the smallest program
|
||||
const lingo = filled.sources.lingo || pseudoToLingo(SIMPLE).source;
|
||||
const start = filled.sources.lingo ? filled.sources : { lingo };
|
||||
const hub = () => new SyncHub(start, undefined, { call: big.st.call });
|
||||
hub().edit('lingo', lingo); // warm up the engines
|
||||
const times = [];
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const t0 = performance.now();
|
||||
hub().edit('lingo', lingo + (i % 2 ? '' : '\n'));
|
||||
times.push(performance.now() - t0);
|
||||
}
|
||||
times.sort((a, b) => a - b);
|
||||
const median = times[3];
|
||||
assert.ok(median < 50, `${big.id}: the median cascade took ${median.toFixed(1)} ms (limit 50)`);
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
// 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`);
|
||||
});
|
||||
Reference in new issue
Block a user