From 9bc147affd2dcf7c9d61d77f84d94cc744a6a383 Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 11 Nov 2026 15:46:01 +0000 Subject: [PATCH] Level tables key every type of the library under craft_ui The surface and story layout tables name the library's types under craft_ui, but since the split a type's crate target is the crate that declares it, so no library row matched: Slider's value groups lost their form rows and every library type sat on the panel surface. The table key reads a type of any library crate as craft_ui, as the level rows already read a library module path. The stale-row check runs in the craft-ui facade's trials, where every crate of the library is linked, and checks the library's rows whenever one of its crates is. --- crates/ui-contract/src/contract/level.rs | 44 ++++++++++++------- .../ui-contract/src/contract/level_table.rs | 3 +- crates/ui-contract/src/contract/mod.rs | 2 +- crates/ui/tests/it/components_index.rs | 12 ++++- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/crates/ui-contract/src/contract/level.rs b/crates/ui-contract/src/contract/level.rs index 2410bc018..35bb251d9 100644 --- a/crates/ui-contract/src/contract/level.rs +++ b/crates/ui-contract/src/contract/level.rs @@ -128,7 +128,8 @@ const LIBRARY: &[(&str, Level)] = &[ ("value_drag", Controls), ]; -/// The crates of the craft-ui library: the facade and the crates it re-exports, as `module_path!` spells them. +/// The crates of the craft-ui library: the facade, whose name the tables give every type of the library, and the +/// crates it re-exports, as `module_path!` spells them. const LIBRARY_CRATES: [&str; 8] = [ "craft_ui", "craft_ui_runtime", @@ -182,10 +183,13 @@ fn surface_of(registration: &Registration) -> Surface { SURFACES.iter().find(|row| row.0 == target && row.1 == short).map_or(Surface::Panel, |row| row.2) } -/// The crate target and short name of a registered type, as the tables name it. +/// The crate target and short name of a registered type, as the tables name it: a type of the library under the +/// library's own name, `craft_ui`, whichever of its crates declares it. fn table_key(registration: &Registration) -> (&'static str, &'static str) { let path = base_path(parts(registration).1); - (registration.crate_target(), path.rsplit("::").next().unwrap_or(path)) + let target = registration.crate_target(); + let target = if LIBRARY_CRATES.contains(&target) { LIBRARY_CRATES[0] } else { target }; + (target, path.rsplit("::").next().unwrap_or(path)) } /// The type's path without its type arguments. @@ -344,16 +348,21 @@ fn linked() -> Vec<&'static Registration> { super::registrations().into_iter().filter(|registration| registration.crate_target() == registration.crate_name().replace('-', "_")).collect() } -/// Guards against a surface or story layout row whose type is gone, in every crate that has a linked registration, and -/// against a layout row whose story group is gone. -#[crate::testing::trial] -fn surface_table_has_no_stale_row() { - let linked = linked(); +/// The rows of the surface and story layout tables whose type is not among `linked`, in every crate that has a type +/// there, and the layout rows whose story group none of the type's linked stories has. The library's crates are +/// linked together only above them, so the craft-ui facade's trials run it with every registration of the library. +#[cfg(feature = "testing")] +#[doc(hidden)] +pub fn stale_table_rows(linked: &[&'static Registration]) -> Vec { let named: std::collections::HashSet<(&str, &str)> = linked.iter().map(|registration| table_key(registration)).collect(); - let crates: std::collections::HashSet<&str> = named.iter().map(|(target, _)| *target).collect(); + let mut crates: std::collections::HashSet<&str> = named.iter().map(|(target, _)| *target).collect(); + // The library's rows are checked whenever one of its crates is linked, whatever key its types get. + if linked.iter().any(|registration| LIBRARY_CRATES.contains(®istration.crate_target())) { + crates.extend(LIBRARY_CRATES); + } let rows = SURFACES.iter().map(|row| (row.0, row.1)).chain(STORY_LAYOUTS.iter().map(|row| (row.0, row.1))); - let stale: Vec<_> = rows.filter(|row| crates.contains(row.0) && !named.contains(row)).collect(); - assert!(stale.is_empty(), "rows without a registered type: {stale:?}"); + let mut stale: Vec = + rows.filter(|row| crates.contains(row.0) && !named.contains(row)).map(|row| format!("{row:?}: no linked type")).collect(); // A layout row names a group of the type's linked stories, where the type's stories are linked. let keys: std::collections::HashMap<&str, (&str, &str)> = linked.iter().map(|registration| (parts(registration).1, table_key(registration))).collect(); @@ -363,12 +372,13 @@ fn surface_table_has_no_stale_row() { groups.entry(key).or_default().push(entry.story.group_name(key.1)); } } - let stale: Vec<_> = STORY_LAYOUTS - .iter() - .filter(|row| groups.get(&(row.0, row.1)).is_some_and(|names| !names.iter().any(|name| name == row.2))) - .map(|row| (row.0, row.1, row.2)) - .collect(); - assert!(stale.is_empty(), "layout rows without a story group: {stale:?}"); + stale.extend( + STORY_LAYOUTS + .iter() + .filter(|row| groups.get(&(row.0, row.1)).is_some_and(|names| !names.iter().any(|name| name == row.2))) + .map(|row| format!("{:?}: no such story group", (row.0, row.1, row.2))), + ); + stale } /// Guards against a registered type that no row places (it would list under no level) and against names a diff --git a/crates/ui-contract/src/contract/level_table.rs b/crates/ui-contract/src/contract/level_table.rs index 1313199a4..8acb4d0b3 100644 --- a/crates/ui-contract/src/contract/level_table.rs +++ b/crates/ui-contract/src/contract/level_table.rs @@ -1,7 +1,8 @@ //! How a viewer shows the stories of a type, as the old gallery drew them: the surface of each type that does not sit //! on a dock panel (bars on the window chrome, canvas tools and overlays on the document, docks, dialogs and shells on //! their own), and the layout of each type whose stories are not stacked. A type added since follows the same -//! convention. +//! convention. A type of the craft-ui library is under the library's name, `craft_ui`, whichever of its crates declares +//! it. use super::level::StoryLayout::{self, Columns, FormRows}; use super::level::Surface::{self, Canvas, Chrome, Own}; diff --git a/crates/ui-contract/src/contract/mod.rs b/crates/ui-contract/src/contract/mod.rs index 6c554b42b..31f74f09a 100644 --- a/crates/ui-contract/src/contract/mod.rs +++ b/crates/ui-contract/src/contract/mod.rs @@ -82,7 +82,7 @@ pub use lazy::Lazy; pub(crate) use level::kit_module; #[doc(hidden)] #[cfg(feature = "testing")] -pub use level::{Catalog, CatalogEntry, Level, StoryLayout, Surface, catalog, story_title}; +pub use level::{Catalog, CatalogEntry, Level, StoryLayout, Surface, catalog, stale_table_rows, story_title}; pub use looks::Looks; pub use overlay::{Overlay, OverlayUi, Overlays, Popup, PopupHandle, SizeLimits, Trigger}; pub use paint_ui::PaintUi; diff --git a/crates/ui/tests/it/components_index.rs b/crates/ui/tests/it/components_index.rs index bb07dbf20..e932828e1 100644 --- a/crates/ui/tests/it/components_index.rs +++ b/crates/ui/tests/it/components_index.rs @@ -1,5 +1,7 @@ -//! The components index (`docs/components-index.md`) is what the registrations give. +//! The components index (`docs/components-index.md`) is what the registrations give, and the level tables name only +//! registered types. +use craft_ui::contract::stale_table_rows; use craft_ui::testing::index::components_index; use craft_ui::testing::library_registrations; use craft_ui::testing::trial; @@ -14,3 +16,11 @@ fn the_committed_components_index_is_what_the_registrations_give() { "docs/components-index.md is stale; run `cargo run -p craft-ui-gallery --bin components-index`" ); } + +/// Guards against a surface or story layout row whose type or story group is gone; the library's crates are linked +/// together only here. +#[trial] +fn the_level_tables_name_only_registered_types_and_story_groups() { + let stale = stale_table_rows(&library_registrations()); + assert!(stale.is_empty(), "stale level table rows: {stale:#?}"); +}