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
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
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { dedupePolicyEntries, recommendationLabel } from './policyEntries';
|
|
|
|
const e = (entity: string, recommendation: string, stateKey = entity) => ({
|
|
entity,
|
|
reason: 'spam waves',
|
|
recommendation,
|
|
stateKey,
|
|
});
|
|
|
|
test('dedupePolicyEntries: a stable rule and its legacy twin show once (#321)', () => {
|
|
const out = dedupePolicyEntries([
|
|
e('@spammer:evil.example', 'm.ban'),
|
|
e('@spammer:evil.example', 'org.matrix.mjolnir.ban'),
|
|
e('@*:spam.example', 'm.ban'),
|
|
]);
|
|
assert.deepEqual(
|
|
out.map((x) => x.entity),
|
|
['@spammer:evil.example', '@*:spam.example'],
|
|
);
|
|
});
|
|
|
|
test('dedupePolicyEntries: different recommendations stay separate', () => {
|
|
assert.equal(dedupePolicyEntries([e('@a:x', 'm.ban'), e('@a:x', 'org.example.mute')]).length, 2);
|
|
});
|
|
|
|
test('recommendationLabel', () => {
|
|
assert.equal(recommendationLabel('m.ban'), 'Ban');
|
|
assert.equal(recommendationLabel('org.matrix.mjolnir.ban'), 'Ban');
|
|
assert.equal(recommendationLabel('org.example.mute'), 'org.example.mute');
|
|
});
|