Skip to content

Fix #472: don't expand to other windows when --window is explicit#481

Merged
nmetulev merged 2 commits into
mainfrom
fix/issue-472-explicit-window
Apr 21, 2026
Merged

Fix #472: don't expand to other windows when --window is explicit#481
nmetulev merged 2 commits into
mainfrom
fix/issue-472-explicit-window

Conversation

@nmetulev
Copy link
Copy Markdown
Member

Fixes #472.

Problem

winapp ui inspect --window <HWND> (and ui search / ui find) returned elements from other top-level windows of the same process, not just the explicitly targeted HWND.

Root cause: UiAutomationService calls GetAllAppWindows(session) / FindElementOnOtherWindows whenever the user didn't pass a selector, gated only on string.IsNullOrEmpty(elementId). WindowHandle alone can't distinguish an explicit --window from an auto-selected one — it's set in both cases — so explicit --window callers got the same fan-out as --app-only callers.

Fix

  • Add UiSessionInfo.IsExplicitWindow (default false).
  • Set it to true only in UiSessionService.ResolveByHwnd (the --window path). All other resolution paths leave it false.
  • Gate the three popup/other-window expansion sites in UiAutomationService on !session.IsExplicitWindow:
    • InspectAsync — popup expansion via GetAllAppWindows
    • SearchAsync — popup fallback when no main results
    • FindSingleElementAsync — both FindElementOnOtherWindows calls

Tests

New UiSessionServiceTests (3 tests, no new dependencies — inline IUiAutomationService stub + NullLogger):

  • UiSessionInfo.IsExplicitWindow defaults to false
  • ResolveSessionAsync by HWND sets the flag true
  • ResolveSessionAsync by PID leaves it false

Full suite: 767/767 passing. scripts/build-cli.ps1 clean (schema/skills regenerated, no diff in those files).

ui inspect/search/find-single previously called GetAllAppWindows /
FindElementOnOtherWindows whenever the user didn't specify a selector,
even when they had explicitly targeted a single HWND via --window. That
made the output include elements from sibling top-level windows of the
same process, contradicting the explicit --window scope.

Add UiSessionInfo.IsExplicitWindow, set it in UiSessionService.ResolveByHwnd,
and gate the popup/other-window expansion in UiAutomationService on that
flag (InspectAsync, SearchAsync, FindSingleElementAsync).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 20, 2026 21:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an issue where UI operations scoped with --window <HWND> unintentionally expanded to other top-level windows belonging to the same process, by explicitly tracking whether the session was resolved via an explicit HWND.

Changes:

  • Add UiSessionInfo.IsExplicitWindow to distinguish explicit --window sessions from auto-selected windows.
  • Set IsExplicitWindow = true only when resolving sessions by HWND in UiSessionService.
  • Prevent cross-window expansion in UiAutomationService (inspect, search, find) when IsExplicitWindow is set, and add targeted unit tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/winapp-CLI/WinApp.Cli/Services/UiSessionService.cs Marks HWND-resolved sessions as explicitly scoped via IsExplicitWindow.
src/winapp-CLI/WinApp.Cli/Services/UiAutomationService.cs Gates popup/other-window expansion paths on !session.IsExplicitWindow to respect explicit --window scoping.
src/winapp-CLI/WinApp.Cli/Models/UiSessionInfo.cs Introduces IsExplicitWindow with documentation describing intended scoping behavior.
src/winapp-CLI/WinApp.Cli.Tests/UiSessionServiceTests.cs Adds tests verifying default/explicit HWND/PID behaviors for IsExplicitWindow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 20, 2026

Build Metrics Report

Binary Sizes

Artifact Baseline Current Delta
CLI (ARM64) 30.65 MB 30.66 MB 📈 +1.0 KB (+0.00%)
CLI (x64) 31.02 MB 31.02 MB 📈 +1.5 KB (+0.00%)
MSIX (ARM64) 12.93 MB 12.94 MB 📈 +1.4 KB (+0.01%)
MSIX (x64) 13.74 MB 13.74 MB 📈 +0.3 KB (+0.00%)
NPM Package 26.89 MB 26.89 MB 📈 +1.0 KB (+0.00%)
NuGet Package 26.98 MB 26.98 MB 📈 +1.7 KB (+0.01%)
VS Code Extension 19.72 MB 19.72 MB 📉 -0.2 KB (-0.00%)

Test Results

773 passed, 1 skipped out of 774 tests in 439.1s (+3 tests, -42.6s vs. baseline)

Test Coverage

20.9% line coverage, 35.2% branch coverage · ✅ no change vs. baseline

CLI Startup Time

31ms median (x64, winapp --version) · ✅ no change vs. baseline


Updated 2026-04-21 17:38:35 UTC · commit 30551c9 · workflow run

@nmetulev nmetulev merged commit 9f9b407 into main Apr 21, 2026
9 checks passed
@nmetulev nmetulev deleted the fix/issue-472-explicit-window branch April 21, 2026 17:23
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.

[Bug]: winui ui inspect --window <hwnd>: showed more than the listed HWND

3 participants