test: assert completion cache writes

This commit is contained in:
Shakker
2026-05-11 12:50:39 +01:00
parent 7a6dbffa05
commit 1eb42c68d9

View File

@@ -94,16 +94,21 @@ describe("completion-cli write-state", () => {
await program.parseAsync(["completion", "--write-state"], { from: "user" });
const cacheDir = path.join(stateDir, "completions");
expect(await fs.readdir(cacheDir)).toEqual(
expect.arrayContaining(["openclaw.bash", "openclaw.fish", "openclaw.ps1", "openclaw.zsh"]),
);
expect(registerSubCliByNameMock).toHaveBeenCalledWith(program, "qa", expect.any(Array), {
purpose: "completion",
});
expect((await fs.readdir(cacheDir)).sort()).toEqual([
"openclaw.bash",
"openclaw.fish",
"openclaw.ps1",
"openclaw.zsh",
]);
expect(registerSubCliByNameMock.mock.calls).toEqual([
[program, "qa", process.argv, { purpose: "completion" }],
]);
expect(registerPluginCliCommandsFromValidatedConfigMock).toHaveBeenCalledTimes(1);
expect(stderrWrites).toHaveBeenCalledWith(
expect.stringContaining("skipping subcommand `qa` while building completion cache"),
);
expect(stderrWrites.mock.calls).toEqual([
[
"[completion] skipping subcommand `qa` while building completion cache: qa scenario pack not found: qa/scenarios/index.md\n",
],
]);
await fs.rm(stateDir, { recursive: true, force: true });
await fs.rm(homeDir, { recursive: true, force: true });
@@ -128,13 +133,16 @@ describe("completion-cli write-state", () => {
await program.parseAsync(["completion", "--write-state"], { from: "user" });
expect(registerSubCliByNameMock).toHaveBeenCalledWith(program, "qa", expect.any(Array), {
purpose: "completion",
});
expect(registerSubCliByNameMock.mock.calls).toEqual([
[program, "qa", process.argv, { purpose: "completion" }],
]);
expect(registerPluginCliCommandsFromValidatedConfigMock).not.toHaveBeenCalled();
expect(await fs.readdir(path.join(stateDir, "completions"))).toEqual(
expect.arrayContaining(["openclaw.bash", "openclaw.fish", "openclaw.ps1", "openclaw.zsh"]),
);
expect((await fs.readdir(path.join(stateDir, "completions"))).sort()).toEqual([
"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 });