use crate::lsp::manager::LspManager;
#[tokio::test]
#[ignore = "requires rust-analyzer on PATH; gated by CI job"]
async fn two_agents_coherent_after_edit() {
let fixture =
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/lsp-mux/rust");
let (_td, root) = super::test_support::stage_fixture(&fixture);
let mgr_a = LspManager::new();
let mgr_b = LspManager::new();
let ca = mgr_a
.get_or_start("rust", &root, Some(true))
.await
.expect("A get_or_start");
let cb = mgr_b
.get_or_start("rust", &root, Some(true))
.await
.expect("B get_or_start");
let target = root.join("src/lib.rs");
ca.did_change(&target).await.expect("A did_change initial");
cb.did_change(&target).await.expect("B did_change initial");
let syms_before = cb
.document_symbols(&target, "rust")
.await
.expect("B document_symbols before");
let names_before: Vec<_> = syms_before.iter().map(|s| s.name.clone()).collect();
assert!(
!names_before.iter().any(|n| n == "fresh_symbol"),
"fresh_symbol should not exist yet: {:?}",
names_before
);
let updated = "pub fn original_symbol() -> &'static str { \"original\" }\n\
pub fn fresh_symbol() -> &'static str { \"fresh\" }\n";
std::fs::write(&target, updated).unwrap();
let syms_stale = cb
.document_symbols(&target, "rust")
.await
.expect("B document_symbols stale");
let names_stale: Vec<_> = syms_stale.iter().map(|s| s.name.clone()).collect();
assert!(
!names_stale.iter().any(|n| n == "fresh_symbol"),
"B should not see fresh_symbol before notification: {:?}",
names_stale
);
mgr_a.notify_file_changed(&target).await;
let syms_after = cb
.document_symbols(&target, "rust")
.await
.expect("B document_symbols after");
let names_after: Vec<_> = syms_after.iter().map(|s| s.name.clone()).collect();
assert!(
names_after.iter().any(|n| n == "fresh_symbol"),
"Agent B's view stale after notification: {:?}",
names_after
);
mgr_a.shutdown_all().await;
mgr_b.shutdown_all().await;
}