Skip to content

fix(v3/windows): skip the WebView2 embed test in CI - #5951

Merged
leaanthony merged 3 commits into
masterfrom
fix/webview2-cookie-test-ci-hang
Aug 12, 2026
Merged

leaanthony merged 3 commits into
masterfrom
fix/webview2-cookie-test-ci-hang

Conversation

@leaanthony

@leaanthony leaanthony commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

TestCookieManager intermittently hangs on windows-latest until the 10 minute package timeout, which fails the whole Run Go Tests v3 (windows-latest) job and blocks unrelated PRs.

Evidence it is a flake, not a regression

Three completed Build + Test v3 runs at the identical commit 0b43f20c9:

run result TestCookieManager
31547262490 success PASS (13.94s)
31547268338 failure timed out at 600s
31548140772 success passed

Same code, 13.94 s one run and a ten-minute hang the next. I checked the passing run's log specifically to confirm the test ran rather than being skipped.

Why it hangs for the full ten minutes

panic: test timed out after 10m0s
	running tests:
		TestCookieManager (10m0s)

goroutine 151 [syscall]:
golang.org/x/sys/windows.(*LazyProc).Call(...)
edge.(*Chromium).Embed(...) chromium.go:218
edge.TestCookieManager(...) cookies_test.go:73

chromium.go:218 is the GetMessageW call in Chromium.Embed's message pump:

if err := createCoreWebView2EnvironmentWithOptions(...); err != nil {
    e.errorCallback(...)          // reported, then falls through
}
e.webview2RuntimeVersion, err = webviewloader.GetAvailable...()
if err != nil {
    e.errorCallback(...)          // reported, then falls through
}
for {
    if atomic.LoadUintptr(&e.inited) != 0 { break }
    r, _, _ := w32.User32GetMessageW.Call(...)   // line 218
    if r == 0 { break }
    ...
}

Both error paths report and fall into the pump anyway, and the pump has no deadline — GetMessageW returns 0 only on WM_QUIT. If the environment-created callback never fires, Embed spins forever. CI's test timeout is the only thing in the system that ever breaks the loop.

What this PR does

Skips the test when CI is set, unless WAILS_TEST_WEBVIEW2=1 forces it. It stays a normal test locally on Windows, where an interactive window station and a working WebView2 runtime are actually present.

It is the only test in pkg/edge that embeds a real WebView2 — TestFocusBeforeControllerReady, TestFocusBeforeControllerReadyConcurrent and TestHasCapability are pure logic and keep running in CI.

This deliberately does not touch Chromium.Embed. Giving the pump a deadline needs SetTimer/KillTimer or MsgWaitForMultipleObjectsEx bindings, none of which exist in internal/w32 today, and it is production behaviour that deserves its own change and real Windows testing.

The underlying bug is worth fixing separately

The missing deadline is not only a test problem: a user whose WebView2 environment fails to initialise gets a silently hung window rather than an error, because Embed reports through errorCallback and then blocks forever instead of returning false. Worth folding into #5769 (migrate off pkg/edge) or fixing directly.

Verification

GOOS=windows go vet ./internal/webview2/pkg/edge/ clean (two pre-existing unsafe.Pointer warnings in unrelated files, vet exits 0), GOOS=windows go test -c compiles, gofmt clean. The diff also adds the missing trailing newline at end of file, which is why gofmt -l previously listed it.

Summary by CodeRabbit

  • Tests
    • Updated cookie manager testing to skip WebView2-specific checks in CI environments unless explicitly enabled.
    • Improved test reliability during WebView2 setup by ensuring platform-specific execution requirements are met.

Copilot AI lite review requested due to automatic review settings August 12, 2026 00:36
@github-actions github-actions Bot added the v3 label Aug 12, 2026
@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The WebView2 cookie manager test now skips in CI unless WAILS_TEST_WEBVIEW2 is set. It locks execution to the current OS thread during COM and WebView2 setup. The existing cookie-management logic remains unchanged.

