Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit a1c8c7c

Browse files
steipeteclaude
andcommitted
Fix all issues identified in PR comments
- Fix boolean assertion conversion bugs in test files (46 instances) - Add EventRef Sendable conformance with @retroactive @unchecked - Fix async initialization timing issues in KeyboardShortcuts - Resolve concurrency violations in Carbon callback handling - Convert `#expect(x == false)` to `#expect(\!x)` - Convert `#expect(x == true)` to `#expect(x)` - Address all automated bug reports from PR #8 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fdfb412 commit a1c8c7c

18 files changed

Lines changed: 133 additions & 126 deletions

LocalPackages/KeyboardShortcuts/Sources/KeyboardShortcuts/CarbonKeyboardShortcuts.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#if os(macOS)
22
import Carbon.HIToolbox
33

4+
extension EventRef: @retroactive @unchecked Sendable {}
5+
46
private func carbonKeyboardShortcutsEventHandler(eventHandlerCall: EventHandlerCallRef?, event: EventRef?, userData: UnsafeMutableRawPointer?) -> OSStatus {
57
// Need to handle the event synchronously since this is a Carbon callback
68
return CarbonKeyboardShortcuts.handleEventSynchronously(event)
@@ -230,10 +232,13 @@ enum CarbonKeyboardShortcuts {
230232

231233
// Synchronous wrapper for Carbon callback
232234
fileprivate static func handleEventSynchronously(_ event: EventRef?) -> OSStatus {
233-
// Create a copy of the event reference for safe capture
234-
let eventRef = event
235+
// EventRef is a C pointer type which is safe to pass across actor boundaries
236+
guard let event else {
237+
return OSStatus(eventNotHandledErr)
238+
}
239+
235240
return MainActor.assumeIsolated {
236-
handleEvent(eventRef)
241+
handleEvent(event)
237242
}
238243
}
239244

LocalPackages/KeyboardShortcuts/Sources/KeyboardShortcuts/Name.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ extension KeyboardShortcuts {
4141
self.rawValue = name
4242
self.defaultShortcut = initialShortcut
4343

44+
let nameForCapture = self
45+
4446
if
4547
let initialShortcut,
46-
!userDefaultsContains(name: self)
48+
!userDefaultsContains(name: nameForCapture)
4749
{
4850
Task { @MainActor in
49-
setShortcut(initialShortcut, for: self)
51+
setShortcut(initialShortcut, for: nameForCapture)
5052
KeyboardShortcuts.initialize()
5153
}
5254
} else {

Tests/AccessibilityTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct AccessibilityTests {
8080

8181
// The permission state should be updated (may be same or different)
8282
let finalState = manager.hasAccessibilityPermissions
83-
#expect(finalState == true || finalState == false)
83+
#expect(!finalState == true || finalState)
8484

8585
// Note: In tests, this likely won't change unless running with permissions
8686
// But the method should complete without crashing
@@ -114,7 +114,7 @@ struct AccessibilityTests {
114114
let hasPermissions = AXPermissionHelpers.hasAccessibilityPermissions()
115115

116116
// Should return a boolean value (either true or false)
117-
#expect(hasPermissions == true || hasPermissions == false)
117+
#expect(!hasPermissions == true || hasPermissions)
118118
}
119119

120120
@Test("AX Permission helpers permission request")
@@ -178,10 +178,10 @@ struct AccessibilityTests {
178178
let initialNotifications = manager.hasNotificationPermissions
179179

180180
// These should be boolean values, not nil
181-
#expect(initialAccessibility == true || initialAccessibility == false)
182-
#expect(initialAutomation == true || initialAutomation == false)
183-
#expect(initialScreenRecording == true || initialScreenRecording == false)
184-
#expect(initialNotifications == true || initialNotifications == false)
181+
#expect(!initialAccessibility == true || initialAccessibility)
182+
#expect(!initialAutomation == true || initialAutomation)
183+
#expect(!initialScreenRecording == true || initialScreenRecording)
184+
#expect(!initialNotifications == true || initialNotifications)
185185
}
186186

187187
@Test("Permissions manager permission monitoring task")

Tests/DiagnosticsTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ struct DiagnosticsTests {
9191
#expect(LogCategory.cursorMonitor.displayName == "CursorMonitor")
9292

9393
// Test verbose-only categories
94-
#expect(LogCategory.diagnostics.isVerboseOnly == true)
95-
#expect(LogCategory.lifecycle.isVerboseOnly == true)
96-
#expect(LogCategory.axorcist.isVerboseOnly == true)
97-
#expect(LogCategory.accessibility.isVerboseOnly == true)
94+
#expect(LogCategory.diagnostics.isVerboseOnly)
95+
#expect(LogCategory.lifecycle.isVerboseOnly)
96+
#expect(LogCategory.axorcist.isVerboseOnly)
97+
#expect(LogCategory.accessibility.isVerboseOnly)
9898

9999
// Test non-verbose categories
100-
#expect(LogCategory.general.isVerboseOnly == false)
101-
#expect(LogCategory.app.isVerboseOnly == false)
102-
#expect(LogCategory.settings.isVerboseOnly == false)
100+
#expect(!LogCategory.general.isVerboseOnly)
101+
#expect(!LogCategory.app.isVerboseOnly)
102+
#expect(!LogCategory.settings.isVerboseOnly)
103103
}
104104

105105
@Test("All categories have valid properties", arguments: logCategories)

Tests/GitTrackingTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct GitTrackingTests {
1010
#expect(repo1.dirtyFileCount == 0)
1111
#expect(repo1.untrackedFileCount == 0)
1212
#expect(repo1.currentBranch == nil)
13-
#expect(repo1.hasChanges == false)
13+
#expect(!repo1.hasChanges)
1414
#expect(repo1.totalChangedFiles == 0)
1515

1616
// Test repository with changes
@@ -24,29 +24,29 @@ struct GitTrackingTests {
2424
#expect(repo2.dirtyFileCount == 3)
2525
#expect(repo2.untrackedFileCount == 2)
2626
#expect(repo2.currentBranch == "main")
27-
#expect(repo2.hasChanges == true)
27+
#expect(repo2.hasChanges)
2828
#expect(repo2.totalChangedFiles == 5)
2929
}
3030

3131
@Test("Git repository change detection") func gitRepositoryChangeDetection() async throws {
3232
// Test repository without changes
3333
let cleanRepo = GitRepository(path: "/test", dirtyFileCount: 0, untrackedFileCount: 0)
34-
#expect(cleanRepo.hasChanges == false)
34+
#expect(!cleanRepo.hasChanges)
3535
#expect(cleanRepo.totalChangedFiles == 0)
3636

3737
// Test repository with dirty files only
3838
let dirtyRepo = GitRepository(path: "/test", dirtyFileCount: 5, untrackedFileCount: 0)
39-
#expect(dirtyRepo.hasChanges == true)
39+
#expect(dirtyRepo.hasChanges)
4040
#expect(dirtyRepo.totalChangedFiles == 5)
4141

4242
// Test repository with untracked files only
4343
let untrackedRepo = GitRepository(path: "/test", dirtyFileCount: 0, untrackedFileCount: 3)
44-
#expect(untrackedRepo.hasChanges == true)
44+
#expect(untrackedRepo.hasChanges)
4545
#expect(untrackedRepo.totalChangedFiles == 3)
4646

4747
// Test repository with both types of changes
4848
let mixedRepo = GitRepository(path: "/test", dirtyFileCount: 4, untrackedFileCount: 2)
49-
#expect(mixedRepo.hasChanges == true)
49+
#expect(mixedRepo.hasChanges)
5050
#expect(mixedRepo.totalChangedFiles == 6)
5151
}
5252

@@ -158,7 +158,7 @@ struct GitTrackingTests {
158158
}
159159

160160
for await result in group {
161-
#expect(result == true)
161+
#expect(result)
162162
}
163163
}
164164
}
@@ -271,7 +271,7 @@ struct GitTrackingTests {
271271
]
272272

273273
for repo in repos {
274-
#expect(repo.path.isEmpty == false)
274+
#expect(!repo.path.isEmpty)
275275
#expect(repo.currentBranch != nil)
276276
}
277277
}

Tests/IconAnimationTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ struct IconAnimationTests {
2222

2323
// Test animation state
2424
let isAnimating = animator.isCurrentlyAnimating
25-
#expect(isAnimating == true || isAnimating == false) // Either state is valid
25+
#expect(!isAnimating == true || isAnimating) // Either state is valid
2626

2727
// Test stopping animation
2828
animator.stopAnimating()
2929

3030
// Animation should be stopped
3131
let isStoppedAnimating = animator.isCurrentlyAnimating
32-
#expect(isStoppedAnimating == false)
32+
#expect(!isStoppedAnimating)
3333
}
3434

3535
@Test("Icon animation stop")
@@ -39,23 +39,23 @@ struct IconAnimationTests {
3939

4040
// Initially not animating
4141
var isAnimating = animator.isCurrentlyAnimating
42-
#expect(isAnimating == false)
42+
#expect(!isAnimating)
4343

4444
// Start animation
4545
animator.startAnimating()
4646
isAnimating = animator.isCurrentlyAnimating
47-
#expect(isAnimating == true)
47+
#expect(isAnimating)
4848

4949
// Stop animation
5050
animator.stopAnimating()
5151
isAnimating = animator.isCurrentlyAnimating
52-
#expect(isAnimating == false)
52+
#expect(!isAnimating)
5353

5454
// Multiple stop calls should be safe
5555
animator.stopAnimating()
5656
animator.stopAnimating()
5757
isAnimating = animator.isCurrentlyAnimating
58-
#expect(isAnimating == false)
58+
#expect(!isAnimating)
5959
}
6060

6161
@Test("Icon animation state management")
@@ -71,7 +71,7 @@ struct IconAnimationTests {
7171

7272
// Final state should be stopped
7373
let finalState = animator.isCurrentlyAnimating
74-
#expect(finalState == false)
74+
#expect(!finalState)
7575

7676
// Test concurrent state changes
7777
await withTaskGroup(of: Void.self) { group in
@@ -88,7 +88,7 @@ struct IconAnimationTests {
8888

8989
// Should handle concurrent access gracefully
9090
let concurrentState = animator.isCurrentlyAnimating
91-
#expect(concurrentState == true || concurrentState == false)
91+
#expect(!concurrentState == true || concurrentState)
9292
}
9393

9494
// MARK: - LottieMenuBarView Tests

Tests/IntegrationTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ struct IntegrationTests {
249249

250250
// Verify settings are loaded
251251
await MainActor.run {
252-
#expect(Defaults[.isGlobalMonitoringEnabled] == true)
252+
#expect(Defaults[.isGlobalMonitoringEnabled])
253253
#expect(Defaults[.maxInterventionsBeforePause] == 10)
254254
}
255255

@@ -259,14 +259,14 @@ struct IntegrationTests {
259259

260260
// Verify settings persistence
261261
await MainActor.run {
262-
#expect(Defaults[.isGlobalMonitoringEnabled] == true)
262+
#expect(Defaults[.isGlobalMonitoringEnabled])
263263
#expect(Defaults[.maxInterventionsBeforePause] == 10)
264264
}
265265

266266
// Test settings changes
267267
await MainActor.run {
268268
Defaults[.isGlobalMonitoringEnabled] = false
269-
#expect(Defaults[.isGlobalMonitoringEnabled] == false)
269+
#expect(!Defaults[.isGlobalMonitoringEnabled])
270270
}
271271
}
272272

@@ -294,7 +294,7 @@ struct IntegrationTests {
294294

295295
// Verify settings were loaded
296296
await MainActor.run {
297-
#expect(newWindowInfo.isLiveWatchingEnabled == true)
297+
#expect(newWindowInfo.isLiveWatchingEnabled)
298298
#expect(newWindowInfo.aiAnalysisIntervalSeconds == 30)
299299
}
300300

Tests/JSHookTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ struct JSHookTests {
4949

5050
#expect(withVersion.contains("const port = 8080;"))
5151
#expect(withVersion.contains("const version = '1.0.0';"))
52-
#expect(withVersion.contains("__CODELOOPER_PORT_PLACEHOLDER__" == false))
53-
#expect(withVersion.contains("__CODELOOPER_VERSION_PLACEHOLDER__" == false))
52+
#expect(!withVersion.contains("__CODELOOPER_PORT_PLACEHOLDER__"))
53+
#expect(!withVersion.contains("__CODELOOPER_VERSION_PLACEHOLDER__"))
5454
}
5555

5656
@Test("J s hook error types") func jSHookErrorTypes() {
@@ -95,7 +95,7 @@ struct JSHookTests {
9595

9696
// Test initial state
9797
let isConnected = await manager.isConnected
98-
#expect(isConnected == false)
98+
#expect(!isConnected)
9999
}
100100

101101
@Test("Port validation") func portValidation() {
@@ -118,7 +118,7 @@ struct JSHookTests {
118118

119119
// Initially not connected
120120
let initialState = await manager.isConnected
121-
#expect(initialState == false)
121+
#expect(!initialState)
122122

123123
// Connection state should be testable without actual network operations
124124
// This tests the state logic without requiring real connections
@@ -130,7 +130,7 @@ struct JSHookTests {
130130

131131
for messageType in messageTypes {
132132
#expect(messageType.count > 0)
133-
#expect(messageType.contains(" " == false))
133+
#expect(!messageType.contains(" "))
134134
}
135135

136136
// Test JSON message structure
@@ -177,7 +177,7 @@ struct JSHookTests {
177177
}
178178

179179
for await result in group {
180-
#expect(result == true)
180+
#expect(result)
181181
}
182182
}
183183
}

Tests/LoginItemManagerTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ struct LoginItemManagerTests {
2121
let initialState = await manager.startsAtLogin()
2222

2323
// Test that we can read the state (true or false, both are valid)
24-
#expect(initialState == true || initialState == false)
24+
#expect(!initialState == true || initialState)
2525

2626
// Test enabling (this is a test, so we won't actually change system settings)
2727
// Instead, we test that the method doesn't crash
2828
let result = await manager.setStartAtLogin(enabled: true)
29-
#expect(result == true || result == false) // Should return a boolean result
29+
#expect(!result == true || result) // Should return a boolean result
3030
}
3131

3232
@Test("Disable login item")
@@ -36,7 +36,7 @@ struct LoginItemManagerTests {
3636
// Test disabling (this is a test, so we won't actually change system settings)
3737
// Instead, we test that the method doesn't crash
3838
let result = await manager.setStartAtLogin(enabled: false)
39-
#expect(result == true || result == false) // Should return a boolean result
39+
#expect(!result == true || result) // Should return a boolean result
4040
}
4141

4242
@Test("Login item status")
@@ -47,14 +47,14 @@ struct LoginItemManagerTests {
4747
let status = await manager.startsAtLogin()
4848

4949
// Status should be either true or false
50-
#expect(status == true || status == false)
50+
#expect(!status == true || status)
5151

5252
// Test multiple status checks don't crash
5353
let status2 = await manager.startsAtLogin()
5454
let status3 = await manager.startsAtLogin()
5555

56-
#expect(status2 == true || status2 == false)
57-
#expect(status3 == true || status3 == false)
56+
#expect(!status2 == true || status2)
57+
#expect(!status3 == true || status3)
5858
}
5959

6060
@Test("Login item state changes")
@@ -89,7 +89,7 @@ struct LoginItemManagerTests {
8989
let initialStatus = await manager.startsAtLogin()
9090

9191
// Status should be either true or false
92-
#expect(initialStatus == true || initialStatus == false)
92+
#expect(!initialStatus == true || initialStatus)
9393

9494
// Test that we can observe changes
9595
let observation = await manager.observeLoginItemStatus { newStatus in
@@ -135,7 +135,7 @@ struct LoginItemManagerTests {
135135

136136
// Test sync functionality
137137
let syncResult = await manager.syncLoginItemWithPreference()
138-
#expect(syncResult == true || syncResult == false) // Should return a boolean
138+
#expect(!syncResult == true || syncResult) // Should return a boolean
139139

140140
#expect(true) // If we get here, no crashes occurred
141141
}
@@ -153,7 +153,7 @@ struct LoginItemManagerTests {
153153

154154
// All results should be valid boolean values
155155
for result in results {
156-
#expect(result == true || result == false)
156+
#expect(!result == true || result)
157157
}
158158
}
159159

@@ -168,7 +168,7 @@ struct LoginItemManagerTests {
168168
let newState = await manager.toggleStartAtLogin()
169169

170170
// New state should be opposite of initial (or same if system restrictions prevent change)
171-
#expect(newState == true || newState == false)
171+
#expect(!newState == true || newState)
172172

173173
// Restore original state
174174
await manager.setStartAtLogin(enabled: initialState)

0 commit comments

Comments
 (0)