fix(test): avoid update-cli import timeout

This commit is contained in:
Peter Steinberger
2026-01-10 23:39:30 +01:00
parent b977e8a284
commit eff092268a
2 changed files with 6 additions and 9 deletions

View File

@@ -7,11 +7,10 @@ vi.mock("../infra/update-runner.js", () => ({
runGatewayUpdate: vi.fn(), 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", () => ({ vi.mock("../commands/doctor.js", () => ({
doctorCommand: vi.fn(), doctorCommand: vi.fn(),
})); }));
// Mock the daemon-cli module // Mock the daemon-cli module
vi.mock("./daemon-cli.js", () => ({ vi.mock("./daemon-cli.js", () => ({
runDaemonRestart: vi.fn(), runDaemonRestart: vi.fn(),
@@ -30,11 +29,9 @@ describe("update-cli", () => {
it( it(
"exports updateCommand and registerUpdateCli", "exports updateCommand and registerUpdateCli",
async () => { async () => {
const { updateCommand, registerUpdateCli } = await import( const { updateCommand, registerUpdateCli } = await import("./update-cli.js");
"./update-cli.js" expect(typeof updateCommand).toBe("function");
); expect(typeof registerUpdateCli).toBe("function");
expect(typeof updateCommand).toBe("function");
expect(typeof registerUpdateCli).toBe("function");
}, },
20_000, 20_000,
); );

View File

@@ -1,6 +1,5 @@
import type { Command } from "commander"; import type { Command } from "commander";
import { doctorCommand } from "../commands/doctor.js";
import { resolveClawdbotPackageRoot } from "../infra/clawdbot-root.js"; import { resolveClawdbotPackageRoot } from "../infra/clawdbot-root.js";
import { import {
runGatewayUpdate, runGatewayUpdate,
@@ -9,7 +8,6 @@ import {
import { defaultRuntime } from "../runtime.js"; import { defaultRuntime } from "../runtime.js";
import { formatDocsLink } from "../terminal/links.js"; import { formatDocsLink } from "../terminal/links.js";
import { theme } from "../terminal/theme.js"; import { theme } from "../terminal/theme.js";
import { runDaemonRestart } from "./daemon-cli.js";
export type UpdateCommandOptions = { export type UpdateCommandOptions = {
json?: boolean; json?: boolean;
@@ -157,12 +155,14 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
defaultRuntime.log(theme.heading("Restarting daemon...")); defaultRuntime.log(theme.heading("Restarting daemon..."));
} }
try { try {
const { runDaemonRestart } = await import("./daemon-cli.js");
const restarted = await runDaemonRestart(); const restarted = await runDaemonRestart();
if (!opts.json && restarted) { if (!opts.json && restarted) {
defaultRuntime.log(theme.success("Daemon restarted successfully.")); defaultRuntime.log(theme.success("Daemon restarted successfully."));
defaultRuntime.log(""); defaultRuntime.log("");
process.env.CLAWDBOT_UPDATE_IN_PROGRESS = "1"; process.env.CLAWDBOT_UPDATE_IN_PROGRESS = "1";
try { try {
const { doctorCommand } = await import("../commands/doctor.js");
await doctorCommand(defaultRuntime, { nonInteractive: true }); await doctorCommand(defaultRuntime, { nonInteractive: true });
} catch (err) { } catch (err) {
defaultRuntime.log(theme.warn(`Doctor failed: ${String(err)}`)); defaultRuntime.log(theme.warn(`Doctor failed: ${String(err)}`));