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:
@@ -57,6 +57,35 @@ struct HistoryStoreTests {
|
||||
#expect(store.entries.isEmpty)
|
||||
}
|
||||
|
||||
@Test func loadNotifiesOnChange() {
|
||||
let url = tempFile()
|
||||
let writer = HistoryStore(fileURL: url)
|
||||
writer.add(entry("a", at: 0)); writer.add(entry("b", at: 1))
|
||||
writer.flush()
|
||||
|
||||
let store = HistoryStore(fileURL: url)
|
||||
var calls = 0
|
||||
store.onChange = { calls += 1 }
|
||||
#expect(store.load() == .loaded)
|
||||
#expect(calls == 1)
|
||||
#expect(store.entries.count == 2)
|
||||
}
|
||||
|
||||
@Test func unreadableFileIsReportedAndNeverOverwritten() throws {
|
||||
let url = tempFile()
|
||||
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true) // history.json is a directory
|
||||
let store = HistoryStore(fileURL: url)
|
||||
guard case .unreadable = store.load() else {
|
||||
Issue.record("expected unreadable"); return
|
||||
}
|
||||
store.add(entry("a", at: 0))
|
||||
store.flush()
|
||||
var isDirectory: ObjCBool = false
|
||||
#expect(FileManager.default.fileExists(atPath: url.path, isDirectory: &isDirectory))
|
||||
#expect(isDirectory.boolValue)
|
||||
#expect(store.lastError != nil)
|
||||
}
|
||||
|
||||
@Test func onChangeFiresForEdits() {
|
||||
let store = HistoryStore(fileURL: tempFile())
|
||||
var calls = 0
|
||||
|
||||
Reference in New Issue
Block a user