'use strict'; /* Small server fixes found by the bot harness (tools/bot.js), each with the test that failed before the fix. */ const test = require('node:test'); const assert = require('node:assert'); const T = require('./military-helpers'); const M = require('../server/military/movements'); const { R, D } = T; // The conservation ledger of the harness found it: a shipment that comes home (a landing site changed hands, a POP vanished) rides // back on a `link` return leg. Cargo above the Rack hall cap is dropped on arrival, but the return handler stayed silent for link // legs, so the loss was invisible to the player and to every audit that sums the `cargoLost` notifications. test('a bounced shipment that does not fit the Rack hall reports the overflow (link return legs with cargo are no longer silent)', () => { const h = T.setup(); const a = T.addOperator(h, 'alice', { infra: { rack_hall: 1 } }); const cap = R.storageCap(require('../server/state').loadTown(h.db, a.townId)); h.db.run('UPDATE towns SET fiber = ?, hardware = 0, capital = 0 WHERE id = ?', cap - 100, a.townId); const row = T.town(h, a.townId); const ctx = h.ctx(); M.launchReturn(ctx, { worldId: h.worldId, ownerId: a.opId, fromTownId: null, at: { x: row.x + 5, y: row.y }, to: row, units: {}, cargo: { fiber: 400 }, arriveAt: h.clock.now() + 60 * 1000, parentId: null, extra: { link: 1 } }); h.advance(2 * 60 * 1000); const n = T.notes(h, a.userId, 'movement_returned'); assert.equal(n.length, 1, 'the bounced shipment is announced'); assert.ok(Math.abs(n[0].cargoLost.fiber - 300) <= 2, 'and says how much did not fit (400 sent, 100 of room, a minute of production on top): ' + n[0].cargoLost.fiber); assert.ok(Math.abs(T.town(h, a.townId).fiber - cap) < 1e-6, 'the store is full, not above the cap'); }); test('empty carriers coming home on a link leg stay silent (no notification spam)', () => { const h = T.setup(); const a = T.addOperator(h, 'alice'); const row = T.town(h, a.townId); M.launchReturn(h.ctx(), { worldId: h.worldId, ownerId: a.opId, fromTownId: null, at: { x: row.x + 5, y: row.y }, to: row, units: {}, cargo: {}, arriveAt: h.clock.now() + 60 * 1000, parentId: null, extra: { link: 1 } }); h.advance(2 * 60 * 1000); assert.equal(T.notes(h, a.userId, 'movement_returned').length, 0); }); // Balance pass B1 (docs/BALANCE.md): the second build slot opens at Core router 3; FORMULAS.extraQueueCores (default none) can open more. test('build slots follow the Core router: one, a second from FORMULAS.secondQueueCoreLevel, more from FORMULAS.extraQueueCores', () => { const F = D.FORMULAS; const at = (core) => R.queueSlots({ buildings: { core_router: { type: 'core_router', level: core } } }); assert.equal(F.secondQueueCoreLevel, 3, 'the tuned value (B1)'); assert.deepEqual([0, 1, 2, 3, 10, 20].map(at), [1, 1, 1, 2, 2, 2], 'default: two slots from the second-slot level, no extra ones'); const saved = F.extraQueueCores; try { F.extraQueueCores = [6, 10]; assert.deepEqual([2, 3, 5, 6, 9, 10, 20].map(at), [1, 2, 2, 3, 3, 4, 4]); } finally { F.extraQueueCores = saved; } });