Skip to content

fix(e2e): DevtoolsUx toggle tests — one-shot fixture reset - #85

Merged
Chris Anderson (codemonkeychris) merged 1 commit into
mainfrom
fix/devtoolsux-e2e-toggle-reset
Apr 24, 2026
Merged

Chris Anderson (codemonkeychris) merged 1 commit into
mainfrom
fix/devtoolsux-e2e-toggle-reset

Conversation

@codemonkeychris

Copy link
Copy Markdown
Collaborator

Summary

  • Fixture factory DevtoolsUxFixtures.DevtoolsUxTest set DebugUI.Value = false on every call. Because Reactor re-renders from the root, each observable notification re-ran the factory and clobbered the toggle before the component could render the new value — so Devtools_Menu_Toggle_Flows_Through_To_Subscribers and Devtools_Menu_Toggle_Is_Reversible both timed out waiting for debug-on / debug-off.
  • Moved the reset inside DevtoolsUxTestComponent.Render, gated by UseRef so it fires once per mount, synchronously before UseObservable reads the value. UseEffect isn't sufficient here: effects flush after Render has already captured debugUI, so the initial remount would still reflect stale state from the previous test and the subsequent TextBlock update never propagates.
  • Toggle tests now call NavigateToFixtureFresh — NavigateToFixture is a no-op when _currentFixture already matches, which skips the Component remount and leaves the prior test's toggle state in place.
  • Keeps a small ergonomic improvement to AppTestBase.WaitForText that includes the last-seen text in the timeout message. This was what made the root cause legible during investigation and is generally useful.

Test plan

  • dotnet test tests/Reactor.AppTests -p:Platform=x64 --filter ClassName=Microsoft.UI.Reactor.AppTests.Tests.DevtoolsUxTests — 3/3 pass
  • Individual tests also pass in isolation
  • Full dotnet test tests/Reactor.AppTests -p:Platform=x64 — verified going from 53/57 → 54/57; unrelated failures remain (Interactive_DataGrid_ClickEditTabCommit has a known duplicate-handler bug in the reconciler, and a newly observed flake in GestureTests.Interactive_OnPan_Drag_ReportsTranslationAndPhase is ordering-sensitive — both are separate investigations)

🤖 Generated with Claude Code

DevtoolsUxFixtures.DevtoolsUxTest was setting DebugUI.Value = false on
every invocation. Reactor re-renders from the root on any reactive
change, which re-runs the fixture factory — so the moment a toggle
click notified subscribers, the factory clobbered the new value before
the component could render it. The mirrored TextBlock stayed at
"debug-off" and WaitForText timed out.

Moved the reset inside DevtoolsUxTestComponent.Render, gated by a
UseRef so it fires once per mount, synchronously before UseObservable
reads the value. UseEffect isn't suitable here: effects flush after
Render has already captured `debugUI`, so the initial remount would
still reflect whatever state the previous test left behind.

Both toggle tests now use NavigateToFixtureFresh — the plain form is a
no-op when the fixture is already loaded (static _currentFixture
check), which skips the Component remount and leaves prior-test state
in place.

