fix: history load notifies and never overwrites unreadable file; dictionary keeps ids across external edits, undo safety

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 16:04:01 +02:00
co-authored by Claude Sonnet 5.5
parent 5542f9cf70
commit 31c34a1d4a
8 changed files with 150 additions and 6 deletions
@@ -43,6 +43,23 @@ struct DictionaryStoreTests {
#expect(changes == 1)
}
@Test func externalChangeFiresBothCallbacksAndKeepsIDs() throws {
let url = tempFile()
let store = DictionaryStore(fileURL: url)
try store.load()
try store.apply { $0.append(.term("Vercel")) }
let id = store.entries[0].id
var changes = 0, external = 0
store.onChange = { changes += 1 }
store.onExternalChange = { external += 1 }
try "Nieuw\nVercel\n".write(to: url, atomically: true, encoding: .utf8)
store.reloadIfChanged()
#expect(changes == 1 && external == 1)
#expect(store.entries[1].id == id)
try store.apply { $0.append(.term("Eigen")) }
#expect(changes == 2 && external == 1)
}
@Test func ourOwnWriteDoesNotTriggerAReload() throws {
let store = DictionaryStore(fileURL: tempFile())
try store.load()