facett-demo/tests/devid_badge.rs
//! **The DEV-ID badge, proven END-TO-END through the elm bridge.**
//!
//! `facett-core`'s own `devid::tests` drive [`badge_text`] and [`normalize`] with string
//! literals. That proves the mapping is right; it does NOT prove that a real pane ever
//! reaches it. The wiring between them is a `module_path!()` inside
//! `impl_facet_via_elm!`, and a `module_path!()` that expanded in the wrong crate would
//! leave every pane rendering `⟨unregistered⟩` while both unit tests stayed green — a
//! guard watching the half that cannot break.
//!
//! So this binary asks the actual panes, through the actual trait:
//!
//! ```bash
//! cargo test -p facett-demo --test devid_badge
//! ```
use facett_core::devid::{self, UNREGISTERED};
use facett_core::Facet;
/// **Pin the gate open for this binary, in whichever profile it was compiled in.**
///
/// The chip is off by default in a release build (it ships behind `FACETT_DEVID=1`), so
/// `the_badge_is_painted_by_the_draw_path_the_apps_actually_use` — a question about the
/// DRAW PATH, whose answer is the same in both profiles — failed under
/// `cargo test --release --workspace` with "no dev-id atom in the rendered tree"
/// (MEASURED 2026-08-31). Gating the file to `debug_assertions` would make it a dark file
/// in exactly the profile that ships; asserting only when the gate happens to be open
/// would turn a positive proof into "assert nothing" — LAW 2's named failure. Every test
/// here calls this so the order libtest picks cannot decide the gate first.
fn force_devid_on() {
facett_core::devid::force_gate(true);
}
/// `Facet::component()` on a REAL bridged pane must reach the registry.
///
/// If this goes red while `facett-core`'s unit tests stay green, the bridge is broken,
/// not the mapping.
#[test]
fn real_bridged_panes_report_a_registry_component() {
force_devid_on();
let map = facett_map::MapView::new("2-D map", vec![(18.07, 59.33)]);
let raw = Facet::component(&map);
assert!(!raw.is_empty(), "the elm bridge left component() empty — module_path! did not land");
// Pin the RAW value, not just the normalised one. `module_path!()` inside a
// macro_rules body expands where the macro is INVOKED; had it somehow expanded in
// facett-core instead, every pane would report the same core path and `normalize`
// would still hand back something plausible. This is the assertion that can tell
// those two worlds apart.
assert_eq!(raw, "facett_map", "module_path! expanded in the wrong crate");
assert_eq!(devid::normalize(raw), "map", "raw was {raw:?}");
let (text, registered) = devid::badge_text(raw, Facet::title(&map));
assert!(registered, "a registered pane must not be marked unregistered: {text:?}");
assert_eq!(text, "map/2-D map", "the chip shows the registry name AND the pane");
assert!(!text.contains(UNREGISTERED));
// The whole point of the id: it resolves to somewhere to look.
let (dir, file) = devid::resolve(raw).expect("map resolves");
assert_eq!(dir, "facett-map");
assert!(!file.is_empty(), "a resolved id must name a source file");
}
/// The SAME assertion for the 3-D map, so a pass cannot come from one lucky crate.
#[test]
fn the_3d_map_reports_its_own_component_not_the_geomaps() {
force_devid_on();
let m = facett_map3d::Map3D::from_ways("3-D map", &[], 10.0);
let raw = Facet::component(&m);
assert_eq!(devid::normalize(raw), "map3d", "raw was {raw:?}");
assert!(devid::is_registered(raw));
let (dir, _) = devid::resolve(raw).expect("map3d resolves");
assert_eq!(dir, "facett-map3d", "each pane must resolve to its OWN crate");
// And the two are genuinely different — the identity-value trap: a component() that
// returned one constant for every pane would satisfy both tests above in isolation.
let g = facett_map::MapView::new("2-D map", vec![(18.07, 59.33)]);
assert_ne!(
devid::normalize(Facet::component(&m)),
devid::normalize(Facet::component(&g)),
"two different panes reported the SAME dev-id — the badge cannot tell them apart"
);
}
/// **The chip is really ON SCREEN** — the assertion the two tests above cannot make.
///
/// They prove a pane knows its id and that the id resolves. Neither proves the badge is
/// painted, and the badge was in fact first wired into `Deck::pane_ui` — a draw path
/// facett-demo never calls (it goes through `Deck::ui`). That version compiled, tested
/// green, and would have shown nothing. So this walks the live AccessKit tree of a real
/// rendered deck and requires the atom to be there, the same net
/// `deck_no_error_atoms.rs` uses.
#[test]
fn the_badge_is_painted_by_the_draw_path_the_apps_actually_use() {
force_devid_on();
use egui_kittest::kittest::{By, Queryable};
use egui_kittest::Harness;
use facett_core::devid::DEVID_ATOM;
let mut deck = facett_core::FacetDeck::new(vec![Box::new(facett_map::MapView::new(
"2-D map",
vec![(18.07, 59.33)],
))]);
let mut harness = Harness::new_ui(move |ui| {
deck.ui(ui);
});
harness.run();
// Counted through the same `label_contains` net `deck_no_error_atoms.rs` uses.
let any = harness.query_all(By::new().label_contains(DEVID_ATOM)).count();
assert!(any > 0, "no dev-id atom in the rendered tree — the badge is not painted by FacetDeck::ui");
let with_id = harness.query_all(By::new().label_contains(&format!("{DEVID_ATOM} map"))).count();
assert!(with_id > 0, "the chip rendered but does not carry the pane's id");
let unregistered =
harness.query_all(By::new().label_contains(facett_core::devid::UNREGISTERED)).count();
assert_eq!(unregistered, 0, "a REGISTERED pane rendered the unregistered marker");
}