Merge pull request #1492 from svkozak/fix-discord-accountId
Discord: preserve accountId in message actions (refs #1489)
This commit is contained in:
@@ -5,6 +5,10 @@ vi.mock("../../gateway/call.js", () => ({
|
||||
callGateway: (opts: unknown) => callGatewayMock(opts),
|
||||
}));
|
||||
|
||||
vi.mock("../agent-scope.js", () => ({
|
||||
resolveSessionAgentId: () => "agent-123",
|
||||
}));
|
||||
|
||||
import { createCronTool } from "./cron-tool.js";
|
||||
|
||||
describe("cron tool", () => {
|
||||
@@ -85,6 +89,23 @@ describe("cron tool", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("does not default agentId when job.agentId is null", async () => {
|
||||
const tool = createCronTool({ agentSessionKey: "main" });
|
||||
await tool.execute("call-null", {
|
||||
action: "add",
|
||||
job: {
|
||||
name: "wake-up",
|
||||
schedule: { atMs: 123 },
|
||||
agentId: null,
|
||||
},
|
||||
});
|
||||
|
||||
const call = callGatewayMock.mock.calls[0]?.[0] as {
|
||||
params?: { agentId?: unknown };
|
||||
};
|
||||
expect(call?.params?.agentId).toBeNull();
|
||||
});
|
||||
|
||||
it("adds recent context for systemEvent reminders when contextMessages > 0", async () => {
|
||||
callGatewayMock
|
||||
.mockResolvedValueOnce({
|
||||
|
||||
@@ -89,7 +89,7 @@ describe("handleDiscordMessagingAction", () => {
|
||||
},
|
||||
enableAllActions,
|
||||
);
|
||||
expect(reactMessageDiscord).toHaveBeenCalledWith("C1", "M1", "✅");
|
||||
expect(reactMessageDiscord).toHaveBeenCalledWith("C1", "M1", "✅", {});
|
||||
});
|
||||
|
||||
it("forwards accountId for reactions", async () => {
|
||||
@@ -116,7 +116,7 @@ describe("handleDiscordMessagingAction", () => {
|
||||
},
|
||||
enableAllActions,
|
||||
);
|
||||
expect(removeOwnReactionsDiscord).toHaveBeenCalledWith("C1", "M1");
|
||||
expect(removeOwnReactionsDiscord).toHaveBeenCalledWith("C1", "M1", {});
|
||||
});
|
||||
|
||||
it("removes reactions when remove flag set", async () => {
|
||||
@@ -130,7 +130,7 @@ describe("handleDiscordMessagingAction", () => {
|
||||
},
|
||||
enableAllActions,
|
||||
);
|
||||
expect(removeReactionDiscord).toHaveBeenCalledWith("C1", "M1", "✅");
|
||||
expect(removeReactionDiscord).toHaveBeenCalledWith("C1", "M1", "✅", {});
|
||||
});
|
||||
|
||||
it("rejects removes without emoji", async () => {
|
||||
@@ -252,15 +252,18 @@ describe("handleDiscordGuildAction - channel management", () => {
|
||||
},
|
||||
channelsEnabled,
|
||||
);
|
||||
expect(createChannelDiscord).toHaveBeenCalledWith({
|
||||
guildId: "G1",
|
||||
name: "test-channel",
|
||||
type: 0,
|
||||
parentId: undefined,
|
||||
topic: "Test topic",
|
||||
position: undefined,
|
||||
nsfw: undefined,
|
||||
});
|
||||
expect(createChannelDiscord).toHaveBeenCalledWith(
|
||||
{
|
||||
guildId: "G1",
|
||||
name: "test-channel",
|
||||
type: 0,
|
||||
parentId: undefined,
|
||||
topic: "Test topic",
|
||||
position: undefined,
|
||||
nsfw: undefined,
|
||||
},
|
||||
{},
|
||||
);
|
||||
expect(result.details).toMatchObject({ ok: true });
|
||||
});
|
||||
|
||||
@@ -289,15 +292,18 @@ describe("handleDiscordGuildAction - channel management", () => {
|
||||
},
|
||||
channelsEnabled,
|
||||
);
|
||||
expect(editChannelDiscord).toHaveBeenCalledWith({
|
||||
channelId: "C1",
|
||||
name: "new-name",
|
||||
topic: "new topic",
|
||||
position: undefined,
|
||||
parentId: undefined,
|
||||
nsfw: undefined,
|
||||
rateLimitPerUser: undefined,
|
||||
});
|
||||
expect(editChannelDiscord).toHaveBeenCalledWith(
|
||||
{
|
||||
channelId: "C1",
|
||||
name: "new-name",
|
||||
topic: "new topic",
|
||||
position: undefined,
|
||||
parentId: undefined,
|
||||
nsfw: undefined,
|
||||
rateLimitPerUser: undefined,
|
||||
},
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
it("clears the channel parent when parentId is null", async () => {
|
||||
@@ -309,15 +315,18 @@ describe("handleDiscordGuildAction - channel management", () => {
|
||||
},
|
||||
channelsEnabled,
|
||||
);
|
||||
expect(editChannelDiscord).toHaveBeenCalledWith({
|
||||
channelId: "C1",
|
||||
name: undefined,
|
||||
topic: undefined,
|
||||
position: undefined,
|
||||
parentId: null,
|
||||
nsfw: undefined,
|
||||
rateLimitPerUser: undefined,
|
||||
});
|
||||
expect(editChannelDiscord).toHaveBeenCalledWith(
|
||||
{
|
||||
channelId: "C1",
|
||||
name: undefined,
|
||||
topic: undefined,
|
||||
position: undefined,
|
||||
parentId: null,
|
||||
nsfw: undefined,
|
||||
rateLimitPerUser: undefined,
|
||||
},
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
it("clears the channel parent when clearParent is true", async () => {
|
||||
@@ -329,20 +338,23 @@ describe("handleDiscordGuildAction - channel management", () => {
|
||||
},
|
||||
channelsEnabled,
|
||||
);
|
||||
expect(editChannelDiscord).toHaveBeenCalledWith({
|
||||
channelId: "C1",
|
||||
name: undefined,
|
||||
topic: undefined,
|
||||
position: undefined,
|
||||
parentId: null,
|
||||
nsfw: undefined,
|
||||
rateLimitPerUser: undefined,
|
||||
});
|
||||
expect(editChannelDiscord).toHaveBeenCalledWith(
|
||||
{
|
||||
channelId: "C1",
|
||||
name: undefined,
|
||||
topic: undefined,
|
||||
position: undefined,
|
||||
parentId: null,
|
||||
nsfw: undefined,
|
||||
rateLimitPerUser: undefined,
|
||||
},
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
it("deletes a channel", async () => {
|
||||
await handleDiscordGuildAction("channelDelete", { channelId: "C1" }, channelsEnabled);
|
||||
expect(deleteChannelDiscord).toHaveBeenCalledWith("C1");
|
||||
expect(deleteChannelDiscord).toHaveBeenCalledWith("C1", {});
|
||||
});
|
||||
|
||||
it("moves a channel", async () => {
|
||||
@@ -356,12 +368,15 @@ describe("handleDiscordGuildAction - channel management", () => {
|
||||
},
|
||||
channelsEnabled,
|
||||
);
|
||||
expect(moveChannelDiscord).toHaveBeenCalledWith({
|
||||
guildId: "G1",
|
||||
channelId: "C1",
|
||||
parentId: "P1",
|
||||
position: 5,
|
||||
});
|
||||
expect(moveChannelDiscord).toHaveBeenCalledWith(
|
||||
{
|
||||
guildId: "G1",
|
||||
channelId: "C1",
|
||||
parentId: "P1",
|
||||
position: 5,
|
||||
},
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
it("clears the channel parent on move when parentId is null", async () => {
|
||||
@@ -374,12 +389,15 @@ describe("handleDiscordGuildAction - channel management", () => {
|
||||
},
|
||||
channelsEnabled,
|
||||
);
|
||||
expect(moveChannelDiscord).toHaveBeenCalledWith({
|
||||
guildId: "G1",
|
||||
channelId: "C1",
|
||||
parentId: null,
|
||||
position: undefined,
|
||||
});
|
||||
expect(moveChannelDiscord).toHaveBeenCalledWith(
|
||||
{
|
||||
guildId: "G1",
|
||||
channelId: "C1",
|
||||
parentId: null,
|
||||
position: undefined,
|
||||
},
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
it("clears the channel parent on move when clearParent is true", async () => {
|
||||
@@ -392,12 +410,15 @@ describe("handleDiscordGuildAction - channel management", () => {
|
||||
},
|
||||
channelsEnabled,
|
||||
);
|
||||
expect(moveChannelDiscord).toHaveBeenCalledWith({
|
||||
guildId: "G1",
|
||||
channelId: "C1",
|
||||
parentId: null,
|
||||
position: undefined,
|
||||
});
|
||||
expect(moveChannelDiscord).toHaveBeenCalledWith(
|
||||
{
|
||||
guildId: "G1",
|
||||
channelId: "C1",
|
||||
parentId: null,
|
||||
position: undefined,
|
||||
},
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
it("creates a category with type=4", async () => {
|
||||
@@ -406,12 +427,15 @@ describe("handleDiscordGuildAction - channel management", () => {
|
||||
{ guildId: "G1", name: "My Category" },
|
||||
channelsEnabled,
|
||||
);
|
||||
expect(createChannelDiscord).toHaveBeenCalledWith({
|
||||
guildId: "G1",
|
||||
name: "My Category",
|
||||
type: 4,
|
||||
position: undefined,
|
||||
});
|
||||
expect(createChannelDiscord).toHaveBeenCalledWith(
|
||||
{
|
||||
guildId: "G1",
|
||||
name: "My Category",
|
||||
type: 4,
|
||||
position: undefined,
|
||||
},
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
it("edits a category", async () => {
|
||||
@@ -420,16 +444,19 @@ describe("handleDiscordGuildAction - channel management", () => {
|
||||
{ categoryId: "CAT1", name: "Renamed Category" },
|
||||
channelsEnabled,
|
||||
);
|
||||
expect(editChannelDiscord).toHaveBeenCalledWith({
|
||||
channelId: "CAT1",
|
||||
name: "Renamed Category",
|
||||
position: undefined,
|
||||
});
|
||||
expect(editChannelDiscord).toHaveBeenCalledWith(
|
||||
{
|
||||
channelId: "CAT1",
|
||||
name: "Renamed Category",
|
||||
position: undefined,
|
||||
},
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
it("deletes a category", async () => {
|
||||
await handleDiscordGuildAction("categoryDelete", { categoryId: "CAT1" }, channelsEnabled);
|
||||
expect(deleteChannelDiscord).toHaveBeenCalledWith("CAT1");
|
||||
expect(deleteChannelDiscord).toHaveBeenCalledWith("CAT1", {});
|
||||
});
|
||||
|
||||
it("sets channel permissions for role", async () => {
|
||||
@@ -444,13 +471,16 @@ describe("handleDiscordGuildAction - channel management", () => {
|
||||
},
|
||||
channelsEnabled,
|
||||
);
|
||||
expect(setChannelPermissionDiscord).toHaveBeenCalledWith({
|
||||
channelId: "C1",
|
||||
targetId: "R1",
|
||||
targetType: 0,
|
||||
allow: "1024",
|
||||
deny: "2048",
|
||||
});
|
||||
expect(setChannelPermissionDiscord).toHaveBeenCalledWith(
|
||||
{
|
||||
channelId: "C1",
|
||||
targetId: "R1",
|
||||
targetType: 0,
|
||||
allow: "1024",
|
||||
deny: "2048",
|
||||
},
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
it("sets channel permissions for member", async () => {
|
||||
@@ -464,13 +494,16 @@ describe("handleDiscordGuildAction - channel management", () => {
|
||||
},
|
||||
channelsEnabled,
|
||||
);
|
||||
expect(setChannelPermissionDiscord).toHaveBeenCalledWith({
|
||||
channelId: "C1",
|
||||
targetId: "U1",
|
||||
targetType: 1,
|
||||
allow: "1024",
|
||||
deny: undefined,
|
||||
});
|
||||
expect(setChannelPermissionDiscord).toHaveBeenCalledWith(
|
||||
{
|
||||
channelId: "C1",
|
||||
targetId: "U1",
|
||||
targetType: 1,
|
||||
allow: "1024",
|
||||
deny: undefined,
|
||||
},
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
it("removes channel permissions", async () => {
|
||||
@@ -479,7 +512,7 @@ describe("handleDiscordGuildAction - channel management", () => {
|
||||
{ channelId: "C1", targetId: "R1" },
|
||||
channelsEnabled,
|
||||
);
|
||||
expect(removeChannelPermissionDiscord).toHaveBeenCalledWith("C1", "R1");
|
||||
expect(removeChannelPermissionDiscord).toHaveBeenCalledWith("C1", "R1", {});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user