Skip to content

Commit 5a3d6c0

Browse files
authored
Merge 0555bfa into c0514bd
2 parents c0514bd + 0555bfa commit 5a3d6c0

6 files changed

Lines changed: 56 additions & 8 deletions

File tree

‎src/OpenClaw.Tray.WinUI/Chat/ChatUsageFormatter.cs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using OpenClaw.Chat;
22
using System;
33
using System.Collections.Generic;
4+
using System.Globalization;
45

56
namespace OpenClawTray.Chat;
67

@@ -93,13 +94,13 @@ private static string FormatCount(long value)
9394
{
9495
var millions = value / 1_000_000d;
9596
return millions % 1d == 0d
96-
? $"{millions:0}M"
97-
: $"{millions:0.#}M";
97+
? millions.ToString("0", CultureInfo.InvariantCulture) + "M"
98+
: millions.ToString("0.#", CultureInfo.InvariantCulture) + "M";
9899
}
99100

100101
if (value >= 1_000)
101-
return $"{value / 1_000d:0.0}K";
102+
return (value / 1_000d).ToString("0.0", CultureInfo.InvariantCulture) + "K";
102103

103-
return value.ToString();
104+
return value.ToString(CultureInfo.InvariantCulture);
104105
}
105106
}

‎tests/Directory.Build.props‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<TargetFramework>net10.0</TargetFramework>
1212
<ImplicitUsings>enable</ImplicitUsings>
1313
<Nullable>enable</Nullable>
14+
<IsTestProject>true</IsTestProject>
1415
<IsPackable>false</IsPackable>
1516
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1617
<OpenClawLibsodiumVersion>1.0.20.1</OpenClawLibsodiumVersion>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Xunit;
2+
3+
namespace OpenClaw.Shared.Tests;
4+
5+
[CollectionDefinition("AppVersionInfo", DisableParallelization = true)]
6+
public sealed class AppVersionInfoTestCollection
7+
{
8+
public const string Name = "AppVersionInfo";
9+
}

‎tests/OpenClaw.Shared.Tests/AppVersionInfoTests.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace OpenClaw.Shared.Tests;
1010
/// at startup. Tests use <see cref="AppVersionInfo.TestOverride"/> to inject a
1111
/// deterministic version string without relying on the running host process.
1212
/// </summary>
13+
[Collection(AppVersionInfoTestCollection.Name)]
1314
public sealed class AppVersionInfoTests : IDisposable
1415
{
1516
public AppVersionInfoTests()

‎tests/OpenClaw.Shared.Tests/Mxc/MxcPolicyBuilderTests.cs‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ public void ForSystemRun_DocumentsReadOnly_AppearsInReadonlyPaths()
112112

113113
Assert.NotNull(policy.Filesystem!.ReadonlyPaths);
114114
Assert.Empty(policy.Filesystem.ReadwritePaths!);
115+
var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
115116
Assert.Contains(policy.Filesystem.ReadonlyPaths!,
116-
p => p.EndsWith("Documents", StringComparison.OrdinalIgnoreCase));
117+
p => string.Equals(p, documentsPath, StringComparison.OrdinalIgnoreCase));
117118
}
118119

119120
[Fact]
@@ -123,8 +124,9 @@ public void ForSystemRun_DesktopReadWrite_AppearsInReadwritePaths()
123124
var policy = MxcPolicyBuilder.ForSystemRun(settings, "C:\\s");
124125

125126
Assert.NotNull(policy.Filesystem!.ReadwritePaths);
127+
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
126128
Assert.Contains(policy.Filesystem.ReadwritePaths!,
127-
p => p.EndsWith("Desktop", StringComparison.OrdinalIgnoreCase));
129+
p => string.Equals(p, desktopPath, StringComparison.OrdinalIgnoreCase));
128130
}
129131

130132
[Fact]
@@ -133,8 +135,9 @@ public void ForSystemRun_DownloadsReadOnly_AppearsInReadonlyPaths()
133135
var settings = new SettingsData { SandboxDownloadsAccess = SandboxFolderAccess.ReadOnly };
134136
var policy = MxcPolicyBuilder.ForSystemRun(settings, "C:\\s");
135137

138+
var downloadsPath = GetExpectedDownloadsPath();
136139
Assert.Contains(policy.Filesystem!.ReadonlyPaths!,
137-
p => p.EndsWith("Downloads", StringComparison.OrdinalIgnoreCase));
140+
p => string.Equals(p, downloadsPath, StringComparison.OrdinalIgnoreCase));
138141
}
139142

140143
[Fact]
@@ -273,4 +276,36 @@ public void ForSystemRun_CustomFolder_NotOverlappingDeny_StillGranted()
273276

274277
Assert.Contains("D:\\code\\my-project", policy.Filesystem!.ReadwritePaths!);
275278
}
279+
280+
private static string GetExpectedDownloadsPath()
281+
{
282+
var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
283+
return ResolveKnownFolderDownloads() ?? Path.Combine(userProfile, "Downloads");
284+
}
285+
286+
private static readonly Guid s_folderIdDownloads =
287+
new("374DE290-123F-4565-9164-39C4925E467B");
288+
289+
private static string? ResolveKnownFolderDownloads()
290+
{
291+
if (!OperatingSystem.IsWindows()) return null;
292+
try
293+
{
294+
var hr = SHGetKnownFolderPath(s_folderIdDownloads, 0, IntPtr.Zero, out var ptr);
295+
if (hr != 0 || ptr == IntPtr.Zero) return null;
296+
try { return System.Runtime.InteropServices.Marshal.PtrToStringUni(ptr); }
297+
finally { System.Runtime.InteropServices.Marshal.FreeCoTaskMem(ptr); }
298+
}
299+
catch
300+
{
301+
return null;
302+
}
303+
}
304+
305+
[System.Runtime.InteropServices.DllImport("shell32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode, ExactSpelling = true)]
306+
private static extern int SHGetKnownFolderPath(
307+
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStruct)] Guid rfid,
308+
uint dwFlags,
309+
IntPtr hToken,
310+
out IntPtr ppszPath);
276311
}

‎tests/OpenClaw.Shared.Tests/WindowsNodeClientTests.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace OpenClaw.Shared.Tests;
1414

15+
[Collection(AppVersionInfoTestCollection.Name)]
1516
public class WindowsNodeClientTests
1617
{
1718
[Theory]
@@ -423,7 +424,7 @@ public void HandleResponse_NotPairedError_WithUnsafeRequestId_DoesNotSurfaceRequ
423424
Assert.Single(pairingEvents);
424425
Assert.Equal(PairingApprovalKind.DevicePair, pairingEvents[0].ApprovalKind);
425426
Assert.Null(pairingEvents[0].RequestId);
426-
Assert.DoesNotContain("bad", pairingEvents[0].Message);
427+
Assert.DoesNotContain("req-1 && bad", pairingEvents[0].Message);
427428
}
428429
finally
429430
{

0 commit comments

Comments
 (0)