dwarves-gui/tests/robot_coderoom_room.rs
//! **ROBOT-UI: the Coderoom tab draws the code room of the SELECTED workspace.**
//!
//! The shipped shell, given only the forge; the forge proxies `CodeRoom.Answer` to a
//! mock nornir whose answers are written in `common` in the reader's own shapes. Every
//! assertion is a VALUE read back from the pane's `state_json` and compared with the
//! answer the server gave:
//!
//! 1. the crate graph: crates, joins and their counts — and no verdict colour;
//! 2. the room identity line and the diff line a person compares with the server;
//! 3. `not_wired` for compat / what-breaks, with nornir's sentences, and NO number;
//! 4. what was asked, of which workspace, through the forge;
//! 5. a room that refuses: the state and its sentence — no crate, no count.
mod common;
use common::*;
use facett_core::Facet;
use serde_json::json;
#[test]
fn the_coderoom_tab_draws_the_selected_workspaces_room_through_the_forge() {
let st = stand(full_room());
let mut app = shell(&st.host);
Facet::update_json(&mut app, &json!({ "set_tab": "Coderoom" }).to_string());
Facet::update_json(&mut app, r#"{"reread":true}"#);
let s = Facet::state_json(&app);
let c = &s["coderoom"];
// 1. the graph — every figure is the reader's
let want = crate_graph();
assert_eq!(c["from_room"], true, "{c}");
assert_eq!(
c["crate_count"].as_u64(),
Some(want["crates"].as_array().unwrap().len() as u64)
);
assert_eq!(
c["link_count"].as_u64(),
Some(want["edges"].as_array().unwrap().len() as u64)
);
assert_eq!(
(
c["depends_on_edges"].as_u64(),
c["call_edges"].as_u64(),
c["call_sites"].as_u64()
),
(Some(3), Some(10), Some(23))
);
let shop = c["crates"]
.as_array()
.unwrap()
.iter()
.find(|x| x["id"] == "shop@0.1.0")
.expect("shop is drawn");
assert_eq!(shop["symbols"], 41);
assert_eq!(
c["links"][2],
json!({ "from": "shop@0.1.0", "to": "shop-core@0.1.0", "depends_on": 1, "calls": 7, "call_sites": 19, "uses_type": 2 })
);
assert_eq!(
(c["graph_nodes"].as_u64(), c["graph_edges"].as_u64()),
(Some(3), Some(3))
);
// 2. which room, and where it was asked
assert_eq!(c["workspace"], WS);
assert_eq!(c["identity"][0], format!("room: {ROOM_LINE}"));
assert_eq!(
c["identity"][1],
"diff shop@1 → shop@2: 3 nodes added · 1 removed · 2 changed"
);
assert_eq!(
(
c["room"]["nodes"].as_u64(),
c["room"]["edges_total"].as_u64()
),
(Some(985), Some(2310))
);
assert!(
c["source"].as_str().unwrap().contains(&st.host),
"via the forge: {}",
c["source"]
);
assert_eq!(c["diff_summary"], "1 added · 0 removed · 1 changed");
// 3. no verdict without a producer
assert_eq!(c["verdicts_measured"], false);
assert!(
c["breaking_edges"].is_null() && c["compatible_edges"].is_null(),
"{c}"
);
assert_eq!(c["edge_count"], 0, "no red or green edge");
let layer = |name: &str| {
c["layers"]
.as_array()
.unwrap()
.iter()
.find(|l| l["layer"] == name)
.cloned()
.unwrap()
};
assert_eq!(
(
layer("compat verdicts")["state"].as_str(),
layer("compat verdicts")["evidence"].as_str()
),
(Some("not_wired"), Some(COMPAT_NOTE))
);
assert_eq!(
(
layer("what breaks")["state"].as_str(),
layer("what breaks")["evidence"].as_str()
),
(Some("not_wired"), Some(BREAKS_NOTE))
);
// 4. the questions: this workspace, the graph with the ring, the diff of the repo it named
let asked = asked(&st.room);
assert!(
asked.iter().all(|a| a.0 == WS),
"every question carried the selected workspace: {asked:?}"
);
for surface in [
"Viz.CrateGraph",
"Coderoom.Compat",
"Coderoom.WhatBreaks",
"Coderoom.SnapshotDiff",
] {
assert!(
asked.iter().any(|a| a.1 == surface),
"`{surface}` was asked: {asked:?}"
);
}
assert_eq!(
params_of(&st.room, "Viz.CrateGraph"),
Some(json!({ "universe": false }))
);
assert_eq!(
params_of(&st.room, "Coderoom.SnapshotDiff"),
Some(json!({ "repo": "shop" }))
);
// 5. the server stops having a room: the pane shows the state — and not one number
st.room
.set("Viz.CrateGraph", refusal("not_consumed", NOT_CONSUMED));
Facet::update_json(&mut app, r#"{"reread":true}"#);
let c = Facet::state_json(&app)["coderoom"].clone();
assert_eq!(c["from_room"], false);
assert_eq!(
(
c["room"]["graph"]["state"].as_str(),
c["room"]["graph"]["evidence"].as_str()
),
(Some("not_consumed"), Some(NOT_CONSUMED))
);
for key in [
"crate_count",
"link_count",
"crates",
"links",
"summary",
"breaking_edges",
] {
assert!(
c.get(key).is_none(),
"`{key}` must not exist without a measured graph: {c}"
);
}
// …and it comes back with the room
st.room.set("Viz.CrateGraph", crate_graph());
Facet::update_json(&mut app, r#"{"reread":true}"#);
assert_eq!(Facet::state_json(&app)["coderoom"]["crate_count"], 3);
let whole = Facet::state_json(&app).to_string();
assert!(
!whole.contains("nornir-poison.example") && !whole.contains(":7878"),
"the UI dialled only the forge"
);
matrix("coderoom_tab_draws_the_selected_workspaces_room", true, "crate graph, room identity, snapshot diff and the not_wired verdict layers read back from state_json equal the server's answers");
}