Add gated plan usage history to TUI analytics (#45766)

## What changed

- Add consumer plan usage history behind `analytics_plan_history`, disabled by default, fetching seven days of five-hour and weekly allowance periods.
- Show period usage percentages with expandable breakdowns by feature, model, surface, or turn start, plus snapshot freshness and incomplete coverage indicators.
- Preserve unknown usage separately from zero and handle an unavailable history endpoint without blocking other analytics reports.

## Testing

Add backend and TUI tests for unavailable endpoints, response validation, feature and account gating, account changes during requests, period navigation, snapshot resets, and narrow and wide layouts.

GitOrigin-RevId: 7bea87a3407730b18040d7dda7e7dd0afe67fb2e
This commit is contained in:
Felipe Coury authored and copyberry committed 2026-09-15 19:12:18 +00:00
1 parent 0e7ab7c1b5
commit 0d0979f457
23 files changed
+1062 -18

No files matched your search

@@ -819,3 +819,30 @@ async fn live_account_identity_is_visible_and_closing_aborts_pending_loads() {
view.cancel_loads();
assert!(cancelled_rx.await.is_err());
}
#[tokio::test]
async fn plan_history_rejects_account_change_during_response() {
let server = MockServer::start().await;
for status in [200, 404, 503] {
server.reset().await;
let (home, live) = live(&server, "plus").await;
let home_path = home.path().to_path_buf();
Mock::given(method("GET"))
.and(path("/backend-api/wham/usage/plan_limit_history"))
.and(header("chatgpt-account-id", "account-a"))
.respond_with(move |_: &wiremock::Request| {
sign_in(&home_path, "account-a", "user-b", "plus");
ResponseTemplate::new(status).set_body_json(json!({
"data_as_of":"2026-09-02T00:00:00Z", "coverage_start":null,
"coverage_complete":true, "periods":[]
}))
})
.expect(/*r*/ 1)
.mount(&server)
.await;
assert_eq!(
live.plan_history().await.err().unwrap(),
"Account changed. Press R to refresh Analytics."
);
}
}