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:
parent
9104480463
commit
3c23c51902
92 changed files with 4887 additions and 300 deletions
41
e2e/lib.js
41
e2e/lib.js
|
|
@ -107,13 +107,15 @@ async function newPage(browser, ctxOpts, o) {
|
|||
o = o || {};
|
||||
const ctx = await browser.newContext(ctxOpts);
|
||||
const page = await ctx.newPage();
|
||||
page.setDefaultTimeout(8000); // a missing element fails in 8 s, not 30 s
|
||||
const errors = [];
|
||||
page.on('console', (m) => { if (m.type() === 'error' || m.type() === 'warning') errors.push(m.type() + ': ' + m.text() + (m.location() && m.location().url ? ' @ ' + m.location().url : '')); });
|
||||
page.on('pageerror', (e) => errors.push('pageerror: ' + e.message));
|
||||
page.on('requestfailed', (r) => { if (!/\/ws(\?|$)/.test(r.url()) && !(r.failure() && /ERR_ABORTED/.test(r.failure().errorText))) errors.push('requestfailed: ' + r.url() + ' ' + (r.failure() && r.failure().errorText)); });
|
||||
page.on('response', (r) => { if (r.status() >= 400 && !(o.allowStatus || []).includes(r.status())) errors.push('HTTP ' + r.status() + ' ' + r.request().method() + ' ' + r.url()); });
|
||||
page.on('dialog', (d) => { errors.push('dialog: ' + d.message()); d.dismiss(); });
|
||||
await page.addInitScript(() => { try { localStorage.setItem('upstream.lang', 'en'); } catch (e) { /* ignore */ } });
|
||||
if (!o.keepLang) await page.addInitScript(() => { try { localStorage.setItem('upstream.lang', 'en'); } catch (e) { /* ignore */ } });
|
||||
if (o.init) await page.addInitScript(o.init); // runs before the app's scripts, on every navigation
|
||||
return { ctx, page, errors };
|
||||
}
|
||||
// Sign in by token injection (fast path used by the layout matrix and the push test).
|
||||
|
|
@ -155,4 +157,39 @@ async function overflowReport(page) {
|
|||
});
|
||||
}
|
||||
|
||||
module.exports = { ROOT, PASSWORD, sleep, group, check, record, summary, results, bootServer, landNear, placeTown, setBuildings, giveUnits, PROFILES, newPage, openSignedIn, overflowReport, R };
|
||||
// ---------------------------------------------------------------- helpers shared by run.js and flows.js
|
||||
const noErrors = (p, label) => (p.errors.length ? (label || 'console') + ' errors:\n' + p.errors.join('\n') : true);
|
||||
|
||||
// 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));
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// A flight that normally takes the world's real time (speed 1) is made to land in `inMs`: both the movement row and its event move,
|
||||
// then the scheduler re-arms. This is what a long wait would have done; the handlers still run as in production.
|
||||
function hurryMovement(S, movementId, inMs) {
|
||||
const at = Date.now() + (inMs === undefined ? 2500 : inMs);
|
||||
S.db.run('UPDATE movements SET arrive_at = ? WHERE id = ?', at, movementId);
|
||||
S.db.run("UPDATE events SET due_at = ? WHERE status = 'pending' AND type IN ('arrive', 'return') AND json_extract(payload, '$.movementId') = ?", at, Number(movementId));
|
||||
S.srv.scheduler.arm();
|
||||
return at;
|
||||
}
|
||||
// Same for any pending event of a type (a training batch, a build).
|
||||
function hurryEvents(S, type, townId, inMs) {
|
||||
const at = Date.now() + (inMs === undefined ? 2500 : inMs);
|
||||
S.db.run("UPDATE events SET due_at = ? WHERE status = 'pending' AND type = ? AND town_id = ?", at, type, townId);
|
||||
S.srv.scheduler.arm();
|
||||
return at;
|
||||
}
|
||||
const latestMovement = (S, ownerOperatorId, type) => S.db.get("SELECT * FROM movements WHERE owner_id = ? AND status = 'out' " + (type ? 'AND type = ? ' : '') + 'ORDER BY id DESC LIMIT 1', ...(type ? [ownerOperatorId, type] : [ownerOperatorId]));
|
||||
|
||||
module.exports = { noErrors, tapper, openFromMore, hurryMovement, hurryEvents, latestMovement, ROOT, PASSWORD, sleep, group, check, record, summary, results, bootServer, landNear, placeTown, setBuildings, giveUnits, PROFILES, newPage, openSignedIn, overflowReport, R };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue