From ae713f7bd8c5a0f15987838aa130a8a3d8f96ad9 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Tue, 27 Oct 2026 09:27:51 +0100 Subject: [PATCH] refactor: item_render's error-order check lives in item_render's tests model_library's test ended with a check of ItemRenderer::load_with_library, which made model_library depend on item_render, one of the edges that keep the client lib in a single cycle. The check moves to item_render's tests with its own fixture. No behaviour change. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/item_render.rs | 27 ++++++++++++++++++++++ crates/horizon-client/src/model_library.rs | 13 +---------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/crates/horizon-client/src/item_render.rs b/crates/horizon-client/src/item_render.rs index 8188eb712..320988f5e 100644 --- a/crates/horizon-client/src/item_render.rs +++ b/crates/horizon-client/src/item_render.rs @@ -759,6 +759,33 @@ pub fn cluster_poses(state: &ItemRenderState, pose: Mat4, amount: u32, seed: i64 mod tests { use super::*; + /// A bad item model surfaces only once items.json has loaded, so a broken + /// items.json still reports itself first. + #[test] + fn item_model_errors_wait_for_the_item_definitions() -> crate::Result<()> { + let root = + std::env::temp_dir().join(format!("horizon-item-model-errors-{}", std::process::id())); + let model = root.join("assets/horizon/models/INVALID.json"); + fs::create_dir_all(model.parent().unwrap())?; + fs::write(model, "{}")?; + let library = crate::model_library::ParsedModels::load(&root).into_item_library(); + assert!(library.is_err()); + fs::write(root.join("items.json"), "{")?; + let load = || { + ItemRenderer::load_with_library(&root, library.clone()) + .err() + .unwrap() + .to_string() + }; + let broken_items = load(); + fs::write(root.join("items.json"), "{}")?; + let bad_model = load(); + let _ = fs::remove_dir_all(&root); + assert!(!broken_items.starts_with("item models:")); + assert!(bad_model.starts_with("item models:")); + Ok(()) + } + #[test] fn rendered_amounts_follow_the_count_bands() { let bands: Vec = [0, 1, 2, 16, 17, 32, 33, 48, 49, 64] diff --git a/crates/horizon-client/src/model_library.rs b/crates/horizon-client/src/model_library.rs index 018bc6af2..5edf0f5a4 100644 --- a/crates/horizon-client/src/model_library.rs +++ b/crates/horizon-client/src/model_library.rs @@ -232,18 +232,7 @@ mod tests { .block_library(&fixture.0, vec!["horizon:nested/child".into()]) .is_ok() ); - let library = parsed.into_item_library(); - assert!(library.is_err()); - fs::write(fixture.0.join("items.json"), "{")?; - let load = || { - crate::item_render::ItemRenderer::load_with_library(&fixture.0, library.clone()) - .err() - .unwrap() - .to_string() - }; - assert!(!load().starts_with("item models:")); - fs::write(fixture.0.join("items.json"), "{}")?; - assert!(load().starts_with("item models:")); + assert!(parsed.into_item_library().is_err()); Ok(()) } }