commit bb75d226677e90893a1d970502fd5d0b72fe0e13
parent 93b6e60b8bb96910ab37a7a4ad4fdff21b902963
Author: anon <anon@example.com>
Date: Wed, 4 Nov 2026 20:00:19 +0000
Verify corpse expiry during a native pickup gesture
Diffstat:
5 files changed, 193 insertions(+), 9 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -4757,6 +4757,11 @@ and server restarts. Turn every reproduced bug into a focused regression test.
untaken gloves expired before pickup committed. Evidence:
[earned creature upgrades](docs/earned-creature-upgrade.md) and
`local/earned-creature-upgrade/`.
+ A short controlled two-member native regression now expires partially looted
+ remains during an active pickup gesture. Both windows close before typed
+ destruction; page/cold recovery retains the collected item and wallets while
+ the untaken item stays deleted. No defect reproduced on this path; see
+ [pickup expiry](docs/corpse-loot.md#expiry-during-a-native-pickup).
- [x] [P0] Remove stale corpse source rows after another entitled player collects
an item. Reproduction: two native team members open one corpse, then one
collects its item while the other's mouse gesture is pending. An empty
diff --git a/docs/corpse-loot.md b/docs/corpse-loot.md
@@ -405,6 +405,26 @@ socket failures were confined to the intentional restart. Screenshots,
per-step states and machine-checked results are retained in
`local/corpse-expiry-smoke/`.
+### Expiry during a native pickup
+
+`TestBrowserCorpseExpiryDuringNativePickup` adds a repeatable two-member case.
+One native member collects item1 while item2 remains at corpse slot7. The other
+member holds a consumed mouse-down over that remaining source while the fixture
+advances the normal expiry visitor to its saved deadline. Both clients receive
+close, hidden-character destruction and corpse destruction in that order.
+The windows and both native objects disappear; releasing and clicking again
+emits no pickup request and neither client crashes or freezes.
+
+Both page reloads retain the collected QL1 item and the1/0 wallets. Cold Go
+loading retains sole ownership and allocator2, deletes the corpse source, and
+confirms the untaken QL2 item is absent. The fixture isolates expiry from respawn
+and does not establish a historical lifetime. This path passes without a product
+change; broader placement remains open. Captures and verification are in
+`local/corpse-pickup-expiry/`.
+The final expiry/peer checks pass in26.21/26.78 seconds, with all seven saved
+traces free of native errors or dropped events. The captured close falls between
+the consumed mouse-down and mouse-up; vet and driver syntax also pass.
+
The published WASM client was checked with a real combat kill, fallen corpse,
open/close/reopen, native Monster Parts details showing QL 1, pickup into the
ordinary inventory, empty corpse, page reconnect and server restart. The item
diff --git a/server/browser_corpse_expiry_test.go b/server/browser_corpse_expiry_test.go
@@ -0,0 +1,71 @@
+package main
+
+import (
+ "context"
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "slices"
+ "testing"
+ "time"
+)
+
+func TestBrowserCorpseExpiryDuringNativePickup(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for native corpse expiry during pickup")
+ }
+
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/corpse-pickup-expiry", time.Now().Format("20060102-150405"))
+ world := newBrowserCorpsePeerWorld(t)
+ corpse := world.characters[1000000].corpse
+ corpse.items = append(corpse.items, ownedItem{ID: 2, Type: 51005, Template: 42640, Quality: 2, Slot: 7, Count: 1})
+ // Isolate retirement of the remaining loot from the separately tested respawn.
+ world.nextItem, world.npcRespawns = 2, nil
+ if err := world.flushWorld(); err != nil {
+ t.Fatal(err)
+ }
+ deadline := corpse.expiresAt
+ 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()
+ json.NewEncoder(w).Encode(map[string]any{"first": world.characters[1].inventory, "second": world.characters[2].inventory,
+ "present": world.characters[1000000] != nil, "loot": [2]uint32{world.clients[1].lootCorpse, world.clients[2].lootCorpse},
+ "interest": [2]bool{world.clients[1].npcs[1000000], world.clients[2].npcs[1000000]}})
+ })
+ mux.HandleFunc("POST /test-expire", func(w http.ResponseWriter, r *http.Request) {
+ world.advanceCorpseExpiry(deadline)
+ w.WriteHeader(http.StatusNoContent)
+ })
+ host := httptest.NewServer(mux)
+ t.Cleanup(host.Close)
+ closeTestBrowserStreams(t, world)
+ ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
+ defer cancel()
+
+ t.Logf("Browser artifacts: %s", output)
+ command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_corpse_pickup_expiry.mjs"), host.URL, output)
+ command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr
+ err := command.Run()
+
+ if err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t)
+ if len(cold.characters[1].inventory.Items) != 0 ||
+ !slices.Equal(cold.characters[2].inventory.Items, []ownedItem{{ID: 1, Type: 51005, Template: 42640, Quality: 1, Slot: 64, Count: 1}}) ||
+ cold.characters[1].inventory.Credits != 1 || cold.characters[2].inventory.Credits != 0 || cold.characters[1000000] != nil || cold.nextItem != 2 {
+ t.Fatal("expiry changed collected ownership, cash, retirement or allocation")
+ }
+ var count int
+ if err := cold.db.QueryRow("SELECT count(*) FROM items WHERE id=2").Scan(&count); err != nil || count != 0 {
+ t.Fatal("untaken item survived expiry", count, err)
+ }
+}
diff --git a/server/browser_corpse_peer_pickup_test.go b/server/browser_corpse_peer_pickup_test.go
@@ -17,14 +17,8 @@ import (
"time"
)
-func TestBrowserCorpsePeerPickupClearsNativeSource(t *testing.T) {
- if os.Getenv("AO_GAME_TEST") != "1" {
- t.Skip("set AO_GAME_TEST=1 for native concurrent corpse pickup")
- }
-
- _, source, _, _ := runtime.Caller(0)
- root := filepath.Dir(filepath.Dir(source))
- output := filepath.Join(root, "local/corpse-peer-pickup", time.Now().Format("20060102-150405"))
+func newBrowserCorpsePeerWorld(t *testing.T) *server {
+ t.Helper()
world := newTestServer(t)
players := make(map[uint32]*character)
for index, x := range []float32{958, 962} {
@@ -56,12 +50,25 @@ func TestBrowserCorpsePeerPickupClearsNativeSource(t *testing.T) {
if corpse == nil || len(corpse.items) != 1 {
t.Fatal("controlled killing blow did not generate one item")
}
- item := corpse.items[0]
corpse.expiresAt = time.Now().Add(10 * time.Minute)
if err := world.flushWorld(); err != nil {
t.Fatal(err)
}
delete(world.clients, 1)
+ return world
+}
+
+func TestBrowserCorpsePeerPickupClearsNativeSource(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for native concurrent corpse pickup")
+ }
+
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/corpse-peer-pickup", time.Now().Format("20060102-150405"))
+ world := newBrowserCorpsePeerWorld(t)
+ players, corpse := world.characters, world.characters[1000000].corpse
+ item := corpse.items[0]
mux := http.NewServeMux()
mux.Handle("/", world.httpHandler())
mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) {
diff --git a/tools/client/test_corpse_pickup_expiry.mjs b/tools/client/test_corpse_pickup_expiry.mjs
@@ -0,0 +1,81 @@
+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']});
+const games = [];
+const evidence = {};
+const source = (state, slot) => state.grids.flatMap(grid => grid.cells).find(cell =>
+ cell.identity[0] === 107 && cell.identity[1] === slot && !cell.dummy);
+const closed = state => !state.actors.some(actor => actor.id === 1000000 && (actor.type === 51050 || actor.type === 50000)) &&
+ !state.regions.some(region => region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128);
+try {
+ for (let id = 1; id <= 2; ++id) {
+ const context = await browser.newContext({viewport: {width: 1024, height: 768}});
+ await context.addCookies([{name: 'ao_client', value: 'corpse-peer-' + id, url}]);
+ const page = await context.newPage();
+ const game = await GameTest.attach(page);
+ games.push(game);
+ await page.goto(url);
+ await game.ready();
+ await game.click(...await game.pick(51050, 1000000), 'right');
+ await game.wait('two shared corpse sources', state => source(state, 0) && source(state, 7));
+ }
+ const [first, second] = games;
+ const server = async () => (await first.page.request.get(url + '/test-state')).json();
+ await second.click(30, 45);
+ await second.wait('one item collected before expiry', state => second.local(state).inventory.length === 1);
+ await first.wait('remaining nonzero source retained', state => source(state, 7));
+ evidence.partial = await server();
+
+ // Expire the remaining source during a consumed native mouse-down gesture.
+ const cell = source(first.state, 7);
+ const point = await first.point((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2);
+ await first.page.bringToFront();
+ await first.page.mouse.move(point.x, point.y);
+ const sequence = first.sequence;
+ await first.page.mouse.down();
+ try {
+ await first.waitInput(sequence, 1025);
+ assert.equal((await first.page.request.post(url + '/test-expire')).status(), 204);
+ await first.wait('expiry closes the clicked source and corpse', closed);
+ await second.wait('expiry closes the other member window', closed);
+ } finally {
+ const release = first.sequence;
+ await first.page.mouse.up();
+ await first.waitInput(release, 1026);
+ }
+ await first.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2);
+ await first.snapshot();
+ evidence.expired = await server();
+ evidence.pickupsAfterExpiry = first.events.filter(event => event.sequence > sequence &&
+ event.direction === 'framesent' && event.opcode === '47537a24').length;
+ assert.equal(evidence.pickupsAfterExpiry, 0);
+ assert.deepEqual(evidence.expired, {...evidence.partial, present: false, loot: [0, 0], interest: [false, false]});
+ evidence.retirement = [];
+ for (const game of games) {
+ const retirement = game.events.filter(event => event.direction === 'framereceived' && event.actor?.[1] === 1000000 &&
+ (event.opcode === '2049527c' || event.opcode === '36510078')).map(event => [event.opcode, ...event.actor]);
+ assert.deepEqual(retirement, [['2049527c', 51050, 1000000], ['36510078', 50000, 1000000], ['36510078', 51050, 1000000]]);
+ evidence.retirement.push(retirement);
+ await game.save(output + '/expired-' + (game === first ? 1 : 2));
+ await game.page.reload();
+ await game.ready();
+ assert.deepEqual(game.local().inventory.map(item => [item.type, item.id, item.slot, item.quality, item.count]),
+ game === second ? [[51005, 1, 48, 1, 1]] : []);
+ assert(closed(game.state));
+ assert.deepEqual(game.errors, []);
+ }
+ console.log('PASS: corpse expiry during native pickup closes both windows, preserves collected loot and destroys only untaken loot');
+} finally {
+ try {
+ await fs.mkdir(output, {recursive: true});
+ await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n');
+ for (let index = 0; index < games.length; ++index) await games[index].save(output + '/final-' + (index + 1));
+ } finally { await browser.close(); }
+}