mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 16:04:59 +00:00
fix(slack): skip monitor startup for disabled accounts [AI-assisted] (openclaw#30592) thanks @liuxiaopai-ai
Verified: - pnpm install --frozen-lockfile - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: liuxiaopai-ai <73659136+liuxiaopai-ai@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -6,7 +6,9 @@ import {
|
||||
defaultSlackTestConfig,
|
||||
getSlackTestState,
|
||||
getSlackClient,
|
||||
getSlackHandlers,
|
||||
getSlackHandlerOrThrow,
|
||||
flush,
|
||||
resetSlackTestState,
|
||||
runSlackMessageOnce,
|
||||
startSlackMonitor,
|
||||
@@ -119,6 +121,32 @@ describe("monitorSlackProvider tool results", () => {
|
||||
};
|
||||
}
|
||||
|
||||
it("skips socket startup when Slack channel is disabled", async () => {
|
||||
slackTestState.config = {
|
||||
channels: {
|
||||
slack: {
|
||||
enabled: false,
|
||||
mode: "socket",
|
||||
botToken: "xoxb-config",
|
||||
appToken: "xapp-config",
|
||||
},
|
||||
},
|
||||
};
|
||||
const client = getSlackClient();
|
||||
if (!client) {
|
||||
throw new Error("Slack client not registered");
|
||||
}
|
||||
client.auth.test.mockClear();
|
||||
|
||||
const { controller, run } = startSlackMonitor(monitorSlackProvider);
|
||||
await flush();
|
||||
controller.abort();
|
||||
await run;
|
||||
|
||||
expect(client.auth.test).not.toHaveBeenCalled();
|
||||
expect(getSlackHandlers()?.size ?? 0).toBe(0);
|
||||
});
|
||||
|
||||
it("skips tool summaries with responsePrefix", async () => {
|
||||
replyMock.mockResolvedValue({ text: "final reply" });
|
||||
|
||||
|
||||
@@ -58,12 +58,26 @@ function parseApiAppIdFromAppToken(raw?: string) {
|
||||
|
||||
export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) {
|
||||
const cfg = opts.config ?? loadConfig();
|
||||
const runtime: RuntimeEnv = opts.runtime ?? createNonExitingRuntime();
|
||||
|
||||
let account = resolveSlackAccount({
|
||||
cfg,
|
||||
accountId: opts.accountId,
|
||||
});
|
||||
|
||||
if (!account.enabled) {
|
||||
runtime.log?.(`[${account.accountId}] slack account disabled; monitor startup skipped`);
|
||||
if (opts.abortSignal?.aborted) {
|
||||
return;
|
||||
}
|
||||
await new Promise<void>((resolve) => {
|
||||
opts.abortSignal?.addEventListener("abort", () => resolve(), {
|
||||
once: true,
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const historyLimit = Math.max(
|
||||
0,
|
||||
account.config.historyLimit ??
|
||||
@@ -93,8 +107,6 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) {
|
||||
);
|
||||
}
|
||||
|
||||
const runtime: RuntimeEnv = opts.runtime ?? createNonExitingRuntime();
|
||||
|
||||
const slackCfg = account.config;
|
||||
const dmConfig = slackCfg.dm;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user