Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,17 @@ pub fn filter_legacy_buckets(entries: &[BillingCycleUsageEntry]) -> Vec<BillingC

/// "Is there any data in `entries` that's not my own?"
pub fn has_non_viewer_data(entries: &[BillingCycleUsageEntry], viewer_uid: Option<&str>) -> bool {
entries.iter().any(|e| match &e.subject_type {
AiCreditsUsageAndCostSubjectType::Team => true,
_ => match (e.subject_uid.as_deref(), viewer_uid) {
(Some(uid), Some(viewer)) => uid != viewer,
// Unknown subject — conservatively treat as non-viewer.
_ => true,
},
})
entries
.iter()
.filter(|e| e.credits_used != 0 || e.cost_cents != 0)
.any(|e| match &e.subject_type {
AiCreditsUsageAndCostSubjectType::Team => true,
_ => match (e.subject_uid.as_deref(), viewer_uid) {
(Some(uid), Some(viewer)) => uid != viewer,
// Unknown subject — conservatively treat as non-viewer.
_ => true,
},
})
}

pub fn format_credits(credits: i64) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ fn has_non_viewer_data_returns_true_for_team_aggregate_row() {
assert!(has_non_viewer_data(&entries, Some(VIEWER_UID)));
}

#[test]
fn has_non_viewer_data_returns_false_for_empty_team_aggregate_row() {
// The server can send a zero Team aggregate row for a solo workspace. That
// placeholder should not create the "Other members" row.
let entries = vec![
viewer_user_entry(),
entry(
AiCreditsUsageAndCostSubjectType::Team,
None,
AiCreditsUsageAndCostType::Aggregate,
AiCreditsUsageBucket::Aggregate,
AiCreditsUsageSource::Aggregate,
0,
0,
),
];
assert!(!has_non_viewer_data(&entries, Some(VIEWER_UID)));
}

#[test]
fn has_non_viewer_data_returns_true_for_other_user_row() {
// PerUserTotals / FullBreakdown emit per-user rows, so a departed teammate
Expand Down