Skip to content

Commit 4351d6a

Browse files
authored
fix(pairing): allow node bootstrap startup (#600)
1 parent 5aeb8f6 commit 4351d6a

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

src/OpenClaw.Tray.WinUI/Services/StartupSetupState.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ public static bool CanStartNodeGateway(SettingsManager settings, string dataPath
7979
return HasStoredNodeDeviceToken(dataPath);
8080
}
8181

82+
internal static bool HasBootstrapGatewayRecord(GatewayRegistry? registry)
83+
{
84+
var active = registry?.GetActive();
85+
return !string.IsNullOrWhiteSpace(active?.BootstrapToken);
86+
}
87+
8288
public static bool RequiresSetup(SettingsManager settings, string dataPath) =>
8389
RequiresSetup(settings, dataPath, registry: null);
8490

@@ -91,7 +97,8 @@ public static bool RequiresSetup(SettingsManager settings, string dataPath, Gate
9197

9298
if (settings.EnableNodeMode)
9399
{
94-
return !HasStoredNodeDeviceToken(dataPath);
100+
return !HasStoredNodeDeviceToken(dataPath)
101+
&& !HasBootstrapGatewayRecord(registry);
95102
}
96103

97104
if (registry is not null

tests/OpenClaw.Tray.Tests/StartupSetupStateTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,40 @@ public void RequiresSetup_PreservesNodeModePrecedence_WhenRegistryHasExternalGat
229229
Assert.True(StartupSetupState.RequiresSetup(settings, temp.Path, registry));
230230
}
231231

232+
[Fact]
233+
public void RequiresSetup_ReturnsFalse_WhenNodeModeHasActiveBootstrapGateway()
234+
{
235+
using var temp = TempSettings.Create();
236+
var settings = new SettingsManager(temp.Path) { EnableNodeMode = true };
237+
var registry = new GatewayRegistry(temp.Path);
238+
registry.AddOrUpdate(new GatewayRecord
239+
{
240+
Id = "bootstrap-gateway",
241+
Url = "wss://remote.example.com",
242+
BootstrapToken = "bootstrap-token"
243+
});
244+
registry.SetActive("bootstrap-gateway");
245+
246+
Assert.False(StartupSetupState.RequiresSetup(settings, temp.Path, registry));
247+
Assert.False(StartupSetupState.CanStartNodeGateway(settings, temp.Path));
248+
}
249+
250+
[Fact]
251+
public void RequiresSetup_ReturnsTrue_WhenNodeModeHasInactiveBootstrapGateway()
252+
{
253+
using var temp = TempSettings.Create();
254+
var settings = new SettingsManager(temp.Path) { EnableNodeMode = true };
255+
var registry = new GatewayRegistry(temp.Path);
256+
registry.AddOrUpdate(new GatewayRecord
257+
{
258+
Id = "inactive-bootstrap-gateway",
259+
Url = "wss://remote.example.com",
260+
BootstrapToken = "bootstrap-token"
261+
});
262+
263+
Assert.True(StartupSetupState.RequiresSetup(settings, temp.Path, registry));
264+
}
265+
232266
[Fact]
233267
public async Task ClassifyAsync_ReturnsAppOwnedLocalWsl_WhenDistroAndLocalRegistryEvidenceExist()
234268
{

0 commit comments

Comments
 (0)