test: add suites for utils/room (40) + plugins/matrix-to (7)

- utils/room (40, via subagent): 28 helpers — state-event accessors, m.direct
  parsing, space/room classification, parent/child graph (incl. cycle safety),
  mute-rule + notification logic, unread info, reply trimming, member display/
  avatar/search, reaction/edit/mention extraction, room-icon branches. SDK/
  crypto-heavy helpers skipped. No bugs found.
- plugins/matrix-to (7): matrix.to permalink build + parse for user/room/event
  including via-server round-trips and negative cases.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-30 14:28:32 -04:00
parent d37fa1584c
commit 0bd2273bee
2 changed files with 659 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import {
getMatrixToUser,
getMatrixToRoom,
getMatrixToRoomEvent,
testMatrixTo,
parseMatrixToUser,
parseMatrixToRoom,
parseMatrixToRoomEvent,
} from './matrix-to';
test('getMatrixToUser builds a user permalink', () => {
assert.equal(getMatrixToUser('@alice:example.org'), 'https://matrix.to/#/@alice:example.org');
});
test('getMatrixToRoom builds room links with optional via servers', () => {
assert.equal(getMatrixToRoom('#room:example.org'), 'https://matrix.to/#/#room:example.org');
assert.equal(
getMatrixToRoom('!abc:example.org', ['a.org', 'b.org']),
'https://matrix.to/#/!abc:example.org?via=a.org&via=b.org',
);
// empty via array → no query string
assert.equal(getMatrixToRoom('!abc:example.org', []), 'https://matrix.to/#/!abc:example.org');
});
test('getMatrixToRoomEvent builds event links', () => {
assert.equal(
getMatrixToRoomEvent('!abc:example.org', '$evt', ['a.org']),
'https://matrix.to/#/!abc:example.org/$evt?via=a.org',
);
assert.equal(
getMatrixToRoomEvent('!abc:example.org', '$evt'),
'https://matrix.to/#/!abc:example.org/$evt',
);
});
test('testMatrixTo recognizes matrix.to hrefs', () => {
assert.equal(testMatrixTo('https://matrix.to/#/@a:b.org'), true);
assert.equal(testMatrixTo('http://matrix.to/#/!r:b.org'), true);
assert.equal(testMatrixTo('https://example.org/#/@a:b.org'), false);
});
test('parseMatrixToUser round-trips and rejects non-user links', () => {
assert.equal(parseMatrixToUser(getMatrixToUser('@a:b.org')), '@a:b.org');
assert.equal(parseMatrixToUser('https://matrix.to/#/@a:b.org/'), '@a:b.org'); // trailing slash ok
assert.equal(parseMatrixToUser('https://matrix.to/#/#room:b.org'), undefined);
assert.equal(parseMatrixToUser('https://example.org'), undefined);
});
test('parseMatrixToRoom extracts alias/id and via servers', () => {
assert.deepEqual(parseMatrixToRoom('https://matrix.to/#/#room:b.org'), {
roomIdOrAlias: '#room:b.org',
viaServers: undefined,
});
assert.deepEqual(parseMatrixToRoom(getMatrixToRoom('!abc:b.org', ['a.org', 'c.org'])), {
roomIdOrAlias: '!abc:b.org',
viaServers: ['a.org', 'c.org'],
});
// a user link is not a room link
assert.equal(parseMatrixToRoom('https://matrix.to/#/@a:b.org'), undefined);
});
test('parseMatrixToRoomEvent extracts room, event, and via servers', () => {
assert.deepEqual(parseMatrixToRoomEvent(getMatrixToRoomEvent('!abc:b.org', '$e', ['a.org'])), {
roomIdOrAlias: '!abc:b.org',
eventId: '$e',
viaServers: ['a.org'],
});
assert.deepEqual(parseMatrixToRoomEvent('https://matrix.to/#/!abc:b.org/$e'), {
roomIdOrAlias: '!abc:b.org',
eventId: '$e',
viaServers: undefined,
});
// a room-only link has no event
assert.equal(parseMatrixToRoomEvent('https://matrix.to/#/!abc:b.org'), undefined);
});