|
| 1 | +import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types"; |
| 2 | +import type { PluginCommandContext } from "openclaw/plugin-sdk/plugin-entry"; |
| 3 | +import { describe, expect, it } from "vitest"; |
| 4 | +import { buildFrameworkSlashContext } from "./framework-context-adapter.js"; |
| 5 | + |
| 6 | +function createCommandContext(isAuthorizedSender: boolean): PluginCommandContext { |
| 7 | + return { |
| 8 | + senderId: "SENDER_OPENID", |
| 9 | + channel: "qqbot", |
| 10 | + isAuthorizedSender, |
| 11 | + args: "on", |
| 12 | + commandBody: "/bot-streaming on", |
| 13 | + config: {} as OpenClawConfig, |
| 14 | + from: "qqbot:c2c:SENDER_OPENID", |
| 15 | + requestConversationBinding: async () => undefined, |
| 16 | + detachConversationBinding: async () => ({ removed: false }), |
| 17 | + getCurrentConversationBinding: async () => null, |
| 18 | + } as unknown as PluginCommandContext; |
| 19 | +} |
| 20 | + |
| 21 | +describe("buildFrameworkSlashContext", () => { |
| 22 | + it("preserves the framework authorization decision in the slash context", () => { |
| 23 | + const authorized = buildFrameworkSlashContext({ |
| 24 | + ctx: createCommandContext(true), |
| 25 | + account: { |
| 26 | + accountId: "default", |
| 27 | + enabled: true, |
| 28 | + appId: "app", |
| 29 | + clientSecret: "secret", |
| 30 | + secretSource: "config", |
| 31 | + markdownSupport: true, |
| 32 | + config: {}, |
| 33 | + }, |
| 34 | + from: { msgType: "c2c", targetType: "c2c", targetId: "SENDER_OPENID" }, |
| 35 | + commandName: "bot-streaming", |
| 36 | + }); |
| 37 | + const unauthorized = buildFrameworkSlashContext({ |
| 38 | + ctx: createCommandContext(false), |
| 39 | + account: { |
| 40 | + accountId: "default", |
| 41 | + enabled: true, |
| 42 | + appId: "app", |
| 43 | + clientSecret: "secret", |
| 44 | + secretSource: "config", |
| 45 | + markdownSupport: true, |
| 46 | + config: {}, |
| 47 | + }, |
| 48 | + from: { msgType: "c2c", targetType: "c2c", targetId: "SENDER_OPENID" }, |
| 49 | + commandName: "bot-streaming", |
| 50 | + }); |
| 51 | + |
| 52 | + expect(authorized.commandAuthorized).toBe(true); |
| 53 | + expect(unauthorized.commandAuthorized).toBe(false); |
| 54 | + }); |
| 55 | +}); |
0 commit comments