Changes

WebView2 cookie test

Layer / File(s) Summary
CI guard and WebView2 setup
v3/internal/webview2/pkg/edge/cookies_test.go
The test reads environment variables, skips in CI without explicit opt-in, and locks execution to the current OS thread during setup. The cookie-management test structure remains intact.

Estimated code review effort: 2 (Simple) | ~5 minutes

Poem

A rabbit checks the CI gate,
Then locks one thread to keep things straight.
Cookies hop through WebView2’s door,
While unchanged tests check once more.
Hop, hop—safe runs galore!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides detailed motivation, evidence, scope, and verification, but omits the template’s type selection, test configuration, issue link, and checklist. Add the missing issue reference, type and platform selections, wails doctor output or environment details, and completed checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Windows CI change and matches the primary purpose of the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/webview2-cookie-test-ci-hang

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 reduces CI flakiness on Windows by conditionally skipping the pkg/edge WebView2 embedding integration test (TestCookieManager) when running under CI, while still allowing the test to be forced on via WAILS_TEST_WEBVIEW2=1.

Changes:

  • Skip TestCookieManager when CI is set unless WAILS_TEST_WEBVIEW2=1 is explicitly provided.
  • Add an explanatory comment describing the CI hang failure mode and the rationale for skipping.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
v3/internal/webview2/pkg/edge/cookies_test.go (1)

28-29: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Require the documented opt-in value.

The PR contract uses WAILS_TEST_WEBVIEW2=1. The current condition treats every non-empty value as enabled. WAILS_TEST_WEBVIEW2=0 can therefore run the test and reintroduce the CI hang.

