Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions tests/OpenClaw.Tray.Tests/NodeCapabilityGatingTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using OpenClaw.Shared;
using OpenClawTray.Services;

namespace OpenClaw.Tray.Tests;
Expand Down Expand Up @@ -144,4 +145,80 @@ public void DefaultOnCapabilities_OnlyDisabledWhenExplicitlySetToFalse()
Assert.False(NodeCapabilityGating.ShouldRegisterBrowserProxy(s));
Assert.False(NodeCapabilityGating.ShouldRegisterSystemRun(s));
}

// ── GetLocalNodeCapabilities ──────────────────────────────────────────────

[Fact]
public void GetLocalNodeCapabilities_NullNodes_ReturnsNull()
{
Assert.Null(NodeCapabilityGating.GetLocalNodeCapabilities(null, "device-1"));
}

[Fact]
public void GetLocalNodeCapabilities_EmptyNodes_ReturnsNull()
{
Assert.Null(NodeCapabilityGating.GetLocalNodeCapabilities([], "device-1"));
}

[Fact]
public void GetLocalNodeCapabilities_NullDeviceId_ReturnsNull()
{
var nodes = new[] { new GatewayNodeInfo { NodeId = "device-1" } };
Assert.Null(NodeCapabilityGating.GetLocalNodeCapabilities(nodes, null));
}

[Fact]
public void GetLocalNodeCapabilities_EmptyDeviceId_ReturnsNull()
{
var nodes = new[] { new GatewayNodeInfo { NodeId = "device-1" } };
Assert.Null(NodeCapabilityGating.GetLocalNodeCapabilities(nodes, ""));
}

[Fact]
public void GetLocalNodeCapabilities_NoMatchingNode_ReturnsNull()
{
var nodes = new[]
{
new GatewayNodeInfo { NodeId = "device-1", Capabilities = ["canvas"] },
new GatewayNodeInfo { NodeId = "device-2", Capabilities = ["screen"] },
};
Assert.Null(NodeCapabilityGating.GetLocalNodeCapabilities(nodes, "device-99"));
}

[Fact]
public void GetLocalNodeCapabilities_MatchingNode_ReturnsCapabilities()
{
var nodes = new[]
{
new GatewayNodeInfo { NodeId = "device-1", Capabilities = ["canvas", "screen"] },
new GatewayNodeInfo { NodeId = "device-2", Capabilities = ["location"] },
};
var result = NodeCapabilityGating.GetLocalNodeCapabilities(nodes, "device-1");
Assert.NotNull(result);
Assert.Equal(new[] { "canvas", "screen" }, result);
}

[Fact]
public void GetLocalNodeCapabilities_MatchingNodeCaseInsensitive_ReturnsCapabilities()
{
var nodes = new[]
{
new GatewayNodeInfo { NodeId = "Device-ABC", Capabilities = ["canvas"] },
};
var result = NodeCapabilityGating.GetLocalNodeCapabilities(nodes, "device-abc");
Assert.NotNull(result);
Assert.Equal(new[] { "canvas" }, result);
}

[Fact]
public void GetLocalNodeCapabilities_NodeWithNoCapabilities_ReturnsEmptyList()
{
var nodes = new[]
{
new GatewayNodeInfo { NodeId = "device-1", Capabilities = [] },
};
var result = NodeCapabilityGating.GetLocalNodeCapabilities(nodes, "device-1");
Assert.NotNull(result);
Assert.Empty(result);
}
}