commit
e092cb029c
252 files changed
+35037
No files matched your search
@@ -0,0 +1,84 @@
|
||||
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// pplus-web pins pplus-core (core/) and core pins pplus-library (core/library/), each by commit. A pointer that names
|
||||
// a commit the checkout does not have, or a checkout left behind its pointer, builds and tests the site from other
|
||||
// sources than the commits say: the chain sat broken that way on main for five weeks once, and nothing said so
|
||||
// (docs/deploy.md, "Moving the pointers"). These run the cheap half of `pixi run release-check` (scripts/release.mjs):
|
||||
// no network, no build.
|
||||
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';
|
||||
import { quickCheck } from '../scripts/release.mjs';
|
||||
|
||||
test('every pointer names a commit its checkout has, and no checkout is behind its pointer', (t) => {
|
||||
const found = quickCheck();
|
||||
for (const f of found.filter((x) => x.level === 'note')) t.diagnostic(f.text);
|
||||
// under CI there is always a checkout to read: a pointer nobody could read is a gap, not a pass
|
||||
if (process.env.CI) assert.ok(!found.some((x) => x.unread), found.map((x) => x.text).join('\n'));
|
||||
assert.deepEqual(found.filter((x) => x.level === 'problem').map((x) => x.text), []);
|
||||
});
|
||||
|
||||
const git = (dir, ...args) => {
|
||||
const r = spawnSync('git', ['-c', 'user.name=test', '-c', 'user.email=test@example.invalid', '-c', 'commit.gpgsign=false', '-C', dir, ...args], { encoding: 'utf8' });
|
||||
assert.equal(r.status, 0, r.stderr);
|
||||
return r.stdout.trim();
|
||||
};
|
||||
|
||||
/** A parent repository whose submodule `child` (a repository of two commits) is pinned at `pin` and checked out at `at`. */
|
||||
function fakeChain(pin, at) {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pplus-chain-'));
|
||||
git(root, 'init', '-q');
|
||||
fs.writeFileSync(path.join(root, 'package.json'), '{"name":"parent"}\n');
|
||||
const child = path.join(root, 'child');
|
||||
fs.mkdirSync(child);
|
||||
git(child, 'init', '-q');
|
||||
const commits = [];
|
||||
for (const n of ['one', 'two']) { fs.writeFileSync(path.join(child, 'f'), n); git(child, 'add', 'f'); git(child, 'commit', '-q', '-m', n); commits.push(git(child, 'rev-parse', 'HEAD')); }
|
||||
fs.writeFileSync(path.join(root, '.gitmodules'), '[submodule "child"]\n\tpath = child\n\turl = https://example.invalid/child.git\n\tbranch = main\n');
|
||||
const sha = pin === 'missing' ? 'f'.repeat(40) : commits[pin];
|
||||
git(root, 'update-index', '--add', '--cacheinfo', `160000,${sha},child`);
|
||||
git(child, 'checkout', '-q', commits[at]);
|
||||
return { root, commits };
|
||||
}
|
||||
|
||||
test('a pointer to a commit the checkout lacks, or a checkout behind its pointer, is a problem that names the fix', () => {
|
||||
if (spawnSync('git', ['--version']).status !== 0) assert.fail('git is not on the PATH');
|
||||
const cases = [
|
||||
{ pin: 'missing', at: 1, want: /does not have that commit\. Fix: git submodule update --init --recursive/ },
|
||||
{ pin: 1, at: 0, want: /behind the pinned .* Fix: git submodule update --recursive/ },
|
||||
];
|
||||
for (const c of cases) {
|
||||
const { root } = fakeChain(c.pin, c.at);
|
||||
try {
|
||||
const problems = quickCheck(root).filter((x) => x.level === 'problem');
|
||||
assert.equal(problems.length, 1, JSON.stringify(problems));
|
||||
assert.match(problems[0].text, c.want);
|
||||
} finally { fs.rmSync(root, { recursive: true, force: true }); }
|
||||
}
|
||||
// at the pointer: nothing to say; ahead of it (work in progress, not yet pinned): a note, not a problem
|
||||
for (const [pin, at, notes] of [[1, 1, 0], [0, 1, 1]]) {
|
||||
const { root } = fakeChain(pin, at);
|
||||
try {
|
||||
const found = quickCheck(root);
|
||||
assert.deepEqual(found.filter((x) => x.level === 'problem'), []);
|
||||
assert.equal(found.filter((x) => x.level === 'note').length, notes);
|
||||
} finally { fs.rmSync(root, { recursive: true, force: true }); }
|
||||
}
|
||||
});
|
||||
|
||||
test('build-info names the three commits the site is built from, as git has them', async () => {
|
||||
const { buildInfo } = await import('../scripts/build-info.mjs');
|
||||
const ROOT = new URL('..', import.meta.url).pathname;
|
||||
if (!fs.existsSync(path.join(ROOT, '.git')) && !process.env.CI) return; // a package has no commits to name
|
||||
const info = buildInfo();
|
||||
const head = (dir) => spawnSync('git', ['-C', dir, 'rev-parse', 'HEAD'], { encoding: 'utf8' }).stdout.trim();
|
||||
assert.equal(info.web.commit, head(ROOT));
|
||||
assert.equal(info.core.commit, head(path.join(ROOT, 'core')));
|
||||
assert.equal(info.library.commit, head(path.join(ROOT, 'core', 'library')));
|
||||
assert.equal(info.web.version, JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')).version);
|
||||
assert.equal(info.core.version, JSON.parse(fs.readFileSync(path.join(ROOT, 'core', 'package.json'), 'utf8')).version);
|
||||
assert.match(info.mojo, /^\d+\.\d+\.\d+$/);
|
||||
});
|
||||
Reference in new issue
Block a user