fix(routing): treat group/channel peer.kind as equivalent (land #31135 by @Sid-Qin)

Landed-from: #31135
Contributor: @Sid-Qin
Co-authored-by: Sid <sidqin0410@gmail.com>
This commit is contained in:
Peter Steinberger
2026-03-02 01:46:46 +00:00
parent e076665e5e
commit 70ee256ae0
3 changed files with 82 additions and 1 deletions

View File

@@ -547,6 +547,74 @@ describe("backward compatibility: peer.kind dm → direct", () => {
});
});
describe("backward compatibility: peer.kind group ↔ channel", () => {
test("config group binding matches runtime channel scope", () => {
const cfg: OpenClawConfig = {
bindings: [
{
agentId: "slack-group-agent",
match: {
channel: "slack",
peer: { kind: "group", id: "C123456" },
},
},
],
};
const route = resolveAgentRoute({
cfg,
channel: "slack",
accountId: null,
peer: { kind: "channel", id: "C123456" },
});
expect(route.agentId).toBe("slack-group-agent");
expect(route.matchedBy).toBe("binding.peer");
});
test("config channel binding matches runtime group scope", () => {
const cfg: OpenClawConfig = {
bindings: [
{
agentId: "slack-channel-agent",
match: {
channel: "slack",
peer: { kind: "channel", id: "C123456" },
},
},
],
};
const route = resolveAgentRoute({
cfg,
channel: "slack",
accountId: null,
peer: { kind: "group", id: "C123456" },
});
expect(route.agentId).toBe("slack-channel-agent");
expect(route.matchedBy).toBe("binding.peer");
});
test("group/channel compatibility does not match direct peer kind", () => {
const cfg: OpenClawConfig = {
bindings: [
{
agentId: "group-only-agent",
match: {
channel: "slack",
peer: { kind: "group", id: "C123456" },
},
},
],
};
const route = resolveAgentRoute({
cfg,
channel: "slack",
accountId: null,
peer: { kind: "direct", id: "C123456" },
});
expect(route.agentId).toBe("main");
expect(route.matchedBy).toBe("default");
});
});
describe("role-based agent routing", () => {
type DiscordBinding = NonNullable<OpenClawConfig["bindings"]>[number];