Express lightpaths: regen cards for their channels, and dirty connectors dim them (#58)

A regen site added to a fiber that already carries expresses now charges a
regen card for every express channel in that glass, as it does for the
fiber's own channels. One helper, regenAddCost(), prices it for the action,
the fiber panel's button and the MCP dry-run quote, so the three agree.
Lighting an express over existing regen sites already paid its cards
(xpCost); only adding a site later was free for them.

A dirty connector on a fiber is in the glass, so it now dims the expresses
riding that fiber by the same factor (capOf multiplies xpG by xpGlassF over
the express's fibers), and the express's panel names the fiber. The other
link-degrading incidents (MTU mismatch, microbursts, a marginal optic's CRC
errors) belong to the fiber's own routers and optics, which an express
bypasses, as the optic-failure incident already treats them, so they leave
expresses alone. The incident marks the connector with loss.glass=true;
sanitize keeps the flag only when it is true, so an old save's loss loads
as router-side, as it behaved before. A fiber that only carries expresses
can now get the dirty connector too (never the router-side variants), like
the backhoe and amp-hut incidents already find it.
This commit is contained in:
jvanvik 2026-11-09 22:50:04 +01:00
parent 2dc8274f34
commit ae78e82ddb
17 changed files with 123 additions and 9 deletions

View file

@ -4,6 +4,7 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { load } = require('./harness');
const { createSession, TOOLS } = require('../scripts/lib/mcp-game');
// Three POPs on routers that take 400G optics, broadband in Paris, transit in Frankfurt, and two ROADM fibers
// (s1 Frankfurt–Brussels, s2 Brussels–Paris), finished and dark. df(a,b,extra) lays another one.
@ -139,6 +140,103 @@ test('reach: the light must make the whole run between regen sites, through Brus
assert.deepEqual(errors, []);
});
test('a regen site added later under an express needs a regen card for its channels too: the fiber panel and the MCP quote say so', (t) => {
const { ev, errors } = game(t, SPANS + "ACT.buildPop({city:'ams'});S.pops.ams.rgen=1;window.s3=df('fra','ams');compute();");
ev(BUILD + "ACT.xpCh({id:x,o:'zr4',d:1});L(s1).ch=['zr4'];compute()");
assert.equal(ev('L(x).ch.length'), 2);
const card = ev("Math.round(optCost('zr4')*REGEN_CH)"), two = ev("Math.round(optCost('zr4')*2*REGEN_CH)"), three = ev("Math.round(optCost('zr4')*3*REGEN_CH)");
assert.equal(ev('regenAddCost(L(s3))'), ev('REGEN_COST'), 'a dark fiber with nothing in it: the hut alone');
assert.equal(ev('regenAddCost(L(s2))'), ev('REGEN_COST') + two, 'two express channels and nothing of its own');
assert.equal(ev('regenAddCost(L(s1))'), ev('REGEN_COST') + three, 'its own channel and the two expresses');
// The fiber panel's button shows that price, and adding the site charges it.
ev('selectLink(s2)');
assert.ok(ev("$('panel').textContent").includes('Regen site ' + ev('fmt$(REGEN_COST+' + two + ')')), "the price on the fiber's regen button");
let cash = ev('S.cash');
ev('ACT.regen({id:s2,d:1})');
assert.equal(ev('L(s2).regen'), 1);
assert.equal(cash - ev('S.cash'), ev('REGEN_COST') + two);
cash = ev('S.cash');
ev('ACT.regen({id:s3,d:1})');
assert.equal(cash - ev('S.cash'), ev('REGEN_COST'), 'no express on it: no card');
// Lighting another channel afterwards pays its card at the new site, as before.
cash = ev('S.cash');
ev("ACT.xpCh({id:x,o:'zr4',d:1})");
assert.equal(cash - ev('S.cash'), ev("optCost('zr4')") + card);
assert.deepEqual(errors, []);
});
test('a dirty connector in the glass under an express dims it too; an MTU mismatch, microbursts or a marginal optic there do not', (t) => {
const { ev, errors } = game(t);
ev(BUILD + "L(s1).ch=['zr4'];compute()");
const cap = (id) => Math.round(ev(`capOf(L(${id}))`));
assert.equal(cap('x'), 400);
// The fiber's own routers and optics: the fiber suffers, the express riding past them does not.
for (const [set, name] of [['L(s1).deg=S.day+3', 'an MTU mismatch'], ['L(s1).loss={until:S.day+3,f:0.8}', 'microbursts'], ['L(s1).loss={until:S.day+3,f:0.7}', 'a marginal optic']]) {
ev(`L(s1).deg=0;L(s1).loss=null;${set};compute()`);
assert.ok(cap('s1') < 400, name + ' slows the fiber');
assert.equal(cap('x'), 400, name + ' leaves the express alone');
}
// A dirty connector is in the glass: every wave there, the express too.
ev('L(s1).deg=0;L(s1).loss=null;L(s2).loss={until:S.day+3,f:0.6,glass:true};compute()');
assert.equal(cap('x'), 240, 'Brussels–Paris lets 60% through');
assert.equal(ev('linkDown(L(x))'), false, 'dimmed, not dark');
assert.ok(ev('R.load[x]') > 1, 'it still carries traffic');
ev('selectLink(x)');
assert.match(ev("$('panel').textContent"), /Brussels ⇄ Paris has a dirty connector: every wave in that fiber, this express too, runs at 60%/);
ev('L(s1).loss={until:S.day+3,f:0.6,glass:true};compute()');
assert.equal(cap('x'), 144, 'two dirty fibers: both bite');
ev('L(s1).loss.until=S.day;L(s2).loss.until=S.day;compute();selectLink(x)');
assert.equal(cap('x'), 400, 'cleaned: full rate again');
assert.doesNotMatch(ev("$('panel').textContent"), /dirty connector/);
// Dealt by the dice: on a fiber with channels of its own, only the dirty connector (the first of the three) is in the glass.
for (const v of [0, 1, 2]) {
ev(`L(s1).loss=null;L(s2).loss=null;S.inc=[];compute();{const q=[0.5,0.1,${(v + 0.5) / 3},0];const r0=Math.random;Math.random=()=>q.length?q.shift():r0();fireFailure('loss');Math.random=r0;}compute()`);
assert.equal(ev('!!L(s2).loss'), false, 'the dice picked the fiber with its own channel');
if (v !== 1) assert.ok(cap('s1') < 400, 'the fiber itself slows, variant ' + v);
assert.equal(ev('!!(L(s1).loss&&L(s1).loss.glass)'), v === 0, 'variant ' + v);
assert.equal(cap('x'), v === 0 ? 240 : 400, 'variant ' + v);
}
// A fiber that only carries expresses has nothing but glass to go wrong: the dice find it, and it is always the connector.
ev("L(s1).ch=[];L(s1).loss=null;S.inc=[];compute();fireFailure('loss');compute()");
assert.equal(ev('S.inc.at(-1).type'), 'loss');
assert.ok(ev('[s1,s2].includes(S.inc.at(-1).ref)'));
assert.equal(ev('L(S.inc.at(-1).ref).loss.glass'), true);
assert.equal(cap('x'), 240);
// Fixed: the express is back.
ev('clearInc(S.inc.at(-1));compute()');
assert.equal(cap('x'), 400);
assert.deepEqual(errors, []);
});
test('saves: a dirty connector keeps dimming the express after a reload; an old save\'s loss stays on its own fiber', (t) => {
const { ev, errors } = game(t);
ev(BUILD + "L(s2).loss={until:S.day+3,f:0.6,glass:true};compute()");
ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()');
assert.equal(ev('JSON.stringify(L(s2).loss)'), ev('JSON.stringify({until:S.day+3,f:0.6,glass:true})'));
assert.equal(Math.round(ev('capOf(L(x))')), 240);
// A loss from before the connector was told apart, or a hand-edited flag that is not true: router-side, as it was.
for (const loss of ['{until:S.day+3,f:0.6}', '{until:S.day+3,f:0.6,glass:"yes"}']) {
ev(`{const o=JSON.parse(JSON.stringify(S));o.links.find(l=>l.id===s2).loss=${loss};S=migrate(o);compute();}`);
assert.equal(ev('JSON.stringify(L(s2).loss)'), ev('JSON.stringify({until:S.day+3,f:0.6})'), loss);
assert.equal(Math.round(ev('capOf(L(x))')), 400, loss);
}
assert.deepEqual(errors, []);
});
test('MCP: the dry run of a regen site under an express quotes what the game then charges', () => {
const s = createSession(), T = (n, a = {}) => TOOLS.find((x) => x.name === n).run(s, a), ev = (x) => s.game.ev(x);
T('new_game', { city: 'fra', preset: 'sandbox', seed: 7, name: 'Probe' });
ev(BASE.replace(/^ACT\.start\(\{\}\);if\(UI\.pendGame\)ACT\.pitchSkip\(\);/, '') + SPANS + BUILD);
assert.equal(ev("S.links.filter(l=>l.kind==='xp').length"), 1);
const q = T('act', { action: 'regen', args: { id: ev('s1'), d: 1 }, dryRun: true }).quote;
assert.deepEqual(q.blocked, []);
assert.equal(q.setup, ev("REGEN_COST+Math.round(optCost('zr4')*REGEN_CH)"), 'the hut and a card for the express channel');
const c0 = ev('S.cash');
T('act', { action: 'regen', args: { id: ev('s1'), d: 1 } });
assert.equal(q.setup, c0 - ev('S.cash'), 'quote equals charge');
assert.deepEqual(s.errors(), []);
});
test('slots: lit channels, sold alien waves and express channels share every line system', (t) => {
const { ev, errors } = game(t);
ev("L(s1).ch=Array(10).fill('zr4');S.biz.push({id:uid(),city:'fra',city2:'bru',link:s1,slots:53,type:'wwave',name:'Alien Co',bw:1,rate:1000,reqs:[],mood:100,since:S.day});for(const c of ['fra','bru','par'])S.pops[c].routers=4;compute()");