commit 701b70a20ff5f01b854248ac150a72528e8e6b42
parent 1c9c7298515ac02946ec16a2dfd7f09bbf1afe3b
Author: anon <anon@example.com>
Date: Wed, 4 Nov 2026 19:12:30 +0000
Verify native inventory refusals during player trade
Diffstat:
5 files changed, 103 insertions(+), 9 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -4234,6 +4234,11 @@ and server restarts. Turn every reproduced bug into a focused regression test.
both directions during wear/removal without writes or deadline changes.
No product defect reproduced on this path; see
[backpack joins](docs/backpacks.md#stack-join-during-pending-equipment).
+ A focused native reclaim/trade checkpoint also verifies a carried backpack
+ deposit during trade: cancellation restores the source, retry retains part1
+ inside bag2, and page/cold recovery conserves both IDs and the empty peer.
+ This route already works; obsolete cache/session assertions in its regression
+ were corrected. See [inventory trade refusals](docs/player-trading.md#inventory-refusals-during-player-trade).
- [x] [P0] Refresh resources after clearing an empty stale weapon hand.
A controlled earlier bank transfer leaves a native QL75 LIZARD at101:6.
Refusal now publishes the owner's current resource foundations and points.
diff --git a/docs/player-trading.md b/docs/player-trading.md
@@ -242,3 +242,25 @@ All ten combined traces are error-free without dropped events; the independent
report is `local/traded-weapon/verification.json`. The focused player-trade
suite passes20 groups and65 results in16.846s; vet, JavaScript syntax, gofmt
and whitespace checks pass.
+
+## Inventory refusals during player trade
+
+The focused `TestBrowserReclaimDuringPlayerTrade` now also follows its collected
+part through an ordinary-source deposit into an already-open owned backpack.
+The actual page104/48 -> bag2/111 request aborts the empty trade and receives
+source cancellation146. Both inventories remain unchanged. A second real pickup
+and same-window deposit retry move that exact part1 into bag2/slot0. Page replay
+reopens the bag with its child; cold Go loading retains both identities and an
+empty peer inventory, with allocator2.
+
+This route already worked; no server behavior change was needed. The fixture
+now keeps the unrelated peer's allocation cache unchanged and distinguishes
+the reset reclaim-window snapshot from durable ownership after page reload.
+Reordering cells inside ordinary inventory was observed to remain local and
+emit no InventoryMove; it does not reproduce the server's rejection branch.
+
+The accepted controlled run `local/trade-reclaim/20261104-110859` passes in14.84s
+(Go22.458s). It uses one real WASM owner and a nearby controlled peer acting
+through public trade handlers. It is not earned progression or a two-native-client
+trade-acceptance check. Independent packet/state audits and captures are under
+`local/trade-inventory-drag/`; the broader disappearance audit remains open.
diff --git a/docs/reclaim.md b/docs/reclaim.md
@@ -185,6 +185,9 @@ also establishes a real item offer, 37-credit offer and one-sided acceptance,
then checks unchanged terms/store bytes, private source cancellation, trade
cancellation/reclaim retry and both participants' exact cold inventories/wallets.
Accepted native captures: `local/trade-reclaim/20261102-210650/`.
+The current extended fixture also checks the collected part's refused deposit
+during another trade, same-page retry into its owned bag and page/cold recovery;
+see [inventory refusals during trade](player-trading.md#inventory-refusals-during-player-trade).
`TestBrowserReclaimDuringEquipment` opens reclaim beside the original street
booth, starts real axe placement and holds its server completion at a controlled
diff --git a/server/browser_trade_reclaim_test.go b/server/browser_trade_reclaim_test.go
@@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "reflect"
"runtime"
"slices"
"testing"
@@ -48,6 +49,15 @@ func TestBrowserReclaimDuringPlayerTrade(t *testing.T) {
if err := world.saveInventory_locked(player, inventory); err != nil {
t.Fatal(err)
}
+ if granted, err := world.grantItem_locked(player, 99228); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ inventory = player.inventory
+ inventory.Items = slices.Clone(inventory.Items)
+ inventory.Items[0].Slot = 65
+ if err := world.saveInventory_locked(player, inventory); err != nil {
+ t.Fatal(err)
+ }
world.clients[2] = &worldClient{id: 2, target: true, ready: true, conn: &combatTestConn{}}
mux := http.NewServeMux()
mux.Handle("/", world.httpHandler())
@@ -78,15 +88,16 @@ func TestBrowserReclaimDuringPlayerTrade(t *testing.T) {
command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_trade_reclaim.mjs"), host.URL, output)
command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr
+ t.Logf("Browser artifacts: %s", output)
if err := command.Run(); err != nil {
t.Fatal(err)
}
cold := newTestInventoryServer(t)
- expected := []ownedItem{{ID: 1, Type: 51005, Template: 42640, Quality: 1, Slot: 64, Count: 1}}
- if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) ||
- len(cold.characters[1].inventory.Reclaim) != 0 || len(cold.characters[2].inventory.Items) != 0 {
+ expected := playerInventory{LastID: 2, Items: []ownedItem{{ID: 2, Type: 51017, Template: 99228, Quality: 1, Slot: 65, Count: 1}},
+ Containers: map[uint32][]ownedItem{2: {{ID: 1, Type: 51005, Template: 42640, Quality: 1, Slot: 0, Count: 1}}}}
+ if !reflect.DeepEqual(player.inventory, expected) || !reflect.DeepEqual(cold.characters[1].inventory, expected) ||
+ world.nextItem != 2 || cold.nextItem != 2 || len(cold.characters[2].inventory.Items) != 0 {
t.Fatal("trade refusal/reclaim retry lost or transferred the exact item")
}
- t.Logf("Browser artifacts: %s", output)
}
diff --git a/tools/client/test_trade_reclaim.mjs b/tools/client/test_trade_reclaim.mjs
@@ -51,21 +51,74 @@ try {
await game.wait('same-window reclaim retry', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 48));
evidence.after = await server();
assert.equal(evidence.after.trade, false);
- assert.deepEqual(evidence.after.peerInventory, {...evidence.before.peerInventory, LastID: 1});
+ assert.deepEqual(evidence.after.peerInventory, evidence.before.peerInventory);
assert.deepEqual(evidence.after.reclaimSlots, [0]);
assert.deepEqual(evidence.after.inventory, {...evidence.before.inventory, Reclaim: null,
- Items: [{...evidence.before.inventory.Reclaim[0].Item, Slot: 64}]});
+ Items: [...evidence.before.inventory.Items, {...evidence.before.inventory.Reclaim[0].Item, Slot: 64}]});
assert.equal(game.events.filter(event => event.direction === 'framesent' && event.opcode === '47537a24').length, 2);
await game.save(output + '/picked');
+
+ // A backpack deposit aborts the trade and must restore its unoffered source.
+ const carried = () => game.state.grids.flatMap(grid => grid.cells).find(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy);
+ if (!carried()) await game.key('i');
+ const bag = game.state.grids.flatMap(grid => grid.cells).find(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === 49 && !cell.dummy);
+ assert(bag);
+ await game.click((bag.bounds[0] + bag.bounds[2]) / 2, (bag.bounds[1] + bag.bounds[3]) / 2, 'right');
+ await game.wait('empty owned bag opens before trade', state => state.grids.some(grid => grid.totalCells === 21));
+ const tradeSequence = game.sequence;
+ assert((await page.request.post(url + '/test-trade')).ok());
+ await game.wait('second native trade opens', () => game.events.some(event => event.sequence > tradeSequence &&
+ event.direction === 'framereceived' && event.opcode === '36284f6e' && Buffer.from(event.hex, 'hex').readUInt32BE(33) === 0));
+ evidence.inventoryTrade = await server();
+ assert.equal(evidence.inventoryTrade.trade, true);
+ const drag = async () => {
+ const source = carried();
+ assert(source);
+ await game.click((source.bounds[0] + source.bounds[2]) / 2, (source.bounds[1] + source.bounds[3]) / 2);
+ await game.wait('real carried source picked', state => state.dragged[0] === 104 && state.dragged[1] === 48);
+ const destination = game.state.grids.find(grid => grid.totalCells === 21).cells.find(cell => cell.identity[0] === 0);
+ assert(destination);
+ assert.equal(destination.identity[0], 0);
+ await game.click((destination.bounds[0] + destination.bounds[2]) / 2, (destination.bounds[1] + destination.bounds[3]) / 2);
+ };
+ await drag();
+ await game.wait('real carried deposit during trade', () => game.events.some(event => event.sequence > tradeSequence &&
+ event.direction === 'framesent' && event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 104 &&
+ Buffer.from(event.hex, 'hex').readUInt32BE(37) === 51017));
+ evidence.inventoryRefused = await server();
+ assert.deepEqual(evidence.inventoryRefused, {...evidence.inventoryTrade, trade: false});
+ await game.save(output + '/inventory-refused');
+ await game.wait('aborted-trade carried source restores', () => carried() && game.state.dragged[0] === 0 && game.state.dragged[1] === 0);
+ await drag();
+ await game.wait('same-page carried deposit retries', state => state.grids.some(grid => grid.cells.some(cell =>
+ cell.identity[0] === 107 && cell.identity[1] === 65536 && !cell.dummy)));
+ evidence.inventoryAfter = await server();
+ assert.deepEqual(evidence.inventoryAfter.inventory.Items, evidence.before.inventory.Items);
+ assert.deepEqual(evidence.inventoryAfter.inventory.Containers[2], [{...evidence.before.inventory.Reclaim[0].Item, Slot: 0}]);
+ assert.deepEqual(evidence.inventoryAfter.peerInventory, evidence.after.peerInventory);
+ await game.save(output + '/inventory-retried');
await page.reload();
await game.ready();
await page.waitForFunction(() => touchRegion(500, 400)?.world === true);
await game.snapshot();
if (!game.state.grids.some(grid => grid.cells.some(cell => cell.identity[0] === 104 && !cell.dummy))) await game.key('i');
- await game.wait('retained part visible after page replay', state => state.grids.some(grid => grid.cells.some(cell =>
- cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy)));
+ await game.wait('retained bag visible after page replay', state => state.grids.some(grid => grid.cells.some(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === 49 && !cell.dummy)));
+ const replayedBag = game.state.grids.flatMap(grid => grid.cells).find(cell => cell.identity[0] === 104 && cell.identity[1] === 49 && !cell.dummy);
+ await game.click((replayedBag.bounds[0] + replayedBag.bounds[2]) / 2, (replayedBag.bounds[1] + replayedBag.bounds[3]) / 2, 'right');
+ await game.wait('retained part replays inside its bag', state => state.grids.some(grid => grid.cells.some(cell =>
+ cell.identity[0] === 107 && cell.identity[1] === 65536 && !cell.dummy)));
+ evidence.final = await server();
+ assert.deepEqual(evidence.final.inventory, evidence.inventoryAfter.inventory);
+ assert.deepEqual(evidence.final.peerInventory, evidence.inventoryAfter.peerInventory);
+ assert.equal(evidence.final.trade, false);
+ assert.equal(evidence.final.reclaimSlots, null);
+ assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot]), [[2, 49]]);
assert.equal(game.errors.length, 0);
- console.log('PASS: reclaim pickup during trade restores its source, preserves both participants and retries after cancellation');
+ assert.equal(game.dropped, 0);
+ console.log('PASS: reclaim and ordinary carried refusals during trade restore usable sources and retain exact ownership through retry/page/cold recovery');
} finally {
try {
await fs.mkdir(output, {recursive: true});