From 71bdfd201aeda4e821bfcc045464f49b92ceb300 Mon Sep 17 00:00:00 2001 From: EJClaw Date: Wed, 14 Oct 2026 05:03:12 +0900 Subject: [PATCH] =?UTF-8?q?=ED=98=BC=EC=9E=90=EC=9D=B8=20=EB=8C=80?= =?UTF-8?q?=EA=B8=B0=EC=8B=A4=EC=97=90=EC=84=9C=20=EB=B8=8C=EB=9D=BC?= =?UTF-8?q?=EC=9A=B0=EC=A0=80=20=EB=92=A4=EB=A1=9C=EA=B0=80=EA=B8=B0(?= =?UTF-8?q?=ED=99=88)=EB=A1=9C=20=EB=82=98=EA=B0=80=EB=A9=B4=20=EB=B9=88?= =?UTF-8?q?=20=EB=B0=A9=EC=9D=B4=2010=EB=B6=84=20=EB=8F=99=EC=95=88=20?= =?UTF-8?q?=EB=82=A8=EB=8D=98=20=EB=AC=B8=EC=A0=9C:=20=EB=8B=A4=EB=A5=B8?= =?UTF-8?q?=20=EC=82=AC=EB=9E=8C=EC=9D=B4=20=EC=97=86=EA=B3=A0=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84=20=EC=A0=84=EC=9D=B4=EB=A9=B4=20detach=EB=A5=BC=20?= =?UTF-8?q?=EB=82=98=EA=B0=80=EA=B8=B0=EB=A1=9C=20=EC=B2=98=EB=A6=AC?= =?UTF-8?q?=ED=95=B4=20=EB=B0=A9=EC=9D=84=20=EB=B0=94=EB=A1=9C=20=EB=8B=AB?= =?UTF-8?q?=EC=9D=8C.=20=EB=B0=A9=20=EC=95=88=20=F0=9F=93=96=20=EA=B7=9C?= =?UTF-8?q?=EC=B9=99=EB=8F=84=20=ED=8C=9D=EC=97=85=EC=9C=BC=EB=A1=9C(?= =?UTF-8?q?=EA=B7=9C=EC=B9=99=20=ED=8E=98=EC=9D=B4=EC=A7=80=EB=A1=9C=20?= =?UTF-8?q?=EB=84=98=EC=96=B4=EA=B0=80=EB=A9=B0=20=EB=B0=A9=EC=9D=84=20?= =?UTF-8?q?=EB=96=A0=EB=82=98=EC=A7=80=20=EC=95=8A=EA=B2=8C),=20e2e/room-b?= =?UTF-8?q?ack.e2e.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + apps/server/src/guests.test.ts | 41 +++++++++++- apps/server/src/rooms/room.ts | 3 + apps/web/src/pages/RoomPage.tsx | 14 +++- docs/06-lobby-rooms.md | 5 +- e2e/room-back.e2e.ts | 115 ++++++++++++++++++++++++++++++++ 6 files changed, 175 insertions(+), 4 deletions(-) create mode 100644 e2e/room-back.e2e.ts diff --git a/README.md b/README.md index 51bdf14..049f82e 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ bun e2e/replay.e2e.ts # 다시 보기 bun e2e/tutorial.e2e.ts # 처음 하는 사람용 규칙 요약 bun e2e/speed.e2e.ts # 게임 속도 배율: 판 애니메이션 재생 속도와 컴퓨터 응답 시간 bun e2e/settings.e2e.ts # 설정 팝업: 게임 중에 열어도 방에서 나가지 않음, 바로 적용, 닫기·포커스 +bun e2e/room-back.e2e.ts # 혼자인 대기실에서 뒤로가기 → 빈 방 바로 닫힘, 친구가 있으면 자리 유지, 규칙 팝업 bun scripts/loadtest.ts --help # 부하·장애 주입 (docs/reports 참고) ``` diff --git a/apps/server/src/guests.test.ts b/apps/server/src/guests.test.ts index 0f22835..f61d5ad 100644 --- a/apps/server/src/guests.test.ts +++ b/apps/server/src/guests.test.ts @@ -93,12 +93,51 @@ describe('idle guests', () => { }); describe('leaving the room page', () => { - test('detach keeps the seat but the room no longer counts the connection', async () => { + test('alone with no game running (뒤로가기 from the lobby): leaving the page leaves the room and it closes at once', async () => { + const s = start(); + const g = await guest(s.base, '혼자'); + const c = await connect(s, g); + const r = await api(s.base, '/api/rooms', { method: 'POST', cookie: c.cookie, body: JSON.stringify({ gameId: 'omok' }) }); + c.send({ t: 'join', code: r.body.code, as: 'player' }); + await c.waitFor((m) => m.t === 'room'); + expect(s.rooms.get(r.body.code)).toBeDefined(); + c.send({ t: 'detach' }); + for (let i = 0; i < 50 && s.rooms.get(r.body.code); i++) await sleep(10); + expect(s.rooms.get(r.body.code)).toBeUndefined(); + expect(s.rooms.activeRoomFor(g.id)).toBeNull(); + // The same socket is fine afterwards. + c.send({ t: 'ping', ts: 1 }); + await c.waitFor((m) => m.t === 'pong'); + }); + + test('someone else is in the lobby: leaving the page keeps my seat (I can come back)', async () => { + const s = start(); + const a = await guest(s.base, '방장'); + const b = await guest(s.base, '친구'); + const ca = await connect(s, a); + const cb = await connect(s, b); + const r = await api(s.base, '/api/rooms', { method: 'POST', cookie: ca.cookie, body: JSON.stringify({ gameId: 'omok' }) }); + ca.send({ t: 'join', code: r.body.code, as: 'player' }); + await ca.waitFor((m) => m.t === 'room'); + cb.send({ t: 'join', code: r.body.code, as: 'player' }); + await cb.waitFor((m) => m.t === 'room'); + const room = s.rooms.get(r.body.code)!; + ca.send({ t: 'detach' }); + for (let i = 0; i < 50 && room.conns.size > 1; i++) await sleep(10); + expect(room.conns.size).toBe(1); + expect(room.seatOf(a.id)).toBeGreaterThanOrEqual(0); + expect(s.rooms.get(r.body.code)).toBe(room); + }); + + test('detach during a game keeps the seat but the room no longer counts the connection', async () => { const s = start(); const g = await guest(s.base, '홈으로'); const c = await connect(s, g); const code = await practiceRoom(s, c); const room = s.rooms.get(code)!; + c.send({ t: 'start' }); + for (let i = 0; i < 50 && room.status !== 'playing'; i++) await sleep(10); + expect(room.status).toBe('playing'); expect(room.conns.size).toBe(1); c.send({ t: 'detach' }); for (let i = 0; i < 50 && room.conns.size; i++) await sleep(10); diff --git a/apps/server/src/rooms/room.ts b/apps/server/src/rooms/room.ts index 81a10a8..cd4fb8b 100644 --- a/apps/server/src/rooms/room.ts +++ b/apps/server/src/rooms/room.ts @@ -546,6 +546,9 @@ export class Room { const u = conn.userId; if (this.conns.get(u) !== conn) return; if (this.spectators.has(u)) return this.disconnect(conn); + // Alone in the lobby: nobody to come back to, so leaving the page (뒤로가기, 홈) leaves the room and the empty room + // closes now instead of lingering (2026-10-14). A game (running, or its result: 다시 보기 comes back) keeps the seat. + if (this.status === 'lobby' && this.conns.size === 1 && !this.seatedIds().some((x) => x !== u && !isBotId(x) && !this.leftDuringGame.has(x))) return this.leave(u); this.conns.delete(u); this.detached.set(u, conn); if (this.conns.size === 0) this.becameEmpty('disconnect'); diff --git a/apps/web/src/pages/RoomPage.tsx b/apps/web/src/pages/RoomPage.tsx index b38af28..06bc530 100644 --- a/apps/web/src/pages/RoomPage.tsx +++ b/apps/web/src/pages/RoomPage.tsx @@ -98,6 +98,8 @@ function Room({ code, me }: { code: string; me: PublicUser }) { // 설정 opens as a popup over the room: going to /me would unmount the room and detach from it. const [settingsOpen, setSettingsOpen] = useState(false); const closeSettings = useCallback(() => setSettingsOpen(false), []); + // 규칙 too: going to /rules would leave the room page (and, alone in a lobby, the room itself). + const [rulesOpen, setRulesOpen] = useState(false); // [한 판 더] takes me back to this room's lobby after game N (kept per tab so a reload stays there). const lobbyKey = `bg:lobby:${code}`; const [lobbyAfter, setLobbyAfter] = useState(() => Number(sessionStorage.getItem(lobbyKey)) || null); @@ -217,7 +219,7 @@ function Room({ code, me }: { code: string; me: PublicUser }) { )} - @@ -247,6 +249,16 @@ function Room({ code, me }: { code: string; me: PublicUser }) { )} {settingsOpen && } + {rulesOpen && ( + setRulesOpen(false)} label={`${gameName(room.gameId)} 규칙`}> +

