Skip to content

[codex] preserve visible window state during activation#166

Merged
PrzemyslawKlys merged 1 commit intov2-speedygonzalesfrom
codex/fix-window-activation-focus-targets
Apr 1, 2026
Merged

[codex] preserve visible window state during activation#166
PrzemyslawKlys merged 1 commit intov2-speedygonzalesfrom
codex/fix-window-activation-focus-targets

Conversation

@PrzemyslawKlys
Copy link
Copy Markdown
Member

What changed

This change tightens the window-activation path so DesktopManager no longer changes the show state of a window that is already visible while trying to focus it.

It also moves the foreground-sensitive regression tests onto the repo-owned DesktopManager.TestApp harness instead of depending on whichever window happens to be active during a test run.

Why it changed

Running the foreground-focused tests could end up touching an arbitrary active window, which made the suite feel unsafe and could leave a maximized window restored to normal size.

The root cause was that activation preparation always called ShowWindow, even for visible windows. That behavior is now limited to minimized or hidden windows, and the tests now target a specific DesktopManager-owned window end to end.

Impact

  • Safer foreground activation during tests and automation preparation.
  • Foreground-sensitive tests now use a dedicated repo-owned harness.
  • Added regression coverage that a maximized harness window stays maximized after activation.

Validation

  • dotnet test Sources/DesktopManager.Tests/DesktopManager.Tests.csproj -f net8.0-windows --filter "DesktopAutomationAssertionTests|WindowManagerFilterTests|WindowTopMostActivationTests"
  • The targeted slice built and passed in this environment; interactive UI cases were skipped because no interactive desktop session was available.

- avoid calling ShowWindow on already visible windows during activation prep
- move foreground-sensitive tests onto the repo-owned DesktopManager.TestApp harness
- add coverage that maximized harness windows stay maximized after activation
@PrzemyslawKlys PrzemyslawKlys marked this pull request as ready for review April 1, 2026 12:17
@PrzemyslawKlys PrzemyslawKlys merged commit 01a0470 into v2-speedygonzales Apr 1, 2026
7 checks passed
@PrzemyslawKlys PrzemyslawKlys deleted the codex/fix-window-activation-focus-targets branch April 1, 2026 12:17
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe241a7570

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


manager.MaximizeWindow(window);
Thread.Sleep(150);
manager.ActivateWindow(window);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle activation-policy failures in maximized activation test

When RUN_FOREGROUND_UI_TESTS is enabled on Windows configurations that block focus stealing (the same UIPI/focus-policy scenario already handled in ActivateWindow_BringsToFront), manager.ActivateWindow(window) can throw InvalidOperationException. This new test does not catch that case, so it hard-fails instead of being marked inconclusive like the adjacent activation test, making the suite flaky in environments where foreground activation is intentionally restricted.

Useful? React with 👍 / 👎.

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