use super::*;
use serde_json::json;
use tempfile::tempdir;
fn newborn_world(
root: &std::path::Path,
data: &std::path::Path,
bin: &std::path::Path,
) -> ConsumerCtx {
seed(data);
over(
root,
world_of(data, &[]),
data.to_path_buf(),
fake_litany(bin),
)
}
fn prepare(ws: &str) -> serde_json::Value {
json!({"op": "prepare", "workspace": ws, "payload": {"rung": "bare"}})
}
#[test]
fn a_second_gesture_addresses_the_wall_the_first_founded() {
let (root, data, bin) = (tempdir().unwrap(), tempdir().unwrap(), tempdir().unwrap());
let ctx = newborn_world(root.path(), data.path(), bin.path());
let born = ctx.answer(&prepare("home"));
assert_eq!(born["kind"], "prepared", "{born}");
assert!(
crate::binding::workspace_path(data.path(), "home")
.join("repo.git")
.is_dir(),
"the raise founded the wall the reply named"
);
let again = ctx.answer(&prepare("home"));
assert_eq!(again["kind"], "prepared", "{again}");
let listed = ctx.answer(&json!({"op": "conversations", "workspace": "home"}));
assert_eq!(listed["ok"], true, "{listed}");
assert_eq!(listed["kind"], "conversations", "{listed}");
}
#[test]
fn the_windows_posted_receipt_addresses_the_wall_it_just_raised() {
let (root, data, bin) = (tempdir().unwrap(), tempdir().unwrap(), tempdir().unwrap());
let ctx = newborn_world(root.path(), data.path(), bin.path());
let window = crate::registry::window();
let seated = operator(window.clone());
let born = ctx.answer_as(&seated, &prepare("home"));
assert_eq!(born["kind"], "prepared", "{born}");
assert!(
crate::registry::registered(root.path(), &window).contains("home"),
"the create seated its creator (REMOTE §4)"
);
let listed = ctx.answer_as(
&seated,
&json!({"op": "conversations", "workspace": "home"}),
);
assert_eq!(listed["kind"], "conversations", "{listed}");
let stranger = seat("stranger");
crate::registry::register(root.path(), &stranger.client, "elsewhere").expect("seated");
let refusal = ctx.answer_as(
&stranger,
&json!({"op": "conversations", "workspace": "home"}),
);
assert_eq!(
refusal["error"], "unknown workspace \"home\" — none is enumerated here",
"{refusal}"
);
}
#[test]
fn a_half_born_directory_is_resumed_not_wedged() {
let (root, data, bin) = (tempdir().unwrap(), tempdir().unwrap(), tempdir().unwrap());
let ctx = newborn_world(root.path(), data.path(), bin.path());
let debris = crate::binding::workspace_path(data.path(), "home");
std::fs::create_dir_all(&debris).unwrap();
let born = ctx.answer(&prepare("home"));
assert_eq!(born["kind"], "prepared", "{born}");
assert!(
debris.join("repo.git").is_dir(),
"the resume finished the dead birth"
);
}
#[test]
fn a_scoped_clients_prepare_never_joins_anothers_wall() {
let (root, data, bin) = (tempdir().unwrap(), tempdir().unwrap(), tempdir().unwrap());
let ctx = newborn_world(root.path(), data.path(), bin.path());
let window = crate::registry::window();
let seated = operator(window.clone());
let born = ctx.answer_as(&seated, &prepare("home"));
assert_eq!(born["kind"], "prepared", "{born}");
let refusal = ctx.answer_as(&seat("stranger"), &prepare("home"));
assert_eq!(
refusal["error"], "unknown workspace \"home\" — none is enumerated here",
"{refusal}"
);
}
#[test]
fn a_gesture_addresses_a_project_primed_since_the_last_derivation() {
let (root, data, world_root) = (tempdir().unwrap(), tempdir().unwrap(), tempdir().unwrap());
let world = crate::test_support::world_under(world_root.path());
let ctx = over_world(
root.path(),
world_of(data.path(), &[]),
data.path().to_path_buf(),
Cli::new("/no/such/bl"),
world.clone(),
);
let listing = json!({"op": "close", "project": "proj", "id": "bl-1", "name": "alba"});
let before = ctx.answer(&listing);
assert_eq!(before["ok"], false, "{before}");
assert_eq!(
before["error"], "unknown project \"proj\" — none is enumerated here",
"the cached set is what the defect resolved over — and it says so"
);
let clones = world.balls_clones_dir();
std::fs::create_dir_all(clones.join("%2Fd%2Fproj")).expect("a primed project");
let after = ctx.answer(&listing);
assert_ne!(
after["error"], before["error"],
"the name the prime made addressable is addressable now: {after}"
);
}