test: add 50 preferences persistence and migration tests#540
Conversation
Cover value clamping (HUD timeout 1-10s, hold delay 100-2000ms, TCP port 1024-65535), LeaderKeyPreference Codable round-trips (navigation, base, custom layers), overlay suppressed bundle IDs Set operations and deduplication, Neovim reference topic validation, enum raw value round-trips for all preference enums, invalid raw value handling, RuleCollectionLayer Codable, default values, reset behavior, and config description format. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Code Review — PR #540: 50 Preferences Persistence & Migration TestsOverall this is a solid test addition. Good boundary coverage, good use of Major1. prefs.overlaySuppressedBundleIDs = Set(["com.a.app", "com.a.app", "com.b.app"])
XCTAssertEqual(prefs.overlaySuppressedBundleIDs.count, 2)
// Option A: test insert-based deduplication
prefs.overlaySuppressedBundleIDs.insert("com.a.app")
prefs.overlaySuppressedBundleIDs.insert("com.a.app")
XCTAssertEqual(prefs.overlaySuppressedBundleIDs.filter { $0 == "com.a.app" }.count, 1)
// Option B: if the setter accepts [String], assign duplicates2. Misleading test name: The name implies a graceful fallback to a default value, but the assertion is Minor3. Hardcoded magic number func testResetCommunicationSettings_RestoresProtocolAndPort() {
let defaultPort = 37001 // ← magic number
...
XCTAssertEqual(prefs.tcpServerPort, defaultPort)
}If the default port ever changes, this test fails for the wrong reason with an unhelpful message. Use the source-of-truth constant if one exists ( 4. Hardcoded preset value XCTAssertEqual(prefs.contextHUDHoldDelayMs, 150, "Preset value should win over custom")Same issue as above: if 5. Test isolation: manual save/restore is fragile Several tests manually save and restore shared state: let originalPort = prefs.tcpServerPort
prefs.tcpServerPort = 8080
// ... test ...
prefs.tcpServerPort = originalPortThis works until a test throws or override func tearDown() {
super.tearDown()
PreferencesService().reset() // or inject an in-memory store
}6. This suppresses Swift concurrency warnings. Fine if it's genuinely needed to avoid noise from XCTest's pre-concurrency API surface, but worth a one-line comment so future maintainers know it's intentional and not a stray import. Nit
Good coverage of the happy paths and boundaries. Addressing the deduplication test and the misleading name would be the priority fixes. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0d44b87fdb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| func testContextHUDTimeout_ClampedToMinimum() { | ||
| let prefs = PreferencesService() | ||
| prefs.contextHUDTimeout = 0.5 |
There was a problem hiding this comment.
Reset shared preferences after each persistence test
This test mutates PreferencesService, which writes to UserDefaults.standard, but the class does not isolate or clean up most of these mutations. Since PreferencesService.init() reads persisted defaults, later tests can observe prior test state instead of defaults (including tests in this file that assert default behavior), which makes the suite order-dependent and flaky when test order changes or when the defaults domain is already dirty. Add per-test setup/teardown to clear the KeyPath.* keys (or route tests through an isolated defaults suite).
Useful? React with 👍 / 👎.
Summary
Closes #532
Test plan