Files
openclaw/extensions/discord/src/session-key-normalization.test.ts
scoootscooob 5682ec37fa refactor: move Discord channel implementation to extensions/ (#45660)
* 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
2026-03-14 02:53:57 -07:00

45 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { normalizeExplicitDiscordSessionKey } from "./session-key-normalization.js";
describe("normalizeExplicitDiscordSessionKey", () => {
it("rewrites bare discord:dm keys for direct chats", () => {
expect(
normalizeExplicitDiscordSessionKey("discord:dm:123456", {
ChatType: "direct",
From: "discord:123456",
SenderId: "123456",
}),
).toBe("discord:direct:123456");
});
it("rewrites legacy discord:dm keys for direct chats", () => {
expect(
normalizeExplicitDiscordSessionKey("agent:fina:discord:dm:123456", {
ChatType: "direct",
From: "discord:123456",
SenderId: "123456",
}),
).toBe("agent:fina:discord:direct:123456");
});
it("rewrites phantom discord:channel keys when sender matches", () => {
expect(
normalizeExplicitDiscordSessionKey("discord:channel:123456", {
ChatType: "direct",
From: "discord:123456",
SenderId: "123456",
}),
).toBe("discord:direct:123456");
});
it("leaves non-direct channel keys unchanged", () => {
expect(
normalizeExplicitDiscordSessionKey("agent:fina:discord:channel:123456", {
ChatType: "channel",
From: "discord:channel:123456",
SenderId: "789",
}),
).toBe("agent:fina:discord:channel:123456");
});
});