commit bf7091004c0a8a31a30a7682bc1ccca89b4571d8
parent 1d41bd899e17fa05f2dbd90bcc2b722191ad691a
Author: anon <anon@example.com>
Date: Fri, 6 Nov 2026 00:20:46 +0000
Cover pending nano casts across live and reloading admin edits
Diffstat:
4 files changed, 137 insertions(+), 19 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -213,15 +213,13 @@ rewriting this document does not close them.
## P1: bounded follow-up work
-- [ ] **Update the pending-cast admin item-edit regression for live inventory edits.**
- `TestNanoReservationItemEditCommitsRefundWithActorReload` still expects an
- actor reload and refund when changing a carried kit's count. The current
- `liveInventoryEdit_locked` path deliberately preserves the actor and cast.
- November 5: both subcases fail identically in the pre-Trader-change binary
- and the current nano regression batch. Cover reservation preservation and
- later settlement for a live edit, while retaining a real actor-reload/refund
- case and rejected-write checks. Completion: both edit paths have passing
- assertions for exactly one cost or refund and no partial item mutation.
+- [x] **Update the pending-cast admin item-edit regression for live inventory edits.**
+ Carried-kit edits now have passing checks for session/cast preservation,
+ completion or cancellation, failed writes and retry. The separate equipped
+ helmet edit checks atomic refund/reload, rejected writes, retry and repeated
+ cold recovery without duplicate refunds. November 5: the related reservation,
+ live-admin and open-shop edit checks pass. This corrects the obsolete test
+ expectation; no game behavior changed. See [admin edit semantics](docs/admin.md).
- [ ] **Keep account UI changes in the browser source when publishing.**
November 5: publishing the door-observation client exposed existing drift
between `client/browser/index.html` and the checked-in served page: regeneration
diff --git a/docs/admin.md b/docs/admin.md
@@ -42,6 +42,10 @@ ownership, assignment and instance editing.
Same-zone map teleports and ordinary carried-item edits update connected players
without reconnecting. Profile, equipment, backpack and bank changes, or inventory
edits during an open shop/trade or equipment transition, reload the player.
+Carried-item edits also preserve a pending nano cast and its reservation until
+ordinary completion or cancellation. An equipped-item edit refunds a pending
+cast in the same transaction as the item change, before reloading the actor.
+Failed writes leave both the item and reservation unchanged.
Password changes preserve the current game session and take effect on the next login.
## Map
@@ -115,6 +119,13 @@ network packet identifiers.
## Focused checks
+The November 5 pending-cast edit check passes 13 test roots and 31 results,
+covering reservations, live inventory edits, actor reloads and open-shop edits.
+It verifies exact cost/refund settlement and unchanged state after rejected
+writes. Logs are `local/alpha-admin-cast/regressions.log` and `vet.log`;
+`go vet ./server/...` and diff checks pass. This was a regression-fixture update,
+with no server or client behavior change.
+
```sh
go test ./server -run '^(TestAdmin|TestControl|TestHTTPHandler|TestSetGameTime|TestMapPlayers|TestMapTeleport)' -count=1 -timeout=5m
node --test server/map_test.js
diff --git a/docs/trader-health-payment.md b/docs/trader-health-payment.md
@@ -70,6 +70,9 @@ roots and 2,677 results, with one unrelated failing root:
reproduce in the retained pre-change binary. That test expects item edits to
reload the actor, while the current live inventory-edit path preserves the
pending cast; the separate P1 TODO records the required regression update.
+That follow-up is now complete: carried edits verify preserved reservations and
+settlement, while equipped edits verify atomic refund/reload. Both pass, with
+rejected-write/retry and cold recovery coverage (`local/alpha-admin-cast/regressions.log`).
Logs are `local/alpha-health-payment/final-focused.log`, `regressions.log` and
`baseline-admin-reservation.log`. `go vet ./server/...`, JavaScript syntax and
diff checks pass.
diff --git a/server/nano_reservation_test.go b/server/nano_reservation_test.go
@@ -200,14 +200,23 @@ func TestNanoReservationStartupFailureRetainsRefundForRetry(t *testing.T) {
}
}
-func TestNanoReservationItemEditCommitsRefundWithActorReload(t *testing.T) {
+func TestNanoReservationEquippedItemEditCommitsRefundWithActorReload(t *testing.T) {
for _, fail := range []bool{false, true} {
t.Run(map[bool]string{false: "success", true: "failed write"}[fail], func(t *testing.T) {
world, conn := newNanoOutcomeWorld(t, 100)
world.baseURL = "/"
- if granted, err := world.grantItem_locked(world.characters[1], 85366); !granted || err != nil {
+ player := world.characters[1]
+ player.stats.Abilities.Stamina = 11
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if granted, err := world.grantItem_locked(player, 85557); !granted || err != nil {
t.Fatal(granted, err)
}
+ player.inventory.Items[0].Slot = 18
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
client := world.clients[1]
if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1000000, 53019, 29618})[20:]); err != nil {
t.Fatal(err)
@@ -217,22 +226,119 @@ func TestNanoReservationItemEditCommitsRefundWithActorReload(t *testing.T) {
t.Fatal(err)
}
}
+ if client.nanoCast == nil {
+ t.Fatal("fixture cast was not admitted")
+ }
+ deadline := client.nanoCast.readyAt.Add(time.Nanosecond)
conn.packets = nil
- response := postControlForm(world, "/admin/items/3", url.Values{"data": {"type: 51005\ntemplate: 85366\nquality: 1\ncount: 24\n"}})
- var nano, reserved, count uint32
- if err := world.db.QueryRow("SELECT characters.nano,characters.nano_reserved,items.count FROM characters JOIN items ON items.id=3 WHERE characters.id=1").Scan(&nano, &reserved, &count); err != nil {
+ edit := url.Values{"data": {"type: 51022\ntemplate: 85557\nquality: 2\ncount: 1\n"}}
+ response := postControlForm(world, "/admin/items/3", edit)
+ var nano, reserved, quality uint32
+ if err := world.db.QueryRow("SELECT characters.nano,characters.nano_reserved,items.quality FROM characters JOIN items ON items.id=3 WHERE characters.id=1").Scan(&nano, &reserved, &quality); err != nil {
t.Fatal(err)
}
if fail {
- if response.Code != http.StatusInternalServerError || nano != 21 || reserved != 9 || count != 25 || client.nanoCast == nil ||
- client.nanoCast.cancelled || len(conn.packets) != 0 || world.characters[1].inventory.Items[0].Count != 25 {
+ if response.Code != http.StatusInternalServerError || nano != 21 || reserved != 9 || quality != 1 || client.nanoCast == nil ||
+ client.nanoCast.cancelled || len(conn.packets) != 0 || player.inventory.Items[0].Quality != 1 {
t.Fatal("failed item edit changed inventory, reservation or live cast")
}
- } else if response.Code != http.StatusSeeOther || nano != 30 || reserved != 0 || count != 24 || client.nanoCast != nil ||
- world.characters[1].nano != 30 || world.characters[1].nanoReserved != 0 || world.characters[1].savedVitals.NanoReserved != 0 {
- t.Fatalf("item reload lost or repeated its refund: status=%d nano=%d reserve=%d count=%d", response.Code, nano, reserved, count)
+ if _, err := world.db.Exec("DROP TRIGGER fail_edit"); err != nil {
+ t.Fatal(err)
+ }
+ response = postControlForm(world, "/admin/items/3", edit)
+ }
+ world.advanceNanos(deadline)
+ cold := newTestInventoryServer(t).characters[1]
+ if response.Code != http.StatusSeeOther || client.nanoCast != nil || client.ready || world.clients[1] != nil ||
+ player.nano != 30 || player.nanoReserved != 0 || player.savedVitals.NanoReserved != 0 ||
+ cold.nano != 30 || cold.nanoReserved != 0 || cold.inventory.Items[0].Quality != 2 || cold.inventory.Items[0].Slot != 18 ||
+ world.characters[1000000].health != 100 {
+ t.Fatalf("equipment reload lost its refund or completed the abandoned cast: status=%d nano=%d reserve=%d quality=%d", response.Code, player.nano, player.nanoReserved, cold.inventory.Items[0].Quality)
+ }
+ if again := newTestInventoryServer(t).characters[1]; again.nano != 30 || again.nanoReserved != 0 {
+ t.Fatal("cold startup repeated the equipment-edit refund")
+ }
+ })
+ }
+}
+
+func TestNanoReservationCarriedItemEditPreservesCastUntilSettlement(t *testing.T) {
+ for _, outcome := range []string{"complete", "cancel", "failed write"} {
+ t.Run(outcome, func(t *testing.T) {
+ world, conn := newNanoOutcomeWorld(t, 100)
+ world.baseURL = "/"
+ player, client := world.characters[1], world.clients[1]
+ if granted, err := world.grantItem_locked(player, 85366); !granted || err != nil {
+ t.Fatal(granted, err)
+ }
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1000000, 53019, 29618})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ cast := client.nanoCast
+ if cast == nil {
+ t.Fatal("fixture cast was not admitted")
+ }
+ if outcome == "failed write" {
+ if _, err := world.db.Exec("CREATE TRIGGER fail_edit BEFORE UPDATE ON items WHEN NEW.id=3 BEGIN SELECT RAISE(FAIL, 'test edit'); END"); err != nil {
+ t.Fatal(err)
+ }
+ }
+ conn.packets = nil
+ edit := url.Values{"data": {"type: 51005\ntemplate: 85366\nquality: 1\ncount: 24\n"}}
+
+ response := postControlForm(world, "/admin/items/3", edit)
+
+ if outcome == "failed write" {
+ var nano, reserved, count uint32
+ if err := world.db.QueryRow("SELECT characters.nano,characters.nano_reserved,items.count FROM characters JOIN items ON items.id=3 WHERE characters.id=1").Scan(&nano, &reserved, &count); err != nil {
+ t.Fatal(err)
+ }
+ if response.Code != http.StatusInternalServerError || nano != 21 || reserved != 9 || count != 25 ||
+ player.nano != 21 || player.nanoReserved != 9 || player.inventory.Items[0].Count != 25 ||
+ client.nanoCast != cast || cast.cancelled || len(conn.packets) != 0 {
+ t.Fatal("failed carried-item edit changed or published the item or cast")
+ }
+ if _, err := world.db.Exec("DROP TRIGGER fail_edit"); err != nil {
+ t.Fatal(err)
+ }
+ response = postControlForm(world, "/admin/items/3", edit)
+ }
+ var nano, reserved, count uint32
+ if err := world.db.QueryRow("SELECT characters.nano,characters.nano_reserved,items.count FROM characters JOIN items ON items.id=3 WHERE characters.id=1").Scan(&nano, &reserved, &count); err != nil {
+ t.Fatal(err)
+ }
+ if response.Code != http.StatusSeeOther || nano != 21 || reserved != 9 || count != 24 || player.nano != 21 || player.nanoReserved != 9 ||
+ player.savedVitals.NanoReserved != 9 || player.inventory.Items[0].Count != 24 || world.clients[1] != client || !client.ready || client.nanoCast != cast || cast.cancelled {
+ t.Fatal("live edit changed the pending cast, session or reservation")
+ }
+ for _, packet := range conn.packets {
+ if opcode := binary.BigEndian.Uint32(packet[16:20]); opcode == 0x43197d22 || opcode == 0x3c {
+ t.Fatal("carried-item edit sent an actor reload")
+ }
+ }
+
+ // Completing or cancelling the retained cast settles its original reservation once.
+ if outcome == "cancel" {
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{108})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ }
+ at := cast.readyAt.Add(time.Nanosecond)
+ world.advanceNanos(at)
+ health := world.characters[1000000].health
+ world.advanceNanos(at.Add(time.Second))
+ cold := newTestInventoryServer(t).characters[1]
+ if client.nanoCast != nil || player.nanoReserved != 0 || cold.nanoReserved != 0 || cold.inventory.Items[0].Count != 24 || world.characters[1000000].health != health {
+ t.Fatal("live edit lost settlement, inventory or duplicated the effect")
+ }
+ if outcome == "cancel" {
+ if player.nano != 30 || cold.nano != 30 || health != 100 {
+ t.Fatal("cancelled cast did not refund once without damage")
+ }
+ } else if player.nano != 21 || cold.nano != 21 || health < 77 || health > 90 {
+ t.Fatal("completed cast lost its cost or damage", player.nano, cold.nano, health)
}
})
}