mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 05:21:36 +00:00
perf(test): reduce hot-suite import and setup overhead
This commit is contained in:
@@ -27,14 +27,20 @@ vi.mock("../runtime.js", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
|
||||
function buildProgram() {
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
return program;
|
||||
}
|
||||
|
||||
describe("cron cli", () => {
|
||||
it("trims model and thinking on cron add", { timeout: 60_000 }, async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(
|
||||
[
|
||||
@@ -68,10 +74,7 @@ describe("cron cli", () => {
|
||||
it("defaults isolated cron add to announce delivery", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(
|
||||
[
|
||||
@@ -98,10 +101,7 @@ describe("cron cli", () => {
|
||||
it("infers sessionTarget from payload when --session is omitted", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(
|
||||
["cron", "add", "--name", "Main reminder", "--cron", "* * * * *", "--system-event", "hi"],
|
||||
@@ -129,10 +129,7 @@ describe("cron cli", () => {
|
||||
it("supports --keep-after-run on cron add", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(
|
||||
[
|
||||
@@ -159,10 +156,7 @@ describe("cron cli", () => {
|
||||
it("sends agent id on cron add", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(
|
||||
[
|
||||
@@ -190,10 +184,7 @@ describe("cron cli", () => {
|
||||
it("omits empty model and thinking on cron edit", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(
|
||||
["cron", "edit", "job-1", "--message", "hello", "--model", " ", "--thinking", " "],
|
||||
@@ -212,10 +203,7 @@ describe("cron cli", () => {
|
||||
it("trims model and thinking on cron edit", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(
|
||||
[
|
||||
@@ -244,10 +232,7 @@ describe("cron cli", () => {
|
||||
it("sets and clears agent id on cron edit", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(["cron", "edit", "job-1", "--agent", " Ops ", "--message", "hello"], {
|
||||
from: "user",
|
||||
@@ -269,10 +254,7 @@ describe("cron cli", () => {
|
||||
it("allows model/thinking updates without --message", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(["cron", "edit", "job-1", "--model", "opus", "--thinking", "low"], {
|
||||
from: "user",
|
||||
@@ -291,10 +273,7 @@ describe("cron cli", () => {
|
||||
it("updates delivery settings without requiring --message", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(
|
||||
["cron", "edit", "job-1", "--deliver", "--channel", "telegram", "--to", "19098680"],
|
||||
@@ -319,10 +298,7 @@ describe("cron cli", () => {
|
||||
it("supports --no-deliver on cron edit", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(["cron", "edit", "job-1", "--no-deliver"], { from: "user" });
|
||||
|
||||
@@ -338,10 +314,7 @@ describe("cron cli", () => {
|
||||
it("does not include undefined delivery fields when updating message", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
// Update message without delivery flags - should NOT include undefined delivery fields
|
||||
await program.parseAsync(["cron", "edit", "job-1", "--message", "Updated message"], {
|
||||
@@ -376,10 +349,7 @@ describe("cron cli", () => {
|
||||
it("includes delivery fields when explicitly provided with message", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
// Update message AND delivery - should include both
|
||||
await program.parseAsync(
|
||||
@@ -416,10 +386,7 @@ describe("cron cli", () => {
|
||||
it("includes best-effort delivery when provided with message", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(
|
||||
["cron", "edit", "job-1", "--message", "Updated message", "--best-effort-deliver"],
|
||||
@@ -442,10 +409,7 @@ describe("cron cli", () => {
|
||||
it("includes no-best-effort delivery when provided with message", async () => {
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const { registerCronCli } = await import("./cron-cli.js");
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerCronCli(program);
|
||||
const program = buildProgram();
|
||||
|
||||
await program.parseAsync(
|
||||
["cron", "edit", "job-1", "--message", "Updated message", "--no-best-effort-deliver"],
|
||||
|
||||
@@ -79,6 +79,17 @@ vi.mock("../runtime.js", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { resolveOpenClawPackageRoot } = await import("../infra/openclaw-root.js");
|
||||
const { readConfigFileSnapshot, writeConfigFile } = await import("../config/config.js");
|
||||
const { checkUpdateStatus, fetchNpmTagVersion, resolveNpmChannelTag } =
|
||||
await import("../infra/update-check.js");
|
||||
const { runCommandWithTimeout } = await import("../process/exec.js");
|
||||
const { runDaemonRestart } = await import("./daemon-cli.js");
|
||||
const { defaultRuntime } = await import("../runtime.js");
|
||||
const { updateCommand, registerUpdateCli, updateStatusCommand, updateWizardCommand } =
|
||||
await import("./update-cli.js");
|
||||
|
||||
describe("update-cli", () => {
|
||||
const baseSnapshot = {
|
||||
valid: true,
|
||||
@@ -100,13 +111,8 @@ describe("update-cli", () => {
|
||||
});
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
const { resolveOpenClawPackageRoot } = await import("../infra/openclaw-root.js");
|
||||
const { readConfigFileSnapshot } = await import("../config/config.js");
|
||||
const { checkUpdateStatus, fetchNpmTagVersion, resolveNpmChannelTag } =
|
||||
await import("../infra/update-check.js");
|
||||
const { runCommandWithTimeout } = await import("../process/exec.js");
|
||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue(process.cwd());
|
||||
vi.mocked(readConfigFileSnapshot).mockResolvedValue(baseSnapshot);
|
||||
vi.mocked(fetchNpmTagVersion).mockResolvedValue({
|
||||
@@ -154,18 +160,12 @@ describe("update-cli", () => {
|
||||
});
|
||||
|
||||
it("exports updateCommand and registerUpdateCli", async () => {
|
||||
const { updateCommand, registerUpdateCli, updateWizardCommand } =
|
||||
await import("./update-cli.js");
|
||||
expect(typeof updateCommand).toBe("function");
|
||||
expect(typeof registerUpdateCli).toBe("function");
|
||||
expect(typeof updateWizardCommand).toBe("function");
|
||||
}, 20_000);
|
||||
|
||||
it("updateCommand runs update and outputs result", async () => {
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { defaultRuntime } = await import("../runtime.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
|
||||
const mockResult: UpdateRunResult = {
|
||||
status: "ok",
|
||||
mode: "git",
|
||||
@@ -193,9 +193,6 @@ describe("update-cli", () => {
|
||||
});
|
||||
|
||||
it("updateStatusCommand prints table output", async () => {
|
||||
const { defaultRuntime } = await import("../runtime.js");
|
||||
const { updateStatusCommand } = await import("./update-cli.js");
|
||||
|
||||
await updateStatusCommand({ json: false });
|
||||
|
||||
const logs = vi.mocked(defaultRuntime.log).mock.calls.map((call) => call[0]);
|
||||
@@ -203,9 +200,6 @@ describe("update-cli", () => {
|
||||
});
|
||||
|
||||
it("updateStatusCommand emits JSON", async () => {
|
||||
const { defaultRuntime } = await import("../runtime.js");
|
||||
const { updateStatusCommand } = await import("./update-cli.js");
|
||||
|
||||
await updateStatusCommand({ json: true });
|
||||
|
||||
const last = vi.mocked(defaultRuntime.log).mock.calls.at(-1)?.[0];
|
||||
@@ -215,9 +209,6 @@ describe("update-cli", () => {
|
||||
});
|
||||
|
||||
it("defaults to dev channel for git installs when unset", async () => {
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
|
||||
vi.mocked(runGatewayUpdate).mockResolvedValue({
|
||||
status: "ok",
|
||||
mode: "git",
|
||||
@@ -240,11 +231,6 @@ describe("update-cli", () => {
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
const { resolveOpenClawPackageRoot } = await import("../infra/openclaw-root.js");
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { checkUpdateStatus } = await import("../infra/update-check.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
|
||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue(tempDir);
|
||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
||||
root: tempDir,
|
||||
@@ -275,10 +261,6 @@ describe("update-cli", () => {
|
||||
});
|
||||
|
||||
it("uses stored beta channel when configured", async () => {
|
||||
const { readConfigFileSnapshot } = await import("../config/config.js");
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
|
||||
vi.mocked(readConfigFileSnapshot).mockResolvedValue({
|
||||
...baseSnapshot,
|
||||
config: { update: { channel: "beta" } },
|
||||
@@ -305,13 +287,6 @@ describe("update-cli", () => {
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
const { resolveOpenClawPackageRoot } = await import("../infra/openclaw-root.js");
|
||||
const { readConfigFileSnapshot } = await import("../config/config.js");
|
||||
const { resolveNpmChannelTag } = await import("../infra/update-check.js");
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
const { checkUpdateStatus } = await import("../infra/update-check.js");
|
||||
|
||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue(tempDir);
|
||||
vi.mocked(readConfigFileSnapshot).mockResolvedValue({
|
||||
...baseSnapshot,
|
||||
@@ -358,10 +333,6 @@ describe("update-cli", () => {
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
const { resolveOpenClawPackageRoot } = await import("../infra/openclaw-root.js");
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
|
||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue(tempDir);
|
||||
vi.mocked(runGatewayUpdate).mockResolvedValue({
|
||||
status: "ok",
|
||||
@@ -380,10 +351,6 @@ describe("update-cli", () => {
|
||||
});
|
||||
|
||||
it("updateCommand outputs JSON when --json is set", async () => {
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { defaultRuntime } = await import("../runtime.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
|
||||
const mockResult: UpdateRunResult = {
|
||||
status: "ok",
|
||||
mode: "git",
|
||||
@@ -409,10 +376,6 @@ describe("update-cli", () => {
|
||||
});
|
||||
|
||||
it("updateCommand exits with error on failure", async () => {
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { defaultRuntime } = await import("../runtime.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
|
||||
const mockResult: UpdateRunResult = {
|
||||
status: "error",
|
||||
mode: "git",
|
||||
@@ -430,10 +393,6 @@ describe("update-cli", () => {
|
||||
});
|
||||
|
||||
it("updateCommand restarts daemon by default", async () => {
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { runDaemonRestart } = await import("./daemon-cli.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
|
||||
const mockResult: UpdateRunResult = {
|
||||
status: "ok",
|
||||
mode: "git",
|
||||
@@ -450,10 +409,6 @@ describe("update-cli", () => {
|
||||
});
|
||||
|
||||
it("updateCommand skips restart when --no-restart is set", async () => {
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { runDaemonRestart } = await import("./daemon-cli.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
|
||||
const mockResult: UpdateRunResult = {
|
||||
status: "ok",
|
||||
mode: "git",
|
||||
@@ -469,11 +424,6 @@ describe("update-cli", () => {
|
||||
});
|
||||
|
||||
it("updateCommand skips success message when restart does not run", async () => {
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { runDaemonRestart } = await import("./daemon-cli.js");
|
||||
const { defaultRuntime } = await import("../runtime.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
|
||||
const mockResult: UpdateRunResult = {
|
||||
status: "ok",
|
||||
mode: "git",
|
||||
@@ -492,9 +442,6 @@ describe("update-cli", () => {
|
||||
});
|
||||
|
||||
it("updateCommand validates timeout option", async () => {
|
||||
const { defaultRuntime } = await import("../runtime.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
|
||||
vi.mocked(defaultRuntime.error).mockClear();
|
||||
vi.mocked(defaultRuntime.exit).mockClear();
|
||||
|
||||
@@ -505,10 +452,6 @@ describe("update-cli", () => {
|
||||
});
|
||||
|
||||
it("persists update channel when --channel is set", async () => {
|
||||
const { writeConfigFile } = await import("../config/config.js");
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
|
||||
const mockResult: UpdateRunResult = {
|
||||
status: "ok",
|
||||
mode: "git",
|
||||
@@ -537,13 +480,6 @@ describe("update-cli", () => {
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
const { resolveOpenClawPackageRoot } = await import("../infra/openclaw-root.js");
|
||||
const { resolveNpmChannelTag } = await import("../infra/update-check.js");
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { defaultRuntime } = await import("../runtime.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
const { checkUpdateStatus } = await import("../infra/update-check.js");
|
||||
|
||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue(tempDir);
|
||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
||||
root: tempDir,
|
||||
@@ -590,13 +526,6 @@ describe("update-cli", () => {
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
const { resolveOpenClawPackageRoot } = await import("../infra/openclaw-root.js");
|
||||
const { resolveNpmChannelTag } = await import("../infra/update-check.js");
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { defaultRuntime } = await import("../runtime.js");
|
||||
const { updateCommand } = await import("./update-cli.js");
|
||||
const { checkUpdateStatus } = await import("../infra/update-check.js");
|
||||
|
||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue(tempDir);
|
||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
||||
root: tempDir,
|
||||
@@ -634,9 +563,6 @@ describe("update-cli", () => {
|
||||
});
|
||||
|
||||
it("updateWizardCommand requires a TTY", async () => {
|
||||
const { defaultRuntime } = await import("../runtime.js");
|
||||
const { updateWizardCommand } = await import("./update-cli.js");
|
||||
|
||||
setTty(false);
|
||||
vi.mocked(defaultRuntime.error).mockClear();
|
||||
vi.mocked(defaultRuntime.exit).mockClear();
|
||||
@@ -656,10 +582,6 @@ describe("update-cli", () => {
|
||||
setTty(true);
|
||||
process.env.OPENCLAW_GIT_DIR = tempDir;
|
||||
|
||||
const { checkUpdateStatus } = await import("../infra/update-check.js");
|
||||
const { runGatewayUpdate } = await import("../infra/update-runner.js");
|
||||
const { updateWizardCommand } = await import("./update-cli.js");
|
||||
|
||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
||||
root: "/test/path",
|
||||
installKind: "package",
|
||||
|
||||
Reference in New Issue
Block a user