commit
e092cb029c
252 files changed
+35037
No files matched your search
@@ -0,0 +1,108 @@
|
||||
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// The commands people run live in pixi.toml; the README's table lists them. core/ is pplus-core, a project of its
|
||||
// own with its own pixi.toml and this same test. 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 > 15, `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', 'site', '.git', '.pixi', 'corpus', 'golden', 'vendor', 'scratch', '_site', '.quarto'].includes(e.name) && p !== 'core') 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', 'dev', 'test', 'watch']);
|
||||
// the README and AGENTS.md say TypeScript is the only npm dependency and the site has no npm runtime dependency
|
||||
assert.equal(pkg.dependencies, undefined, 'no npm runtime dependency (CodeMirror is vendored in src/vendor/)');
|
||||
assert.deepEqual(Object.keys(pkg.devDependencies ?? {}), ['typescript']);
|
||||
});
|
||||
|
||||
test('every document the README points to exists', () => {
|
||||
const readme = read('README.md');
|
||||
for (const m of readme.matchAll(/\]\(((?:docs|quarto|styles)\/[^)#]+)\)/g)) assert.ok(fs.existsSync(path.join(ROOT, m[1])), `${m[1]} is linked from the README but missing`);
|
||||
for (const m of read('docs/app.md').matchAll(/`(docs\/[\w.-]+\.md)`/g)) assert.ok(fs.existsSync(path.join(ROOT, m[1])), `${m[1]} is named in docs/app.md but missing`);
|
||||
});
|
||||
|
||||
test('the site names the Mojo version core is pinned to, in its documents and in pixi.toml', async () => {
|
||||
// core decides the pin (core/library/mojo/pin.json); these are the site's sentences that have to move with it
|
||||
const { MOJO_VERSION, GODBOLT_COMPILER } = await import('../core/dist/mojo/generated/pin.js');
|
||||
const wrong = [];
|
||||
for (const d of ['README.md', 'AGENTS.md', 'docs/app.md', 'docs/deploy.md', 'quarto/README.md']) {
|
||||
fs.readFileSync(path.join(ROOT, d), 'utf8').split('\n').forEach((line, i) => {
|
||||
for (const m of line.matchAll(/(?:pinned to (?:\*\*)?(?:Mojo )?|verified on Mojo )(\d+\.\d+\.\d+)/g)) if (m[1] !== MOJO_VERSION) wrong.push(`${d}:${i + 1} says ${m[1]}`);
|
||||
for (const m of line.matchAll(/\bmojo_\d+_\d+_\d+\b/g)) if (m[0] !== GODBOLT_COMPILER) wrong.push(`${d}:${i + 1} says ${m[0]}`);
|
||||
});
|
||||
}
|
||||
assert.deepEqual(wrong, [], `core is pinned to Mojo ${MOJO_VERSION}`);
|
||||
assert.match(fs.readFileSync(path.join(ROOT, 'pixi.toml'), 'utf8'), new RegExp(`^mojo = "==${MOJO_VERSION.replace(/\./g, '\\.')}"`, 'm'), 'pixi.toml installs the compiler core is pinned to');
|
||||
});
|
||||
|
||||
test('package.json and pixi.toml agree, and the site pins the same Node and Python as core', () => {
|
||||
// package.json is what a machine without pixi reads; core/pixi.toml is the pin core is tested with
|
||||
const pkg = JSON.parse(read('package.json'));
|
||||
const toml = read('pixi.toml');
|
||||
const core = read('core/pixi.toml');
|
||||
assert.equal(/^version = "([^"]+)"/m.exec(toml)?.[1], pkg.version, 'the version in pixi.toml [workspace] and in package.json');
|
||||
for (const dep of ['nodejs', 'python']) {
|
||||
const pin = (text) => new RegExp(`^${dep} = "([^"]+)"`, 'm').exec(text)?.[1];
|
||||
assert.equal(pin(toml), pin(core), `${dep}: the site pins ${pin(toml)}, core ${pin(core)}`);
|
||||
}
|
||||
const parts = (s) => s.split('.').map(Number).concat([0, 0]).slice(0, 3);
|
||||
const atLeast = (a, b) => { for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] > b[i]; return true; };
|
||||
const floor = /^>=\s*(\d+(?:\.\d+){0,2})$/.exec(pkg.engines?.node ?? '');
|
||||
assert.ok(floor, `engines.node is "${pkg.engines?.node}"; this test reads ">=X.Y.Z"`);
|
||||
const pinned = /^nodejs = ">=(\d+\.\d+\.\d+)/m.exec(toml);
|
||||
assert.ok(pinned && atLeast(parts(pinned[1]), parts(floor[1])), `pixi installs Node ${pinned?.[1]}, below engines.node ${pkg.engines.node}`);
|
||||
assert.equal(pkg.engines.node, JSON.parse(read('core/package.json')).engines?.node, 'the site and core name the same oldest Node');
|
||||
assert.ok(atLeast(parts(process.versions.node), parts(floor[1])), `this Node is ${process.versions.node}, below engines.node ${pkg.engines.node}`);
|
||||
});
|
||||
Reference in new issue
Block a user