fix(cli): add config alias and reduce probe noise
This commit is contained in:
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
|||||||
|
|
||||||
const sendCommand = vi.fn();
|
const sendCommand = vi.fn();
|
||||||
const statusCommand = vi.fn();
|
const statusCommand = vi.fn();
|
||||||
|
const configureCommand = vi.fn();
|
||||||
const loginWeb = vi.fn();
|
const loginWeb = vi.fn();
|
||||||
const callGateway = vi.fn();
|
const callGateway = vi.fn();
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ const runtime = {
|
|||||||
|
|
||||||
vi.mock("../commands/send.js", () => ({ sendCommand }));
|
vi.mock("../commands/send.js", () => ({ sendCommand }));
|
||||||
vi.mock("../commands/status.js", () => ({ statusCommand }));
|
vi.mock("../commands/status.js", () => ({ statusCommand }));
|
||||||
|
vi.mock("../commands/configure.js", () => ({ configureCommand }));
|
||||||
vi.mock("../runtime.js", () => ({ defaultRuntime: runtime }));
|
vi.mock("../runtime.js", () => ({ defaultRuntime: runtime }));
|
||||||
vi.mock("../provider-web.js", () => ({
|
vi.mock("../provider-web.js", () => ({
|
||||||
loginWeb,
|
loginWeb,
|
||||||
@@ -49,7 +51,13 @@ describe("cli program", () => {
|
|||||||
expect(statusCommand).toHaveBeenCalled();
|
expect(statusCommand).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("runs nodes list and calls node.pair.list", async () => {
|
it("runs config alias as configure", async () => {
|
||||||
|
const program = buildProgram();
|
||||||
|
await program.parseAsync(["config"], { from: "user" });
|
||||||
|
expect(configureCommand).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("runs nodes list and calls node.pair.list", async () => {
|
||||||
callGateway.mockResolvedValue({ pending: [], paired: [] });
|
callGateway.mockResolvedValue({ pending: [], paired: [] });
|
||||||
const program = buildProgram();
|
const program = buildProgram();
|
||||||
runtime.log.mockClear();
|
runtime.log.mockClear();
|
||||||
|
|||||||
@@ -232,6 +232,7 @@ export function buildProgram() {
|
|||||||
|
|
||||||
program
|
program
|
||||||
.command("configure")
|
.command("configure")
|
||||||
|
.alias("config")
|
||||||
.description(
|
.description(
|
||||||
"Interactive wizard to update models, providers, skills, and gateway",
|
"Interactive wizard to update models, providers, skills, and gateway",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ async function promptGatewayConfig(
|
|||||||
...next,
|
...next,
|
||||||
gateway: {
|
gateway: {
|
||||||
...next.gateway,
|
...next.gateway,
|
||||||
auth: { ...next.gateway?.auth, mode: "token" },
|
auth: { ...next.gateway?.auth, mode: "token", token: gatewayToken },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -453,7 +453,7 @@ export async function runConfigureWizard(
|
|||||||
const localUrl = "ws://127.0.0.1:18789";
|
const localUrl = "ws://127.0.0.1:18789";
|
||||||
const localProbe = await probeGatewayReachable({
|
const localProbe = await probeGatewayReachable({
|
||||||
url: localUrl,
|
url: localUrl,
|
||||||
token: process.env.CLAWDBOT_GATEWAY_TOKEN,
|
token: baseConfig.gateway?.auth?.token ?? process.env.CLAWDBOT_GATEWAY_TOKEN,
|
||||||
password:
|
password:
|
||||||
baseConfig.gateway?.auth?.password ??
|
baseConfig.gateway?.auth?.password ??
|
||||||
process.env.CLAWDBOT_GATEWAY_PASSWORD,
|
process.env.CLAWDBOT_GATEWAY_PASSWORD,
|
||||||
|
|||||||
@@ -194,6 +194,8 @@ export async function probeGatewayReachable(params: {
|
|||||||
password: params.password,
|
password: params.password,
|
||||||
method: "health",
|
method: "health",
|
||||||
timeoutMs,
|
timeoutMs,
|
||||||
|
clientName: "clawdbot-probe",
|
||||||
|
mode: "probe",
|
||||||
});
|
});
|
||||||
return { ok: true };
|
return { ok: true };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -92,9 +92,10 @@ export async function callGateway<T = unknown>(
|
|||||||
client.stop();
|
client.stop();
|
||||||
stop(err as Error);
|
stop(err as Error);
|
||||||
}
|
}
|
||||||
},
|
}, onClose: (code, reason) => {
|
||||||
onClose: (code, reason) => {
|
|
||||||
if (settled || ignoreClose) return;
|
if (settled || ignoreClose) return;
|
||||||
|
ignoreClose = true;
|
||||||
|
client.stop();
|
||||||
stop(new Error(`gateway closed (${code}): ${reason}`));
|
stop(new Error(`gateway closed (${code}): ${reason}`));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -119,7 +119,9 @@ export class GatewayClient {
|
|||||||
this.opts.onHelloOk?.(helloOk);
|
this.opts.onHelloOk?.(helloOk);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
logError(`gateway connect failed: ${String(err)}`);
|
const msg = `gateway connect failed: ${String(err)}`;
|
||||||
|
if (this.opts.mode === "probe") logDebug(msg);
|
||||||
|
else logError(msg);
|
||||||
this.ws?.close(1008, "connect failed");
|
this.ws?.close(1008, "connect failed");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user