redo-readings: 아직 적용 안 된 제목 정리 행의 정답도 새 표기로(적용하면 옛 발음이 돌아오던 것), 퀴즈 정답 중 연결된 DB 곡에 사람이 넣은 별칭(quiz/admin)으로도 있는 값은 빼지 않음. 회귀 테스트 2개(고치기 전 실패 확인), docs 13

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-04 20:50:18 +09:00
parent 6c5910ca62
commit 9bc9c4afd5
4 changed files with 64 additions and 6 deletions

View File

@@ -145,7 +145,7 @@ switch (cmd) {
const oldTables = i >= 0 ? [(await Bun.file(rest[i + 1]!).json()) as LexiconTable] : [];
const r = redoReadings(db, { dryRun: rest.includes('--dry-run'), oldTables });
for (const e of r.examples) console.log(`${e.where}\t${e.name}\t- ${e.drop.join(', ')}\t+ ${e.add.join(', ')}`);
console.log(JSON.stringify({ songs: r.songs, quizItems: r.quizItems, unknownSongs: r.unknownSongs, unknownWords: r.unknownWords.size }));
console.log(JSON.stringify({ songs: r.songs, quizItems: r.quizItems, pendingReviews: r.pendingReviews, unknownSongs: r.unknownSongs, unknownWords: r.unknownWords.size }));
break;
}
case 'lexicon-missing': {

View File

@@ -69,3 +69,29 @@ test('saved quizzes: generated readings replaced, typed answers kept, 이지선
expect(JSON.parse(got(a).a)).toEqual(['정꾹이', '정국']);
expect(got(b)).toEqual({ t: '[]', a: '[]' });
});
test('제목 정리 rows still waiting get the new spellings too: applying one later does not bring the old reading back', async () => {
const { applyTitleReviews } = await import('./songs/title-review');
const db = openDb(tempDbPath());
const [id] = new Catalog(db).upsert({ title: 'Heaven (feat. X)', artists: [{ name: 'Rod Stewart' }], source: 't', ref: '1' });
db.query(
"INSERT INTO title_reviews (song_id, kind, status, old_title, old_artist, new_title, new_artist, title_answers, artist_answers, created_at) VALUES (?, 'title', 'pending', 'Heaven (feat. X)', 'Rod Stewart', 'Heaven', 'Rod Stewart', ?, ?, 0)",
).run(id!, JSON.stringify(['헤벤']), JSON.stringify(['로드 스투어트']));
expect(redoReadings(db).pendingReviews).toBe(1);
expect(applyTitleReviews(db, { ids: [id!] }, 'admin').applied).toBe(1);
expect(aliases(db, id!, 'title')).toEqual(['Heaven (feat. X)', '헤븐']);
expect(aliases(db, id!, 'artist')).toEqual(['로드 스튜어트', '로드스튜어트']);
});
test('saved quizzes: an answer the song DB has from a person (quiz save / admin) stays even when it equals an old generated reading', () => {
const db = openDb(tempDbPath());
db.query("INSERT INTO users (id, kind, nickname, created_at, last_seen_at) VALUES ('u', 'member', 'u', 0, 0)").run();
const quiz = (db.query("INSERT INTO custom_quizzes (owner_id, name, description, visibility, settings_json, kind, created_at, updated_at) VALUES ('u', 'q', '', 'private', '{}', 'normal', 0, 0) RETURNING id").get() as { id: number }).id;
const [song] = new Catalog(db).upsert({ title: 'Heaven', artists: [{ name: '에일리' }], source: 't', ref: '1' });
db.query("INSERT INTO song_aliases (song_id, part, alias, source) VALUES (?, 'title', '헤벤', 'quiz')").run(song!);
const it = (db.query("INSERT INTO custom_quiz_items (quiz_id, pos, song_id, video_id, title, artist, title_answers, artist_answers) VALUES (?, 0, ?, 'aaaaaaaaaaa', 'Heaven', '에일리', ?, '[]') RETURNING id").get(quiz, song!, JSON.stringify(['헤벤'])) as { id: number }).id;
redoReadings(db);
expect(JSON.parse(db.query<{ t: string }, [number]>('SELECT title_answers t FROM custom_quiz_items WHERE id = ?').get(it)!.t)).toEqual(['헤벤', '헤븐']);
// the song's own typed alias is never touched either
expect(aliases(db, song!, 'title')).toEqual(['헤벤', '헤븐']);
});

