제목 정리 검토: 괄호 안에 한글이 있는 일본어 제목(夜に駆ける (밤에 달리다))을 한글 곡으로 봐서 새 곡일 때 검토 없이 바로 반영하던 것 — 괄호 밖 원제가 일본어인지로 일본어 곡을 가림(japaneseName, 정답 생성도 같은 기준). 회귀 테스트: 그 곡은 일본어 곡·검토 대기로 남고 DB 제목은 그대로, 몽(夢)은 한국어 곡으로 바로 반영(고치기 전 실패 확인)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-04 16:36:30 +09:00
parent da500f489b
commit 651bc98dad
4 changed files with 27 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ import type { Database } from 'bun:sqlite';
import { cleanTitle } from '@mq/shared';
import { englishToHangul } from './en-ko';
import { kanaToHangul } from './ja-ko';
import { hasJapanese, readJapanese, type JaReader } from './ja-reading';
import { hasJapanese, japaneseName, readJapanese, type JaReader } from './ja-reading';
import type { WikiLookup } from './wiki';
export interface SongAnswers {
@@ -115,7 +115,7 @@ export async function songAnswersBatch(db: Database | null, songs: { title: stri
// the Japanese title: shown as is, or already swapped for its bracket's Korean name by cleanTitle
// ("夜に駆ける (밤에 달리다)") — Wikipedia still goes first, so the order is decided on the original
// only when the title outside the brackets was Japanese: "몽(夢)" is a Korean title with a 한자 alias, never renamed
const outsideJa = hasJapanese(s.title.replace(/[([{([【「『][^)\]})]】」』]*[)\]})]】」』]/g, ' '));
const outsideJa = japaneseName(s.title);
const jaTitle = hasJapanese(c.title) ? c.title : outsideJa ? c.aliases.find((a) => hasJapanese(a)) : undefined;
if (opts.korean && jaTitle) {
const bracket = hasJapanese(c.title) ? c.aliases.find((a) => HANGUL.test(a) && !hasJapanese(a)) : c.title;

View File

@@ -6,6 +6,12 @@ import { join } from 'node:path';
export const hasJapanese = (s: string) => /[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u.test(s) && !/\p{Script=Hangul}/u.test(s);
/**
* The name outside its brackets is Japanese: "夜に駆ける (밤에 달리다)" is, "몽(夢)" and "Good bye-bye (グッバイバイ)" are not
* (a Korean/English name with a Japanese or 한자 alias).
*/
export const japaneseName = (s: string) => hasJapanese(s.replace(/[([{([【「『][^)\]})]】」』]*[)\]})]】」』]/g, ' '));
export type JaReader = (texts: string[]) => Promise<(string | null)[]>;
export const readJapanese: JaReader = async (texts) => {

View File

@@ -6,7 +6,7 @@
* charts keep finding the song by its source name. A row whose song was edited since it was made is not applied.
*/
import type { Database } from 'bun:sqlite';
import { hasJapanese } from '../answers/ja-reading';
import { japaneseName } from '../answers/ja-reading';
import { songAnswersBatch, type AnswerOptions } from '../answers';
export type TitleReviewKind = 'title' | 'answers' | 'japanese' | 'check';
@@ -85,7 +85,7 @@ export async function buildTitleReviews(
return;
}
const notes = a.note ? [a.note] : [];
const kind: TitleReviewKind = a.note?.includes('확인 필요') ? 'check' : hasJapanese(s.title) || hasJapanese(s.artist) ? 'japanese' : renamed ? 'title' : 'answers';
const kind: TitleReviewKind = a.note?.includes('확인 필요') ? 'check' : japaneseName(s.title) || japaneseName(s.artist) ? 'japanese' : renamed ? 'title' : 'answers';
const status = opts.review || kind === 'japanese' || kind === 'check' ? 'pending' : 'auto';
save.run(s.id, kind, status, s.title, s.artist, a.title, a.artist, JSON.stringify(ta), JSON.stringify(aa), notes.join(' · ') || null, now);
if (status === 'auto') {

View File

@@ -92,3 +92,20 @@ test('관리자 API: list, apply a kind, skip; guests may not', async () => {
await s.stop();
}
});
test('new songs: a Japanese title with a Korean bracket ("夜に駆ける (밤에 달리다)") still waits as 일본어 곡; "몽(夢)" is a Korean song', async () => {
const db = openDb(tempDbPath());
const c = new Catalog(db);
const [ja] = c.upsert({ title: '夜に駆ける (밤에 달리다)', artists: [{ name: 'YOASOBI' }], source: 't', ref: '1' });
const [ko] = c.upsert({ title: '몽(夢)', artists: [{ name: '가수' }], source: 't', ref: '2' });
const r = await buildTitleReviews(db, { wiki: async () => new Map() });
expect(r).toMatchObject({ pending: 1, auto: 1 });
const rows = listTitleReviews(db, {}).rows;
expect(rows).toHaveLength(1);
expect(rows[0]).toMatchObject({ songId: ja, kind: 'japanese', status: 'pending', newTitle: '밤에 달리다' });
const title = (id: number) => db.query<{ title: string }, [number]>('SELECT title FROM songs WHERE id = ?').get(id)!.title;
expect(title(ja!)).toBe('夜に駆ける (밤에 달리다)');
// the Korean song was applied at once, keeping its title and the 한자 as an answer
expect(title(ko!)).toBe('몽');
expect(db.query<{ alias: string }, [number]>("SELECT alias FROM song_aliases WHERE song_id = ? AND part = 'title'").all(ko!).map((x) => x.alias)).toContain('夢');
});