commit 542dd3ca5f93a6cb40b35669a896c41eeb937949
parent 9a11c775ecd9269ea6937188a15bac06b44d1163
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 17:41:15 +0000
Capture browser exception stacks and verify pending equip edits
Diffstat:
7 files changed, 232 insertions(+), 1 deletion(-)
diff --git a/DEVELOPERS.md b/DEVELOPERS.md
@@ -524,6 +524,10 @@ browser, streams and HTTP server even after failures. Reports and screenshots
remain in `local/game-tests/<run>/`. On the Linux desktop, use the same working
DISPLAY/XAUTHORITY environment as the other GPU browser checks.
+The Chromium harness saves runtime exception details with each error, preserving
+stack frames even for primitive throws such as `unwind`. Verify that diagnostic
+path without loading the game with `node --test tools/client/test_game_errors.mjs`.
+
`TestBrowserStarterEquipment` creates two Atrox Enforcers through Options with
their normal Omni starter loadouts and the production training-ground population.
It checks issued-bat equip/remove/re-wear, normal skill purchases, the issued
diff --git a/TODO.md b/TODO.md
@@ -3785,6 +3785,9 @@ with payloads and known client/server provenance.
ability edit while holding an item) with advancing native frames and no
captured errors. This does not establish a fix; retain the stack-capture
task. Evidence: `local/live-editor-smoke/verification.json`.
+ The harness now saves Chromium exception details, including stacks for
+ primitive `unwind` throws that Playwright's pageerror loses. A real-browser
+ regression checks both Error objects and strings; the freeze remains unreproduced.
These checks are additional work, not claims that the existing feature tests
already establish complete gameplay correctness. Cover positive and negative
@@ -3870,6 +3873,10 @@ and server restarts. Turn every reproduced bug into a focused regression test.
pending replacement. One same-slot refusal preserves the original swap and
deadline; later swaps, page replay and a cold database read retain both IDs.
This path passes without a product change; the broader audit remains open.
+ A live control edit during an admitted pending equip now has a short native
+ regression: reconnect restores the carried instance, frames resume, and the
+ same item equips again without page reload. Page/cold ownership also passes;
+ see [pending equipment edits](docs/inventory.md#live-edits-during-pending-equipment).
A focused two-client native trade now follows an already instantiated QL50
weapon through cancellation, mutual acceptance, immediate recipient
wear/remove/rewear and one shot, without a corrective reconnect. Its physical
diff --git a/docs/inventory.md b/docs/inventory.md
@@ -509,6 +509,21 @@ inventory captures were reviewed.
AO_GAME_TEST=1 go test ./server -run '^TestBrowserSecondEquipmentMove$' -count=1 -timeout=4m -v
```
+### Live edits during pending equipment
+
+`TestBrowserPendingEquipmentEdit` admits a real native Kinetic Axe equip and
+holds its server completion. A control-panel name edit reconnects the playfield,
+cancels that pending action and restores the exact carried instance. Native
+frames resume on the new world stream, and another real equip succeeds without
+reloading the page. Page replay and a fresh database load retain item 1 in slot 6.
+This is a controlled late-acknowledgement fixture, not earned progression or a
+reproduction of the earlier live-edit freeze. The accepted native run took18.69s:
+`local/pending-edit/20261103-094003`; all four traces have empty error lists.
+
+```sh
+AO_GAME_TEST=1 go test ./server -run '^TestBrowserPendingEquipmentEdit$' -count=1 -timeout=3m -v
+```
+
### Weapon instance delivery
The native `WeaponItemFullUpdate` (`0x3b1d2268`) creates the visible owned weapon
diff --git a/server/browser_pending_edit_test.go b/server/browser_pending_edit_test.go
@@ -0,0 +1,71 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "slices"
+ "testing"
+ "time"
+)
+
+func TestBrowserPendingEquipmentEdit(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for a live edit during pending equipment")
+ }
+
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/pending-edit", time.Now().Format("20060102-150405"))
+ world := newTestServer(t)
+ player := world.newCharacter()
+ player.stats = testCharacterStats()
+ player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("pending-edit")))
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if granted, err := world.grantItem_locked(player, 209283); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ mux := http.NewServeMux()
+ mux.Handle("/", world.httpHandler())
+ mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) {
+ world.mutex.Lock()
+ defer world.mutex.Unlock()
+ client := world.clients[1]
+ json.NewEncoder(w).Encode(map[string]any{"inventory": player.inventory,
+ "pending": client != nil && client.equipment != nil})
+ })
+ // Complete the post-edit retry only after native admission is observed.
+ mux.HandleFunc("POST /test-complete", func(w http.ResponseWriter, r *http.Request) {
+ world.mutex.Lock()
+ finish := world.clients[1].equipment.readyAt
+ world.mutex.Unlock()
+ world.advanceEquipment(finish)
+ })
+ host := httptest.NewServer(mux)
+ t.Cleanup(host.Close)
+ closeTestBrowserStreams(t, world)
+ ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
+ defer cancel()
+
+ command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_pending_edit.mjs"), host.URL, output)
+ command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr
+ if err := command.Run(); err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t)
+
+ expected := []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 6, Count: 1}}
+ if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) {
+ t.Fatal("live edit lost or changed the pending weapon")
+ }
+ t.Logf("Browser artifacts: %s", output)
+}
diff --git a/tools/client/game_test.mjs b/tools/client/game_test.mjs
@@ -63,7 +63,13 @@ export class GameTest {
game.record({kind: 'navigation', url: frame.url()});
}
});
- page.on('pageerror', error => game.record({kind: 'error', message: String(error)}));
+ // Playwright's pageerror loses the stack when WASM throws a string such as unwind.
+ const runtime = await page.context().newCDPSession(page);
+ runtime.on('Runtime.exceptionThrown', ({exceptionDetails}) => game.record({kind: 'error',
+ message: exceptionDetails.exception?.description?.split('\n')[0] ??
+ String(exceptionDetails.exception?.value ?? exceptionDetails.text),
+ details: exceptionDetails}));
+ await runtime.send('Runtime.enable');
page.on('console', message => {
if (message.type() === 'error' || message.type() === 'warning')
game.record({kind: 'console', level: message.type(), message: message.text()});
diff --git a/tools/client/test_game_errors.mjs b/tools/client/test_game_errors.mjs
@@ -0,0 +1,53 @@
+import assert from 'node:assert/strict';
+import {once} from 'node:events';
+import fs from 'node:fs/promises';
+import os from 'node:os';
+import path from 'node:path';
+import {createRequire} from 'node:module';
+import {test} from 'node:test';
+import {GameTest} from './game_test.mjs';
+
+const {chromium} = createRequire(import.meta.url)('playwright');
+
+test('browser traces retain stacks for Error objects and primitive unwind throws', {timeout: 10000}, async () => {
+ const output = await fs.mkdtemp(path.join(os.tmpdir(), 'ao-game-errors-'));
+ const browser = await chromium.launch({executablePath: '/usr/bin/chromium',
+ args: ['--no-sandbox', '--disable-dev-shm-usage']});
+ try {
+ const page = await browser.newPage();
+ const game = await GameTest.attach(page);
+ await page.route('http://error-capture.test/**', route => route.fulfill(
+ route.request().url().endsWith('/failure.js') ? {
+ contentType: 'application/javascript', body: `
+ function failDuringLiveEdit() { throw new Error('live edit diagnostic'); }
+ function unwindDuringLiveEdit() { throw 'unwind'; }
+ function reloadPlayfield(fail) { fail(); }
+ document.querySelector('#error').onclick = () => setTimeout(() => reloadPlayfield(failDuringLiveEdit), 0);
+ document.querySelector('#unwind').onclick = () => setTimeout(() => reloadPlayfield(unwindDuringLiveEdit), 0);
+ `,
+ } : {contentType: 'text/html', body: '<button id="error">Error</button><button id="unwind">Unwind</button><script src="/failure.js"></script>'}));
+
+ await page.goto('http://error-capture.test/');
+ for (const id of ['error', 'unwind']) {
+ const captured = once(game.inputEvents, 'input', {signal: AbortSignal.timeout(5000)});
+ await page.locator('#' + id).click();
+ await captured;
+ }
+ await game.save(output);
+ const trace = JSON.parse(await fs.readFile(path.join(output, 'trace.json'), 'utf8'));
+
+ assert.deepEqual(trace.errors.map(error => error.message), ['Error: live edit diagnostic', 'unwind']);
+ assert.deepEqual(trace.errors, game.errors);
+ for (const [index, name] of ['failDuringLiveEdit', 'unwindDuringLiveEdit'].entries()) {
+ const frames = trace.errors[index].details.stackTrace.callFrames;
+ assert.equal(frames[0].functionName, name);
+ assert.equal(frames[1].functionName, 'reloadPlayfield');
+ assert.equal(frames[0].url, 'http://error-capture.test/failure.js');
+ assert.equal(frames[0].lineNumber, index + 1);
+ assert.equal(trace.errors[index].navigation, 1);
+ }
+ } finally {
+ await browser.close();
+ await fs.rm(output, {recursive: true});
+ }
+});
diff --git a/tools/client/test_pending_edit.mjs b/tools/client/test_pending_edit.mjs
@@ -0,0 +1,75 @@
+import assert from 'node:assert/strict';
+import fs from 'node:fs/promises';
+import {createRequire} from 'node:module';
+import {GameTest} from './game_test.mjs';
+
+const {chromium} = createRequire(import.meta.url)('playwright');
+const [url, output] = process.argv.slice(2);
+const browser = await chromium.launch({executablePath: '/usr/bin/chromium',
+ args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage',
+ '--disable-background-timer-throttling', '--disable-renderer-backgrounding']});
+let game;
+const evidence = {};
+try {
+ const context = await browser.newContext({viewport: {width: 1024, height: 768}});
+ await context.addCookies([{name: 'ao_client', value: 'pending-edit', url}]);
+ const page = await context.newPage();
+ game = await GameTest.attach(page);
+ await page.goto(url);
+ await game.ready();
+ const server = async () => (await page.request.get(url + '/test-state')).json();
+ const equip = async () => {
+ const cell = game.state.grids.flatMap(grid => grid.cells).find(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy);
+ const sequence = game.sequence;
+ await game.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2);
+ await game.click(867, 206);
+ await game.wait('native equip request', () => game.events.some(event => event.sequence > sequence &&
+ event.direction === 'framesent' && event.opcode === '47537a24'));
+ assert.equal((await server()).pending, true);
+ };
+
+ // Edit while the admitted native equipment action still awaits completion.
+ await game.key('i');
+ await page.keyboard.press('Control+1');
+ await game.wait('carried weapon visible', state => state.grids.some(grid => grid.cells.some(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy)));
+ await equip();
+ evidence.pending = await server();
+ await game.save(output + '/pending');
+ const stream = game.worldStream, frame = game.state.frame;
+ const edited = await page.request.post(url + '/control/users/1', {
+ form: {data: 'name: Pending Edit Check\n'}, maxRedirects: 0});
+ assert.equal(edited.status(), 303);
+ await game.wait('new world stream after live edit', () => game.worldStream !== stream);
+ await game.ready();
+ await game.wait('native frames resume after live edit', state => state.frame > frame);
+ evidence.edited = await server();
+ assert.equal(evidence.edited.pending, false);
+ assert.deepEqual(evidence.edited.inventory.Items, evidence.pending.inventory.Items);
+ assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot]), [[1, 48]]);
+ await game.save(output + '/edited');
+
+ // Reuse the same instance without reloading the browser page.
+ await game.wait('carried weapon restored after live edit', state => state.grids.some(grid => grid.cells.some(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy)));
+ await equip();
+ assert((await page.request.post(url + '/test-complete')).ok());
+ await game.wait('post-edit equip completes', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 6));
+ evidence.equipped = await server();
+ assert.equal(evidence.equipped.pending, false);
+ assert.equal(game.navigation, 1);
+ assert.equal(game.errors.length, 0);
+ await game.save(output + '/equipped');
+ await page.reload();
+ await game.ready();
+ assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot]), [[1, 6]]);
+ assert.equal(game.errors.length, 0);
+ console.log('PASS: live edit cancels pending equip, resumes native frames and preserves the usable instance');
+} finally {
+ try {
+ await fs.mkdir(output, {recursive: true});
+ await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n');
+ if (game) await game.save(output + '/final');
+ } finally { await browser.close(); }
+}