fix(regression): auto-enable channels resolve selection

This commit is contained in:
Tak Hoffman
2026-03-27 23:48:54 -05:00
parent 897a6a6c5b
commit 5167841ff8
2 changed files with 63 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ const mocks = vi.hoisted(() => ({
resolveCommandSecretRefsViaGateway: vi.fn(),
getChannelsCommandSecretTargetIds: vi.fn(() => []),
loadConfig: vi.fn(),
applyPluginAutoEnable: vi.fn(),
writeConfigFile: vi.fn(),
resolveMessageChannelSelection: vi.fn(),
resolveInstallableChannelPlugin: vi.fn(),
@@ -23,6 +24,10 @@ vi.mock("../config/config.js", () => ({
writeConfigFile: mocks.writeConfigFile,
}));
vi.mock("../config/plugin-auto-enable.js", () => ({
applyPluginAutoEnable: mocks.applyPluginAutoEnable,
}));
vi.mock("../infra/outbound/channel-selection.js", () => ({
resolveMessageChannelSelection: mocks.resolveMessageChannelSelection,
}));
@@ -47,6 +52,7 @@ describe("channelsResolveCommand", () => {
beforeEach(() => {
vi.clearAllMocks();
mocks.loadConfig.mockReturnValue({ channels: {} });
mocks.applyPluginAutoEnable.mockImplementation(({ config }) => ({ config, changes: [] }));
mocks.writeConfigFile.mockResolvedValue(undefined);
mocks.resolveCommandSecretRefsViaGateway.mockResolvedValue({
resolvedConfig: { channels: {} },
@@ -110,4 +116,56 @@ describe("channelsResolveCommand", () => {
);
expect(runtime.log).toHaveBeenCalledWith("friends -> 120363000000@g.us (Friends)");
});
it("uses the auto-enabled config snapshot for omitted channel resolution", async () => {
const autoEnabledConfig = {
channels: { whatsapp: {} },
plugins: { allow: ["whatsapp"] },
};
const resolveTargets = vi.fn().mockResolvedValue([
{
input: "friends",
resolved: true,
id: "120363000000@g.us",
name: "Friends",
},
]);
mocks.resolveCommandSecretRefsViaGateway.mockResolvedValue({
resolvedConfig: { channels: {} },
diagnostics: [],
});
mocks.applyPluginAutoEnable.mockReturnValue({ config: autoEnabledConfig, changes: [] });
mocks.resolveMessageChannelSelection.mockResolvedValue({
channel: "whatsapp",
configured: ["whatsapp"],
source: "single-configured",
});
mocks.getChannelPlugin.mockReturnValue({
id: "whatsapp",
resolver: { resolveTargets },
});
await channelsResolveCommand(
{
entries: ["friends"],
},
runtime,
);
expect(mocks.applyPluginAutoEnable).toHaveBeenCalledWith({
config: { channels: {} },
env: process.env,
});
expect(mocks.resolveMessageChannelSelection).toHaveBeenCalledWith({
cfg: autoEnabledConfig,
channel: null,
});
expect(resolveTargets).toHaveBeenCalledWith(
expect.objectContaining({
cfg: autoEnabledConfig,
inputs: ["friends"],
kind: "group",
}),
);
});
});

View File

@@ -3,6 +3,7 @@ import type { ChannelResolveKind, ChannelResolveResult } from "../../channels/pl
import { resolveCommandSecretRefsViaGateway } from "../../cli/command-secret-gateway.js";
import { getChannelsCommandSecretTargetIds } from "../../cli/command-secret-targets.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 { type RuntimeEnv, writeRuntimeJson } from "../../runtime.js";
@@ -78,7 +79,10 @@ export async function channelsResolveCommand(opts: ChannelsResolveOptions, runti
targetIds: getChannelsCommandSecretTargetIds(),
mode: "read_only_operational",
});
let cfg = resolvedConfig;
let cfg = applyPluginAutoEnable({
config: resolvedConfig,
env: process.env,
}).config;
for (const entry of diagnostics) {
runtime.log(`[secrets] ${entry}`);
}