A link starts at one of your POPs, for typed orders too
The map only drags a link from a POP, but buildLink, orderDf and orderCable read both ends from UI.pending, which the agent API fills from its arguments. An agent could sign a dark fiber IRU from a city with no POP (Aracaju got three of them). The three orders now refuse that with a toast, and their dry-run quotes report it as blocked. Three tests ordered from a city with no POP (ACT.start ignores city, so the only POP was Frankfurt); they now open the POP they assumed.
This commit is contained in:
parent
ac5ce7fa05
commit
3fd44908af
15 changed files with 77 additions and 9 deletions
|
|
@ -5,7 +5,7 @@ const assert = require('node:assert/strict');
|
|||
const { load } = require('./harness');
|
||||
|
||||
const horn = (ev) => ev("BADGES.find(b=>b.id==='horn').ok()");
|
||||
const start = (ev) => ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=5e9;S.lvl=4;S.won=true;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'bue'})");
|
||||
const start = (ev) => ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=5e9;S.lvl=4;S.won=true;for(const g of GOALS)S.done[g.id]=0;ACT.buildPop({city:'bue'});ACT.launchBB({city:'bue'})");
|
||||
|
||||
test('#272 your own subsea cable from Buenos Aires to Santiago earns The Long Way Round', () => {
|
||||
const { ev, errors } = load();
|
||||
|
|
|
|||
|
|
@ -1285,7 +1285,7 @@ test('#51 a dark fiber shows what is rented out, and spare capacity can be liste
|
|||
|
||||
test('#126 you can zoom in far enough, and pick a short link between two close cities', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({city:'sao'});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;for(const c of ['cpq'])ACT.buildPop({city:c});UI.pending=null;UI.via=null;UI.lmode='wave';UI.route='main';openLinkModal('sao','cpq');ACT.buildLink({tier:1});closeModal()");
|
||||
ev("ACT.start({city:'sao'});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;for(const c of ['sao','cpq'])ACT.buildPop({city:c});UI.pending=null;UI.via=null;UI.lmode='wave';UI.route='main';openLinkModal('sao','cpq');ACT.buildLink({tier:1});closeModal()");
|
||||
assert.ok(ev('ZMAX') >= 16);
|
||||
const id = ev("S.links.find(l=>l.a==='sao'||l.b==='sao').id");
|
||||
// the middle of the drawn link, on screen, fully zoomed in on it
|
||||
|
|
|
|||
56
tests/link-preconditions.test.js
Normal file
56
tests/link-preconditions.test.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// Typed orders (the MCP act tool) name both ends of a link, where the map only drags one from a POP of yours.
|
||||
// A link from a city with no POP is refused, 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(), []);
|
||||
});
|
||||
|
|
@ -54,7 +54,7 @@ test('packages included in the original order stay aligned with its accelerated
|
|||
const { ev, dom } = load();
|
||||
try {
|
||||
setup(ev);
|
||||
ev("S.won=true;UI.pending={a:'sin',b:'lax'};UI.seaterminal=UI.seaengineering=true;ACT.orderCable();S.links=[S.links.at(-1)]");
|
||||
ev("S.won=true;ACT.buildPop({city:'sin'});UI.pending={a:'sin',b:'lax'};UI.seaterminal=UI.seaengineering=true;ACT.orderCable();S.links=[S.links.at(-1)]");
|
||||
assert.equal(ev('S.links[0].subterminal'), ev('S.links[0].ready'));
|
||||
assert.equal(ev('S.links[0].subengineering'), ev('S.links[0].ready'));
|
||||
const ready = ev('S.links[0].ready');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue