diff options
| author | historia <[not public]> | 2026-09-16 13:52:58 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-16 13:52:58 -0400 |
| commit | c054b27f628f23fecc505b9e09e78721738f3c4e (patch) | |
| tree | ea197165bc454ee811dd22b9ceef5dc94bb0b279 /internal/game/inventory_pickup_test.go | |
| parent | f2d44f10f52d3fe68fdb19b518a330f7af9e1ed2 (diff) | |
| download | thehouseoficarus-c054b27f628f23fecc505b9e09e78721738f3c4e.tar.gz | |
fix: shutdown admission, recovery identity/order, rollback journal retention, pickup merge
Diffstat (limited to 'internal/game/inventory_pickup_test.go')
| -rw-r--r-- | internal/game/inventory_pickup_test.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/game/inventory_pickup_test.go b/internal/game/inventory_pickup_test.go new file mode 100644 index 0000000..a0d267e --- /dev/null +++ b/internal/game/inventory_pickup_test.go @@ -0,0 +1,55 @@ +package game + +// Regression: picking up a stackable item must merge into an existing stack +// even when every inventory slot is occupied — capacity is required only +// when a NEW slot is needed, matching the get-all paths. + +import ( + "path/filepath" + "testing" + + "thehouseoficarus/internal/net" + "thehouseoficarus/internal/player" +) + +func TestPickupMergesIntoFullInventory(t *testing.T) { + h := newHarness(t) + h.seedAccount("alice", "pw", false) + p := h.seedCharacter("alice", "alice") + writeSeedFile(t, filepath.Join(h.dir, "items", "chips.yaml"), []byte("id: chips\nname: chips\nstackable: true\n")) + sess := &net.Session{Conn: newChanConn(), Player: p, State: net.StateGame} + h.g.RunOnOwner(func() { + h.g.ItemStore.Reload(h.dir) + for i := 0; i < 28; i++ { + p.SetInvSlot(i, &player.InventorySlot{ItemID: "filler", Quantity: 1}) + } + p.SetInvSlot(0, &player.InventorySlot{ItemID: "chips", Quantity: 10}) + h.g.World.AddGroundItem(1, "chips", 5) + h.g.doGet(sess, "chips") + if got := countChips(p); got != 15 { + t.Errorf("pickup rejected despite existing chip stack: have %d, want 15", got) + } + }) +} + +func TestPickupFullInventoryWithoutStackStillRefused(t *testing.T) { + h := newHarness(t) + h.seedAccount("alice", "pw", false) + p := h.seedCharacter("alice", "alice") + writeSeedFile(t, filepath.Join(h.dir, "items", "chips.yaml"), []byte("id: chips\nname: chips\nstackable: true\n")) + sess := &net.Session{Conn: newChanConn(), Player: p, State: net.StateGame} + h.g.RunOnOwner(func() { + h.g.ItemStore.Reload(h.dir) + for i := 0; i < 28; i++ { + p.SetInvSlot(i, &player.InventorySlot{ItemID: "filler", Quantity: 1}) + } + h.g.World.AddGroundItem(1, "chips", 5) + h.g.doGet(sess, "chips") + if got := countChips(p); got != 0 { + t.Errorf("pickup without an existing stack must be refused, have %d", got) + } + if got := h.g.World.GroundItems(1)["chips"]; got != 5 { + t.Errorf("refused pickup must leave the ground stack intact, have %d", got) + } + }) +} |
