test: micro-optimize slow suites and CLI command setup

This commit is contained in:
Peter Steinberger
2026-03-02 23:00:42 +00:00
parent ba5ae5b4f1
commit 2287d1ec13
7 changed files with 259 additions and 164 deletions

View File

@@ -1,5 +1,5 @@
import { Command } from "commander";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { ConfigFileSnapshot, OpenClawConfig } from "../config/types.js";
/**
@@ -61,27 +61,24 @@ function setSnapshotOnce(snapshot: ConfigFileSnapshot) {
}
let registerConfigCli: typeof import("./config-cli.js").registerConfigCli;
let sharedProgram: Command;
async function runConfigCommand(args: string[]) {
const program = new Command();
program.exitOverride();
registerConfigCli(program);
await program.parseAsync(args, { from: "user" });
await sharedProgram.parseAsync(args, { from: "user" });
}
describe("config cli", () => {
beforeAll(async () => {
({ registerConfigCli } = await import("./config-cli.js"));
sharedProgram = new Command();
sharedProgram.exitOverride();
registerConfigCli(sharedProgram);
});
beforeEach(() => {
vi.clearAllMocks();
});
afterEach(() => {
vi.restoreAllMocks();
});
describe("config set - issue #6070", () => {
it("preserves existing config keys when setting a new value", async () => {
const resolved: OpenClawConfig = {