mirror of
https://github.com/openai/codex.git
synced 2026-11-26 07:26:11 +00:00
Route pet asset downloads through the shared HTTP client (#36008)
## Why Built-in pet downloads used a standalone blocking client, so CDN redirects did not use Codex's configured route handling. ## What changed - Download pet spritesheets asynchronously with a reusable `RouteAwareClientPool`. - Keep cache validation, asset installation, and pet decoding off the async runtime while sharing one asset-and-load path across startup, previews, and selection. - Preserve the download size limit while consuming streamed response chunks, and remove the TUI's direct `reqwest` dependency. ## Testing Add coverage for oversized response chunks, cached built-in assets, pet loads without an existing Tokio runtime, and stale preview and selection completions. GitOrigin-RevId: 725e76f3ddb7e84b7212769892f28dc0add15741
This commit is contained in:
1 parent
ad6fc66b6d
commit
09cf609218
11 files changed
+293
-95
No files matched your search
@@ -0,0 +1,86 @@
|
||||
use super::*;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn pet_load_without_runtime_sends_completion_event() {
|
||||
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
let app_event_tx = AppEventSender::new(tx);
|
||||
|
||||
spawn_pet_load(
|
||||
async { Ok::<Option<crate::pets::AmbientPet>, String>(None) },
|
||||
app_event_tx,
|
||||
|result| AppEvent::ConfiguredPetLoaded {
|
||||
pet_id: crate::pets::DEFAULT_PET_ID.to_string(),
|
||||
result,
|
||||
},
|
||||
);
|
||||
|
||||
match rx.blocking_recv().expect("pet load completion event") {
|
||||
AppEvent::ConfiguredPetLoaded { pet_id, result } => {
|
||||
assert_eq!(pet_id, crate::pets::DEFAULT_PET_ID);
|
||||
assert!(result.expect("successful pet load").is_none());
|
||||
}
|
||||
event => panic!("expected configured pet completion, got {event:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn shared_pet_load_uses_cached_builtin_assets() {
|
||||
let (chat, _tx, _rx, _op_rx) =
|
||||
crate::chatwidget::tests::make_chatwidget_manual_with_sender().await;
|
||||
let codex_home = tempfile::tempdir().unwrap();
|
||||
crate::pets::write_test_pack(codex_home.path());
|
||||
|
||||
crate::pets::load_pet_with_assets(
|
||||
crate::pets::DEFAULT_PET_ID.to_string(),
|
||||
AbsolutePathBuf::from_absolute_path(codex_home.path()).expect("absolute temporary path"),
|
||||
chat.frame_requester.clone(),
|
||||
/*animations_enabled*/ false,
|
||||
&chat.pet_http_client,
|
||||
)
|
||||
.await
|
||||
.expect("load cached built-in pet");
|
||||
|
||||
assert!(
|
||||
codex_home
|
||||
.path()
|
||||
.join("cache")
|
||||
.join("tui-pets")
|
||||
.join("frame-cache")
|
||||
.join(crate::pets::DEFAULT_PET_ID)
|
||||
.is_dir()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn stale_pet_preview_completion_keeps_current_preview() {
|
||||
let (mut chat, _tx, _rx, _op_rx) =
|
||||
crate::chatwidget::tests::make_chatwidget_manual_with_sender().await;
|
||||
chat.pet_picker_preview_request_id = 2;
|
||||
chat.pet_picker_preview_pet = Some(crate::pets::test_ambient_pet(
|
||||
chat.frame_requester.clone(),
|
||||
/*animations_enabled*/ false,
|
||||
));
|
||||
|
||||
chat.finish_pet_picker_preview_load(/*request_id*/ 1, Err("stale preview".to_string()));
|
||||
|
||||
assert!(chat.pet_picker_preview_pet.is_some());
|
||||
assert_eq!(chat.pet_picker_preview_request_id, 2);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn stale_pet_selection_completion_keeps_current_loading_popup() {
|
||||
let (mut chat, _tx, _rx, _op_rx) =
|
||||
crate::chatwidget::tests::make_chatwidget_manual_with_sender().await;
|
||||
let current_request_id = chat.show_pet_selection_loading_popup();
|
||||
let stale_request_id = current_request_id.wrapping_sub(/*rhs*/ 1);
|
||||
|
||||
assert!(!chat.finish_pet_selection_loading_popup(stale_request_id));
|
||||
assert_eq!(
|
||||
chat.bottom_pane.active_view_id(),
|
||||
Some(crate::chatwidget::PET_SELECTION_LOADING_VIEW_ID)
|
||||
);
|
||||
assert!(chat.finish_pet_selection_loading_popup(current_request_id));
|
||||
assert_eq!(chat.bottom_pane.active_view_id(), None);
|
||||
}
|
||||
Reference in new issue
Block a user