test: debrand generic channel fixture names

This commit is contained in:
Peter Steinberger
2026-03-27 21:47:31 +00:00
parent f09b449ab1
commit 03e7e3cd27
3 changed files with 57 additions and 52 deletions

View File

@@ -15,23 +15,23 @@ describe("resolveConversationLabel", () => {
ThreadLabel: "Thread Alpha",
ChatType: "group",
GroupSubject: "Ops",
From: "telegram:group:42",
From: "demo-channel:group:42",
},
expected: "Thread Alpha",
},
{
name: "uses SenderName for direct chats when available",
ctx: { ChatType: "direct", SenderName: "Ada", From: "telegram:99" },
ctx: { ChatType: "direct", SenderName: "Ada", From: "demo-channel:99" },
expected: "Ada",
},
{
name: "falls back to From for direct chats when SenderName is missing",
ctx: { ChatType: "direct", From: "telegram:99" },
expected: "telegram:99",
ctx: { ChatType: "direct", From: "demo-channel:99" },
expected: "demo-channel:99",
},
{
name: "derives Telegram-like group labels with numeric id suffix",
ctx: { ChatType: "group", GroupSubject: "Ops", From: "telegram:group:42" },
name: "derives numeric-id group labels",
ctx: { ChatType: "group", GroupSubject: "Ops", From: "demo-channel:group:42" },
expected: "Ops id:42",
},
{

View File

@@ -10,16 +10,16 @@ describe("resolveChannelModelOverride", () => {
cfg: {
channels: {
modelByChannel: {
telegram: {
"-100123": "openai/gpt-5.4",
"demo-group": {
"-100123": "demo-provider/demo-parent-model",
},
},
},
} as unknown as OpenClawConfig,
channel: "telegram",
channel: "demo-group",
groupId: "-100123:topic:99",
},
expected: { model: "openai/gpt-5.4", matchKey: "-100123" },
expected: { model: "demo-provider/demo-parent-model", matchKey: "-100123" },
},
{
name: "prefers topic-specific match over parent group id",
@@ -27,17 +27,17 @@ describe("resolveChannelModelOverride", () => {
cfg: {
channels: {
modelByChannel: {
telegram: {
"-100123": "openai/gpt-5.4",
"-100123:topic:99": "anthropic/claude-sonnet-4-6",
"demo-group": {
"-100123": "demo-provider/demo-parent-model",
"-100123:topic:99": "demo-provider/demo-topic-model",
},
},
},
} as unknown as OpenClawConfig,
channel: "telegram",
channel: "demo-group",
groupId: "-100123:topic:99",
},
expected: { model: "anthropic/claude-sonnet-4-6", matchKey: "-100123:topic:99" },
expected: { model: "demo-provider/demo-topic-model", matchKey: "-100123:topic:99" },
},
{
name: "falls back to parent session key when thread id does not match",
@@ -45,17 +45,17 @@ describe("resolveChannelModelOverride", () => {
cfg: {
channels: {
modelByChannel: {
discord: {
"123": "openai/gpt-5.4",
"demo-thread": {
"123": "demo-provider/demo-parent-model",
},
},
},
} as unknown as OpenClawConfig,
channel: "discord",
channel: "demo-thread",
groupId: "999",
parentSessionKey: "agent:main:discord:channel:123:thread:456",
parentSessionKey: "agent:main:demo-thread:channel:123:thread:456",
},
expected: { model: "openai/gpt-5.4", matchKey: "123" },
expected: { model: "demo-provider/demo-parent-model", matchKey: "123" },
},
] as const;

View File

@@ -13,12 +13,12 @@ describe("delivery context helpers", () => {
it("normalizes channel/to/accountId and drops empty contexts", () => {
expect(
normalizeDeliveryContext({
channel: " whatsapp ",
channel: " demo-channel ",
to: " +1555 ",
accountId: " acct-1 ",
}),
).toEqual({
channel: "whatsapp",
channel: "demo-channel",
to: "+1555",
accountId: "acct-1",
});
@@ -28,12 +28,12 @@ describe("delivery context helpers", () => {
it("does not inherit route fields from fallback when channels conflict", () => {
const merged = mergeDeliveryContext(
{ channel: "telegram" },
{ channel: "discord", to: "channel:def", accountId: "acct", threadId: "99" },
{ channel: "demo-primary" },
{ channel: "demo-fallback", to: "channel:def", accountId: "acct", threadId: "99" },
);
expect(merged).toEqual({
channel: "telegram",
channel: "demo-primary",
to: undefined,
accountId: undefined,
});
@@ -42,12 +42,12 @@ describe("delivery context helpers", () => {
it("inherits missing route fields when channels match", () => {
const merged = mergeDeliveryContext(
{ channel: "telegram" },
{ channel: "telegram", to: "123", accountId: "acct", threadId: "99" },
{ channel: "demo-channel" },
{ channel: "demo-channel", to: "123", accountId: "acct", threadId: "99" },
);
expect(merged).toEqual({
channel: "telegram",
channel: "demo-channel",
to: "123",
accountId: "acct",
threadId: "99",
@@ -56,12 +56,12 @@ describe("delivery context helpers", () => {
it("uses fallback route fields when fallback has no channel", () => {
const merged = mergeDeliveryContext(
{ channel: "telegram" },
{ channel: "demo-channel" },
{ to: "123", accountId: "acct", threadId: "99" },
);
expect(merged).toEqual({
channel: "telegram",
channel: "demo-channel",
to: "123",
accountId: "acct",
threadId: "99",
@@ -69,20 +69,25 @@ describe("delivery context helpers", () => {
});
it("builds stable keys only when channel and to are present", () => {
expect(deliveryContextKey({ channel: "whatsapp", to: "+1555" })).toBe("whatsapp|+1555||");
expect(deliveryContextKey({ channel: "whatsapp" })).toBeUndefined();
expect(deliveryContextKey({ channel: "whatsapp", to: "+1555", accountId: "acct-1" })).toBe(
"whatsapp|+1555|acct-1|",
expect(deliveryContextKey({ channel: "demo-channel", to: "+1555" })).toBe(
"demo-channel|+1555||",
);
expect(deliveryContextKey({ channel: "slack", to: "channel:C1", threadId: "123.456" })).toBe(
"slack|channel:C1||123.456",
expect(deliveryContextKey({ channel: "demo-channel" })).toBeUndefined();
expect(deliveryContextKey({ channel: "demo-channel", to: "+1555", accountId: "acct-1" })).toBe(
"demo-channel|+1555|acct-1|",
);
expect(
deliveryContextKey({ channel: "demo-channel", to: "channel:C1", threadId: "123.456" }),
).toBe("demo-channel|channel:C1||123.456");
});
it("formats generic non-matrix conversation targets as channels", () => {
expect(formatConversationTarget({ channel: "demo-channel", conversationId: "123" })).toBe(
"channel:123",
);
});
it("formats channel-aware conversation targets", () => {
expect(formatConversationTarget({ channel: "discord", conversationId: "123" })).toBe(
"channel:123",
);
it("formats matrix conversation targets as rooms", () => {
expect(formatConversationTarget({ channel: "matrix", conversationId: "!room:example" })).toBe(
"room:!room:example",
);
@@ -113,24 +118,24 @@ describe("delivery context helpers", () => {
expect(
deliveryContextFromSession({
channel: "webchat",
lastChannel: " whatsapp ",
lastChannel: " demo-channel ",
lastTo: " +1777 ",
lastAccountId: " acct-9 ",
}),
).toEqual({
channel: "whatsapp",
channel: "demo-channel",
to: "+1777",
accountId: "acct-9",
});
expect(
deliveryContextFromSession({
channel: "telegram",
channel: "demo-channel",
lastTo: " 123 ",
lastThreadId: " 999 ",
}),
).toEqual({
channel: "telegram",
channel: "demo-channel",
to: "123",
accountId: undefined,
threadId: "999",
@@ -138,12 +143,12 @@ describe("delivery context helpers", () => {
expect(
deliveryContextFromSession({
channel: "telegram",
channel: "demo-channel",
lastTo: " -1001 ",
origin: { threadId: 42 },
}),
).toEqual({
channel: "telegram",
channel: "demo-channel",
to: "-1001",
accountId: undefined,
threadId: 42,
@@ -151,13 +156,13 @@ describe("delivery context helpers", () => {
expect(
deliveryContextFromSession({
channel: "telegram",
channel: "demo-channel",
lastTo: " -1001 ",
deliveryContext: { threadId: " 777 " },
origin: { threadId: 42 },
}),
).toEqual({
channel: "telegram",
channel: "demo-channel",
to: "-1001",
accountId: undefined,
threadId: "777",
@@ -167,21 +172,21 @@ describe("delivery context helpers", () => {
it("normalizes delivery fields, mirrors session fields, and avoids cross-channel carryover", () => {
const normalized = normalizeSessionDeliveryFields({
deliveryContext: {
channel: " Slack ",
channel: " demo-fallback ",
to: " channel:1 ",
accountId: " acct-2 ",
threadId: " 444 ",
},
lastChannel: " whatsapp ",
lastChannel: " demo-primary ",
lastTo: " +1555 ",
});
expect(normalized.deliveryContext).toEqual({
channel: "whatsapp",
channel: "demo-primary",
to: "+1555",
accountId: undefined,
});
expect(normalized.lastChannel).toBe("whatsapp");
expect(normalized.lastChannel).toBe("demo-primary");
expect(normalized.lastTo).toBe("+1555");
expect(normalized.lastAccountId).toBeUndefined();
expect(normalized.lastThreadId).toBeUndefined();