CLI: widen nodes list legacy fallback

This commit is contained in:
LXT 2026-03-20 22:11:56 +08:00
parent 3aa6d28c40
commit e2602f6807
2 changed files with 30 additions and 0 deletions

View File

@ -127,6 +127,7 @@ function shouldFallbackToPairList(error: unknown): boolean {
return (
message.includes("unknown method") ||
message.includes("method not found") ||
message.includes("invalid request") ||
message.includes("not implemented") ||
message.includes("unsupported")
);

View File

@ -182,6 +182,35 @@ describe("cli program (nodes basics)", () => {
expect(output).toContain("One");
});
it("runs nodes list and falls back to node.pair.list on invalid request", async () => {
callGateway.mockImplementation(async (...args: unknown[]) => {
const opts = (args[0] ?? {}) as { method?: string };
if (opts.method === "node.pair.list") {
return {
pending: [],
paired: [
{
nodeId: "n1",
displayName: "One",
remoteIp: "10.0.0.1",
lastConnectedAtMs: Date.now() - 1_000,
},
],
};
}
if (opts.method === "node.list") {
throw new Error("invalid request");
}
return { ok: true };
});
await runProgram(["nodes", "list"]);
const output = getRuntimeOutput();
expect(output).toContain("Pending: 0 · Paired: 1");
expect(output).toContain("One");
});
it("fails clearly for nodes list --connected when node.list is unavailable", async () => {
callGateway.mockImplementation(async (...args: unknown[]) => {
const opts = (args[0] ?? {}) as { method?: string };