View File

@@ -98,6 +98,8 @@ export function planReadings(
export interface RedoResult {
songs: { changed: number; dropped: number; added: number };
quizItems: { changed: number; dropped: number; added: number };
/** 제목 정리 rows still waiting: their answers are applied later, so they get the same change. */
pendingReviews: number;
unknownSongs: number;
unknownWords: Map<string, number>;
examples: { where: string; name: string; drop: string[]; add: string[] }[];
@@ -108,7 +110,7 @@ export interface RedoResult {
* as it was before (`oldTables`, from git) so the spellings it made go too.
*/
export function redoReadings(db: Database, opts: { dryRun?: boolean; oldTables?: LexiconTable[] } = {}): RedoResult {
const out: RedoResult = { songs: { changed: 0, dropped: 0, added: 0 }, quizItems: { changed: 0, dropped: 0, added: 0 }, unknownSongs: 0, unknownWords: new Map(), examples: [] };
const out: RedoResult = { songs: { changed: 0, dropped: 0, added: 0 }, quizItems: { changed: 0, dropped: 0, added: 0 }, pendingReviews: 0, unknownSongs: 0, unknownWords: new Map(), examples: [] };
const songs = db
.query<{ id: number; title: string; artist: string; old_title: string | null }, []>(
'SELECT s.id, s.title, s.artist, r.old_title FROM songs s LEFT JOIN title_reviews r ON r.song_id = s.id WHERE s.deleted_at IS NULL ORDER BY s.id',
@@ -146,17 +148,46 @@ export function redoReadings(db: Database, opts: { dryRun?: boolean; oldTables?:
for (const a of plan.title.add) add.run(s.id, 'title', a.slice(0, 200));
for (const a of plan.artist.add) add.run(s.id, 'artist', a.slice(0, 200));
}
// 이지선다 quizzes have no answers
const items = db
.query<{ id: number; title: string; artist: string; title_answers: string; artist_answers: string }, []>(
"SELECT i.id, i.title, i.artist, i.title_answers, i.artist_answers FROM custom_quiz_items i JOIN custom_quizzes q ON q.id = i.quiz_id WHERE q.kind <> 'duel'",
// 제목 정리 rows not applied yet: whatever they would add is all generated (made by buildTitleReviews)
const pending = db
.query<{ song_id: number; old_title: string; new_title: string; new_artist: string; title_answers: string; artist_answers: string }, []>(
"SELECT song_id, old_title, new_title, new_artist, title_answers, artist_answers FROM title_reviews WHERE status = 'pending'",
)
.all();
const saveReview = db.query('UPDATE title_reviews SET title_answers = ?, artist_answers = ? WHERE song_id = ?');
for (const r of pending) {
const ta = JSON.parse(r.title_answers) as string[];
const aa = JSON.parse(r.artist_answers) as string[];
const plan = planReadings({ title: r.new_title, artist: r.new_artist, source: r.old_title, titleAnswers: ta, artistAnswers: aa }, opts.oldTables);
if (!plan.title.drop.length && !plan.artist.drop.length && !plan.title.add.length && !plan.artist.add.length) continue;
out.pendingReviews++;
const dT = new Set(plan.title.drop);
const dA = new Set(plan.artist.drop);
if (!opts.dryRun)
saveReview.run(
JSON.stringify([...ta.filter((a) => !dT.has(a)), ...plan.title.add].slice(0, 30)),
JSON.stringify([...aa.filter((a) => !dA.has(a)), ...plan.artist.add].slice(0, 30)),
r.song_id,
);
}
// 이지선다 quizzes have no answers. A quiz answer has no record of who wrote it: a generated one is recognised by being
// what the old reader made from that item's own names; one the song's DB also has from an admin or a quiz save
// (song_aliases source other than 'auto') is someone's typing and stays.
const items = db
.query<{ id: number; song_id: number | null; title: string; artist: string; title_answers: string; artist_answers: string }, []>(
"SELECT i.id, i.song_id, i.title, i.artist, i.title_answers, i.artist_answers FROM custom_quiz_items i JOIN custom_quizzes q ON q.id = i.quiz_id WHERE q.kind <> 'duel'",
)
.all();
const typed = db.query<{ part: string; alias: string }, [number]>("SELECT part, alias FROM song_aliases WHERE song_id = ? AND source <> 'auto'");
const save = db.query('UPDATE custom_quiz_items SET title_answers = ?, artist_answers = ? WHERE id = ?');
for (const it of items) {
const ta = JSON.parse(it.title_answers) as string[];
const aa = JSON.parse(it.artist_answers) as string[];
const plan = planReadings({ title: it.title, artist: it.artist, titleAnswers: ta, artistAnswers: aa }, opts.oldTables);
const own = it.song_id ? typed.all(it.song_id) : [];
const mine = (part: string, a: string) => own.some((x) => x.part === part && low(x.alias) === low(a));
plan.title.drop = plan.title.drop.filter((a) => !mine('title', a));
plan.artist.drop = plan.artist.drop.filter((a) => !mine('artist', a));
if (!plan.title.drop.length && !plan.artist.drop.length && !plan.title.add.length && !plan.artist.add.length) continue;
const dT = new Set(plan.title.drop);
const dA = new Set(plan.artist.drop);

View File

@@ -55,6 +55,7 @@
- `decodeEntities`: `&eacute;`·`&deg;` 등 라틴 문자 이름 추가(C&eacute;line Dion) → `cli.ts fix-text`로 DB 고침
- 퀴즈 파일 가수 칸의 따옴표 안('Miki Matsubara Official "stay with me"')을 with로 자르지 않음(가수 정답 '미' 같은 조각)
- 배포 (2026-11-04 20:44~): 백업 `~/backups/music_quiz/app-before-readings-20261104-2044.db` → eac4d97 배포 → `fix-text`(16곡, C&eacute;line Dion 등) → `fix-melon-titles` 18곡(Rod Stewart → Your Song 등, Chuckie는 같은 곡 10449에 합침, 16곡 바로 반영) → `redo-readings`(DB 3,707곡: 옛 발음 2,328개 빼고 10,533개 넣음 / 일반 퀴즈 30곡) → 테스트용1 真夜中のドア 가수 칸 'Miki Matsubara'로 → `redo-readings` 한 번 더(그 곡 가수 발음 6개). 두 번째부터는 바뀌는 것 없음. 표기표에 없는 단어가 남은 곡 56곡(대부분 누군지 확인 안 된 가수 이름)
- redo-readings는 아직 적용 안 된 제목 정리 행(pending)의 정답도 같이 바꿈(나중에 적용해도 옛 발음이 안 돌아오게). 퀴즈 정답에는 누가 썼는지 기록이 없어서 '그 곡 이름으로 옛 규칙이 만든 것과 같은 값'을 자동으로 봄 — 연결된 DB 곡에 사람이 넣은 별칭(source quiz/admin)으로도 있는 값은 남김. 반영 때 빠진 퀴즈 정답 18개는 백업과 대조해 모두 옛 규칙 결과(융 쿠크, 어 하, 헤벤, 미 …)임을 확인
- 'Sheep (Alan Walker Relift)'(10550)는 리믹스라 휴지통 기준에 해당 — 사용자 확인 대기
## 운영 DB에서 확인한 숫자 (2026-11-04 사본)