chore: code/dead tests cleanup (#38286)

* Discord: assert bot-self filter queue guard

* Tests: remove dead gateway SIGTERM placeholder
This commit is contained in:
Vincent Koc
2026-03-06 14:27:02 -05:00
committed by GitHub
parent 5e05a9cb79
commit 38f46e80b0
2 changed files with 74 additions and 26 deletions

View File

@@ -1,8 +0,0 @@
import { describe, it } from "vitest";
describe("gateway SIGTERM", () => {
it.skip("covered by runGatewayLoop signal tests in src/cli/gateway-cli/run-loop.test.ts", () => {
// Kept as a placeholder to document why the old child-process integration
// case was retired: it duplicated run-loop signal coverage at high runtime cost.
});
});

View File

@@ -1,8 +1,20 @@
import { describe, it, vi } from "vitest";
import { describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../../config/types.js";
import { createDiscordMessageHandler } from "./message-handler.js";
import { createNoopThreadBindingManager } from "./thread-bindings.js";
const preflightDiscordMessageMock = vi.hoisted(() => vi.fn());
const processDiscordMessageMock = vi.hoisted(() => vi.fn());
vi.mock("./message-handler.preflight.js", () => ({
preflightDiscordMessage: preflightDiscordMessageMock,
}));
vi.mock("./message-handler.process.js", () => ({
processDiscordMessage: processDiscordMessageMock,
}));
const { createDiscordMessageHandler } = await import("./message-handler.js");
const BOT_USER_ID = "bot-123";
function createHandlerParams(overrides?: Partial<{ botUserId: string }>) {
@@ -14,6 +26,11 @@ function createHandlerParams(overrides?: Partial<{ botUserId: string }>) {
groupPolicy: "allowlist",
},
},
messages: {
inbound: {
debounceMs: 0,
},
},
};
return {
cfg,
@@ -39,35 +56,74 @@ function createHandlerParams(overrides?: Partial<{ botUserId: string }>) {
};
}
function createMessageData(authorId: string) {
function createMessageData(authorId: string, channelId = "ch-1") {
return {
author: { id: authorId, bot: authorId === BOT_USER_ID },
message: {
id: "msg-1",
author: { id: authorId, bot: authorId === BOT_USER_ID },
content: "hello",
channel_id: "ch-1",
channel_id: channelId,
},
channel_id: "ch-1",
channel_id: channelId,
};
}
function createPreflightContext(channelId = "ch-1") {
return {
data: {
channel_id: channelId,
message: {
id: `msg-${channelId}`,
channel_id: channelId,
attachments: [],
},
},
message: {
id: `msg-${channelId}`,
channel_id: channelId,
attachments: [],
},
route: {
sessionKey: `agent:main:discord:channel:${channelId}`,
},
baseSessionKey: `agent:main:discord:channel:${channelId}`,
messageChannelId: channelId,
};
}
describe("createDiscordMessageHandler bot-self filter", () => {
it("skips bot-own messages before debouncer", async () => {
it("skips bot-own messages before the debounce queue", async () => {
preflightDiscordMessageMock.mockReset();
processDiscordMessageMock.mockReset();
const handler = createDiscordMessageHandler(createHandlerParams());
await handler(createMessageData(BOT_USER_ID) as never, {} as never);
await expect(
handler(createMessageData(BOT_USER_ID) as never, {} as never),
).resolves.toBeUndefined();
expect(preflightDiscordMessageMock).not.toHaveBeenCalled();
expect(processDiscordMessageMock).not.toHaveBeenCalled();
});
it("processes messages from other users", async () => {
it("enqueues non-bot messages for processing", async () => {
preflightDiscordMessageMock.mockReset();
processDiscordMessageMock.mockReset();
preflightDiscordMessageMock.mockImplementation(
async (params: { data: { channel_id: string } }) =>
createPreflightContext(params.data.channel_id),
);
const handler = createDiscordMessageHandler(createHandlerParams());
try {
await handler(
createMessageData("user-456") as never,
{
fetchChannel: vi.fn().mockResolvedValue(null),
} as never,
);
} catch {
// Expected: pipeline fails without full mock, but it passed the filter.
}
await expect(
handler(createMessageData("user-456") as never, {} as never),
).resolves.toBeUndefined();
await vi.waitFor(() => {
expect(preflightDiscordMessageMock).toHaveBeenCalledTimes(1);
expect(processDiscordMessageMock).toHaveBeenCalledTimes(1);
});
});
});