From 95691bdd5c524ef773c87b0ddefc28671006c581 Mon Sep 17 00:00:00 2001 From: hided62 Date: Thu, 20 Aug 2026 06:38:13 +0000 Subject: [PATCH] =?UTF-8?q?fix(ranking):=20=EB=AA=85=EC=98=88=EC=9D=98=20?= =?UTF-8?q?=EC=A0=84=EB=8B=B9=20=EC=9D=B4=EC=A0=84=20=EA=B8=B0=EB=A1=9D?= =?UTF-8?q?=EC=9D=84=20=ED=94=84=EB=A1=9C=ED=95=84=EB=B3=84=EB=A1=9C=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 이전 서버 명예의 전당 조회를 요청 프로필의 archive로 제한한다. 클라이언트 profile 입력과 표시를 제거하고 API 및 Chromium 회귀 검증을 추가한다. --- app/game-api/src/router/ranking/index.ts | 14 ++-- .../src/services/legacyArchiveStore.ts | 6 +- app/game-api/test/rankingRouter.test.ts | 69 ++++++++++++++----- .../e2e/legacyArchiveViews.spec.ts | 33 +++++++-- .../src/views/HallOfFameView.vue | 35 +++------- 5 files changed, 100 insertions(+), 57 deletions(-) diff --git a/app/game-api/src/router/ranking/index.ts b/app/game-api/src/router/ranking/index.ts index d4f94630..e550c294 100644 --- a/app/game-api/src/router/ranking/index.ts +++ b/app/game-api/src/router/ranking/index.ts @@ -10,7 +10,7 @@ import { accessAuthedInputProcedure, accessInputProcedure, procedure, router } f import { findLegacyHallOptions, findLegacyHallRows, - LEGACY_ARCHIVE_PROFILES, + isLegacyArchiveProfile, } from '../../services/legacyArchiveStore.js'; const DEFAULT_BG_COLOR = '#330000'; @@ -392,11 +392,12 @@ export const rankingRouter = router({ .input(z.object({ source: z.enum(['current', 'legacy']).default('current') }).optional()) .query(async ({ ctx, input }) => { if ((input?.source ?? 'current') === 'legacy') { - const rows = await findLegacyHallOptions(ctx.db); + if (!isLegacyArchiveProfile(ctx.profile.id)) return []; + const rows = await findLegacyHallOptions(ctx.db, ctx.profile.id); const optionMap = new Map< string, { - sourceProfile: (typeof LEGACY_ARCHIVE_PROFILES)[number]; + sourceProfile: typeof ctx.profile.id; season: number; scenarios: Array<{ id: number; name: string; count: number }>; } @@ -441,7 +442,6 @@ export const rankingRouter = router({ getHallOfFame: accessInputProcedure( z.object({ source: z.enum(['current', 'legacy']).default('current'), - sourceProfile: z.enum(LEGACY_ARCHIVE_PROFILES).optional(), season: z.number().int(), scenario: z.number().int().optional(), }) @@ -486,9 +486,9 @@ export const rankingRouter = router({ } const rows = input.source === 'legacy' - ? input.sourceProfile + ? isLegacyArchiveProfile(ctx.profile.id) ? await findLegacyHallRows(ctx.db, { - sourceProfile: input.sourceProfile, + sourceProfile: ctx.profile.id, season: input.season, ...(input.scenario === undefined ? {} : { scenario: input.scenario }), type: type.key, @@ -528,6 +528,6 @@ export const rankingRouter = router({ }) ); - return { source: input.source, sourceProfile: input.sourceProfile ?? ctx.profile.id, sections }; + return { source: input.source, sourceProfile: ctx.profile.id, sections }; }), }); diff --git a/app/game-api/src/services/legacyArchiveStore.ts b/app/game-api/src/services/legacyArchiveStore.ts index df19a98c..8a35346a 100644 --- a/app/game-api/src/services/legacyArchiveStore.ts +++ b/app/game-api/src/services/legacyArchiveStore.ts @@ -285,7 +285,10 @@ export const findLegacyEmperor = async (db: LegacyArchiveDatabase, id: number): return rows[0] ?? null; }; -export const findLegacyHallOptions = async (db: LegacyArchiveDatabase): Promise => +export const findLegacyHallOptions = async ( + db: LegacyArchiveDatabase, + sourceProfile: LegacyArchiveProfile +): Promise => db.$queryRaw(GamePrisma.sql` SELECT "source_profile" AS "sourceProfile", @@ -294,6 +297,7 @@ export const findLegacyHallOptions = async (db: LegacyArchiveDatabase): Promise< MAX("scenario_name") AS "scenarioName", COUNT(*)::bigint AS "count" FROM "legacy_archive"."game_history" + WHERE "source_profile" = ${sourceProfile} GROUP BY "source_profile", "season", "scenario" ORDER BY "season" DESC, "source_profile", "scenario" `); diff --git a/app/game-api/test/rankingRouter.test.ts b/app/game-api/test/rankingRouter.test.ts index 59cdb936..0b9431f9 100644 --- a/app/game-api/test/rankingRouter.test.ts +++ b/app/game-api/test/rankingRouter.test.ts @@ -105,30 +105,38 @@ const buildContext = (options?: { authenticated?: boolean; isUnited?: boolean; includeOwnerDisplayName?: boolean; + profileId?: string; generals?: RankingGeneralRow[]; rankRows?: Array<{ generalId: number; type: string; value: number }>; }): GameApiContext => { const selectedGeneralRows = options?.generals ?? generalRows; + const selectedProfile = options?.profileId + ? { ...profile, id: options.profileId, name: `${options.profileId}:default` } + : profile; const db = { $queryRaw: async (query: { strings?: readonly string[]; values?: unknown[] }) => { const sql = query.strings?.join(' ') ?? ''; if (sql.includes('legacy_archive"."game_history')) { + if (!query.values?.includes(selectedProfile.id)) return []; + const sourceProfile = selectedProfile.id; return [ { - sourceProfile: 'hwe', + sourceProfile, season: 1, scenario: 7, - scenarioName: '이전 시나리오', + scenarioName: `${sourceProfile.toUpperCase()} 이전 시나리오`, count: 2n, }, ]; } if (sql.includes('legacy_archive"."hall')) { + if (!query.values?.includes(selectedProfile.id)) return []; + const sourceProfile = selectedProfile.id; return query.values?.includes('experience') ? [ { - sourceProfile: 'hwe', - serverId: 'hwe-old-1', + sourceProfile, + serverId: `${sourceProfile}-old-1`, generalNo: 9, type: 'experience', value: 777, @@ -224,13 +232,13 @@ const buildContext = (options?: { db: db as unknown as DatabaseClient, turnDaemon: new InMemoryTurnDaemonTransport(), battleSim: new InMemoryBattleSimTransport(), - profile, + profile: selectedProfile, auth: options?.authenticated === false ? null : auth, uploadDir: 'uploads', uploadPath: '/uploads', uploadPublicUrl: null, redis, - accessTokenStore: new RedisAccessTokenStore(redis, profile.name), + accessTokenStore: new RedisAccessTokenStore(redis, selectedProfile.name), flushStore: new InMemoryFlushStore(), gameTokenSecret: 'test-secret', }; @@ -378,29 +386,56 @@ describe('ranking hall of fame', () => { ]); }); - it('keeps previous-server options and rankings in the dedicated archive source', async () => { - const caller = appRouter.createCaller(buildContext({ authenticated: false })); - await expect(caller.ranking.getHallOfFameOptions({ source: 'legacy' })).resolves.toEqual([ + it('scopes previous-server options and rankings to the request profile', async () => { + const cheCaller = appRouter.createCaller(buildContext({ authenticated: false })); + await expect(cheCaller.ranking.getHallOfFameOptions({ source: 'legacy' })).resolves.toEqual([ { - sourceProfile: 'hwe', + sourceProfile: 'che', season: 1, - scenarios: [{ id: 7, name: '이전 시나리오', count: 2 }], + scenarios: [{ id: 7, name: 'CHE 이전 시나리오', count: 2 }], }, ]); - const result = await caller.ranking.getHallOfFame({ + const cheResult = await cheCaller.ranking.getHallOfFame({ source: 'legacy', - sourceProfile: 'hwe', season: 1, scenario: 7, }); - expect(result.source).toBe('legacy'); - expect(result.sourceProfile).toBe('hwe'); - expect(result.sections[0]).toMatchObject({ + expect(cheResult.source).toBe('legacy'); + expect(cheResult.sourceProfile).toBe('che'); + expect(cheResult.sections[0]).toMatchObject({ title: '명 성', entries: [expect.objectContaining({ generalId: 9, name: '과거장수', ownerName: '과거소유자' })], }); - expect(JSON.stringify(result)).not.toContain('private-legacy-owner-id'); + expect(JSON.stringify(cheResult)).not.toContain('private-legacy-owner-id'); + const staleCrossProfileInput = { + source: 'legacy' as const, + sourceProfile: 'hwe' as const, + season: 1, + scenario: 7, + }; + const staleClientResult = await cheCaller.ranking.getHallOfFame(staleCrossProfileInput); + expect(staleClientResult.sourceProfile).toBe('che'); + expect(staleClientResult.sections[0]?.entries).toHaveLength(1); + + const hweCaller = appRouter.createCaller(buildContext({ authenticated: false, profileId: 'hwe' })); + await expect(hweCaller.ranking.getHallOfFameOptions({ source: 'legacy' })).resolves.toEqual([ + { + sourceProfile: 'hwe', + season: 1, + scenarios: [{ id: 7, name: 'HWE 이전 시나리오', count: 2 }], + }, + ]); + const hweResult = await hweCaller.ranking.getHallOfFame({ source: 'legacy', season: 1, scenario: 7 }); + expect(hweResult.sourceProfile).toBe('hwe'); + expect(hweResult.sections[0]?.entries).toHaveLength(1); + + const developmentCaller = appRouter.createCaller( + buildContext({ authenticated: false, profileId: 'development' }) + ); + await expect(developmentCaller.ranking.getHallOfFameOptions({ source: 'legacy' })).resolves.toEqual([]); + const developmentResult = await developmentCaller.ranking.getHallOfFame({ source: 'legacy', season: 1 }); + expect(developmentResult.sections.every((section) => section.entries.length === 0)).toBe(true); }); it('returns an explicit display name but never exposes the stored account identifier', async () => { diff --git a/app/game-frontend/e2e/legacyArchiveViews.spec.ts b/app/game-frontend/e2e/legacyArchiveViews.spec.ts index e2091f66..3e02076b 100644 --- a/app/game-frontend/e2e/legacyArchiveViews.spec.ts +++ b/app/game-frontend/e2e/legacyArchiveViews.spec.ts @@ -10,20 +10,25 @@ const isLegacyRequest = (route: Route): boolean => decodeURIComponent(`${route.request().url()} ${route.request().postData() ?? ''}`).includes('legacy'); const installArchiveViews = async (page: Page) => { + const hallRequests: string[] = []; await page.addInitScript((profile) => { localStorage.setItem('sammo-game-token', 'ga_archive_views'); localStorage.setItem('sammo-game-profile', profile); }, gameProfile); await page.route(gameTrpcRoute, async (route) => { const legacy = isLegacyRequest(route); - const results = operationNames(route).map((operation) => { + const operations = operationNames(route); + if (operations.some((operation) => operation.startsWith('ranking.getHallOfFame'))) { + hallRequests.push(decodeURIComponent(`${route.request().url()} ${route.request().postData() ?? ''}`)); + } + const results = operations.map((operation) => { if (operation === 'auth.status') return response({ ok: true }); if (operation === 'lobby.info') return response({ myGeneral: { id: 1, name: '기록장수' } }); if (operation === 'ranking.getHallOfFameOptions') { return response([ { - sourceProfile: legacy ? 'hwe' : 'che', - season: legacy ? 1 : 2, + sourceProfile: 'che', + season: 1, scenarios: [{ id: 7, name: legacy ? '이전 시나리오' : '현재 시나리오', count: 1 }], }, ]); @@ -31,7 +36,7 @@ const installArchiveViews = async (page: Page) => { if (operation === 'ranking.getHallOfFame') { return response({ source: legacy ? 'legacy' : 'current', - sourceProfile: legacy ? 'hwe' : 'che', + sourceProfile: 'che', sections: [ { title: '명 성', @@ -184,18 +189,32 @@ const installArchiveViews = async (page: Page) => { }); await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(results) }); }); + return { hallRequests }; }; -test('명예의 전당은 현재 기록과 이전 서버 기록을 분리해 조회한다', async ({ page }) => { - await installArchiveViews(page); +test('명예의 전당은 현재 profile의 현재·이전 서버 기록만 조회한다', async ({ page }, testInfo) => { + const state = await installArchiveViews(page); await page.setViewportSize({ width: 1000, height: 800 }); await page.goto('hall-of-fame'); await expect(page.getByText('현재장수')).toBeVisible(); await page.getByLabel('기록 구분').selectOption('legacy'); await expect(page.getByText('이전장수')).toBeVisible(); - await expect(page.getByLabel('시나리오 검색')).toContainText('HWE / 이전 시나리오'); + await expect(page.getByLabel('시나리오 검색')).toContainText('이전 시나리오'); + await expect(page.getByLabel('시나리오 검색')).not.toContainText('HWE /'); + expect(state.hallRequests.some((request) => request.includes('legacy'))).toBe(true); + expect(state.hallRequests.every((request) => !request.includes('sourceProfile'))).toBe(true); await expect(page.locator('.legacy-hall-page')).toHaveCSS('width', '1000px'); + await page.getByLabel('시나리오 검색').focus(); + await expect(page.getByLabel('시나리오 검색')).toBeFocused(); + await page.screenshot({ path: testInfo.outputPath('hall-profile-scope-desktop.png'), fullPage: true }); + + await page.setViewportSize({ width: 390, height: 844 }); + await expect(page.locator('.legacy-hall-page')).toHaveCSS('width', '500px'); + expect( + await page.getByLabel('시나리오 검색').evaluate((element) => element.scrollWidth <= element.clientWidth) + ).toBe(true); + await page.screenshot({ path: testInfo.outputPath('hall-profile-scope-mobile.png'), fullPage: true }); }); test('왕조 일람과 상세는 이전 서버 source와 profile을 유지한다', async ({ page }) => { diff --git a/app/game-frontend/src/views/HallOfFameView.vue b/app/game-frontend/src/views/HallOfFameView.vue index 443b52f0..69e0579a 100644 --- a/app/game-frontend/src/views/HallOfFameView.vue +++ b/app/game-frontend/src/views/HallOfFameView.vue @@ -44,7 +44,6 @@ const loading = ref(false); const errorMessage = ref(''); const options = ref([]); const selectedSource = ref<'current' | 'legacy'>('current'); -const selectedProfile = ref(null); const selectedSeason = ref(null); const selectedScenario = ref(null); const data = ref(null); @@ -54,11 +53,10 @@ const selection = computed({ selectedSeason.value === null ? '' : selectedScenario.value === null - ? `season:${selectedProfile.value ?? ''}:${selectedSeason.value}` - : `scenario:${selectedProfile.value ?? ''}:${selectedSeason.value}:${selectedScenario.value}`, + ? `season:${selectedSeason.value}` + : `scenario:${selectedSeason.value}:${selectedScenario.value}`, set: (value: string) => { - const [kind, profile, season, scenario] = value.split(':'); - selectedProfile.value = profile || null; + const [kind, season, scenario] = value.split(':'); selectedSeason.value = Number(season); selectedScenario.value = kind === 'scenario' ? Number(scenario) : null; }, @@ -79,11 +77,10 @@ const loadOptions = async (): Promise => { options.value = await trpc.ranking.getHallOfFameOptions.query({ source: selectedSource.value }); const first = options.value[0]; if (first) { - selectedProfile.value = first.sourceProfile; selectedSeason.value = first.season; selectedScenario.value = null; + await loadHall(); } else { - selectedProfile.value = null; selectedSeason.value = null; selectedScenario.value = null; data.value = null; @@ -103,10 +100,6 @@ const loadHall = async (): Promise => { try { data.value = (await trpc.ranking.getHallOfFame.query({ source: selectedSource.value, - sourceProfile: - selectedSource.value === 'legacy' - ? (selectedProfile.value as 'che' | 'kwe' | 'pwe' | 'twe' | 'nya' | 'pya' | 'hwe') - : undefined, season: selectedSeason.value, scenario: selectedScenario.value ?? undefined, })) as HallPayload; @@ -117,10 +110,6 @@ const loadHall = async (): Promise => { } }; -watch([selectedProfile, selectedSeason, selectedScenario], () => { - void loadHall(); -}); - watch(selectedSource, () => { void loadOptions(); }); @@ -145,19 +134,15 @@ onMounted(loadOptions);