Move the engine core into core/, a project of its own (pplus-core)
What programs mean (the languages, translators, Mojo checker and
interpreter, prover, fuzzer, machine model, catalog problems and the Mojo
corpus with godbolt's stored answers) was mixed into the site's tree, so a
change to the prover and a change to a button went through the same gate
and the same docs. This moves all of it under core/, laid out as its own
repository, ready to be extracted with its history and pinned here as a
git submodule.
- core/: src/{engines,services,sync,mojo,exercises,curriculum,common},
mojo/, syntax/mojo.xml, its tests (with Workspace and workForProblem in
place of the site's Session), scripts (corpus pipeline, play, the
exercise and probe starters, engines export/diff), and its docs
(engines, trust, mojo-corpus, exercises, coverage). Its own pixi.toml,
package.json, README, AGENTS.md and CI workflow.
- core/tests/boundary.test.mjs: library modules use no DOM, import no
page widget, and import nothing outside src/.
- core/scripts/cli.mjs: pixi run cli check|run|prove|fuzz|translate.
- core/scripts/dafny.py: Dafny 4.11.0 pinned by version and SHA-256 per
platform, fetched into .tools/ (pixi run dafny-fetch, pixi run dafny).
- The site imports core only as #core/<path>.js: an import map in
index.html, "imports" in package.json for node, core's declarations for
tsc. The site's TypeScript builds core first (npm run build).
- assemble.sh, the Quarto engine copy, the render cache key, check-pages,
quarto-export and quarto-css read core/dist and core/mojo; quarto-css
copies core's syntax/mojo.xml into the extension.
- Site tests that covered engines moved to core; the rest keep Session.
- README, AGENTS.md, docs/app.md, docs/deploy.md and the CI workflow
describe the split (checkout with submodules; core's tests and corpus
status run against the pinned commit).
Gate: site 110 pass; core 307 pass; corpus status --strict passes.
Manual check: the assembled site opens Bridge (count-base-proved),
Developer and Hardware (count-base) with the editor, the stepper and the
board, and no module errors.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FgvbRdoEheAHqsRmr2WuKZ
This commit is contained in:
1567 files changed
+3670
-981
No files matched your search
+5
-209
@@ -4,14 +4,14 @@
|
||||
// whole cascade is fast enough that typing stays instant.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { SyncHub, LINKED, namesFromMatho } from '../dist/sync/hub.js';
|
||||
import { pseudoToLingo } from '../dist/sync/pseudo-to-lingo.js';
|
||||
import { SyncHub, LINKED, namesFromMatho } from '../core/dist/sync/hub.js';
|
||||
import { pseudoToLingo } from '../core/dist/sync/pseudo-to-lingo.js';
|
||||
import { Session } from '../dist/core/session.js';
|
||||
import { PROBLEMS, stateForProblem, problemById } from '../dist/core/catalog.js';
|
||||
import { encodeState, decodeState, emptyState } from '../dist/core/state.js';
|
||||
import { checkMojo } from '../dist/mojo/check.js';
|
||||
import { studyOf } from '../dist/services/pseudo.js';
|
||||
import { EQUATIONS, FIXTURES } from './helpers/sync-programs.mjs';
|
||||
import { checkMojo } from '../core/dist/mojo/check.js';
|
||||
import { studyOf } from '../core/dist/services/pseudo.js';
|
||||
import { EQUATIONS, FIXTURES } from '../core/tests/helpers/sync-programs.mjs';
|
||||
|
||||
globalThis.localStorage = { getItem() { return null; }, setItem() { }, removeItem() { } };
|
||||
|
||||
@@ -38,133 +38,6 @@ const SIMPLE = `FUNCTION SUMMED(N : INTEGER, X : LIST OF FLOAT) RETURNS FLOAT
|
||||
ENDFUNCTION`;
|
||||
const WHILE_PSEUDO = FIXTURES['fixture:div-mod'][0];
|
||||
|
||||
test('a lingo edit updates pseudo, matho and Mojo, and does not rewrite the lingo', () => {
|
||||
const mean = new SyncHub({}).edit('matho', EQUATIONS['mean'][0]);
|
||||
assert.ok(mean.sources.lingo.includes('Start with Total'), 'the equations also became English');
|
||||
const lingo = mean.sources.lingo.replace('The answer is 1 / N * Total.', 'The answer is 2 / N * Total.');
|
||||
const r = next(mean, 'lingo', lingo);
|
||||
assert.equal(r.authority, 'lingo');
|
||||
assert.equal(r.sources.lingo, lingo, 'the edited pane is exactly what was typed');
|
||||
assert.match(r.sources.pseudo, /RETURN 2 \/ N \* Total/);
|
||||
assert.match(r.sources.matho, /\\frac\{2\}\{n\}|2/, 'matho follows');
|
||||
assert.match(r.sources.matho, /\\sum/);
|
||||
assert.match(r.mojo.source, /Float64\(2\) \/ Float64\(n\) \* total/);
|
||||
assert.deepEqual(r.stale, {});
|
||||
assert.ok(r.changed.includes('pseudo') && r.changed.includes('matho') && !r.changed.includes('lingo'));
|
||||
});
|
||||
|
||||
test('a pseudo edit updates lingo', () => {
|
||||
const r0 = new SyncHub({}).edit('pseudo', SIMPLE);
|
||||
assert.match(r0.sources.lingo, /Start with S at 0\.0/);
|
||||
const r = next(r0, 'pseudo', SIMPLE.replace('S <- 0.0', 'S <- 2.0'));
|
||||
assert.match(r.sources.lingo, /Start with S at 2\.0/);
|
||||
assert.equal(r.sources.pseudo, SIMPLE.replace('S <- 0.0', 'S <- 2.0'));
|
||||
assert.equal(r.authority, 'pseudo');
|
||||
});
|
||||
|
||||
test('an edit in X never rewrites X, for every linked language', () => {
|
||||
const base = new SyncHub({}).edit('pseudo', SIMPLE);
|
||||
for (const lang of LINKED) {
|
||||
const text = base.sources[lang];
|
||||
if (!text) continue;
|
||||
const r = new SyncHub(base.sources, sync(base)).edit(lang, text + '\n');
|
||||
assert.equal(r.sources[lang], text + '\n', `${lang} is kept as typed, trailing blank line included`);
|
||||
}
|
||||
});
|
||||
|
||||
test('an error in the authority changes nothing: the others keep their last good text and say why', () => {
|
||||
const ok = new SyncHub({}).edit('pseudo', SIMPLE);
|
||||
const before = { ...ok.sources };
|
||||
const r = next(ok, 'lingo', 'Gibberish that is no sentence of lingo at all.');
|
||||
assert.equal(r.sources.lingo, 'Gibberish that is no sentence of lingo at all.');
|
||||
for (const l of ['pseudo', 'matho', 'speco']) assert.equal(r.sources[l] ?? '', before[l] ?? '', `${l} kept its text`);
|
||||
for (const l of ['pseudo', 'matho', 'speco']) assert.match(r.stale[l], /lingo line 1 does not read yet/);
|
||||
assert.equal(r.stale.lingo, undefined, 'the pane being typed in is not stale');
|
||||
// a pseudo with errors does the same
|
||||
const bad = next(ok, 'pseudo', 'FUNCTION BROKEN(\nRETURN');
|
||||
assert.match(bad.stale.lingo, /pseudo line \d+ does not read yet/);
|
||||
assert.equal(bad.sources.lingo, before.lingo);
|
||||
// and a good edit afterwards clears every mark
|
||||
const fixed = next(bad, 'pseudo', SIMPLE);
|
||||
assert.deepEqual(fixed.stale, {});
|
||||
});
|
||||
|
||||
test('matho goes stale, not blank, on a WHILE; a later expressible program brings it back', () => {
|
||||
const r0 = new SyncHub({}).edit('matho', EQUATIONS['mean'][0]);
|
||||
const matho = r0.sources.matho;
|
||||
const r = next(r0, 'pseudo', WHILE_PSEUDO);
|
||||
assert.equal(r.sources.matho, matho, 'matho keeps its last good text');
|
||||
assert.match(r.stale.matho, /matho has no form for a WHILE loop \(line \d+\)/);
|
||||
assert.equal(r.stale.lingo, undefined, 'lingo can say a WHILE');
|
||||
assert.match(r.sources.lingo, /\S/);
|
||||
const back = next(r, 'pseudo', SIMPLE);
|
||||
assert.equal(back.stale.matho, undefined);
|
||||
assert.notEqual(back.sources.matho, matho);
|
||||
});
|
||||
|
||||
test('contracts survive an edit in English or in equations', () => {
|
||||
const p = problemById('count-base-proved');
|
||||
const st = stateForProblem(p);
|
||||
const filled = new SyncHub(st.sources).fill();
|
||||
const spec = filled.sources.speco;
|
||||
assert.match(spec, /ENSURE/);
|
||||
const r = next({ sources: filled.sources, authority: 'speco', stale: {}, names: {} }, 'lingo', filled.sources.lingo.replace('Add 1 to Total.', 'Add 2 to Total.'));
|
||||
assert.equal(r.sources.speco, spec, 'the speco is what it was');
|
||||
assert.match(r.sources.pseudo, /Total <- Total \+ 2/, 'the edit took');
|
||||
assert.match(r.sources.pseudo, /ENSURE RESULT == LENGTH/, 'the contract is woven into the pseudo the English lowered to');
|
||||
assert.match(r.sources.pseudo, /INVARIANT/);
|
||||
assert.match(r.mojo.source, /# ENSURE/, 'the translator carries the contract as a comment');
|
||||
// a claim about a routine the English no longer has is kept in the speco, not dropped
|
||||
const renamed = filled.sources.lingo.replace('To count base for B and T:', 'To tally base for B and T:');
|
||||
const r2 = next({ sources: filled.sources, authority: 'speco', stale: {}, names: {} }, 'lingo', renamed);
|
||||
assert.match(r2.sources.speco, /kept:/);
|
||||
assert.match(r2.sources.speco, /ENSURE/);
|
||||
});
|
||||
|
||||
test('an edit in speco puts its contracts into the pseudo, then lingo and matho follow', () => {
|
||||
const r0 = new SyncHub({}).edit('pseudo', SIMPLE);
|
||||
const spec = 'SPEC SUMMED(N, X)\n REQUIRE N >= 0\n';
|
||||
const r = next(r0, 'speco', spec);
|
||||
assert.equal(r.sources.speco, spec);
|
||||
assert.match(r.sources.pseudo, /REQUIRE N >= 0/);
|
||||
assert.equal(r.authority, 'speco');
|
||||
// replacing it replaces: the old REQUIRE is gone
|
||||
const r2 = next(r, 'speco', 'SPEC SUMMED(N, X)\n REQUIRE N >= 1\n');
|
||||
assert.match(r2.sources.pseudo, /REQUIRE N >= 1/);
|
||||
assert.doesNotMatch(r2.sources.pseudo, /REQUIRE N >= 0/);
|
||||
// a speco with a syntax error changes nothing
|
||||
const bad = next(r, 'speco', 'SPEC SUMMED(N, X\n REQUIRE ??\n');
|
||||
assert.equal(bad.sources.pseudo, r.sources.pseudo);
|
||||
assert.ok(bad.stale.pseudo);
|
||||
});
|
||||
|
||||
test('the student\'s spelling of equation names survives a trip through pseudo', () => {
|
||||
const r0 = new SyncHub({}).edit('matho', '\\overline{x} = \\frac{1}{n} \\sum_{i=0}^{n-1} x_i');
|
||||
assert.deepEqual(r0.names, { X_BAR: '\\overline{x}' });
|
||||
const r = next(r0, 'pseudo', r0.sources.pseudo.replace('RETURN 1 / N * Total', 'RETURN 2 / N * Total'));
|
||||
assert.match(r.sources.matho, /^\\overline\{x\} = /m);
|
||||
assert.deepEqual(namesFromMatho('f(x) = x + 1'), {}, 'a function written with its inputs is spelled by the generator');
|
||||
});
|
||||
|
||||
test('loading an authored exercise changes nothing until the first edit', () => {
|
||||
for (const p of PROBLEMS) {
|
||||
const st = stateForProblem(p);
|
||||
const before = JSON.stringify(st.sources);
|
||||
const filled = new SyncHub(st.sources).fill();
|
||||
for (const l of [...LINKED, 'mojo', 'asm']) if ((st.sources[l] ?? '').trim()) assert.equal(filled.sources[l], st.sources[l], `${p.id}: authored ${l} is shown as written`);
|
||||
assert.equal(JSON.stringify(st.sources), before, `${p.id}: the state's own sources are untouched`);
|
||||
}
|
||||
// through the session: reading never writes, and nothing is saved or marked as edited
|
||||
const p = problemById('count-base');
|
||||
const s = new Session(stateForProblem(p), { original: stateForProblem(p) });
|
||||
const raw = JSON.stringify(s.state.sources);
|
||||
assert.match(s.source('lingo'), /\S/, 'a missing pane is shown, generated from the pseudo');
|
||||
s.parsedLingo(); s.derivedMojo(); s.lineMaps();
|
||||
assert.equal(JSON.stringify(s.state.sources), raw);
|
||||
assert.equal(s.state.sync, undefined);
|
||||
assert.equal(s.linkState('lingo').kind, 'authored');
|
||||
});
|
||||
|
||||
test('the first edit makes the pane the authority and writes the shown panes into the state', () => {
|
||||
const p = problemById('count-base');
|
||||
const s = new Session(stateForProblem(p));
|
||||
@@ -203,17 +76,6 @@ test('a share link round-trips sync, and a stale pane stays stale', async () =>
|
||||
assert.equal(normalize({ v: 3, sync: { authority: 'mojo' } }).sync, undefined);
|
||||
});
|
||||
|
||||
test('takeAuthority makes a stale pane the authority and regenerates the others from it', () => {
|
||||
const s = new Session(stateForProblem(problemById('count-base')));
|
||||
s.setSource('matho', 'x = '); // does not read: everything else is stale
|
||||
assert.equal(s.linkState('pseudo').kind, 'stale');
|
||||
s.setSource('pseudo', COUNT);
|
||||
assert.equal(s.state.sync.authority, 'pseudo');
|
||||
assert.ok(s.linkState('matho').kind === 'stale' || s.linkState('matho').kind === 'sync');
|
||||
s.takeAuthority('lingo');
|
||||
assert.equal(s.state.sync.authority, 'lingo');
|
||||
});
|
||||
|
||||
test('derivedMojo is the literal translation, is memoized by the pseudo and the call, and passes the checker', () => {
|
||||
const s = new Session(stateForProblem(problemById('count-base')));
|
||||
const a = s.derivedMojo();
|
||||
@@ -230,69 +92,3 @@ test('derivedMojo is the literal translation, is memoized by the pseudo and the
|
||||
assert.equal(new Session(emptyState()).derivedMojo().source, '');
|
||||
});
|
||||
|
||||
test('line maps compose through the hub', () => {
|
||||
const r = new SyncHub({}).edit('pseudo', SIMPLE);
|
||||
// pseudo line 3 is `S <- 0.0`; its lingo and Mojo lines come back through the maps
|
||||
const lingoLines = SyncHub.relate(r.maps, 'pseudo', 3, 'lingo');
|
||||
assert.ok(lingoLines.length, 'a lingo line matches');
|
||||
assert.match(r.sources.lingo.split('\n')[lingoLines[0] - 1], /Start with S at 0\.0/);
|
||||
const mojoLines = SyncHub.relate(r.maps, 'pseudo', 3, 'mojo');
|
||||
assert.match(r.mojo.source.split('\n')[mojoLines[0] - 1], /s = 0\.0/);
|
||||
// from Mojo back to lingo, through the pseudo
|
||||
const back = SyncHub.relate(r.maps, 'mojo', mojoLines[0], 'lingo');
|
||||
assert.deepEqual(back, lingoLines);
|
||||
// an authority's own lowering is used the other way: lingo line -> pseudo line
|
||||
const l = new SyncHub({}).edit('lingo', pseudoToLingo(SIMPLE).source);
|
||||
const lingoLine = l.sources.lingo.split('\n').findIndex((t) => /Start with S at/.test(t)) + 1;
|
||||
const ps = SyncHub.relate(l.maps, 'lingo', lingoLine, 'pseudo');
|
||||
assert.ok(ps.some((n) => /S <- 0\.0/.test(l.sources.pseudo.split('\n')[n - 1])), 'the lingo line maps to the assignment');
|
||||
assert.ok(SyncHub.relate(l.maps, 'lingo', lingoLine, 'mojo').length);
|
||||
});
|
||||
|
||||
test('line maps stay right when contracts are woven into the pseudo an English edit produced', () => {
|
||||
const filled = new SyncHub(stateForProblem(problemById('count-base-proved')).sources).fill();
|
||||
const r = new SyncHub(filled.sources).edit('lingo', filled.sources.lingo);
|
||||
const lingoLine = r.sources.lingo.split('\n').findIndex((t) => /Add 1 to Total/.test(t)) + 1;
|
||||
const ps = SyncHub.relate(r.maps, 'lingo', lingoLine, 'pseudo');
|
||||
assert.ok(ps.length);
|
||||
assert.match(r.sources.pseudo.split('\n')[ps[0] - 1], /Total <- Total \+ 1/);
|
||||
});
|
||||
|
||||
test('every exercise: an edit in any linked pane leaves the Mojo in step with the pseudo and checking clean', () => {
|
||||
let n = 0;
|
||||
for (const p of PROBLEMS) {
|
||||
const st = stateForProblem(p);
|
||||
if (!(st.sources.pseudo ?? '').trim() || !st.call) continue;
|
||||
if (!studyOf(st.sources.pseudo).ok) continue;
|
||||
const r = new SyncHub(st.sources, undefined, { call: st.call }).edit('pseudo', st.sources.pseudo);
|
||||
assert.equal(r.sources.pseudo, st.sources.pseudo);
|
||||
assert.match(r.mojo.source, /Generated by Programming\+/, p.id);
|
||||
n++;
|
||||
}
|
||||
assert.ok(n >= 12, `${n} exercises went through the hub`);
|
||||
});
|
||||
|
||||
test('timing: a full cascade (lingo edit -> pseudo, matho, speco, Mojo) on the largest exercise stays under 50 ms', () => {
|
||||
let big = null;
|
||||
for (const p of PROBLEMS) {
|
||||
const st = stateForProblem(p);
|
||||
const t = st.sources.pseudo ?? '';
|
||||
if (t.trim() && studyOf(t).ok && (!big || t.length > big.pseudo.length)) big = { id: p.id, pseudo: t, st };
|
||||
}
|
||||
assert.ok(big);
|
||||
const filled = new SyncHub(big.st.sources, undefined, { call: big.st.call }).fill();
|
||||
// a lingo that reads: whatever the English generator wrote, or, when it has no English, the smallest program
|
||||
const lingo = filled.sources.lingo || pseudoToLingo(SIMPLE).source;
|
||||
const start = filled.sources.lingo ? filled.sources : { lingo };
|
||||
const hub = () => new SyncHub(start, undefined, { call: big.st.call });
|
||||
hub().edit('lingo', lingo); // warm up the engines
|
||||
const times = [];
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const t0 = performance.now();
|
||||
hub().edit('lingo', lingo + (i % 2 ? '' : '\n'));
|
||||
times.push(performance.now() - t0);
|
||||
}
|
||||
times.sort((a, b) => a - b);
|
||||
const median = times[3];
|
||||
assert.ok(median < 50, `${big.id}: the median cascade took ${median.toFixed(1)} ms (limit 50)`);
|
||||
});
|
||||
Reference in new issue
Block a user