fix(ranking): 명예의 전당 이전 기록을 프로필별로 분리
이전 서버 명예의 전당 조회를 요청 프로필의 archive로 제한한다. 클라이언트 profile 입력과 표시를 제거하고 API 및 Chromium 회귀 검증을 추가한다.
This commit is contained in:
@@ -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 };
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -285,7 +285,10 @@ export const findLegacyEmperor = async (db: LegacyArchiveDatabase, id: number):
|
||||
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`
|
||||
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"
|
||||
`);
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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 }) => {
|
||||
|
||||
@@ -44,7 +44,6 @@ const loading = ref(false);
|
||||
const errorMessage = ref('');
|
||||
const options = ref<HallOption[]>([]);
|
||||
const selectedSource = ref<'current' | 'legacy'>('current');
|
||||
const selectedProfile = ref<string | null>(null);
|
||||
const selectedSeason = ref<number | null>(null);
|
||||
const selectedScenario = ref<number | null>(null);
|
||||
const data = ref<HallPayload | null>(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<void> => {
|
||||
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<void> => {
|
||||
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<void> => {
|
||||
}
|
||||
};
|
||||
|
||||
watch([selectedProfile, selectedSeason, selectedScenario], () => {
|
||||
void loadHall();
|
||||
});
|
||||
|
||||
watch(selectedSource, () => {
|
||||
void loadOptions();
|
||||
});
|
||||
@@ -145,19 +134,15 @@ onMounted(loadOptions);
|
||||
|
||||
<label class="scenario-search">
|
||||
시나리오 검색 :
|
||||
<select v-model="selection" aria-label="시나리오 검색">
|
||||
<template v-for="season in options" :key="`${season.sourceProfile}:${season.season}`">
|
||||
<option :value="`season:${season.sourceProfile}:${season.season}`">
|
||||
* {{ selectedSource === 'legacy' ? `${season.sourceProfile.toUpperCase()} / ` : '' }}시즌 :
|
||||
{{ season.season }} 종합 *
|
||||
</option>
|
||||
<select v-model="selection" aria-label="시나리오 검색" @change="loadHall">
|
||||
<template v-for="season in options" :key="season.season">
|
||||
<option :value="`season:${season.season}`">* 시즌 : {{ season.season }} 종합 *</option>
|
||||
<option
|
||||
v-for="scenario in season.scenarios"
|
||||
:key="`${season.sourceProfile}:${season.season}:${scenario.id}`"
|
||||
:value="`scenario:${season.sourceProfile}:${season.season}:${scenario.id}`"
|
||||
:key="`${season.season}:${scenario.id}`"
|
||||
:value="`scenario:${season.season}:${scenario.id}`"
|
||||
>
|
||||
{{ selectedSource === 'legacy' ? `${season.sourceProfile.toUpperCase()} / ` : ''
|
||||
}}{{ scenario.name }}({{ scenario.count }}회)
|
||||
{{ scenario.name }}({{ scenario.count }}회)
|
||||
</option>
|
||||
</template>
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user