aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit 0b674ed910919dd781f4326aa987982f387858e7
parent bb75d226677e90893a1d970502fd5d0b72fe0e13
Author: anon <anon@example.com>
Date:   Wed,  4 Nov 2026 20:38:34 +0000

Await resolved conditions in native failure checks

Diffstat:
MDEVELOPERS.md | 7+++++++
MTODO.md | 7+++++++
Mtools/client/game_test.mjs | 13+++++++++++++
Atools/client/game_test_test.mjs | 22++++++++++++++++++++++
Mtools/client/test_backpack_nano_learning.mjs | 4++--
Mtools/client/test_corpse_credit_write.mjs | 4++--
Mtools/client/test_reclaim_weapon.mjs | 2+-
Mtools/client/test_team_write.mjs | 8++++----
8 files changed, 58 insertions(+), 9 deletions(-)

diff --git a/DEVELOPERS.md b/DEVELOPERS.md @@ -617,6 +617,13 @@ The driver provides: connection's CharacterReady acknowledgement as well as the native actor and inventory. Actor construction alone precedes usable game input. Predicates can also inspect `game.events` for protocol or input evidence. +- `waitFor(label, predicate)` awaits an asynchronous controller or storage + condition, returning its first truthy resolved value. It polls for ten seconds + without reading the current WASM instance, so it also works during reconnect. + Use it for server-state requests; `wait` predicates stay synchronous. Do not + pass async predicates to Playwright's `waitForFunction`: a Promise can satisfy + its truthiness check before the condition resolves. The helper regression runs + with `node tools/client/game_test_test.mjs`. - `key(key)` and `click(x, y, button)` wait for SDL consumption of press/release. This confirms delivery, not gameplay success: follow them with an outcome predicate. `hold(key, label, predicate, timeout)` releases the key in `finally`. diff --git a/TODO.md b/TODO.md @@ -4904,6 +4904,13 @@ and server restarts. Turn every reproduced bug into a focused regression test. and durable resource-item eligibility now have focused regressions. Two fresh WASM players verified independent stats/IP, native ACCEPT/CANCEL and purchases retained across a server restart. The broader creation audit remains open. +- [x] [P0] Await resolved asynchronous conditions in native failure/retry checks. + A real Ignore-file probe returned false from waitForFunction(async ...) without + waiting; the installed Playwright1.62.1 polls the Promise's truthiness. Five + maintained controller waits now await resolved values. A negative control + reproduces the false result; both focused Node regressions pass. Four short + WASM scenarios pass through actual storage-failure/retry and shock boundaries. + See `local/async-native-waits/README.md` and the harness in `DEVELOPERS.md`. - [ ] [P1] Audit disconnects, retries and failure handling across these features. Cover transport replacement, stale sessions, action replay, database failures and concurrent requests; success must follow the durable significant change. diff --git a/tools/client/game_test.mjs b/tools/client/game_test.mjs @@ -164,6 +164,19 @@ export class GameTest { return this.state; } + // Controller/storage conditions can outlive the current native page instance. + async waitFor(label, predicate) { + const deadline = Date.now() + 10000; + do { + const error = this.errors[0]; + assert(!error, error?.message); + const result = await predicate(); + if (result) return result; + await new Promise(resolve => setTimeout(resolve, 25)); + } while (Date.now() < deadline); + throw new Error(`Timed out waiting for ${label}`); + } + async wait(label, predicate, timeout = 10000) { const deadline = Date.now() + timeout; do { diff --git a/tools/client/game_test_test.mjs b/tools/client/game_test_test.mjs @@ -0,0 +1,22 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import {GameTest} from './game_test.mjs'; + +test('async condition waits for a resolved true value', async () => { + const game = new GameTest(); + let calls = 0; + + const result = await game.waitFor('resolved condition', async () => ++calls === 2); + + assert.equal(result, true); + assert.equal(calls, 2); +}); + +test('async condition propagates its failure', async () => { + const game = new GameTest(); + const failure = new Error('controller failed'); + + const result = game.waitFor('failed controller', async () => { throw failure; }); + + await assert.rejects(result, error => error === failure); +}); diff --git a/tools/client/test_backpack_nano_learning.mjs b/tools/client/test_backpack_nano_learning.mjs @@ -48,8 +48,8 @@ try { await click(cell(107, 65536), 'right'); await game.wait('real crystal Use during the injected write fault', () => game.events.some(event => event.sequence > failedSequence && event.direction === 'framesent' && event.opcode === '52526858' && Buffer.from(event.hex, 'hex').readUInt32BE(53) === 107)); - await page.waitForFunction(async () => { - const state = await (await fetch('/test-fault-state')).json(); + await game.waitFor('crystal write failure reaches server state', async () => { + const state = await (await page.request.get(url + '/test-fault-state')).json(); return !state.connected || state.reconnected || state.livePrograms !== 0; }); evidence.refused = await server(); diff --git a/tools/client/test_corpse_credit_write.mjs b/tools/client/test_corpse_credit_write.mjs @@ -33,8 +33,8 @@ try { assert.equal(evidence.before.credits, 123); const sequences = games.map(game => game.sequence); await use(); - await page.waitForFunction(async () => { - const state = await (await fetch('/test-state')).json(); + await owner.waitFor('corpse cash failure reaches server state', async () => { + const state = await (await page.request.get(url + '/test-state')).json(); return state.reconnected || !state.connected || state.owner.Credits !== 250; }); assert(owner.events.some(event => event.sequence > sequences[0] && event.direction === 'framesent' && diff --git a/tools/client/test_reclaim_weapon.mjs b/tools/client/test_reclaim_weapon.mjs @@ -64,7 +64,7 @@ try { await page.reload(); await game.ready(); await game.wait('native shock recovers', snapshot => game.local(snapshot).stats[247] === 0); - await page.waitForFunction(async () => (await (await fetch('/test-state')).json()).shock === 0); + await game.waitFor('server shock expires', async () => (await state()).shock === 0); await game.key('KeyI'); await game.click(681, 45, 'right'); await game.wait('reclaimed native weapon equips again', snapshot => game.local(snapshot).inventory.some(item => item.id === 1 && item.slot === 6)); diff --git a/tools/client/test_team_write.mjs b/tools/client/test_team_write.mjs @@ -32,9 +32,9 @@ try { const sequences = games.map(game => game.sequence); await game.click(928, 76); // Storage failure may already have started automatic page navigation. - await page.waitForFunction(async () => { - const state = await (await fetch('/test-state')).json(); - return state.reconnected || !state.connected || state.team === null; + await game.waitFor('departure write failure reaches server state', async () => { + const current = await state(); + return current.reconnected || !current.connected || current.team === null; }); assert(game.events.some(event => event.sequence > sequences[0] && event.direction === 'framesent' && event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 24)); @@ -59,7 +59,7 @@ try { await game.click(928, 76); await game.wait('retried native leave request', () => game.events.some(event => event.sequence > replay && event.direction === 'framesent' && event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 24)); - await page.waitForFunction(async () => (await (await fetch('/test-state')).json()).team === null); + await game.waitFor('retried departure commits', async () => (await state()).team === null); evidence.after = await state(); for (let index = 0; index < games.length; ++index) { await games[index].wait('committed departure reaches native roster', () => games[index].events.some(event =>