fix(creation): pin RNG stream, tighten spend/seed validation
Finding 1 (important): test_same_seed_yields_an_identical_character only compared two construct() runs against each other, so swapping dex/con in Attributes.IDS still passed the whole suite while every persisted seed would silently become a different character. Added a golden-vector test that pins one fixed seed to its exact rolled attributes and hidden Luck, so reordering Attributes.IDS or moving the Luck roll fails loudly instead of silently rewriting every saved character. Proved it: swapped IDS, watched the golden vector fail, restored, confirmed green. Also: _validate_spend no longer lets a negative value mask the over-pool check (continue after each error instead of falling through to `total += v`); non-integer spend values (float/bool/string) are now rejected instead of coerced; a missing or non-integer seed is now a validation error instead of silently defaulting to 0. GameState's header comment no longer advertises "stats" it no longer holds. 243 -> 248 tests. 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:
@@ -111,6 +111,9 @@ static func _validate(origin: Dictionary, world: ContentDB, creation: Dictionary
|
||||
if str(creation.get("name", "")).strip_edges() == "":
|
||||
errors.append("player name is required")
|
||||
|
||||
if not creation.has("seed") or typeof(creation["seed"]) != TYPE_INT:
|
||||
errors.append("seed is required and must be an integer")
|
||||
|
||||
var race_id: String = str(creation.get("race_id", ""))
|
||||
if not Races.exists(race_id):
|
||||
errors.append("unknown race: %s" % race_id)
|
||||
@@ -138,9 +141,13 @@ static func _validate_spend(spend: Dictionary) -> Array:
|
||||
if not Attributes.exists(str(stat)):
|
||||
errors.append("cannot spend on '%s' — not an attribute" % stat)
|
||||
continue
|
||||
if typeof(spend[stat]) != TYPE_INT:
|
||||
errors.append("spend value for '%s' must be an integer" % stat)
|
||||
continue
|
||||
var v := int(spend[stat])
|
||||
if v < 0:
|
||||
errors.append("spend is additive only: %s is negative" % stat)
|
||||
continue
|
||||
total += v
|
||||
if total > SPEND_POOL:
|
||||
errors.append("spend exceeds the pool of %d (got %d)" % [SPEND_POOL, total])
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
class_name GameState
|
||||
extends RefCounted
|
||||
## Luck-centric game state (spec decision 5). The SOLE home of numeric Luck,
|
||||
## stats, world-NPC dispositions, and inventory — none of which enter the canon
|
||||
## log (charter §7/§2). The log reads only luck_descriptor() from here.
|
||||
## the character sheet, world-NPC dispositions, and inventory — none of which
|
||||
## enter the canon log (charter §7/§2). The log reads only luck_descriptor()
|
||||
## from here.
|
||||
|
||||
var luck: int = 0
|
||||
var luck_base: int = 0
|
||||
|
||||
Reference in New Issue
Block a user