Skip to content

Commit 05cfaea

Browse files
committed
Preserve legacy Keychain prompt overrides
1 parent eac0b8c commit 05cfaea

10 files changed

Lines changed: 34 additions & 15 deletions

Sources/CodexBar/CookieHeaderStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct KeychainCookieHeaderStore: CookieHeaderStoring {
7272
if case .interactionRequired = KeychainAccessPreflight
7373
.checkGenericPassword(service: self.service, account: self.account)
7474
{
75-
KeychainPromptHandler.handler?(KeychainPromptContext(
75+
KeychainPromptHandler.notify(KeychainPromptContext(
7676
kind: self.promptKind,
7777
service: self.service,
7878
account: self.account))

Sources/CodexBar/CopilotTokenStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct KeychainCopilotTokenStore: CopilotTokenStoring {
4444
if case .interactionRequired = KeychainAccessPreflight
4545
.checkGenericPassword(service: self.service, account: self.account)
4646
{
47-
KeychainPromptHandler.handler?(KeychainPromptContext(
47+
KeychainPromptHandler.notify(KeychainPromptContext(
4848
kind: .copilotToken,
4949
service: self.service,
5050
account: self.account))

Sources/CodexBar/KeychainPromptCoordinator.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ enum KeychainPromptCoordinator {
8888
"https://github.com/steipete/CodexBar/blob/main/docs/keychain-prompts.md"
8989

9090
static func install() {
91-
KeychainPromptHandler.handler = { context in
92-
_ = self.presentKeychainPrompt(context)
93-
}
9491
KeychainPromptHandler.resultHandler = { context in
9592
self.presentKeychainPrompt(context)
9693
}

Sources/CodexBar/KimiTokenStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct KeychainKimiTokenStore: KimiTokenStoring {
4444
if case .interactionRequired = KeychainAccessPreflight
4545
.checkGenericPassword(service: self.service, account: self.account)
4646
{
47-
KeychainPromptHandler.handler?(KeychainPromptContext(
47+
KeychainPromptHandler.notify(KeychainPromptContext(
4848
kind: .kimiToken,
4949
service: self.service,
5050
account: self.account))

Sources/CodexBar/MiniMaxAPITokenStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct KeychainMiniMaxAPITokenStore: MiniMaxAPITokenStoring {
4444
if case .interactionRequired = KeychainAccessPreflight
4545
.checkGenericPassword(service: self.service, account: self.account)
4646
{
47-
KeychainPromptHandler.handler?(KeychainPromptContext(
47+
KeychainPromptHandler.notify(KeychainPromptContext(
4848
kind: .minimaxToken,
4949
service: self.service,
5050
account: self.account))

Sources/CodexBar/MiniMaxCookieStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct KeychainMiniMaxCookieStore: MiniMaxCookieStoring {
4444
if case .interactionRequired = KeychainAccessPreflight
4545
.checkGenericPassword(service: self.service, account: self.account)
4646
{
47-
KeychainPromptHandler.handler?(KeychainPromptContext(
47+
KeychainPromptHandler.notify(KeychainPromptContext(
4848
kind: .minimaxCookie,
4949
service: self.service,
5050
account: self.account))

Sources/CodexBar/SyntheticTokenStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct KeychainSyntheticTokenStore: SyntheticTokenStoring {
4444
if case .interactionRequired = KeychainAccessPreflight
4545
.checkGenericPassword(service: self.service, account: self.account)
4646
{
47-
KeychainPromptHandler.handler?(KeychainPromptContext(
47+
KeychainPromptHandler.notify(KeychainPromptContext(
4848
kind: .syntheticToken,
4949
service: self.service,
5050
account: self.account))

Sources/CodexBar/ZaiTokenStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct KeychainZaiTokenStore: ZaiTokenStoring {
6161
if case .interactionRequired = KeychainAccessPreflight
6262
.checkGenericPassword(service: self.service, account: self.account)
6363
{
64-
KeychainPromptHandler.handler?(KeychainPromptContext(
64+
KeychainPromptHandler.notify(KeychainPromptContext(
6565
kind: .zaiToken,
6666
service: self.service,
6767
account: self.account))

Sources/CodexBarCore/KeychainAccessPreflight.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public enum KeychainPromptHandler {
5959
if let taskHandlerStore {
6060
return taskHandlerStore.handler(context)
6161
}
62-
if let resultHandler {
63-
return resultHandler(context)
62+
if let handler {
63+
handler(context)
64+
return true
6465
}
65-
guard let handler else { return false }
66-
handler(context)
67-
return true
66+
if let resultHandler { return resultHandler(context) }
67+
return false
6868
}
6969

7070
#if DEBUG
@@ -117,6 +117,7 @@ public enum KeychainPromptHandler {
117117
try await operation()
118118
}
119119
}
120+
120121
#endif
121122
}
122123

Tests/CodexBarTests/KeychainPromptCoordinatorTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Testing
33
@testable import CodexBar
44
@testable import CodexBarCore
55

6+
@Suite(.serialized)
67
struct KeychainPromptCoordinatorTests {
78
@Test
89
func `detects raw SwiftPM debug executable`() {
@@ -102,4 +103,24 @@ struct KeychainPromptCoordinatorTests {
102103

103104
#expect(!result)
104105
}
106+
107+
@Test
108+
func `legacy prompt handler takes precedence over result handler`() {
109+
let context = KeychainPromptContext(
110+
kind: .claudeOAuth,
111+
service: "Claude Code-credentials",
112+
account: nil)
113+
114+
let previousHandler = KeychainPromptHandler.handler
115+
let previousResultHandler = KeychainPromptHandler.resultHandler
116+
defer {
117+
KeychainPromptHandler.handler = previousHandler
118+
KeychainPromptHandler.resultHandler = previousResultHandler
119+
}
120+
KeychainPromptHandler.handler = { _ in }
121+
KeychainPromptHandler.resultHandler = { _ in false }
122+
let result = KeychainPromptHandler.notifyIfHandled(context)
123+
124+
#expect(result)
125+
}
105126
}

0 commit comments

Comments
 (0)