fix(discord): preserve channel session keys via channel_id fallbacks (#17622)

* fix(discord): preserve channel session keys via channel_id fallbacks

* docs(changelog): add discord session continuity note

* Tests: cover discord channel_id fallback

---------

Co-authored-by: Shadow <hi@shadowing.dev>
This commit is contained in:
Shakker
2026-02-16 02:30:17 +00:00
committed by GitHub
parent 39d5590230
commit 09566b1693
16 changed files with 235 additions and 49 deletions

View File

@@ -0,0 +1,38 @@
import type { Message } from "@buape/carbon";
import { describe, expect, it } from "vitest";
import { resolveDiscordMessageChannelId } from "./message-utils.js";
function asMessage(payload: Record<string, unknown>): Message {
return payload as unknown as Message;
}
describe("resolveDiscordMessageChannelId", () => {
it("uses message.channelId when present", () => {
const channelId = resolveDiscordMessageChannelId({
message: asMessage({ channelId: " 123 " }),
});
expect(channelId).toBe("123");
});
it("falls back to message.channel_id", () => {
const channelId = resolveDiscordMessageChannelId({
message: asMessage({ channel_id: " 234 " }),
});
expect(channelId).toBe("234");
});
it("falls back to message.rawData.channel_id", () => {
const channelId = resolveDiscordMessageChannelId({
message: asMessage({ rawData: { channel_id: "456" } }),
});
expect(channelId).toBe("456");
});
it("falls back to eventChannelId and coerces numeric values", () => {
const channelId = resolveDiscordMessageChannelId({
message: asMessage({}),
eventChannelId: 789,
});
expect(channelId).toBe("789");
});
});