Skip to content
Closed
Changes from all 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
29 changes: 20 additions & 9 deletions Tests/CodexBarTests/SpendDashboardTokenProvenanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ struct SpendDashboardTokenProvenanceTests {
store.activateCachedTokenAccountSnapshot(provider: .mistral, accountID: account.id)
#expect(store.tokenSnapshotPublicationRevision(for: .mistral) == baselineRevision)
store._test_providerRefreshOverride = { _ in }
let controller = SpendDashboardController(requestBuilder: { mode in
await SpendDashboardSource.makeRequest(settings: settings, store: store, mode: mode)
})
let controller = Self.dashboardController(settings: settings, store: store)
controller.update(configuration: SpendDashboardSource.configuration(settings: settings, store: store))
await Self.waitUntil { !controller.isRefreshing }
#expect(controller.model.groups.first?.totalCost == 3)
Expand All @@ -148,9 +146,7 @@ struct SpendDashboardTokenProvenanceTests {
return loadCount == 1 ? Self.tokenSnapshot(cost: 4) : Self.emptyTokenSnapshot()
}
await store.refreshTokenUsageNow(for: .bedrock, force: true)
let controller = SpendDashboardController(requestBuilder: { mode in
await SpendDashboardSource.makeRequest(settings: settings, store: store, mode: mode)
})
let controller = Self.dashboardController(settings: settings, store: store)
controller.update(configuration: SpendDashboardSource.configuration(settings: settings, store: store))
await Self.waitUntil { !controller.isRefreshing }
#expect(controller.model.groups.first?.totalCost == 4)
Expand All @@ -177,9 +173,7 @@ struct SpendDashboardTokenProvenanceTests {
}
await store.refreshTokenUsageNow(for: .bedrock, force: true)
let publicationRevision = store.tokenSnapshotPublicationRevision(for: .bedrock)
let controller = SpendDashboardController(requestBuilder: { mode in
await SpendDashboardSource.makeRequest(settings: settings, store: store, mode: mode)
})
let controller = Self.dashboardController(settings: settings, store: store)

controller.update(configuration: SpendDashboardSource.configuration(settings: settings, store: store))
await Self.waitUntil { !controller.isRefreshing }
Expand Down Expand Up @@ -308,6 +302,23 @@ struct SpendDashboardTokenProvenanceTests {
return (settings, store)
}

private static let fixtureNow = Date(timeIntervalSince1970: 1_784_179_200)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Choose a timezone-safe fixture instant

On hosts using Mountain, Pacific, Alaska, or Hawaii time, 1_784_179_200 is still July 15 locally (it is 2026-07-16 05:20 UTC). The Bedrock snapshot labels its bucket 2026-07-16 using the local dashboard calendar, so the newly fixed request clock ends the reporting window on July 15 and filters out the fixture's only entry; consequently forced successful empty publication removes prior spend without warning fails its initial totalCost == 4 assertion. Use an instant safely inside July 16 across supported time zones, such as the fixture snapshot's existing noon-UTC timestamp.

Useful? React with 👍 / 👎.


private static func dashboardController(
settings: SettingsStore,
store: UsageStore) -> SpendDashboardController
{
SpendDashboardController(
userDefaults: settings.userDefaults,
requestBuilder: { mode in
await SpendDashboardSource.makeRequest(
settings: settings,
store: store,
mode: mode,
now: Self.fixtureNow)
})
}

private static func tokenSnapshot(cost: Double) -> CostUsageTokenSnapshot {
CostUsageTokenSnapshot(
sessionTokens: 10,
Expand Down
Loading