|
| 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 | +}); |
0 commit comments