fix(discovery): lazy-load bonjour; add tests

This commit is contained in:
Peter Steinberger
2025-12-13 03:55:32 +00:00
parent 47b4d245aa
commit 4b608117a2
5 changed files with 273 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ const sendCommand = vi.fn();
const statusCommand = vi.fn();
const loginWeb = vi.fn();
const startWebChatServer = vi.fn(async () => ({ port: 18788 }));
const callGateway = vi.fn();
const runtime = {
log: vi.fn(),
@@ -19,6 +20,9 @@ vi.mock("../runtime.js", () => ({ defaultRuntime: runtime }));
vi.mock("../provider-web.js", () => ({
loginWeb,
}));
vi.mock("../gateway/call.js", () => ({
callGateway,
}));
vi.mock("../webchat/server.js", () => ({
startWebChatServer,
getWebChatServer: () => null,
@@ -57,4 +61,34 @@ describe("cli program", () => {
JSON.stringify({ port: 18788, basePath: "/", host: "127.0.0.1" }),
);
});
it("runs nodes list and calls node.pair.list", async () => {
callGateway.mockResolvedValue({ pending: [], paired: [] });
const program = buildProgram();
runtime.log.mockClear();
await program.parseAsync(["nodes", "list"], { from: "user" });
expect(callGateway).toHaveBeenCalledWith(
expect.objectContaining({
method: "node.pair.list",
}),
);
expect(runtime.log).toHaveBeenCalledWith("Pending: 0 · Paired: 0");
});
it("runs nodes approve and calls node.pair.approve", async () => {
callGateway.mockResolvedValue({
requestId: "r1",
node: { nodeId: "n1", token: "t1" },
});
const program = buildProgram();
runtime.log.mockClear();
await program.parseAsync(["nodes", "approve", "r1"], { from: "user" });
expect(callGateway).toHaveBeenCalledWith(
expect.objectContaining({
method: "node.pair.approve",
params: { requestId: "r1" },
}),
);
expect(runtime.log).toHaveBeenCalled();
});
});