Audit fixes batch 3: aggregate drift guardrail + RemovedSnapshot data-loss #264

Closed
nelsong6 wants to merge 5 commits from claude/audit-fixes-batch3 into main
nelsong6 commented 2026-07-03 09:51:55 -07:00 (Migrated from github.com)

Third batch from the codebase audit. Stacks on #248. Both changes are fully verified headless (244/244 tests pass against the live game DLL).

RemovedSnapshot data-loss (#259, finding #94, confirmed)

RunStorage.Options was missing IncludeFields = true. The game's SerializableCard (persisted as a removed-card snapshot) stores its data in public fields, so a removed card's props/enchantment serialized as {} and rehydrated empty — silent data loss in the removed-card overlay. Options is now internal so tests (and the future public-API layer) consume the one canonical config instead of hand-copied duplicates.

Aggregate drift guardrail (#251, findings #0/#23/#144)

The recurring bug class in this codebase — the doubled relic Activations bug and its family — comes from hand-maintained parallel field lists. This kills the class mechanically:

  • Collapse the clones onto the merges. CloneAggregate keeps only the 5 lineage fields and delegates the rest to MergeAggregateInto; CloneEnemyAggregate and the 26-field inline RelicAggregate clone in GetRelicAggregate become new + Merge. One field list per aggregate type now lives in the Merge*Into functions.
  • AggregateDriftTests — a reflection-exhaustive guard that populates every scalar field of CardAggregate/RelicAggregate/EnemyAggregate with a distinct value and asserts Clone(src) == src and Merge(new, src) == src. Merge-into-empty catches both omission (field stays default) and double-add (field doubles — the exact Activations shape). Any stat field added but not merged fails the day it's added.

The inner reason/status dictionaries are excluded from the drift comparison (their merges legitimately re-key by an inner id field, and they have dedicated bucket tests); the scalar fields are where the drift class lives.

Not in this batch (deferred, with reason)

  • #258 CI test gate — highest-leverage, but the first Linux CI run must be observed to see which asset-coupled tooltip tests fail on the runner (11 fail against the checked-in stub on Windows; the Linux set may differ). Wants the CI feedback loop, so it's a focused follow-up.
  • #260 multiplayer kill-switch — decision made (gate tracking when Players.Count > 1), but it's a broad behavior change I can't verify without a co-op game; deferred to its own PR.

🤖 Generated with Claude Code

Third batch from the codebase audit. Stacks on #248. Both changes are fully verified headless (244/244 tests pass against the live game DLL). ## RemovedSnapshot data-loss ([#259](https://github.com/romaine-life/spirelens/issues/259), finding #94, confirmed) `RunStorage.Options` was missing `IncludeFields = true`. The game's `SerializableCard` (persisted as a removed-card snapshot) stores its data in public **fields**, so a removed card's props/enchantment serialized as `{}` and rehydrated empty — silent data loss in the removed-card overlay. `Options` is now `internal` so tests (and the future public-API layer) consume the one canonical config instead of hand-copied duplicates. ## Aggregate drift guardrail ([#251](https://github.com/romaine-life/spirelens/issues/251), findings #0/#23/#144) The recurring bug class in this codebase — the doubled relic `Activations` bug and its family — comes from hand-maintained parallel field lists. This kills the class mechanically: - **Collapse the clones onto the merges.** `CloneAggregate` keeps only the 5 lineage fields and delegates the rest to `MergeAggregateInto`; `CloneEnemyAggregate` and the 26-field inline `RelicAggregate` clone in `GetRelicAggregate` become `new + Merge`. One field list per aggregate type now lives in the `Merge*Into` functions. - **`AggregateDriftTests`** — a reflection-exhaustive guard that populates every scalar field of `CardAggregate`/`RelicAggregate`/`EnemyAggregate` with a distinct value and asserts `Clone(src) == src` and `Merge(new, src) == src`. Merge-into-empty catches **both** omission (field stays default) **and** double-add (field doubles — the exact `Activations` shape). Any stat field added but not merged fails the day it's added. The inner reason/status dictionaries are excluded from the drift comparison (their merges legitimately re-key by an inner id field, and they have dedicated bucket tests); the scalar fields are where the drift class lives. ## Not in this batch (deferred, with reason) - **[#258](https://github.com/romaine-life/spirelens/issues/258) CI test gate** — highest-leverage, but the first Linux CI run must be observed to see which asset-coupled tooltip tests fail on the runner (11 fail against the checked-in stub on Windows; the Linux set may differ). Wants the CI feedback loop, so it's a focused follow-up. - **[#260](https://github.com/romaine-life/spirelens/issues/260) multiplayer kill-switch** — decision made (gate tracking when `Players.Count > 1`), but it's a broad behavior change I can't verify without a co-op game; deferred to its own PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nelsong6 commented 2026-07-03 10:33:39 -07:00 (Migrated from github.com)

Superseded by #267, which consolidates this and the rest of the audit work onto current main (these branches all conflicted after #247 landed). Closing in favor of the single mergeable PR.

Superseded by #267, which consolidates this and the rest of the audit work onto current main (these branches all conflicted after #247 landed). Closing in favor of the single mergeable PR.

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
romaine-life/spirelens!264
No description provided.