제한 시간 보정 2: 같은 마감 안에서는 투표로 답할 사람이 줄어도 준 시간 유지, 마감은 남은 답할 사람 중 가장 늦은 화면 기준, 자체 시계를 쓰는 게임도 늘어난 마감을 표시

- room: reveal 단계 키를 게임 마감만으로, clockExtra = max(본인, 답할 사람들)
- 라이어·마피아·아발론 시계, 뱅 반응·차례 타이머, 바둑 계가·마작 울기 타이머가 방 마감(연출 시간 포함)을 따름
- 아발론 암살 마감: 당겨진 마감은 숨기고 늘어난 마감은 보여 줌(무제한이면 그대로 숨김)
- 테스트: 공통 재투표(대표자 A·느린 B·A 투표 후 유지), e2e 라이어 화면 시계 = 방 마감

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-08 12:09:36 +09:00
parent bc8cb7ae8c
commit f793391b79
8 changed files with 117 additions and 26 deletions

View File

@@ -39,7 +39,12 @@ let cs = 1_000_000;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type AnyRoom = any;
async function practice(gameId: string, nick: string, options?: (o: Record<string, unknown>) => Record<string, unknown>): Promise<{ p: Page; room: AnyRoom; me: string; bot: string }> {
async function practice(
gameId: string,
nick: string,
options?: (o: Record<string, unknown>) => Record<string, unknown>,
bots = 1,
): Promise<{ p: Page; room: AnyRoom; me: string; bot: string }> {
const ctx = await browser.newContext({ viewport: { width: 1280, height: 860 }, locale: 'ko-KR' });
await ctx.addInitScript((g) => localStorage.setItem(`bg:qs:${g}`, '1'), gameId);
const p = await ctx.newPage();
@@ -55,6 +60,10 @@ async function practice(gameId: string, nick: string, options?: (o: Record<strin
room.config.options = options(room.config.options);
room.broadcastRoom();
}
for (let i = 1; i < bots; i++) {
await p.getByRole('button', { name: '🤖 컴퓨터 넣기' }).first().click();
await p.getByLabel('자리').getByText(`컴퓨터 ${i + 1}`).waitFor();
}
await p.getByRole('button', { name: '▶ 게임 시작' }).click();
for (let i = 0; i < 100 && !room.game; i++) await Bun.sleep(50);
const me = room.game.players.find((u: string) => !u.startsWith('bot:'))!;
@@ -228,6 +237,34 @@ try {
await p.context().close();
setSpeed(1);
});
await step('라이어 게임: 연출이 끝난 만큼 늘어난 마감이 화면 시계에도 그대로', async () => {
const { p, room, me } = await practice('liar', '호랑이', undefined, 2);
// My screen is made to look 6 s slow to finish each step: the room gives 6 s more, and my clock must show it.
const report = room.settled.bind(room);
room.settled = (u: string, seq: number) => {
if (u === me && room.reveal && !room.reveal.done.has(u)) room.reveal.at -= 6_000;
return report(u, seq);
};
let checked = 0;
for (let i = 0; i < 400 && checked < 3; i++) {
await Bun.sleep(250);
const ph = room.game?.state?.phase;
const done = room.reveal?.done.get(me);
if (!ph || ph.endsAt == null || done === undefined || Date.now() - done < 1_000) continue;
const label = (await p.locator('.lg-clock[role="timer"]').first().getAttribute('aria-label').catch(() => null)) ?? '';
const shown = Number(label.match(/(\d+)초/)?.[1] ?? NaN);
const left = (room.publicDeadline() - Date.now()) / 1000;
const plain = (ph.endsAt - Date.now()) / 1000;
if (room.reveal?.done.get(me) !== done || room.game.state.phase !== ph) continue; // the step moved on meanwhile
if (left - plain < 5) throw new Error(`room deadline not moved: ${left.toFixed(1)}s vs phase ${plain.toFixed(1)}s`);
if (!(Math.abs(shown - left) <= 1.5)) throw new Error(`clock says ${shown}s, the room has ${left.toFixed(1)}s (phase alone ${plain.toFixed(1)}s)`);
checked++;
}
if (checked < 3) throw new Error(`only ${checked} clock checks happened`);
console.log(' liar: the clock follows the moved deadline (3 checks)');
await p.context().close();
});
} finally {
await browser.close();
app.stop?.();