|
| 1 | +// Codex Supervisor tests cover lightweight CLI discovery and lazy registration. |
| 2 | +import { Command } from "commander"; |
| 3 | +import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api"; |
| 4 | +import { describe, expect, it, vi } from "vitest"; |
| 5 | + |
| 6 | +const mocks = vi.hoisted(() => ({ |
| 7 | + registerCodexSupervisorCli: vi.fn(), |
| 8 | +})); |
| 9 | + |
| 10 | +vi.mock("./src/cli.js", () => ({ |
| 11 | + registerCodexSupervisorCli: mocks.registerCodexSupervisorCli, |
| 12 | +})); |
| 13 | + |
| 14 | +import entry from "./cli-metadata.js"; |
| 15 | + |
| 16 | +describe("codex-supervisor CLI metadata entry", () => { |
| 17 | + it("advertises codex and loads its registrar only when invoked", async () => { |
| 18 | + const registerCli = vi.fn(); |
| 19 | + const api = createTestPluginApi({ |
| 20 | + id: "codex-supervisor", |
| 21 | + name: "Codex Supervisor", |
| 22 | + registerCli, |
| 23 | + }); |
| 24 | + |
| 25 | + entry.register(api); |
| 26 | + |
| 27 | + expect(registerCli).toHaveBeenCalledWith(expect.any(Function), { |
| 28 | + descriptors: [ |
| 29 | + { |
| 30 | + name: "codex", |
| 31 | + description: "Inspect Codex sessions across the Gateway and paired nodes", |
| 32 | + hasSubcommands: true, |
| 33 | + }, |
| 34 | + ], |
| 35 | + }); |
| 36 | + expect(mocks.registerCodexSupervisorCli).not.toHaveBeenCalled(); |
| 37 | + |
| 38 | + const registrar = registerCli.mock.calls[0]?.[0]; |
| 39 | + if (typeof registrar !== "function") { |
| 40 | + throw new Error("expected codex-supervisor CLI registrar"); |
| 41 | + } |
| 42 | + const program = new Command(); |
| 43 | + await registrar({ |
| 44 | + program, |
| 45 | + parentPath: [], |
| 46 | + config: {}, |
| 47 | + workspaceDir: undefined, |
| 48 | + logger: api.logger, |
| 49 | + }); |
| 50 | + |
| 51 | + expect(mocks.registerCodexSupervisorCli).toHaveBeenCalledWith(program); |
| 52 | + }); |
| 53 | +}); |
0 commit comments