





















@@ -1063,28 +1063,39 @@ describe("wildcard peer bindings (peer.id=*)", () => {
1063106310641064describe("binding evaluation cache scalability", () => {
10651065test("does not rescan full bindings after channel/account cache rollover (#36915)", () => {
1066-const bindingCount = 2_001;
1066+const cacheKeyCount = 2_001;
10671067const cfg: OpenClawConfig = {
1068-bindings: Array.from({ length: bindingCount }, (_, idx) => ({
1069-agentId: `agent-${idx}`,
1070-match: {
1071-channel: "dingtalk",
1072-accountId: `acct-${idx}`,
1073-peer: { kind: "direct", id: `user-${idx}` },
1068+bindings: [
1069+{
1070+agentId: "agent-0",
1071+match: {
1072+channel: "dingtalk",
1073+accountId: "acct-0",
1074+peer: { kind: "direct", id: "user-0" },
1075+},
10741076},
1075-})),
1077+],
10761078};
10771079const listBindingsSpy = vi.spyOn(routingBindings, "listBindings");
10781080try {
1079-for (let idx = 0; idx < bindingCount; idx += 1) {
1081+const boundRoute = resolveAgentRoute({
1082+ cfg,
1083+channel: "dingtalk",
1084+accountId: "acct-0",
1085+peer: { kind: "direct", id: "user-0" },
1086+});
1087+expect(boundRoute.agentId).toBe("agent-0");
1088+expect(boundRoute.matchedBy).toBe("binding.peer");
1089+1090+for (let idx = 1; idx < cacheKeyCount; idx += 1) {
10801091const route = resolveAgentRoute({
10811092 cfg,
10821093channel: "dingtalk",
10831094accountId: `acct-${idx}`,
10841095peer: { kind: "direct", id: `user-${idx}` },
10851096});
1086-expect(route.agentId).toBe(`agent-${idx}`);
1087-expect(route.matchedBy).toBe("binding.peer");
1097+expect(route.agentId).toBe("main");
1098+expect(route.matchedBy).toBe("default");
10881099}
1089110010901101const repeated = resolveAgentRoute({
@@ -1099,4 +1110,36 @@ describe("binding evaluation cache scalability", () => {
10991110listBindingsSpy.mockRestore();
11001111}
11011112});
1113+1114+test("uses indexed channel/account bindings without per-route scans", () => {
1115+const bindingCount = 101;
1116+const cfg: OpenClawConfig = {
1117+bindings: Array.from({ length: bindingCount }, (_, idx) => ({
1118+agentId: `agent-${idx}`,
1119+match: {
1120+channel: "dingtalk",
1121+accountId: `acct-${idx}`,
1122+peer: { kind: "direct", id: `user-${idx}` },
1123+},
1124+})),
1125+};
1126+1127+const route = resolveAgentRoute({
1128+ cfg,
1129+channel: "dingtalk",
1130+accountId: "acct-100",
1131+peer: { kind: "direct", id: "user-100" },
1132+});
1133+expect(route.agentId).toBe("agent-100");
1134+expect(route.matchedBy).toBe("binding.peer");
1135+1136+const defaultRoute = resolveAgentRoute({
1137+ cfg,
1138+channel: "dingtalk",
1139+accountId: "acct-missing",
1140+peer: { kind: "direct", id: "user-missing" },
1141+});
1142+expect(defaultRoute.agentId).toBe("main");
1143+expect(defaultRoute.matchedBy).toBe("default");
1144+});
11021145});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。