test: trim CLI and doctor hotspots

This commit is contained in:
Peter Steinberger
2026-04-17 09:23:13 +01:00
parent 199bb1fe05
commit a861da41b5
10 changed files with 280 additions and 522 deletions

View File

@@ -7,7 +7,6 @@ import {
resolveConfiguredModelRef,
resolveHooksGmailModel,
} from "../agents/model-selection.js";
import { runChannelPluginStartupMaintenance } from "../channels/plugins/lifecycle-startup.js";
import { formatCliCommand } from "../cli/command-format.js";
import {
maybeRepairLegacyOAuthProfileIds,
@@ -61,6 +60,7 @@ import { buildGatewayConnectionDetails } from "../gateway/call.js";
import type { RuntimeEnv } from "../runtime.js";
import { note } from "../terminal/note.js";
import { shortenHomePath } from "../utils.js";
import { maybeRunDoctorStartupChannelMaintenance } from "./doctor-startup-channel-maintenance.js";
import type { FlowContribution } from "./types.js";
export type DoctorFlowMode = "local" | "remote";
@@ -294,18 +294,11 @@ async function runGatewayServicesHealth(ctx: DoctorHealthFlowContext): Promise<v
}
async function runStartupChannelMaintenanceHealth(ctx: DoctorHealthFlowContext): Promise<void> {
if (!ctx.prompter.shouldRepair) {
return;
}
await runChannelPluginStartupMaintenance({
await maybeRunDoctorStartupChannelMaintenance({
cfg: ctx.cfg,
env: process.env,
log: {
info: (message) => ctx.runtime.log(message),
warn: (message) => ctx.runtime.error(message),
},
trigger: "doctor-fix",
logPrefix: "doctor",
runtime: ctx.runtime,
shouldRepair: ctx.prompter.shouldRepair,
});
}

View File

@@ -0,0 +1,58 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { maybeRunDoctorStartupChannelMaintenance } from "./doctor-startup-channel-maintenance.js";
const runChannelPluginStartupMaintenance = vi.hoisted(() => vi.fn());
vi.mock("../channels/plugins/lifecycle-startup.js", () => ({
runChannelPluginStartupMaintenance,
}));
describe("doctor startup channel maintenance", () => {
beforeEach(() => {
runChannelPluginStartupMaintenance.mockClear();
});
it("runs Matrix startup migration during repair flows", async () => {
const cfg = {
channels: {
matrix: {
homeserver: "https://matrix.example.org",
userId: "@bot:example.org",
accessToken: "tok-123",
},
},
};
const runtime = { log: vi.fn(), error: vi.fn() };
await maybeRunDoctorStartupChannelMaintenance({
cfg,
env: { OPENCLAW_TEST: "1" },
runtime,
shouldRepair: true,
});
expect(runChannelPluginStartupMaintenance).toHaveBeenCalledTimes(1);
expect(runChannelPluginStartupMaintenance).toHaveBeenCalledWith(
expect.objectContaining({
cfg,
env: { OPENCLAW_TEST: "1" },
trigger: "doctor-fix",
logPrefix: "doctor",
log: expect.objectContaining({
info: expect.any(Function),
warn: expect.any(Function),
}),
}),
);
});
it("skips startup migration outside repair flows", async () => {
await maybeRunDoctorStartupChannelMaintenance({
cfg: { channels: { matrix: {} } },
runtime: { log: vi.fn(), error: vi.fn() },
shouldRepair: false,
});
expect(runChannelPluginStartupMaintenance).not.toHaveBeenCalled();
});
});

View File

@@ -0,0 +1,28 @@
import { runChannelPluginStartupMaintenance } from "../channels/plugins/lifecycle-startup.js";
import type { OpenClawConfig } from "../config/types.openclaw.js";
type DoctorStartupMaintenanceRuntime = {
error: (message: string) => void;
log: (message: string) => void;
};
export async function maybeRunDoctorStartupChannelMaintenance(params: {
cfg: OpenClawConfig;
env?: NodeJS.ProcessEnv;
runtime: DoctorStartupMaintenanceRuntime;
shouldRepair: boolean;
}): Promise<void> {
if (!params.shouldRepair) {
return;
}
await runChannelPluginStartupMaintenance({
cfg: params.cfg,
env: params.env ?? process.env,
log: {
info: (message) => params.runtime.log(message),
warn: (message) => params.runtime.error(message),
},
trigger: "doctor-fix",
logPrefix: "doctor",
});
}