Phase 4: close loot/refund leaks, landing-site garrisons, speed-scaled shipping, update/offsite tooling, broad e2e

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
This commit is contained in:
jvanvik 2026-10-12 00:58:12 +02:00
parent 9104480463
commit 3c23c51902
92 changed files with 4887 additions and 300 deletions

View file

@ -1,33 +1,39 @@
'use strict';
/*
* UPSTREAM smoke e2e (npm run e2e). Boots the real server in-process (temp SQLite file, fast world) and drives real Chromium
* through playwright-core. Target: 1-2 minutes. Exit code 1 if any check fails.
* UPSTREAM e2e (npm run e2e). Boots the real server in-process (temp SQLite file, fast or slow world) and drives real Chromium
* through playwright-core. Target: under 3 minutes for the default set. Exit code 1 if any check fails.
*
* node e2e/run.js all suites
* node e2e/run.js push layout only the named suites (desktop, phone, layout, push)
* node e2e/run.js all default suites (everything except 'slow')
* node e2e/run.js push units only the named suites
* E2E_SLOW=1 node e2e/run.js also the slow suite; node e2e/run.js slow runs only it (about 70 s)
* E2E_HEADED=1 node e2e/run.js watch it
* E2E_SHOTS=dir node e2e/run.js save a screenshot after each flow / on each failure into dir
*
* What it does NOT do: it is not the full suite (no combat balance, no alliance/trade flows, no Firefox/WebKit, no real proxy).
* Suites: desktop phone layout push smoke: sign-up, build, map, nav, layout matrix, push by WebSocket (e2e/run.js)
* units movements reconnect slow world (speed 1), seeded buildings and units; flights are moved up like the push suite does (e2e/flows.js)
* alliance trade nb pwa fast world; nb = Norwegian (raw keys, English leftovers, live switch and fresh render), pwa = manifest and icons
* endgame own world backdated to day 100.5: phase banner, 7 sites, ship to a held site
* slow opt-in: no WebSocket at all, the raid must still show up by REST polling (45 s gap)
*
* What it does NOT do: no combat balance, takeover/capture flows, confederation views or diplomacy moves, no Firefox/WebKit, no real
* devices, no real proxy (nginx Proxy Manager), no load. Flights that take real minutes (speed 1, 10 minute minimum latency) are
* moved up in the database (UPDATE movements/events + scheduler.arm), the handlers themselves run unchanged.
*/
const fs = require('fs');
const path = require('path');
const { chromium } = require('playwright-core');
const L = require('./lib.js');
const { check, group, sleep, PROFILES } = L;
const F = require('./flows.js');
const { check, group, sleep, PROFILES, noErrors, tapper, openFromMore } = L;
const SHOTS = process.env.E2E_SHOTS || '';
const want = process.argv.slice(2);
const wanted = (n) => !want.length || want.includes(n);
const SLOW = ['slow']; // opt-in suites: only by name or with E2E_SLOW=1
const wanted = (n) => (want.length ? want.includes(n) : !SLOW.includes(n) || !!process.env.E2E_SLOW);
if (SHOTS) fs.mkdirSync(SHOTS, { recursive: true });
const shot = async (page, name) => { if (SHOTS) await page.screenshot({ path: path.join(SHOTS, name + '.png') }).catch(() => {}); };
const noErrors = (p, label) => (p.errors.length ? (label || 'console') + ' errors:\n' + p.errors.join('\n') : true);
// ---------------------------------------------------------------- shared flow pieces
// Tap/click that does the right thing for the profile (real touch events on phones, real mouse on desktop).
const tapper = (page, touch) => (sel, opts) => (touch ? page.tap(sel, opts) : page.click(sel, opts));
async function signUpThroughUi(P, name, touch) {
const tap = tapper(P.page, touch);
await P.page.goto(P.base + '/');
@ -72,17 +78,6 @@ async function mapTap(page, touch) {
return title;
}
// Open a "More" screen (Rankings, Alerts, Settings, Trade, World) the way a player does: nav -> More -> row.
async function openFromMore(page, touch, id, label) {
const tap = tapper(page, touch);
await tap('#nav [data-screen="more"]');
await page.waitForSelector('.more-list .row-btn');
await page.locator('.more-list .row-btn', { hasText: label }).first().waitFor({ timeout: 3000 });
await tap('.more-list .row-btn:has-text("' + label + '")');
await page.waitForSelector('[data-screen="' + id + '"]:not([hidden])', { timeout: 5000 });
await sleep(500); // let its first fetch land (errors show up here)
}
async function navReachable(page, vw, vh) {
return page.evaluate(([w, h]) => {
const nav = document.getElementById('nav');
@ -272,6 +267,18 @@ async function suitePush(browser) {
} finally { await S.close(); }
}
// Units + movements + reports share one slow world (speed 1: a raid really takes half an hour, so the flight is on screen; the
// arrival is moved up by hurryMovement, like the push suite does).
async function suiteMilitary(browser) {
const S = await L.bootServer({ speed: 1 });
try {
const U = await F.armedPair(S, 'Alice' + F.uniq(), 'Bob' + F.uniq());
if (wanted('units')) await F.suiteUnits(browser, S, U);
if (wanted('movements')) await F.suiteMovements(browser, S, U);
if (wanted('reconnect')) await F.suiteReconnect(browser, S);
} finally { await S.close(); }
}
// ---------------------------------------------------------------- main
(async () => {
const t0 = Date.now();
@ -284,6 +291,18 @@ async function suitePush(browser) {
if (wanted('phone')) await suitePhone(browser, S);
if (wanted('layout')) await suiteLayout(browser, S);
if (wanted('push')) await suitePush(browser);
if (wanted('alliance') || wanted('trade') || wanted('nb') || wanted('pwa')) {
const S2 = await L.bootServer({ speed: 4000 });
try {
if (wanted('alliance')) await F.suiteAlliance(browser, S2);
if (wanted('trade')) await F.suiteTrade(browser, S2);
if (wanted('nb')) await F.suiteNorwegian(browser, S2);
if (wanted('pwa')) await F.suitePwa(browser, S2);
} finally { await S2.close(); }
}
if (wanted('units') || wanted('movements') || wanted('reconnect')) await suiteMilitary(browser);
if (wanted('endgame')) await F.suiteEndgame(browser);
if (wanted('slow')) await F.suiteSlow(browser);
} catch (e) {
L.record('harness: unexpected exception', false, e && e.stack || String(e));
} finally {