Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/CodexBar/UsageStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ extension UsageStore {
_ = self.statuses
_ = self.tokenSnapshotPublications
_ = self.historicalPaceRevision
_ = self.accountSnapshots
_ = self.codexAccountSnapshots
Comment on lines +59 to +60

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Feed account snapshots into the icon work signature

Once the initial icon signature is stored, a refresh that changes only either per-account collection triggers this observation but still does no icon work: observeStoreIconChanges() recomputes storeIconObservationSignature() and returns because that signature reads store.snapshot(for:) and never accountSnapshots or codexAccountSnapshots. The status indicator therefore remains stale in the scenario these dependencies are intended to fix; include the relevant account state in the signature/render source (or publish it into snapshots) and test through the controller's signature gate rather than only asserting raw Observation invalidation.

AGENTS.md reference: AGENTS.md:L4-L5

Useful? React with 👍 / 👎.

return 0
}

Expand Down
67 changes: 67 additions & 0 deletions Tests/CodexBarTests/StatusItemIconObservationSignatureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,73 @@ struct StatusItemIconObservationSignatureTests {
#expect(controller.storeIconObservationSignature() != baseline)
}

@Test
func `store icon observation token invalidates when account snapshots change`() {
let (_, store, controller) = self.makeController(
suiteName: "StatusItemIconObservationSignatureTests-account-snapshots")
defer { controller.releaseStatusItemsForTesting() }

nonisolated(unsafe) var invalidated = false
withObservationTracking {
_ = store.iconObservationToken
} onChange: {
invalidated = true
}

let account = ProviderTokenAccount(
id: UUID(),
label: "Account 1",
token: "token1",
addedAt: 1,
lastUsed: nil)

store.accountSnapshots[.claude] = [
TokenAccountUsageSnapshot(
account: account,
snapshot: nil,
error: nil,
sourceLabel: "fixture",
cacheKey: store.tokenAccountSnapshotCacheKey(provider: .claude, account: account)),
]

#expect(invalidated)
}

@Test
func `store icon observation token invalidates when codex account snapshots change`() {
let (_, store, controller) = self.makeController(
suiteName: "StatusItemIconObservationSignatureTests-codex-account-snapshots")
defer { controller.releaseStatusItemsForTesting() }

nonisolated(unsafe) var invalidated = false
withObservationTracking {
_ = store.iconObservationToken
} onChange: {
invalidated = true
}

let visibleAccount = CodexVisibleAccount(
id: "test-codex-account",
email: "email@example.com",
authFingerprint: nil,
storedAccountID: nil,
selectionSource: .profileHome(path: "/tmp"),
isActive: true,
isLive: true,
canReauthenticate: true,
canRemove: true)

store.codexAccountSnapshots = [
CodexAccountUsageSnapshot(
account: visibleAccount,
snapshot: nil,
error: nil,
sourceLabel: "cached"),
]

#expect(invalidated)
}

@Test
func `store icon observation signature changes when hide critters toggles`() {
let (settings, _, controller) = self.makeController(
Expand Down