Skip to content

fix(tests): Usage hero fixture check fails when a Usage element briefly leaves UI Automation after a resize - #2165

Merged
bkudiess merged 1 commit into
openclaw:mainfrom
bkudiess:bkudiess-usage-hero-flake
Nov 13, 2026
Merged

bkudiess merged 1 commit into
openclaw:mainfrom
bkudiess:bkudiess-usage-hero-flake

Conversation

@bkudiess

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: the Usage hero fixture check (UsageHero_RealShellCapturesCardAndRangeInLightAndDark) fails intermittently with a NullReferenceException when a Usage element is briefly missing from UI Automation right after the test resizes the window.

User Impact

No user-visible change. The Mock Gateway fixture shard B stops failing on this test when the shell re-renders after a resize.

Why This Change Was Made

After resizing the window to the capture width, the test waited for the page width to settle. It did so by reading FindById(run, "UsagePageRoot")! inside a run.WaitForAsync poll, which does not catch errors from its condition. Then it read the page, hero, range controls, actions and page marker once each, outside the wait.

  • FindById skips app windows that UI Automation reports as offscreen, and a lookup can miss an element while the shell re-renders. Both happen right after a resize across a responsive width tier, or when the asynchronous "Windows containment unavailable" banner appears; the banner was visible in the failing run's capture.
  • So a missing element failed the test straight away:
    • latest: a NullReferenceException on main aab86ee;
    • earlier: Assert.False(IsOffscreen) in UsageRangeBounds.

The test now reads every element it measures inside one wait (TryReadUsageHeroLayout):

  • A missing element, an offscreen marker or range control, or ElementNotAvailableException means "not ready yet", and the wait polls again.
  • The wait succeeds only when two consecutive samples of all the bounds it measures are identical. It still times out with a named description if the layout never becomes ready.
  • The hero, range and action assertions and the capture now use that settled snapshot, and the assertions themselves are unchanged.
  • The scroll host and the pre-resize page width are also read inside waits.
  • UsageRangeBounds, which another test uses, keeps its behavior.
  • The timing-pattern baseline for this file drops from 45 to 38 one-shot lookups.

Earlier "Main Usage session header has no visible measured geometry" failures stopped after #2124 (fix(tests): Systems UI checks fail during native transitions) and are not part of this change.

Evidence

  • RED: main's test plus one injected missing UsagePageRoot lookup right after the resize fails with the CI signature, Usage-Light-hero-1400: System.NullReferenceException.
  • GREEN: this change plus the same single injected miss, inside TryReadUsageHeroLayout, passes. The injection was temporary and is not committed.
  • Repeat runs: 5 of 5 consecutive clean local passes of the test (52–54 s each).

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Required proof pools

  • none: test-only change to a mock Gateway fixture UI test. CI runs it natively in the fixture shard B job.

Validation

Local, head 1d15635 on main 378fd1a, isolated OPENCLAW_TRAY_* profile. Native runs held the exclusive native-desktop lock, and the real %APPDATA% and %LOCALAPPDATA%\OpenClawTray metadata manifests were unchanged afterwards.

Command Result
UsageHero, RED (main plus one injected missing root lookup) ❌ NullReferenceException (expected)
UsageHero, GREEN (fix plus the same injection) ✅ 1 passed
UsageHero, clean, 5 consecutive runs ✅ 5 of 5 passed
scripts\test-gateway-fixture.ps1 (full fixture suite, local) ⚠️ hit the 1800-second local deadline. UsageHero completed both themes with no errors; see "Not verified" for the other tests
scripts\validate-test-timing-patterns.ps1 ✅ pass; baseline for this file is 38
./build.ps1 ✅ pass
dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj ✅ 5862 passed, 29 skipped
dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj ✅ 6441 passed
git diff --check ✅ pass

