#![allow(missing_docs)]
#[path = "e2e/common/mod.rs"]
mod common;
use sapphire_sync_core::framework::bridge::LoopbackNetwork;
#[tokio::test(flavor = "multi_thread")]
async fn a_vanished_root_stops_reporting_synced_instead_of_deleting_everything() {
common::init_tracing();
let net = LoopbackNetwork::new();
let (a, b) = common::synced_pair(&net).await;
common::write(&a, "notes/a.md", "base");
common::poll_until(
|| (common::read_text(&b, "notes/a.md").as_deref() == Some("base")).then_some(()),
"the base file written on host a never arrived on host b",
)
.await;
common::settle(&[&a, &b]).await;
let parked = a.ws.with_file_name("notes-parked");
std::fs::rename(&a.ws, &parked).unwrap();
let status = common::poll_until_async(
|| async {
let status = a.runtime().unwrap().status(&a.ws).await;
(!status.enabled).then_some(status)
},
"host a never stopped reporting the vanished workspace as synced",
)
.await;
assert!(
status.paused.is_none(),
"a renamed-away root surfaces no pause reason, but got {:?}",
status.paused
);
assert_eq!(
common::read_text(&b, "notes/a.md").as_deref(),
Some("base"),
"the peer lost its file when host a's root vanished"
);
std::fs::rename(&parked, &a.ws).unwrap();
common::poll_until_async(
|| async {
let status = a.runtime().unwrap().status(&a.ws).await;
status.enabled.then_some(())
},
"host a never re-enabled the workspace after its root came back",
)
.await;
common::settle(&[&a, &b]).await;
common::write(&b, "notes/recovered.md", "after the root came back");
common::poll_until(
|| {
(common::read_text(&a, "notes/recovered.md").as_deref()
== Some("after the root came back"))
.then_some(())
},
"a file written on host b after recovery never reached host a",
)
.await;
common::assert_roots_match(&a, &b);
}
#[tokio::test(flavor = "multi_thread")]
async fn a_root_that_is_not_a_directory_is_reported_as_root_missing() {
common::init_tracing();
let net = LoopbackNetwork::new();
let (a, b) = common::synced_pair(&net).await;
common::write(&a, "notes/a.md", "base");
common::poll_until(
|| (common::read_text(&b, "notes/a.md").as_deref() == Some("base")).then_some(()),
"the base file written on host a never arrived on host b",
)
.await;
common::settle(&[&a, &b]).await;
let parked = a.ws.with_file_name("notes-parked");
std::fs::rename(&a.ws, &parked).unwrap();
std::fs::write(&a.ws, "not a directory").unwrap();
a.runtime().unwrap().scan(&a.ws).await.unwrap();
let status = a.runtime().unwrap().status(&a.ws).await;
assert_eq!(
status.paused.as_deref(),
Some("RootMissing"),
"a root that is not a directory must be reported as RootMissing"
);
assert_eq!(
common::read_text(&b, "notes/a.md").as_deref(),
Some("base"),
"the peer lost its file when host a's root was replaced"
);
std::fs::remove_file(&a.ws).unwrap();
std::fs::rename(&parked, &a.ws).unwrap();
a.runtime().unwrap().scan(&a.ws).await.unwrap();
let status = a.runtime().unwrap().status(&a.ws).await;
assert_eq!(
status.paused, None,
"the pause must clear once the root is a directory again"
);
common::assert_roots_match(&a, &b);
}