#![allow(missing_docs)]
#[path = "e2e/common/mod.rs"]
mod common;
use sapphire_sync_core::framework::bridge::LoopbackNetwork;
use sapphire_sync_core::framework::sync::DEFAULT_MAX_FILE_SIZE;
#[tokio::test(flavor = "multi_thread")]
async fn filtering_and_size_limits_hold_at_the_files() {
common::init_tracing();
let net = LoopbackNetwork::new();
let a = common::start_host(&net, common::NODE_A, "host-a").await;
let b = common::start_host(&net, common::NODE_B, "host-b").await;
common::introduce(&a, &b);
common::write(&a, ".sapphireignore", "*.tmp\n");
common::enable_sync(&a).await;
common::enable_sync(&b).await;
common::settle(&[&a, &b]).await;
common::write(&a, "x.tmp", "excluded");
common::write(&a, "kept.txt", "carried");
common::poll_until(
|| (common::read_text(&b, "kept.txt").as_deref() == Some("carried")).then_some(()),
"the sibling of the excluded file never reached host b",
)
.await;
common::poll_until(
|| (common::read_text(&b, ".sapphireignore").as_deref() == Some("*.tmp\n")).then_some(()),
"the .sapphireignore written on host a never arrived on host b",
)
.await;
assert_eq!(
common::read_text(&b, "x.tmp"),
None,
"a *.tmp file was synced even though .sapphireignore excludes it"
);
let oversize = a.ws.join("big.bin");
{
use std::io::Write as _;
let mut file = std::fs::File::create(&oversize).unwrap();
file.write_all(b"oversize").unwrap();
file.set_len(DEFAULT_MAX_FILE_SIZE + 1).unwrap();
}
common::write(&a, "small.bin", "small");
common::poll_until(
|| (common::read_text(&b, "small.bin").as_deref() == Some("small")).then_some(()),
"the sibling of the oversize file never reached host b",
)
.await;
assert_eq!(
common::read_text(&b, "big.bin"),
None,
"a file over DEFAULT_MAX_FILE_SIZE was synced"
);
for rel in [".sapphireignore", "kept.txt", "small.bin"] {
assert_eq!(
common::read_text(&a, rel),
common::read_text(&b, rel),
"{rel} differs between the hosts"
);
}
assert!(a.ws.join("x.tmp").exists(), "the excluded file left host a");
assert!(
!b.ws.join("x.tmp").exists(),
"the excluded file reached host b"
);
assert!(oversize.exists(), "the oversize file left host a");
assert!(
!b.ws.join("big.bin").exists(),
"the oversize file reached host b"
);
}