fix(ranking): 명예의 전당 이전 기록을 프로필별로 분리

이전 서버 명예의 전당 조회를 요청 프로필의 archive로 제한한다. 클라이언트 profile 입력과 표시를 제거하고 API 및 Chromium 회귀 검증을 추가한다.
This commit is contained in:
2026-08-20 06:38:13 +00:00
parent 1cf15e0396
commit 95691bdd5c
5 changed files with 100 additions and 57 deletions
+7 -7
View File
@@ -10,7 +10,7 @@ import { accessAuthedInputProcedure, accessInputProcedure, procedure, router } f
import { import {
findLegacyHallOptions, findLegacyHallOptions,
findLegacyHallRows, findLegacyHallRows,
LEGACY_ARCHIVE_PROFILES, isLegacyArchiveProfile,
} from '../../services/legacyArchiveStore.js'; } from '../../services/legacyArchiveStore.js';
const DEFAULT_BG_COLOR = '#330000'; const DEFAULT_BG_COLOR = '#330000';
@@ -392,11 +392,12 @@ export const rankingRouter = router({
.input(z.object({ source: z.enum(['current', 'legacy']).default('current') }).optional()) .input(z.object({ source: z.enum(['current', 'legacy']).default('current') }).optional())
.query(async ({ ctx, input }) => { .query(async ({ ctx, input }) => {
if ((input?.source ?? 'current') === 'legacy') { 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< const optionMap = new Map<
string, string,
{ {
sourceProfile: (typeof LEGACY_ARCHIVE_PROFILES)[number]; sourceProfile: typeof ctx.profile.id;
season: number; season: number;
scenarios: Array<{ id: number; name: string; count: number }>; scenarios: Array<{ id: number; name: string; count: number }>;
} }
@@ -441,7 +442,6 @@ export const rankingRouter = router({
getHallOfFame: accessInputProcedure( getHallOfFame: accessInputProcedure(
z.object({ z.object({
source: z.enum(['current', 'legacy']).default('current'), source: z.enum(['current', 'legacy']).default('current'),
sourceProfile: z.enum(LEGACY_ARCHIVE_PROFILES).optional(),
season: z.number().int(), season: z.number().int(),
scenario: z.number().int().optional(), scenario: z.number().int().optional(),
}) })
@@ -486,9 +486,9 @@ export const rankingRouter = router({
} }
const rows = const rows =
input.source === 'legacy' input.source === 'legacy'
? input.sourceProfile ? isLegacyArchiveProfile(ctx.profile.id)
? await findLegacyHallRows(ctx.db, { ? await findLegacyHallRows(ctx.db, {
sourceProfile: input.sourceProfile, sourceProfile: ctx.profile.id,
season: input.season, season: input.season,
...(input.scenario === undefined ? {} : { scenario: input.scenario }), ...(input.scenario === undefined ? {} : { scenario: input.scenario }),
type: type.key, 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 };
}), }),
}); });
@@ -285,7 +285,10 @@ export const findLegacyEmperor = async (db: LegacyArchiveDatabase, id: number):
return rows[0] ?? null; return rows[0] ?? null;
}; };
export const findLegacyHallOptions = async (db: LegacyArchiveDatabase): Promise<LegacyHallOptionRow[]> => export const findLegacyHallOptions = async (
db: LegacyArchiveDatabase,
sourceProfile: LegacyArchiveProfile
): Promise<LegacyHallOptionRow[]> =>
db.$queryRaw<LegacyHallOptionRow[]>(GamePrisma.sql` db.$queryRaw<LegacyHallOptionRow[]>(GamePrisma.sql`
SELECT SELECT
"source_profile" AS "sourceProfile", "source_profile" AS "sourceProfile",
@@ -294,6 +297,7 @@ export const findLegacyHallOptions = async (db: LegacyArchiveDatabase): Promise<
MAX("scenario_name") AS "scenarioName", MAX("scenario_name") AS "scenarioName",
COUNT(*)::bigint AS "count" COUNT(*)::bigint AS "count"
FROM "legacy_archive"."game_history" FROM "legacy_archive"."game_history"
WHERE "source_profile" = ${sourceProfile}
GROUP BY "source_profile", "season", "scenario" GROUP BY "source_profile", "season", "scenario"
ORDER BY "season" DESC, "source_profile", "scenario" ORDER BY "season" DESC, "source_profile", "scenario"
`); `);
+52 -17
View File
@@ -105,30 +105,38 @@ const buildContext = (options?: {
authenticated?: boolean; authenticated?: boolean;
isUnited?: boolean; isUnited?: boolean;
includeOwnerDisplayName?: boolean; includeOwnerDisplayName?: boolean;
profileId?: string;
generals?: RankingGeneralRow[]; generals?: RankingGeneralRow[];
rankRows?: Array<{ generalId: number; type: string; value: number }>; rankRows?: Array<{ generalId: number; type: string; value: number }>;
}): GameApiContext => { }): GameApiContext => {
const selectedGeneralRows = options?.generals ?? generalRows; const selectedGeneralRows = options?.generals ?? generalRows;
const selectedProfile = options?.profileId
? { ...profile, id: options.profileId, name: `${options.profileId}:default` }
: profile;
const db = { const db = {
$queryRaw: async (query: { strings?: readonly string[]; values?: unknown[] }) => { $queryRaw: async (query: { strings?: readonly string[]; values?: unknown[] }) => {
const sql = query.strings?.join(' ') ?? ''; const sql = query.strings?.join(' ') ?? '';
if (sql.includes('legacy_archive"."game_history')) { if (sql.includes('legacy_archive"."game_history')) {
if (!query.values?.includes(selectedProfile.id)) return [];
const sourceProfile = selectedProfile.id;
return [ return [
{ {
sourceProfile: 'hwe', sourceProfile,
season: 1, season: 1,
scenario: 7, scenario: 7,
scenarioName: '이전 시나리오', scenarioName: `${sourceProfile.toUpperCase()} 이전 시나리오`,
count: 2n, count: 2n,
}, },
]; ];
} }
if (sql.includes('legacy_archive"."hall')) { if (sql.includes('legacy_archive"."hall')) {
if (!query.values?.includes(selectedProfile.id)) return [];
const sourceProfile = selectedProfile.id;
return query.values?.includes('experience') return query.values?.includes('experience')
? [ ? [
{ {
sourceProfile: 'hwe', sourceProfile,
serverId: 'hwe-old-1', serverId: `${sourceProfile}-old-1`,
generalNo: 9, generalNo: 9,
type: 'experience', type: 'experience',
value: 777, value: 777,
@@ -224,13 +232,13 @@ const buildContext = (options?: {
db: db as unknown as DatabaseClient, db: db as unknown as DatabaseClient,
turnDaemon: new InMemoryTurnDaemonTransport(), turnDaemon: new InMemoryTurnDaemonTransport(),
battleSim: new InMemoryBattleSimTransport(), battleSim: new InMemoryBattleSimTransport(),
profile, profile: selectedProfile,
auth: options?.authenticated === false ? null : auth, auth: options?.authenticated === false ? null : auth,
uploadDir: 'uploads', uploadDir: 'uploads',
uploadPath: '/uploads', uploadPath: '/uploads',
uploadPublicUrl: null, uploadPublicUrl: null,
redis, redis,
accessTokenStore: new RedisAccessTokenStore(redis, profile.name), accessTokenStore: new RedisAccessTokenStore(redis, selectedProfile.name),
flushStore: new InMemoryFlushStore(), flushStore: new InMemoryFlushStore(),
gameTokenSecret: 'test-secret', 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 () => { it('scopes previous-server options and rankings to the request profile', async () => {
const caller = appRouter.createCaller(buildContext({ authenticated: false })); const cheCaller = appRouter.createCaller(buildContext({ authenticated: false }));
await expect(caller.ranking.getHallOfFameOptions({ source: 'legacy' })).resolves.toEqual([ await expect(cheCaller.ranking.getHallOfFameOptions({ source: 'legacy' })).resolves.toEqual([
{ {
sourceProfile: 'hwe', sourceProfile: 'che',
season: 1, 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', source: 'legacy',
sourceProfile: 'hwe',
season: 1, season: 1,
scenario: 7, scenario: 7,
}); });
expect(result.source).toBe('legacy'); expect(cheResult.source).toBe('legacy');
expect(result.sourceProfile).toBe('hwe'); expect(cheResult.sourceProfile).toBe('che');
expect(result.sections[0]).toMatchObject({ expect(cheResult.sections[0]).toMatchObject({
title: '명 성', title: '명 성',
entries: [expect.objectContaining({ generalId: 9, name: '과거장수', ownerName: '과거소유자' })], 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 () => { it('returns an explicit display name but never exposes the stored account identifier', async () => {
@@ -10,20 +10,25 @@ const isLegacyRequest = (route: Route): boolean =>
decodeURIComponent(`${route.request().url()} ${route.request().postData() ?? ''}`).includes('legacy'); decodeURIComponent(`${route.request().url()} ${route.request().postData() ?? ''}`).includes('legacy');
const installArchiveViews = async (page: Page) => { const installArchiveViews = async (page: Page) => {
const hallRequests: string[] = [];
await page.addInitScript((profile) => { await page.addInitScript((profile) => {
localStorage.setItem('sammo-game-token', 'ga_archive_views'); localStorage.setItem('sammo-game-token', 'ga_archive_views');
localStorage.setItem('sammo-game-profile', profile); localStorage.setItem('sammo-game-profile', profile);
}, gameProfile); }, gameProfile);
await page.route(gameTrpcRoute, async (route) => { await page.route(gameTrpcRoute, async (route) => {
const legacy = isLegacyRequest(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 === 'auth.status') return response({ ok: true });
if (operation === 'lobby.info') return response({ myGeneral: { id: 1, name: '기록장수' } }); if (operation === 'lobby.info') return response({ myGeneral: { id: 1, name: '기록장수' } });
if (operation === 'ranking.getHallOfFameOptions') { if (operation === 'ranking.getHallOfFameOptions') {
return response([ return response([
{ {
sourceProfile: legacy ? 'hwe' : 'che', sourceProfile: 'che',
season: legacy ? 1 : 2, season: 1,
scenarios: [{ id: 7, name: legacy ? '이전 시나리오' : '현재 시나리오', count: 1 }], scenarios: [{ id: 7, name: legacy ? '이전 시나리오' : '현재 시나리오', count: 1 }],
}, },
]); ]);
@@ -31,7 +36,7 @@ const installArchiveViews = async (page: Page) => {
if (operation === 'ranking.getHallOfFame') { if (operation === 'ranking.getHallOfFame') {
return response({ return response({
source: legacy ? 'legacy' : 'current', source: legacy ? 'legacy' : 'current',
sourceProfile: legacy ? 'hwe' : 'che', sourceProfile: 'che',
sections: [ sections: [
{ {
title: '명 성', title: '명 성',
@@ -184,18 +189,32 @@ const installArchiveViews = async (page: Page) => {
}); });
await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(results) }); await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(results) });
}); });
return { hallRequests };
}; };
test('명예의 전당은 현재 기록과 이전 서버 기록을 분리해 조회한다', async ({ page }) => { test('명예의 전당은 현재 profile의 현재·이전 서버 기록 조회한다', async ({ page }, testInfo) => {
await installArchiveViews(page); const state = await installArchiveViews(page);
await page.setViewportSize({ width: 1000, height: 800 }); await page.setViewportSize({ width: 1000, height: 800 });
await page.goto('hall-of-fame'); await page.goto('hall-of-fame');
await expect(page.getByText('현재장수')).toBeVisible(); await expect(page.getByText('현재장수')).toBeVisible();
await page.getByLabel('기록 구분').selectOption('legacy'); await page.getByLabel('기록 구분').selectOption('legacy');
await expect(page.getByText('이전장수')).toBeVisible(); 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 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 }) => { test('왕조 일람과 상세는 이전 서버 source와 profile을 유지한다', async ({ page }) => {
+10 -25
View File
@@ -44,7 +44,6 @@ const loading = ref(false);
const errorMessage = ref(''); const errorMessage = ref('');
const options = ref<HallOption[]>([]); const options = ref<HallOption[]>([]);
const selectedSource = ref<'current' | 'legacy'>('current'); const selectedSource = ref<'current' | 'legacy'>('current');
const selectedProfile = ref<string | null>(null);
const selectedSeason = ref<number | null>(null); const selectedSeason = ref<number | null>(null);
const selectedScenario = ref<number | null>(null); const selectedScenario = ref<number | null>(null);
const data = ref<HallPayload | null>(null); const data = ref<HallPayload | null>(null);
@@ -54,11 +53,10 @@ const selection = computed({
selectedSeason.value === null selectedSeason.value === null
? '' ? ''
: selectedScenario.value === null : selectedScenario.value === null
? `season:${selectedProfile.value ?? ''}:${selectedSeason.value}` ? `season:${selectedSeason.value}`
: `scenario:${selectedProfile.value ?? ''}:${selectedSeason.value}:${selectedScenario.value}`, : `scenario:${selectedSeason.value}:${selectedScenario.value}`,
set: (value: string) => { set: (value: string) => {
const [kind, profile, season, scenario] = value.split(':'); const [kind, season, scenario] = value.split(':');
selectedProfile.value = profile || null;
selectedSeason.value = Number(season); selectedSeason.value = Number(season);
selectedScenario.value = kind === 'scenario' ? Number(scenario) : null; selectedScenario.value = kind === 'scenario' ? Number(scenario) : null;
}, },
@@ -79,11 +77,10 @@ const loadOptions = async (): Promise<void> => {
options.value = await trpc.ranking.getHallOfFameOptions.query({ source: selectedSource.value }); options.value = await trpc.ranking.getHallOfFameOptions.query({ source: selectedSource.value });
const first = options.value[0]; const first = options.value[0];
if (first) { if (first) {
selectedProfile.value = first.sourceProfile;
selectedSeason.value = first.season; selectedSeason.value = first.season;
selectedScenario.value = null; selectedScenario.value = null;
await loadHall();
} else { } else {
selectedProfile.value = null;
selectedSeason.value = null; selectedSeason.value = null;
selectedScenario.value = null; selectedScenario.value = null;
data.value = null; data.value = null;
@@ -103,10 +100,6 @@ const loadHall = async (): Promise<void> => {
try { try {
data.value = (await trpc.ranking.getHallOfFame.query({ data.value = (await trpc.ranking.getHallOfFame.query({
source: selectedSource.value, source: selectedSource.value,
sourceProfile:
selectedSource.value === 'legacy'
? (selectedProfile.value as 'che' | 'kwe' | 'pwe' | 'twe' | 'nya' | 'pya' | 'hwe')
: undefined,
season: selectedSeason.value, season: selectedSeason.value,
scenario: selectedScenario.value ?? undefined, scenario: selectedScenario.value ?? undefined,
})) as HallPayload; })) as HallPayload;
@@ -117,10 +110,6 @@ const loadHall = async (): Promise<void> => {
} }
}; };
watch([selectedProfile, selectedSeason, selectedScenario], () => {
void loadHall();
});
watch(selectedSource, () => { watch(selectedSource, () => {
void loadOptions(); void loadOptions();
}); });
@@ -145,19 +134,15 @@ onMounted(loadOptions);
<label class="scenario-search"> <label class="scenario-search">
시나리오 검색 : 시나리오 검색 :
<select v-model="selection" aria-label="시나리오 검색"> <select v-model="selection" aria-label="시나리오 검색" @change="loadHall">
<template v-for="season in options" :key="`${season.sourceProfile}:${season.season}`"> <template v-for="season in options" :key="season.season">
<option :value="`season:${season.sourceProfile}:${season.season}`"> <option :value="`season:${season.season}`">* 시즌 : {{ season.season }} 종합 *</option>
* {{ selectedSource === 'legacy' ? `${season.sourceProfile.toUpperCase()} / ` : '' }}시즌 :
{{ season.season }} 종합 *
</option>
<option <option
v-for="scenario in season.scenarios" v-for="scenario in season.scenarios"
:key="`${season.sourceProfile}:${season.season}:${scenario.id}`" :key="`${season.season}:${scenario.id}`"
:value="`scenario:${season.sourceProfile}:${season.season}:${scenario.id}`" :value="`scenario:${season.season}:${scenario.id}`"
> >
{{ selectedSource === 'legacy' ? `${season.sourceProfile.toUpperCase()} / ` : '' {{ scenario.name }}({{ scenario.count }})
}}{{ scenario.name }}({{ scenario.count }})
</option> </option>
</template> </template>
</select> </select>