mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-15 03:01:02 +00:00
* refactor: move Discord channel implementation to extensions/discord/src/ Move all Discord source files from src/discord/ to extensions/discord/src/, following the extension migration pattern. Source files in src/discord/ are replaced with re-export shims. Channel-plugin files from src/channels/plugins/*/discord* are similarly moved and shimmed. - Copy all .ts source files preserving subdirectory structure (monitor/, voice/) - Move channel-plugin files (actions, normalize, onboarding, outbound, status-issues) - Fix all relative imports to use correct paths from new location - Create re-export shims at original locations for backward compatibility - Delete test files from shim locations (tests live in extension now) - Update tsconfig.plugin-sdk.dts.json rootDir from "src" to "." to accommodate extension files outside src/ - Update write-plugin-sdk-entry-dts.ts to match new declaration output paths * fix: add importOriginal to thread-bindings session-meta mock for extensions test * style: fix formatting in thread-bindings lifecycle test
96 lines
3.1 KiB
TypeScript
96 lines
3.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildDiscordNativeCommandContext } from "./native-command-context.js";
|
|
|
|
describe("buildDiscordNativeCommandContext", () => {
|
|
it("builds direct-message slash command context", () => {
|
|
const ctx = buildDiscordNativeCommandContext({
|
|
prompt: "/status",
|
|
commandArgs: {},
|
|
sessionKey: "agent:codex:discord:slash:user-1",
|
|
commandTargetSessionKey: "agent:codex:discord:direct:user-1",
|
|
accountId: "default",
|
|
interactionId: "interaction-1",
|
|
channelId: "dm-1",
|
|
commandAuthorized: true,
|
|
isDirectMessage: true,
|
|
isGroupDm: false,
|
|
isGuild: false,
|
|
isThreadChannel: false,
|
|
user: {
|
|
id: "user-1",
|
|
username: "tester",
|
|
globalName: "Tester",
|
|
},
|
|
sender: {
|
|
id: "user-1",
|
|
tag: "tester#0001",
|
|
},
|
|
timestampMs: 123,
|
|
});
|
|
|
|
expect(ctx.From).toBe("discord:user-1");
|
|
expect(ctx.To).toBe("slash:user-1");
|
|
expect(ctx.ChatType).toBe("direct");
|
|
expect(ctx.ConversationLabel).toBe("Tester");
|
|
expect(ctx.SessionKey).toBe("agent:codex:discord:slash:user-1");
|
|
expect(ctx.CommandTargetSessionKey).toBe("agent:codex:discord:direct:user-1");
|
|
expect(ctx.OriginatingTo).toBe("user:user-1");
|
|
expect(ctx.UntrustedContext).toBeUndefined();
|
|
expect(ctx.GroupSystemPrompt).toBeUndefined();
|
|
expect(ctx.Timestamp).toBe(123);
|
|
});
|
|
|
|
it("builds guild slash command context with owner allowlist and channel metadata", () => {
|
|
const ctx = buildDiscordNativeCommandContext({
|
|
prompt: "/status",
|
|
commandArgs: { values: { model: "gpt-5.2" } },
|
|
sessionKey: "agent:codex:discord:slash:user-1",
|
|
commandTargetSessionKey: "agent:codex:discord:channel:chan-1",
|
|
accountId: "default",
|
|
interactionId: "interaction-1",
|
|
channelId: "chan-1",
|
|
threadParentId: "parent-1",
|
|
guildName: "Ops",
|
|
channelTopic: "Production alerts only",
|
|
channelConfig: {
|
|
allowed: true,
|
|
users: ["discord:user-1"],
|
|
systemPrompt: "Use the runbook.",
|
|
},
|
|
guildInfo: {
|
|
id: "guild-1",
|
|
},
|
|
allowNameMatching: false,
|
|
commandAuthorized: true,
|
|
isDirectMessage: false,
|
|
isGroupDm: false,
|
|
isGuild: true,
|
|
isThreadChannel: true,
|
|
user: {
|
|
id: "user-1",
|
|
username: "tester",
|
|
},
|
|
sender: {
|
|
id: "user-1",
|
|
name: "tester",
|
|
tag: "tester#0001",
|
|
},
|
|
timestampMs: 456,
|
|
});
|
|
|
|
expect(ctx.From).toBe("discord:channel:chan-1");
|
|
expect(ctx.ChatType).toBe("channel");
|
|
expect(ctx.ConversationLabel).toBe("chan-1");
|
|
expect(ctx.GroupSubject).toBe("Ops");
|
|
expect(ctx.GroupSystemPrompt).toBe("Use the runbook.");
|
|
expect(ctx.OwnerAllowFrom).toEqual(["user-1"]);
|
|
expect(ctx.MessageThreadId).toBe("chan-1");
|
|
expect(ctx.ThreadParentId).toBe("parent-1");
|
|
expect(ctx.OriginatingTo).toBe("channel:chan-1");
|
|
expect(ctx.UntrustedContext).toEqual([
|
|
expect.stringContaining("Discord channel topic:\nProduction alerts only"),
|
|
]);
|
|
expect(ctx.Timestamp).toBe(456);
|
|
});
|
|
});
|