Server-run play, part 2: the engine
The engine that runs every network of a server session (server-sim design,
section 4): each network in its own vm realm, realms in a small pool of
worker threads, a promise API for the session host. Nothing uses it yet;
the plain build and the game are unchanged (no file under src/).
- scripts/lib/mp-sim-realm.js: one network in a DONT_CONTEXTIFY realm
running the plain page's game (never the MP page's client folder), with
recording DOM stand-ins, no-op timers that count, and the srv... calls:
load from a checkpoint (route memory seeded, then routed), begin a new
network, marks and restores, the day as a page runs it, the action
pipeline with drafts, arming, the sanitize gate and rollback, what-ifs
that put S, R, the dice and uidN back, pulls with top-level key diffs,
slim R and flow records on demand, fx captured and bounded, saves, cards.
- scripts/lib/mp-sim-worker.js: realms per session in one worker, days one
network at a time with other messages between them, loads and unloads
waiting for a session's day, time limits; a throw goes back to the mark
in place, a timeout gets a fresh realm (new epoch) carrying the old R, a
day is retried once and the network broken after a second failure.
- scripts/lib/mp-sim-engine.js: createEngine() with the fake engine's API,
placement by realm count, every pending call rejected when its worker
exits, a worker of its own after two exits in an hour; snapWith() joins
the host's clock, roster and since to a realm's snapshot.
- Contract: a pulled snapshot is the realm's half (the host adds clock,
roster, since); haptic fx carry milliseconds; the fake engine follows,
with close() and snapWith(). The button crawl moved to tests/lib.
- Tests: realm vs jsdom byte for byte over 60 scenic big-network days with
actions; restore; retry after a throw or a timeout; realm order; a timer
audit and the gate over a sweep of sent buttons (SIM_LONG=1: a year and
every button); captures, rollbacks, asks, selection reports, ordering,
bounds, pollution, worker exits; the act tables against the game.
The gate found two keys the game writes in a shape a reload repairs (buyTE's
S.te, mkLeave's S.monkey): game fixes for the integrator, kept visible as a
todo test and a list in the audit.
Rebased onto the 3.3.0 merge (61e31c5): the engine itself needed no change. A
realm still routes in the game's own code (no route worker, no saves), the
route cache that now keeps list orders from day to day leaves a checkpoint and a
retry the same, and the capacity market and moved customers play in a realm as
on a page, under the strict gate. The tests needed three things: an old save's
first days earn the new traffic badges, which the unwatched network's snapshot
keeps; the restore test compares JSON text with sorted keys instead of a
deep-equal of two networks (a diff of gigabytes when they differ); and the crawl
opens the windows that move a customer, with a new test playing the market's and
the path moves' acts, 40 days of sales and a checkpoint against the page.
This commit is contained in:
parent
61e31c53d3
commit
065c922287
12 changed files with 1906 additions and 29 deletions
|
|
@ -10,6 +10,7 @@ const { lit } = require('../scripts/lib/js-literal');
|
|||
const A = require('../scripts/lib/mp-sim-acts');
|
||||
const { checkEvent, checkFx, checkWorker, parseSse, fixture, FIXTURES } = require('./lib/mp-sim-shape');
|
||||
const { createFakeEngine } = require('./lib/mp-sim-fake-engine');
|
||||
const { crawl } = require('./lib/mp-sim-crawl');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
|
|
@ -44,24 +45,6 @@ test('every ACT is classified once: SEND, ASK, VOTE, LOCAL or PUZZLE; SEND is th
|
|||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
// Every button and drop-down a rich game shows, as the page would send it: [act, args].
|
||||
function crawl(ev) {
|
||||
ev(`window.__btns=[];window.__grab=()=>{for(const el of document.querySelectorAll('[data-act],[data-chg]')){const act=el.dataset.act||el.dataset.chg;let a={};try{a=el.dataset.args?JSON.parse(el.dataset.args):{};}catch(e){a={bad:el.dataset.args};}
|
||||
if(el.dataset.chg){a={...a,v:el.value}}__btns.push([act,a]);}};`);
|
||||
const views = [
|
||||
"for(const c of ['fra','ams','nyc','sin','syd']){for(const tab of ['cust','up','peer','infra','links']){UI.sel={type:'city',id:c};UI.tab=tab;renderPanel();__grab();}}",
|
||||
"for(const l of S.links.slice(0,40)){UI.sel={type:'link',id:l.id};renderPanel();__grab();}",
|
||||
"UI.leftOpen=true;for(const k of ['goals','deals','noc','nets']){UI.left=k;renderLeft();__grab();}",
|
||||
"$('dash').hidden=false;for(const k of DTABS){UI.dtab=k;renderDash();__grab();}$('dash').hidden=true;",
|
||||
'ACT.bank();__grab();ACT.bankClose();',
|
||||
"for(const [a,x] of [['opsOpen',{}],['utilities',{city:'fra'}],['bstdOpen',{}],['pniAllOpen',{net:null}],['pniAllOpen',{net:'cog'}],['salesOpen',{}],['routingOpen',{}],['ip4Open',{}],['models',{}],['decomOpen',{}],['teEdit',{}]]){try{ACT[a](x);}catch(e){}__grab();closeModal();}",
|
||||
"openLinkModal('fra','nyc');__grab();closeModal();openLinkModal('fra','ams');__grab();closeModal();",
|
||||
"UI.confirm=null;for(const t of S.transit.slice(0,3)){UI.sel={type:'city',id:t.city};UI.tab='up';UI.confirm=t.id;renderPanel();__grab();}UI.confirm=null;",
|
||||
];
|
||||
for (const v of views) ev(v);
|
||||
return JSON.parse(ev('JSON.stringify(__btns)'));
|
||||
}
|
||||
|
||||
test('the envelope check passes every button a rich game shows for a sent act, as the page sends it', (t) => {
|
||||
const fsx = require('node:fs');
|
||||
const BIG = fsx.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
||||
|
|
@ -74,7 +57,7 @@ test('the envelope check passes every button a rich game shows for a sent act, a
|
|||
assert.ok(sent.length > 200, `a real sweep: ${sent.length} sent buttons of ${btns.length}`);
|
||||
const acts = new Set(sent.map(([a]) => a));
|
||||
assert.ok(acts.size > 40, `${acts.size} different acts`);
|
||||
for (const q of ['pniAll', 'bstdApply', 'utilityKit']) assert.ok(acts.has(q), `the sweep found ${q}`);
|
||||
for (const q of ['pniAll', 'bstdApply', 'utilityKit', 'mktCfg', 'pathPin']) assert.ok(acts.has(q), `the sweep found ${q}`);
|
||||
for (const [act, args] of sent) {
|
||||
// The page adds the drafts the act reads, as they are, and confirms a two-click act's second click.
|
||||
const ui = A.DRAFTS[act] ? JSON.parse(ev(`JSON.stringify({pending:UI.pending||{a:'fra',b:'ams'},route:UI.route||'',via:UI.via||'',cnPrem:!!UI.cnPrem,dfSrc:'lease',dfSys:'lite',seaDesign:'standard',
|
||||
|
|
@ -207,6 +190,11 @@ test('the fake engine answers every call in the shapes of section 4.2', async ()
|
|||
// The worker built that realm again: a new epoch, versions from 0, so every page of it takes a snapshot.
|
||||
const P3 = await e.pull(code, a, { snap: true });
|
||||
assert.notEqual(P3.epoch, L[0].epoch); assert.equal(P3.v, 0); assert.equal(JSON.parse(P3.snap).epoch, P3.epoch);
|
||||
// A pulled snapshot is the realm's half; with the host's clock, roster and since it is the stream event.
|
||||
const host = { clock: fixture('clock'), roster: fixture('roster'), since: { days: 0, again: 0 } };
|
||||
assert.match(checkEvent(JSON.parse(P3.snap)).join(), /clock: missing/, 'the realm\'s half alone is no stream event');
|
||||
assert.deepEqual(checkEvent(JSON.parse(e.snapWith(P3.snap, host))), []);
|
||||
assert.deepEqual(JSON.parse(e.snapWith(P3.snap, host)).clock, host.clock);
|
||||
all.push(D2, D3, tmo, P3);
|
||||
for (const m of all) assert.deepEqual(checkWorker(m), [], JSON.stringify(m).slice(0, 80));
|
||||
// Held answers wait; a worker that dies rejects everything pending.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue