Repository navigation
fix(v3/windows): skip the WebView2 embed test in CI - #5951
Conversation
WalkthroughThe WebView2 cookie manager test now skips in CI unless ChangesWebView2 cookie test
Estimated code review effort: 2 (Simple) | ~5 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
TestCookieManagerwhenCIis set unlessWAILS_TEST_WEBVIEW2=1is 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.
Co-authored-by: leaanthony <[email protected]>
There was a problem hiding this comment.
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 winRequire 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=0can 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
📒 Files selected for processing (1)
v3/internal/webview2/pkg/edge/cookies_test.go
| runtime.LockOSThread() | ||
| defer runtime.UnlockOSThread() |
There was a problem hiding this comment.
🩺 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 || trueRepository: 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:
- 1: https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/threading-model
- 2: InvalidCastException when setting CoreWebView2NewWindowRequestedEventArgs.NewWindow in WPF MicrosoftEdge/WebView2Feedback#217
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
… the WebView2 embed test in CI
* 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]>
…s): skip the WebView2 embed test in CI
TestCookieManagerintermittently hangs onwindows-latestuntil the 10 minute package timeout, which fails the wholeRun Go Tests v3 (windows-latest)job and blocks unrelated PRs.Evidence it is a flake, not a regression
Three completed
Build + Test v3runs at the identical commit0b43f20c9:TestCookieManagerSame 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
chromium.go:218is theGetMessageWcall inChromium.Embed's message pump:Both error paths report and fall into the pump anyway, and the pump has no deadline —
GetMessageWreturns 0 only onWM_QUIT. If the environment-created callback never fires,Embedspins 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
CIis set, unlessWAILS_TEST_WEBVIEW2=1forces 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/edgethat embeds a real WebView2 —TestFocusBeforeControllerReady,TestFocusBeforeControllerReadyConcurrentandTestHasCapabilityare pure logic and keep running in CI.This deliberately does not touch
Chromium.Embed. Giving the pump a deadline needsSetTimer/KillTimerorMsgWaitForMultipleObjectsExbindings, none of which exist ininternal/w32today, 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
Embedreports througherrorCallbackand then blocks forever instead of returningfalse. Worth folding into #5769 (migrate offpkg/edge) or fixing directly.Verification
GOOS=windows go vet ./internal/webview2/pkg/edge/clean (two pre-existingunsafe.Pointerwarnings in unrelated files, vet exits 0),GOOS=windows go test -ccompiles,gofmtclean. The diff also adds the missing trailing newline at end of file, which is whygofmt -lpreviously listed it.Summary by CodeRabbit