Skip to content

Commit ad61912

Browse files
author
Peter Steinberger
committed
Fix doctor completion cache plugin loading
1 parent 7621208 commit ad61912

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { spawnSync } from "node:child_process";
2+
import { describe, expect, it, vi } from "vitest";
3+
4+
vi.mock("node:child_process", () => ({
5+
spawnSync: vi.fn(() => ({ status: 0 })),
6+
}));
7+
8+
vi.mock("../infra/openclaw-root.js", () => ({
9+
resolveOpenClawPackageRoot: vi.fn(async () => "/tmp/openclaw-root"),
10+
}));
11+
12+
vi.mock("../cli/completion-runtime.js", async () => {
13+
const actual = await vi.importActual<typeof import("../cli/completion-runtime.js")>(
14+
"../cli/completion-runtime.js",
15+
);
16+
return {
17+
...actual,
18+
completionCacheExists: vi.fn(async () => false),
19+
resolveShellFromEnv: vi.fn(() => "powershell"),
20+
};
21+
});
22+
23+
describe("doctor completion", () => {
24+
it("skips plugin command registration when doctor writes completion cache", async () => {
25+
const { ensureCompletionCacheExists } = await import("./doctor-completion.js");
26+
const { COMPLETION_SKIP_PLUGIN_COMMANDS_ENV } = await import("../cli/completion-runtime.js");
27+
28+
await expect(ensureCompletionCacheExists()).resolves.toBe(true);
29+
30+
expect(spawnSync).toHaveBeenCalledWith(
31+
process.execPath,
32+
["/tmp/openclaw-root/openclaw.mjs", "completion", "--write-state"],
33+
expect.objectContaining({
34+
cwd: "/tmp/openclaw-root",
35+
env: expect.objectContaining({
36+
[COMPLETION_SKIP_PLUGIN_COMMANDS_ENV]: "1",
37+
}),
38+
}),
39+
);
40+
});
41+
});

src/commands/doctor-completion.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from "node:path";
33
import { resolveCliName } from "../cli/cli-name.js";
44
import {
55
completionCacheExists,
6+
COMPLETION_SKIP_PLUGIN_COMMANDS_ENV,
67
installCompletion,
78
isCompletionInstalled,
89
resolveCompletionCachePath,
@@ -32,7 +33,10 @@ async function generateCompletionCache(): Promise<boolean> {
3233
const binPath = path.join(root, "openclaw.mjs");
3334
const result = spawnSync(process.execPath, [binPath, "completion", "--write-state"], {
3435
cwd: root,
35-
env: process.env,
36+
env: {
37+
...process.env,
38+
[COMPLETION_SKIP_PLUGIN_COMMANDS_ENV]: "1",
39+
},
3640
encoding: "utf-8",
3741
timeout: COMPLETION_CACHE_WRITE_TIMEOUT_MS,
3842
});

0 commit comments

Comments
 (0)