dwarves-gui/tests/live_probe.rs
//! **Live probe** — the real app, headless, against a running server: what each
//! code-room pane shows. Ignored; run it by hand:
//!
//! `DWARVES_PROBE_SERVER=http://100.89.200.50:7900 DWARVES_PROBE_WS=nordisk \
//! cargo test -p dwarves-gui --test live_probe -- --ignored --nocapture`
use facett_core::Facet;
use serde_json::{json, Value};
fn short(v: &Value) -> String {
let s = v.to_string();
if s.len() > 1500 {
format!("{}…", &s[..1500])
} else {
s
}
}
#[test]
#[ignore = "live: needs DWARVES_PROBE_SERVER"]
fn what_the_panes_show_on_a_live_server() {
let host = std::env::var("DWARVES_PROBE_SERVER").expect("DWARVES_PROBE_SERVER");
let ws = std::env::var("DWARVES_PROBE_WS").unwrap_or_else(|_| "nordisk".into());
// SAFETY: one test in this binary.
unsafe {
std::env::set_var("DWARVES_SERVER", &host);
std::env::set_var("NORNIR_WORKSPACE", &ws);
std::env::set_var("DWARVES_WAREHOUSES", &ws);
}
let mut app = dwarves_gui::build_native_app(
host.clone(),
std::path::PathBuf::from("/nonexistent/live-probe"),
);
// the 🏛 3D room: the Coderoom tab in its 3-D mode, read until it lands
Facet::update_json(&mut app, &json!({ "set_tab": "Coderoom" }).to_string());
Facet::update_json(&mut app, r#"{"mode":"3d"}"#);
let t0 = std::time::Instant::now();
for _ in 0..600 {
Facet::update_json(&mut app, r#"{"reread":true}"#);
let r = Facet::state_json(&app)["coderoom"]["room3d"].clone();
if !r["pending"].as_bool().unwrap_or(false) {
eprintln!(
"\n===== 3D room ({:.1}s) =====\n{}",
t0.elapsed().as_secs_f32(),
short(&r)
);
break;
}
std::thread::sleep(std::time::Duration::from_millis(500));
}
for (tab, key) in [
("Coderoom", "coderoom"),
("Lenses", "lenses"),
("Data", "dataview"),
] {
let t0 = std::time::Instant::now();
Facet::update_json(&mut app, &json!({ "set_tab": tab }).to_string());
Facet::update_json(&mut app, r#"{"reread":true}"#);
let s = Facet::state_json(&app);
let pane = s.get(key).cloned().unwrap_or(Value::Null);
eprintln!(
"\n===== {tab} ({:.1}s) =====\n{}",
t0.elapsed().as_secs_f32(),
short(&pane)
);
if pane.is_null() {
let keys: Vec<_> = s
.as_object()
.map(|o| o.keys().cloned().collect())
.unwrap_or_default();
eprintln!("(no `{key}` key; state keys: {keys:?})");
}
}
}