Hanselman dual review (Claude Opus 5.5 and GPT-6 Astra, high effort) found no blocking issues.

  • Fixed: the wait description now names exactly what the wait checks. Both models raised this.
  • Not changed (LOW, one model only):
    • record a reason for each "not ready" sample;
    • read all the elements in one tree walk per poll;
    • re-acquire the scroll pattern if the page root is ever replaced.

Real Behavior Proof

  • Environment tested: local Windows 11 interactive desktop (exclusive native-desktop lock), isolated OPENCLAW_TRAY_* profile, fixture Gateway.
  • PR head or commit tested: 1d15635 (base main 378fd1a)
  • Exact steps or command run: dotnet test tests\OpenClaw.Tray.UITests -c Debug -r win-x64 -p:DevBuild=false --filter "FullyQualifiedName~GatewayFixtureUiTests.UsageHero_RealShellCapturesCardAndRangeInLightAndDark", with the fixture environment that scripts\test-gateway-fixture.ps1 sets.
  • Evidence after fix:
    • RED with injection: Failed ... Usage-Light-hero-1400: System.NullReferenceException.
    • GREEN with injection: Passed! 1/1 (56 s).
    • Clean: Passed! 1/1 five times in a row.
  • Observed result: the test survives a transient missing element and still proves the same layout.
  • Screenshot or artifact links verified? N/A
  • Not verified or blocked:
    • The local full fixture suite reached the 1800-second deadline on this slower dev host. UsageHero completed both themes in it with no errors.
    • Three other tests failed in that local run:
      • Dashboards wheel and SessionsDesign gallery: I ran without -NativeInputProof and -Screenshots, which CI passes.
      • SettingsPane_KeepsToggleChoiceAcrossPinnedPagesAndRestart: ElementNotAvailableException in the shared Invoke helper. This is not in the CI flake inventory and is not changed here.

Security Impact

  • New permissions or capabilities? No
  • Secrets or tokens handling changed? No
  • New or changed network calls? No
  • Command or tool execution surface changed? No
  • Data access scope changed? No
  • If any answer is Yes, explain the risk and mitigation: N/A

Compatibility and Migration

  • Backward compatible? Yes
  • Config or environment changes? No
  • Migration needed? No
  • If yes, list the exact upgrade steps: N/A

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • I left unresolved only conversations that still need maintainer judgment.

…ly leaves UI Automation after a resize

Read every peer the hero proof measures inside one wait that treats a missing,
offscreen or replaced element as not ready, and require two identical layout
samples before asserting and capturing. The previous poll dereferenced a
one-shot UsagePageRoot lookup and failed with a NullReferenceException when the
shell re-rendered after the resize or when the host-warning banner appeared.

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

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

The PR waits for a complete, stable Usage hero layout before measuring and capturing it after a window resize.

Example: The Light-theme fixture resizes to the 1400-DIP capture target and UsagePageRoot temporarily disappears from UI Automation.

  • Before: The width poll dereferences null and fails with NullReferenceException.
  • After: The poll retries until two complete geometry samples match, then runs the existing layout assertions.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused test repair with no identified defect; confidence rests on source review and reported native harness results while the relevant CI lane remains unfinished.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored test-only repair requires no separate shipped-entry-point proof; the body reports focused Windows fixture execution, with broader native CI still pending.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Test only · Worth it: Yes · Fix scope: Complete
User problem: Contributors receive false Usage fixture failures when UI Automation temporarily omits controls after resizing.
Reason: The collaborator-authored repair follows the repository's established readiness policy without weakening the visual contract or introducing product options.

Merge readiness

✅ Ready for maintainer review

Keep open: this collaborator-authored PR fixes a concrete test-readiness failure still present on main, preserves the layout assertions, and introduces no identified correctness defect.

Priority: P2
Reviewed head: 1d156352f80dc6288593bc5c64c5499c5bab55bd

Before merge

None.

Findings

None.

Agent review details

How this fits together

The native fixture test drives Companion against a synthetic Gateway, reads the Usage page through Windows UI Automation, and produces geometry assertions and capture artifacts.

