Each zone (Vanua Levu & Taveuni off Suva, the Out Islands off Nassau, and 16 more) is a pool of island homes at your POP in its city: no node and no link on the map, its Gbps join the city's demand. Rent backhaul at the city's teleport (about 35% sign up over GEO, 75% over MEO, 90% over Starblink from a gateway there) or, from level 3, lay a spur cable and everyone may sign up. The first order brings the island kit. Islanders pay island prices, their homes are IPv6-only in the NAT64 pool, and investors on a revenue share take their cut. A spur can be cut for weeks (failure 'wspur', chaos only): a satellite kept beside it carries the islands. Zones are off in puzzles, the Architect, scenarios and below level 2. The satellite geometry works on points now (satSeesAt, satPairAt, satKmAt; the city functions wrap them, with the same answers). Starblink serves a zone only from a gateway in its own city (16 of 18; a gateway anywhere in reach would serve the same 16), with its storm and rival rule; Nunavut and Southeast Alaska stay on GEO. Rules W6 and F12.
317 lines
22 KiB
JavaScript
317 lines
22 KiB
JavaScript
// The act tables of server-run play (scripts/lib/mp-sim-acts.js) against the game itself (the server-sim design, 5.8):
|
|
// SEND is the agent's game commands, adjusted; the CONFIRM table is how each two-click button arms (SRV_ARM is the key
|
|
// its first click writes); DRAFTS are the page-held UI values each act reads, all of them; and for every draft and text
|
|
// act, and every two-click one, the server's pipeline (drafts and arming from the request, then one run) leaves the same
|
|
// network as the page's clicks in jsdom.
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { load } = require('./harness');
|
|
const { lit } = require('../scripts/lib/js-literal');
|
|
const A = require('../scripts/lib/mp-sim-acts');
|
|
const { createEngine } = require('../scripts/lib/mp-sim-engine');
|
|
const { crawl } = require('./lib/mp-sim-crawl');
|
|
const { MP, TEST, ROOMY, page, bigScenic, msg, ctxOf, begin, checked, differs } = require('./lib/mp-sim-play');
|
|
// A local game made a server network, as the host's import does (5.2): the session's marks, then the save path.
|
|
const STAMP = `S.mp={...${JSON.stringify(MP)},seq:0,sim:1};`;
|
|
|
|
const E = createEngine({ workers: 1, test: TEST, timeouts: ROOMY });
|
|
test.after(() => E.close());
|
|
|
|
test('SEND is the agent\'s game commands without the puzzles, teCheck, traceRun and closeModal, with connCancel, pieRename and tutSkip', (t) => {
|
|
const { ev, errors, dom } = load({ agent: true });
|
|
t.after(() => dom.window.close());
|
|
const cmd = JSON.parse(ev('JSON.stringify(Object.keys(API_CMD))'));
|
|
const want = cmd.filter((k) => !/^pz[A-Z]/.test(k) && !['teCheck', 'traceRun', 'closeModal'].includes(k)).concat(['connCancel', 'pieRename', 'tutSkip']).sort();
|
|
assert.deepEqual(A.SEND, want);
|
|
for (const a of [...A.SEND, ...A.ASK]) assert.equal(ev(`typeof ACT[${JSON.stringify(a)}]`), 'function', a);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
|
|
/* A rich network with something behind every two-click button: the big fixture, an intern, a sales head, a scrubbing
|
|
center, a teleport with a LEO gateway, an own exchange, an island Wi-Fi zone with a circuit. Its S also goes to the
|
|
realm, so both sides start the same. */
|
|
function rich() {
|
|
const P = page({ save: bigScenic() });
|
|
P.ev(`S.lvl=Math.max(S.lvl,6);ACT.opsHire({id:'kevin'});closeModal();ACT.salesHire({id:'eng'});closeModal();
|
|
ACT.buildScrub({city:'fra'});closeModal();ACT.teleBuild({city:'sea'});closeModal();ACT.teleLeo({city:'sea'});closeModal();
|
|
ACT.buildPop({city:'suv'});ACT.teleBuild({city:'suv'});ACT.wispSat({z:'vanualevu',bird:'kac1',g:2});closeModal();UI.confirm=null;UI.sel=null;
|
|
S.day=Math.max(S.day,IP4_HOLD+30);S=migrate(JSON.parse(JSON.stringify(S)));compute();`);
|
|
// (Address blocks are held two years before they may be sold: these were bought long ago.)
|
|
return P;
|
|
}
|
|
// Pie in the Sky: a network that won (a Tier 1 club in Frankfurt, as tests/pie-in-the-sky.test.js builds it) and
|
|
// founded a rocket company with a factory, a pad in Singapore and pies on the shelf.
|
|
function pieCo() {
|
|
const P = page();
|
|
P.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e11;S.lvl=6;for(const g of GOALS)S.done[g.id]=0;delete S.done.t1;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=500");
|
|
P.ev("S.transit=[];S.ixp={};S.peers={};S.pni=[];S.grace=null;for(const n of t1Need())S.pni.push({id:'p'+n.id,net:n.id,city:'fra',tier:2});S.nextFail=1e9;S.nextEvent=1e9;compute()");
|
|
P.ev("for(const n of NETS)if(!R.reachable[n.id]){if(!S.pops[n.pops[0]])S.pops[n.pops[0]]={day:0,bb:null,boost:0,down:0,routers:1,gen:false};S.pni.push({id:'i'+n.id,net:n.id,city:n.pops[0],tier:0});}compute();checkGoals();");
|
|
P.ev("ACT.buildPop({city:'sin'});ACT.pieFound();ACT.pieFactory();ACT.piePad({city:'sin'});S.pie.stock=400;closeModal();S.rng=99;uidN=1000;" + STAMP + "S=migrate(JSON.parse(JSON.stringify(S)));compute();");
|
|
return P;
|
|
}
|
|
// A small network with one transit port, Auto-TE and a script slot: a cap on that transit drops most of its traffic
|
|
// (teDeploy's other path, when the AI's script is the one deployed).
|
|
function oneUp() {
|
|
const P = page();
|
|
P.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=3000");
|
|
P.ev("ACT.buyTransit({city:'fra',net:NETS.filter(n=>sellsAt(n,'fra')&&n.price)[0].id,tier:1});ACT.coreUp();ACT.coreUp();S.te={on:true,day:S.day,script:''};closeModal();S.rng=99;uidN=1000;" + STAMP + "S=migrate(JSON.parse(JSON.stringify(S)));compute();");
|
|
P.cap = `cap transit ${P.ev('NETS.find(n=>n.id===S.transit[0].net).name')} at 5 gbps`;
|
|
return P;
|
|
}
|
|
// A Hong Kong and a Shanghai POP and a mainland license: a link between them crosses the border, and may cross it premium.
|
|
const CROSS = "S.cnLic={state:'ok'};for(const c of ['hkg','sha'])if(!S.pops[c])S.pops[c]={day:0,bb:null,boost:0,down:0,routers:1,gen:false};S=migrate(JSON.parse(JSON.stringify(S)));compute();";
|
|
const loadInto = async (code, nid, P) => { const L = checked((await E.load(code, [{ nid, env: { s: P.ev('JSON.stringify(S)'), uidN: +P.ev('uidN'), rt: null }, lang: 'en', prefs: {} }]))[0]); assert.equal(L.err, undefined, L.err); return L; };
|
|
|
|
test('two-click buttons: the first click arms SRV_ARM\'s key (or waits for ok), and confirmed:true on the server is both clicks', async (t) => {
|
|
const P = rich();
|
|
t.after(() => P.close());
|
|
const { ev } = P;
|
|
const code = 'C0NF1R', nid = 'conf0001';
|
|
await loadInto(code, nid, P);
|
|
// Each act's args as its button carries them, from a crawl; the rest made here (they arm before any check).
|
|
const found = {};
|
|
for (const [a, args] of crawl(ev)) if (A.CONFIRM[a] && !found[a]) found[a] = args;
|
|
ev('UI.confirm=null;UI.sel=null;closeModal();');
|
|
// (The gateway closes before its teleport, which would take it along.)
|
|
Object.assign(found, { rmScrub: { city: 'fra' }, teleLeoRm: { city: 'sea' }, teleRm: { city: 'sea' }, cancelVxc: found.cancelVxc || { id: 'nolink' }, dkOptOut: found.dkOptOut || { city: 'fra', n: 'Nobody' } }, found);
|
|
// (A zone's circuit is cancelled before the zone, which would take it along.)
|
|
for (const a of ['wispSatRm', 'wispRm']) { const v = found[a] || { z: 'vanualevu' }; delete found[a]; found[a] = v; }
|
|
const missing = Object.keys(A.CONFIRM).filter((a) => !found[a] && a !== 'repayLoan');
|
|
assert.deepEqual(missing, [], 'a button for every two-click act');
|
|
const changed = {};
|
|
for (const [a, args] of Object.entries(found)) {
|
|
const kind = A.CONFIRM[a];
|
|
// The first click: the page's own (a view change), never sent. S stays; the button is armed.
|
|
ev('UI.confirm=null;');
|
|
const s0 = ev('JSON.stringify(S)');
|
|
ev(`ACT[${JSON.stringify(a)}](${JSON.stringify(args)})`);
|
|
assert.equal(ev('JSON.stringify(S)'), s0, `${a}: the first click changes nothing`);
|
|
const armed = JSON.parse(ev('JSON.stringify(UI.confirm)'));
|
|
if (kind === 'arg') assert.notEqual(armed, null, `${a}: armed`);
|
|
else assert.equal(armed, A.armKey(a, args), `${a}: SRV_ARM's key is what the first click writes`);
|
|
// The second click on the page, and the same click on the server, sent with confirmed:true.
|
|
const ctx = ctxOf(ev);
|
|
if (kind === 'arg') ev(`UI.confirm=null;ACT[${JSON.stringify(a)}](${JSON.stringify({ ...args, ok: 1 })})`);
|
|
else ev(`ACT[${JSON.stringify(a)}](${JSON.stringify(args)})`);
|
|
closeAll(ev);
|
|
const r = checked(await E.act(code, nid, msg(a, args, { confirmed: true, ctx })));
|
|
changed[a] = ev('JSON.stringify(S)') !== s0;
|
|
const want = ev('JSON.stringify(S)'), got = (await E.eval(code, nid, 'return JSON.stringify(S)')).value;
|
|
assert.ok(want === got, `${a} ${JSON.stringify(args)} (${r.outcome}${r.why ? ': ' + r.why : ''}):\n${want === got ? '' : differs(want, got)}`);
|
|
if (changed[a]) assert.equal(r.outcome, 'applied', a);
|
|
}
|
|
// The ones with a real target were really done.
|
|
for (const a of ['cancelTransit', 'cancelIx', 'cancelPni', 'rmLink', 'rmSite', 'dropBiz', 'salesFire', 'opsFire', 'rmScrub', 'teleLeoRm', 'teleRm', 'wispSatRm', 'wispRm', 'connCancel']) if (found[a]) assert.equal(changed[a], true, `${a} did its thing`);
|
|
assert.deepEqual(P.errors, []);
|
|
});
|
|
const closeAll = (ev) => ev('closeModal();');
|
|
|
|
test('repayLoan: armed by its id, repaid by the second click (a network small enough to borrow)', async (t) => {
|
|
const P = page();
|
|
t.after(() => P.close());
|
|
P.ev(`UI.pitched=true;beginState('Packet Pals','fra',{mode:'normal',preset:'oncall',mp:{code:'K7Q2XD',pid:'loan0001',asn:201234,seed:5,preset:'oncall',color:'#3a86ff',title:'x'}});S.mp.sim=1;S.tut=null;compute();
|
|
ACT.launchBB({city:'fra'});spawnLoanOffer(false);ACT.takeLoan({id:S.loanOffers[0].id});closeModal();S.cash+=5e6;uidN=1000;`);
|
|
const id = P.ev('S.loans[0].id');
|
|
const code = 'L0ANS0', nid = 'loan0001';
|
|
await loadInto(code, nid, P);
|
|
P.ev('UI.confirm=null');
|
|
const s0 = P.ev('JSON.stringify(S)');
|
|
P.ev(`ACT.repayLoan({id:'${id}'})`);
|
|
assert.equal(P.ev('JSON.stringify(S)'), s0);
|
|
assert.equal(P.ev('UI.confirm'), A.armKey('repayLoan', { id }));
|
|
P.ev(`ACT.repayLoan({id:'${id}'})`);
|
|
assert.equal(P.ev('S.loans.length'), 0, 'repaid');
|
|
const r = checked(await E.act(code, nid, msg('repayLoan', { id }, { confirmed: true })));
|
|
assert.equal(r.outcome, 'applied');
|
|
assert.equal((await E.eval(code, nid, 'return JSON.stringify(S)')).value, P.ev('JSON.stringify(S)'));
|
|
});
|
|
|
|
/* The UI values an act reads, recorded while it runs (its redraw, after(), and windows left out: they read the page's
|
|
own state to draw it). Every page-held value it reads must be one of its DRAFTS, or the view state of a window (ctx.win,
|
|
WINDOWS: the window it redraws reads it); each of its DRAFTS is read on one of the paths played here. Page-held: what
|
|
the drafts are, what only LOCAL acts write (the windows' view state, the PNI sheet's plan), and the map's own. */
|
|
const WIN_UI = [...new Set(Object.values(A.WINDOWS).flatMap((w) => w.ui || []))];
|
|
const PAGE_HELD = [...new Set([...Object.keys(A.DRAFT_TYPES), ...WIN_UI, 'pniAll', 'lmode', 'dfMode', 'drag', 'snap', 'hover', 'vp', 'nf', 'dtab'])];
|
|
test('DRAFTS: the page-held UI values each act reads, all of them', (t) => {
|
|
const P = rich();
|
|
t.after(() => P.close());
|
|
const SPY = `window.__reads=new Set();window.__spy=()=>{for(const k of new Set(${JSON.stringify(PAGE_HELD)}.concat(Object.keys(UI)))){let v=UI[k];Object.defineProperty(UI,k,{get(){__reads.add(k);return v;},set(x){v=x;},configurable:true,enumerable:true});}};
|
|
window.__unspy=()=>{const r=[...__reads];for(const k of Object.keys(UI)){const d=Object.getOwnPropertyDescriptor(UI,k);const v=d.get?d.get():d.value;Object.defineProperty(UI,k,{value:v,writable:true,configurable:true,enumerable:true});}return r;};`;
|
|
const { ev } = P;
|
|
ev(SPY);
|
|
const near = ev("Object.keys(CITY).filter(c=>!S.pops[c]&&homeOk(c)).sort((a,b)=>kmBetween('ams',a)-kmBetween('ams',b))[0]");
|
|
const sib = ev("(()=>{const l=S.links.find(l=>l.kind==='wave'&&landTrenches(l.a,l.b).length);return l.a+'|'+l.b;})()").split('|');
|
|
const runs = [
|
|
['buildLink', `openLinkModal('fra','${near}')`, { tier: 1 }],
|
|
['buildLink', `openLinkModal('${sib[0]}','${sib[1]}');UI.route='same';`, { tier: 1 }],
|
|
['buildLink', `openLinkModal('lon','nyc');UI.via='land';`, { tier: 1 }],
|
|
['buildLink', CROSS + "openLinkModal('hkg','sha');ACT.cnPrem({v:1});", { tier: 1 }],
|
|
['orderDf', "UI.pending={a:'fra',b:'muc'};UI.dfSrc='lease';UI.dfSys='lite';", {}],
|
|
['orderDf', "UI.pending={a:'fra',b:'muc'};UI.dfSrc='build';UI.dfSys='lite';", {}],
|
|
['orderCable', "UI.pending={a:'lon',b:'nyc'};UI.seaDesign='express';UI.seaterminal=true;UI.seaengineering=false;", {}],
|
|
['decomGo', "UI.decom=new Set(['bet']);", {}],
|
|
['teDeploy', "S.te={on:true,day:S.day,script:''};UI.slop=undefined;", { script: 'prefer cog at fra' }],
|
|
(() => { const Q = oneUp(); return ['teDeploy', `UI.slop=${JSON.stringify(Q.cap)};`, { script: Q.cap }, Q]; })(),
|
|
['pieLaunch', 'UI.pieIns=true;UI.pieLas=false;', { rk: 'falcon', cr: 'short' }, pieCo()],
|
|
];
|
|
const reads = {};
|
|
for (const [act, setup, args, other] of runs) {
|
|
const ev = other ? other.ev : P.ev;
|
|
if (other) { t.after(() => other.close()); ev(SPY); }
|
|
ev(setup);
|
|
ev(`window.__keep=[after,openModal,renderAll,renderPanel,renderLeft,renderHUD,renderHint,renderDash,renderBank];
|
|
after=openModal=renderAll=renderPanel=renderLeft=renderHUD=renderHint=renderDash=renderBank=()=>{};__spy();__reads.clear();`);
|
|
try { ev(`ACT.${act}(${JSON.stringify(args)})`); } finally {
|
|
reads[act] = new Set([...(reads[act] || []), ...JSON.parse(ev('JSON.stringify(__unspy())'))]);
|
|
ev('[after,openModal,renderAll,renderPanel,renderLeft,renderHUD,renderHint,renderDash,renderBank]=__keep;closeModal();');
|
|
}
|
|
const extra = [...reads[act]].filter((k) => PAGE_HELD.includes(k) && !A.DRAFTS[act].includes(k) && !WIN_UI.includes(k));
|
|
assert.deepEqual(extra, [], `${act} reads page-held UI that is not in its DRAFTS`);
|
|
}
|
|
for (const act of Object.keys(A.DRAFTS)) {
|
|
assert.ok(reads[act], `${act} was played`);
|
|
for (const k of A.DRAFTS[act]) assert.ok(reads[act].has(k), `${act} reads ${k}`);
|
|
}
|
|
assert.deepEqual(P.errors, []);
|
|
});
|
|
|
|
test('drafts and texts: the server\'s run of each draft and text act leaves the network the page\'s clicks leave', async (t) => {
|
|
const P = rich();
|
|
t.after(() => P.close());
|
|
const { ev } = P;
|
|
ev("S.te={on:true,day:S.day,script:''};closeModal();UI.sel=null;compute();" + CROSS);
|
|
const code = 'DRAFT5', nid = 'drft0001';
|
|
await loadInto(code, nid, P);
|
|
const near = ev("Object.keys(CITY).filter(c=>!S.pops[c]&&homeOk(c)).sort((a,b)=>kmBetween('ams',a)-kmBetween('ams',b))[0]");
|
|
const script = ev('TE_EXAMPLE'), metric = ev("S.links.find(l=>l.kind==='wave'&&l.a!=='bet'&&l.b!=='bet').id");
|
|
// [act, args, what the page did before the click (its drafts), the drafts sent]
|
|
const plays = [
|
|
['buildLink', { tier: 1 }, `openLinkModal('fra','${near}')`, () => pick(ev, ['pending', 'route', 'via', 'cnPrem'])],
|
|
['buildLink', { tier: 1 }, "openLinkModal('hkg','sha');ACT.cnPrem({v:1});", () => pick(ev, ['pending', 'route', 'via', 'cnPrem'])],
|
|
['orderDf', {}, "UI.pending={a:'fra',b:'muc'};UI.dfSrc='lease';UI.dfSys='lite';", () => pick(ev, ['pending', 'dfSrc', 'dfSys'])],
|
|
['orderCable', {}, "UI.pending={a:'lon',b:'nyc'};UI.seaDesign='express';UI.seaterminal=true;UI.seaengineering=false;", () => pick(ev, ['pending', 'seaDesign', 'seaterminal', 'seaengineering'])],
|
|
['decomGo', {}, "UI.decom=new Set(['bet']);", () => ({ decom: JSON.parse(ev('JSON.stringify([...UI.decom])')) })],
|
|
['teDeploy', { script }, 'UI.slop=undefined;', () => ({ slop: false })],
|
|
['setMetric', { id: metric, v: 'custom' }, '', null],
|
|
['metricSet', { id: metric, v: '42' }, '', null],
|
|
['renameGo', { name: 'Tubular Bells' }, '', null],
|
|
];
|
|
await play(code, nid, ev, plays);
|
|
assert.equal(ev("S.links.filter(l=>l.premium).length"), 1, 'the crossing into Hong Kong went premium');
|
|
// A what-if with its text: the window, and the network as it was.
|
|
const K = checked(await E.ask(code, nid, msg('teCheck', { script })));
|
|
assert.match(K.modal.h, /term/);
|
|
assert.equal((await E.eval(code, nid, 'return JSON.stringify(S)')).value, ev('JSON.stringify(S)'));
|
|
assert.deepEqual(P.errors, []);
|
|
// The rocket company's acts, on a network that won and founded one.
|
|
const Q = pieCo();
|
|
t.after(() => Q.close());
|
|
await loadInto('P1EC0S', 'piec0001', Q);
|
|
await play('P1EC0S', 'piec0001', Q.ev, [
|
|
['pieRename', { name: 'Pie Hard' }, '', null],
|
|
['pieLaunch', { rk: 'falcon', cr: 'short' }, 'UI.pieIns=true;UI.pieLas=false;', () => pick(Q.ev, ['pieIns', 'pieLas'])],
|
|
]);
|
|
assert.deepEqual(Q.errors, []);
|
|
// The AI's script, deployed as it wrote it, drops most of the traffic: its own apology, not the fat-finger one.
|
|
const T = oneUp();
|
|
t.after(() => T.close());
|
|
await loadInto('SL0PPY', 'slop0001', T);
|
|
await play('SL0PPY', 'slop0001', T.ev, [['teDeploy', { script: T.cap }, `UI.slop=${JSON.stringify(T.cap)};`, () => ({ slop: true })]]);
|
|
assert.equal(T.ev("S.log.slice(0,3).some(x=>/AI apologises/.test(x.t))"), true, 'the slop path');
|
|
assert.deepEqual(T.errors, []);
|
|
});
|
|
/* A click inside a window (the page sends it with ctx.modal, and ctx.win names the window): the server redraws that
|
|
window as the page does, never another one (a stand-in that said every window is open had a rocket company's click
|
|
answer with the routing window, and the intern's with the build standard), with the view state only the page holds
|
|
(the intern's POP, the pie window's tab and POP). Every sent button in the windows: the window the page shows after
|
|
its own click against the act's ui.modal or ui.closed, and the network after it. */
|
|
test('a click inside a window: the server answers with the window the page shows, its view state and all', async (t) => {
|
|
const P = rich(), Q = pieCo();
|
|
t.after(() => { P.close(); Q.close(); });
|
|
await loadInto('W1NDW5', 'wind0001', P);
|
|
await loadInto('P1EW1N', 'piew0001', Q);
|
|
const lastPop = "Object.keys(S.pops).sort((a,b)=>CITY[a].name.localeCompare(CITY[b].name)).at(-1)";
|
|
const sets = [
|
|
[P, 'W1NDW5', 'wind0001', [['opsOpen', {}, ''], ['opsOpen', {}, `ACT.opsCity({v:${lastPop}})`], ['utilities', { city: 'fra' }, ''], ['bstdOpen', {}, ''],
|
|
['pniAllOpen', { net: null }, ''], ['salesOpen', {}, ''], ['routingOpen', {}, ''], ['models', {}, ''], ['teEdit', {}, ''], ['ip4Open', {}, '']]],
|
|
[Q, 'P1EW1N', 'piew0001', ['traffic', 'co', 'fly', 'dish'].map((tab) => ['pieOpen', {}, `ACT.pieTab({t:'${tab}'});ACT.pieCity({v:${lastPop}})`])],
|
|
];
|
|
const kind = (h) => (/data-routing/.test(h) ? 'routing' : /data-sheet="bstd"/.test(h) ? 'bstd' : (/<h2[^>]*>([^<]{0,40})/.exec(h) || [, '?'])[1].trim());
|
|
let n = 0;
|
|
const wins = new Set(), seenUi = new Set();
|
|
for (const [X, code, nid, openers] of sets) {
|
|
const { ev } = X;
|
|
ev("window.__mh=null;{const om=openModal;openModal=function(h,c){__mh=String(h);return om.apply(this,arguments);};}");
|
|
const open = (o, x, setup) => ev(`closeModal();UI.confirm=null;ACT[${JSON.stringify(o)}](${JSON.stringify(x)});${setup};__mh=null;`);
|
|
for (const [o, x, setup] of openers) {
|
|
open(o, x, setup);
|
|
if (ev("$('modal').hidden")) continue;
|
|
const seen = new Set();
|
|
const btns = JSON.parse(ev("JSON.stringify([...$('modal').querySelectorAll('[data-act],[data-chg]')].map(el=>{const act=el.dataset.act||el.dataset.chg;let a={};try{a=el.dataset.args?JSON.parse(el.dataset.args):{};}catch(e){}if(el.dataset.chg)a={...a,v:el.value};return [act,a];}))"));
|
|
for (const [act, args] of btns) {
|
|
// (Two-click, draft and text acts have their own tests: a text button reads its field, which the page sends.)
|
|
if (!A.SEND.includes(act) || A.CONFIRM[act] || A.DRAFTS[act] || (A.TEXT[act] && Object.keys(A.TEXT[act]).some((k) => !(k in args))) || seen.has(act)) continue;
|
|
seen.add(act);
|
|
open(o, x, setup);
|
|
const ctx = ctxOf(ev, { modal: true });
|
|
if (ctx.win) { wins.add(ctx.win.k); for (const k of Object.keys(ctx.win.ui || {})) seenUi.add(k); }
|
|
try { ev(`ACT[${JSON.stringify(act)}](${JSON.stringify(args)})`); } catch (e) { /* compared all the same */ }
|
|
const pageWin = ev("$('modal').hidden") ? 'closed' : ev('__mh') || 'unchanged';
|
|
const r = checked(await E.act(code, nid, msg(act, args, { ctx })));
|
|
const ui = r.upd ? JSON.parse(r.upd).acts[0].ui : {};
|
|
const srvWin = ui.modal ? ui.modal.h : ui.closed ? 'closed' : 'unchanged';
|
|
n++;
|
|
const name = (w) => (w === 'closed' || w === 'unchanged' ? w : kind(w));
|
|
assert.ok(srvWin === pageWin, `${o} → ${act} ${JSON.stringify(args)}: the page shows ${name(pageWin)}, the server ${name(srvWin)}${name(pageWin) === name(srvWin) ? ' (another drawing of it)' : ''}`);
|
|
const want = ev('JSON.stringify(S)'), got = (await E.eval(code, nid, 'return JSON.stringify(S)')).value;
|
|
assert.ok(want === got, `${act}:\n${want === got ? '' : differs(want, got)}`);
|
|
}
|
|
}
|
|
// The stand-in is no window once the act is done.
|
|
assert.deepEqual((await E.eval(code, nid, "return [$('modal').hidden,$('modal').className,$('modalCard').innerHTML]")).value, [true, '', '']);
|
|
assert.deepEqual(X.errors, []);
|
|
}
|
|
t.diagnostic(`${n} buttons inside windows sent`);
|
|
assert.ok(n >= 30, `${n} buttons`);
|
|
assert.deepEqual([...wins].sort(), ['bstd', 'ops', 'pie', 'routing'], 'the windows the page named');
|
|
assert.deepEqual([...seenUi].sort(), [...WIN_UI].sort(), 'and their view state');
|
|
// Every view state a window carries is checked in the realm before it is set.
|
|
assert.deepEqual((await E.eval('W1NDW5', 'wind0001', 'return Object.keys(SIM_WINOK).sort()')).value, [...WIN_UI].sort());
|
|
});
|
|
|
|
async function play(code, nid, ev, plays) {
|
|
for (const [act, args, before, ui] of plays) {
|
|
ev(before);
|
|
const ctx = ctxOf(ev), drafts = ui ? ui() : null;
|
|
const s0 = ev('JSON.stringify(S)');
|
|
ev(`ACT.${act}(${JSON.stringify(args)});closeModal();`);
|
|
const r = checked(await E.act(code, nid, msg(act, args, { ...(drafts ? { ui: drafts } : {}), ctx })));
|
|
const want = ev('JSON.stringify(S)'), got = (await E.eval(code, nid, 'return JSON.stringify(S)')).value;
|
|
assert.notEqual(want, s0, `${act} did something on the page`);
|
|
assert.equal(r.outcome, 'applied', `${act}: ${r.why || ''}`);
|
|
assert.ok(want === got, `${act}:\n${want === got ? '' : differs(want, got)}`);
|
|
}
|
|
}
|
|
const pick = (ev, keys) => JSON.parse(ev(`JSON.stringify(Object.fromEntries(${JSON.stringify(keys)}.filter(k=>UI[k]!==undefined&&UI[k]!==null).map(k=>[k,UI[k]])))`));
|
|
|
|
// The gate (5.8 step 6) passes buyTE and the monkey's banana: the game writes S.te and S.monkey as a reload makes them,
|
|
// so the server runs both and leaves the network the page's clicks leave.
|
|
test('buyTE and the banana pass the gate, and leave the network the page leaves', async (t) => {
|
|
const P = page({ save: bigScenic() });
|
|
t.after(() => P.close());
|
|
const code = 'B0YTE0', nid = 'buyt0001';
|
|
P.ev("S.rules=makeRules('oncall');S.cash=Math.max(S.cash,1e9);S.monkey.next=S.day;mkTick(S.day);closeModal();compute();");
|
|
assert.equal(P.ev('mkOn()'), true, 'the monkey is here');
|
|
await loadInto(code, nid, P);
|
|
for (const [act, run] of [['coreUp', 'ACT.coreUp()'], ['coreUp', 'ACT.coreUp()'], ['buyTE', 'ACT.buyTE()'], ['mkBanana', 'ACT.mkBanana({})']]) {
|
|
P.ev(run + ';closeModal();');
|
|
const r = checked(await E.act(code, nid, msg(act, {})));
|
|
assert.equal(r.outcome, 'applied', `${act}: ${r.why || ''}`);
|
|
const want = P.ev('JSON.stringify(S)'), got = (await E.eval(code, nid, 'return JSON.stringify(S)')).value;
|
|
assert.ok(want === got, `${act}:\n${want === got ? '' : differs(want, got)}`);
|
|
}
|
|
assert.deepEqual(JSON.parse(P.ev('JSON.stringify([!!S.te,S.monkey.on])')), [true, 0]);
|
|
assert.deepEqual(P.errors, []);
|
|
});
|