Phase 3: trade/end-game client, bot simulator, first balance pass

Built:
- Client: trade screen, world/end-game screen (landing sites, shipping, node build, final ranking), report sharing + alliance reports tab, alert describers for all notification types, error-code strings (en+nb) for every server CODE.
- tools/bot.js (+ tools/bot/): 50 headless bots against the real server in-process with a fake clock; resource/unit conservation ledger, exit 1 on broken invariants. docs/BALANCE.md has method and every run behind a number.
- Balance changes (evidence in docs/BALANCE.md): secondQueueCoreLevel 10 -> 3, TRANSPORT.capacityPerLink 500 -> 1000 (end game was shipping-limited in bot runs).
- Server fixes: POST /reports/:id/share 500 without a pending reportCleanup; bounced link shipments were silent about cargo overflow.

Tested: npm test 207/207 (new: bot determinism + invariants, client alerts/world/i18n over CODES, two regression tests that failed before their fix); openapi check up to date. Real-browser scratch runs (not in repo): WebSocket push shows an incoming-attack banner ~214 ms after launch, polling fallback ~52 s, 15 scripted flows, 71 screenshots.

NOT tested: Playwright suite (e2e/ still empty), real devices/Safari, nginx proxy websockets, throttled networks, HTTP-level bot load. NOT claimed: balance. Bots are not humans; open balance items (loot waste, escrow refund clipping, no garrisons at landing sites, end game not scaling with world speed) are listed in docs/BALANCE.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
jvanvik 2026-10-11 20:24:41 +02:00
parent d84b0c9d12
commit 931f59e11e
49 changed files with 4750 additions and 59 deletions

View file

@ -31,7 +31,8 @@
* What can be sent to a tile. c = {
* tile: GET /map/tile response,
* home: units at the sending POP, transport: { links, active } of the sending POP,
* allianceId: my alliance id or null, crews: number of rollout crews at home
* allianceId: my alliance id or null, crews: number of rollout crews at home,
* transportOnly: the dialog was opened for a transport (trade screen): a POP, anybody's, offers only the transport
* } -> [{ type, ok, reason }] (reason is a code the sheet turns into text; null when ok)
* Hidden (not even greyed): types that make no sense for this kind of tile. Pact rules (NAP, confederation) are not
* known to the client: the server refuses those and the sheet shows its message.
@ -42,6 +43,14 @@
if (!t) return out;
const has = (type) => unitsForType(type, home).length > 0;
const add = (type, ok, reason) => out.push({ type, ok: !!ok, reason: ok ? null : reason });
const linksFree = () => {
const links = (c.transport && c.transport.links) || 0, active = (c.transport && c.transport.active) || 0;
return { ok: links > active, reason: links === 0 ? 'no_link' : 'links_busy' };
};
if (c.transportOnly) { // resources may go to any POP, a rival's too (the server warns its owner of the arrival)
if (t.town) { const l = linksFree(); add('transport', l.ok, l.reason); }
return out;
}
if (t.town) {
if (t.town.mine) {
add('reinforce', has('reinforce'), 'no_units');
@ -60,6 +69,14 @@
} else if (t.type === 'incumbent') {
add('scan', has('scan'), 'no_units');
add('attack', has('attack'), 'no_units');
} else if (t.type === 'backbone') {
// End game landing site: scan or attack, nothing else. Attacking needs an alliance and a site that is not your own
// alliance's (pacts are the server's call: its answer is shown by the dialog).
const b = t.backbone || {};
add('scan', has('scan'), 'no_units');
if (!c.allianceId) add('attack', false, 'no_alliance');
else if (b.mine) add('attack', false, 'own_site');
else add('attack', has('attack'), 'no_units');
} else if (t.type === 'land') {
const s = t.settle || {};
if (!s.possible) add('settle', false, 'settle:' + (s.code || 'invalid_target'));