{gameName(room.gameId)} 규칙

+ + {ui ? :

불러오는 중…

} + +
+ )} {leaveAsk && ( {}, + staticDir: join(import.meta.dir, '../apps/web/dist'), +}); + +const browser = await chromium.launch({ executablePath: process.env.CHROME ?? '/usr/bin/google-chrome', headless: true }); +let failed = false; +const step = async (name: string, fn: () => Promise) => { + const t0 = performance.now(); + try { + await fn(); + console.log(`✓ ${name} (${Math.round(performance.now() - t0)}ms)`); + } catch (e) { + failed = true; + console.log(`✗ ${name}: ${(e as Error).message.split('\n')[0]}`); + throw e; + } +}; + +async function makeRoom(p: Page, name?: string): Promise { + await p.goto(ORIGIN + '/'); + await p.getByRole('button', { name: '+ 방 만들기' }).click(); + await p.getByRole('dialog', { name: '게임 고르기' }).getByRole('button', { name: /오목/ }).click(); + if (name) { + await p.getByLabel('내 이름(닉네임)').fill(name); + await p.getByRole('button', { name: '이 이름으로 시작하기' }).click(); + } + await p.waitForURL(/\/r\/\d{6}$/); + await p.getByRole('button', { name: '규칙 보기' }).waitFor(); + return p.url().slice(-6); +} +const roomOpen = async (code: string) => { + const r = await fetch(`${ORIGIN}/api/rooms/${code}`); + if (r.status !== 200 && r.status !== 404) throw new Error(`room lookup ${r.status}`); + return r.ok; +}; + +try { + const ctxA = await browser.newContext({ viewport: { width: 1440, height: 900 }, locale: 'ko-KR' }); + const ctxB = await browser.newContext({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true, locale: 'ko-KR' }); + const a = await ctxA.newPage(); + const b = await ctxB.newPage(); + const errors: string[] = []; + for (const p of [a, b]) p.on('pageerror', (e) => errors.push(e.message)); + for (const p of [a, b]) await p.addInitScript(() => localStorage.setItem('bg:qs:omok', '1')); + + let code = ''; + await step('혼자 방 만들기 → 📖 규칙은 팝업(주소 그대로, 방 그대로)', async () => { + code = await makeRoom(a, '호랑이'); + await a.getByRole('button', { name: '규칙 보기' }).click(); + const sheet = a.getByRole('dialog', { name: '오목 규칙' }); + await sheet.waitFor(); + if (!a.url().endsWith(`/r/${code}`)) throw new Error(`navigated to ${a.url()}`); + await a.waitForTimeout(600); + await a.screenshot({ path: join(SHOTS, 'room-rules-popup.png') }); + await sheet.getByRole('button', { name: '닫기' }).click(); + if (!(await roomOpen(code))) throw new Error('the room closed while reading the rules'); + }); + + await step('혼자인 대기실에서 브라우저 뒤로가기 → 홈, 방이 바로 없어짐', async () => { + await a.goBack(); + await a.waitForURL(ORIGIN + '/'); + for (let i = 0; i < 6 && (await roomOpen(code)); i++) await a.waitForTimeout(500); + if (await roomOpen(code)) throw new Error('the empty room is still open'); + await a.reload(); + await a.getByRole('button', { name: '+ 방 만들기' }).waitFor(); + if (await a.getByText(/하던 게임으로 돌아가기/).count()) throw new Error('home still offers to go back to the room'); + await a.screenshot({ path: join(SHOTS, 'room-back-home.png') }); + }); + + await step('친구가 있는 대기실에서 뒤로가기 → 내 자리는 남고, 다시 들어갈 수 있음', async () => { + code = await makeRoom(a); + await b.goto(`${ORIGIN}/r/${code}`); + await b.getByLabel('내 이름(닉네임)').fill('고양이'); + await b.getByRole('button', { name: '이 이름으로 입장하기' }).click(); + await a.getByLabel('자리').getByText('고양이').waitFor(); + await a.goBack(); + await a.waitForURL(ORIGIN + '/'); + await a.waitForTimeout(500); + if (!(await roomOpen(code))) throw new Error('the room closed although a friend is in it'); + await b.getByLabel('자리').getByText('호랑이').waitFor({ timeout: 3000 }); + await a.goForward(); + await a.waitForURL(`${ORIGIN}/r/${code}`); + await a.getByLabel('자리').getByText('고양이').waitFor(); + }); + + if (errors.length) throw new Error(`page errors: ${errors.join(' | ')}`); +} catch (e) { + failed = true; + console.log(String((e as Error).stack ?? e)); +} finally { + await browser.close(); + await app.stop(); +} +console.log(failed ? 'E2E FAILED' : 'E2E PASSED'); +process.exit(failed ? 1 : 0);