fix(currency): cap repeated currency move tags at one per reply

TagExtractor collects every [MOVE:] tag occurrence with no dedupe, and
MoveValidator is a pure membership test against available_moves, so N
copies of one legal move all pass validation. MoveApplier then looped
and applied every copy. A model could therefore pick an arbitrary
amount of money in unary by repeating one tag: [MOVE: accept_item(copper)]
x47 against a 47c purse drains it to 0; [MOVE: give_item(gold)] x10
mints +100,000c. The eight-move vocabulary (§6) takes no quantity
argument precisely so the AI cannot choose a number — this closed that
gap by another door and was a §2 breach (AI owns text, never state).

MoveApplier.apply() now tracks currency moves (give_item/accept_item on
a denomination) already applied within one call, keyed on name+denom,
and skips repeats. Non-currency moves are untouched — repeated
give_item(amulet) still yields multiple copies, which stays bounded by
the pre-existing cross-reply gifts_given gate and is a separate,
already-reported issue. move_validator.gd and tag_extractor.gd are
untouched.

Also adds the Finding-2 test the currency spec (§7) named but never
delivered: after GameState.grant("gold", 1), inventory stays empty, so
accept_item(gold) in available_moves comes only from the affordability
loop, never double-offered via the inventory.keys() loop.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QYa9u7Kdxv5gX4AnwWexy8
This commit is contained in:
2026-07-12 18:47:19 -05:00
parent 6c496d3ed8
commit 8e1238c316
3 changed files with 83 additions and 0 deletions

View File

@@ -66,6 +66,21 @@ func test_a_gold_coin_is_asked_for_once_affordable():
assert_true("accept_item(gold)" in moves)
func test_currency_never_arrives_via_the_inventory_loop():
# §7 of the currency spec: currency never enters the inventory dict, so the
# only accept_item(<denom>) in available_moves comes from the affordability
# loop — never a double-offer via the inventory.keys() loop.
var gs = GameState.new()
gs.grant("gold", 1)
assert_true(gs.inventory.is_empty(), "currency must never be written into inventory")
var moves = NpcContent.available_moves(_fenn(), gs, CanonLog.new())
var gold_offers := 0
for m in moves:
if m == "accept_item(gold)":
gold_offers += 1
assert_eq(gold_offers, 1, "accept_item(gold) must be offered exactly once")
func test_currency_gift_is_offered_repeatedly():
var npc := _fenn()
npc["capabilities"]["giveable_items"] = ["copper", "amulet"]