flowchart LR
  A[Fixture Gateway] --> B[Companion Usage page]
  C[Native fixture test] --> B
  B --> D[UI Automation observations]
  D --> E[Stable layout snapshot]
  E --> F[Assertions and captures]
Loading

Technical review

Best possible solution:

Keep the repair in the existing fixture owner, retry transient UI Automation omissions, and assert the unchanged layout contract from the successful snapshot.

Do we have a high-confidence way to reproduce the issue?

The current-main source deterministically throws if the post-resize root lookup returns null, matching the reported injected-miss result; this review did not execute a reproduction.

Is this the best way to solve the issue?

This is a focused repair: the named snapshot helper handles a meaningful native observation boundary, separates geometry equality from marker identity, and preserves persistent-failure detection.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ec6271566652.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Precisely scoped introduced change: The pinned introduction changes only the Usage fixture helper, hero capture readiness, and its timing-pattern baseline; production files and base-only CI changes are outside this PR. (tests/OpenClaw.Tray.UITests/GatewayFixtureUiTests.UsageResponsive.cs:81, 1d156352f80d)
  • Failure path remains on main: Main directly dereferences the root lookup inside the width poll; GatewayFixtureRun propagates NullReferenceException, and FindById can return null when the owned app window is offscreen. (tests/OpenClaw.Tray.UITests/GatewayFixtureUiTests.UsageResponsive.cs:568, ec6271566652)
  • Existing test contract preserved: The new snapshot retains the required range-control visibility checks and hero, range, action, viewport, and responsive-tier assertions; missing observations reset stability rather than passing the test. (tests/OpenClaw.Tray.UITests/GatewayFixtureUiTests.UsageResponsive.cs:609, 1d156352f80d)
  • Reported validation and current CI: The body reports an injected-miss failure before repair, a pass after repair, five clean focused passes, and successful build, Shared, Tray, and timing-guard validation. The full local fixture run was incomplete. Exact-head CI has no failed check, but fixture shard B and other lanes remain in progress. This review ran no tests or review helpers. Supplied body identity: 2e563e574d06d0ab04711d3949da777df2b706b4190753f16c585cc498df904e. (1d156352f80d)
  • Feature history and distinct prior repair: Merged Usage implementation and subsequent fixture repairs consistently identify bkudiess as the area contributor. fix(tests): Systems UI checks fail during native transitions #2124 fixes loaded-session discovery, rather than this resize lookup. Some older blobs were unavailable to local follow/pickaxe searches; supplied provenance, main blame, path history, and GitHub PR descriptions establish the relevant history. (tests/OpenClaw.Tray.UITests/GatewayFixtureUiTests.UsageResponsive.cs:568, ec6271566652)
  • Repository policy applied: Read the complete root instructions; no nested AGENTS.md governs either changed path, and the maintainer-notes directory is absent. The change follows the documented captured-element and consecutive-stable-bounds pattern and lowers the baseline from 45 to 38. (docs/TEST_COVERAGE.md:775, 1d156352f80d)

Likely related people:

  • Barbara Kudiess: Raw commit 9d36f5c adds tests/OpenClaw.Tray.UITests/GatewayFixtureUiTests.UsageResponsive.cs:529 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9d36f5c8bfa0; files: tests/OpenClaw.Tray.UITests/GatewayFixtureUiTests.UsageResponsive.cs)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Change footprint Production +0/-0; tests and baseline +65/-20 Growth supports one native-observation boundary and value-based geometry comparison without adding production machinery or another fixture.

Labels

Label changes:

  • add P2: A focused repair to intermittent native fixture failures improves CI reliability without changing shipped product behavior.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A focused repair to intermittent native fixture failures improves CI reliability without changing shipped product behavior.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 13, 2026, 7:06 AM ET / 12:06 UTC.

@bkudiess
bkudiess merged commit 30e8a49 into openclaw:main Nov 13, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant