// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC // SPDX-License-Identifier: Apache-2.0 // Core pins pplus-library (library/) by commit. A pointer that names a commit the library checkout does not have, or // a checkout left behind its pointer, tests core against other programs and stored answers than the commit says: // core's main once pinned a library commit from before the corpus moved, and a fresh clone had no programs at all // (docs/ci.md). This is the cheap half of pplus-web's `release-check` (its scripts/release.mjs walks all three // repositories); here only core's own pointer, with no network. import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import { spawnSync } from 'node:child_process'; const ROOT = new URL('..', import.meta.url).pathname; const LIB = path.join(ROOT, 'library'); const git = (dir, ...args) => { const r = spawnSync('git', ['-C', dir, ...args], { encoding: 'utf8' }); return r.status === 0 ? r.stdout.trim() : null; }; test('the library commit core pins is in library/, and library/ is not behind it', (t) => { const readable = spawnSync('git', ['--version']).status === 0 && fs.existsSync(path.join(ROOT, '.git')); if (!readable) { // a package made by package.py has no .git: there is no pointer to read; under CI there always is one assert.ok(!process.env.CI, 'CI must run this in a git checkout, with git on the PATH'); t.diagnostic('not a git checkout: no pointer to read'); return; } const pin = /^160000 ([0-9a-f]{40}) /.exec(git(ROOT, 'ls-files', '--stage', '--', 'library') ?? '')?.[1]; assert.ok(pin, 'core records no commit for library/ (.gitmodules and the index disagree)'); assert.ok(fs.existsSync(path.join(LIB, '.git')), 'library/ is not checked out. Fix: git submodule update --init'); assert.notEqual(git(LIB, 'cat-file', '-e', `${pin}^{commit}`), null, `core pins library at ${pin.slice(0, 10)}, and library/ does not have that commit. Fix: git submodule update --init (it fetches the pinned commit); if no remote has it, it was never pushed: push pplus-library from the machine that made it`); const head = git(LIB, 'rev-parse', 'HEAD'); if (head === pin) return; assert.equal(git(LIB, 'merge-base', '--is-ancestor', head, pin), null, `library/ is at ${head.slice(0, 10)}, behind the pinned ${pin.slice(0, 10)}, so every test here reads an older library. Fix: git submodule update`); if (git(LIB, 'merge-base', '--is-ancestor', pin, head) !== null) t.diagnostic(`library/ is ahead of the pinned ${pin.slice(0, 10)}: when the change is done, commit the new pointer (git add library) with what core regenerates (pixi run library-emit, mojo-emit)`); else assert.fail(`library/ is at ${head.slice(0, 10)}, which is neither the pinned ${pin.slice(0, 10)} nor after it. Fix: git submodule update, or, if ${head.slice(0, 10)} is the one wanted, git add library`); });