Deals belong to Sales: the intern sticks to the network, the sales desk signs deals for you, orbit ones too

The NOC intern loses the sales order. Saves that had it load cleanly: sanitize drops the order, its log lines and its
weekly tally, and an intern who was running it hands its switch and minimum to the sales desk (S.slAuto).

With someone at the sales desk, the player can let them sign offers once a game day and decline the ones under a
minimum (39-sales-auto.js), each in their own style: the engineer and the CEO sign after the #185 routing trial (one a
day, a misfit waits a week), the shark signs every offer whose POPs are up, promises and commission included, and the
CEO's declines are a handshake away. Orbit offers need room on their landing dish instead of a trial. Nobody at the
desk (the default; the CEO is a choice, not a given): every deal is signed by hand. The sales desk runs before the
intern's shift, so a deal signed today is in the loads the intern works from. The sheet shows the switch, the minimum
and this week's and last week's tally; the NOC gets one notice a week.

Orbit offers go through the desk too (99-pie-sales.js): they carry o.by, so commission, renewal haggles and each
one's mark at renewal apply. The engineer only offers where the landing dish has 1.5x room on a well-served POP, and
those customers renew like the nerds (0.5x leave). The shark rings airlines, cruise lines and the Mars mission first,
at the biggest size that fits and 25% more, and half of them get a full-sky promise (REQS.skyfull: a crust at 90%)
before there is one; they grumble down to 40 happiness and never cancel over the promise alone. The CEO plays every
other golf game with the Founder: the biggest orbit deal that fits, Mars first, at 30% off; jitters cut his orbit
prices by 0.4x the jitters and from 0.6 the Founder skips golf. Without a salesperson orbit offers are drawn exactly
as before (the O7 balance save has nobody at the desk: payback unchanged, 7.0 years on seed 7, 7.5 on seed 11).

Also: the scenario reference plays 'sales' as the CEO signing for you; the route fuzz leaves out the state and
buttons of a standing order only main still has; the intern's on/off dials (paid peering, keep a spare) show their
translated value in the shipped page instead of the raw label.
This commit is contained in:
Frederic Jung 2026-11-06 09:40:18 +01:00
parent 2243280aff
commit 9a5522bbb1
No known key found for this signature in database
28 changed files with 613 additions and 184 deletions

View file

