From 06af6f33ab507910bc58680f17f9b2b196bda0e5 Mon Sep 17 00:00:00 2001 From: Will Sarg <12886992+willsarg@users.noreply.github.com> Date: Sun, 12 Jul 2026 15:00:55 -0400 Subject: [PATCH 1/2] fix: skip cost-usage first-launch auto-enable under tests applyTokenCostDefaultIfNeeded() scans the real home directory for usage sources and, when found, writes costUsageEnabled mid-startup. That write trips the background-work settings observer and adds a second, machine-dependent startup refresh, flaking exact-count/version assertions (AdaptiveRefreshTimerTests, CodexAccountMenuDisplaySnapshotTests) on developer machines with real usage logs. Skip the auto-enable under tests, matching the other isRunningTests defaults in SettingsStore; the detection logic stays covered via hasAnyTokenCostUsageSources. Closes #2099 Co-Authored-By: Claude Opus 4.8 (1M context) --- Sources/CodexBar/SettingsStore+TokenCost.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/CodexBar/SettingsStore+TokenCost.swift b/Sources/CodexBar/SettingsStore+TokenCost.swift index 2668d099e4..3a7c7a9323 100644 --- a/Sources/CodexBar/SettingsStore+TokenCost.swift +++ b/Sources/CodexBar/SettingsStore+TokenCost.swift @@ -13,6 +13,13 @@ extension SettingsStore { } func applyTokenCostDefaultIfNeeded() { + // Skip the first-launch auto-enable under tests: it scans the real home directory for usage + // sources and, when it finds them, writes `costUsageEnabled` mid-startup. That write trips the + // background-work settings observer and adds a second, machine-dependent startup refresh, which + // flakes exact-count/version assertions (e.g. AdaptiveRefreshTimerTests, CodexAccountMenu…) on + // developer machines that have real usage logs. Tests cover the detection logic directly via + // `hasAnyTokenCostUsageSources`. Mirrors the other `isRunningTests` defaults in `SettingsStore`. + guard !Self.isRunningTests else { return } // Settings are persisted in UserDefaults.standard. guard UserDefaults.standard.object(forKey: "tokenCostUsageEnabled") == nil else { return } From 5688dc1d70381616ff1fdc35bcf94d8859a225be Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 14 Jul 2026 11:43:10 +0100 Subject: [PATCH 2/2] docs: tighten startup test guard comment --- Sources/CodexBar/SettingsStore+TokenCost.swift | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Sources/CodexBar/SettingsStore+TokenCost.swift b/Sources/CodexBar/SettingsStore+TokenCost.swift index 3a7c7a9323..354485615d 100644 --- a/Sources/CodexBar/SettingsStore+TokenCost.swift +++ b/Sources/CodexBar/SettingsStore+TokenCost.swift @@ -13,12 +13,7 @@ extension SettingsStore { } func applyTokenCostDefaultIfNeeded() { - // Skip the first-launch auto-enable under tests: it scans the real home directory for usage - // sources and, when it finds them, writes `costUsageEnabled` mid-startup. That write trips the - // background-work settings observer and adds a second, machine-dependent startup refresh, which - // flakes exact-count/version assertions (e.g. AdaptiveRefreshTimerTests, CodexAccountMenu…) on - // developer machines that have real usage logs. Tests cover the detection logic directly via - // `hasAnyTokenCostUsageSources`. Mirrors the other `isRunningTests` defaults in `SettingsStore`. + // Tests cover detection directly; skip filesystem-driven auto-enablement to keep startup deterministic. guard !Self.isRunningTests else { return } // Settings are persisted in UserDefaults.standard. guard UserDefaults.standard.object(forKey: "tokenCostUsageEnabled") == nil else { return }