Files
pplus-core/tests/spdx.test.mjs
T
alexm 401084bab3
Test / gate (push) Failing after 19m0s
Initial commit
2026-11-12 22:23:54 -05:00

39 lines
2.0 KiB
JavaScript

// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
// SPDX-License-Identifier: Apache-2.0
// Every source file written here says who holds its copyright and under which license, in two SPDX lines at its
// top, so a file copied out of the repository still says where it came from. Left without them, on purpose:
// generated files (their tools rewrite them), and the files that came from the course (src/engines/ and
// src/curriculum/), which THIRD_PARTY.md puts under the same copyright and license. A new file fails here until
// it has the lines; this test goes with them if the owner drops the headers.
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 LEFT_OUT = [/^src\/engines\//, /^src\/curriculum\//, /^src\/mojo\/generated\//, /^src\/library\/generated\.ts$/];
const HOLDER = 'SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC';
const LICENSE = 'SPDX-License-Identifier: Apache-2.0';
test('every hand-written source, script and test starts with its SPDX lines', () => {
const files = [];
const walk = (dir) => {
for (const e of fs.readdirSync(path.join(ROOT, dir), { withFileTypes: true })) {
const f = `${dir}/${e.name}`;
if (e.isDirectory()) { if (!['node_modules', '__pycache__'].includes(e.name)) walk(f); }
else if (/\.(ts|js|mjs|py|sh)$/.test(e.name) && !LEFT_OUT.some((r) => r.test(f))) files.push(f);
}
};
for (const d of ['src', 'scripts', 'tests']) walk(d);
assert.ok(files.length > 140, `${files.length} files read`);
const missing = [];
for (const f of files) {
const lines = fs.readFileSync(path.join(ROOT, f), 'utf8').split('\n');
const at = lines[0].startsWith('#!') ? 1 : 0;
const mark = /\.(py|sh)$/.test(f) ? '# ' : '// ';
if (lines[at] !== mark + HOLDER || lines[at + 1] !== mark + LICENSE) missing.push(f);
}
assert.deepEqual(missing, []);
assert.match(fs.readFileSync(path.join(ROOT, 'LICENSE.md'), 'utf8'), /Apache License/);
});