dwarves-gui/tests/robot_coverage_room.rs
//! **ROBOT-UI: the Coverage tab's code half is nornir's code room.**
//!
//! The shipped shell → forge → mock nornir. The room answers `Knowledge.TestReach`
//! (which fns exist, which a test reaches, the call sites arriving); the warehouse
//! serves the bench tables. The index on screen must be exactly what those say:
//! the surface, the covered count, the named uncovered fns with the room's fan-in —
//! and, when the room refuses, its state FIRST and no repo scanned.
mod common;
use common::*;
use facett_core::Facet;
use serde_json::json;
#[test]
fn the_coverage_index_is_folded_from_the_rooms_answer_through_the_forge() {
let st = stand(full_room());
let mut app = shell(&st.host);
Facet::update_json(&mut app, &json!({ "set_tab": "Coverage" }).to_string());
Facet::update_json(&mut app, "\"scan\"");
let s = Facet::state_json(&app);
let c = &s["coverage"];
assert_eq!(c["error"], json!(null), "{c}");
let idx = &c["index"];
// the room's answer, by state, with the room it was read from
assert_eq!(
(c["room"]["state"].as_str(), c["room"]["measured"].as_bool()),
(Some("complete"), Some(true))
);
assert_eq!(c["room"]["room"], ROOM_LINE);
assert!(
c["room"]["via"]
.as_str()
.unwrap()
.contains("Knowledge.TestReach")
&& c["room"]["via"].as_str().unwrap().contains(&st.host)
);
assert_eq!(
(idx["graph"]["fns"].as_u64(), idx["graph"]["tests"].as_u64()),
(Some(5), Some(1))
);
// the fold: 4 production fns (the test fn is test code), 2 reached, 2 named in the gap
let reach = test_reach();
assert_eq!(
idx["test"]["surface"].as_u64(),
reach["surface_fns"].as_u64(),
"the pane's surface is the room's"
);
assert_eq!(
idx["test"]["covered"].as_u64(),
reach["test_reachable"].as_u64(),
"…and so is the reached count"
);
assert_eq!(
(
idx["test"]["surface"].as_u64(),
idx["test"]["covered"].as_u64(),
idx["test"]["missing"].as_u64(),
idx["test"]["tests"].as_u64()
),
(Some(4), Some(2), Some(2), Some(1))
);
assert_eq!(
(
idx["repos_total"].as_u64(),
idx["repos_scanned"].as_u64(),
idx["repos_benched"].as_u64()
),
(Some(1), Some(1), Some(1))
);
// the status line carries no "not read" — and still names the feeds that ARE missing
let status = c["status"].as_str().unwrap();
assert!(
!status.contains("CODE GRAPH NOT READ") && status.contains("MISSING FEEDS"),
"{status}"
);
assert_eq!(params_of(&st.room, "Knowledge.TestReach"), Some(json!({})));
assert!(asked(&st.room)
.iter()
.any(|a| a == &(WS.to_string(), "Knowledge.TestReach".to_string())));
// the room refuses: its state leads, nothing is scanned — the bench half is still read
st.room
.set("Knowledge.TestReach", refusal("not_consumed", NOT_CONSUMED));
Facet::update_json(&mut app, "\"scan\"");
let c = Facet::state_json(&app)["coverage"].clone();
assert_eq!(c["room"]["state"], "not_consumed");
assert_eq!(
c["status"]
.as_str()
.unwrap()
.split(" — every repo")
.next()
.unwrap(),
format!("CODE GRAPH NOT READ [not_consumed]: {NOT_CONSUMED}")
);
assert!(
c["index"]["repos_scanned"].is_null()
&& c["index"]["test"].is_null()
&& c["index"]["graph"]["fns"].is_null(),
"no number for a graph nobody read: {}",
c["index"]
);
assert!(
c["index"]["bench"]["hot_paths"].is_null(),
"no surface ⇒ no hot-path count either"
);
matrix("coverage_index_is_folded_from_the_rooms_answer", true, "surface / covered / missing read back from state_json equal the room's Knowledge.TestReach answer; a refusing room leads with its state");
}