buildPop returned without a word for a city that is off the map (the small
Brazilian towns retired in 3d469d9), so the agent API reported no_effect
with no toast. It now toasts that the city is off the map and names the
nearest open city in its country to build in instead, and its dry run
reports that as blocked. An old save that kept a POP there is unchanged.
91 lines
5 KiB
JavaScript
91 lines
5 KiB
JavaScript
// Typed orders (the MCP act tool) name both ends of a link and any city for a POP, where the map only offers what
|
|
// a player can reach: a link dragged from one of your POPs, a POP in a city that is on the map. These hold the same
|
|
// lines: a link from a city with no POP is refused, and so is a POP in a retired small city, each with a toast that
|
|
// says why and a dry run that reports it as blocked.
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { createSession, TOOLS } = require('../scripts/lib/mcp-game');
|
|
|
|
function sandbox() {
|
|
const s = createSession(), T = (name, args = {}) => TOOLS.find((t) => t.name === name).run(s, args), ev = (x) => s.game.ev(x);
|
|
T('new_game', { city: 'sao', preset: 'sandbox', seed: 7, name: 'Probe' });
|
|
const act = (action, args, dryRun) => T('act', { action, args, dryRun });
|
|
return { s, ev, act, pops: () => JSON.parse(ev('JSON.stringify(Object.keys(S.pops).sort())')), links: () => ev('S.links.length') };
|
|
}
|
|
|
|
test('a dark fiber IRU, a wave or a cable from a city with no POP is refused, and its dry run says why', () => {
|
|
const { s, act, pops, links } = sandbox();
|
|
for (const [action, args, city] of [
|
|
['orderDf', { a: 'aju', b: 'rec', source: 'lease', system: 'roadm' }, 'Aracaju'],
|
|
['orderDf', { a: 'rio', b: 'sao', source: 'build', system: 'lite' }, 'Rio de Janeiro'],
|
|
['buildLink', { a: 'bsb', b: 'for', tier: 1 }, 'Brasília'],
|
|
['orderCable', { a: 'for', b: 'lis' }, 'Fortaleza'],
|
|
]) {
|
|
const why = new RegExp(`You have no POP in ${city}`);
|
|
const q = act(action, args, true);
|
|
assert.equal(q.outcome, 'quote', action);
|
|
assert.ok(q.quote.blocked.some((b) => why.test(b)), `${action} ${args.a}→${args.b}: ${JSON.stringify(q.quote.blocked)}`);
|
|
const r = act(action, args);
|
|
assert.equal(r.outcome, 'rejected', `${action} ${args.a}→${args.b}`);
|
|
assert.ok(r.toasts.some((t) => why.test(t)), JSON.stringify(r.toasts));
|
|
assert.equal(r.charged, 0);
|
|
assert.equal(r.cashChange, 0);
|
|
}
|
|
// nothing was built, and no POP opened at either end
|
|
assert.deepEqual(pops(), ['sao']);
|
|
assert.equal(links(), 0);
|
|
assert.deepEqual(s.errors(), []);
|
|
});
|
|
|
|
test('from one of your POPs the same orders still go through and open a POP at the far end', () => {
|
|
const { s, act, pops, links } = sandbox();
|
|
for (const [action, args] of [
|
|
['orderDf', { a: 'sao', b: 'rio', source: 'lease', system: 'roadm' }],
|
|
['buildLink', { a: 'sao', b: 'bsb', tier: 1 }],
|
|
['orderCable', { a: 'rio', b: 'lis' }],
|
|
]) {
|
|
assert.deepEqual(act(action, args, true).quote.blocked, [], action);
|
|
assert.equal(act(action, args).outcome, 'applied', action);
|
|
}
|
|
assert.deepEqual(pops(), ['bsb', 'lis', 'rio', 'sao']);
|
|
assert.equal(links(), 3);
|
|
// the game's own click path is unchanged: the link window from a POP signs the IRU
|
|
const { ev } = sandbox();
|
|
ev("openLinkModal('sao','cwb');UI.lmode='df';UI.dfSrc='lease';UI.dfSys='lite';ACT.orderDf()");
|
|
assert.equal(ev("S.links.filter(l=>l.kind==='df'&&l.a==='sao'&&l.b==='cwb').length"), 1);
|
|
assert.ok(ev('!!S.pops.cwb'));
|
|
assert.deepEqual(s.errors(), []);
|
|
});
|
|
|
|
test('a POP in a retired small city is refused with a toast naming an open city nearby, and its dry run is blocked', () => {
|
|
const { s, ev, act, pops } = sandbox();
|
|
const q = act('buildPop', { city: 'aju' }, true);
|
|
assert.deepEqual(q.quote.blocked, [ev("apiText(popOffWhy('aju'))")]);
|
|
assert.match(q.quote.blocked[0], /Aracaju is off the map/);
|
|
const r = act('buildPop', { city: 'aju' });
|
|
assert.equal(r.outcome, 'rejected');
|
|
assert.ok(r.toasts.some((t) => /Aracaju is off the map.*\n.*Build in Salvador instead/s.test(t)), JSON.stringify(r.toasts));
|
|
assert.equal(r.charged, 0);
|
|
// every retired city names an open city in its own country to build in instead
|
|
const near = JSON.parse(ev(`JSON.stringify(CITIES.filter(c=>c.off).map(c=>{const m=popOffWhy(c.id).match(/Build in (.+) instead/);
|
|
const o=m&&CITIES.find(x=>x.name===m[1]);return {c:c.id,ok:!!o&&!o.off&&o.cc===c.cc};}))`));
|
|
assert.ok(near.length > 0, 'there are retired cities');
|
|
assert.deepEqual(near.filter((x) => !x.ok), []);
|
|
// an open city still takes a POP; an unknown id does nothing and says nothing
|
|
assert.equal(act('buildPop', { city: 'ssa' }).outcome, 'applied');
|
|
ev("ACT.buildPop({city:'nope'})");
|
|
assert.deepEqual(pops(), ['sao', 'ssa']);
|
|
assert.deepEqual(s.errors(), []);
|
|
});
|
|
|
|
test('an old save that kept a POP in a retired city keeps it, and buildPop there stays quiet', () => {
|
|
const { s, ev, act } = sandbox();
|
|
ev("S.pops.aju={day:0,bb:null,boost:0,down:0,routers:1,gen:false};S=migrate(JSON.parse(JSON.stringify(S)));compute()");
|
|
assert.ok(ev("!!S.pops.aju&&cityOn('aju')"));
|
|
const r = act('buildPop', { city: 'aju' });
|
|
assert.equal(r.outcome, 'no_effect');
|
|
assert.deepEqual(r.toasts, []);
|
|
// and a link may start there, since it is one of your POPs
|
|
assert.equal(act('orderDf', { a: 'aju', b: 'rec', source: 'lease', system: 'roadm' }).outcome, 'applied');
|
|
assert.deepEqual(s.errors(), []);
|
|
});
|