@ -3,29 +3,29 @@ const assert = require('node:assert/strict');
const { load } = require('./harness');
const { lit } = require('../scripts/lib/js-literal');
// #185's sales and repair engines now run as the NOC intern's standing orders, once per game day.
// #185's engines: the repair one is the NOC intern's standing order, the sales one belongs to the sales desk
// (39-sales-auto.js). Here the engineer, who signs only what the trial says the network can serve, as #185 did.
function setup(ev) {
ev("ACT.start({});S.cash=1e8;S.offers=[];S.biz=[];S.nextFail=S.nextEvent=1e6;for(const g of GOALS)S.done[g.id]=0;S.pops.fra.rgen=3;ACT.buyTransit({city:'fra',net:'lvl',tier:1});S.lvl=2;S.ops.intern='kevin';S.ops.floor=0;S.rules=makeRules('freeze');compute()");
ev("ACT.start({});S.cash=1e8;S.offers=[];S.biz=[];S.nextFail=S.nextEvent=1e6;for(const g of GOALS)S.done[g.id]=0;S.pops.fra.rgen=3;ACT.buyTransit({city:'fra',net:'lvl',tier:1});S.lvl=2;S.ops.intern='kevin';S.ops.floor=0;S.rules=makeRules('freeze');ACT.salesHire({id:'eng'});compute()");
}
const orders = (ev, on) => ev(`for(const k of ${lit(on)})S.ops.on[k]=true`);
const shift = ev => ev('opsDay(S.day)');
const shift = ev => ev('slAutoDay(S.day);opsDay(S.day)');
function offer(ev, id, extra = {}) {
ev(`S.offers.push(${lit({ id, city: 'fra', name: id, type: 'dia', bw: 1, rate: 600, reqs: [], exp: 30, ...extra })})`);
}
test('the sales order signs ready offers once per shift, and pausing it stops it', () => {
test('the sales desk signs ready offers once a day, and switching it off stops it', () => {
const { ev, dom, errors } = load();
setup(ev);
offer(ev, 'first');
shift(ev);
assert.equal(ev('S.biz.length'), 0, 'off by default');
orders(ev, ['sales']);
ev('ACT.salesAuto()');
shift(ev);
assert.equal(ev('S.biz[0].id'), 'first');
ev("ACT.opsToggle({k:'sales'})");
ev('ACT.salesAuto()');
offer(ev, 'off');
ev('dayTick()');
assert.equal(ev('S.biz.length'), 1, 'a paused order signs nothing');
assert.equal(ev('S.biz.length'), 1, 'switched off, it signs nothing');
assert.ok(ev("S.offers.some(o=>o.id==='off')"));
assert.deepEqual(errors, []);
dom.window.close();
@ -41,7 +41,7 @@ test('the trial includes new bandwidth and later offers cannot overbook earlier
assert.equal(ev('!!autoOffer(S.offers[0])'), true);
assert.equal(ev('JSON.stringify(S)'), state);
assert.equal(ev('S===beforeState&&R===beforeResult&&UI.hotMap===beforeHot'), true);
ev('S.ops.on.sales=true;opsDay(S.day)');
ev('S.slAuto.on=true;slAutoDay(S.day)');
assert.equal(ev('S.biz.length'), 1);
assert.equal(ev('S.offers[0].id'), 'two');
assert.ok(ev('bizSf(S.biz[0])') >= 0.95);
@ -49,7 +49,7 @@ test('the trial includes new bandwidth and later offers cannot overbook earlier
dom.window.close();
});
test('the sales order checks actual circuits, latency and NNI capacity', () => {
test('the sales desk checks actual circuits, latency and NNI capacity', () => {
const { ev, dom, errors } = load();
setup(ev);
ev("ACT.buildPop({city:'ams'});S.pops.ams.rgen=3;compute()");
@ -65,7 +65,7 @@ test('the sales order checks actual circuits, latency and NNI capacity', () => {
offer(ev, 'fabric-one', { type: 'fabip', prov, bw: bandwidth, reqs: ['nni'] });
offer(ev, 'fabric-two', { type: 'fabip', prov, bw: bandwidth, reqs: ['nni'] });
// Transit has enough headroom, so the second rejection is the shared NNI port.
ev("S.transit[0].tier=4;compute();S.ops.on.sales=true;opsDay(S.day)");
ev("S.transit[0].tier=4;compute();S.slAuto.on=true;slAutoDay(S.day)");
assert.equal(ev('S.biz.length'), 1);
assert.equal(ev('S.offers[0].id'), 'fabric-two');
assert.ok(ev("nniUsed('fra',fabric)<=NNI[0].g"));
@ -95,7 +95,7 @@ test('fiber sales check live equipment and free spectrum, and repeated carrier o
assert.equal(ev('!!autoOffer(S.offers[0])'), false);
ev("S.offers[0].slots=1;S.offers[0].name='Same Carrier';S.links[0].eqDown=10;compute()");
assert.equal(ev('!!autoOffer(S.offers[0])'), false, 'a broken amplifier prevents a wave sale');
ev('S.links[0].eqDown=0;compute();S.ops.on.sales=true;opsDay(S.day)');
ev('S.links[0].eqDown=0;compute();S.slAuto.on=true;slAutoDay(S.day)');
assert.equal(ev('S.biz.length'), 1);
assert.equal(ev('S.biz[0].slots'), 2);
assert.equal(ev('S.biz[0].rate'), 1600);
@ -111,7 +111,7 @@ test('capacity pair sales need completed infrastructure and reserve it for the a
assert.equal(ev('!!autoOffer(S.offers[0])'), false);
ev("ACT.buildPop({city:'ams'});S.links=[{id:'own',a:'fra',b:'ams',kind:'df',own:true,sys:'roadm',ch:[],km:450,sub:false,ready:0,cut:0,mo:1}];compute()");
assert.equal(ev('!!autoOffer(S.offers[0])'), true);
ev('S.ops.on.sales=true;opsDay(S.day)');
ev('S.slAuto.on=true;slAutoDay(S.day)');
assert.equal(ev('S.biz[0].link'), 'own');
assert.equal(ev('capPend(S.biz[0])'), true, 'normal delivery handover still happens on a game day');
offer(ev, 'second-pairs', { type: 'capfib', city2: 'ams', slots: 2, win: 90 });
@ -125,7 +125,7 @@ test('future event demand is tested before signing, with booked events reserving
setup(ev);
offer(ev, 'event', { type: 'event', bw: 80, rate: 0, start: 10, dur: 3, fee: 5000, exp: 9 });
assert.equal(ev('!!autoOffer(S.offers[0])'), true);
ev('S.ops.on.sales=true;opsDay(S.day)');
ev('S.slAuto.on=true;slAutoDay(S.day)');
assert.equal(ev('S.biz[0].start'), 10, 'the trial does not move the actual event date');
assert.equal(ev('R.cityDem.fra'), 0);
offer(ev, 'too-large', { bw: 30 });
@ -184,7 +184,7 @@ test('the repair order rushes affordable repairs once, skips unaffordable and ex
dom.window.close();
});
test('the sales order leaves unready and expired offers alone without failure notifications', () => {
test('the sales desk leaves unready and expired offers alone without failure notifications', () => {
const { ev, dom, errors } = load();
setup(ev);
offer(ev, 'generator', { reqs: ['gen'] });
@ -193,11 +193,11 @@ test('the sales order leaves unready and expired offers alone without failure no
offer(ev, 'expired', { exp: 0 });
offer(ev, 'ipv6', { reqs: ['ipv6'] });
const log = ev('S.log.length');
ev('S.ops.on.sales=true;opsDay(S.day)');
ev('S.slAuto.on=true;slAutoDay(S.day)');
assert.equal(ev('S.biz.length'), 0);
assert.equal(ev('S.offers.length'), 5);
assert.equal(ev('S.log.length'), log, 'no failed manual-action toasts and no shift line when nothing got done');
ev('S.pops.fra.gen=true;compute();opsDay(S.day)');
assert.equal(ev('S.log.length'), log, 'no failed manual-action toasts and no notice when nothing got done');
ev('S.pops.fra.gen=true;compute();slAutoDay(S.day)');
assert.equal(ev('S.biz.length'), 1);
assert.equal(ev('S.biz[0].id'), 'generator');
// Manual acceptance keeps its existing sign-now, provision-later behavior.
@ -207,15 +207,17 @@ test('the sales order leaves unready and expired offers alone without failure no
dom.window.close();
});
test('the #185 toggles in old saves become the sales and repair orders, malformed ones stay off', () => {
test('#185\'s auto-repair toggle in old saves becomes the repair order; its auto-accept, which never ran without an intern, goes', () => {
const { ev, dom, errors } = load();
setup(ev);
ev("delete S.ops;S.autoSales=true;S.autoRepair=true;S=migrate(JSON.parse(JSON.stringify(S)))");
assert.equal(ev('S.ops.on.sales&&S.ops.on.repair'), true);
ev("delete S.ops;delete S.slAuto;S.autoSales=true;S.autoRepair=true;S=migrate(JSON.parse(JSON.stringify(S)))");
assert.equal(ev('S.ops.on.repair'), true);
assert.equal(ev("'sales' in S.ops.on"), false, 'the intern has no sales order any more');
assert.equal(ev('S.slAuto.on'), false, 'nothing signs on its own that did not before');
assert.equal(ev("'autoSales' in S||'autoRepair' in S"), false);
assert.equal(ev('S.ops.intern'), null, 'no intern until you hire one, so nothing runs yet');
ev("delete S.ops;S.autoSales='true';S.autoRepair=1;S=migrate(S)");
assert.equal(ev('S.ops.on.sales||S.ops.on.repair'), false);
assert.equal(ev('S.ops.on.repair'), false);
assert.deepEqual(errors, []);
dom.window.close();
});

275
tests/sales-auto.test.js Normal file
View file

@ -0,0 +1,275 @@
// Deals belong to Sales: the NOC intern has no sales order any more, the sales desk signs deals for you in its own
// style (src/game/60-features/39-sales-auto.js), and orbit offers go through the desk too (99-pie-sales.js).
const test = require('node:test');
const assert = require('node:assert/strict');
const { load } = require('./harness');
const { lit } = require('../scripts/lib/js-literal');
// Frankfurt with 400G transit, level 4, nothing breaking, Change Freeze (no fat fingers).
const BASE = "ACT.start({});S.cash=1e8;for(const g of GOALS)S.done[g.id]=0;S.lvl=4;S.nextFail=S.nextEvent=1e9;UI.speed=0;S.rules=makeRules('freeze');S.offers=[];S.biz=[];" +
"ACT.launchBB({city:'fra'});S.pops.fra.rgen=3;ACT.buyTransit({city:'fra',net:'lvl',tier:3});compute()";
function game(t, who) {
const h = load();
t.after(() => h.dom.window.close());
h.ev(BASE);
if (who) h.ev(`ACT.salesHire({id:'${who}'});closeModal()`);
return h;
}
const offer = (ev, id, extra = {}) => ev(`S.offers.push(${lit({ id, city: 'fra', name: id, type: 'dia', bw: 1, rate: 6000, reqs: [], exp: 60, ...extra })})`);
const ids = (ev, k) => JSON.parse(ev(`JSON.stringify(S.${k}.map(x=>x.id))`));
const desk = ev => ev('slAutoDay(S.day)');
test('an old save whose intern ran the sales order loads cleanly: the order is gone, its settings are at the sales desk', t => {
const { ev, dom, errors } = game(t);
ev("ACT.opsHire({id:'kevin'});closeModal()");
// What 2.10 saved: the order on with its dials, a day that only signed and declined, a week's tally of it.
ev(`S.ops.on.sales=true;S.ops.p.sales={acc:true,min:5000};S.ops.on.repair=true;
S.ops.log=[{d:3,i:'kevin',r:[['sales',2,[]],['decline',5,[]]]},{d:2,i:'kevin',r:[['sales',1,[]],['repair',1,[]]]},{d:1,i:'kevin',r:[]}];
S.ops.wk={w:0,i:'kevin',n:{sales:3,decline:5,repair:1},wh:{},up:0,mo:0,rev:18000,ff:0};S.ops.rep={w:0,i:'kevin',n:{sales:1},wh:{},up:0,mo:0,rev:6000,ff:0};
delete S.slAuto;S=migrate(JSON.parse(JSON.stringify(S)))`);
assert.deepEqual(JSON.parse(ev('JSON.stringify(Object.keys(S.ops.on))')).includes('sales'), false, 'no sales order');
assert.equal(ev("'sales' in S.ops.p"), false);
assert.equal(ev('S.ops.on.repair'), true, 'everything else the intern did stays');
assert.equal(ev("JSON.stringify(S.ops.log)"), '[{"d":2,"i":"kevin","r":[["repair",1,[]]]},{"d":1,"i":"kevin","r":[]}]', 'a day of only deals has nothing left to say');
assert.equal(ev("JSON.stringify(S.ops.wk)"), '{"w":0,"i":"kevin","n":{"repair":1},"wh":{},"up":0,"mo":0,"ff":0}');
assert.equal(ev('S.ops.rep'), null, 'a report of only deals goes');
assert.equal(ev('JSON.stringify(S.slAuto)'), '{"on":true,"min":5000,"wk":null,"rep":null}', 'the switch and the minimum moved to the sales desk');
// Nobody runs sales in that save, so nothing signs on its own yet: the player signs by hand, as without the intern.
assert.equal(ev('slP()'), null);
offer(ev, 'tiny', { rate: 600 }); offer(ev, 'ready');
ev('for(let i=0;i<3;i++)dayTick()');
assert.deepEqual(ids(ev, 'offers').slice(0, 2), ['tiny', 'ready'], 'nothing declined, nothing signed');
assert.equal(ev('S.biz.length'), 0);
ev("ACT.accept({id:'ready'})");
assert.deepEqual(ids(ev, 'biz'), ['ready'], 'by hand, as before');
// The Ops sheet has no sales order, and every order it shows still has a switch.
dom.window.innerWidth = 360; ev('opsModal()');
const doc = dom.window.document, ks = [...doc.querySelectorAll('#modalCard [data-act="opsToggle"]')].map(b => JSON.parse(b.dataset.args).k);
assert.deepEqual(ks, JSON.parse(ev('JSON.stringify(OPS.map(o=>o.k))')));
assert.ok(!ks.includes('sales'));
assert.doesNotMatch(doc.getElementById('modalCard').textContent, /Handle sales|signed|declined/);
// An intern who was not hired never ran the order: nothing to carry over.
ev("S.ops.intern=null;S.ops.on.sales=true;delete S.slAuto;S=migrate(JSON.parse(JSON.stringify(S)))");
assert.equal(ev('S.slAuto.on||S.slAuto.min'), 0);
// Junk at the desk is repaired.
ev("S.slAuto={on:'yes',min:1234,wk:{w:'x',p:'pirate'},rep:{w:2,p:'eng',n:-4,rev:9e99,x:3,y:'a'}};S=migrate(S)");
assert.equal(ev('JSON.stringify(S.slAuto)'), '{"on":false,"min":0,"wk":null,"rep":{"w":2,"p":"eng","n":0,"rev":10000000000,"x":3,"y":0}}');
assert.deepEqual(errors, []);
});
test('nobody at the desk: nothing is signed for you, and the sheet says how to change that', t => {
const { ev, dom, errors } = game(t);
ev('S.slAuto.on=true;S.slAuto.min=5000');
offer(ev, 'tiny', { rate: 600 }); offer(ev, 'ready');
desk(ev);
assert.deepEqual(ids(ev, 'offers'), ['tiny', 'ready']);
ev('ACT.salesAuto();ACT.salesMin()');
assert.equal(ev('S.slAuto.on&&S.slAuto.min===5000'), true, 'the switches need someone at the desk');
ev('ACT.salesOpen()');
assert.match(dom.window.document.getElementById('modalCard').textContent, /you sign every deal by hand/);
assert.equal(dom.window.document.querySelector('#modalCard [data-act="salesAuto"]'), null);
assert.deepEqual(errors, []);
});
test('the engineer signs only what the trial says the network can serve: one trial a day, a misfit waits a week', t => {
const { ev, errors } = game(t, 'eng');
ev('ACT.salesAuto();ACT.salesMin();ACT.salesMin()');
assert.equal(ev('S.slAuto.on&&S.slAuto.min'), 5000);
offer(ev, 'tiny', { rate: 600 }); offer(ev, 'gen', { reqs: ['gen'] }); offer(ev, 'huge', { bw: 1e5, rate: 600 }); offer(ev, 'ok');
ev("window.__t=0;window.__a=autoOffer;autoOffer=o=>{__t++;return __a(o)}");
desk(ev);
assert.equal(ev('__t'), 1, 'one routing trial a day');
assert.deepEqual(ids(ev, 'offers'), ['gen', 'huge', 'ok'], 'the tiny one is declined; the unmet promise waits without a trial');
ev('S.day++'); desk(ev);
assert.deepEqual(ids(ev, 'biz'), ['ok']);
assert.equal(ev("S.biz[0].by"), undefined, 'an offer nobody brought stays nobody\'s');
assert.equal(ev('JSON.stringify([S.slAuto.wk.n,S.slAuto.wk.x])'), '[1,1]', 'the week\'s tally');
ev('S.day++'); desk(ev);
assert.equal(ev('__t'), 2, 'the misfit is not tried again within the week');
ev('S.day+=7'); desk(ev);
assert.equal(ev('__t'), 3);
ev('autoOffer=__a');
assert.deepEqual(errors, []);
});
test('the shark signs every offer the moment it lands, promises and all, while the cash covers the commission', t => {
const { ev, errors } = game(t, 'shark');
ev('ACT.salesAuto()');
offer(ev, 'gen', { reqs: ['gen'], by: 'shark' }); offer(ev, 'a', { by: 'shark' }); offer(ev, 'b', { bw: 1e5, rate: 600 });
ev("window.__t=0;window.__a=autoOffer;autoOffer=o=>{__t++;return __a(o)}");
const c0 = ev('S.cash');
desk(ev);
assert.equal(ev('__t'), 0, 'no trial: the shark does not ask the NOC');
assert.deepEqual(ids(ev, 'biz'), ['gen', 'a', 'b'], 'all three, the one the network cannot carry too');
assert.equal(c0 - ev('S.cash'), 12000, 'a month of each of his own deals as commission');
ev('autoOffer=__a');
ev('S.cash=1000'); offer(ev, 'c', { by: 'shark' });
desk(ev);
assert.deepEqual(ids(ev, 'offers'), ['c'], 'no cash for the commission: it waits');
assert.deepEqual(errors, []);
});
test('the CEO signs after a trial, and a decline is a handshake away; this week\'s and last week\'s tally in the sheet', t => {
const { ev, dom, errors } = game(t, 'ceo');
ev('ACT.salesAuto();for(let i=0;i<5;i++)ACT.salesMin()');
assert.equal(ev('S.slAuto.min'), 50000);
ev('window.__r=0;window.__r0=Math.random;Math.random=()=>{__r++;return __r0();}');
ev("for(let i=0;i<60;i++)S.offers.push({id:'d'+i,city:'fra',name:'Deal '+i,type:'dia',bw:1,rate:600,reqs:[],exp:60})");
desk(ev);
ev('Math.random=__r0');
assert.equal(ev('__r'), 0, 'hashes, not the game\'s random stream');
const y = ev('S.slAuto.wk.y');
assert.equal(ev('S.offers.length'), 0, 'every tiny one declined');
assert.ok(y >= 10 && y <= 30, `about one in three already shaken on (${y} of 60)`);
assert.equal(ev("S.biz.filter(b=>b.by==='ceo').length"), y);
const w = ev('S.slAuto.wk.w');
ev('S.day=(S.slAuto.wk.w+1)*7'); desk(ev);
assert.equal(ev('S.slAuto.rep.w'), w, 'a new week: last week is the report');
assert.match(ev('S.log[0].t'), new RegExp(`^Sales desk Last week the CEO declined 60 tiny offers, signed ${y} of those anyway\\.$`));
ev('S.slAuto.min=0'); offer(ev, 'fit');
desk(ev);
assert.ok(ids(ev, 'biz').includes('fit'), 'and signs what fits');
dom.window.innerWidth = 360; ev('ACT.salesOpen()');
const card = dom.window.document.getElementById('modalCard');
assert.equal(card.querySelectorAll('.sl-auto .ops-rep').length, 2, 'last week, and this week so far');
assert.match(card.querySelector('.sl-auto').textContent, /This week the CEO signed a customer \(\+\$6\.0k\/mo\)\./);
ev("UI.left='deals';renderLeft()");
assert.match(dom.window.document.getElementById('left').textContent, /This week the CEO signed a customer/, 'and on the desk\'s card in Deals');
assert.deepEqual(errors, []);
});
test('the sales sheet with signing for you works at 360 px in every language', t => {
for (const lang of ['en', 'de', 'es', 'fr', 'it', 'pt']) {
const h = load(lang === 'en' ? {} : { lang });
const { ev, dom, errors } = h;
ev(BASE); dom.window.innerWidth = 360;
const doc = dom.window.document;
ev("ACT.phoneTab({t:'deals'})");
doc.querySelector('#leftBody [data-act="salesOpen"]').click();
doc.querySelector('#modalCard [data-act="salesHire"][data-args*="eng"]').click();
doc.querySelector('#modalCard [data-act="salesAuto"]').click();
assert.equal(doc.querySelector('#modalCard [data-act="salesAuto"]').getAttribute('aria-pressed'), 'true', lang);
doc.querySelector('#modalCard [data-act="salesMin"]').click();
assert.equal(ev('S.slAuto.min'), 2000, lang);
assert.doesNotMatch(doc.getElementById('modalCard').textContent, /\b(sales|ops)\.[a-z_]+/, lang);
assert.deepEqual(errors, [], lang);
dom.window.close();
}
});
/* ---------- orbit ---------- */
// A sandbox with London, New York and Frankfurt, a company, a 16-antenna dish with landing rights at each POP and a
// lasered Shortcrust at cov (1: full).
function sky(t, who, cov = 1) {
const h = load();
t.after(() => h.dom.window.close());
const { ev } = h;
ev("ACT.modeSet({m:'sandbox'});ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.nextFail=1e9;S.nextEvent=1e9;S.pieV=1;S.lvl=13;S.offers=[];S.biz=[]");
ev("for(const c of ['lon','nyc','fra'])if(!S.pops[c])ACT.buildPop({city:c});S.links=S.links.filter(l=>0);"
+ "S.links.push({id:'ln',a:'lon',b:'nyc',kind:'wave',tier:3,km:5818,sub:true,cable:'grace',cut:0,mo:1},{id:'lf',a:'lon',b:'fra',kind:'wave',tier:3,km:640,sub:false,cut:0,mo:1});for(const c of ['lon','nyc','fra'])ACT.buyTransit({city:c,net:'cog',tier:1})");
ev("ACT.pieFound();for(const c of ['lon','nyc','fra']){ACT.pieDish({city:c});S.pie.lic[CITY[c].cc]={state:'ok',until:1e6};}for(const x of S.pie.dishes)x.ant=PIE_ANT_MAX");
ev(`S.pie.crusts.short.cohorts=[{n:Math.ceil(CRUSTS.short.full*${cov}),day:S.day,las:true}];compute()`);
if (who) ev(`ACT.salesHire({id:'${who}'});closeModal()`);
return h;
}
// n orbit offers as the day brings them (pieSpawn on an empty table, compute kept), by whoever is at the desk.
const spawn = (ev, n = 300) => JSON.parse(ev(`(()=>{const out=[];for(let i=0;i<${n};i++){S.offers=[];const t=pieOfferTypes();if(!t.length)break;pieSpawn(pick(pieSlTypes(t)));for(const o of S.offers)out.push({t:o.type,by:o.by||null,bw:o.bw,rate:o.rate,list:BIZ_T[o.type].rate,reqs:o.reqs.slice(),city:o.city});}S.offers=[];return JSON.stringify(out);})()`));
const avg = (l, f) => l.reduce((a, x) => a + f(x), 0) / Math.max(1, l.length);
test('orbit offers without a salesperson are what they were: nobody\'s, list price, no promises', t => {
const { ev, errors } = sky(t);
const o = spawn(ev);
assert.ok(o.length > 200);
assert.ok(o.every(x => x.by === null && x.rate === x.list && !x.reqs.length));
assert.deepEqual(errors, []);
});
test('the engineer sells orbit only where the dish has room to spare, and those customers stay', t => {
const { ev, errors } = sky(t, 'eng');
const o = spawn(ev);
assert.ok(o.length > 200 && o.every(x => x.by === 'eng' && x.rate === x.list && !x.reqs.length));
// Every dish nearly full: the room left fits the smallest deal, but not with the engineer's headroom.
ev("S.biz=[];window.__room=()=>{const ds=pieDishes();return ds.map(d=>d.g)};for(const c of ['lon','nyc','fra'])S.biz.push({id:'fill'+c,type:'pizza',city:c,city2:null,bw:pieDishes().find(d=>d.city===c).g-30,rate:1,reqs:[],latMax:null,route:'normal',name:'Fill '+c,mood:100,since:0,sites:null});compute()");
assert.ok(ev("pieOfferTypes().length") > 0, 'the market still has room');
assert.equal(spawn(ev, 50).filter(x => x.t === 'flywifi').length, 0, 'not even a 20G airline where the dish has 30G left');
ev("S.salesBak=S.sales.p;S.sales.p=null");
assert.ok(spawn(ev, 50).some(x => x.t === 'flywifi'), 'without them, that airline is offered');
ev('S.sales.p=S.salesBak;delete S.salesBak');
assert.equal(ev("salesLeaveMul({by:'eng',type:'pizza'})"), 0.5, 'their orbit customers renew like the nerds');
assert.equal(ev("salesLeaveMul({by:'eng',type:'dia'})"), 0.75);
assert.deepEqual(errors, []);
});
test('the shark sells airlines and cruise lines, the biggest that fits at a quarter more, and promises a full sky', t => {
const { ev, errors } = sky(t, 'shark', 0.7);
const plain = (() => { ev("S.sales.p=null"); const x = spawn(ev); ev("S.sales.p='shark'"); return x; })();
const o = spawn(ev);
assert.ok(o.every(x => x.by === 'shark' && x.rate === Math.round(x.list * 1.25)));
assert.ok(o.every(x => ['flywifi', 'boat', 'marsorb'].includes(x.t)), 'no pizza homes while bigger fish are around');
const size = l => avg(l, x => x.bw * x.rate);
assert.ok(size(o) > size(plain) * 1.5, `bigger deals (${Math.round(size(o))} vs ${Math.round(size(plain))} a month)`);
const over = o.filter(x => x.reqs.includes('skyfull')).length / o.length;
assert.ok(over > 0.35 && over < 0.65, `half of them promised a full sky at 70% (${Math.round(over * 100)}%)`);
// Signing one pays the commission; the promise makes them grumble, never cancel, until the sky is full.
ev("S.offers=[];for(let i=0;i<50&&!S.offers.some(o=>o.reqs.includes('skyfull'));i++){S.offers=[];pieSpawn('boat');}");
const r = JSON.parse(ev("(()=>{const o=S.offers[0],c=S.cash;ACT.accept({id:o.id});const b=S.biz.find(b=>b.id===o.id);return JSON.stringify({paid:c-S.cash,mo:b.bw*b.rate,by:b.by});})()"));
assert.equal(r.by, 'shark');
assert.equal(r.paid, r.mo, 'a month of the deal as commission');
// One the sky serves in full (a full dish is the shark's other way to oversell), promised more than it has.
ev("S.biz=[{id:'cruise',type:'boat',city:'lon',city2:null,bw:50,rate:34375,reqs:['skyfull'],latMax:null,route:'normal',name:'Promised Cruises',mood:100,since:-100,sites:null,by:'shark'}];compute()");
assert.ok(ev("bizSf(S.biz[0])") >= 0.95, 'served in full');
ev("const b=S.biz[0];window.__m=[];for(let i=0;i<80;i++){dayTick();__m.push(Math.round(b.mood));}");
const m = JSON.parse(ev('JSON.stringify(__m)'));
assert.ok(ev('S.biz.length') === 1 && m.at(-1) === ev('PIE_GRUMBLE'), `grumbles down to ${ev('PIE_GRUMBLE')} and stays (${m.slice(0, 5)}…${m.at(-1)})`);
ev("S.pie.crusts.short.cohorts=[{n:CRUSTS.short.full,day:S.day,las:true}];compute();for(let i=0;i<10;i++)dayTick()");
assert.ok(ev('S.biz[0].mood') > m.at(-1), 'a full sky keeps the promise: happier again');
assert.deepEqual(errors, []);
});
test('the CEO and the Founder sign a big orbit deal on the golf course at 30% off; jumpy markets cost him', t => {
const { ev, errors } = sky(t, 'ceo', 0.8);
const golfDay = ev("(()=>{for(let d=S.day+1;d<S.day+400;d++)if(slR('golfsky|'+d)<PIE_GOLF_SKY)return d;})()");
ev('window.__r=0;window.__r0=Math.random;Math.random=()=>{__r++;return __r0();}');
ev(`S.day=${golfDay};salesGolf(S.day)`);
ev('Math.random=__r0');
assert.equal(ev('__r'), 0, 'no draws from the game\'s random stream');
const b = JSON.parse(ev("JSON.stringify(S.biz.at(-1))"));
assert.equal(b.type, 'marsorb', 'the Mars mission first');
assert.equal(b.by, 'ceo');
assert.equal(b.rate, Math.round(ev('BIZ_T.marsorb.rate') * 0.7), '30% off list');
assert.deepEqual(b.reqs, ['skyfull'], 'with a promise nobody checked (the crust is at 80%)');
assert.match(ev('S.log[0].t'), /The CEO and the Founder signed .+ on the golf course: .+ in orbit over .+, 30% off list\. He also promised: Promised a full sky/);
// Jitters: his own orbit offers get cheaper, a golf deal too, and from 0.6 the Founder does not show up.
ev('S.pie.founder.jit=0.5');
const o = spawn(ev, 50);
assert.ok(o.every(x => x.by === 'ceo' && x.rate === Math.round(x.list * 0.8)), 'orbit prices 20% down at jitters 0.5');
const n = ev('S.biz.length');
ev(`salesGolf(${golfDay})`);
assert.equal(ev('S.biz.length'), n + 1);
assert.equal(ev('S.biz.at(-1).rate'), Math.round(ev(`BIZ_T.${ev('S.biz.at(-1).type')}.rate`) * 0.7 * 0.8), 'and the golf deal too');
ev('S.pie.founder.jit=0.7');
ev(`salesGolf(${golfDay})`);
assert.equal(ev('S.biz.length'), n + 1, 'the Founder skipped golf');
assert.match(ev('S.log[0].t'), /The Founder skipped golf/);
// A golf day of the other kind is on the ground, as before.
const ground = ev("(()=>{for(let d=S.day+1;d<S.day+400;d++)if(slR('golfsky|'+d)>=PIE_GOLF_SKY)return d;})()");
ev(`salesGolf(${ground})`);
assert.equal(ev('BIZ_T[S.biz.at(-1).type].orbit'), undefined, 'on the ground');
assert.deepEqual(errors, []);
});
test('the sales desk signs orbit offers where the dish has room, without a routing trial', t => {
const { ev, errors } = sky(t, 'eng');
ev('ACT.salesAuto()');
ev("S.offers=[];pieSpawn('pizza');pieSpawn('boat')");
const want = ids(ev, 'offers');
ev("window.__t=0;window.__a=autoOffer;autoOffer=o=>{__t++;return __a(o)}");
ev('slAutoDay(S.day);autoOffer=__a');
assert.equal(ev('__t'), 0);
assert.deepEqual(ids(ev, 'biz'), want, 'both signed in one day');
assert.ok(ev("S.biz.every(b=>b.by==='eng')"));
// A full dish: an offer that does not fit waits.
ev("S.offers=[{id:'big',city:'lon',city2:null,name:'Big Boat',type:'boat',bw:1e5,rate:27500,reqs:[],exp:S.day+40,by:'eng'}];slAutoDay(S.day)");
assert.deepEqual(ids(ev, 'offers'), ['big']);
assert.deepEqual(errors, []);
});

View file

@ -5,7 +5,7 @@ const path = require('node:path');
const { load } = require('./harness');
const { lit } = require('../scripts/lib/js-literal');
// The sales trial (#185, the intern's sales order) runs the pass with the offer first and skips the pass without
// The sales trial (#185, now the sales desk's signing for you) runs the pass with the offer first and skips the pass without
// it when it cannot change the answer. It must sign exactly the offers the original two-pass trial signs.
const ORIGINAL = `(function(o){if(!o||!own(BIZ_T,o.type)||!(o.exp>S.day)||!(o.bw>0)||o.rate<0||!bCities(o).length||!bCities(o).every(popUp)||!reqOk(o))return null;
const T=BIZ_T[o.type],b=offerCustomer(o);if(T.event&&(!(o.start>S.day)||!(o.dur>0)))return null;

View file

@ -141,18 +141,6 @@ test('PNI: weekly, big enough networks only, paid peering left out by default, a
assert.deepEqual(errors, []);
});
test('sales: decline offers below the minimum, sign the ready ones with #185\'s trial', t => {
const { ev, errors } = game(t);
hire(ev); on(ev, 'sales', { acc: true, min: 5000 });
ev('S.transit[0].tier=3;S.pops.fra.rgen=3;compute()');
ev("S.offers=[{id:'tiny',city:'fra',name:'Tiny',type:'dia',bw:1,rate:600,reqs:[],exp:30},{id:'big',city:'fra',name:'Big',type:'dia',bw:10,rate:600,reqs:[],exp:30},{id:'gen',city:'fra',name:'Gen',type:'dia',bw:10,rate:600,reqs:['gen'],exp:30}]");
shift(ev);
assert.deepEqual(JSON.parse(ev('JSON.stringify(S.biz.map(b=>b.id))')), ['big']);
assert.deepEqual(JSON.parse(ev('JSON.stringify(S.offers.map(o=>o.id))')), ['gen'], 'unmet requirements wait, the tiny one is gone');
assert.match(ev('opsEntry(S.ops.log[0])'), /declined a tiny offer, signed a customer/);
assert.deepEqual(errors, []);
});
test('repairs: rush what has a price, as the Rush repair button would', t => {
twins(t, "S.links=[{id:'f',a:'fra',b:'ams',kind:'df',sys:'lite',ch:['zr4'],km:450,sub:false,ready:0,cut:0,eqDown:10,mo:1}];S.inc=[{id:'amp',type:'amp',ref:'f',until:10,cost:3000,msg:'amp'}];S.pops.ams={day:0,bb:null,boost:0,down:0,routers:1,gen:false}",
ev => on(ev, 'repair'), "ACT.fixInc({id:'amp'})", 'S.inc.length');
@ -235,26 +223,27 @@ test('the shift runs inside dayTick, respects a stopped clock, batches its work
test('the NOC gets one notice a week, the shift report; the daily lines stay in the Ops sheet', t => {
const { ev, errors } = game(t, "S.transit[0].hist=[600]");
ev('S.day=14');
hire(ev); on(ev, 'transit', { x: 1.5 }); on(ev, 'sales', { acc: true, min: 5000 });
hire(ev); on(ev, 'transit', { x: 1.5 });
ev('S.transit[0].tier=3;S.pops.fra.rgen=3;compute()');
const n0 = ev('S.log.length');
for (let d = 14; d < 21; d++) {
if (d === 15) ev("S.offers=[{id:'tiny',city:'fra',name:'Tiny',type:'dia',bw:1,rate:600,reqs:[],exp:60},{id:'big',city:'fra',name:'Big',type:'dia',bw:10,rate:600,reqs:[],exp:60}]");
if (d === 15) ev('S.transit[0].hist=[6000]');
ev(`S.day=${d}`); shift(ev);
}
assert.equal(ev('S.log.length'), n0, 'a whole week of shifts: no NOC notice yet');
assert.ok(ev('S.ops.log.length') >= 2, 'the Ops sheet has the daily detail');
ev('S.day=21'); shift(ev);
assert.equal(ev('S.log.length'), n0 + 1, 'one notice for the week');
assert.match(ev('S.log[0].t'), /^Kevin's week Kevin signed a customer \(\+\$6\.0k\/mo\), topped up transit .*declined a tiny offer.*Week total: \$[\d.]+k up front, \+\$[\d.]+k\/mo\./);
assert.equal(ev('S.log[0].k'), 'good');
assert.match(ev('S.log[0].t'), /^Kevin's week Kevin topped up transit .*Week total: \$[\d.]+k up front, \+\$[\d.]+k\/mo\./);
assert.doesNotMatch(ev('S.log[0].t'), /signed|declined/, 'deals are the sales desk\'s, not the intern\'s');
ev('S.day=22'); shift(ev);
assert.equal(ev('S.log.length'), n0 + 1, 'and nothing more until the next week ends');
// Only the sales order now: one tiny offer declined on day 23, reported when the week ends.
ev("for(const k in S.ops.on)S.ops.on[k]=false;S.ops.on.sales=true;S.offers=[{id:'t2',city:'fra',name:'T2',type:'dia',bw:1,rate:600,reqs:[],exp:60}];S.day=23");shift(ev);
ev("S.day=28");shift(ev);
// A week that only stopped at the budget, on day 23, reported when the week ends.
ev("S.ops.cap.transit=10000;S.ops.spent.transit=10000;S.ops.p.transit={x:3};S.day=23");shift(ev);
// A minute later in real time, so this one does not fold into last week's (both are plain notices now).
ev("S.log[0].at-=60000;for(const k in S.ops.on)S.ops.on[k]=false;S.day=28");shift(ev);
assert.equal(ev('S.log.length'), n0 + 2);
assert.match(ev('S.log[0].t'), /declined a tiny offer\.$/, 'nothing spent: no money line');
assert.match(ev('S.log[0].t'), /stopped at the budget for .*Keep transit headroom\)?\.$/, 'nothing spent: no money line');
assert.equal(ev('S.log[0].k'), '');
ev("S.day=35");shift(ev);
assert.equal(ev('S.log.length'), n0 + 2, 'an idle week: no notice');
@ -288,9 +277,7 @@ test('the mood follows the week, with no dice', t => {
const quiet = ev('opsMood()');
assert.equal(ev('opsMood()'), quiet, 'the same day reads the same');
assert.ok([ev("tr('ops.mood_quiet',{name:'Kevin'})"), ev("tr('ops.mood_kevin')")].includes(quiet));
ev("S.ops.wk=opsWkNew(Math.floor(S.day/7));S.ops.wk.n.sales=1");
assert.equal(ev('opsMood()'), ev("tr('ops.mood_sales',{name:'Kevin'})"));
ev("S.ops.wk.n.broke=1;delete S.ops.wk.n.sales");
ev("S.ops.wk=opsWkNew(Math.floor(S.day/7));S.ops.wk.n.broke=1");
assert.equal(ev('opsMood()'), ev("tr('ops.mood_broke',{name:'Kevin'})"));
assert.deepEqual(errors, []);
});
@ -346,8 +333,8 @@ test('saves: old saves load with no intern and everything off, settings survive
assert.equal(ev("JSON.stringify(S.ops.skip)"), '{"fra":["transit"]}');
assert.equal(ev("JSON.stringify(S.ops.log)"), '[{"d":1,"i":"kevin","r":[["transit",2,["fra +1×100G"]]]}]');
assert.equal(ev('S.ops.floor===50000&&S.ops.tpl.bb===true'), true);
ev(`S.ops.wk={w:3,i:'kevin',n:{sales:2,evil:9,transit:'x'},wh:{transit:['fra +1×100G','<b>']},up:-5,mo:'a',rev:41000,ff:99};S.ops.rep={i:'mallory'};S=migrate(S)`);
assert.equal(ev("JSON.stringify(S.ops.wk)"), '{"w":3,"i":"kevin","n":{"sales":2},"wh":{"transit":["fra +1×100G"]},"up":0,"mo":0,"rev":41000,"ff":7}');
ev(`S.ops.wk={w:3,i:'kevin',n:{sales:2,evil:9,transit:'x',repair:2},wh:{transit:['fra +1×100G','<b>']},up:-5,mo:'a',rev:41000,ff:99};S.ops.rep={i:'mallory'};S=migrate(S)`);
assert.equal(ev("JSON.stringify(S.ops.wk)"), '{"w":3,"i":"kevin","n":{"repair":2},"wh":{"transit":["fra +1×100G"]},"up":0,"mo":0,"ff":7}', 'the retired sales order\'s tally goes');
assert.equal(ev('S.ops.rep'), null);
assert.deepEqual(errors, []);
});
@ -381,22 +368,6 @@ test('the Ops sheet works at 360 px in every language, from the NOC tab and the
}
});
test('sales trial at most one offer a shift, and an offer that did not fit waits a week', t => {
const { ev, errors } = game(t);
hire(ev); on(ev, 'sales', { acc: true, min: 0 });
ev("S.offers=['a','b','c'].map(id=>({id,city:'fra',name:id,type:'dia',bw:1e5,rate:600,reqs:[],exp:60}));window.__t=0;window.__a=autoOffer;autoOffer=o=>{__t++;return __a(o)}");
shift(ev);
assert.equal(ev('__t'), 1, 'one routing trial per shift');
for (let i = 0; i < 2; i++) { ev('S.day++'); shift(ev); }
assert.equal(ev('__t'), 3, 'each offer once');
ev('S.day++'); shift(ev);
assert.equal(ev('__t'), 3, 'too big for the network: not tried again within the week');
ev('S.day+=7'); shift(ev);
assert.equal(ev('__t'), 4);
ev('autoOffer=__a');
assert.deepEqual(errors, []);
});
test('re-hiring in a later month starts on a fresh budget, not last month\'s spending', t => {
const { ev, errors } = game(t);
hire(ev);
@ -452,11 +423,11 @@ test('decommission keeps its spare in another trench than the big link', t => {
assert.deepEqual(errors, []);
});
test('decommission sees the traffic of a customer signed earlier in the same shift', t => {
test('decommission sees the traffic of a customer the sales desk signed the same day', t => {
const { ev, errors } = game(t, "S.pops.fra.bb.d=30;ACT.buildPop({city:'ams'});S.pops.ams.rgen=1;for(const [id,tier,tr] of [['big',2,'T1'],['s1',1,'T2'],['s2',1,'T3']])S.links.push({id,a:'fra',b:'ams',kind:'wave',tier,km:400,sub:false,cut:0,mo:1000,trench:tr});compute()");
hire(ev); on(ev, 'sales', { acc: true, min: 0 }); on(ev, 'decom', { keep: false });
ev("S.offers=[{id:'o1',city:'fra',city2:'ams',name:'Bulk Co',type:'l2vpn',bw:450,rate:20,reqs:[],exp:S.day+20}]");
shift(ev);
hire(ev); on(ev, 'decom', { keep: false });
ev("ACT.salesHire({id:'eng'});S.slAuto.on=true;closeModal();S.offers=[{id:'o1',city:'fra',city2:'ams',name:'Bulk Co',type:'l2vpn',bw:450,rate:20,reqs:[],exp:S.day+20}]");
ev('slAutoDay(S.day)'); shift(ev);
assert.deepEqual(JSON.parse(ev('JSON.stringify(S.biz.map(b=>b.id))')).length, 1, 'signed');
assert.equal(ev('S.links.length'), 3, 'its 450G needs every wave, so none goes');
ev('compute()');
@ -464,13 +435,13 @@ test('decommission sees the traffic of a customer signed earlier in the same shi
assert.deepEqual(errors, []);
});
test('no recompute on a shift that only declined offers or stopped at a budget', t => {
test('no recompute on a shift that only stopped at a budget', t => {
const { ev, errors } = game(t);
hire(ev); on(ev, 'sales', { acc: false, min: 50000 }); on(ev, 'transit', { x: 3 }, 10000);
ev("S.ops.spent.transit=10000;S.transit[0].hist=[600];S.offers=[{id:'tiny',city:'fra',name:'Tiny',type:'dia',bw:1,rate:600,reqs:[],exp:30}]");
hire(ev); on(ev, 'transit', { x: 3 }, 10000);
ev("S.ops.spent.transit=10000;S.transit[0].hist=[600]");
const n = ev("window.__c=compute;window.__n=0;compute=()=>{__n++;return __c()};opsDay(S.day);compute=__c;__n");
assert.equal(n, 0, 'nothing in the network changed');
assert.match(ev('opsEntry(S.ops.log[0])'), /declined a tiny offer, stopped at the budget/);
assert.match(ev('opsEntry(S.ops.log[0])'), /stopped at the budget/);
ev("S.ops.spent.transit=0");
assert.equal(ev("window.__n=0;compute=()=>{__n++;return __c()};opsDay(S.day);compute=__c;__n"), 1, 'a real job still recomputes once');
assert.deepEqual(errors, []);
@ -567,8 +538,8 @@ test('transit: the log line and budget line show the monthly cost a top-up adds'
test('#226 the shift report\'s Open button in the NOC opens the Ops sheet, and survives a reload', t => {
const { ev, errors, dom } = game(t);
ev('S.day=14'); hire(ev); on(ev, 'sales', { acc: false, min: 5000 });
ev("S.offers=[{id:'t',city:'fra',name:'T',type:'dia',bw:1,rate:600,reqs:[],exp:60}];S.day=15"); shift(ev);
ev('S.day=14'); hire(ev); on(ev, 'transit', { x: 3 }, 10000);
ev("S.ops.spent.transit=10000;S.transit[0].hist=[600];S.day=15"); shift(ev);
ev('S.day=21'); shift(ev);
assert.match(ev('S.log[0].t'), /^Kevin's week/);
ev("S=migrate(JSON.parse(JSON.stringify(S)));closeModal();ACT.leftTab({t:'noc'})");