Skip to content

🧪 [Testing] Add timeout error path test for WaitForWindow#104

Open
Ven0m0 wants to merge 1 commit intomainfrom
test-waitforwindow-timeout-1221782000402455162
Open

🧪 [Testing] Add timeout error path test for WaitForWindow#104
Ven0m0 wants to merge 1 commit intomainfrom
test-waitforwindow-timeout-1221782000402455162

Conversation

@Ven0m0
Copy link
Copy Markdown
Owner

@Ven0m0 Ven0m0 commented May 4, 2026

🎯 What:

  • The WaitForWindow function in Lib/v2/WindowManager.ahk was improperly catching TimeoutError, which WinWait in AutoHotkey v2 no longer throws (it returns 0 instead on timeout).
  • Refactored WaitForWindow to support Dependency Injection for its API calls.
  • Fixed the timeout return value check.
  • Added a dedicated test for the timeout scenario in ahk/test_WindowManager.ahk.

📊 Coverage:

  • Now tests the exact scenario where the window never appears and a timeout occurs.
  • Evaluates correct execution arguments and validates that WaitForWindow propagates the false return state.

Result:

  • Improved overall code coverage.
  • Fixed an underlying logical bug inside the error-handling path itself.

PR created automatically by Jules for task 1221782000402455162 started by @Ven0m0

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings May 4, 2026 01:28
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

This PR updates the shared AutoHotkey v2 window helper to fix WaitForWindow's timeout handling and adds a corresponding test path. It fits into the repo's shared Lib/v2/ utilities by correcting behavior in a reusable window-management helper and extending the manual test harness under ahk/.

Changes:

  • Refactors WaitForWindow in Lib/v2/WindowManager.ahk to use an injectable API wrapper instead of catching TimeoutError.
  • Changes timeout detection to treat WinWait(...) = 0 as the timeout case.
  • Adds a timeout-focused test in ahk/test_WindowManager.ahk using a mocked window API.

Reviewed changes

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

File Description
Lib/v2/WindowManager.ahk Refactors WaitForWindow to use dependency injection and return false when WinWait times out.
ahk/test_WindowManager.ahk Adds a mock WinWait implementation and a new timeout regression test for WaitForWindow.

Comment thread Lib/v2/WindowManager.ahk
Comment on lines +36 to +40
WaitForWindow(winTitle, timeout := 30, api := "") {
if !api
api := SystemWindowAPI()

return api.WinWait(winTitle, , timeout) != 0
Comment on lines 194 to 203
TestToggleFakeFullscreen_MakeFullscreen()
TestToggleFakeFullscreen_RestoreWindow()

TestGetMonitorAtPos_InsideMonitor()
TestGetMonitorAtPos_OutsideMonitors()
TestGetMonitorAtPos_MultipleMonitors()
TestWaitForWindow_Timeout()

FileOpen("*", "w `n").Write("All tests complete.`n")
ExitApp
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 4, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • Lib/v2/WindowManager.ahk - Refactored WaitForWindow to use DI pattern and fixed incorrect TimeoutError catch (AHK v2 WinWait returns 0 on timeout, it does not throw). Added WinWait proxy to SystemWindowAPI.
  • ahk/test_WindowManager.ahk - Added WinWait mock and TestWaitForWindow_Timeout test covering the timeout return path.

Reviewed by kimi-k2.6-20260420 · 363,582 tokens

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the WaitForWindow function in WindowManager.ahk to support dependency injection, facilitating better unit testing. It also introduces a mock implementation for WinWait and a new test case, TestWaitForWindow_Timeout, to verify timeout behavior. Feedback was provided regarding the test runner in test_WindowManager.ahk, which currently does not verify the return values of test functions, meaning failures would not be correctly propagated to CI environments.

Comment on lines 194 to +200
TestToggleFakeFullscreen_MakeFullscreen()
TestToggleFakeFullscreen_RestoreWindow()

TestGetMonitorAtPos_InsideMonitor()
TestGetMonitorAtPos_OutsideMonitors()
TestGetMonitorAtPos_MultipleMonitors()
TestWaitForWindow_Timeout()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The test runner in this script does not verify the return values of the test functions. If a test fails (returns false), the script will still proceed to print "All tests complete." and exit with a success code (0). This makes the tests ineffective for CI environments where a non-zero exit code is required to signal failure. Since this PR adds a new test, it's a good opportunity to ensure failures are correctly propagated.

if !TestToggleFakeFullscreen_MakeFullscreen()
    ExitApp(1)
if !TestToggleFakeFullscreen_RestoreWindow()
    ExitApp(1)

if !TestGetMonitorAtPos_InsideMonitor()
    ExitApp(1)
if !TestGetMonitorAtPos_OutsideMonitors()
    ExitApp(1)
if !TestGetMonitorAtPos_MultipleMonitors()
    ExitApp(1)
if !TestWaitForWindow_Timeout()
    ExitApp(1)

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.

2 participants