perf: use normalized ClickClack group lookups

This commit is contained in:
Shakker
2026-07-30 04:21:03 +01:00
parent cd60d65f0a
commit e95fe13eb2
2 changed files with 4 additions and 10 deletions
@@ -117,16 +117,12 @@ describe("resolveClickClackGroupPolicy", () => {
expect(result.requireMention).toBe(false);
});
it("trims channel id keys", () => {
// Edge case: leading/trailing whitespace is trimmed during resolution
// but our test passes raw channelId as is; exact match requires
// the trimmed key. The resolver does not trim; the caller must trim.
// Validating that untrimmed exact match works.
it("trims inbound channel ids before lookup", () => {
const result = resolveClickClackGroupPolicy({
account: {
groups: { "chn_exact ": { requireMention: true } },
groups: { chn_exact: { requireMention: true } },
},
channelId: "chn_exact ",
channelId: " chn_exact ",
});
expect(result.requireMention).toBe(true);
});
+1 -3
View File
@@ -35,9 +35,7 @@ export function resolveClickClackGroupPolicy(params: {
};
const wildcard = account.groups?.["*"];
const channelKey = channelId?.trim();
const exact = channelKey
? Object.entries(account.groups ?? {}).find(([key]) => key.trim() === channelKey)?.[1]
: undefined;
const exact = channelKey ? account.groups?.[channelKey] : undefined;
// Channel rules are partial overrides. Resolve each field independently so
// an exact channel rule can inherit unspecified fields from the wildcard
// rule before falling back to the account-level policy.