Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Merge branch 'main' into randomized-tests-operation-script

Max Brunsfeldc960277349b4
diff --cc crates/collab/src/tests.rs
index 178d31ba634,9c0f9f3bd89..10014932428
--- a/crates/collab/src/tests.rs
+++ b/crates/collab/src/tests.rs
@@@ -468,16 -429,17 +463,8 @@@ impl TestClient
cx: &mut TestAppContext,
) -> ViewHandle<Workspace> {
let (_, root_view) = cx.add_window(|_| EmptyView);
- cx.add_view(&root_view, |cx| {
- Workspace::new(
- Default::default(),
- 0,
- project.clone(),
- |_, _| unimplemented!(),
- cx,
- )
- })
+ cx.add_view(&root_view, |cx| Workspace::test_new(project.clone(), cx))
}
-
- fn create_new_root_dir(&mut self) -> PathBuf {
- format!(
- "/{}-root-{}",
- self.username,
- util::post_inc(&mut self.next_root_dir_id)
- )
- .into()
- }
}
impl Drop for TestClient {
diff --cc crates/collab/src/tests/randomized_integration_tests.rs
index 0b4aa3ec9bf,960f9bfc1db..19961c3ba53
--- a/crates/collab/src/tests/randomized_integration_tests.rs
+++ b/crates/collab/src/tests/randomized_integration_tests.rs
@@@ -535,125 -610,223 +535,125 @@@ async fn apply_client_operation
active_call
.update(cx, |call, cx| call.accept_incoming(cx))
.await?;
- } else {
- log::info!("{}: declining incoming call", client.username);
- active_call.update(cx, |call, _| call.decline_incoming())?;
}
- } else {
- let available_contacts = client.user_store.read_with(cx, |user_store, _| {
- user_store
- .contacts()
- .iter()
- .filter(|contact| contact.online && !contact.busy)
- .cloned()
- .collect::<Vec<_>>()
- });
- let distribution = rng.lock().gen_range(0..100);
- match distribution {
- 0..=29 if !available_contacts.is_empty() => {
- let contact = available_contacts.choose(&mut *rng.lock()).unwrap();
- log::info!(
- "{}: inviting {}",
- client.username,
- contact.user.github_login
- );
- active_call
- .update(cx, |call, cx| call.invite(contact.user.id, None, cx))
- .await?;
- }
- 30..=39
- if can_hang_up && active_call.read_with(cx, |call, _| call.room().is_some()) =>
- {
- log::info!("{}: hanging up", client.username);
- active_call.update(cx, |call, cx| call.hang_up(cx)).await?;
+ ClientOperation::RejectIncomingCall => {
+ let active_call = cx.read(ActiveCall::global);
+ if active_call.read_with(cx, |call, _| call.incoming().borrow().is_none()) {
+ Err(TestError::Inapplicable)?;
}
- _ => {}
+
+ log::info!("{}: declining incoming call", client.username);
+ active_call.update(cx, |call, _| call.decline_incoming())?;
}
- }
- Ok(())
-}
+ ClientOperation::LeaveCall => {
+ let active_call = cx.read(ActiveCall::global);
+ if active_call.read_with(cx, |call, _| call.room().is_none()) {
+ Err(TestError::Inapplicable)?;
+ }
-async fn randomly_mutate_git(client: &mut TestClient, rng: &Mutex<StdRng>) {
- let directories = client.fs.directories().await;
- let mut dir_path = directories.choose(&mut *rng.lock()).unwrap().clone();
- if dir_path.file_name() == Some(OsStr::new(".git")) {
- dir_path.pop();
- }
- let mut git_dir_path = dir_path.clone();
- git_dir_path.push(".git");
-
- if !directories.contains(&git_dir_path) {
- log::info!(
- "{}: creating git directory at {:?}",
- client.username,
- git_dir_path
- );
- client.fs.create_dir(&git_dir_path).await.unwrap();
- }
+ log::info!("{}: hanging up", client.username);
- active_call.update(cx, |call, cx| call.hang_up(cx))?;
++ active_call.update(cx, |call, cx| call.hang_up(cx)).await?;
+ }
- let mut child_file_paths = child_file_paths(client, &dir_path).await;
- let count = rng.lock().gen_range(0..=child_file_paths.len());
- child_file_paths.shuffle(&mut *rng.lock());
- child_file_paths.truncate(count);
+ ClientOperation::InviteContactToCall { user_id } => {
+ let active_call = cx.read(ActiveCall::global);
- let mut new_index = Vec::new();
- for abs_child_file_path in &child_file_paths {
- let child_file_path = abs_child_file_path.strip_prefix(&dir_path).unwrap();
- let new_base = Alphanumeric.sample_string(&mut *rng.lock(), 16);
- new_index.push((child_file_path, new_base));
- }
- log::info!(
- "{}: updating Git index at {:?}: {:#?}",
- client.username,
- git_dir_path,
- new_index
- );
- client
- .fs
- .set_index_for_repo(&git_dir_path, &new_index)
- .await;
-}
+ log::info!("{}: inviting {}", client.username, user_id,);
+ active_call
+ .update(cx, |call, cx| call.invite(user_id.to_proto(), None, cx))
+ .await
+ .log_err();
+ }
-async fn randomly_mutate_fs(client: &mut TestClient, rng: &Mutex<StdRng>) {
- let parent_dir_path = client
- .fs
- .directories()
- .await
- .choose(&mut *rng.lock())
- .unwrap()
- .clone();
-
- let is_dir = rng.lock().gen::<bool>();
- if is_dir {
- let mut dir_path = parent_dir_path.clone();
- dir_path.push(gen_file_name(rng));
- log::info!("{}: creating local dir at {:?}", client.username, dir_path);
- client.fs.create_dir(&dir_path).await.unwrap();
- } else {
- let child_file_paths = child_file_paths(client, &parent_dir_path).await;
- let create_new_file = child_file_paths.is_empty() || rng.lock().gen();
- let text = Alphanumeric.sample_string(&mut *rng.lock(), 16);
- if create_new_file {
- let mut file_path = parent_dir_path.clone();
- file_path.push(gen_file_name(rng));
- file_path.set_extension("rs");
+ ClientOperation::OpenLocalProject { first_root_name } => {
log::info!(
- "{}: creating local file at {:?}",
+ "{}: opening local project at {:?}",
client.username,
- file_path
+ first_root_name
);
+
+ let root_path = Path::new("/").join(&first_root_name);
+ client.fs.create_dir(&root_path).await.unwrap();
client
.fs
- .create_file(&file_path, Default::default())
+ .create_file(&root_path.join("main.rs"), Default::default())
.await
.unwrap();
+ let project = client.build_local_project(root_path, cx).await.0;
+ ensure_project_shared(&project, client, cx).await;
+ client.local_projects_mut().push(project.clone());
+ }
+
+ ClientOperation::AddWorktreeToProject {
+ project_root_name,
+ new_root_path,
+ } => {
+ let project = project_for_root_name(client, &project_root_name, cx)
+ .ok_or(TestError::Inapplicable)?;
+
log::info!(
- "{}: setting local file {:?} text to {:?}",
+ "{}: finding/creating local worktree at {:?} to project with root path {}",
client.username,
- file_path,
- text
+ new_root_path,
+ project_root_name
);
- client
- .fs
- .save(&file_path, &Rope::from(text.as_str()), fs::LineEnding::Unix)
+
+ ensure_project_shared(&project, client, cx).await;
+ if !client.fs.paths().await.contains(&new_root_path) {
+ client.fs.create_dir(&new_root_path).await.unwrap();
+ }
+ project
+ .update(cx, |project, cx| {
+ project.find_or_create_local_worktree(&new_root_path, true, cx)
+ })
.await
.unwrap();
- } else {
- let file_path = child_file_paths.choose(&mut *rng.lock()).unwrap();
+ }
+
+ ClientOperation::CloseRemoteProject { project_root_name } => {
+ let project = project_for_root_name(client, &project_root_name, cx)
+ .ok_or(TestError::Inapplicable)?;
+
log::info!(
- "{}: setting local file {:?} text to {:?}",
+ "{}: closing remote project with root path {}",
client.username,
- file_path,
- text
+ project_root_name,
);
- client
- .fs
- .save(file_path, &Rope::from(text.as_str()), fs::LineEnding::Unix)
- .await
+
+ let ix = client
+ .remote_projects()
+ .iter()
+ .position(|p| p == &project)
.unwrap();
+ cx.update(|_| {
+ client.remote_projects_mut().remove(ix);
+ client.buffers().retain(|project, _| project != project);
+ drop(project);
+ });
}
- }
-}
-async fn randomly_mutate_projects(
- client: &mut TestClient,
- rng: &Mutex<StdRng>,
- cx: &mut TestAppContext,
-) -> Result<()> {
- let active_call = cx.read(ActiveCall::global);
- let remote_projects =
- if let Some(room) = active_call.read_with(cx, |call, _| call.room().cloned()) {
- room.read_with(cx, |room, _| {
- room.remote_participants()
- .values()
- .flat_map(|participant| participant.projects.clone())
- .collect::<Vec<_>>()
- })
- } else {
- Default::default()
- };
-
- let project = if remote_projects.is_empty() || rng.lock().gen() {
- if client.local_projects.is_empty() || rng.lock().gen() {
- let paths = client.fs.paths().await;
- let local_project = if paths.is_empty() || rng.lock().gen() {
- let root_path = client.create_new_root_dir();
- client.fs.create_dir(&root_path).await.unwrap();
- client
- .fs
- .create_file(&root_path.join("main.rs"), Default::default())
- .await
- .unwrap();
- log::info!(
- "{}: opening local project at {:?}",
- client.username,
- root_path
- );
- client.build_local_project(root_path, cx).await.0
- } else {
- let root_path = paths.choose(&mut *rng.lock()).unwrap();
- log::info!(
- "{}: opening local project at {:?}",
- client.username,
- root_path
- );
- client.build_local_project(root_path, cx).await.0
- };
- client.local_projects.push(local_project.clone());
- local_project
- } else {
- client
- .local_projects
- .choose(&mut *rng.lock())
- .unwrap()
- .clone()
- }
- } else {
- if client.remote_projects.is_empty() || rng.lock().gen() {
- let remote_project_id = remote_projects.choose(&mut *rng.lock()).unwrap().id;
- let remote_project = if let Some(project) =
- client.remote_projects.iter().find(|project| {
- project.read_with(cx, |project, _| {
- project.remote_id() == Some(remote_project_id)
- })
- }) {
- project.clone()
- } else {
- log::info!(
- "{}: opening remote project {}",
- client.username,
- remote_project_id
- );
- let call = cx.read(ActiveCall::global);
- let room = call.read_with(cx, |call, _| call.room().unwrap().clone());
- let remote_project = room
- .update(cx, |room, cx| {
+ ClientOperation::OpenRemoteProject {
+ host_id,
+ first_root_name,
+ } => {
+ let active_call = cx.read(ActiveCall::global);
+ let project = active_call
+ .update(cx, |call, cx| {
+ let room = call.room().cloned()?;
+ let participant = room
+ .read(cx)
+ .remote_participants()
+ .get(&host_id.to_proto())?;
+ let project_id = participant
+ .projects
+ .iter()
+ .find(|project| project.worktree_root_names[0] == first_root_name)?
+ .id;
+ Some(room.update(cx, |room, cx| {
room.join_project(
- remote_project_id,
+ project_id,
client.language_registry.clone(),
FakeFs::new(cx.background().clone()),
cx,