mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 08:54:45 +00:00
test: trim CLI and doctor hotspots
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
58
src/flows/doctor-startup-channel-maintenance.test.ts
Normal file
58
src/flows/doctor-startup-channel-maintenance.test.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
28
src/flows/doctor-startup-channel-maintenance.ts
Normal file
28
src/flows/doctor-startup-channel-maintenance.ts
Normal 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",
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user