Proposed fix
-if os.Getenv("WAILS_TEST_WEBVIEW2") == "" && os.Getenv("CI") != "" {
+if os.Getenv("WAILS_TEST_WEBVIEW2") != "1" && os.Getenv("CI") != "" {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@v3/internal/webview2/pkg/edge/cookies_test.go` around lines 28 - 29, Update
the WebView2 test skip condition to require WAILS_TEST_WEBVIEW2 to equal "1"
exactly when running in CI, so values such as "0" continue to skip the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@v3/internal/webview2/pkg/edge/cookies_test.go`:
- Around line 33-34: Ensure all WebView2 cookie-manager calls and Release
operations execute on the same dedicated COM STA thread that creates the
control. Update the test flow around t.Run so subtests do not invoke these
operations from their separate goroutines; move the operations outside t.Run or
marshal them through one runtime.LockOSThread-protected STA goroutine.

---

Outside diff comments:
In `@v3/internal/webview2/pkg/edge/cookies_test.go`:
- Around line 28-29: Update the WebView2 test skip condition to require
WAILS_TEST_WEBVIEW2 to equal "1" exactly when running in CI, so values such as
"0" continue to skip the test.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4a9dae1b-3c32-4732-9ced-7e0a75e655e5

📥 Commits

Reviewing files that changed from the base of the PR and between 20b7eb7 and ee52043.

📒 Files selected for processing (1)
  • v3/internal/webview2/pkg/edge/cookies_test.go

Comment on lines +33 to +34
runtime.LockOSThread()
defer runtime.UnlockOSThread()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

test_file="v3/internal/webview2/pkg/edge/cookies_test.go"

# Confirm the test's thread and subtest boundaries.
rg -n -C 8 \
  'LockOSThread|UnlockOSThread|CoInitializeEx|CoUninitialize|t\.Run|GetCookieManager|cookieManager\.|cookie\.Release' \
  "$test_file"

# Check whether the cookie-manager wrappers marshal calls to the WebView2 thread.
rg -n -C 8 \
  'type .*CookieManager|func .*GetCookieManager|func .*CreateCookie|func .*DeleteAllCookies|func .*AddOrUpdateCookie|func .*DeleteCookie' \
  --glob '*.go' .

Repository: wailsapp/wails

Length of output: 31048


🏁 Script executed:

#!/bin/bash
set -euo pipefail

test_file="v3/internal/webview2/pkg/edge/cookies_test.go"

# Inspect the complete test lifecycle and the relevant WebView2 implementation.
sed -n '1,230p' "$test_file"
sed -n '930,1025p' v3/internal/webview2/pkg/edge/chromium.go

# Identify whether these COM wrappers perform any thread marshalling.
rg -n -C 5 \
  'Invoke|Post|Send|runOn|mainThread|LockOSThread|CoInitialize|CoUninitialize' \
  v3/internal/webview2/pkg/edge --glob '*.go'

Repository: wailsapp/wails

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Read the installed Go testing implementation and documentation for t.Run.
go env GOROOT
rg -n -C 12 \
  'func \(t \*T\) Run|runs f in a separate goroutine|separate goroutine' \
  "$(go env GOROOT)/src/testing/testing.go" \
  "$(go env GOROOT)/src/testing/testing_test.go" 2>/dev/null || true

Repository: wailsapp/wails

Length of output: 2380


🌐 Web query:

Microsoft WebView2 COM threading model ICoreWebView2 methods thread that created the control

💡 Result:

The Microsoft WebView2 control is built on the Component Object Model (COM) and follows a strict threading model [1]. It must be created on a UI thread that uses a message pump, and all interactions with the control and its methods (including ICoreWebView2 interface methods) must occur on that same thread [1][2]. Key details regarding the WebView2 threading model include: 1. Thread Affinity: You must create the WebView2 control on a UI thread [1]. Any request or method call made to an ICoreWebView2 instance must be performed on the thread that created the control [1]. Accessing the control or its methods from any other thread is not supported and will lead to issues, such as COM exceptions or incorrect behavior [1][2]. 2. Callbacks: All event handlers, completion handlers, and other callbacks associated with WebView2 are executed on the same UI thread that created the control [1]. 3. Exceptions: The threading requirements are strict for almost all operations. A notable exception is the Content property of ICoreWebView2WebResourceRequest, which is read from a background thread [1]. For this property, the stream should be agile or created from a background Single Threaded Apartment (STA) to avoid performance issues on the UI thread [1]. 4. Object Properties: While some methods might technically execute if called from a different thread, accessing the resulting objects or their properties (such as cookies or specific event arguments) from outside the original UI thread will typically throw an exception [1]. In summary, for reliable and supported operation, always ensure that all ICoreWebView2 methods and interactions are strictly confined to the thread that initially created the WebView2 control [1][2].

Citations:


Keep all WebView2 calls on the COM STA thread.

t.Run runs each callback in a separate goroutine, while runtime.LockOSThread applies only to the parent goroutine. The subtests therefore call cookie-manager methods and Release outside the STA that created the WebView2 control. Move these operations out of t.Run, or marshal them through one dedicated locked STA goroutine.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@v3/internal/webview2/pkg/edge/cookies_test.go` around lines 33 - 34, Ensure
all WebView2 cookie-manager calls and Release operations execute on the same
dedicated COM STA thread that creates the control. Update the test flow around
t.Run so subtests do not invoke these operations from their separate goroutines;
move the operations outside t.Run or marshal them through one
runtime.LockOSThread-protected STA goroutine.

Source: MCP tools

@leaanthony
leaanthony merged commit 2b8468e into master Aug 12, 2026
22 checks passed
@leaanthony
leaanthony deleted the fix/webview2-cookie-test-ci-hang branch August 12, 2026 01:11
leaanthony pushed a commit that referenced this pull request Aug 12, 2026
timlinde pushed a commit to Topborn/wails that referenced this pull request Aug 22, 2026
* fix(v3/windows): skip the WebView2 embed test in CI

* test: lock OS thread for COM STA in TestCookieManager

Co-authored-by: leaanthony <[email protected]>

---------

Co-authored-by: taliesin-ai <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
timlinde pushed a commit to Topborn/wails that referenced this pull request Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants