diff --git a/client/src/main.ts b/client/src/main.ts index 9703beb..d560eb7 100644 --- a/client/src/main.ts +++ b/client/src/main.ts @@ -19,11 +19,26 @@ let inputElapsed = 0; let walkTo: { x: number; z: number } | undefined; let pendingAction: { op: string; target: string } | undefined; let actionElapsed = 0; -let actionAttempts = 0; // A gather target can stay legitimately, persistently unreachable for a long time (a // depleted resource waits out a real respawn timer measured in minutes, not a stray -// frame) -- retrying it forever would starve everything else. Give up on a target after -// a few tries and steer the next action() call to a fresh one instead. +// frame) -- retrying it forever would starve everything else. But a *working* attack is +// mostly cooldown rejections between the hits that land, so "stuck" can't just mean +// "hasn't succeeded since the click": it has to mean no progress at all for a while. +// Track a per-target progress signal (target HP for attack, held-item count for +// gather/loot) and only give up once that's stopped moving for a wall-clock budget -- +// not a frame/attempt count, since a throttled or backgrounded tab can go seconds +// between rendered frames, and counting attempts instead of real elapsed time let a +// "few tries" balloon into tens of real seconds. +let lastProgress: number | undefined; +let lastProgressAt = 0; +function progressSignature(): number | undefined { + if (!pendingAction || !snapshot) return undefined; + if (pendingAction.op === 'attack') { + if (pendingAction.target === 'boss') return snapshot.world.bossHp; + return snapshot.entities.find(e => e.id === pendingAction!.target)?.hp; + } + return Object.values(snapshot.self.inventory).reduce((a: number, b: number) => a + b, 0); +} const avoidUntil = new Map(); let requestedClose = false; const keys = new Set(); @@ -60,7 +75,7 @@ function action(op: string) { selection(target); pendingAction = { op: target.kind === 'corpse' ? 'loot' : op, target: target.id }; walkTo = target.position; - actionAttempts = 0; + lastProgress = undefined; lastProgressAt = Date.now(); } function connect() { requestedClose = false; sequence = 0; @@ -174,13 +189,15 @@ async function boot() { // under the intent rate limit) instead of giving up forever -- the server's // own action cooldown makes repeat attempts harmless. But a target can also be // legitimately, persistently rejected (a depleted resource waits out a real - // respawn timer), so give up on THIS target after a few tries and let the next - // action() pick a fresh one rather than retrying a lost cause indefinitely. + // respawn timer), so give up on THIS target after a wall-clock budget and let + // the next action() pick a fresh one rather than retrying a lost cause forever. else { actionElapsed += dt; if (actionElapsed >= 0.3) { actionElapsed = 0; - if (++actionAttempts > 8) { + const sig = progressSignature(); + if (sig !== undefined && sig !== lastProgress) { lastProgress = sig; lastProgressAt = Date.now(); } + if (Date.now() - lastProgressAt > 5000) { avoidUntil.set(pendingAction.target, Date.now() + 8000); const retryOp = pendingAction.op === 'loot' ? 'gather' : pendingAction.op; walkTo = undefined; pendingAction = undefined; @@ -188,7 +205,7 @@ async function boot() { } else { send(pendingAction.op, pendingAction.target); } } } - } else { x = dx / distance; z = dz / distance; actionElapsed = 0.3; actionAttempts = 0; } + } else { x = dx / distance; z = dz / distance; actionElapsed = 0.3; } } view.moving = !!(x || z); if (inputElapsed >= 0.05) { send('move', '', x, z); inputElapsed = 0; } @@ -228,7 +245,7 @@ async function boot() { for (const id of ['inventory', 'settings']) { $(`${id}-toggle`).onclick = () => { visible(id, $(id).hidden); visible('movement', $('inventory').hidden && $('settings').hidden && !!snapshot); if (id === 'inventory' && snapshot) inventory(snapshot.self); }; } document.querySelectorAll('[data-close]').forEach(button => button.onclick = () => visible(button.dataset.close!, false)); $('attack').onclick = () => action('attack'); $('gather').onclick = () => action('gather'); $('heal').onclick = () => send('heal'); $('keystone').onclick = () => send('return'); - $('target-boss').onclick = () => { selection(snapshot?.entities.find(e => e.id === 'boss')); walkTo = { x: 0, z: 0 }; pendingAction = { op: 'attack', target: 'boss' }; }; + $('target-boss').onclick = () => { selection(snapshot?.entities.find(e => e.id === 'boss')); walkTo = { x: 0, z: 0 }; pendingAction = { op: 'attack', target: 'boss' }; lastProgress = undefined; lastProgressAt = Date.now(); }; $('dev-boss').onclick = () => void api('/api/dev/boss', {}).catch(e => notice(e.message)); $('reconnect').onclick = () => location.reload(); $('new-character').onclick = () => { requestedClose = true; ws?.close(); location.reload(); }; @@ -257,6 +274,6 @@ async function boot() { if (hit.entity) { selection(hit.entity); action(['boss', 'sentinel'].includes(hit.entity.kind) ? 'attack' : 'gather'); } else if (hit.point) { selection(); walkTo = hit.point; pendingAction = undefined; } }); - Object.defineProperty(window, '__aeternalis', { value: { diagnostics: () => view.diagnostics(), get snapshot() { return snapshot; } }, configurable: true }); + Object.defineProperty(window, '__aeternalis', { value: { diagnostics: () => view.diagnostics(), get snapshot() { return snapshot; }, get walkTo() { return walkTo; }, get pendingAction() { return pendingAction; }, get keys() { return [...keys]; } }, configurable: true }); } boot().catch(error => { console.error(error); $('arrival-error').textContent = `Unable to enter the world: ${error.message}`; $('connection-status').textContent = 'Unavailable'; }); diff --git a/playwright.config.ts b/playwright.config.ts index 11282c6..213ea19 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -2,7 +2,16 @@ import { defineConfig } from '@playwright/test'; export default defineConfig({ testDir: './tests', timeout: 45000, workers: 1, fullyParallel: false, - use: { baseURL: 'http://127.0.0.1:18089', browserName: 'chromium', channel: process.env.PLAYWRIGHT_CHANNEL || undefined, headless: true, screenshot: 'only-on-failure', trace: 'retain-on-failure', launchOptions: { args: ['--use-angle=swiftshader', '--enable-unsafe-swiftshader'] } }, + use: { baseURL: 'http://127.0.0.1:18089', browserName: 'chromium', channel: process.env.PLAYWRIGHT_CHANNEL || undefined, headless: true, screenshot: 'only-on-failure', trace: 'retain-on-failure', launchOptions: { args: [ + '--use-angle=swiftshader', '--enable-unsafe-swiftshader', + // The CI runner's headless page was getting treated as backgrounded/occluded, + // which throttles requestAnimationFrame to ~1Hz or worse -- turning every + // frame-driven client action (movement steering, gather/attack retries) into a + // multi-second-per-tick crawl and blowing well past assertion timeouts even + // though the server side was fine. These are the standard flags to keep a + // headless/automated tab running at full rAF rate regardless of visibility. + '--disable-background-timer-throttling', '--disable-backgrounding-occluded-windows', '--disable-renderer-backgrounding', + ] } }, webServer: { command: 'node tools/dev-server.mjs', url: 'http://127.0.0.1:18089/readyz', timeout: 180000, reuseExistingServer: false,