Tests: fast-path Slack message tool discovery

This commit is contained in:
Gustavo Madeira Santana
2026-04-17 01:58:00 -04:00
parent 878f2122e5
commit 7ae670e501
8 changed files with 277 additions and 49 deletions

View File

@@ -0,0 +1 @@
export { describeSlackMessageTool as describeMessageTool } from "./src/message-tool-api.js";

View File

@@ -1,14 +1,9 @@
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
import { Type } from "@sinclair/typebox";
import {
type ChannelMessageActionAdapter,
type ChannelMessageToolDiscovery,
} from "openclaw/plugin-sdk/channel-contract";
import type { ChannelMessageActionAdapter } from "openclaw/plugin-sdk/channel-contract";
import type { SlackActionContext } from "./action-runtime.js";
import { isSlackInteractiveRepliesEnabled } from "./interactive-replies.js";
import { handleSlackMessageAction } from "./message-action-dispatch.js";
import { extractSlackToolSend, listSlackMessageActions } from "./message-actions.js";
import { createSlackMessageToolBlocksSchema } from "./message-tool-schema.js";
import { extractSlackToolSend } from "./message-actions.js";
import { describeSlackMessageTool } from "./message-tool-api.js";
import { resolveSlackChannelId } from "./targets.js";
type SlackActionInvoke = (
@@ -28,35 +23,8 @@ export function createSlackActions(
providerId: string,
options?: { invoke?: SlackActionInvoke },
): ChannelMessageActionAdapter {
function describeMessageTool({
cfg,
accountId,
}: Parameters<
NonNullable<ChannelMessageActionAdapter["describeMessageTool"]>
>[0]): ChannelMessageToolDiscovery {
const actions = listSlackMessageActions(cfg, accountId);
const capabilities = new Set<"blocks" | "interactive">();
if (actions.includes("send")) {
capabilities.add("blocks");
}
if (isSlackInteractiveRepliesEnabled({ cfg, accountId })) {
capabilities.add("interactive");
}
return {
actions,
capabilities: Array.from(capabilities),
schema: actions.includes("send")
? {
properties: {
blocks: Type.Optional(createSlackMessageToolBlocksSchema()),
},
}
: null,
};
}
return {
describeMessageTool,
describeMessageTool: describeSlackMessageTool,
extractToolSend: ({ args }) => extractSlackToolSend(args),
handleAction: async (ctx) => {
return await handleSlackMessageAction({

View File

@@ -0,0 +1,44 @@
import { describe, expect, it } from "vitest";
import { describeSlackMessageTool } from "./message-tool-api.js";
describe("Slack message tool public API", () => {
it("describes configured Slack message actions without loading channel runtime", () => {
expect(
describeSlackMessageTool({
cfg: {
channels: {
slack: {
botToken: "xoxb-test",
},
},
},
}),
).toMatchObject({
actions: expect.arrayContaining(["send", "upload-file", "read"]),
capabilities: expect.arrayContaining(["blocks"]),
});
});
it("honors account-scoped action gates", () => {
expect(
describeSlackMessageTool({
cfg: {
channels: {
slack: {
botToken: "xoxb-default",
accounts: {
ops: {
botToken: "xoxb-ops",
actions: {
messages: false,
},
},
},
},
},
},
accountId: "ops",
}).actions,
).not.toContain("upload-file");
});
});

View File

@@ -0,0 +1,30 @@
import { Type } from "@sinclair/typebox";
import type { ChannelMessageActionAdapter } from "openclaw/plugin-sdk/channel-contract";
import { isSlackInteractiveRepliesEnabled } from "./interactive-replies.js";
import { listSlackMessageActions } from "./message-actions.js";
import { createSlackMessageToolBlocksSchema } from "./message-tool-schema.js";
export function describeSlackMessageTool({
cfg,
accountId,
}: Parameters<NonNullable<ChannelMessageActionAdapter["describeMessageTool"]>>[0]) {
const actions = listSlackMessageActions(cfg, accountId);
const capabilities = new Set<"blocks" | "interactive">();
if (actions.includes("send")) {
capabilities.add("blocks");
}
if (isSlackInteractiveRepliesEnabled({ cfg, accountId })) {
capabilities.add("interactive");
}
return {
actions,
capabilities: Array.from(capabilities),
schema: actions.includes("send")
? {
properties: {
blocks: Type.Optional(createSlackMessageToolBlocksSchema()),
},
}
: null,
};
}