Skip to content

test(inventory): pin equip-slot/exclusivity/stack/drop invariants in Inventories.bb (22 tests)#571

Merged
CoreyRDean merged 1 commit into
developfrom
test/inventory-equip-rules
Jun 10, 2026
Merged

test(inventory): pin equip-slot/exclusivity/stack/drop invariants in Inventories.bb (22 tests)#571
CoreyRDean merged 1 commit into
developfrom
test/inventory-equip-rules

Conversation

@CoreyRDean

Copy link
Copy Markdown
Collaborator

What

Adds src/Tests/Modules/InventoryEquipRulesTest.bb (733 lines, 22 test blocks / ~170 asserts) — the first gameplay-correctness coverage for Inventories.bb. The test Includes the real Items.bb + Inventories.bb (ItemsTest stub pattern), so assertions exercise production code, not a replica.

Pinned invariants: ActorHasSlot flag/race/class gating, SlotsMatch slot routing (weapon/armour/ring/amulet/backpack/potion), InventorySwap equip/unequip round-trip + displacement + stack-into-equip rejection + split/relocate + dupe guards, InventoryAdd merge/drain + 16-bit non-lossy ceiling, InventoryDrop partial/final/overdraw, GetArmourLevel (broken armour = 0, Shield..Feet range only), InventoryMass, InventoryHasItem.

⚠ Two engine-bug findings (PINNED, not fixed — these tests assert current behavior so a fix PR can flip the assertions deliberately)

  1. Exclusivity bypass on equip indices 11–13 — real bug (runtime-confirmed, independently verified). Inventories.bb:229 gates the race/class exclusivity fork on SlotI < Slot_Backpack — but Slot_Backpack (= 11) is the 1-based slot name constant while SlotI is a slot index (equip indices run 0..13; SlotI_Backpack = 14). Net effect: Ring4, Amulet1, Amulet2 skip race/class exclusivity entirely — a wrong-race ring equips fine in Ring4. The comment above ("If it's an equipped slot") shows intent was all 14 equip indices. Fix would be SlotI < SlotI_Backpack + updating the pinned assertions.

  2. Race-match short-circuits the class check — likely bug, owner call. A matching ExclusiveRace$ returns True before ExclusiveClass$ is checked, so an "Elf Mage only" item equips on an Elf Warrior. Skipping the disabled-slot flag on race match is documented as intentional (:231), but nothing sanctions skipping the class check — and the comment at :240 is a copy-pasted race comment over the class block. OR-vs-AND exclusivity semantics needs a maintainer decision before fixing.

Verification (independent verifier ≠ implementer)

  • Scope: git diff --stat develop...HEAD = the one new test file only; no engine modules, none of the CI-generator-gated files.
  • .\test.bat InventoryEquipRules[PASS]; full suite → Ran 55 files: 55 passed, 0 failed.; compile.bat -t exit 0.
  • ~10 assertion clusters traced to source by the verifier; stubs confirmed compile-only (every call uses TellServer=False).

🤖 Generated with Claude Code

Adds InventoryEquipRulesTest.bb -- first direct test coverage for the
equip-slot fork logic in Inventories.bb (ActorHasSlot's race/class
exclusivity checks and per-slot disabled-flag gating, SlotsMatch's
item-type -> slot-index mapping) plus the InventorySwap / InventoryAdd /
InventoryDrop callers and the equipped-range readers (GetArmourLevel,
InventoryMass, InventoryHasItem).

The module is included for real (Items.bb supplies ItemInstance, same
stub pattern as ItemsTest.bb), so these pins exercise the production
code, not a replica.

Pinned current behavior, flagged for human review (not 'fixed' -- these
are regression pins):
- ActorHasSlot's exclusivity fork gates on SlotI < Slot_Backpack (the
  1-based slot NAME constant, 11) instead of SlotI_Backpack (the slot
  INDEX, 14), so indices 11-13 (Ring4, Amulet1, Amulet2) skip the
  ExclusiveRace$/ExclusiveClass$ checks entirely: a wrong-race ring is
  denied in Ring1-3 but allowed in Ring4.
- A matching ExclusiveRace$ returns True immediately, skipping both the
  ExclusiveClass$ check and the disabled-slot flag check.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CoreyRDean CoreyRDean requested a review from a team as a code owner June 10, 2026 23:13
@CoreyRDean CoreyRDean merged commit 3942567 into develop Jun 10, 2026
1 check passed
@CoreyRDean CoreyRDean deleted the test/inventory-equip-rules branch June 10, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant