mirror of https://github.com/openclaw/openclaw.git
test: tighten shared node match coverage
This commit is contained in:
parent
73c2edbc0c
commit
dd54b6f4c7
|
|
@ -5,6 +5,7 @@ describe("shared/node-match", () => {
|
|||
it("normalizes node keys by lowercasing and collapsing separators", () => {
|
||||
expect(normalizeNodeKey(" Mac Studio! ")).toBe("mac-studio");
|
||||
expect(normalizeNodeKey("---PI__Node---")).toBe("pi-node");
|
||||
expect(normalizeNodeKey("###")).toBe("");
|
||||
});
|
||||
|
||||
it("matches candidates by node id, remote ip, normalized name, and long prefix", () => {
|
||||
|
|
@ -16,6 +17,7 @@ describe("shared/node-match", () => {
|
|||
expect(resolveNodeMatches(nodes, "mac-abcdef")).toEqual([nodes[0]]);
|
||||
expect(resolveNodeMatches(nodes, "100.0.0.2")).toEqual([nodes[1]]);
|
||||
expect(resolveNodeMatches(nodes, "mac studio")).toEqual([nodes[0]]);
|
||||
expect(resolveNodeMatches(nodes, " Mac---Studio!! ")).toEqual([nodes[0]]);
|
||||
expect(resolveNodeMatches(nodes, "pi-456")).toEqual([nodes[1]]);
|
||||
expect(resolveNodeMatches(nodes, "pi")).toEqual([]);
|
||||
expect(resolveNodeMatches(nodes, " ")).toEqual([]);
|
||||
|
|
@ -33,6 +35,18 @@ describe("shared/node-match", () => {
|
|||
).toBe("ios-live");
|
||||
});
|
||||
|
||||
it("falls back to raw ambiguous matches when none of them are connected", () => {
|
||||
expect(() =>
|
||||
resolveNodeIdFromCandidates(
|
||||
[
|
||||
{ nodeId: "ios-a", displayName: "iPhone", connected: false },
|
||||
{ nodeId: "ios-b", displayName: "iPhone", connected: false },
|
||||
],
|
||||
"iphone",
|
||||
),
|
||||
).toThrow(/ambiguous node: iphone.*matches: iPhone, iPhone/);
|
||||
});
|
||||
|
||||
it("throws clear unknown and ambiguous node errors", () => {
|
||||
expect(() =>
|
||||
resolveNodeIdFromCandidates(
|
||||
|
|
@ -56,4 +70,13 @@ describe("shared/node-match", () => {
|
|||
|
||||
expect(() => resolveNodeIdFromCandidates([], "")).toThrow(/node required/);
|
||||
});
|
||||
|
||||
it("lists remote ips in unknown-node errors when display names are missing", () => {
|
||||
expect(() =>
|
||||
resolveNodeIdFromCandidates(
|
||||
[{ nodeId: "mac-123", remoteIp: "100.0.0.1" }, { nodeId: "pi-456" }],
|
||||
"nope",
|
||||
),
|
||||
).toThrow(/unknown node: nope.*known: 100.0.0.1, pi-456/);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue