mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 17:38:27 +00:00
* fix: use .js extension for ESM imports of RoutePeerKind
The imports incorrectly used .ts extension which doesn't resolve
with moduleResolution: NodeNext. Changed to .js and added 'type'
import modifier.
* fix tsconfig
* refactor: unify peer kind to ChatType, rename dm to direct
- Replace RoutePeerKind with ChatType throughout codebase
- Change 'dm' literal values to 'direct' in routing/session keys
- Keep backward compat: normalizeChatType accepts 'dm' -> 'direct'
- Add ChatType export to plugin-sdk, deprecate RoutePeerKind
- Update session key parsing to accept both 'dm' and 'direct' markers
- Update all channel monitors and extensions to use ChatType
BREAKING CHANGE: Session keys now use 'direct' instead of 'dm'.
Existing 'dm' keys still work via backward compat layer.
* fix tests
* test: update session key expectations for dmdirect migration
- Fix test expectations to expect :direct: in generated output
- Add explicit backward compat test for normalizeChatType('dm')
- Keep input test data with :dm: keys to verify backward compat
* fix: accept legacy 'dm' in session key parsing for backward compat
getDmHistoryLimitFromSessionKey now accepts both :dm: and :direct:
to ensure old session keys continue to work correctly.
* test: add explicit backward compat tests for dmdirect migration
- session-key.test.ts: verify both :dm: and :direct: keys are valid
- getDmHistoryLimitFromSessionKey: verify both formats work
* feat: backward compat for resetByType.dm config key
* test: skip unix-path Nix tests on Windows
117 lines
3.3 KiB
TypeScript
117 lines
3.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { OpenClawConfig } from "../../config/config.js";
|
|
import { resolveOutboundSessionRoute } from "./outbound-session.js";
|
|
|
|
const baseConfig = {} as OpenClawConfig;
|
|
|
|
describe("resolveOutboundSessionRoute", () => {
|
|
it("builds Slack thread session keys", async () => {
|
|
const route = await resolveOutboundSessionRoute({
|
|
cfg: baseConfig,
|
|
channel: "slack",
|
|
agentId: "main",
|
|
target: "channel:C123",
|
|
replyToId: "456",
|
|
});
|
|
|
|
expect(route?.sessionKey).toBe("agent:main:slack:channel:c123:thread:456");
|
|
expect(route?.from).toBe("slack:channel:C123");
|
|
expect(route?.to).toBe("channel:C123");
|
|
expect(route?.threadId).toBe("456");
|
|
});
|
|
|
|
it("uses Telegram topic ids in group session keys", async () => {
|
|
const route = await resolveOutboundSessionRoute({
|
|
cfg: baseConfig,
|
|
channel: "telegram",
|
|
agentId: "main",
|
|
target: "-100123456:topic:42",
|
|
});
|
|
|
|
expect(route?.sessionKey).toBe("agent:main:telegram:group:-100123456:topic:42");
|
|
expect(route?.from).toBe("telegram:group:-100123456:topic:42");
|
|
expect(route?.to).toBe("telegram:-100123456");
|
|
expect(route?.threadId).toBe(42);
|
|
});
|
|
|
|
it("treats Telegram usernames as DMs when unresolved", async () => {
|
|
const cfg = { session: { dmScope: "per-channel-peer" } } as OpenClawConfig;
|
|
const route = await resolveOutboundSessionRoute({
|
|
cfg,
|
|
channel: "telegram",
|
|
agentId: "main",
|
|
target: "@alice",
|
|
});
|
|
|
|
expect(route?.sessionKey).toBe("agent:main:telegram:direct:@alice");
|
|
expect(route?.chatType).toBe("direct");
|
|
});
|
|
|
|
it("honors dmScope identity links", async () => {
|
|
const cfg = {
|
|
session: {
|
|
dmScope: "per-peer",
|
|
identityLinks: {
|
|
alice: ["discord:123"],
|
|
},
|
|
},
|
|
} as OpenClawConfig;
|
|
|
|
const route = await resolveOutboundSessionRoute({
|
|
cfg,
|
|
channel: "discord",
|
|
agentId: "main",
|
|
target: "user:123",
|
|
});
|
|
|
|
expect(route?.sessionKey).toBe("agent:main:direct:alice");
|
|
});
|
|
|
|
it("strips chat_* prefixes for BlueBubbles group session keys", async () => {
|
|
const route = await resolveOutboundSessionRoute({
|
|
cfg: baseConfig,
|
|
channel: "bluebubbles",
|
|
agentId: "main",
|
|
target: "chat_guid:ABC123",
|
|
});
|
|
|
|
expect(route?.sessionKey).toBe("agent:main:bluebubbles:group:abc123");
|
|
expect(route?.from).toBe("group:ABC123");
|
|
});
|
|
|
|
it("treats Zalo Personal DM targets as direct sessions", async () => {
|
|
const cfg = { session: { dmScope: "per-channel-peer" } } as OpenClawConfig;
|
|
const route = await resolveOutboundSessionRoute({
|
|
cfg,
|
|
channel: "zalouser",
|
|
agentId: "main",
|
|
target: "123456",
|
|
});
|
|
|
|
expect(route?.sessionKey).toBe("agent:main:zalouser:direct:123456");
|
|
expect(route?.chatType).toBe("direct");
|
|
});
|
|
|
|
it("uses group session keys for Slack mpim allowlist entries", async () => {
|
|
const cfg = {
|
|
channels: {
|
|
slack: {
|
|
dm: {
|
|
groupChannels: ["G123"],
|
|
},
|
|
},
|
|
},
|
|
} as OpenClawConfig;
|
|
|
|
const route = await resolveOutboundSessionRoute({
|
|
cfg,
|
|
channel: "slack",
|
|
agentId: "main",
|
|
target: "channel:G123",
|
|
});
|
|
|
|
expect(route?.sessionKey).toBe("agent:main:slack:group:g123");
|
|
expect(route?.from).toBe("slack:group:G123");
|
|
});
|
|
});
|