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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user