Fix the max-prefix freeze at rival exchanges and keep the loop alive

The max-prefix incident looked up an exchange id as a city, the same
bug as #24. Both messages now name the exchange and its city.

frame() now schedules the next frame first and catches a failing day
tick or draw, so one bad lookup shows a warning instead of freezing the
game.
This commit is contained in:
Frederic Jung 2026-10-24 21:02:08 +02:00
parent 16e1f95d1b
commit 988e0c5d15
No known key found for this signature in database
3 changed files with 31 additions and 6 deletions

View file

@ -121,6 +121,22 @@ test('a peer at a rival exchange can de-peer you without stopping the game', ()
ev(`S.peers['ggl@${ix}']=true;window.snub=()=>({why:'Testing.'})`);
ev('dayTick()');
assert.equal(ev(`'ggl@${ix}' in S.peers`), false);
assert.match(ev("document.getElementById('toasts').textContent"), new RegExp(`de-peered you in ${ev(`CITY[ixCity('${ix}')].name`)}`));
assert.match(ev("document.getElementById('toasts').textContent"), new RegExp(`de-peered you at ${ev(`ixName('${ix}')`)} in ${ev(`CITY[ixCity('${ix}')].name`)}`));
assert.deepEqual(errors, []);
});
test('an IX meltdown at a rival exchange names the city, and a failing day tick does not stop the game', () => {
const { ev, errors } = load();
ev("ACT.start({});S.cash=1e8;ACT.buildPop({city:'ams'});ACT.buyIx({city:'ams~2',tier:1});S.day=100");
const src = ev('fireFailure.toString()').replace(/^function fireFailure/, 'function')
.replace('let tot=opts.reduce', "opts.splice(0,opts.length,['funny',1]);let tot=opts.reduce")
.replace('type=pick(f);}', "type='maxpfx';}");
ev('window.__ff=' + src);
ev('__ff()');
assert.match(ev("S.inc.find(i=>i.type==='maxpfx').msg"), /in Amsterdam, is down/);
// a tick that throws is caught, reported once, and the loop keeps going
ev("const dt0=dayTick;window.dayTick=()=>{throw new Error('boom')};UI.speed=1;acc=DAY_MS;last=0;frame(16);window.dayTick=dt0");
assert.equal(ev('UI.tickErr'), true);
assert.match(ev("document.getElementById('toasts').textContent"), /NOC glitched/);
assert.deepEqual(errors.filter(e => !/tick failed/.test(e)), []);
});