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 statusCommand = vi.fn();
|
||||
const configureCommand = vi.fn();
|
||||
const loginWeb = vi.fn();
|
||||
const callGateway = vi.fn();
|
||||
|
||||
@@ -16,6 +17,7 @@ const runtime = {
|
||||
|
||||
vi.mock("../commands/send.js", () => ({ sendCommand }));
|
||||
vi.mock("../commands/status.js", () => ({ statusCommand }));
|
||||
vi.mock("../commands/configure.js", () => ({ configureCommand }));
|
||||
vi.mock("../runtime.js", () => ({ defaultRuntime: runtime }));
|
||||
vi.mock("../provider-web.js", () => ({
|
||||
loginWeb,
|
||||
@@ -49,7 +51,13 @@ describe("cli program", () => {
|
||||
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: [] });
|
||||
const program = buildProgram();
|
||||
runtime.log.mockClear();
|
||||
|
||||
@@ -232,6 +232,7 @@ export function buildProgram() {
|
||||
|
||||
program
|
||||
.command("configure")
|
||||
.alias("config")
|
||||
.description(
|
||||
"Interactive wizard to update models, providers, skills, and gateway",
|
||||
)
|
||||
|
||||
@@ -176,7 +176,7 @@ async function promptGatewayConfig(
|
||||
...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 localProbe = await probeGatewayReachable({
|
||||
url: localUrl,
|
||||
token: process.env.CLAWDBOT_GATEWAY_TOKEN,
|
||||
token: baseConfig.gateway?.auth?.token ?? process.env.CLAWDBOT_GATEWAY_TOKEN,
|
||||
password:
|
||||
baseConfig.gateway?.auth?.password ??
|
||||
process.env.CLAWDBOT_GATEWAY_PASSWORD,
|
||||
|
||||
@@ -194,6 +194,8 @@ export async function probeGatewayReachable(params: {
|
||||
password: params.password,
|
||||
method: "health",
|
||||
timeoutMs,
|
||||
clientName: "clawdbot-probe",
|
||||
mode: "probe",
|
||||
});
|
||||
return { ok: true };
|
||||
} catch (err) {
|
||||
|
||||
@@ -92,9 +92,10 @@ export async function callGateway<T = unknown>(
|
||||
client.stop();
|
||||
stop(err as Error);
|
||||
}
|
||||
},
|
||||
onClose: (code, reason) => {
|
||||
}, onClose: (code, reason) => {
|
||||
if (settled || ignoreClose) return;
|
||||
ignoreClose = true;
|
||||
client.stop();
|
||||
stop(new Error(`gateway closed (${code}): ${reason}`));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -119,7 +119,9 @@ export class GatewayClient {
|
||||
this.opts.onHelloOk?.(helloOk);
|
||||
})
|
||||
.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");
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user