Fix #472: don't expand to other windows when --window is explicit#481
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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.IsExplicitWindowto distinguish explicit--windowsessions from auto-selected windows. - Set
IsExplicitWindow = trueonly when resolving sessions by HWND inUiSessionService. - Prevent cross-window expansion in
UiAutomationService(inspect,search,find) whenIsExplicitWindowis 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.
Contributor
Build Metrics ReportBinary Sizes
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 Time31ms median (x64, Updated 2026-04-21 17:38:35 UTC · commit |
chiaramooney
approved these changes
Apr 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #472.
Problem
winapp ui inspect --window <HWND>(andui search/ui find) returned elements from other top-level windows of the same process, not just the explicitly targeted HWND.Root cause:
UiAutomationServicecallsGetAllAppWindows(session)/FindElementOnOtherWindowswhenever the user didn't pass a selector, gated only onstring.IsNullOrEmpty(elementId).WindowHandlealone can't distinguish an explicit--windowfrom an auto-selected one — it's set in both cases — so explicit--windowcallers got the same fan-out as--app-only callers.Fix
UiSessionInfo.IsExplicitWindow(defaultfalse).trueonly inUiSessionService.ResolveByHwnd(the--windowpath). All other resolution paths leave itfalse.UiAutomationServiceon!session.IsExplicitWindow:InspectAsync— popup expansion viaGetAllAppWindowsSearchAsync— popup fallback when no main resultsFindSingleElementAsync— bothFindElementOnOtherWindowscallsTests
New
UiSessionServiceTests(3 tests, no new dependencies — inlineIUiAutomationServicestub +NullLogger):UiSessionInfo.IsExplicitWindowdefaults tofalseResolveSessionAsyncby HWND sets the flagtrueResolveSessionAsyncby PID leaves itfalseFull suite: 767/767 passing.
scripts/build-cli.ps1clean (schema/skills regenerated, no diff in those files).