mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 21:00:24 +00:00
fix(regression): auto-enable message channel selection
This commit is contained in:
@@ -11,6 +11,7 @@ import { createTestRegistry } from "../test-utils/channel-plugins.js";
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
|
||||
let testConfig: Record<string, unknown> = {};
|
||||
const applyPluginAutoEnable = vi.hoisted(() => vi.fn(({ config }) => ({ config, changes: [] })));
|
||||
vi.mock("../config/config.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../config/config.js")>();
|
||||
return {
|
||||
@@ -19,6 +20,10 @@ vi.mock("../config/config.js", async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../config/plugin-auto-enable.js", () => ({
|
||||
applyPluginAutoEnable,
|
||||
}));
|
||||
|
||||
const { resolveCommandSecretRefsViaGateway, callGatewayMock } = vi.hoisted(() => ({
|
||||
resolveCommandSecretRefsViaGateway: vi.fn(async ({ config }: { config: unknown }) => ({
|
||||
resolvedConfig: config,
|
||||
@@ -65,6 +70,8 @@ beforeEach(() => {
|
||||
handleDiscordAction.mockClear();
|
||||
handleTelegramAction.mockClear();
|
||||
resolveCommandSecretRefsViaGateway.mockClear();
|
||||
applyPluginAutoEnable.mockClear();
|
||||
applyPluginAutoEnable.mockImplementation(({ config }) => ({ config, changes: [] }));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -370,6 +377,54 @@ describe("messageCommand", () => {
|
||||
expect(handleTelegramAction).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("defaults channel from the auto-enabled config snapshot when only one channel becomes configured", async () => {
|
||||
const rawConfig = {};
|
||||
const resolvedConfig = {};
|
||||
const autoEnabledConfig = {
|
||||
channels: {
|
||||
telegram: {
|
||||
token: "12345:auto-enabled-token",
|
||||
},
|
||||
},
|
||||
plugins: { allow: ["telegram"] },
|
||||
};
|
||||
mockResolvedCommandConfig({
|
||||
rawConfig,
|
||||
resolvedConfig,
|
||||
diagnostics: [],
|
||||
});
|
||||
applyPluginAutoEnable.mockReturnValue({ config: autoEnabledConfig, changes: [] });
|
||||
setActivePluginRegistry(
|
||||
createTestRegistry([
|
||||
{
|
||||
...createTelegramSendPluginRegistration(),
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
const deps = makeDeps();
|
||||
await messageCommand(
|
||||
{
|
||||
target: "123456",
|
||||
message: "hi",
|
||||
},
|
||||
deps,
|
||||
runtime,
|
||||
);
|
||||
|
||||
expect(applyPluginAutoEnable).toHaveBeenCalledWith({
|
||||
config: resolvedConfig,
|
||||
env: process.env,
|
||||
});
|
||||
expect(handleTelegramAction).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
action: "send",
|
||||
to: "123456",
|
||||
}),
|
||||
autoEnabledConfig,
|
||||
);
|
||||
});
|
||||
|
||||
it("requires channel when multiple configured", async () => {
|
||||
process.env.TELEGRAM_BOT_TOKEN = "token-abc";
|
||||
process.env.DISCORD_BOT_TOKEN = "token-discord";
|
||||
|
||||
@@ -9,6 +9,7 @@ import { resolveMessageSecretScope } from "../cli/message-secret-scope.js";
|
||||
import { createOutboundSendDeps, type CliDeps } from "../cli/outbound-send-deps.js";
|
||||
import { withProgress } from "../cli/progress.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js";
|
||||
import type { OutboundSendDeps } from "../infra/outbound/deliver.js";
|
||||
import { runMessageAction } from "../infra/outbound/message-action-runner.js";
|
||||
import { type RuntimeEnv, writeRuntimeJson } from "../runtime.js";
|
||||
@@ -32,12 +33,16 @@ export async function messageCommand(
|
||||
channel: scope.channel,
|
||||
accountId: scope.accountId,
|
||||
});
|
||||
const { resolvedConfig: cfg, diagnostics } = await resolveCommandSecretRefsViaGateway({
|
||||
const { resolvedConfig, diagnostics } = await resolveCommandSecretRefsViaGateway({
|
||||
config: loadedRaw,
|
||||
commandName: "message",
|
||||
targetIds: scopedTargets.targetIds,
|
||||
...(scopedTargets.allowedPaths ? { allowedPaths: scopedTargets.allowedPaths } : {}),
|
||||
});
|
||||
const cfg = applyPluginAutoEnable({
|
||||
config: resolvedConfig,
|
||||
env: process.env,
|
||||
}).config;
|
||||
for (const entry of diagnostics) {
|
||||
runtime.log(`[secrets] ${entry}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user