mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
## What changed - Extend `account/usage/read` with an optional `threadId` request and a backward-compatible `threadUsage` response containing estimated credits, optional USD cost, and model, reasoning, speed, and token breakdowns. - Fetch thread usage for eligible Business and Enterprise plans when `/status` is opened, then update the rendered status card asynchronously. - Preserve terminal scrollback when replacing a visible status-card tail, and append a refreshed card when the original tail can no longer be updated. ## Testing - Add app-server coverage for authentication, canonical thread IDs, unavailable billing routes, and malformed IDs. - Add TUI coverage for usage formatting, stale responses, retries, history updates, terminal reflow, and scrollback preservation. GitOrigin-RevId: 49300914b3fba917c0f08e8595363e04e5ba6d37
40 lines
1.2 KiB
Rust
40 lines
1.2 KiB
Rust
use super::*;
|
|
use codex_app_server_protocol::AccountTokenUsageSummary;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn loaded_state_freezes_chart_anchor_date_at_completion() {
|
|
let state = Arc::new(RwLock::new(TokenActivityState::Loading));
|
|
let handle = TokenActivityHandle {
|
|
state: Arc::clone(&state),
|
|
};
|
|
let today =
|
|
NaiveDate::from_ymd_opt(/*year*/ 2026, /*month*/ 5, /*day*/ 29).expect("valid date");
|
|
|
|
handle.finish_with_today(
|
|
Ok(GetAccountTokenUsageResponse {
|
|
summary: AccountTokenUsageSummary {
|
|
lifetime_tokens: None,
|
|
peak_daily_tokens: None,
|
|
longest_running_turn_sec: None,
|
|
current_streak_days: None,
|
|
longest_streak_days: None,
|
|
},
|
|
daily_usage_buckets: None,
|
|
thread_usage: None,
|
|
}),
|
|
today,
|
|
);
|
|
|
|
let state = state.read().expect("token activity state poisoned");
|
|
match &*state {
|
|
TokenActivityState::Loaded {
|
|
today: loaded_today,
|
|
..
|
|
} => {
|
|
assert_eq!(*loaded_today, today);
|
|
}
|
|
other => panic!("expected loaded state, got {other:?}"),
|
|
}
|
|
}
|