// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC // SPDX-License-Identifier: Apache-2.0 // The third-party inventories cannot drift from what they describe. library/THIRD_PARTY.md is written by // `pixi run mojo-emit` (scripts/mojo/mojocorpus/notices.py) from the pin, the lock and every harvested file; // THIRD_PARTY.md here is written by hand and held to the locks and pins it names. 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 read = (p) => fs.readFileSync(path.join(ROOT, p), 'utf8'); function python(code) { const r = spawnSync('python3', ['-c', `import sys, json; sys.path.insert(0, 'scripts/mojo')\nfrom mojocorpus import notices\nfrom mojocorpus.common import load_pin\npin = load_pin()\n${code}`], { encoding: 'utf8', cwd: ROOT }); assert.equal(r.status, 0, r.stderr.split('\n').slice(-20).join('\n')); return JSON.parse(r.stdout); } const noPython = spawnSync('python3', ['--version']).status !== 0 ? 'python3 is not installed' : false; test('library/THIRD_PARTY.md is what mojo-emit writes from the pin, the lock and the corpus', { skip: noPython }, () => { const want = python('print(json.dumps(notices.render(pin)))'); assert.ok(read('library/THIRD_PARTY.md') === want, 'library/THIRD_PARTY.md is out of date: run `pixi run mojo-emit` and commit library/'); }); test("every source's license was checked at the commit the lock holds, and the copies are the ones checked", { skip: noPython }, () => { assert.deepEqual(python('print(json.dumps(notices.problems(pin)))'), []); }); test('moving a source to another commit makes the inventory stale and its license unchecked', { skip: noPython }, () => { const r = python(` before = notices.render(pin) real = notices.load_lock def moved(): lock = real() lock["sources"]["mojo-quest"]["commit"] = "0" * 40 return lock notices.load_lock = moved print(json.dumps({"changed": notices.render(pin) != before, "problems": notices.problems(pin)}))`); assert.equal(r.changed, true); assert.deepEqual(r.problems, ['mojo-quest: license checked at 8e884a709866, but the lock holds 000000000000']); }); test('the inventory counts every harvested program and names every file without a header', { skip: noPython }, () => { const inv = python('print(json.dumps(notices.inventory(pin)))'); const mojo = []; const walk = (d) => { for (const e of fs.readdirSync(path.join(ROOT, d), { withFileTypes: true })) { const p = path.join(d, e.name); if (e.isDirectory()) walk(p); else if (p.endsWith('.mojo')) mojo.push(p); } }; walk('library/mojo/corpus'); assert.equal(inv.programs.length, mojo.length, 'a .mojo file under the corpus is in no manifest'); const table = read('library/THIRD_PARTY.md'); for (const p of inv.programs.filter((p) => p.header === 'none')) assert.ok(table.includes(`\`${p.file}\``), `${p.file} has no header and is not listed`); for (const p of inv.programs.filter((p) => p.header !== 'none' && !p.header.startsWith('Apache-2.0 WITH LLVM-exception'))) assert.ok(table.includes(p.file), p.file); }); test('THIRD_PARTY.md names the versions and licenses the locks and the Dafny pin hold', () => { const doc = read('THIRD_PARTY.md'); const row = (name) => doc.split('\n').find((l) => l.startsWith(`| ${name} `)) ?? ''; const lock = read('pixi.lock'); const conda = (pkg) => { const m = lock.match(new RegExp(`\\n- conda: \\S*/${pkg}-(\\d[^-/]*)-[^/\\s]*\\.conda\\n(?: .*\\n)*? license: (.+)`)); assert.ok(m, `${pkg} is not in pixi.lock`); return { version: m[1], license: m[2].trim() }; }; const mojo = conda('mojo'); assert.ok(row('Mojo').includes(`| ${mojo.version} |`) && row('Mojo').includes(mojo.license), `Mojo ${mojo.version}, ${mojo.license}`); for (const pkg of ['mojo-compiler', 'mojo-python', 'mblack']) { assert.equal(conda(pkg).license, mojo.license, `${pkg} has another license than mojo`); assert.ok(row('Mojo').includes(`\`${pkg}\``), `${pkg} is not named in the Mojo row`); } for (const [name, pkg] of [['Node.js', 'nodejs'], ['Python', 'python']]) { const c = conda(pkg); assert.ok(row(name).includes(`| ${c.version} |`) && row(name).includes(`| ${c.license} |`), `${name} ${c.version}, ${c.license}`); } const ts = JSON.parse(read('package-lock.json')).packages['node_modules/typescript']; assert.ok(row('TypeScript').includes(`| ${ts.version} |`) && row('TypeScript').includes(`| ${ts.license} |`), `TypeScript ${ts.version}, ${ts.license}`); const dafny = read('scripts/dafny.py').match(/^VERSION = "([^"]+)"/m)[1]; assert.ok(row('Dafny').includes(`| ${dafny} |`), `Dafny ${dafny}`); const npm = Object.keys(JSON.parse(read('package-lock.json')).packages).filter((k) => k); assert.deepEqual(npm, ['node_modules/typescript'], 'a new npm package needs a row here (and AGENTS.md allows none)'); }); test('THIRD_PARTY.md describes every generated file the app ships', () => { const doc = read('THIRD_PARTY.md'); for (const f of fs.readdirSync(path.join(ROOT, 'src/mojo/generated'))) assert.ok(doc.includes(`\`src/mojo/generated/${f}\``), `src/mojo/generated/${f} is not described`); });