다시 보기: 컴퓨터와 한 판·점수 문구 이전 게임도 다시 볼 수 있게(결과 비교를 순위·점수·이유·요약으로)
운영 DB 44판 중 21판이 '다시 볼 수 없어요'였던 원인: 저장 결과의 practice 표시와 새 scoreText 때문에 JSON 전체 비교가 실패. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ import { GAMES } from '@bg/games';
|
||||
import { openDb } from '../db';
|
||||
import { Room, type Conn, type RoomConfig } from './room';
|
||||
import { RoomStore } from './store';
|
||||
import { Replays, rebuildGame, type ReplayInput } from './replay';
|
||||
import { Replays, rebuildGame, sameOutcome, type ReplayInput } from './replay';
|
||||
|
||||
const json = (v: unknown) => JSON.parse(JSON.stringify(v));
|
||||
|
||||
@@ -262,6 +262,24 @@ describe('replay: access and edge cases', () => {
|
||||
expect(await new Replays(db, GAMES, users).get(pk, 'A')).toMatchObject({ ok: false, status: 410 });
|
||||
});
|
||||
|
||||
test('practice games (marked "practice") and games recorded before final scores existed are replayable', async () => {
|
||||
const { db, room, users } = omokRoom();
|
||||
room.act('A', 1, { type: 'place', x: 7, y: 7 });
|
||||
room.leave('B');
|
||||
const pk = room.game!.gamePk;
|
||||
const stored = JSON.parse(db.query<{ result_json: string }, [string]>('SELECT result_json FROM games WHERE id = ?').get(pk)!.result_json);
|
||||
// As the store writes a game played with computers.
|
||||
db.query('UPDATE games SET result_json = ? WHERE id = ?').run(JSON.stringify({ ...stored, practice: true }), pk);
|
||||
const practice = await new Replays(db, GAMES, users).get(pk, 'A');
|
||||
expect(practice.ok).toBe(true);
|
||||
// A scored game recorded without scoreText gets it from the rebuilt game; a changed outcome still fails.
|
||||
const scored = { ...GAMES, omok: { ...GAMES.omok!, result: (st: unknown) => { const r = GAMES.omok!.result(st); return r && { ...r, scoreText: { A: '1점', B: '0점' } }; } } };
|
||||
const old = await new Replays(db, scored, users).get(pk, 'A');
|
||||
if (!old.ok) throw new Error(old.error);
|
||||
expect((JSON.parse(old.body) as ReplayData).result.scoreText).toEqual({ A: '1점', B: '0점' });
|
||||
expect(sameOutcome({ ranking: [['A'], ['B']], summary: 'x', reason: 'normal' }, { ranking: [['B'], ['A']], summary: 'x', reason: 'normal' })).toBe(false);
|
||||
});
|
||||
|
||||
test('my games list: newest first, paged, with ranks and nicknames', async () => {
|
||||
const { db, room, clock, users } = omokRoom();
|
||||
room.act('A', 1, { type: 'place', x: 7, y: 7 });
|
||||
|
||||
Reference in New Issue
Block a user