대기실 보완: 만들고 아무도 안 들어간 방도 5분 뒤 정리, 거절된 채팅(도배 방지·빈 메시지)은 nonce를 담아 알려서 "보내는 중" 줄을 지우고 안내

- 회귀 테스트: 서버 2개(수정 전 코드에서 실패 확인), e2e 1단계 추가

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-18 21:12:35 +09:00
parent 735ddd0322
commit af2dce5b50
6 changed files with 51 additions and 7 deletions

View File

@@ -206,10 +206,28 @@ describe('rooms over WebSocket', () => {
await cb.waitFor((m) => m.t === 'chat' && m.line.text === '도배29');
expect(ca.messages.some((m) => m.t === 'error')).toBe(false);
s.settings.setSite({ ...s.settings.getSite(), chatFloodGuard: true, chatRatePerSec: 1, chatBurst: 3 }, a.id);
for (let i = 0; i < 6; i++) ca.send({ t: 'chat', text: `또${i}` });
expect((await errorOf(ca)).message).toContain('너무 빨리');
for (let i = 0; i < 6; i++) ca.send({ t: 'chat', text: `또${i}`, n: `n${i}` });
const refused = await errorOf(ca);
expect(refused.message).toContain('너무 빨리');
await sleep(100);
expect(chatOf(cb).filter((l) => l.text.startsWith('또')).length).toBe(3);
// every refused line names its nonce so the sender can drop its "보내는 중" copy
expect(ca.messages.filter((m) => m.t === 'error').map((m) => (m as { n?: string }).n)).toEqual(['n3', 'n4', 'n5']);
// a line that is empty after cleaning is refused with its nonce too
s.settings.setSite({ ...s.settings.getSite(), chatFloodGuard: false }, a.id);
ca.send({ t: 'chat', text: '\u0007', n: 'blank' });
expect(await ca.waitFor((m) => m.t === 'error' && m.n === 'blank')).toMatchObject({ message: '빈 메시지는 보낼 수 없어요.' });
});
test('a room created but never entered expires like an empty room', async () => {
s = boot();
const a = await guest(s.base, '만들기만');
const code = (await api(s.base, '/api/rooms', { method: 'POST', cookie: a.cookie, body: '{}' })).body.code;
s.rooms.sweep(Date.now() + 60_000);
expect(s.rooms.get(code)).toBeDefined(); // still there for the creator who is on the way in
s.rooms.sweep(Date.now() + 5 * 60_000 + 1000);
expect(s.rooms.get(code)).toBeUndefined();
expect((await api(s.base, `/api/rooms/${code}`)).res.status).toBe(404);
});
test('lobby song count follows catalog changes made by another process', async () => {

View File

@@ -133,6 +133,8 @@ export class RoomManager {
const cfg = applyConfigPatch({ ...DEFAULT_ROOM_CONFIG, title: `${nick}님의 방`.slice(0, 40) }, init);
if (typeof cfg === 'string') return cfg;
const room = new Room(this.newCode(), hostId, cfg, this.deps);
// Empty until someone joins: a room created and never entered expires like any empty room.
room.emptySince = Date.now();
this.rooms.set(room.code, room);
this.deps.log?.('room created', { code: room.code, host: hostId });
return room;
@@ -294,7 +296,7 @@ export class RoomManager {
const room = this.roomOf(ws.data.userId);
if (!room || ws.data.roomCode !== room.code) return '방에 들어가 있지 않아요.';
const t = text.replace(/[\u0000-\u001f\u007f]/g, ' ').trim();
if (!t) return null;
if (!t) return '빈 메시지는 보낼 수 없어요.';
room.say(ws.data.userId, t, n);
return null;
}

View File

@@ -103,9 +103,11 @@ export class Gateway {
if (g?.on) {
let b = this.buckets.get(ws.data.connId);
if (!b) this.buckets.set(ws.data.connId, (b = new TokenBucket(g.ratePerSec, g.burst)));
if (!b.take()) return this.send(ws, { t: 'error', message: '채팅을 너무 빨리 보내고 있어요. 잠깐 쉬었다 보내 주세요.' });
if (!b.take()) return this.send(ws, { t: 'error', message: '채팅을 너무 빨리 보내고 있어요. 잠깐 쉬었다 보내 주세요.', n: m.n });
}
return err(rooms.chat(ws, m.text, m.n));
const e = rooms.chat(ws, m.text, m.n);
if (e) this.send(ws, { t: 'error', message: e, n: m.n });
return;
}
}
},