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
@@ -49,4 +49,23 @@ struct DictionaryFileTests {
#expect(file.entries.isEmpty)
#expect(file.serialized() == "# c\n")
}
@Test func preservingIDsKeepsIdsOfUnchangedLines() {
let old = DictionaryFile(parsing: "a\nb => c\nd\n")
let new = DictionaryFile(parsing: "z\na\nb => c\nd2\n").preservingIDs(from: old)
let oldIDs = old.entries.map(\.id), newIDs = new.entries.map(\.id)
#expect(newIDs[1] == oldIDs[0])
#expect(newIDs[2] == oldIDs[1])
#expect(!oldIDs.contains(newIDs[0]))
#expect(!oldIDs.contains(newIDs[3]))
#expect(new.serialized() == "z\na\nb => c\nd2\n")
}
@Test func preservingIDsMapsDuplicatesOneToOneInOrder() {
let old = DictionaryFile(parsing: "a\na\n")
let new = DictionaryFile(parsing: "a\na\na\n").preservingIDs(from: old)
let oldIDs = old.entries.map(\.id), newIDs = new.entries.map(\.id)
#expect(Array(newIDs[0...1]) == oldIDs)
#expect(!oldIDs.contains(newIDs[2]))
}
}