fix(regression): auto-enable directory channel selection

This commit is contained in:
Tak Hoffman
2026-03-27 23:45:18 -05:00
parent 811685b95f
commit 8539886cd8
2 changed files with 48 additions and 1 deletions

View File

@@ -14,6 +14,7 @@ function getRuntimeCapture(): CliRuntimeCapture {
const mocks = vi.hoisted(() => ({
loadConfig: vi.fn(),
applyPluginAutoEnable: vi.fn(),
writeConfigFile: vi.fn(),
resolveInstallableChannelPlugin: vi.fn(),
resolveMessageChannelSelection: vi.fn(),
@@ -26,6 +27,10 @@ vi.mock("../config/config.js", () => ({
writeConfigFile: mocks.writeConfigFile,
}));
vi.mock("../config/plugin-auto-enable.js", () => ({
applyPluginAutoEnable: mocks.applyPluginAutoEnable,
}));
vi.mock("../commands/channel-setup/channel-plugin-resolution.js", () => ({
resolveInstallableChannelPlugin: mocks.resolveInstallableChannelPlugin,
}));
@@ -53,6 +58,7 @@ describe("registerDirectoryCli", () => {
vi.clearAllMocks();
getRuntimeCapture().resetRuntimeCapture();
mocks.loadConfig.mockReturnValue({ channels: {} });
mocks.applyPluginAutoEnable.mockImplementation(({ config }) => ({ config, changes: [] }));
mocks.writeConfigFile.mockResolvedValue(undefined);
mocks.resolveChannelDefaultAccountId.mockReturnValue("default");
mocks.resolveMessageChannelSelection.mockResolvedValue({
@@ -108,4 +114,41 @@ describe("registerDirectoryCli", () => {
);
expect(getRuntimeCapture().defaultRuntime.error).not.toHaveBeenCalled();
});
it("uses the auto-enabled config snapshot for omitted channel selection", async () => {
const autoEnabledConfig = { channels: { whatsapp: {} }, plugins: { allow: ["whatsapp"] } };
const self = vi.fn().mockResolvedValue({ id: "self-2", name: "WhatsApp Bot" });
mocks.applyPluginAutoEnable.mockReturnValue({
config: autoEnabledConfig,
changes: ["whatsapp"],
});
mocks.resolveMessageChannelSelection.mockResolvedValue({
channel: "whatsapp",
configured: ["whatsapp"],
source: "single-configured",
});
mocks.getChannelPlugin.mockReturnValue({
id: "whatsapp",
directory: { self },
});
const program = new Command().name("openclaw");
registerDirectoryCli(program);
await program.parseAsync(["directory", "self", "--json"], { from: "user" });
expect(mocks.applyPluginAutoEnable).toHaveBeenCalledWith({
config: { channels: {} },
env: process.env,
});
expect(mocks.resolveMessageChannelSelection).toHaveBeenCalledWith({
cfg: autoEnabledConfig,
channel: null,
});
expect(self).toHaveBeenCalledWith(
expect.objectContaining({
cfg: autoEnabledConfig,
}),
);
});
});

View File

@@ -3,6 +3,7 @@ import { resolveChannelDefaultAccountId } from "../channels/plugins/helpers.js";
import { getChannelPlugin } from "../channels/plugins/index.js";
import { resolveInstallableChannelPlugin } from "../commands/channel-setup/channel-plugin-resolution.js";
import { loadConfig, writeConfigFile } from "../config/config.js";
import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js";
import { danger } from "../globals.js";
import { resolveMessageChannelSelection } from "../infra/outbound/channel-selection.js";
import { defaultRuntime } from "../runtime.js";
@@ -97,7 +98,10 @@ export function registerDirectoryCli(program: Command) {
.option("--json", "Output JSON", false);
const resolve = async (opts: { channel?: string; account?: string }) => {
let cfg = loadConfig();
let cfg = applyPluginAutoEnable({
config: loadConfig(),
env: process.env,
}).config;
const explicitChannel = opts.channel?.trim();
const resolvedExplicit = explicitChannel
? await resolveInstallableChannelPlugin({