Server-run play, part 1: game prerequisites and shared contracts

Groundwork for running multiplayer games on the session server; nothing
of it is switched on yet, and the plain build is unchanged.

- A new network in two halves (beginState/beginShow), the coach split into
  tutAdvance/coachDom, toastPop split out of toast, bootNotes() for the
  once-per-load toasts, the five text actions take their text as an
  argument, and srvOn() with its two checks in the loop.
- Live state is what a reload makes of it (migrate() is a no-op on it):
  new POPs, ports, PNIs, customers, attacks, dark fiber and the intern's
  notes are written in their saved shape; a 365-day test proves it.
- pniAll and bstdApply check the quote the sheet showed (bstdApply by its
  plan, within 1% for the daily hardware drift; utilityKit too).
- assemble({mp}) leaves src/game/98-server-play/ and its CSS out of every
  page but a multiplayer build's, which also gets a SIM_ID build id.
- Contracts for the server, protocol and browser parts: the action tables
  and envelope check (scripts/lib/mp-sim-acts.js), event fixtures, a shape
  checker, a fake engine, and load({mp:true}) in the test harness.
- route-fuzz judges both pages with one migrate(), so reload repairs of
  the base no longer count as divergences.
This commit is contained in:
jvanvik 2026-11-07 10:26:06 +01:00
parent e25f843526
commit d1e127da67
60 changed files with 2200 additions and 105 deletions

View file

@ -72,6 +72,29 @@ test('pages: the build carries no agent code, and is the page assembled without
assert.deepEqual(errors, []);
});
test('pages: the build carries nothing of server-run play; only a multiplayer build has it, with its build id', () => {
// src/game/98-server-play/ and its CSS are for self-hosted multiplayer copies (MP_API): left out of this page whole,
// and the SIM_ID placeholder stays as it is. Lines of those files (long enough to be theirs, and without labels,
// which the build turns into ids) are looked for in both builds.
const page = require('../scripts/lib/page');
const mp = page.assemble({ mp: true }), lines = mp.html.split('\n'), mine = [];
for (const m of mp.map) if (page.MP_ONLY.some((p) => (p.endsWith('/') ? m.file.startsWith(p) : m.file === p)))
for (let i = m.from; i <= m.to; i++) { const l = lines[i - 1].trim(); if (l.length >= 40 && !/\b(tr|trn|N_)\(/.test(l)) mine.push(l); }
assert.ok(mine.length >= 2, 'the server-play files have lines to look for');
const html = read('index.html');
for (const l of mine) assert.equal(html.includes(l), false, `the page has no "${l.slice(0, 60)}…"`);
assert.match(html, /const SIM_ID=\/\*__SIM_ID__\*\/'';/, 'and no build id');
assert.equal('simId' in JSON.parse(read('version.json')), false);
const MPOUT = fs.mkdtempSync(path.join(os.tmpdir(), 'tubes-pages-mp-'));
try {
execFileSync(process.execPath, ['scripts/build.js'], { cwd: root, stdio: 'pipe', env: { ...process.env, OUT: MPOUT, VERSION: '1.2.3', BUILD_DATE: '2026-10-27', MP_API: '/api/mp' } });
const mph = fs.readFileSync(path.join(MPOUT, 'index.html'), 'utf8'), id = page.simId(mp.html);
for (const l of mine) assert.ok(mph.includes(l), `the multiplayer page has "${l.slice(0, 60)}…"`);
assert.match(mph, new RegExp(`const SIM_ID='${id}';`), 'stamped with its build id');
assert.equal(JSON.parse(fs.readFileSync(path.join(MPOUT, 'version.json'), 'utf8')).simId, id, 'which version.json names too');
} finally { fs.rmSync(MPOUT, { recursive: true, force: true }); }
});
test('pages: only the release workflow deploys, and only with the GitHub Pages actions', () => {
const dir = path.join(root, '.github', 'workflows');
for (const f of fs.readdirSync(dir)) {