import { afterEach, describe, expect, it, vi } from "vitest"; const readFileSyncMock = vi.hoisted(() => vi.fn()); vi.mock("node:fs", async () => { const actual = await vi.importActual("node:fs"); const base = ("default" in actual ? actual.default : actual) as Record; return { ...actual, default: { ...base, readFileSync: readFileSyncMock, }, readFileSync: readFileSyncMock, }; }); vi.mock("../channels/registry.js", () => ({ CHAT_CHANNEL_ORDER: ["telegram", "discord"], })); async function loadModule() { return await import("./channel-options.js"); } describe("resolveCliChannelOptions", () => { afterEach(() => { vi.resetModules(); vi.clearAllMocks(); }); it("uses precomputed startup metadata when available", async () => { readFileSyncMock.mockReturnValue( JSON.stringify({ channelOptions: ["cached", "telegram", "cached"] }), ); const mod = await loadModule(); expect(mod.resolveCliChannelOptions()).toEqual(["cached", "telegram"]); }); it("falls back to core channel order when metadata is missing", async () => { readFileSyncMock.mockImplementation(() => { throw new Error("ENOENT"); }); const mod = await loadModule(); expect(mod.resolveCliChannelOptions()).toEqual(["telegram", "discord"]); }); it("ignores external catalog env during CLI bootstrap", async () => { process.env.OPENCLAW_PLUGIN_CATALOG_PATHS = "/tmp/plugins-catalog.json"; readFileSyncMock.mockReturnValue(JSON.stringify({ channelOptions: ["cached", "telegram"] })); const mod = await loadModule(); expect(mod.resolveCliChannelOptions()).toEqual(["cached", "telegram"]); delete process.env.OPENCLAW_PLUGIN_CATALOG_PATHS; }); });