Also keeps the WaitForText last-seen-text diagnostic in AppTestBase
added during the broader E2E investigation — pure ergonomic
improvement that was invaluable for diagnosing this.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@codemonkeychris
Chris Anderson (codemonkeychris) merged commit ce37958 into main Apr 24, 2026
3 checks passed
@codemonkeychris
Chris Anderson (codemonkeychris) deleted the fix/devtoolsux-e2e-toggle-reset branch May 28, 2026 19:11
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Jun 25, 2026
H1 (#85): validate the per-element effective-theme-name cache against the
element's own RequestedTheme/ActualTheme DPs, not only the global generation
stamp, so a subtree-local RequestedTheme override the reconciler applies
without a generation bump is no longer served a stale cached name.

H2 (#86): drop the ThemeRef resolution caches on accent/system-palette changes
that keep the same Light/Dark theme (which do not raise ActualThemeChanged).
Both ReactorHost and ReactorHostControl now subscribe a dedicated always-on
UISettings.ColorValuesChanged at root mount and unsubscribe it in Dispose;
the handler calls ThemeRef.InvalidateCache() + RequestRender() (both
thread-safe). Independent of the chart-gated UISettings so it works in apps
that never activate charting.

Tests:
- ThemeRefCacheFixtures (selftest): resolve/cache-hit/invalidate, per-element
  RequestedTheme flip both directions (H1 guard), stale-until-invalidate then
  fresh-after-invalidate (#86 guard).
- ListViewHandlerSelectionFixtures (selftest): typed multi-selection snapshot
  for ListView + GridView (#100), IsItemClickEnabled tracking across record
  cycles (partial H4 — full no-duplicate-fire needs real pointer input / E2E).
- AnimationAmbientTests: two HasAny one-way-latch unit tests (#183 gate).

Behaviour preserved: theme resolution returns identical brushes and still
updates on theme/palette change; no new reflection (AOT/trim clean).

Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Jun 25, 2026
Second pr-review round on PR #667. Addresses the theme-resolution findings:

H1 (correctness): the #85 effective-theme-name cache was generation-validated
plus the element's own RequestedTheme/ActualTheme DP reads, so a Default-themed
descendant of an ancestor whose RequestedTheme flips could serve a stale theme
inside the synchronous reconcile (before WinUI propagates the child's
ActualTheme). Make the name cache reconcile-scoped instead: the host bumps a
_reconcilePass once per Render() (ThemeRef.BeginReconcilePass), so every element
re-walks its ancestors at most once per render -- collapsing the dozens of
per-token walks (the #85 win) while matching the original always-walk result
exactly. This is the brief's 'resolve once per reconcile at the container'
option.

M1 (correctness): ResolveForTheme now captures the theme generation before the
uncached scan and only publishes the resolved brush when no InvalidateCache()
(e.g. from UISettings.ColorValuesChanged on a pool thread) raced it -- closing a
window where a pre-invalidation brush could be republished into the just-cleared
cache. _themeGeneration is kept solely for this guard; the per-render bump uses
the separate _reconcilePass.

Tests (additive, in-scope):
- ThemeRefCache_AncestorThemeFlipInheritedByDefaultChild selftest -- H1
  regression guard (ancestor flip + new pass re-resolves a Default child).
- ThemeRefCache_DefaultDictionaryFallback selftest -- #86 Default-dict fallback.
- ListView/GridView MultiSelection fixtures -- assert the typed copy preserves
  SelectedItems order and surfaces an empty snapshot on clear (#100).
- ObservableTreeTracker reentrancy test -- a side-effecting getter that fires
  PropertyChanged mid-walk exercises the _syncing fresh-scratch guard (#5).

Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Jun 25, 2026
Copilot round-3 review: AttachThemeListener subscribed ActualThemeChanged on
the rendered root and latched _themeListenerAttached, so after a root-element
type swap (newControl != _currentControl) the listener stayed stranded on the
detached old root. Theme flips then stopped firing InvalidateCache()+RequestRender(),
leaving ThemeRef-resolved brushes stale (the #85/#86 caches were never dropped).

ReactorHostControl is a ContentControl, so subscribe on the host instance itself
(this.ActualThemeChanged) — stable across rendered-root swaps — instead of the
swappable root. A single subscription suffices and the latch no longer needs to
move it. ReactorHost (not a FrameworkElement) already re-binds correctly via
_themeListenerElement, so it is unchanged.

Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Jun 29, 2026
…change (#660 #86)

ThemeRef.Resolve recursed Application.Resources.MergedDictionaries (XamlControlsResources
and its nested dictionaries) on every resolve — per cell x per color token x per render on
the data-grid workload. Cache the deterministic (resourceKey, themeName) -> Brush result in
a process-wide ConcurrentDictionary and clear it from the hosts' theme-change handlers
(ActualThemeChanged + UISettings.ColorValuesChanged). Transient-null Application.Resources
(early startup) is not cached, so no poisoned null entry. Cached value mirrors the uncached
return exactly (including null for unknown keys); ThemeDictionary brushes are shared
instances, so returning the cached reference is identical behavior.

Self-contained in Theme.cs (no BrushHelper/ThemeBinding/Reconciler coupling). The per-element
theme-NAME cache (#85) is intentionally NOT here — it needs a generation bump where a localized
RequestedTheme is applied (Reconciler.cs, sibling-owned), which is a cross-ownership change
flagged to the coordinator.

Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Jun 30, 2026
…omics (#660)

Remove per-frame delegate/closure allocations and full-barrier atomics from the
render-loop hosts (ReactorHost + ReactorHostControl), which run at render/data-tick
frequency on the data-grid stress workload:

  #178 QueryCache.DispatcherPost: pass action.Invoke, drop the () => action() trampoline
  #179 cache _rerenderAction instead of () => RequestRender() every render
  #180 cache _renderLoopHandler (DispatcherQueueHandler) for TryEnqueue
  #181 cache _requestRenderAction (RequestRender method group) for BeginRender + Reconcile
  #182 HotReloadService.ConsumeUpdatePending: Volatile.Read fast-path, atomic only when pending
  #183 AnimationAmbient.HasAny sentinel gates the per-setState AsyncLocal walk
  #185 _lastRenderMs: Volatile.Write (single writer) instead of Interlocked.Exchange
  #186 report gate: integer ElapsedMilliseconds compare instead of Elapsed.TotalSeconds
  #187 remove unconditional [embed:trace] Console.Error writes at window open

Behavior preserved: identical render cadence, delegate semantics, and re-render
coalescing; HasAny is a one-way sentinel so any app that opens an Animations.Animate
transaction keeps the full AsyncLocal path. New AnimationAmbient.HasAny tests.

Deferred (flagged to coordinator): theme resolution cache (#85/#86) — #85's per-element
theme-name cache needs generation invalidation on localized RequestedTheme application
which lives in Reconciler.cs (sibling-owned), so it's a cross-boundary change; and theme
resolution can't be measured headlessly. #184 charting dirty-gate (chart-specific, secondary).

Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Jun 30, 2026
…change (#660 #86)

ThemeRef.Resolve recursed Application.Resources.MergedDictionaries (XamlControlsResources
and its nested dictionaries) on every resolve — per cell x per color token x per render on
the data-grid workload. Cache the deterministic (resourceKey, themeName) -> Brush result in
a process-wide ConcurrentDictionary and clear it from the hosts' theme-change handlers
(ActualThemeChanged + UISettings.ColorValuesChanged). Transient-null Application.Resources
(early startup) is not cached, so no poisoned null entry. Cached value mirrors the uncached
return exactly (including null for unknown keys); ThemeDictionary brushes are shared
instances, so returning the cached reference is identical behavior.

Self-contained in Theme.cs (no BrushHelper/ThemeBinding/Reconciler coupling). The per-element
theme-NAME cache (#85) is intentionally NOT here — it needs a generation bump where a localized
RequestedTheme is applied (Reconciler.cs, sibling-owned), which is a cross-ownership change
flagged to the coordinator.

Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Jun 30, 2026
…rame atomics, cache theme-brush resolution (#660) (#751)

* perf(render-loop): cache per-frame host delegates + drop per-frame atomics (#660)

Remove per-frame delegate/closure allocations and full-barrier atomics from the
render-loop hosts (ReactorHost + ReactorHostControl), which run at render/data-tick
frequency on the data-grid stress workload:

  #178 QueryCache.DispatcherPost: pass action.Invoke, drop the () => action() trampoline
  #179 cache _rerenderAction instead of () => RequestRender() every render
  #180 cache _renderLoopHandler (DispatcherQueueHandler) for TryEnqueue
  #181 cache _requestRenderAction (RequestRender method group) for BeginRender + Reconcile
  #182 HotReloadService.ConsumeUpdatePending: Volatile.Read fast-path, atomic only when pending
  #183 AnimationAmbient.HasAny sentinel gates the per-setState AsyncLocal walk
  #185 _lastRenderMs: Volatile.Write (single writer) instead of Interlocked.Exchange
  #186 report gate: integer ElapsedMilliseconds compare instead of Elapsed.TotalSeconds
  #187 remove unconditional [embed:trace] Console.Error writes at window open

Behavior preserved: identical render cadence, delegate semantics, and re-render
coalescing; HasAny is a one-way sentinel so any app that opens an Animations.Animate
transaction keeps the full AsyncLocal path. New AnimationAmbient.HasAny tests.

Deferred (flagged to coordinator): theme resolution cache (#85/#86) — #85's per-element
theme-name cache needs generation invalidation on localized RequestedTheme application
which lives in Reconciler.cs (sibling-owned), so it's a cross-boundary change; and theme
resolution can't be measured headlessly. #184 charting dirty-gate (chart-specific, secondary).

Co-authored-by: Copilot <[email protected]>

* perf(theme): cache (key,theme) -> Brush resolution, cleared on theme change (#660 #86)

ThemeRef.Resolve recursed Application.Resources.MergedDictionaries (XamlControlsResources
and its nested dictionaries) on every resolve — per cell x per color token x per render on
the data-grid workload. Cache the deterministic (resourceKey, themeName) -> Brush result in
a process-wide ConcurrentDictionary and clear it from the hosts' theme-change handlers
(ActualThemeChanged + UISettings.ColorValuesChanged). Transient-null Application.Resources
(early startup) is not cached, so no poisoned null entry. Cached value mirrors the uncached
return exactly (including null for unknown keys); ThemeDictionary brushes are shared
instances, so returning the cached reference is identical behavior.

Self-contained in Theme.cs (no BrushHelper/ThemeBinding/Reconciler coupling). The per-element
theme-NAME cache (#85) is intentionally NOT here — it needs a generation bump where a localized
RequestedTheme is applied (Reconciler.cs, sibling-owned), which is a cross-ownership change
flagged to the coordinator.

Co-authored-by: Copilot <[email protected]>

* fix(theme): complete #86 brush-cache invalidation per #751 review

Two correctness hardenings on the (key,theme)->Brush cache:

1. Wire ReactorHostControl to UISettings.ColorValuesChanged (high-contrast /
   accent / palette) -> InvalidateResolutionCache, mirroring ReactorHost. Before,
   the embedded host only invalidated on ActualThemeChanged (Light/Dark), so an
   app using ReactorHostControl without a ReactorApp would keep stale brushes on a
   same-theme accent/high-contrast change. Subscribe on theme-listener attach,
   unsubscribe in Dispose.

2. Cache ONLY successful (non-null) resolutions. A cached null for an unknown key
   would go stale if a ResourceDictionary defining that key is merged in after the
   first resolve (a dictionary add raises no theme-change event). Unknown keys are
   rare; re-walking them is the same cost as pre-cache and always correct.

Invalidation now covers: Light<->Dark (ActualThemeChanged, both hosts — AND the
cache key includes the theme name so a toggle auto-misses) + accent/palette/
high-contrast (ColorValuesChanged, both hosts). Existing theme selftests pass with
the cache active, incl. StructuralSkip_ThemeRangeParity
(ThemeRange_ForegroundReresolvedOnToggle: resolve brush -> toggle theme -> assert
re-resolved) and Issue522_CacheClear_StyleClearedDespiteCacheClear. Full headless
suite 9915/0; build 0/0.

Co-authored-by: Copilot <[email protected]>

* test(theme): regression coverage for #86 brush-cache invalidation (H1/H2)

Selftest fixtures pinning the two converged review findings (the code fixes
landed in 3fd38c4):

- Theme_BrushCacheNullMissNotCached (H2): resolve an unknown key → null (NOT
  cached) → merge a ResourceDictionary defining it → resolves to the brush. Guards
  against the cached-null poisoning a later-merged key (XamlIslandBootstrap /
  docking-embed late XamlControlsResources binding).
- Theme_BrushCacheInvalidationReResolves (H1 mechanism): resolve key→brushA
  (cached) → swap to brushB for the same (key,theme) → still brushA (stale) →
  ThemeRef.InvalidateResolutionCache() (what the hosts call on
  ColorValuesChanged/ActualThemeChanged) → re-resolves to brushB.

Both green. Validates the invalidation path the ReactorHostControl
ColorValuesChanged wiring (3fd38c4) depends on.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
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