fix(moderation): policy viewer lists a stable rule and its legacy twin once (#321) #392

Merged
jared merged 1 commits from fix/policy-dedupe into lotus 2026-10-18 02:05:13 -04:00
Owner

Fixes #321.

dedupePolicyEntries keyed on `${entity} ${recommendation}` using the raw recommendation. A bot's stable rule (m.ban) and its legacy twin (org.matrix.mjolnir.ban) for the same entity therefore never matched, and the viewer listed the rule twice, both labelled "Ban".

Change

  • New normalizeRecommendation (org.matrix.mjolnir.ban → m.ban), used both for the de-dup key and for recommendationLabel.
  • The pure helpers (PolicyEntry, recommendationLabel, dedupePolicyEntries) move to policyEntries.ts so they can be unit-tested. The viewer's rendering is unchanged.

Tests: the issue's exact case, @spammer:evil.example under both m.ban and org.matrix.mjolnir.ban plus a glob rule, now gives 2 entries instead of 3. Different recommendations for one entity stay separate, and there are label cases. No UI run: this is a pure keying change covered by the unit test.

tsc clean · ESLint clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5

Fixes #321. `dedupePolicyEntries` keyed on `` `${entity} ${recommendation}` `` using the **raw** recommendation. A bot's stable rule (`m.ban`) and its legacy twin (`org.matrix.mjolnir.ban`) for the same entity therefore never matched, and the viewer listed the rule twice, both labelled "Ban". **Change** - New `normalizeRecommendation` (`org.matrix.mjolnir.ban` → `m.ban`), used both for the de-dup key and for `recommendationLabel`. - The pure helpers (`PolicyEntry`, `recommendationLabel`, `dedupePolicyEntries`) move to `policyEntries.ts` so they can be unit-tested. The viewer's rendering is unchanged. **Tests:** the issue's exact case, `@spammer:evil.example` under both `m.ban` and `org.matrix.mjolnir.ban` plus a glob rule, now gives 2 entries instead of 3. Different recommendations for one entity stay separate, and there are label cases. No UI run: this is a pure keying change covered by the unit test. `tsc` clean · ESLint clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
jared added 1 commit 2026-10-17 20:28:39 -04:00
fix(moderation): policy viewer lists a stable rule and its legacy twin once (#321)
CI / Build & Quality Checks (pull_request) Successful in 3m0s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 15s
CI / Playwright smoke (e2e) (pull_request) Successful in 15m30s
15f2fcc4d1
dedupePolicyEntries keyed on the raw recommendation, so m.ban and
org.matrix.mjolnir.ban for the same entity never matched and the rule
showed twice (both labelled "Ban"). Key on the normalised value; move
the pure helpers to policyEntries.ts with unit tests.

Fixes #321

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
jared merged commit ea5a0d4906 into lotus 2026-10-18 02:05:13 -04:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/cinny#392