Skip to content

Commit eca3a73

Browse files
author
hujuncheng
committed
Fix CrossModel menu metrics and diagnostics
1 parent da4b482 commit eca3a73

4 files changed

Lines changed: 41 additions & 6 deletions

File tree

Sources/CodexBar/SettingsStore+MenuPreferences.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ extension SettingsStore {
143143

144144
static func isBalanceOnlyProvider(_ provider: UsageProvider) -> Bool {
145145
switch provider {
146-
case .deepseek, .mistral, .kimik2, .moonshot, .poe:
146+
case .deepseek, .mistral, .kimik2, .moonshot, .poe, .crossmodel:
147147
true
148148
default:
149149
false

Sources/CodexBar/UsageStore.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@ extension UsageStore {
969969
let openAIDebugContext = self.openAIAPIKeyDebugContext(processEnvironment: processEnvironment)
970970
let azureOpenAIDebugContext = self.azureOpenAIAPIKeyDebugContext(processEnvironment: processEnvironment)
971971
let openRouterDebugContext = self.openRouterAPIKeyDebugContext(processEnvironment: processEnvironment)
972+
let crossModelDebugContext = self.crossModelAPIKeyDebugContext(processEnvironment: processEnvironment)
972973
let elevenLabsDebugContext = self.elevenLabsAPIKeyDebugContext(processEnvironment: processEnvironment)
973974
let deepSeekHasEnvToken = DeepSeekSettingsReader.apiKey(environment: processEnvironment) != nil
974975
let deepSeekHasTokenAccount = self.settings.selectedTokenAccount(for: .deepseek) != nil
@@ -1070,10 +1071,7 @@ extension UsageStore {
10701071
case .openrouter:
10711072
return Self.apiKeyDebugLine(openRouterDebugContext)
10721073
case .crossmodel:
1073-
let resolution = ProviderTokenResolver.crossModelResolution()
1074-
let hasAny = resolution != nil
1075-
let source = resolution?.source.rawValue ?? "none"
1076-
return "CROSSMODEL_API_KEY=\(hasAny ? "present" : "missing") source=\(source)"
1074+
return Self.apiKeyDebugLine(crossModelDebugContext)
10771075
case .elevenlabs:
10781076
return Self.apiKeyDebugLine(elevenLabsDebugContext)
10791077
case .warp:
@@ -1262,6 +1260,20 @@ extension UsageStore {
12621260
hasTokenAccount: false)
12631261
}
12641262

1263+
private func crossModelAPIKeyDebugContext(processEnvironment: [String: String]) -> APIKeyDebugContext {
1264+
let config = self.settings.providerConfig(for: .crossmodel)
1265+
let environment = ProviderConfigEnvironment.applyAPIKeyOverride(
1266+
base: processEnvironment,
1267+
provider: .crossmodel,
1268+
config: config)
1269+
return APIKeyDebugContext(
1270+
label: "CROSSMODEL_API_KEY",
1271+
resolution: ProviderTokenResolver.crossModelResolution(environment: environment),
1272+
configToken: config?.sanitizedAPIKey,
1273+
hasEnvToken: CrossModelSettingsReader.apiToken(environment: processEnvironment) != nil,
1274+
hasTokenAccount: false)
1275+
}
1276+
12651277
private func elevenLabsAPIKeyDebugContext(processEnvironment: [String: String]) -> APIKeyDebugContext {
12661278
let config = self.settings.providerConfig(for: .elevenlabs)
12671279
let environment = ProviderConfigEnvironment.applyAPIKeyOverride(

Tests/CodexBarTests/SettingsStoreAdditionalTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ struct SettingsStoreAdditionalTests {
154154
func `menu bar metric preference restricts text only balance providers to automatic`() {
155155
let settings = Self.makeSettingsStore(suite: "SettingsStoreAdditionalTests-text-only-metric")
156156

157-
for provider in [UsageProvider.deepseek, .kimik2, .poe] {
157+
for provider in [UsageProvider.deepseek, .kimik2, .poe, .crossmodel] {
158158
settings.setMenuBarMetricPreference(.primary, for: provider)
159159
#expect(settings.menuBarMetricPreference(for: provider) == .automatic)
160160

Tests/CodexBarTests/UsageStorePathDebugTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,27 @@ struct UsageStorePathDebugTests {
5252

5353
#expect(debugLog == "DEEPSEEK_API_KEY=present source=settings-token-account")
5454
}
55+
56+
@Test
57+
func `crossmodel debug log includes config backed api key`() async throws {
58+
let suite = "UsageStorePathDebugTests-crossmodel-debug-config-key"
59+
let defaults = try #require(UserDefaults(suiteName: suite))
60+
defaults.removePersistentDomain(forName: suite)
61+
let configStore = testConfigStore(suiteName: suite)
62+
let settings = SettingsStore(
63+
userDefaults: defaults,
64+
configStore: configStore,
65+
zaiTokenStore: NoopZaiTokenStore())
66+
settings.crossModelAPIToken = "cm-config-test"
67+
let store = UsageStore(
68+
fetcher: UsageFetcher(),
69+
browserDetection: BrowserDetection(cacheTTL: 0),
70+
settings: settings,
71+
startupBehavior: .testing,
72+
environmentBase: [:])
73+
74+
let debugLog = await store.debugLog(for: UsageProvider.crossmodel)
75+
76+
#expect(debugLog == "CROSSMODEL_API_KEY=present source=settings-config")
77+
}
5578
}

0 commit comments

Comments
 (0)