From 10fbb618384ec4c214fced0feed3adf1d72c4cb6 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 17 Aug 2026 16:27:40 +0000 Subject: [PATCH] Cache the test pet spritesheet encoding (#39028) ## Why Pet tests reuse the same blank WebP spritesheet fixture, so encoding a new image for every temporary path does unnecessary repeated work. ## What changed Encode the test spritesheet once with `LazyLock`, then write the cached WebP bytes to each requested fixture path. GitOrigin-RevId: 26d75bb1bac448717ca63aeb82eb4e500c86fad8 --- codex-rs/tui/src/pets/catalog.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/codex-rs/tui/src/pets/catalog.rs b/codex-rs/tui/src/pets/catalog.rs index e1d5c0c788..0beb01b3e6 100644 --- a/codex-rs/tui/src/pets/catalog.rs +++ b/codex-rs/tui/src/pets/catalog.rs @@ -1,5 +1,12 @@ //! Built-in pet catalog ported from the Codex App avatar catalog. +#[cfg(test)] +use std::fs; +#[cfg(test)] +use std::io::Cursor; +#[cfg(test)] +use std::sync::LazyLock; + pub(super) const DEFAULT_FRAME_WIDTH: u32 = 192; pub(super) const DEFAULT_FRAME_HEIGHT: u32 = 208; pub(super) const DEFAULT_FRAME_COLUMNS: u32 = 8; @@ -72,6 +79,13 @@ pub(super) fn builtin_pet(id: &str) -> Option { #[cfg(test)] pub(super) fn write_test_spritesheet(path: &std::path::Path) { - let image = image::RgbaImage::new(SPRITESHEET_WIDTH, SPRITESHEET_HEIGHT); - image.save(path).unwrap(); + static TEST_SPRITESHEET: LazyLock> = LazyLock::new(|| { + let image = image::RgbaImage::new(SPRITESHEET_WIDTH, SPRITESHEET_HEIGHT); + let mut bytes = Vec::new(); + image::DynamicImage::ImageRgba8(image) + .write_to(&mut Cursor::new(&mut bytes), image::ImageFormat::WebP) + .unwrap(); + bytes + }); + fs::write(path, TEST_SPRITESHEET.as_slice()).unwrap(); }