Files
openclaw/src/gateway/node-catalog.test.ts
2026-03-29 23:14:22 +01:00

114 lines
3.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { createKnownNodeCatalog, getKnownNode, listKnownNodes } from "./node-catalog.js";
describe("gateway/node-catalog", () => {
it("filters paired nodes by active node token instead of sticky historical roles", () => {
const catalog = createKnownNodeCatalog({
pairedDevices: [
{
deviceId: "legacy-mac",
publicKey: "legacy-public-key",
displayName: "Peter's Mac Studio",
clientId: "clawdbot-macos",
role: "node",
roles: ["node"],
tokens: {
node: {
token: "legacy-token",
role: "node",
scopes: [],
createdAtMs: 1,
revokedAtMs: 2,
},
},
createdAtMs: 1,
approvedAtMs: 1,
},
{
deviceId: "current-mac",
publicKey: "current-public-key",
displayName: "Peter's Mac Studio",
clientId: "openclaw-macos",
role: "node",
roles: ["node"],
tokens: {
node: {
token: "current-token",
role: "node",
scopes: [],
createdAtMs: 1,
},
},
createdAtMs: 1,
approvedAtMs: 1,
},
],
connectedNodes: [],
});
expect(listKnownNodes(catalog).map((node) => node.nodeId)).toEqual(["current-mac"]);
});
it("builds one merged node view for paired and live state", () => {
const connectedAtMs = 123;
const catalog = createKnownNodeCatalog({
pairedDevices: [
{
deviceId: "mac-1",
publicKey: "public-key",
displayName: "Mac",
clientId: "openclaw-macos",
clientMode: "node",
role: "node",
roles: ["node"],
remoteIp: "100.0.0.10",
tokens: {
node: {
token: "current-token",
role: "node",
scopes: [],
createdAtMs: 1,
},
},
createdAtMs: 1,
approvedAtMs: 99,
},
],
connectedNodes: [
{
nodeId: "mac-1",
connId: "conn-1",
client: {} as never,
clientId: "openclaw-macos",
clientMode: "node",
displayName: "Mac",
platform: "darwin",
version: "1.2.3",
caps: ["screen"],
commands: ["screen.snapshot"],
remoteIp: "100.0.0.11",
pathEnv: "/usr/bin:/bin",
connectedAtMs,
},
],
});
expect(getKnownNode(catalog, "mac-1")).toEqual(
expect.objectContaining({
nodeId: "mac-1",
displayName: "Mac",
clientId: "openclaw-macos",
clientMode: "node",
remoteIp: "100.0.0.11",
caps: ["screen"],
commands: ["screen.snapshot"],
pathEnv: "/usr/bin:/bin",
approvedAtMs: 99,
connectedAtMs,
paired: true,
connected: true,
}),
);
});
});