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
93 lines
3.4 KiB
GDScript
93 lines
3.4 KiB
GDScript
extends "res://addons/gut/test.gd"
|
|
|
|
const NpcContent = preload("res://scripts/npc/npc_content.gd")
|
|
|
|
func _fenn() -> Dictionary:
|
|
return {"id": "fenn", "capabilities": {
|
|
"offerable_quests": ["find_the_ledger"],
|
|
"giveable_items": [],
|
|
"revealable_topics": ["varrell_twins", "fenns_debt"]}}
|
|
|
|
|
|
func test_universal_moves_always_present():
|
|
var moves = NpcContent.available_moves(_fenn(), GameState.new(), CanonLog.new())
|
|
for m in ["adjust_disposition", "refuse", "end_conversation", "become_hostile"]:
|
|
assert_true(m in moves, "missing universal move %s" % m)
|
|
|
|
|
|
func test_offers_unstarted_quest_and_unrevealed_topics():
|
|
var moves = NpcContent.available_moves(_fenn(), GameState.new(), CanonLog.new())
|
|
assert_true("offer_quest(find_the_ledger)" in moves)
|
|
assert_true("reveal(varrell_twins)" in moves)
|
|
assert_true("reveal(fenns_debt)" in moves)
|
|
|
|
|
|
func test_active_quest_is_not_offered_again():
|
|
var log = CanonLog.new()
|
|
log.add_quest("find_the_ledger", "x", "y")
|
|
var moves = NpcContent.available_moves(_fenn(), GameState.new(), log)
|
|
assert_false("offer_quest(find_the_ledger)" in moves)
|
|
|
|
|
|
func test_revealed_topic_drops_out():
|
|
var gs = GameState.new()
|
|
gs.mark_revealed("varrell_twins")
|
|
var moves = NpcContent.available_moves(_fenn(), gs, CanonLog.new())
|
|
assert_false("reveal(varrell_twins)" in moves)
|
|
assert_true("reveal(fenns_debt)" in moves)
|
|
|
|
|
|
func test_accept_item_offered_per_held_item():
|
|
var gs = GameState.new()
|
|
gs.add_item("worn_shortsword", 2)
|
|
var moves = NpcContent.available_moves(_fenn(), gs, CanonLog.new())
|
|
assert_true("accept_item(worn_shortsword)" in moves)
|
|
|
|
|
|
func test_a_broke_party_is_asked_for_nothing():
|
|
var moves = NpcContent.available_moves(_fenn(), GameState.new(), CanonLog.new())
|
|
for denom in ["copper", "silver", "gold"]:
|
|
assert_false("accept_item(%s)" % denom in moves, "an empty purse cannot pay a %s" % denom)
|
|
|
|
|
|
func test_accept_item_denomination_gated_on_affordability():
|
|
var gs = GameState.new()
|
|
gs.grant("copper", 347)
|
|
var moves = NpcContent.available_moves(_fenn(), gs, CanonLog.new())
|
|
assert_true("accept_item(copper)" in moves)
|
|
assert_true("accept_item(silver)" in moves)
|
|
assert_false("accept_item(gold)" in moves, "347c cannot pay a gold coin")
|
|
|
|
|
|
func test_a_gold_coin_is_asked_for_once_affordable():
|
|
var gs = GameState.new()
|
|
gs.grant("gold", 1)
|
|
var moves = NpcContent.available_moves(_fenn(), gs, CanonLog.new())
|
|
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"]
|
|
var gs = GameState.new()
|
|
gs.mark_gift_given("copper")
|
|
gs.mark_gift_given("amulet")
|
|
var moves = NpcContent.available_moves(npc, gs, CanonLog.new())
|
|
assert_true("give_item(copper)" in moves, "money is not a one-shot gift")
|
|
assert_false("give_item(amulet)" in moves, "a real item still is")
|