Built: - Economy: raid loot capped to the room the raiders have at home (rest stays with the victim, "lootLeft" in the report); trade escrow reserves its room so refunds always fit; trade accept refuses with no_room_for_goods when the goods would not fit. Loot destroyed per 30-day run 31-61k -> ~1k, refunds clipped ~27k -> 0 (docs/BALANCE.md, 3 seeds). - End game: members of the holding alliance garrison landing sites (migration 005_site_garrison.sql), garrison counts in site defence, 72 h capture shield, withdraw route, POP view lists garrisoned units. Shipping capacity scales with world speed (3x world: winner 76-98 -> ~30-36 days after sites open). Bot runs show real contests (84-194 attacks on held sites at 1x). - Ops: deploy/update.sh (backup, stop, ff-merge, npm ci --ignore-scripts, health check, rollback), deploy/upstream-offsite (rsync only), admin end-world snapshots results, EPIPE fix, docs/workflows/ filled in. - e2e 62 -> 163 checks: units, raids/reports, alliance+messages, trade, end game, nb, PWA, reconnect, slow polling fallback (opt-in). Two app bugs found: message push ignored, "New" button stayed English. Tested: npm test 274/274, openapi check, npm run e2e 163/163 (137 s), bot runs 50x30d seeds 1-3 and 140-day/60-day speed-3 end-game runs INVARIANTS OK, adversarial review pass (findings fixed or documented). NOT tested: update.sh on a real box (systemd, real npm, runuser; stubs only, shellcheck not installed), garrison card/loot text on a phone, Node 22.13, humans. Known leaks left open and documented (BALANCE S6): loot/shipments can still overflow when stock arrives in flight, bounced backbone shipments lose overflow (reported to the sender). Garrison numbers (heldDefenceMult 2, shield 72 h) are first guesses from 2 seeds. Not claimed: balanced. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
72 lines
4.6 KiB
JavaScript
72 lines
4.6 KiB
JavaScript
'use strict';
|
|
/* Transport capacity scales with world speed (docs/BALANCE.md B7): trips are per sitting, not per hour, so a link carries
|
|
* capacityPerLink x speed. One function (rules.transportCapacity) is the only reader of the constant; commands, trade terms and the
|
|
* client's numbers (the `transport` block of a POP view) all go through it. Fake clock, in-memory db. */
|
|
const test = require('node:test');
|
|
const assert = require('node:assert');
|
|
const T = require('./military-helpers');
|
|
const { R, D } = T;
|
|
const err = (fn) => { try { fn(); } catch (e) { return e; } assert.fail('expected an error'); };
|
|
|
|
const CAP = D.TRANSPORT.capacityPerLink;
|
|
|
|
test('transportCapacity: capacityPerLink x speed, read at call time', () => {
|
|
assert.equal(R.transportCapacity(1), CAP);
|
|
assert.equal(R.transportCapacity(3), 3 * CAP);
|
|
assert.equal(R.transportCapacity(0.5), Math.round(CAP / 2));
|
|
assert.equal(R.transportCapacity(10), 10 * CAP);
|
|
assert.equal(R.transportCapacity(), CAP, 'no speed = 1x');
|
|
const keep = D.TRANSPORT.capacityPerLink;
|
|
D.TRANSPORT.capacityPerLink = 250;
|
|
try { assert.equal(R.transportCapacity(4), 1000); } finally { D.TRANSPORT.capacityPerLink = keep; }
|
|
});
|
|
|
|
test('transportPlan and tradeTermsCheck use the world speed', () => {
|
|
const town = { speed: 3, buildings: { internet_exchange: { type: 'internet_exchange', level: 2 } }, res: { fiber: 9000, hardware: 9000, capital: 9000, battery: 0 }, updatedAt: 0, unitDraw: 0, footprint: 0 };
|
|
town.buildings.rack_hall = { type: 'rack_hall', level: 20 };
|
|
const plan = (n, speed) => R.transportPlan(Object.assign({}, town, { speed }), { fiber: n }, 0, 0);
|
|
assert.notEqual(plan(3 * CAP, 3).code, 'capacity_exceeded');
|
|
assert.equal(plan(3 * CAP + 1, 3).code, 'capacity_exceeded');
|
|
assert.equal(plan(3 * CAP + 1, 3).capacity, 3 * CAP);
|
|
assert.equal(plan(CAP + 1, 1).code, 'capacity_exceeded', 'a 1x world is as before');
|
|
const terms = (n, speed) => R.tradeTermsCheck({ giveRes: 'fiber', giveAmount: n, wantRes: 'hardware', wantAmount: n, maxDistance: 10 }, speed);
|
|
assert.equal(terms(3 * CAP, 3).ok, true);
|
|
assert.equal(terms(3 * CAP + 1, 3).code, 'capacity_exceeded');
|
|
assert.equal(terms(3 * CAP, 1).code, 'capacity_exceeded');
|
|
assert.equal(terms(CAP).ok, true, 'speed defaults to 1');
|
|
});
|
|
|
|
test('server: a 3x world sends, ships and trades up to three times the 1x capacity; the POP view reports the real number', () => {
|
|
const h = T.setup({ speed: 3 });
|
|
const a = T.addOperator(h, 'sender', { x: 5, y: 0, infra: { internet_exchange: 2, rack_hall: 20 }, res: 20000 });
|
|
const b = T.addOperator(h, 'receiver', { x: 9, y: 0, infra: { rack_hall: 20 } });
|
|
const send = (n) => h.run('sendTransport', { userId: a.userId, fromTownId: a.townId, toTownId: b.townId, cargo: { fiber: n } });
|
|
assert.equal(err(() => send(3 * CAP + 1)).code, 'capacity_exceeded');
|
|
assert.equal(h.queries.town(a.userId, a.townId).town.military.transport.capacityPerLink, 3 * CAP);
|
|
const mv = send(3 * CAP);
|
|
assert.equal(mv.cargo.fiber, 3 * CAP);
|
|
const offer = h.run('tradeOffer', { userId: a.userId, townId: a.townId, giveRes: 'hardware', giveAmount: 2 * CAP, wantRes: 'capital', wantAmount: 2 * CAP, maxDistance: 30 }).offer;
|
|
assert.equal(offer.give.amount, 2 * CAP, 'an offer may fill a whole 3x transport');
|
|
assert.equal(err(() => h.run('tradeOffer', { userId: a.userId, townId: a.townId, giveRes: 'hardware', giveAmount: 3 * CAP + 1, wantRes: 'capital', wantAmount: 3 * CAP + 1, maxDistance: 30 })).code, 'capacity_exceeded');
|
|
// the same send in a 1x world is refused
|
|
const h1 = T.setup({ speed: 1 });
|
|
const a1 = T.addOperator(h1, 'sender', { x: 5, y: 0, infra: { internet_exchange: 2, rack_hall: 20 }, res: 20000 });
|
|
const b1 = T.addOperator(h1, 'receiver', { x: 9, y: 0 });
|
|
assert.equal(err(() => h1.run('sendTransport', { userId: a1.userId, fromTownId: a1.townId, toTownId: b1.townId, cargo: { fiber: 3 * CAP } })).code, 'capacity_exceeded');
|
|
});
|
|
|
|
test('no file outside rules.js and data.js reads TRANSPORT.capacityPerLink directly (a constant read bypasses the world speed)', () => {
|
|
const fs = require('fs'), path = require('path');
|
|
const root = path.join(__dirname, '..');
|
|
const hits = [];
|
|
const walk = (dir) => {
|
|
for (const f of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
if (f.name === 'node_modules' || f.name === '.git' || f.name === 'test' || f.name === 'e2e' || f.name === 'docs') continue;
|
|
const p = path.join(dir, f.name);
|
|
if (f.isDirectory()) walk(p);
|
|
else if (/\.js$/.test(f.name) && /TRANSPORT\.capacityPerLink/.test(fs.readFileSync(p, 'utf8'))) hits.push(path.relative(root, p));
|
|
}
|
|
};
|
|
walk(root);
|
|
assert.deepEqual(hits.filter((p) => !/^public\/js\/(rules|data)\.js$/.test(p)), []);
|
|
});
|