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
95 lines
4.4 KiB
JavaScript
95 lines
4.4 KiB
JavaScript
// Stage 8: the sync hub (restructure plan, section 2.3), without any UI. Pseudo is the hub; the pane that is
|
|
// edited is the authority and is never rewritten; an authority with errors changes nothing; a language that
|
|
// cannot say the program goes stale rather than blank; contracts ride along; opening rewrites nothing; and the
|
|
// 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 '../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 '../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() { } };
|
|
|
|
const sync = (r) => ({ authority: r.authority, stale: r.stale, names: r.names });
|
|
const next = (r, lang, text) => new SyncHub(r.sources, sync(r)).edit(lang, text);
|
|
|
|
const COUNT = `FUNCTION COUNT_BASE(B : CHAR, T : STRING) RETURNS INTEGER
|
|
DECLARE Total : INTEGER
|
|
Total <- 0
|
|
FOR EACH C IN T
|
|
IF C == B THEN
|
|
Total <- Total + 1
|
|
ENDIF
|
|
NEXT C
|
|
RETURN Total
|
|
ENDFUNCTION`;
|
|
const SIMPLE = `FUNCTION SUMMED(N : INTEGER, X : LIST OF FLOAT) RETURNS FLOAT
|
|
DECLARE S : FLOAT
|
|
S <- 0.0
|
|
FOR I <- 0 TO N
|
|
S <- S + X[I]
|
|
NEXT I
|
|
RETURN S
|
|
ENDFUNCTION`;
|
|
const WHILE_PSEUDO = FIXTURES['fixture:div-mod'][0];
|
|
|
|
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));
|
|
let events = 0; s.onChange(() => events++);
|
|
const lingo = s.source('lingo').replace('Start with Count at 0.', 'Start with Count at 5.');
|
|
assert.notEqual(lingo, s.source('lingo'));
|
|
s.setSource('lingo', lingo);
|
|
assert.equal(events, 1, 'one change event for the whole cascade');
|
|
assert.equal(s.state.sync.authority, 'lingo');
|
|
assert.equal(s.state.sources.lingo, lingo);
|
|
assert.match(s.source('pseudo'), /Count <- 5/);
|
|
assert.match(s.derivedMojo().source, /count = 5/);
|
|
assert.equal(s.linkState('lingo').kind, 'authority');
|
|
assert.equal(s.linkState('pseudo').kind, 'sync');
|
|
// an unchanged text is not an edit
|
|
s.setSource('lingo', lingo);
|
|
assert.equal(events, 1);
|
|
// Mojo and x86-64 are not linked
|
|
s.setSource('mojo', 'def main():\n pass\n');
|
|
assert.equal(s.state.sync.authority, 'lingo');
|
|
});
|
|
|
|
test('a share link round-trips sync, and a stale pane stays stale', async () => {
|
|
const p = problemById('count-base');
|
|
const s = new Session(stateForProblem(p));
|
|
s.setSource('pseudo', 'FUNCTION BROKEN(\nRETURN');
|
|
assert.equal(s.linkState('lingo').kind, 'stale');
|
|
const blob = await encodeState(s.state);
|
|
const back = await decodeState(blob);
|
|
assert.deepEqual(back.sync, s.state.sync);
|
|
const s2 = new Session(back);
|
|
assert.match(s2.linkState('lingo').reason, /pseudo line/);
|
|
assert.equal(s2.source('pseudo'), 'FUNCTION BROKEN(\nRETURN', 'a state that has been edited is not filled again');
|
|
// a malformed sync field is dropped, not trusted
|
|
const { normalize } = await import('../dist/core/state.js');
|
|
assert.equal(normalize({ v: 3, sync: { authority: 'mojo' } }).sync, undefined);
|
|
});
|
|
|
|
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();
|
|
assert.match(a.source, /^# Generated by Programming\+ from pseudo\./);
|
|
assert.equal(s.derivedMojo(), a, 'the same object while the pseudo and the call are unchanged');
|
|
const diags = checkMojo(a.source).diagnostics.filter((d) => d.severity === 'error');
|
|
assert.deepEqual(diags, []);
|
|
s.setSource('pseudo', s.source('pseudo').replace('Total <- 0', 'Total <- 1'));
|
|
assert.notEqual(s.derivedMojo(), a);
|
|
assert.match(s.derivedMojo().source, /total = 1/);
|
|
s.setCall('COUNT_BASE("C", "CCC")');
|
|
assert.match(s.derivedMojo().source, /count_base\("C", "CCC"\)/);
|
|
// no pseudo, no Mojo
|
|
assert.equal(new Session(emptyState()).derivedMojo().source, '');
|
|
});
|
|
|