Skip to content

Commit 5aeb8f6

Browse files
authored
fix(pairing): bootstrap setup codes as node first
1 parent 7f19e81 commit 5aeb8f6

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

‎src/OpenClaw.Connection/GatewayClientFactory.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public IGatewayClientLifecycle Create(
1919
credential.Token,
2020
logger,
2121
tokenIsBootstrapToken: credential.IsBootstrapToken,
22+
bootstrapPairAsNode: credential.IsBootstrapToken,
2223
identityPath: identityPath);
2324

2425
return new GatewayClientLifecycleAdapter(client);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System.Reflection;
2+
using OpenClaw.Shared;
3+
using Xunit;
4+
5+
namespace OpenClaw.Connection.Tests;
6+
7+
public sealed class GatewayClientFactoryTests
8+
{
9+
[Fact]
10+
public void Create_BootstrapCredential_PairsAsNode()
11+
{
12+
var tempDir = Path.Combine(Path.GetTempPath(), "openclaw-gateway-factory-" + Guid.NewGuid().ToString("N"));
13+
Directory.CreateDirectory(tempDir);
14+
15+
try
16+
{
17+
using var lifecycle = new GatewayClientFactory().Create(
18+
"ws://127.0.0.1:18789",
19+
new GatewayCredential("bootstrap-token", IsBootstrapToken: true, Source: "test"),
20+
tempDir,
21+
NullLogger.Instance);
22+
23+
Assert.Equal("node", GetConnectRole(lifecycle.DataClient));
24+
}
25+
finally
26+
{
27+
Directory.Delete(tempDir, recursive: true);
28+
}
29+
}
30+
31+
[Fact]
32+
public void Create_SharedCredential_PairsAsOperator()
33+
{
34+
var tempDir = Path.Combine(Path.GetTempPath(), "openclaw-gateway-factory-" + Guid.NewGuid().ToString("N"));
35+
Directory.CreateDirectory(tempDir);
36+
37+
try
38+
{
39+
using var lifecycle = new GatewayClientFactory().Create(
40+
"ws://127.0.0.1:18789",
41+
new GatewayCredential("shared-token", IsBootstrapToken: false, Source: "test"),
42+
tempDir,
43+
NullLogger.Instance);
44+
45+
Assert.Equal("operator", GetConnectRole(lifecycle.DataClient));
46+
}
47+
finally
48+
{
49+
Directory.Delete(tempDir, recursive: true);
50+
}
51+
}
52+
53+
private static string GetConnectRole(OpenClawGatewayClient client)
54+
{
55+
var method = typeof(OpenClawGatewayClient).GetMethod(
56+
"GetConnectRole",
57+
BindingFlags.Instance | BindingFlags.NonPublic);
58+
59+
Assert.NotNull(method);
60+
return Assert.IsType<string>(method.Invoke(client, null));
61+
}
62+
}

0 commit comments

Comments
 (0)