mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 04:47:26 +00:00
fix(feishu): honor wildcard group config for reply policy (#29456)
## Summary - honor Feishu wildcard group policy fallback via `channels.feishu.groups["*"]` when no explicit group entry matches - keep exact and case-insensitive explicit group matches higher precedence than wildcard fallback - add changelog credit and TypeScript-safe test assertions ## Verification - pnpm install --frozen-lockfile - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: Wayne Pika <262095977+WaynePika@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,62 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isFeishuGroupAllowed, resolveFeishuAllowlistMatch } from "./policy.js";
|
||||
import {
|
||||
isFeishuGroupAllowed,
|
||||
resolveFeishuAllowlistMatch,
|
||||
resolveFeishuGroupConfig,
|
||||
} from "./policy.js";
|
||||
import type { FeishuConfig } from "./types.js";
|
||||
|
||||
describe("feishu policy", () => {
|
||||
describe("resolveFeishuGroupConfig", () => {
|
||||
it("falls back to wildcard group config when direct match is missing", () => {
|
||||
const cfg = {
|
||||
groups: {
|
||||
"*": { requireMention: false },
|
||||
"oc-explicit": { requireMention: true },
|
||||
},
|
||||
} as unknown as FeishuConfig;
|
||||
|
||||
const resolved = resolveFeishuGroupConfig({
|
||||
cfg,
|
||||
groupId: "oc-missing",
|
||||
});
|
||||
|
||||
expect(resolved).toEqual({ requireMention: false });
|
||||
});
|
||||
|
||||
it("prefers exact group config over wildcard", () => {
|
||||
const cfg = {
|
||||
groups: {
|
||||
"*": { requireMention: false },
|
||||
"oc-explicit": { requireMention: true },
|
||||
},
|
||||
} as unknown as FeishuConfig;
|
||||
|
||||
const resolved = resolveFeishuGroupConfig({
|
||||
cfg,
|
||||
groupId: "oc-explicit",
|
||||
});
|
||||
|
||||
expect(resolved).toEqual({ requireMention: true });
|
||||
});
|
||||
|
||||
it("keeps case-insensitive matching for explicit group ids", () => {
|
||||
const cfg = {
|
||||
groups: {
|
||||
"*": { requireMention: false },
|
||||
OC_UPPER: { requireMention: true },
|
||||
},
|
||||
} as unknown as FeishuConfig;
|
||||
|
||||
const resolved = resolveFeishuGroupConfig({
|
||||
cfg,
|
||||
groupId: "oc_upper",
|
||||
});
|
||||
|
||||
expect(resolved).toEqual({ requireMention: true });
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveFeishuAllowlistMatch", () => {
|
||||
it("allows wildcard", () => {
|
||||
expect(
|
||||
|
||||
@@ -56,6 +56,7 @@ export function resolveFeishuGroupConfig(params: {
|
||||
groupId?: string | null;
|
||||
}): FeishuGroupConfig | undefined {
|
||||
const groups = params.cfg?.groups ?? {};
|
||||
const wildcard = groups["*"];
|
||||
const groupId = params.groupId?.trim();
|
||||
if (!groupId) {
|
||||
return undefined;
|
||||
@@ -68,7 +69,10 @@ export function resolveFeishuGroupConfig(params: {
|
||||
|
||||
const lowered = groupId.toLowerCase();
|
||||
const matchKey = Object.keys(groups).find((key) => key.toLowerCase() === lowered);
|
||||
return matchKey ? groups[matchKey] : undefined;
|
||||
if (matchKey) {
|
||||
return groups[matchKey];
|
||||
}
|
||||
return wildcard;
|
||||
}
|
||||
|
||||
export function resolveFeishuGroupToolPolicy(
|
||||
|
||||
Reference in New Issue
Block a user