facett-app/src/bin/devid_release_probe.rs
//! **The RELEASE-profile probe for the DEV-ID chip.**
//!
//! This binary exists to be compiled with `--release` and run by
//! `facett-app/tests/devid_release_profile.rs`. It is not a demo and nobody runs it by
//! hand; it is behind `required-features = ["devid-probe"]` so a normal build of
//! facett-app never produces it.
//!
//! # Why a separate process at all
//!
//! `debug_assertions` is a compile-time fact and `cargo test` always compiles with it
//! **on**. So no `#[test]`, anywhere, can observe what a release build does — and that is
//! not a theoretical gap: the chip shipped gated on `#[cfg(debug_assertions)]` alone,
//! `badge` compiled to an empty function in every installed `korp-ui`, and five tests
//! stayed green through it. The only way to assert on a release build is to *build one
//! and run it*.
//!
//! # What it renders
//!
//! A real one-slot [`Scene`] through [`facett_app::scene::render`] — the same container
//! korp uses (`main.rs` calls `scene::render`), on a real [`egui::Context`] with AccessKit
//! switched on. It then reports what actually landed in the accessibility tree. That is
//! the *applied* output: not "the gate says yes", but "an atom carrying the chip's text
//! exists in the tree a screen reader / robot driver would read".
//!
//! # Output
//!
//! One line of JSON on stdout:
//!
//! ```json
//! {"debug_assertions":false,"enabled":true,"badge_text":"korp/map_canvas",
//! "devid_atoms":1,"labels":["dev-id: korp/map_canvas"]}
//! ```
//!
//! `debug_assertions` is reported so the caller can PROVE the process it inspected really
//! was a release build. Without that field a mis-wired test would silently assert on a
//! debug binary and pass for the wrong reason.
use facett_app::scene::{self, NavState, Pane, Scene, SceneHost};
use serde_json::{json, Value};
/// The slot id the probe renders. Deliberately korp-shaped: `korp` is a component the
/// errcode registry really carries, so a registered chip must read `korp/map_canvas`.
const SLOT: &str = "map_canvas";
struct Probe;
impl SceneHost for Probe {
fn slot(&mut self, id: &str, ui: &mut egui::Ui) -> Value {
ui.label(format!("content of {id}"));
Value::Null
}
fn component(&self) -> &'static str {
"korp"
}
}
fn main() {
let scene = Scene::new("devid-release-probe", Pane::slot("root", SLOT).title("Map"));
let mut nav = NavState::new(&scene);
let mut host = Probe;
let ctx = egui::Context::default();
ctx.enable_accesskit();
let input = egui::RawInput {
screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 800.0))),
..Default::default()
};
// Two frames: egui hands back the AccessKit tree from the frame AFTER the one that
// enabled it, and a scene's first frame is also its layout pass.
let mut labels: Vec<String> = Vec::new();
for _ in 0..2 {
let mut out = ctx.run_ui(input.clone(), |ui| {
scene::render(&scene, &mut nav, ui, &mut host);
});
out.textures_delta.clear();
if let Some(update) = out.platform_output.accesskit_update {
labels = update
.nodes
.iter()
.filter_map(|(_, n)| n.label())
.filter(|l| l.contains(facett_core::devid::DEVID_ATOM))
.map(|l| l.to_string())
.collect();
}
}
let (badge_text, _) = facett_core::devid::badge_text(Probe.component(), SLOT);
println!(
"{}",
json!({
// The load-bearing field: proof the caller inspected a RELEASE process.
"debug_assertions": cfg!(debug_assertions),
"enabled": facett_core::devid::enabled(),
"badge_text": badge_text,
"devid_atoms": labels.len(),
"labels": labels,
})
);
}