Files
alexm 401084bab3
Test / gate (push) Failing after 19m0s
Initial commit
2026-11-12 22:23:54 -05:00

85 lines
4.3 KiB
JavaScript

// 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. 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', 'work'].includes(e.name)) walk(p); } // work/ is git-ignored notes
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`);
});
test('package.json and pixi.toml agree: the same version, and the Node pixi pins is one engines.node allows', () => {
// package.json is what a machine without pixi reads (and CI did, until pixi came to the runner); the two can drift
const pkg = JSON.parse(read('package.json'));
const toml = read('pixi.toml');
assert.equal(/^version = "([^"]+)"/m.exec(toml)?.[1], pkg.version, 'the version in pixi.toml [workspace] and in package.json');
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, 'pixi.toml pins nodejs with a lower bound');
assert.ok(atLeast(parts(pinned[1]), parts(floor[1])), `pixi installs Node ${pinned[1]}, below engines.node ${pkg.engines.node}`);
assert.ok(atLeast(parts(process.versions.node), parts(floor[1])), `this Node is ${process.versions.node}, below engines.node ${pkg.engines.node}`);
});