mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 02:24:31 +00:00
test(telegram): table-drive channel override and id helper cases
This commit is contained in:
@@ -3,65 +3,67 @@ import type { OpenClawConfig } from "../config/config.js";
|
||||
import { resolveChannelModelOverride } from "./model-overrides.js";
|
||||
|
||||
describe("resolveChannelModelOverride", () => {
|
||||
it("matches parent group id when topic suffix is present", () => {
|
||||
const cfg = {
|
||||
channels: {
|
||||
modelByChannel: {
|
||||
telegram: {
|
||||
"-100123": "openai/gpt-4.1",
|
||||
const cases = [
|
||||
{
|
||||
name: "matches parent group id when topic suffix is present",
|
||||
input: {
|
||||
cfg: {
|
||||
channels: {
|
||||
modelByChannel: {
|
||||
telegram: {
|
||||
"-100123": "openai/gpt-4.1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig,
|
||||
channel: "telegram",
|
||||
groupId: "-100123:topic:99",
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
const resolved = resolveChannelModelOverride({
|
||||
cfg,
|
||||
channel: "telegram",
|
||||
groupId: "-100123:topic:99",
|
||||
});
|
||||
|
||||
expect(resolved?.model).toBe("openai/gpt-4.1");
|
||||
expect(resolved?.matchKey).toBe("-100123");
|
||||
});
|
||||
|
||||
it("prefers topic-specific match over parent group id", () => {
|
||||
const cfg = {
|
||||
channels: {
|
||||
modelByChannel: {
|
||||
telegram: {
|
||||
"-100123": "openai/gpt-4.1",
|
||||
"-100123:topic:99": "anthropic/claude-sonnet-4-6",
|
||||
expected: { model: "openai/gpt-4.1", matchKey: "-100123" },
|
||||
},
|
||||
{
|
||||
name: "prefers topic-specific match over parent group id",
|
||||
input: {
|
||||
cfg: {
|
||||
channels: {
|
||||
modelByChannel: {
|
||||
telegram: {
|
||||
"-100123": "openai/gpt-4.1",
|
||||
"-100123:topic:99": "anthropic/claude-sonnet-4-6",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig,
|
||||
channel: "telegram",
|
||||
groupId: "-100123:topic:99",
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
const resolved = resolveChannelModelOverride({
|
||||
cfg,
|
||||
channel: "telegram",
|
||||
groupId: "-100123:topic:99",
|
||||
});
|
||||
|
||||
expect(resolved?.model).toBe("anthropic/claude-sonnet-4-6");
|
||||
expect(resolved?.matchKey).toBe("-100123:topic:99");
|
||||
});
|
||||
|
||||
it("falls back to parent session key when thread id does not match", () => {
|
||||
const cfg = {
|
||||
channels: {
|
||||
modelByChannel: {
|
||||
discord: {
|
||||
"123": "openai/gpt-4.1",
|
||||
expected: { model: "anthropic/claude-sonnet-4-6", matchKey: "-100123:topic:99" },
|
||||
},
|
||||
{
|
||||
name: "falls back to parent session key when thread id does not match",
|
||||
input: {
|
||||
cfg: {
|
||||
channels: {
|
||||
modelByChannel: {
|
||||
discord: {
|
||||
"123": "openai/gpt-4.1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig,
|
||||
channel: "discord",
|
||||
groupId: "999",
|
||||
parentSessionKey: "agent:main:discord:channel:123:thread:456",
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
const resolved = resolveChannelModelOverride({
|
||||
cfg,
|
||||
channel: "discord",
|
||||
groupId: "999",
|
||||
parentSessionKey: "agent:main:discord:channel:123:thread:456",
|
||||
});
|
||||
expected: { model: "openai/gpt-4.1", matchKey: "123" },
|
||||
},
|
||||
] as const;
|
||||
|
||||
expect(resolved?.model).toBe("openai/gpt-4.1");
|
||||
expect(resolved?.matchKey).toBe("123");
|
||||
});
|
||||
for (const testCase of cases) {
|
||||
it(testCase.name, () => {
|
||||
const resolved = resolveChannelModelOverride(testCase.input);
|
||||
expect(resolved?.model).toBe(testCase.expected.model);
|
||||
expect(resolved?.matchKey).toBe(testCase.expected.matchKey);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user