fix(cli): keep update completion refresh lightweight

This commit is contained in:
Peter Steinberger
2026-04-27 08:23:44 +01:00
parent 1ee893bc5f
commit f427ddc220
7 changed files with 55 additions and 9 deletions

View File

@@ -106,4 +106,35 @@ describe("completion-cli write-state", () => {
await fs.rm(stateDir, { recursive: true, force: true });
await fs.rm(homeDir, { recursive: true, force: true });
});
it("can skip plugin command registration for update-triggered cache writes", async () => {
const [{ COMPLETION_SKIP_PLUGIN_COMMANDS_ENV }, { registerCompletionCli }] = await Promise.all([
import("./completion-runtime.js"),
import("./completion-cli.js"),
]);
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-completion-state-"));
const homeDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-completion-home-"));
process.env.OPENCLAW_STATE_DIR = stateDir;
process.env.HOME = homeDir;
process.env[COMPLETION_SKIP_PLUGIN_COMMANDS_ENV] = "1";
try {
const program = new Command();
program.name("openclaw");
registerCompletionCli(program);
await program.parseAsync(["completion", "--write-state"], { from: "user" });
expect(registerSubCliByNameMock).toHaveBeenCalledWith(program, "qa");
expect(registerPluginCliCommandsFromValidatedConfigMock).not.toHaveBeenCalled();
expect(await fs.readdir(path.join(stateDir, "completions"))).toEqual(
expect.arrayContaining(["openclaw.bash", "openclaw.fish", "openclaw.ps1", "openclaw.zsh"]),
);
} finally {
delete process.env[COMPLETION_SKIP_PLUGIN_COMMANDS_ENV];
await fs.rm(stateDir, { recursive: true, force: true });
await fs.rm(homeDir, { recursive: true, force: true });
}
});
});