mirror of
https://github.com/openai/codex.git
synced 2026-11-14 21:40:39 +00:00
## Why Several TUI views hard-code 24-hour timestamps even when the detected system preference is 12-hour time. ## What changed Use the existing `ClockFormat` preference for rate-limit and spend-control reset times, usage notices, backend banners, reset-credit expiration times, analytics timestamps, and expanded session details in the resume picker. Capture the preference when constructing views and preserve existing timezone handling, including analytics' UTC labels. ## Testing Add coverage for midnight, noon, and next-day reset labels in both clock formats, plus 12-hour analytics rendering with UTC labels. Update snapshots for status, banners, usage notices, reset-credit details, and expanded sessions, including narrow-width layouts. Pin test fixtures to explicit clock formats for deterministic output. GitOrigin-RevId: 73c36d603ddc4eb7800614650a14c6f2961f8b70
58 lines
2.0 KiB
Rust
58 lines
2.0 KiB
Rust
use super::BackendBanner;
|
|
use pretty_assertions::assert_eq;
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
fn parse_rejects_more_actions_than_the_inline_banner_can_display() {
|
|
let labels: Vec<_> = (1..=8).map(|index| format!("Action {index}")).collect();
|
|
let mut raw = json!({
|
|
"banner_type": "usage_limit", "title": "Usage limit reached",
|
|
"description": "Choose how to continue.",
|
|
"ctas": labels.iter().map(|label| json!({
|
|
"action": "view_usage", "label": label,
|
|
})).collect::<Vec<_>>(),
|
|
});
|
|
let banner = BackendBanner::parse(&raw).expect("eight actions fit");
|
|
assert_eq!(
|
|
banner
|
|
.actionable_banner(crate::clock_format::ClockFormat::TwentyFourHour)
|
|
.actions
|
|
.into_iter()
|
|
.map(|action| action.name)
|
|
.collect::<Vec<_>>(),
|
|
labels
|
|
);
|
|
|
|
raw["ctas"].as_array_mut().unwrap().push(json!({
|
|
"action": "view_usage", "label": "Hidden ninth action",
|
|
}));
|
|
assert_eq!(BackendBanner::parse(&raw), None);
|
|
}
|
|
|
|
#[test]
|
|
fn parse_rejects_unsupported_or_unrenderable_content() {
|
|
let valid = json!({
|
|
"banner_type": "usage_limit", "title": "Usage limit reached",
|
|
"description": "Choose how to continue.", "ctas": [],
|
|
});
|
|
for invalid_fields in [
|
|
json!({"presentation":"future_mode"}),
|
|
json!({"presentation":null}),
|
|
json!({"title":" "}),
|
|
json!({"title":"x".repeat(1025)}),
|
|
json!({"title":"line\n".repeat(4)}),
|
|
json!({"description":"x".repeat(4097)}),
|
|
json!({"description":"line\n".repeat(13)}),
|
|
json!({"blocked_model_slug":""}),
|
|
json!({"blocked_model_slug":"bad\nslug"}),
|
|
json!({"fallback_model_slugs":["x".repeat(257)]}),
|
|
json!({"fallback_model_slugs":vec!["model"; 17]}),
|
|
] {
|
|
let mut raw = valid.clone();
|
|
raw.as_object_mut()
|
|
.unwrap()
|
|
.extend(invalid_fields.as_object().unwrap().clone());
|
|
assert_eq!(BackendBanner::parse(&raw), None, "{invalid_fields}");
|
|
}
|
|
}
|