Skip to content

Commit 725ea5a

Browse files
shanselmanCopilot
andcommitted
test: verify COM wrapper runtime switch matrix
Co-authored-by: Copilot App <[email protected]>
1 parent 5216838 commit 725ea5a

1 file changed

Lines changed: 93 additions & 14 deletions

File tree

‎tests/OpenClaw.Tray.Tests/InstallerIssAssertionTests.cs‎

Lines changed: 93 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Diagnostics;
2+
13
namespace OpenClaw.Tray.Tests;
24

35
/// <summary>
@@ -198,28 +200,105 @@ public void LocalInstallerBuild_UsesOneIdentitySwitchAndValidatesPayloadMarker()
198200
Assert.DoesNotContain("<DevBuild>true</DevBuild>", project);
199201
}
200202

201-
[Fact]
202-
public void ProductionBuild_DisablesComWrapperDiagnosticsWithoutChangingDevBuilds()
203+
[Theory]
204+
[InlineData("Release", false, false, "win-x64", true)]
205+
[InlineData("Release", false, true, "win-x64", true)]
206+
[InlineData("Release", false, false, "win-arm64", true)]
207+
[InlineData("Release", false, true, "win-arm64", true)]
208+
[InlineData("Release", true, false, "win-x64", false)]
209+
[InlineData("Debug", false, false, "win-x64", false)]
210+
public async Task ComWrapperDiagnosticsSwitch_EvaluatesOnlyForProductionBuilds(
211+
string configuration,
212+
bool devBuild,
213+
bool packageMsix,
214+
string runtimeIdentifier,
215+
bool expected)
203216
{
217+
var repositoryRoot = TestRepositoryPaths.GetRepositoryRoot();
204218
var projectPath = Path.Combine(
205-
TestRepositoryPaths.GetRepositoryRoot(),
219+
repositoryRoot,
206220
"src",
207221
"OpenClaw.Tray.WinUI",
208222
"OpenClaw.Tray.WinUI.csproj");
209-
var project = System.Xml.Linq.XDocument.Load(projectPath);
210-
var option = Assert.Single(
211-
project.Descendants("RuntimeHostConfigurationOption"),
212-
element =>
223+
var startInfo = new ProcessStartInfo("dotnet")
224+
{
225+
WorkingDirectory = repositoryRoot,
226+
RedirectStandardOutput = true,
227+
RedirectStandardError = true,
228+
UseShellExecute = false,
229+
CreateNoWindow = true,
230+
};
231+
startInfo.ArgumentList.Add("msbuild");
232+
startInfo.ArgumentList.Add(projectPath);
233+
startInfo.ArgumentList.Add("-nologo");
234+
startInfo.ArgumentList.Add("-v:q");
235+
startInfo.ArgumentList.Add("-getItem:RuntimeHostConfigurationOption");
236+
startInfo.ArgumentList.Add($"-p:Configuration={configuration}");
237+
startInfo.ArgumentList.Add($"-p:DevBuild={devBuild.ToString().ToLowerInvariant()}");
238+
startInfo.ArgumentList.Add($"-p:PackageMsix={packageMsix.ToString().ToLowerInvariant()}");
239+
startInfo.ArgumentList.Add($"-p:RuntimeIdentifier={runtimeIdentifier}");
240+
241+
using var process = Process.Start(startInfo);
242+
Assert.NotNull(process);
243+
var standardOutput = process.StandardOutput.ReadToEndAsync();
244+
var standardError = process.StandardError.ReadToEndAsync();
245+
using var timeout = new CancellationTokenSource(TimeSpan.FromMinutes(2));
246+
try
247+
{
248+
await process.WaitForExitAsync(timeout.Token);
249+
}
250+
catch (OperationCanceledException) when (timeout.IsCancellationRequested)
251+
{
252+
if (!process.HasExited)
253+
process.Kill(entireProcessTree: true);
254+
await process.WaitForExitAsync();
255+
256+
throw new TimeoutException(
257+
$"MSBuild evaluation timed out.{Environment.NewLine}" +
258+
$"Standard output:{Environment.NewLine}{await standardOutput}{Environment.NewLine}" +
259+
$"Standard error:{Environment.NewLine}{await standardError}");
260+
}
261+
262+
var output = await standardOutput;
263+
var error = await standardError;
264+
265+
Assert.True(
266+
process.ExitCode == 0,
267+
$"MSBuild evaluation failed with exit code {process.ExitCode}.{Environment.NewLine}" +
268+
$"Standard output:{Environment.NewLine}{output}{Environment.NewLine}" +
269+
$"Standard error:{Environment.NewLine}{error}");
270+
271+
JsonNode? result;
272+
try
273+
{
274+
result = JsonNode.Parse(output);
275+
}
276+
catch (System.Text.Json.JsonException exception)
277+
{
278+
throw new InvalidDataException(
279+
$"MSBuild evaluation returned invalid JSON:{Environment.NewLine}{output}",
280+
exception);
281+
}
282+
283+
var options = result?["Items"]?["RuntimeHostConfigurationOption"]?.AsArray();
284+
Assert.NotNull(options);
285+
var matchingOptions = options
286+
.Where(option =>
213287
string.Equals(
214-
element.Attribute("Include")?.Value,
288+
option?["Identity"]?.GetValue<string>(),
215289
"System.Diagnostics.Debugger.IsSupported",
216-
StringComparison.Ordinal));
290+
StringComparison.Ordinal))
291+
.ToArray();
292+
293+
if (!expected)
294+
{
295+
Assert.Empty(matchingOptions);
296+
return;
297+
}
217298

218-
Assert.Equal("false", option.Attribute("Value")?.Value);
219-
Assert.Equal("true", option.Attribute("Trim")?.Value);
220-
Assert.Equal(
221-
"'$(Configuration)' == 'Release' and '$(DevBuild)' != 'true'",
222-
option.Parent?.Attribute("Condition")?.Value);
299+
var matchingOption = Assert.Single(matchingOptions);
300+
Assert.Equal("false", matchingOption?["Value"]?.GetValue<string>());
301+
Assert.Equal("true", matchingOption?["Trim"]?.GetValue<string>());
223302
}
224303

225304
[Fact]

0 commit comments

Comments
 (0)