Skip to content

test(d3): port upstream d3 tests to raise CI coverage - #33

Merged
Chris Anderson (codemonkeychris) merged 1 commit into
mainfrom
test/d3-port-coverage
Apr 19, 2026
Merged

Chris Anderson (codemonkeychris) merged 1 commit into
mainfrom
test/d3-port-coverage

Conversation

@codemonkeychris

Copy link
Copy Markdown
Collaborator

Summary

  • Ports 389 xUnit tests from the upstream d3 submodule test suites into tests/Reactor.Tests/D3/, covering the full public surface of Microsoft.UI.Reactor.Charting.D3.
  • Lifts Reactor package line coverage 43.22% → 52.09% (+8.87pp, +3,367 covered lines) and branch coverage 39.20% → 46.22% — all in CI, no selftest needed.
  • Adds an inert ChildReconcilerReconcileTests.cs placeholder (wrapped in #if CHILD_RECONCILER_RECONCILE_TESTS) documenting why ChildReconciler.Reconcile coverage has to stay in selftest: the custom-register-type approach fails because new Border() throws COMException without a XAML Application host.

Modules covered: d3-array, d3-format, d3-ease, d3-random, d3-path, d3-polygon, d3-shape (Arc/Area/Curve/Line/Pie/Radial/Stack/Symbol/Link), d3-scale, d3-interpolate (number/round/color), d3-hierarchy (Stratify/Cluster/Partition/Treemap/Pack), d3-chord, d3-contour, d3-delaunay/voronoi, d3-color.

Not ported (reactor1 doesn't implement): d3-array set ops / fsum / rank / mode / transpose / shuffle / sort; d3-scale diverging/identity/sequential/symlog/sqrt/radial/time; d3-interpolate string/object/hcl/lab/cubehelix/zoom. ArcGenerator's corner-radius path is also currently throw NotImplementedException in src.

Test plan

  • dotnet test tests/Reactor.Tests/Reactor.Tests.csproj — 4048 passing, 46 skipped (pre-existing), 0 failing
  • dotnet test ... --collect:"XPlat Code Coverage" — Reactor package line-rate 0.5209, branch-rate 0.4622
  • CI green on Windows runner

🤖 Generated with Claude Code

Adds 389 xUnit tests under tests/Reactor.Tests/D3/ ported from the
upstream d3-* submodule test suites. Coverage for the Reactor package
climbs from 43.22% → 52.09% line (+8.87pp) and 39.20% → 46.22% branch.

Modules covered: d3-array (Statistics, Range, Ticks, Group/Bin, Extent,
Bisect, TickIncrement), d3-format (Format + type specifiers + precision
+ prefix), d3-ease, d3-random (incl. Cauchy, Weibull, IrwinHall),
d3-path (PathBuilder), d3-polygon, d3-shape (Arc, Area, Curve, Line,
Pie, Radial, Stack, Symbol/Link), d3-scale (Linear + Ordinal/Band/
Point/Log/Pow/Quantize/Quantile/Threshold), d3-interpolate (number,
round, color), d3-hierarchy (Stratify, Cluster, Partition, Treemap,
Pack), d3-chord, d3-contour, d3-delaunay/voronoi, d3-color.

Also adds an inert placeholder, tests/Reactor.Tests/ChildReconcilerReconcileTests.cs
(wrapped in #if CHILD_RECONCILER_RECONCILE_TESTS), documenting why the
Reconcile surface of ChildReconciler cannot be covered in CI: the
custom-register approach fails because `new Border()` throws
COMException without a full XAML Application host — Reconcile coverage
has to stay in selftest.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codemonkeychris
Chris Anderson (codemonkeychris) merged commit ccea2cf into main Apr 19, 2026
3 checks passed
Chris Anderson (codemonkeychris) added a commit that referenced this pull request May 1, 2026
* docs(spec): plan response to WinUI/XAML reviewer feedback (#33)

Adds docs/specs/033 covering the actionable items from the external
WinUI/XAML expert review: GridSize for typed grid tracks, scoped
PersistedStateCache, typed ElementRef<T>, four-way component-flavor
guidance with Func soft-deprecated, Expr(...) for inline blocks,
SystemBackdrop modifiers, and an interop-first sample.

Memo/reflection feedback (#7) is documented as already resolved —
audit shows IPropsComparable dispatch in Reconciler.cs and the
reviewer was reading the test-only mirror. Adds explanatory comments
to MemoizationSelfHostTests and MemoizationPropagationTests so future
reviewers don't mistake the harness for product behavior.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(spec): fix ICommand casing in interop-first sample (§7)

Copilot review on PR #100 flagged inconsistent acronym casing:
- FromIcommand → FromICommand (matches .NET convention and the ICommand
  type it wraps)
- IcommandBridge.cs → ICommandBridge.cs

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codemonkeychris
Chris Anderson (codemonkeychris) deleted the test/d3-port-coverage branch May 28, 2026 19:11
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Jun 26, 2026
Hot keyed list-diff path (grid steady state) allocated heavily and missed
fast-paths even when keys were unchanged. Eliminate per-diff allocations and
add the missing fast-path, preserving diff behavior exactly.

ChildReconciler.cs:
- Keyed prefix/suffix loops now take the Element.CanSkipUpdate early-exit
  that the positional path has, so stable keyed rows no longer re-diff every
  tick (#30); cache children.Count once instead of re-reading the COM
  IVector.get_Size per suffix iteration (#37).
- Replace HashSet-returning ComputeLIS with allocation-free ComputeLISInto
  filling a pooled bool mask; pool tails/tailIndices/predecessors from
  ArrayPool (#31/#32). Keep a thin ComputeLIS(int[]) wrapper for tests.
- Pool ReconcileKeyedMiddle's working arrays (ArrayPool) and the two
  key->index maps (re-entrancy-safe ThreadStatic dict pool); buffers cleared
  and returned on every exit (#33).
- Filter: count-pass + single Element[] fill, no List+ToArray (#36).
- GetKey: cache Type.Name via ConcurrentDictionary (#38).

KeyedListDiff.cs:
- Rent newKeys from ArrayPool<string>, threading explicit newCount (rented
  array may be larger); returned clearArray:true in a finally (#2).
- Move the no-op (SequenceEqual) + empty/empty fast paths ABOVE the duplicate
  scan so the steady-state grid case never allocates/scans a dup set (#1).
- Fold the churn-bailout decision into ApplyGeneral, computed from the same
  post-prefix/suffix scratch map the general walk builds (diff-range churn ==
  full-range churn), removing the O(2n) null-marker pre-pass (#34).
- Pool the doomed ReactorRow[] (ArrayPool, descending IComparer sort over
  [0,removes), cleared+returned) (#3).
- Lazy-allocate movedRows only on an actual move under an ambient (#35).
- In-place SyncLastKeysToSource instead of LastKeys Clear()+Add (#10).
- HasDuplicates reuses state.Scratch (TryAdd) for 4+ keys instead of a fresh
  HashSet (#11); cached null-key diagnostic sample (#41).

Tests: add pooling non-corruption coverage (rented-buffer-larger-than-count,
interleaved independent states, randomized stress vs oracle with survivor
identity, pooled doomed removes, churn with shared prefix+suffix, Scratch
reuse for the dup scan) and ComputeLISInto bool-mask coverage. Full
Reactor.Tests suite green (9693 passed); core lib Release build is
warning-clean (AOT/trim).

Closes #653

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Jun 27, 2026
…ff (#657)

* perf: eliminate per-diff allocations in ChildReconciler + KeyedListDiff

Hot keyed list-diff path (grid steady state) allocated heavily and missed
fast-paths even when keys were unchanged. Eliminate per-diff allocations and
add the missing fast-path, preserving diff behavior exactly.

ChildReconciler.cs:
- Keyed prefix/suffix loops now take the Element.CanSkipUpdate early-exit
  that the positional path has, so stable keyed rows no longer re-diff every
  tick (#30); cache children.Count once instead of re-reading the COM
  IVector.get_Size per suffix iteration (#37).
- Replace HashSet-returning ComputeLIS with allocation-free ComputeLISInto
  filling a pooled bool mask; pool tails/tailIndices/predecessors from
  ArrayPool (#31/#32). Keep a thin ComputeLIS(int[]) wrapper for tests.
- Pool ReconcileKeyedMiddle's working arrays (ArrayPool) and the two
  key->index maps (re-entrancy-safe ThreadStatic dict pool); buffers cleared
  and returned on every exit (#33).
- Filter: count-pass + single Element[] fill, no List+ToArray (#36).
- GetKey: cache Type.Name via ConcurrentDictionary (#38).

KeyedListDiff.cs:
- Rent newKeys from ArrayPool<string>, threading explicit newCount (rented
  array may be larger); returned clearArray:true in a finally (#2).
- Move the no-op (SequenceEqual) + empty/empty fast paths ABOVE the duplicate
  scan so the steady-state grid case never allocates/scans a dup set (#1).
- Fold the churn-bailout decision into ApplyGeneral, computed from the same
  post-prefix/suffix scratch map the general walk builds (diff-range churn ==
  full-range churn), removing the O(2n) null-marker pre-pass (#34).
- Pool the doomed ReactorRow[] (ArrayPool, descending IComparer sort over
  [0,removes), cleared+returned) (#3).
- Lazy-allocate movedRows only on an actual move under an ambient (#35).
- In-place SyncLastKeysToSource instead of LastKeys Clear()+Add (#10).
- HasDuplicates reuses state.Scratch (TryAdd) for 4+ keys instead of a fresh
  HashSet (#11); cached null-key diagnostic sample (#41).

Tests: add pooling non-corruption coverage (rented-buffer-larger-than-count,
interleaved independent states, randomized stress vs oracle with survivor
identity, pooled doomed removes, churn with shared prefix+suffix, Scratch
reuse for the dup scan) and ComputeLISInto bool-mask coverage. Full
Reactor.Tests suite green (9693 passed); core lib Release build is
warning-clean (AOT/trim).

Closes #653

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* perf: address PR review on keyed-diff allocation fixes

Review follow-ups on #657 (keyed list-diff allocation work):

- ChildReconciler.ReconcileKeyedMiddle: return the pooled matched and inLis
  bool[] buffers with clearArray:false instead of true (Copilot review).
  Both are value-typed (no reference pinning) and have their used range
  fully (re)initialized before any read - matched via the Array.Clear on
  rent, inLis via ComputeLISInto leading clear - so the full-array wipe on
  return was avoidable O(rented-capacity) work on the hot path. Matches how
  the int[] newToOld already returns. Reference-typed pooled buffers
  (string[]/ReactorRow[] in KeyedListDiff) still clear.

- Tests (ChildReconcilerLisIntoTests): replace the circular oracle that
  compared ComputeLISInto against ComputeLIS (now a thin wrapper over it)
  with an independent brute-force LIS-length DP that honors the -1 unmapped
  sentinel, asserting the mask marks a valid strictly-increasing subsequence
  of maximal length.

- Tests (ChildReconcilerKeyedSkipTests, new): cover the #30 keyed
  CanSkipUpdate fast path - an identical keyed list skips every row with no
  ops and no child-control access, across repeated stable frames.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: correct keyed-middle reorder identity (C1/H1) + reorder & alloc tests

The keyed-middle reconciliation in ChildReconciler patched surviving
controls by their FINAL panel index while the panel was only partially
rearranged, so on reorders a survivor was patched against the wrong
control (C1, CRITICAL): e.g. rotation [a,b,c,d]->[b,c,d,a] rendered "c"
at slot 0 and scrambled keyed identity (focus/animation/state landed on
the wrong row). A related stale keyToIndex (only the moved key was
rewritten) left shifted siblings mis-indexed after an insert/move (H1).

Fix: extract the index logic into RunKeyedMiddleCore<TSink> behind a
struct-generic IKeyedMiddleSink seam (devirtualized, AOT-clean) and
replace the left-to-right loop with the canonical right-to-left LIS walk.
Each item is positioned immediately before its already-placed right
neighbour; LIS members stay put and only out-of-LIS movers relocate
(minimal moves). Every survivor is patched at its CURRENT live position,
resolved from a pooled oldRelToPanel int[] that is mutated in lock-step
with every Insert/Move so it stays exact -- fixing C1 and H1 together.
The production RealKeyedMiddleSink drives the identical Mount/Move/
UpdateChild/Unmount/Replace + ambient enter/move behaviour as before.
oldRelToPanel replaces the second pooled key->index dict (one fewer
rented dict per call).

Tests:
- ChildReconcilerKeyedMiddleCoreTests (new): a headless SimKeyedMiddleSink
  drives the SAME RunKeyedMiddleCore over identity cells (exact production
  parity, no live-WinUI selftest wall), with a 4-invariant oracle (length,
  prefix/suffix untouched, per-slot identity+content, every patch hits its
  claimed survivor) across rotation, full reverse, scramble, block-swap,
  inserts/removes/duplicates and prefix/suffix offsets. A faithful
  pre-fix reproduction proves the rotation regression test has teeth (the
  buggy walk corrupts content[0] and mis-patches; the real core is clean).
- KeyedListDiffPoolingTests: two GC.GetAllocatedBytesForCurrentThread
  budgets guarding the #1/#2/#11 pooling -- no-op steady-state diff is
  0 B/iter and a 128-key reorder is 72 B/diff; reverting the pooling
  (a new string[128] + a 128-entry HashSet per diff) fails them.

Diff correctness preserved; pooled buffers returned on every exit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: gate keyed no-op fast path on duplicate-free state + test hardening

Address Copilot re-review of e664f9f.

KeyedListDiff: the no-op fast path runs above the duplicate scan (#1), so
an UNCHANGED list that already holds duplicate keys -- the state a prior
duplicate bailout leaves behind, since ReactorListState.Reset preserves
the dups in Source/LastKeys but collapses ByKey to first occurrences --
would match LastKeys and return Empty, silently skipping the duplicate
bailout/diagnostic and leaving the diff in an invalid duplicate state.
Gate the fast path on `state.ByKey.Count == oldCount`: true exactly for
the duplicate-free steady state (allocation-free path preserved), false
when dups were collapsed (re-takes the bailout). The check is O(1) and
short-circuits before the O(n) SequenceEqualOrdinal, so the common
unique-key path pays nothing. No-op steady-state allocation stays 0 B/iter.

Tests:
- KeyedListDiffTests: new Apply_Unchanged_Duplicate_List_Re_Bails_Instead_
  Of_NoOp_FastPath -- proves an unchanged duplicate list re-bails; verified
  to FAIL without the guard (takes the no-op path and returns Empty).
- ChildReconcilerLisIntoTests: strengthen the LIS oracle to assert selected
  indices are never the unmapped -1 sentinel (a buggy impl could swap a real
  member for a -1 and still satisfy strictly-increasing + length).
- KeyedListDiffPoolingTests: drop the unused `using System.Buffers;`
  (fully-qualify the one ArrayPool cref) flagged by the reviewer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant