Skip to content

Commit 8bcd0f3

Browse files
authored
fix(tests): isolate locale and device identity from host environment (#715)
Fix test isolation for locale-sensitive attachment size formatting and gateway-client device identity state.\n\nValidation: local build, Shared tests, Tray tests; GitHub checks green.\n\nCo-authored-by: Copilot <[email protected]>
1 parent d23f8ca commit 8bcd0f3

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

‎src/OpenClaw.Shared/ChatAttachment.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23
using System.IO;
34
using System.Text.Json.Serialization;
45
using System.Threading.Tasks;
@@ -126,8 +127,8 @@ private static string FormatBytes(long bytes)
126127
return bytes switch
127128
{
128129
< 1024 => $"{bytes} B",
129-
< 1024 * 1024 => $"{bytes / 1024.0:F1} KB",
130-
_ => $"{bytes / (1024.0 * 1024.0):F1} MB"
130+
< 1024 * 1024 => $"{(bytes / 1024.0).ToString("F1", CultureInfo.InvariantCulture)} KB",
131+
_ => $"{(bytes / (1024.0 * 1024.0)).ToString("F1", CultureInfo.InvariantCulture)} MB"
131132
};
132133
}
133134
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,17 +479,19 @@ public void OperatorConnect_FreshDevice_RequestsBootstrapHandoffScopes()
479479
[Fact]
480480
public void OperatorConnect_FreshBootstrapDevice_StartsWithV2Signature()
481481
{
482-
var helper = new GatewayClientTestHelper(tokenIsBootstrapToken: true);
483-
helper.SetDeviceTokenForTest(null);
482+
var tmpDir = Path.Combine(Path.GetTempPath(), $"oca-gw-test-{Guid.NewGuid():N}");
483+
Directory.CreateDirectory(tmpDir);
484+
var helper = new GatewayClientTestHelper(tokenIsBootstrapToken: true, identityPath: tmpDir);
484485

485486
Assert.True(helper.Client.UseV2Signature);
486487
}
487488

488489
[Fact]
489490
public void OperatorConnect_SharedTokenDevice_StartsWithV3Signature()
490491
{
491-
var helper = new GatewayClientTestHelper(tokenIsBootstrapToken: false);
492-
helper.SetDeviceTokenForTest(null);
492+
var tmpDir = Path.Combine(Path.GetTempPath(), $"oca-gw-test-{Guid.NewGuid():N}");
493+
Directory.CreateDirectory(tmpDir);
494+
var helper = new GatewayClientTestHelper(tokenIsBootstrapToken: false, identityPath: tmpDir);
493495

494496
Assert.False(helper.Client.UseV2Signature);
495497
}

0 commit comments

Comments
 (0)