From f0e1cd65485a83d55b1247673f6d3d402795a8e2 Mon Sep 17 00:00:00 2001 From: sudacode Date: Thu, 23 Jul 2026 01:41:14 -0700 Subject: [PATCH] fix(anki): keep existing maturity tier on re-mined notes - appendFromNoteInfo no longer overwrites a note's tracked tier with 'new' when the note already has one recorded - add test covering re-mining a note that already has a mature/learning tier --- .../known-word-cache-maturity.test.ts | 30 +++++++++++++++++++ src/anki-integration/known-word-cache.ts | 6 +++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/anki-integration/known-word-cache-maturity.test.ts b/src/anki-integration/known-word-cache-maturity.test.ts index 7eedd3e8..f095d9cd 100644 --- a/src/anki-integration/known-word-cache-maturity.test.ts +++ b/src/anki-integration/known-word-cache-maturity.test.ts @@ -342,3 +342,33 @@ test('appendFromNoteInfo marks freshly mined notes as new tier', async () => { cleanup(); } }); + +test('appendFromNoteInfo preserves an existing maturity tier', async () => { + const { manager, clientState, cleanup } = createMaturityHarness(maturityConfig()); + + try { + clientState.findNotesByQuery.set('deck:"Mining"', [7, 8]); + clientState.findNotesByQuery.set('deck:"Mining" prop:ivl>=21', [7]); + clientState.findNotesByQuery.set('deck:"Mining" prop:ivl>=1 prop:ivl<21', []); + clientState.findNotesByQuery.set('deck:"Mining" is:learn', [8]); + clientState.notesInfoResult = [ + { noteId: 7, fields: { Word: { value: '猫' } } }, + { noteId: 8, fields: { Word: { value: '犬' } } }, + ]; + await manager.refresh(true); + + manager.appendFromNoteInfo({ + noteId: 7, + fields: { Word: { value: '子猫' } }, + }); + manager.appendFromNoteInfo({ + noteId: 8, + fields: { Word: { value: '子犬' } }, + }); + + assert.equal(manager.getKnownWordTier('子猫'), 'mature'); + assert.equal(manager.getKnownWordTier('子犬'), 'learning'); + } finally { + cleanup(); + } +}); diff --git a/src/anki-integration/known-word-cache.ts b/src/anki-integration/known-word-cache.ts index 5a9c2b71..39cfe811 100644 --- a/src/anki-integration/known-word-cache.ts +++ b/src/anki-integration/known-word-cache.ts @@ -342,7 +342,11 @@ export class KnownWordCacheManager { } // A just-mined card has never been reviewed. - if (this.isMaturityTrackingEnabled() && this.noteEntriesById.has(noteInfo.noteId)) { + if ( + this.isMaturityTrackingEnabled() && + this.noteEntriesById.has(noteInfo.noteId) && + !this.noteTierById.has(noteInfo.noteId) + ) { this.noteTierById.set(noteInfo.noteId, 'new'); }