From 15e2b0f23bc94d132e940e7fc5ac286d6eec9d62 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 27 Oct 2026 16:02:22 -0700 Subject: [PATCH 1/2] Tests: hold the served font catalog still while font menu tests settle options_font_family_preserves_peer_faces_and_batches_layer_flags failed in 7 of 10 full photocraft-ui-egui lib runs on macOS with "Harness::run exceeded max_steps (8)", and passed alone. The served catalog is process-wide, and each family another test adds while the font menu is open adds a row that egui 0.37 styles on its next pass, so the menu needs one more pass per family. the_font_menu_settles_while_other_engines_register_fonts adds a family on every pass of its own harness. Tests that add served families now hold a test-only lock for writing (served_fonts::changing_catalog), and the two tests that wait for the real font menu to settle hold it for reading (steady_catalog), as CHILD_SPAWNS does for the file-lock tests (#7418). --- crates/ui-egui/src/text/served_fonts.rs | 24 ++++++++++++++++++- crates/ui-egui/src/tools/type_font_preview.rs | 5 +++- .../src/tools/type_tool/canvas_tests.rs | 8 ++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/text/served_fonts.rs b/crates/ui-egui/src/text/served_fonts.rs index b7ae085f41..7a418e3f8d 100644 --- a/crates/ui-egui/src/text/served_fonts.rs +++ b/crates/ui-egui/src/text/served_fonts.rs @@ -12,6 +12,25 @@ use crate::PhotocraftApp; /// Layers whose document was busy with a background job when their font arrived. static PENDING: Mutex> = Mutex::new(Vec::new()); +/// The served catalog is process-wide, and every family added while a font menu is open adds a +/// row that egui styles on its next pass, so `Harness::run` takes one more pass per family. Tests +/// that add families hold this for writing ([`changing_catalog`]), and tests that wait for an +/// open font menu to settle hold it for reading ([`steady_catalog`]). +#[cfg(test)] +static CATALOG: std::sync::RwLock<()> = std::sync::RwLock::new(()); + +/// Held by a test while it adds families to the served catalog. +#[cfg(test)] +pub(crate) fn changing_catalog() -> std::sync::RwLockWriteGuard<'static, ()> { + CATALOG.write().unwrap_or_else(PoisonError::into_inner) +} + +/// Held by a test while it waits for an open font menu to settle: no family is added meanwhile. +#[cfg(test)] +pub(crate) fn steady_catalog() -> std::sync::RwLockReadGuard<'static, ()> { + CATALOG.read().unwrap_or_else(PoisonError::into_inner) +} + /// Registers delivered font files (`(family, bytes)`, the family as the manifest lists it) and /// re-renders the type layers that use those families, or whose text falls back to them (a script /// fallback, e.g. Arabic set in Inter), and show our own layout. A PSD layer still @@ -83,7 +102,10 @@ mod tests { fn a_layer_in_a_script_redraws_when_that_scripts_fallback_arrives() { // Thai: other tests use other scripts (the served catalog is process-wide). let thai = "Served Test Thai"; - photocraft_text::served::add_fonts(&parse_manifest(&format!("{thai} | Regular | fonts/t/T.ttf | Thai\n")).0); + { + let _catalog = changing_catalog(); + photocraft_text::served::add_fonts(&parse_manifest(&format!("{thai} | Regular | fonts/t/T.ttf | Thai\n")).0); + } let layer = |text: &str| TextLayer { text: text.into(), font_family: "Inter".into(), ..Default::default() }; assert!(redraws_for(&layer("สวัสดี"), &[thai.into()]), "Thai text set in Inter falls back to it"); assert!(!redraws_for(&layer("hello"), &[thai.into()])); diff --git a/crates/ui-egui/src/tools/type_font_preview.rs b/crates/ui-egui/src/tools/type_font_preview.rs index bb91b61ea0..efbf32e22a 100644 --- a/crates/ui-egui/src/tools/type_font_preview.rs +++ b/crates/ui-egui/src/tools/type_font_preview.rs @@ -193,7 +193,10 @@ mod tests { // Families the host serves but hasn't sent (own names: the served catalog is process-wide). let (a, b) = ("Served Hover Rest A", "Served Hover Rest B"); let (fonts, _) = photocraft_text::served::parse_manifest(&format!("{a} | Regular | fonts/a/A.ttf\n{b} | Regular | fonts/b/B.ttf\n")); - photocraft_text::served::add_fonts(&fonts); + { + let _catalog = crate::served_fonts::changing_catalog(); + photocraft_text::served::add_fonts(&fonts); + } let mut app = app_with_type_layer(); let ctx = egui::Context::default(); diff --git a/crates/ui-egui/src/tools/type_tool/canvas_tests.rs b/crates/ui-egui/src/tools/type_tool/canvas_tests.rs index a6dd09e44a..010c9b4bcc 100644 --- a/crates/ui-egui/src/tools/type_tool/canvas_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/canvas_tests.rs @@ -1898,7 +1898,10 @@ fn variable_font_axes_become_sliders_with_the_drawn_value() { /// Families the host serves are in the font menu before they are fetched. #[test] fn the_font_menu_lists_served_families() { - photocraft_text::served::add_families(["Served Menu Test Serif".to_string()]); + { + let _catalog = crate::served_fonts::changing_catalog(); + photocraft_text::served::add_families(["Served Menu Test Serif".to_string()]); + } assert!(super::families().iter().any(|f| f == "Served Menu Test Serif")); } @@ -2176,6 +2179,7 @@ mod multi_layer_formatting { #[test] fn options_font_family_preserves_peer_faces_and_batches_layer_flags() { + let _catalog = crate::served_fonts::steady_catalog(); let (app, ids) = fixture(); let before = ids.map(|id| style(&app, id, 0)); let mut h = controls(app, false); @@ -2223,6 +2227,7 @@ mod multi_layer_formatting { /// Here both happen on every pass. #[test] fn the_font_menu_settles_while_other_engines_register_fonts() { + let _catalog = crate::served_fonts::changing_catalog(); let (app, _) = fixture(); let mut pass = 0u32; let mut h = Harness::builder().with_size(vec2(1100.0, 800.0)).build_ui_state( @@ -2249,6 +2254,7 @@ mod multi_layer_formatting { /// layers selected, sets them and is kept for new type, as the options bar's menu does. #[test] fn a_style_picked_in_the_character_sections_font_menu_is_kept_for_new_type() { + let _catalog = crate::served_fonts::steady_catalog(); let (app, ids) = fixture(); // The first style row under the family (so it is in view), other than the defaults'. let pick = super::super::styles("Inter").into_iter().find(|s| s != "Regular" && s != "Bold Italic").expect("Inter has several styles"); From a315580208602236d4348f317e7518e7d4182c64 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 29 Oct 2026 03:11:05 -0700 Subject: [PATCH 2/2] Tests: hold the served catalog lock while the UI-stack test adds families the_interface_languages_served_face_comes_first_in_the_ui_stack adds two families to the process-wide served catalog. It now holds changing_catalog() while it adds them, like the other tests that change the catalog, so a font menu test that holds steady_catalog() does not see new rows appear while it settles. --- crates/ui-egui/src/text/served_fonts.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/text/served_fonts.rs b/crates/ui-egui/src/text/served_fonts.rs index 7601e17c52..dfa75733d7 100644 --- a/crates/ui-egui/src/text/served_fonts.rs +++ b/crates/ui-egui/src/text/served_fonts.rs @@ -246,7 +246,12 @@ mod tests { #[test] fn the_interface_languages_served_face_comes_first_in_the_ui_stack() { let (jpan, hans) = ("Served Test Jpan", "Served Test Hans"); - photocraft_text::served::add_fonts(&parse_manifest(&format!("{jpan} | Regular | fonts/j/J.ttf | Jpan\n{hans} | Regular | fonts/h/H.ttf | Hans\n")).0); + { + let _catalog = changing_catalog(); + photocraft_text::served::add_fonts( + &parse_manifest(&format!("{jpan} | Regular | fonts/j/J.ttf | Jpan\n{hans} | Regular | fonts/h/H.ttf | Hans\n")).0, + ); + } crate::i18n::set_current(crate::i18n::Lang::from_code("zh-hans").expect("Simplified Chinese")); let ctx = egui::Context::default(); crate::theme::install_fonts(&ctx);