diff options
| author | historia <[not public]> | 2026-09-18 05:31:09 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-18 05:31:09 -0400 |
| commit | 153acb7f644d755c45533b7c5311e3ffa47e8973 (patch) | |
| tree | 7645e6f7b65bc3830b078e3b9336d2e6b199d584 /internal/game/polish_shop_merge_test.go | |
| parent | 87d08f0151e643951769e323995f1c5ed89ee200 (diff) | |
| download | thehouseoficarus-153acb7f644d755c45533b7c5311e3ffa47e8973.tar.gz | |
fix: harden engine across casino, economy, concurrency, security, and content
Diffstat (limited to 'internal/game/polish_shop_merge_test.go')
| -rw-r--r-- | internal/game/polish_shop_merge_test.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/game/polish_shop_merge_test.go b/internal/game/polish_shop_merge_test.go new file mode 100644 index 0000000..8851464 --- /dev/null +++ b/internal/game/polish_shop_merge_test.go @@ -0,0 +1,55 @@ +package game + +// Regression: giveShopItems used to merge a purchase into any inventory slot +// holding the same item id, ignoring Quality/MaxQuality, while every other +// merge site (craft, harvest, ammo return, pickup) merges only into a stack +// with the properties a fresh stack gets (stackProps). A purchase could +// therefore merge into a differently qualified stack. shopInvCapacity had the +// same blind spot, which mattered because the buy path charges for the +// quantity capacity reports as placeable. + +import ( + "path/filepath" + "testing" + + "thehouseoficarus/internal/player" +) + +func TestGiveShopItemsDoesNotMergeIntoDifferentQualityStack(t *testing.T) { + h := newHarness(t) + h.seedAccount("alice") + p := h.seedCharacter("alice", "alice") + writeSeedFile(t, filepath.Join(h.dir, "items", "polish_shop_gem.yaml"), + []byte("id: polish_shop_gem\nname: polish shop gem\nstackable: true\nmax_quality: 5\nvalue: 1\n")) + + h.g.RunOnOwner(func() { + h.g.ItemStore.Reload(h.dir) + def := mustLoadItem(t, h.g, "polish_shop_gem") + + // A differently qualified stack is not a merge target: with no free + // slot, capacity must report 0 and the purchase must not be placed. + p.SetInvSlot(0, &player.InventorySlot{ItemID: def.ID, Quantity: 10, Quality: 1, MaxQuality: 5}) + fillInventoryExcept(p) + if got := h.g.shopInvCapacity(p, def.ID, def); got != 0 { + t.Fatalf("shopInvCapacity = %d, want 0 (the only stack has a different quality)", got) + } + h.g.giveShopItems(p, def.ID, 3, def) + if slot := p.InvSlot(0); slot.Quantity != 10 || slot.Quality != 1 || slot.MaxQuality != 5 { + t.Errorf("purchase merged into a differently qualified stack: %+v", slot) + } + if got := p.CountItem(def.ID); got != 10 { + t.Errorf("gems carried = %d, want 10 (nothing should have been delivered)", got) + } + + // The same full inventory accepts the purchase once the stack carries + // the properties a fresh stack gets. + p.SetInvSlot(0, &player.InventorySlot{ItemID: def.ID, Quantity: 10, Quality: 5, MaxQuality: 5}) + if got := h.g.shopInvCapacity(p, def.ID, def); got == 0 { + t.Fatalf("shopInvCapacity = %d, want room for a matching stack", got) + } + h.g.giveShopItems(p, def.ID, 3, def) + if slot := p.InvSlot(0); slot.Quantity != 13 || slot.Quality != 5 || slot.MaxQuality != 5 { + t.Errorf("matched stack = %+v, want quantity 13 at quality 5", slot) + } + }) +} |
