commit 53c7795b407be2095ce1d247c61ac90865fe0ed5
parent 1dd0204602cd72e36ba485b31c06f3a29f030deb
Author: anon <anon@example.com>
Date: Wed, 28 Oct 2026 23:12:12 +0000
Audit equipment conservation across failed moves
Diffstat:
3 files changed, 205 insertions(+), 0 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -2857,6 +2857,16 @@ and server restarts. Turn every reproduced bug into a focused regression test.
after reconnect and restart. The rejected-drag defect below is reproduced and
fixed; continue auditing other paths rather than treating that one fix or
passing Go tests as proof that the entire earlier report is resolved.
+- [x] Extend equipment conservation checks across placement rollback, retry and
+ lost replies. Both wear/removal now cover failed and ignored location deletes
+ and inserts, failed COMMIT, unchanged unrelated items, cold ownership and no
+ observer success on failure. A grant during the equip delay and failed output
+ retain their committed instances. A hardware WASM audit conserved 31 fixture
+ identities through full-inventory removal refusal, shirt wear and reconnect;
+ all unrelated database items were unchanged. The full-inventory refusal was
+ native-side, and the attempted wrong-slot placement requested a valid chest
+ slot, so neither is claimed as a new server-rejection reproduction. The P0
+ disappearance audit remains open. See [equipment conservation](docs/inventory.md#equipment-conservation-audit).
- [x] Restore the inventory icon after a rejected equipment drag. Check: native
pickup/place and auto-equip of unsupported armor leave its icon usable and
its instance/slot unchanged. Repeated rejection preserves the worn suit's AC;
diff --git a/docs/inventory.md b/docs/inventory.md
@@ -231,6 +231,50 @@ context to check persistence and isolation. Chromium and Firefox pass those
checks alongside the existing cache and viewport cases.
+## Equipment conservation audit
+
+`server/equipment_conservation_test.go` adds focused public-handler checks for
+both wear and removal. Each direction injects a failed or ignored placement
+deletion, a failed or ignored insertion, and a deferred foreign-key failure at
+commit. Every failure must retain both the moved weapon and an unrelated item
+in memory and after a cold load, send only source correction to the owner, and
+send no equipment update to an observer. Removing the fault and repeating the
+request must commit the same instances at their intended destinations.
+
+Additional checks grant an unrelated item during the equip delay and lose the
+first outgoing reply after a successful wear/removal. The new item must survive
+completion; a lost reply must disconnect the session while preserving the
+committed placement for reconnect. These tests extend the audit without changing
+equipment behavior or establishing that every disappearance report is resolved.
+
+The related equipment, inventory, utility and wearable-container group passes
+31 root tests /156 results normally and under the race detector, with no skips.
+`go vet ./server` also passes. Logs live in `local/equipment-conservation/`.
+
+The hardware WASM pass in `local/equipment-conservation/` uses one isolated
+visitor with 31 explicitly provisioned instances, not an earned progression
+character. Native right-click wear put one axe in the right hand. The second
+axe's captured request from native slot49 to the occupied hand received
+slot49->48 and slot48->49 corrections. Both identities and their icons remained
+available. Filling all 30 ordinary inventory slots made
+native right-click removal display `Inventory full, please make room in your
+inventory first!`; the client emitted no removal request. This verifies the
+native admission guard, not a server rejection round trip.
+
+An explicit shirt pickup and placement in the Wear window produced a native
+request for its valid chest slot, despite the scripted click aiming at the head
+cell. It therefore counts as successful wear, not invalid-slot coverage. All
+31 native identities remained unique at every full-inventory checkpoint and
+after reconnect. A read-only database comparison retained all 49 current item
+records and locations except that intended shirt move; unrelated items were
+unchanged. No page error occurred. Fast unsatisfied pointer/click sequences in
+the initial exploration are excluded from rejection claims, following the input
+timing limits in [native equipment input](native-equipment-input.md).
+
+The owned browser was closed after the run. The isolated visitor and tracked
+fixture instances remain available for continuing this audit. This pass does
+not claim a native server restart, complete item/slot coverage, or a new fix.
+
## Melee equipment
QL 1 Kinetic Axe, template 209283, is the first supported weapon. Its definition
diff --git a/server/equipment_conservation_test.go b/server/equipment_conservation_test.go
@@ -0,0 +1,151 @@
+package main
+
+import (
+ "bytes"
+ "encoding/binary"
+ "reflect"
+ "testing"
+)
+
+func TestEquipmentPlacementFailurePreservesEveryItemThenRetries(t *testing.T) {
+ for _, direction := range []string{"wear", "remove"} {
+ for _, failure := range []string{"delete", "ignored delete", "insert", "ignored insert", "commit"} {
+ t.Run(direction+"/"+failure, func(t *testing.T) {
+ world, owner := newEquipmentWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ player, client := world.characters[1], world.clients[1]
+ observer := &combatTestConn{}
+ world.characters[2] = &character{id: 2, playfield: player.playfield, health: 100}
+ world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true}
+ if granted, err := world.grantItem_locked(player, 121567); err != nil || !granted {
+ t.Fatal("grant unrelated item", granted, err)
+ }
+ request := inventoryMovePacket(1, 64, 6)
+ if direction == "remove" {
+ if err := world.handleInventory(client, request[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ request = itemMovePacket(1, 6, 111)
+ }
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ items := append([]ownedItem(nil), player.inventory.Items...)
+ owner.packets = nil
+ observer.packets = nil
+ statement := "CREATE TRIGGER reject_equipment BEFORE DELETE ON item_locations WHEN OLD.item_id=1 BEGIN SELECT RAISE(FAIL, 'equipment placement failure'); END"
+ switch failure {
+ case "ignored delete":
+ statement = "CREATE TRIGGER reject_equipment BEFORE DELETE ON item_locations WHEN OLD.item_id=1 BEGIN SELECT RAISE(IGNORE); END"
+ case "insert":
+ statement = "CREATE TRIGGER reject_equipment BEFORE INSERT ON item_locations WHEN NEW.item_id=1 BEGIN SELECT RAISE(FAIL, 'equipment placement failure'); END"
+ case "ignored insert":
+ statement = "CREATE TRIGGER reject_equipment BEFORE INSERT ON item_locations WHEN NEW.item_id=1 BEGIN SELECT RAISE(IGNORE); END"
+ case "commit":
+ statement = "CREATE TABLE pending_equipment (player_id INTEGER REFERENCES players(id) DEFERRABLE INITIALLY DEFERRED); CREATE TRIGGER reject_equipment AFTER INSERT ON item_locations WHEN NEW.item_id=1 BEGIN INSERT INTO pending_equipment VALUES (999999); END"
+ }
+ if _, err := world.db.Exec(statement); err != nil {
+ t.Fatal(err)
+ }
+
+ if err := world.handleInventory(client, request[20:]); err != nil || client.equipment == nil {
+ t.Fatal("move admission", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ after, err := readTestItemStore(world)
+ cold := newTestInventoryServer(t)
+
+ if err != nil || !bytes.Equal(before, after) || !reflect.DeepEqual(items, player.inventory.Items) ||
+ !reflect.DeepEqual(items, cold.characters[1].inventory.Items) || client.equipment != nil || len(observer.packets) != 0 {
+ t.Fatal("failed placement changed an item or published pending equipment", err)
+ }
+ for _, packet := range owner.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) != 0x47537a24 {
+ t.Fatalf("failed placement emitted more than inventory correction: %x", packet)
+ }
+ }
+ if len(owner.packets) != 1 && direction == "remove" || len(owner.packets) != 2 && direction == "wear" {
+ t.Fatal("failed placement did not restore the native source")
+ }
+
+ if _, err := world.db.Exec("DROP TRIGGER reject_equipment"); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleInventory(client, request[20:]); err != nil || client.equipment == nil {
+ t.Fatal("retry admission", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ cold = newTestInventoryServer(t)
+
+ if direction == "wear" {
+ items[0].Slot = 6
+ } else {
+ items[0].Slot = 64
+ }
+ if !reflect.DeepEqual(items, player.inventory.Items) || !reflect.DeepEqual(items, cold.characters[1].inventory.Items) {
+ t.Fatal("retry changed an instance, quantity or unrelated placement")
+ }
+ })
+ }
+ }
+}
+
+func TestPendingEquipmentRetainsAnItemGrantedDuringItsDelay(t *testing.T) {
+ world, _ := newEquipmentWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ client := world.clients[1]
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("move admission", err)
+ }
+ deadline := client.equipment.readyAt
+
+ granted, err := world.grantItem_locked(world.characters[1], 121567)
+ world.advanceEquipment(deadline)
+ cold := newTestInventoryServer(t)
+
+ expected := []ownedItem{
+ {ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 6, Count: 1},
+ {ID: 2, Type: 51018, Template: 121567, Quality: 1, Slot: 65, Count: 1},
+ }
+ if err != nil || !granted || !reflect.DeepEqual(expected, world.characters[1].inventory.Items) ||
+ !reflect.DeepEqual(expected, cold.characters[1].inventory.Items) {
+ t.Fatal("completing a delayed move lost or changed a newly granted item", granted, err)
+ }
+}
+
+func TestEquipmentLostReplyRetainsCommittedPlacementAcrossRestart(t *testing.T) {
+ for _, direction := range []string{"wear", "remove"} {
+ t.Run(direction, func(t *testing.T) {
+ world, _ := newEquipmentWorld(t)
+ t.Cleanup(func() { world.db.Close() })
+ client := world.clients[1]
+ request := inventoryMovePacket(1, 64, 6)
+ if direction == "remove" {
+ if err := world.handleInventory(client, request[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ request = itemMovePacket(1, 6, 111)
+ }
+ output := &failingCombatConn{}
+ client.conn = output
+
+ if err := world.handleInventory(client, request[20:]); err != nil || client.equipment == nil {
+ t.Fatal("move admission", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ cold := newTestInventoryServer(t)
+
+ expected := ownedItem{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 6, Count: 1}
+ if direction == "remove" {
+ expected.Slot = 64
+ }
+ if !output.closed || !reflect.DeepEqual([]ownedItem{expected}, world.characters[1].inventory.Items) ||
+ !reflect.DeepEqual([]ownedItem{expected}, cold.characters[1].inventory.Items) {
+ t.Fatal("lost reply reversed or lost the committed item placement")
+ }
+ })
+ }
+}