From eff092268a030d1551691e376357fe5315f37667 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 10 Jan 2026 23:39:30 +0100 Subject: [PATCH] fix(test): avoid update-cli import timeout --- src/cli/update-cli.test.ts | 11 ++++------- src/cli/update-cli.ts | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/cli/update-cli.test.ts b/src/cli/update-cli.test.ts index 9ac0901e6..8be638001 100644 --- a/src/cli/update-cli.test.ts +++ b/src/cli/update-cli.test.ts @@ -7,11 +7,10 @@ vi.mock("../infra/update-runner.js", () => ({ runGatewayUpdate: vi.fn(), })); -// Mock the doctor command to avoid loading heavy dependencies +// Mock doctor (heavy module; should not run in unit tests) vi.mock("../commands/doctor.js", () => ({ doctorCommand: vi.fn(), })); - // Mock the daemon-cli module vi.mock("./daemon-cli.js", () => ({ runDaemonRestart: vi.fn(), @@ -30,11 +29,9 @@ describe("update-cli", () => { it( "exports updateCommand and registerUpdateCli", async () => { - const { updateCommand, registerUpdateCli } = await import( - "./update-cli.js" - ); - expect(typeof updateCommand).toBe("function"); - expect(typeof registerUpdateCli).toBe("function"); + const { updateCommand, registerUpdateCli } = await import("./update-cli.js"); + expect(typeof updateCommand).toBe("function"); + expect(typeof registerUpdateCli).toBe("function"); }, 20_000, ); diff --git a/src/cli/update-cli.ts b/src/cli/update-cli.ts index 5e97b39ef..de4e88253 100644 --- a/src/cli/update-cli.ts +++ b/src/cli/update-cli.ts @@ -1,6 +1,5 @@ import type { Command } from "commander"; -import { doctorCommand } from "../commands/doctor.js"; import { resolveClawdbotPackageRoot } from "../infra/clawdbot-root.js"; import { runGatewayUpdate, @@ -9,7 +8,6 @@ import { import { defaultRuntime } from "../runtime.js"; import { formatDocsLink } from "../terminal/links.js"; import { theme } from "../terminal/theme.js"; -import { runDaemonRestart } from "./daemon-cli.js"; export type UpdateCommandOptions = { json?: boolean; @@ -157,12 +155,14 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise { defaultRuntime.log(theme.heading("Restarting daemon...")); } try { + const { runDaemonRestart } = await import("./daemon-cli.js"); const restarted = await runDaemonRestart(); if (!opts.json && restarted) { defaultRuntime.log(theme.success("Daemon restarted successfully.")); defaultRuntime.log(""); process.env.CLAWDBOT_UPDATE_IN_PROGRESS = "1"; try { + const { doctorCommand } = await import("../commands/doctor.js"); await doctorCommand(defaultRuntime, { nonInteractive: true }); } catch (err) { defaultRuntime.log(theme.warn(`Doctor failed: ${String(err)}`));