@@ -31,22 +31,24 @@ namespace OpenClaw.Tray.UITests;
3131/// </summary>
3232public sealed class UIThreadFixture : IDisposable
3333{
34- // Match OpenClaw.Tray.WinUI.csproj's Microsoft.WindowsAppSDK package version
35- // (1.8). The bootstrapper resolves a system-installed
36- // Microsoft.WindowsAppRuntime.1.8 framework MSIX (stable channel = empty version
34+ // Match the Microsoft.WindowsAppSDK package's runtime major/minor. The
35+ // bootstrapper resolves a system-installed Microsoft.WindowsAppRuntime.2.0
36+ // framework MSIX (stable channel = empty version
3737 // tag). On dev machines and on CI the runtime is installed out-of-band — see
3838 // .github/workflows/ci.yml ("Install WindowsAppRuntime") and the README setup
3939 // notes. Self-contained deployment was tried but doesn't survive the xunit
4040 // testhost: the testhost.exe lives in the .NET SDK directory, so the SDK's
4141 // P/Invoke-based auto-initializer can't probe the test bin folder.
42- private const uint WinAppSdkMajorMinor = 0x00010008 ;
42+ private const uint WinAppSdkMajorMinor = 0x00020000 ;
4343 private const string WinAppSdkVersionTag = "" ;
44+ private const int DefaultStartupTimeoutSeconds = 90 ;
4445
4546 private static int s_bootstrapInitialized ; // 0 = no, 1 = yes
4647
4748 private readonly Thread _uiThread ;
4849 private readonly ManualResetEventSlim _ready = new ( false ) ;
4950 private Exception ? _startupError ;
51+ private volatile string _startupPhase = "not started" ;
5052
5153 /// <summary>
5254 /// True when env var SLOW_UI_TESTS=1. Window stays visible, tests insert
@@ -84,9 +86,20 @@ public UIThreadFixture()
8486 _uiThread . SetApartmentState ( ApartmentState . STA ) ;
8587 _uiThread . Start ( ) ;
8688
87- // Wait up to 30s for Application.Start + Window setup to signal ready.
88- if ( ! _ready . Wait ( TimeSpan . FromSeconds ( 30 ) ) )
89- throw new InvalidOperationException ( "UIThreadFixture failed to initialize within 30s" ) ;
89+ // Wait for Application.Start + Window setup to signal ready. CI can be
90+ // slow on first WinAppSDK activation, so keep the default generous but
91+ // overrideable when debugging.
92+ var timeoutSeconds = int . TryParse (
93+ Environment . GetEnvironmentVariable ( "OPENCLAW_UI_FIXTURE_TIMEOUT_SECONDS" ) ,
94+ out var configuredTimeoutSeconds ) && configuredTimeoutSeconds > 0
95+ ? configuredTimeoutSeconds
96+ : DefaultStartupTimeoutSeconds ;
97+ if ( ! _ready . Wait ( TimeSpan . FromSeconds ( timeoutSeconds ) ) )
98+ {
99+ var threadState = _uiThread . IsAlive ? _uiThread . ThreadState . ToString ( ) : "stopped" ;
100+ throw new InvalidOperationException (
101+ $ "UIThreadFixture failed to initialize within { timeoutSeconds } s; phase='{ _startupPhase } ', threadState='{ threadState } '") ;
102+ }
90103 if ( _startupError != null )
91104 throw new InvalidOperationException ( "UIThreadFixture initialization failed" , _startupError ) ;
92105 }
@@ -137,6 +150,8 @@ private void UIThreadProc()
137150 {
138151 try
139152 {
153+ _startupPhase = "initializing Windows App SDK bootstrap" ;
154+
140155 // Initialize WinAppSDK runtime (unpackaged process).
141156 if ( Interlocked . Exchange ( ref s_bootstrapInitialized , 1 ) == 0 )
142157 {
@@ -145,17 +160,22 @@ private void UIThreadProc()
145160
146161 // Application.Start blocks the calling thread until Application.Current.Exit().
147162 // The lambda runs once, on this same thread, with a live dispatcher.
163+ _startupPhase = "starting WinUI Application" ;
148164 Application . Start ( p =>
149165 {
150166 try
151167 {
168+ _startupPhase = "creating TestApp" ;
152169 var app = new TestApp ( ) ; // ctor stashes itself as Application.Current
153170 // Application.Resources can only be touched once the COM object
154171 // is fully wired; safe by the time we reach here (post-ctor).
172+ _startupPhase = "merging app resources" ;
155173 app . MergeStandardResources ( ) ;
156174
175+ _startupPhase = "getting dispatcher" ;
157176 Dispatcher = DispatcherQueue . GetForCurrentThread ( ) ;
158177
178+ _startupPhase = "creating hidden test window" ;
159179 Container = new Grid { Padding = new Microsoft . UI . Xaml . Thickness ( 24 ) } ;
160180 TestWindow = new Window
161181 {
@@ -173,14 +193,17 @@ private void UIThreadProc()
173193 catch { /* best-effort sizing */ }
174194 }
175195
196+ _startupPhase = "activating test window" ;
176197 TestWindow . Activate ( ) ;
177198
178199 if ( ! IsSlow )
179200 {
180201 // Default: hide the window so CI runs are silent.
202+ _startupPhase = "hiding test window" ;
181203 TryHide ( TestWindow ) ;
182204 }
183205
206+ _startupPhase = "ready" ;
184207 _ready . Set ( ) ;
185208 }
186209 catch ( Exception ex )
0 commit comments