Allow replies during room creation cooldowns

This commit is contained in:
jjbrunton committed 2026-08-09 16:22:48 +01:00
1 parent c630303b47
commit 910576921b
3 files changed
+55 -6

No files matched your search

+29
View File
@@ -115,6 +115,35 @@ describe('ChatService invitation cooldown', () => {
expect(result).toBe(false);
});
it('allows replies in existing rooms during a room-creation cooldown', async () => {
const { svc, matrix } = buildService();
matrix.sendTextMessage = async () => '$reply';
svc.setInvitationCooldown(
new MatrixRateLimitError(
'429',
60_000,
'M_LIMIT_EXCEEDED',
'rate.room_creation_limit',
),
);
// Simulate a cooldown persisted before operation scopes were recorded.
delete svc.getInvitationCooldown()!.scope;
await expect(svc.sendChatMessage('!room:example.test', 'hi')).resolves.toBe(true);
});
it('treats a generic limit raised while creating a room as room-creation-only', async () => {
const { svc, matrix } = buildService();
matrix.sendInitialDirectMessage = async () => {
throw new MatrixRateLimitError('429', 60_000, 'M_LIMIT_EXCEEDED', null);
};
matrix.sendTextMessage = async () => '$reply';
await expect(svc.startConversationDetailed('someuser', 'opener', 't2_someuser'))
.resolves.toMatchObject({ status: 'retryable' });
await expect(svc.sendChatMessage('!room:example.test', 'reply')).resolves.toBe(true);
});
it('persists the cooldown to disk and restores it after a fresh service load', async () => {
const logger = createMockLogger();
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'chat-cooldown-'));