Skip to content

Commit 24a8108

Browse files
ranjeshjCopilot
andcommitted
Fix tray UI test runtime bootstrap
Align the UI test WinAppSDK bootstrap/runtime install with the Microsoft.WindowsAppSDK package version and add fixture startup diagnostics. Co-authored-by: Copilot <[email protected]>
1 parent bfbd554 commit 24a8108

2 files changed

Lines changed: 34 additions & 11 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ jobs:
158158
--logger trx;LogFileName=OpenClaw.Tray.IntegrationTests.trx"
159159
160160
# UI tests need a real visual tree AND a system-registered WindowsAppRuntime
161-
# framework MSIX — the test fixture calls Bootstrap.Initialize(1.8, stable),
161+
# framework MSIX — the test fixture calls Bootstrap.Initialize(2.0, stable),
162162
# which looks up the framework package by identity. The hosted windows-2025
163163
# runner image doesn't preinstall it, so we install it explicitly here.
164-
# Version pinned to match Microsoft.WindowsAppSDK 1.8.260101001 in the csprojs.
165-
- name: Install WindowsAppRuntime 1.8
164+
# Version pinned to match Microsoft.WindowsAppSDK 2.0.1 in the csprojs.
165+
- name: Install WindowsAppRuntime 2.0.1
166166
shell: pwsh
167167
run: |
168-
$url = "https://aka.ms/windowsappsdk/1.8/1.8.260101001/windowsappruntimeinstall-x64.exe"
168+
$url = "https://aka.ms/windowsappsdk/2.0/2.0.1/windowsappruntimeinstall-x64.exe"
169169
$exe = "$env:RUNNER_TEMP\WindowsAppRuntimeInstall.exe"
170170
Invoke-WebRequest -Uri $url -OutFile $exe
171171
& $exe --quiet

‎tests/OpenClaw.Tray.UITests/UIThreadFixture.cs‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,24 @@ namespace OpenClaw.Tray.UITests;
3131
/// </summary>
3232
public 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

Comments
 (0)