dwarves-gui/tests/robot_warehouse_nav_room.rs
//! **ROBOT-UI: the Warehouse navigator's two tiers are the server's.**
//!
//! The shipped shell → forge → mock nornir. The skeleton (repos, their crates, repo
//! dependency edges) is the room's `Viz.CrateGraph`; the function tier is its
//! `Viz.FunctionTier`. The pane must draw exactly those — the reader's fns by name, its
//! call edges, nothing under a crate it named no fn of — and, when the room refuses,
//! the state and NOT ONE node: there is no fixture skeleton and no synthetic function
//! to fall back to.
mod common;
use common::*;
use facett_core::Facet;
use serde_json::json;
#[test]
fn the_navigator_draws_the_rooms_skeleton_and_function_tier_through_the_forge() {
let st = stand(full_room());
let mut app = shell(&st.host);
Facet::update_json(&mut app, &json!({ "set_tab": "Warehouse" }).to_string());
Facet::update_json(&mut app, r#"{"read":true}"#);
let w = Facet::state_json(&app)["warehouse"].clone();
// the skeleton: the one consumed repo, under the workspace as the breadcrumb root
assert_eq!(
(
w["level"].as_str(),
w["repo_count"].as_u64(),
w["node_count"].as_u64(),
w["edge_count"].as_u64()
),
(Some("constellation"), Some(1), Some(1), Some(0)),
"{w}"
);
assert_eq!(w["breadcrumb"], json!([WS]));
assert!(w["skeleton_error"].is_null());
let src = w["skeleton_source"].as_str().unwrap();
assert!(
src.starts_with(&format!("Viz.CrateGraph [complete] · {ROOM_LINE}"))
&& src.contains(&st.host),
"{src}"
);
assert_eq!(w["room"]["skeleton"]["room"], ROOM_LINE);
assert_eq!(
params_of(&st.room, "Viz.CrateGraph"),
Some(json!({ "universe": false })),
"the workspace's own crates"
);
assert!(
!asked(&st.room).iter().any(|a| a.1 == "Viz.FunctionTier"),
"the function tier is not asked on the landing"
);
// drill: the repo's crates are the two the reader says it defines
Facet::update_json(&mut app, r#"{"drill":"repo:shop"}"#);
let w = Facet::state_json(&app)["warehouse"].clone();
let mut crates: Vec<String> = w["nodes"]
.as_array()
.unwrap()
.iter()
.filter(|n| n["kind"] == "crate")
.filter_map(|n| n["label"].as_str().map(str::to_string))
.collect();
crates.sort();
assert_eq!(crates, vec!["shop", "shop-core"]);
Facet::update_json(&mut app, r#"{"home":true}"#);
// the world: the reader's four fns and two call edges — and nothing else
Facet::update_json(&mut app, r#"{"world_target":100000}"#);
Facet::update_json(&mut app, r#"{"world":true}"#);
let w = Facet::state_json(&app)["warehouse"].clone();
let tier = function_tier();
assert_eq!(w["real_fn_nodes"].as_u64(), tier["total_fns"].as_u64());
assert_eq!(w["real_call_edges"].as_u64(), tier["total_calls"].as_u64());
assert_eq!(
(
w["preview_repo_nodes"].as_u64(),
w["preview_crate_nodes"].as_u64(),
w["preview_fn_nodes"].as_u64()
),
(Some(1), Some(2), Some(4))
);
assert_eq!(
(
w["real_fn_crates"].as_u64(),
w["crates_without_fns"].as_u64(),
w["repo_dep_edges"].as_u64()
),
(Some(2), Some(0), Some(0))
);
// 1 repo + 2 crates + 4 fns; edges: 2 repo→crate + 4 crate→fn + 2 calls
assert_eq!(
(w["preview_nodes"].as_u64(), w["preview_edges"].as_u64()),
(Some(7), Some(8))
);
assert!(w["real_error"].is_null());
assert!(
w.get("synthetic_functions").is_none() && w.get("synthetic_fn_nodes").is_none(),
"no synthetic tier exists: {w}"
);
assert_eq!(w["room"]["functions"]["room"], ROOM_LINE);
assert!(asked(&st.room)
.iter()
.any(|a| a == &(WS.to_string(), "Viz.FunctionTier".to_string())));
// the room refuses both tiers: the state, its sentence, and not one node
st.room
.set("Viz.CrateGraph", refusal("not_consumed", NOT_CONSUMED));
st.room
.set("Viz.FunctionTier", refusal("not_consumed", NOT_CONSUMED));
Facet::update_json(&mut app, r#"{"reread":true}"#);
let w = Facet::state_json(&app)["warehouse"].clone();
assert!(
w["skeleton_read"] == false && w["functions_read"] == false,
"{w}"
);
assert!(
w["preview_nodes"].is_null()
&& w["real_fn_nodes"].is_null()
&& w["preview_edges"].is_null(),
"nothing is counted of a refusal: {w}"
);
assert_eq!(
w["skeleton_error"],
format!("[not_consumed] {NOT_CONSUMED}")
);
assert_eq!(w["real_error"], format!("[not_consumed] {NOT_CONSUMED}"));
assert_eq!(w["room"]["skeleton"]["state"], "not_consumed");
matrix("navigator_draws_the_rooms_skeleton_and_function_tier", true, "repos / crates / fns / call edges read back from state_json equal the room's answers; a refusing room leaves no node");
}