Initial commit
Test / gate (push) Failing after 19m0s

This commit is contained in:
alexm committed 2026-11-12 22:23:54 -05:00
commit 401084bab3
265 files changed
+69224

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
// SPDX-License-Identifier: Apache-2.0
// pplus-core has no DOM: what a program means is decided without a browser. Its library modules never touch the
// document, the window or browser storage, and never import the course's page widgets, which live beside the
// engines only so the course and pplus-web can take them from one place (docs/engines.md).
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 SRC = path.join(ROOT, 'src');
/** The course's page widgets: they draw into a page, and only pages (the course's, pplus-web's) import them. */
export const WIDGETS = new Set([
'engines/pseudo/dom.js', 'engines/pseudo/views.js', 'engines/pseudo/views-analysis.js', 'engines/pseudo/lab.js',
'engines/pseudo/editor.js', 'engines/pseudo/exercise.js', 'engines/pseudo/sharpen.js', 'engines/pseudo/plan.js',
'engines/pseudo/planner.js', 'engines/pseudo/highlight.js',
'engines/asm86/views.js', 'engines/asm86/hwviews.js', 'engines/asm86/dom.js', 'engines/asm86/sandbox.js', 'engines/asm86/specs-hw.js',
'engines/shared/dom.js', 'engines/shared/share.js', 'engines/shared/viz.js',
]);
function walk(dir, out = []) {
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
const p = path.join(dir, e.name);
if (e.isDirectory()) walk(p, out); else if (/\.(ts|js)$/.test(e.name)) out.push(path.relative(SRC, p));
}
return out;
}
const asJs = (p) => p.replace(/\.ts$/, '.js');
const files = walk(SRC);
const library = files.filter((f) => !WIDGETS.has(asJs(f)));
test('every widget named here exists, so the list cannot rot', () => {
for (const w of WIDGETS) assert.ok(files.some((f) => asJs(f) === w), `${w} is not in src/`);
});
test('no library module touches the document, the window or browser storage', () => {
const bad = [];
for (const f of library) {
const code = fs.readFileSync(path.join(SRC, f), 'utf8').replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '');
for (const w of ['document.', 'window.', 'localStorage', 'sessionStorage', 'navigator.', 'HTMLElement']) if (code.includes(w)) bad.push(`${f}: ${w}`);
}
assert.deepEqual(bad, []);
});
test('no library module imports a widget, and nothing imports from outside core', () => {
const bad = [];
for (const f of library) {
const code = fs.readFileSync(path.join(SRC, f), 'utf8');
for (const m of code.matchAll(/(?:from|import)\s*\(?\s*['"](\.{1,2}\/[^'"]+)['"]/g)) {
const target = path.normalize(path.join(path.dirname(f), m[1]));
if (target.startsWith('..')) bad.push(`${f} imports ${m[1]}, outside src/`);
else if (WIDGETS.has(asJs(target))) bad.push(`${f} imports the widget ${m[1]}`);
}
if (/['"]#core\//.test(code)) bad.push(`${f} uses #core/, which is how pplus-web reaches core`);
}
assert.deepEqual(bad, []);
});