File size: 3,151 Bytes
fc93158 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | 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);
});
});
|