[P1] Eliminate hand-maintained aggregate field lists + add a reflection-exhaustive drift test #251

Closed
opened 2026-07-03 02:30:50 -07:00 by nelsong6 · 3 comments
nelsong6 commented 2026-07-03 02:30:50 -07:00 (Migrated from github.com)

Priority: P1. From the 2026-07-02 audit. This is the exact shape of the already-fixed doubled-Activations bug (commit f859cda / the relic merge consolidation) — fixed once as an instance, but the class keeps recurring.

Problem

Aggregate stats are merged/cloned/pooled through several hand-maintained parallel field lists that silently drift:

  • GetRelicAggregate's ~26-field clone block duplicates MergeRelicAggregateInto (whose own comment says "add fields HERE, once").
  • CloneEnemyAggregate duplicates MergeEnemyAggregateInto.
  • CardAggregatePooler.MergeInto omits CombatsInDeck vs RunTracker.MergeAggregateInto.
  • The three dictionary-merge helpers are byte-duplicated across two files.
  • CloneAggregate / MergeAggregateInto / pooler are four parallel lists; MergeAggregateInto silently omits several lineage fields, and CloneAggregate copies RemovedSnapshot by reference.

Consequence: a stat that lives only in an omitted field is dropped on merge/clone/pool; a field added twice is double-counted. For a stats tool these are "wrong numbers that look plausible and evade the current tests" — the most dangerous kind.

Note: findings in this theme were surfaced by the audit's finders but several were not re-verified due to a verification-cap; confirm each field-coverage gap against the current class definitions in Core/RunData.cs before acting. The test below makes that verification permanent.

Fix

  1. Replace every clone with new X(); MergeXInto(result, source); (derive clone from the one merge function).
  2. Make CardAggregatePooler delegate to the canonical merge.
  3. Consolidate the duplicated dictionary-merge helpers into one internal home.

Guardrail (the real fix)

A reflection-exhaustive test over every settable property of CardAggregate / RelicAggregate / EnemyAggregate / AppliedEffectAggregate: populate each property with a distinct value and assert JSON(clone) == JSON(source), merge-into-empty == source, and additivity (merge(a,b) sums numerics). Any newly-added-but-unmerged field then fails the day it is added — covering all future fields for free.

**Priority: P1.** From the 2026-07-02 audit. This is the exact shape of the already-fixed doubled-`Activations` bug (commit f859cda / the relic merge consolidation) — fixed once as an instance, but the *class* keeps recurring. ## Problem Aggregate stats are merged/cloned/pooled through several **hand-maintained parallel field lists** that silently drift: - `GetRelicAggregate`'s ~26-field clone block duplicates `MergeRelicAggregateInto` (whose own comment says "add fields HERE, once"). - `CloneEnemyAggregate` duplicates `MergeEnemyAggregateInto`. - `CardAggregatePooler.MergeInto` omits `CombatsInDeck` vs `RunTracker.MergeAggregateInto`. - The three dictionary-merge helpers are byte-duplicated across two files. - `CloneAggregate` / `MergeAggregateInto` / pooler are four parallel lists; `MergeAggregateInto` silently omits several lineage fields, and `CloneAggregate` copies `RemovedSnapshot` by reference. Consequence: a stat that lives only in an omitted field is dropped on merge/clone/pool; a field added twice is double-counted. For a stats tool these are "wrong numbers that look plausible and evade the current tests" — the most dangerous kind. > Note: findings in this theme were surfaced by the audit's finders but several were not re-verified due to a verification-cap; confirm each field-coverage gap against the current class definitions in `Core/RunData.cs` before acting. The *test* below makes that verification permanent. ## Fix 1. Replace every clone with `new X(); MergeXInto(result, source);` (derive clone from the one merge function). 2. Make `CardAggregatePooler` delegate to the canonical merge. 3. Consolidate the duplicated dictionary-merge helpers into one internal home. ## Guardrail (the real fix) A **reflection-exhaustive** test over every settable property of `CardAggregate` / `RelicAggregate` / `EnemyAggregate` / `AppliedEffectAggregate`: populate each property with a distinct value and assert `JSON(clone) == JSON(source)`, `merge-into-empty == source`, and additivity (`merge(a,b)` sums numerics). Any newly-added-but-unmerged field then fails the day it is added — covering all future fields for free.
nelsong6 commented 2026-07-03 09:34:22 -07:00 (Migrated from github.com)

Uncapped audit pass — the RELIC/ENEMY inline clones are still live (verified), fold into this issue:

  • GetRelicAggregate (RunTracker.cs:3136-3163) hand-copies 26 RelicAggregate fields parallel to MergeRelicAggregateInto whose own comment says 'add fields HERE, once' (#0, #144).
  • CloneEnemyAggregate (~3258) duplicates MergeEnemyAggregateInto (#23).
  • CardAggregatePooler.MergeInto omits CombatsInDeck and duplicates 3 dict-merge helpers verbatim (#1, #2, #42, #77, #105).
  • The reflection-exhaustive drift test should cover all four aggregate types (Card/Relic/Enemy/AppliedEffect) and fail on both omission AND double-add. Also: 7 relic test classes have tautological POCO-arithmetic 'Accumulates' tests that execute zero production code (#113) — delete, rely on PendingCombatPromotionTests.
**Uncapped audit pass — the RELIC/ENEMY inline clones are still live (verified), fold into this issue:** - `GetRelicAggregate` (`RunTracker.cs:3136-3163`) hand-copies 26 RelicAggregate fields parallel to `MergeRelicAggregateInto` whose own comment says 'add fields HERE, once' (#0, #144). - `CloneEnemyAggregate` (~3258) duplicates `MergeEnemyAggregateInto` (#23). - `CardAggregatePooler.MergeInto` omits `CombatsInDeck` and duplicates 3 dict-merge helpers verbatim (#1, #2, #42, #77, #105). - The reflection-exhaustive drift test should cover **all four** aggregate types (Card/Relic/Enemy/AppliedEffect) and fail on both omission AND double-add. Also: 7 relic test classes have tautological POCO-arithmetic 'Accumulates' tests that execute zero production code (#113) — delete, rely on `PendingCombatPromotionTests`.
nelsong6 commented 2026-07-03 10:03:06 -07:00 (Migrated from github.com)

Addressed in #264: the three parallel aggregate clone lists were collapsed onto the canonical Merge*Into functions (CloneAggregate keeps only lineage fields; CloneEnemyAggregate and the 26-field inline RelicAggregate clone became new+Merge), and AggregateDriftTests reflection-exhaustively asserts Clone(src)==src and Merge(new,src)==src — catching omission AND double-add. CardAggregatePooler.MergeInto delegation (#1) and the tautological POCO tests (#113) remain.

Addressed in #264: the three parallel aggregate clone lists were collapsed onto the canonical Merge*Into functions (CloneAggregate keeps only lineage fields; CloneEnemyAggregate and the 26-field inline RelicAggregate clone became new+Merge), and AggregateDriftTests reflection-exhaustively asserts Clone(src)==src and Merge(new,src)==src — catching omission AND double-add. CardAggregatePooler.MergeInto delegation (#1) and the tautological POCO tests (#113) remain.
nelsong6 commented 2026-07-05 15:45:13 -07:00 (Migrated from github.com)

Closing during repository issue cleanup. If this becomes active work again, we can reopen or recreate it as a fresh, specific task.

Closing during repository issue cleanup. If this becomes active work again, we can reopen or recreate it as a fresh, specific task.
Sign in to join this conversation.
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#251
No description provided.