dwarves-gui/tests/robot_lenses_live.rs
//! **ROBOT-UI (LAW): the 🔍 Lenses (Mímir) pane renders LIVE findings THROUGH the host.**
//!
//! The LIVE twin of the dead-upstream Lenses scenario in
//! `robot_warehouse_dead_upstream.rs` (which proves an outage reads as UNAVAILABLE, never
//! a clean/empty warehouse). Here a REAL dwarves warehouse/Mímir PROXY
//! (`dwarves::warehouse_proxy`) fronts a LIVE embedded nornir (a `MockMimir` serving the
//! `Mimir.*` lens folds), and the SHIPPED shell (`build_native_app`, host-only, given ONLY
//! the dwarves proxy host) must render the lens findings the host folded — proving the
//! whole chain end-to-end with NO cluster and NO window:
//!
//! (live) embedded nornir Mímir ──> dwarves warehouse-proxy (:auto) ──> the 🔍 Lenses pane
//!
//! [`the_lenses_pane_renders_live_findings_via_the_host_given_only_dwarves_server`] — the
//! Lenses pane, scanned through the LIVE proxy, reports `scanned=true`, a `status` that is
//! NOT UNAVAILABLE, no `error`, `thin=true` (the fold happened on the host), and the REAL
//! bloat finding the upstream served (a named monomorphization with its instantiation
//! count) — LIVE data crossed the host, not a fabricated or empty reading. It stays
//! host-only: `NORNIR_SERVER` is poisoned and no `:7878`/nornir address leaks.
//!
//! Emits a `nornir-testmatrix` cell under `--features testmatrix`.
use dwarves_gui::{build_native_app, DWARVES_TABS};
use facett_core::Facet;
use nornir_warehouse_embed::testkit::{spawn_mock_mimir, MockMimir};
use serde_json::json;
const NORNIR_POISON: &str = "http://nornir-poison.example:7878";
#[allow(unused_variables)]
fn matrix(check: &str, ok: bool, detail: &str) {
#[cfg(feature = "testmatrix")]
nornir_testmatrix::functional_status("dwarves-gui", check, ok, detail);
}
/// The bloat finding the upstream Mímir serves — a REAL monomorphization tax (the exact
/// shape the pane's thin bloat view renders: an `evidence_note` + a `findings` array). The
/// symbol name is the load-bearing assertion: it must survive the proxy round-trip to the
/// pane's state_json, proving LIVE data (not an empty/fabricated reading).
const BLOAT_FINDING: &str = r#"{
"evidence_note": "generic bloat over symbol_sizes — 2 monomorphizations of 1 generic",
"findings": [
{ "symbol": "core::ptr::drop_in_place", "bytes": 180000, "instantiations": 2 }
]
}"#;
/// A LIVE Mímir upstream: the bloat lens serves a real finding; the rest answer honestly
/// empty (`{}`), which is what a healthy warehouse with no other findings returns. Every
/// `Mimir.*` RPC the thin pane calls must answer Ok, else the whole scan errors.
fn live_mimir_upstream() -> nornir_warehouse_embed::testkit::MockWarehouseServer {
spawn_mock_mimir(MockMimir {
generic_cost: BLOAT_FINDING.to_string(),
..Default::default()
})
}
fn assert_host_only(app: &mut dwarves_gui::tabbed::TabbedView) {
for (_key, label) in DWARVES_TABS.iter() {
Facet::update_json(app, &json!({ "set_tab": label }).to_string());
}
let whole = Facet::state_json(app).to_string();
assert!(
!whole.contains(":7878") && !whole.contains("nornir-poison.example"),
"host-only: no nornir `:7878` address may leak into the shell state_json"
);
}
#[test]
fn the_lenses_pane_renders_live_findings_via_the_host_given_only_dwarves_server() {
let upstream = live_mimir_upstream();
let proxy = dwarves::warehouse_proxy::spawn_proxy(upstream.endpoint.clone(), String::new());
let dwarves_host = proxy.endpoint.clone();
// SAFETY: single-purpose test binary. `build_native_app` takes NO nornir arg by design;
// poison NORNIR_SERVER (the UI must ignore it) and give it ONLY the dwarves proxy host.
unsafe {
std::env::set_var("NORNIR_SERVER", NORNIR_POISON);
std::env::set_var("DWARVES_SERVER", &dwarves_host);
std::env::set_var("DWARVES_WAREHOUSES", "nordisk");
}
let mut app = build_native_app(
dwarves_host.clone(),
std::path::PathBuf::from("/nonexistent/dwarves-gui/lenses-live"),
);
// Open Lenses and SCAN — the fold crosses the dwarves host to the live Mímir and back.
Facet::update_json(&mut app, &json!({ "set_tab": "Lenses" }).to_string());
Facet::update_json(&mut app, r#""scan""#);
let s = Facet::state_json(&app);
let lens = &s["lenses"];
// ── HONEST LIVE reading — scanned, not UNAVAILABLE, no error, folded on the host. ─
let status = lens["status"].as_str().unwrap_or_default();
let not_unavailable = !status.starts_with("UNAVAILABLE");
let scanned_ok = lens["scanned"] == true;
let no_error = lens["error"].is_null();
let thin_ok = lens["thin"] == true;
assert!(
not_unavailable,
"a live upstream ⇒ status is NOT UNAVAILABLE: {status:?}"
);
assert!(scanned_ok, "the scan succeeded (scanned=true): {lens}");
assert!(no_error, "no error on a live scan: {}", lens["error"]);
assert!(
thin_ok,
"the reading was folded on the host (thin=true): {lens}"
);
// A LIVE scan raises NO error code — the dead-upstream twin asserts the code is SET,
// so together they prove the code is a real signal and not a constant.
let no_code = lens["error_code"].is_null();
assert!(
no_code,
"a live scan carries no error code: {}",
lens["error_code"]
);
// ── REAL findings crossed the host: the seeded bloat finding is in the pane state. ─
let bloat = &lens["bloat"];
let findings = bloat["findings"].as_array();
let has_findings = findings.map(|a| !a.is_empty()).unwrap_or(false);
let real_symbol = findings
.and_then(|a| a.first())
.map(|f| f["symbol"] == "core::ptr::drop_in_place")
.unwrap_or(false);
assert!(
!bloat.is_null(),
"the bloat lens rendered a real (non-null) report: {bloat}"
);
assert!(
has_findings,
"the bloat lens carries the LIVE finding served by the host: {bloat}"
);
assert!(
real_symbol,
"the exact monomorphized symbol survived the proxy round-trip: {bloat}"
);
assert_host_only(&mut app);
drop(proxy);
drop(upstream);
let ok = not_unavailable
&& scanned_ok
&& no_error
&& thin_ok
&& has_findings
&& real_symbol
&& no_code;
matrix(
"lenses_pane_live_findings_via_the_host",
ok,
"the 🔍 Lenses (Mímir) pane, scanned through the shipped host-only shell against a REAL \
dwarves proxy fronting a LIVE Mímir upstream, reports scanned=true / status not \
UNAVAILABLE / no error / thin=true and renders the REAL bloat finding the host folded \
(the monomorphized core::ptr::drop_in_place symbol survives the proxy round-trip into \
the pane state) — LIVE lens data via the host, the twin of the dead-upstream \
UNAVAILABLE scenario; no :7878/nornir address leaks",
);
}