Skip to content

Commit bcb799e

Browse files
committed
fix(connections): implement safe mode persistence and add write-through test
1 parent 90ac808 commit bcb799e

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525

2626
### Fixed
2727

28-
- Changing Safe Mode from the toolbar now saves that level as the connection default, so disconnecting and reconnecting keeps the same protection.
28+
- Safe mode level changes in the toolbar now persist as the connection default across reconnects.
2929
- Toolbar customizations now persist after closing and reopening a session window. (#1455)
3030
- Pasting rows with commas in a cell now keeps each value in its own column and preserves NULL vs the literal text "NULL".
3131
- BigQuery: switching to another table loads its data immediately instead of leaving the grid empty.

TableProTests/Core/Storage/ConnectionStoragePersistenceTests.swift

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
//
55

66
import Foundation
7+
@testable import TablePro
78
import TableProPluginKit
89
import Testing
9-
@testable import TablePro
1010

1111
@Suite("ConnectionStorage Persistence")
1212
@MainActor
@@ -26,8 +26,12 @@ struct ConnectionStoragePersistenceTests {
2626
withIntermediateDirectories: true
2727
)
2828
let suiteName = "com.TablePro.tests.ConnectionStorage.\(unique)"
29-
self.defaults = UserDefaults(suiteName: suiteName)!
30-
let syncDefaults = UserDefaults(suiteName: "com.TablePro.tests.Sync.\(unique)")!
29+
guard let defaults = UserDefaults(suiteName: suiteName),
30+
let syncDefaults = UserDefaults(suiteName: "com.TablePro.tests.Sync.\(unique)")
31+
else {
32+
fatalError("Failed to create isolated test user defaults")
33+
}
34+
self.defaults = defaults
3135
let metadata = SyncMetadataStorage(userDefaults: syncDefaults)
3236
self.syncTracker = SyncChangeTracker(metadataStorage: metadata)
3337
self.storage = ConnectionStorage(
@@ -49,12 +53,34 @@ struct ConnectionStoragePersistenceTests {
4953
#expect(reloaded.contains { $0.id == connection.id })
5054
}
5155

56+
@Test("updateSafeModeLevel writes the new level through to disk")
57+
func updateSafeModeLevelWritesThrough() {
58+
let connection = DatabaseConnection(
59+
name: "Write Through",
60+
host: "127.0.0.1",
61+
port: 3_306,
62+
type: .mysql,
63+
safeModeLevel: .silent
64+
)
65+
66+
storage.addConnection(connection)
67+
storage.invalidateCache()
68+
#expect(storage.loadConnections().first { $0.id == connection.id }?.safeModeLevel == .silent)
69+
70+
let updated = storage.updateSafeModeLevel(.readOnly, for: connection.id)
71+
#expect(updated)
72+
73+
storage.invalidateCache()
74+
let reloaded = storage.loadConnections().first { $0.id == connection.id }
75+
#expect(reloaded?.safeModeLevel == .readOnly)
76+
}
77+
5278
@Test("round-trip save and load preserves connections")
5379
func roundTripSaveLoad() {
5480
let connection = DatabaseConnection(
5581
name: "Round Trip Test",
5682
host: "127.0.0.1",
57-
port: 5432,
83+
port: 5_432,
5884
type: .postgresql
5985
)
6086

0 commit comments

Comments
 (0)