mod common;
use common::call_tool_raw;
#[tokio::test]
async fn test_concurrent_same_path_edits_serialize() {
let cwd = std::env::current_dir().expect("should get cwd");
let temp_dir = tempfile::TempDir::new_in(&cwd).expect("should create temp dir in cwd");
let working_dir = temp_dir
.path()
.to_str()
.expect("temp dir path is valid UTF-8");
let file_name = "concurrent.txt";
let file_path = temp_dir.path().join(file_name);
let content = "alpha\nbeta\ngamma\n";
std::fs::write(&file_path, content).expect("should write file");
let resp1 = call_tool_raw(
"edit_replace",
serde_json::json!({
"path": file_name,
"old_text": "alpha",
"new_text": "ALPHA",
"working_dir": working_dir
}),
)
.await;
assert!(
!resp1["result"]["isError"].as_bool().unwrap_or(true),
"first edit expected success: {resp1}"
);
let resp2 = call_tool_raw(
"edit_replace",
serde_json::json!({
"path": file_name,
"old_text": "beta",
"new_text": "BETA",
"working_dir": working_dir
}),
)
.await;
assert!(
!resp2["result"]["isError"].as_bool().unwrap_or(true),
"second edit expected success: {resp2}"
);
let final_content = std::fs::read_to_string(&file_path).expect("should read file");
assert_eq!(final_content, "ALPHA\nBETA\ngamma\n");
}