1use std::path::{Path, PathBuf};
2
3use call::ActiveCall;
4use client::RECEIVE_TIMEOUT;
5use collections::HashMap;
6use git::{
7 repository::{RepoPath, Worktree as GitWorktree},
8 status::{DiffStat, FileStatus, StatusCode, TrackedStatus},
9};
10use git_ui::{git_panel::GitPanel, project_diff::ProjectDiff};
11use gpui::{AppContext as _, BackgroundExecutor, TestAppContext, VisualTestContext};
12use project::ProjectPath;
13use serde_json::json;
14
15use util::{path, rel_path::rel_path};
16use workspace::{MultiWorkspace, Workspace};
17
18use crate::TestServer;
19
20fn collect_diff_stats<C: gpui::AppContext>(
21 panel: &gpui::Entity<GitPanel>,
22 cx: &C,
23) -> HashMap<RepoPath, DiffStat> {
24 panel.read_with(cx, |panel, cx| {
25 let Some(repo) = panel.active_repository() else {
26 return HashMap::default();
27 };
28 let snapshot = repo.read(cx).snapshot();
29 let mut stats = HashMap::default();
30 for entry in snapshot.statuses_by_path.iter() {
31 if let Some(diff_stat) = entry.diff_stat {
32 stats.insert(entry.repo_path.clone(), diff_stat);
33 }
34 }
35 stats
36 })
37}
38
39#[gpui::test]
40async fn test_project_diff(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) {
41 let mut server = TestServer::start(cx_a.background_executor.clone()).await;
42 let client_a = server.create_client(cx_a, "user_a").await;
43 let client_b = server.create_client(cx_b, "user_b").await;
44 cx_a.set_name("cx_a");
45 cx_b.set_name("cx_b");
46
47 server
48 .create_room(&mut [(&client_a, cx_a), (&client_b, cx_b)])
49 .await;
50
51 client_a
52 .fs()
53 .insert_tree(
54 path!("/a"),
55 json!({
56 ".git": {},
57 "changed.txt": "after\n",
58 "unchanged.txt": "unchanged\n",
59 "created.txt": "created\n",
60 "secret.pem": "secret-changed\n",
61 }),
62 )
63 .await;
64
65 client_a.fs().set_head_and_index_for_repo(
66 Path::new(path!("/a/.git")),
67 &[
68 ("changed.txt", "before\n".to_string()),
69 ("unchanged.txt", "unchanged\n".to_string()),
70 ("deleted.txt", "deleted\n".to_string()),
71 ("secret.pem", "shh\n".to_string()),
72 ],
73 );
74 let (project_a, worktree_id) = client_a.build_local_project(path!("/a"), cx_a).await;
75 let active_call_a = cx_a.read(ActiveCall::global);
76 let project_id = active_call_a
77 .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx))
78 .await
79 .unwrap();
80
81 cx_b.update(editor::init);
82 cx_b.update(git_ui::init);
83 let project_b = client_b.join_remote_project(project_id, cx_b).await;
84 let window_b = cx_b.add_window(|window, cx| {
85 let workspace = cx.new(|cx| {
86 Workspace::new(
87 None,
88 project_b.clone(),
89 client_b.app_state.clone(),
90 window,
91 cx,
92 )
93 });
94 MultiWorkspace::new(workspace, window, cx)
95 });
96 let cx_b = &mut VisualTestContext::from_window(*window_b, cx_b);
97 let workspace_b = window_b
98 .root(cx_b)
99 .unwrap()
100 .read_with(cx_b, |multi_workspace, _| {
101 multi_workspace.workspace().clone()
102 });
103
104 cx_b.update(|window, cx| {
105 window
106 .focused(cx)
107 .unwrap()
108 .dispatch_action(&git_ui::project_diff::Diff, window, cx)
109 });
110 let diff = workspace_b.update(cx_b, |workspace, cx| {
111 workspace.active_item(cx).unwrap().act_as::<ProjectDiff>(cx)
112 });
113 let diff = diff.unwrap();
114 cx_b.run_until_parked();
115
116 diff.update(cx_b, |diff, cx| {
117 assert_eq!(
118 diff.excerpt_paths(cx),
119 vec![
120 rel_path("changed.txt").into_arc(),
121 rel_path("deleted.txt").into_arc(),
122 rel_path("created.txt").into_arc()
123 ]
124 );
125 });
126
127 client_a
128 .fs()
129 .insert_tree(
130 path!("/a"),
131 json!({
132 ".git": {},
133 "changed.txt": "before\n",
134 "unchanged.txt": "changed\n",
135 "created.txt": "created\n",
136 "secret.pem": "secret-changed\n",
137 }),
138 )
139 .await;
140 cx_b.run_until_parked();
141
142 project_b.update(cx_b, |project, cx| {
143 let project_path = ProjectPath {
144 worktree_id,
145 path: rel_path("unchanged.txt").into(),
146 };
147 let status = project.project_path_git_status(&project_path, cx);
148 assert_eq!(
149 status.unwrap(),
150 FileStatus::Tracked(TrackedStatus {
151 worktree_status: StatusCode::Modified,
152 index_status: StatusCode::Unmodified,
153 })
154 );
155 });
156
157 diff.update(cx_b, |diff, cx| {
158 assert_eq!(
159 diff.excerpt_paths(cx),
160 vec![
161 rel_path("deleted.txt").into_arc(),
162 rel_path("unchanged.txt").into_arc(),
163 rel_path("created.txt").into_arc()
164 ]
165 );
166 });
167}
168
169#[gpui::test]
170async fn test_remote_git_worktrees(
171 executor: BackgroundExecutor,
172 cx_a: &mut TestAppContext,
173 cx_b: &mut TestAppContext,
174) {
175 let mut server = TestServer::start(executor.clone()).await;
176 let client_a = server.create_client(cx_a, "user_a").await;
177 let client_b = server.create_client(cx_b, "user_b").await;
178 server
179 .create_room(&mut [(&client_a, cx_a), (&client_b, cx_b)])
180 .await;
181 let active_call_a = cx_a.read(ActiveCall::global);
182
183 client_a
184 .fs()
185 .insert_tree(
186 path!("/project"),
187 json!({ ".git": {}, "file.txt": "content" }),
188 )
189 .await;
190
191 let (project_a, _) = client_a.build_local_project(path!("/project"), cx_a).await;
192
193 let project_id = active_call_a
194 .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx))
195 .await
196 .unwrap();
197 let project_b = client_b.join_remote_project(project_id, cx_b).await;
198
199 executor.run_until_parked();
200
201 let repo_b = cx_b.update(|cx| project_b.read(cx).active_repository(cx).unwrap());
202
203 // Initially only the main worktree (the repo itself) should be present
204 let worktrees = cx_b
205 .update(|cx| repo_b.update(cx, |repository, _| repository.worktrees()))
206 .await
207 .unwrap()
208 .unwrap();
209 assert_eq!(worktrees.len(), 1);
210 assert_eq!(worktrees[0].path, PathBuf::from(path!("/project")));
211
212 // Client B creates a git worktree via the remote project
213 let worktree_directory = PathBuf::from(path!("/project"));
214 cx_b.update(|cx| {
215 repo_b.update(cx, |repository, _| {
216 repository.create_worktree(
217 "feature-branch".to_string(),
218 worktree_directory.clone(),
219 Some("abc123".to_string()),
220 )
221 })
222 })
223 .await
224 .unwrap()
225 .unwrap();
226
227 executor.run_until_parked();
228
229 // Client B lists worktrees — should see main + the one just created
230 let worktrees = cx_b
231 .update(|cx| repo_b.update(cx, |repository, _| repository.worktrees()))
232 .await
233 .unwrap()
234 .unwrap();
235 assert_eq!(worktrees.len(), 2);
236 assert_eq!(worktrees[0].path, PathBuf::from(path!("/project")));
237 assert_eq!(worktrees[1].path, worktree_directory.join("feature-branch"));
238 assert_eq!(worktrees[1].ref_name.as_ref(), "refs/heads/feature-branch");
239 assert_eq!(worktrees[1].sha.as_ref(), "abc123");
240
241 // Verify from the host side that the worktree was actually created
242 let host_worktrees = {
243 let repo_a = cx_a.update(|cx| {
244 project_a
245 .read(cx)
246 .repositories(cx)
247 .values()
248 .next()
249 .unwrap()
250 .clone()
251 });
252 cx_a.update(|cx| repo_a.update(cx, |repository, _| repository.worktrees()))
253 .await
254 .unwrap()
255 .unwrap()
256 };
257 assert_eq!(host_worktrees.len(), 2);
258 assert_eq!(host_worktrees[0].path, PathBuf::from(path!("/project")));
259 assert_eq!(
260 host_worktrees[1].path,
261 worktree_directory.join("feature-branch")
262 );
263
264 // Client B creates a second git worktree without an explicit commit
265 cx_b.update(|cx| {
266 repo_b.update(cx, |repository, _| {
267 repository.create_worktree(
268 "bugfix-branch".to_string(),
269 worktree_directory.clone(),
270 None,
271 )
272 })
273 })
274 .await
275 .unwrap()
276 .unwrap();
277
278 executor.run_until_parked();
279
280 // Client B lists worktrees — should now have main + two created
281 let worktrees = cx_b
282 .update(|cx| repo_b.update(cx, |repository, _| repository.worktrees()))
283 .await
284 .unwrap()
285 .unwrap();
286 assert_eq!(worktrees.len(), 3);
287
288 let feature_worktree = worktrees
289 .iter()
290 .find(|worktree| worktree.ref_name.as_ref() == "refs/heads/feature-branch")
291 .expect("should find feature-branch worktree");
292 assert_eq!(
293 feature_worktree.path,
294 worktree_directory.join("feature-branch")
295 );
296
297 let bugfix_worktree = worktrees
298 .iter()
299 .find(|worktree| worktree.ref_name.as_ref() == "refs/heads/bugfix-branch")
300 .expect("should find bugfix-branch worktree");
301 assert_eq!(
302 bugfix_worktree.path,
303 worktree_directory.join("bugfix-branch")
304 );
305 assert_eq!(bugfix_worktree.sha.as_ref(), "fake-sha");
306
307 // Client B (guest) attempts to rename a worktree. This should fail
308 // because worktree renaming is not forwarded through collab
309 let rename_result = cx_b
310 .update(|cx| {
311 repo_b.update(cx, |repository, _| {
312 repository.rename_worktree(
313 worktree_directory.join("feature-branch"),
314 worktree_directory.join("renamed-branch"),
315 )
316 })
317 })
318 .await
319 .unwrap();
320 assert!(
321 rename_result.is_err(),
322 "Guest should not be able to rename worktrees via collab"
323 );
324
325 executor.run_until_parked();
326
327 // Verify worktrees are unchanged — still 3
328 let worktrees = cx_b
329 .update(|cx| repo_b.update(cx, |repository, _| repository.worktrees()))
330 .await
331 .unwrap()
332 .unwrap();
333 assert_eq!(
334 worktrees.len(),
335 3,
336 "Worktree count should be unchanged after failed rename"
337 );
338
339 // Client B (guest) attempts to remove a worktree. This should fail
340 // because worktree removal is not forwarded through collab
341 let remove_result = cx_b
342 .update(|cx| {
343 repo_b.update(cx, |repository, _| {
344 repository.remove_worktree(worktree_directory.join("feature-branch"), false)
345 })
346 })
347 .await
348 .unwrap();
349 assert!(
350 remove_result.is_err(),
351 "Guest should not be able to remove worktrees via collab"
352 );
353
354 executor.run_until_parked();
355
356 // Verify worktrees are unchanged — still 3
357 let worktrees = cx_b
358 .update(|cx| repo_b.update(cx, |repository, _| repository.worktrees()))
359 .await
360 .unwrap()
361 .unwrap();
362 assert_eq!(
363 worktrees.len(),
364 3,
365 "Worktree count should be unchanged after failed removal"
366 );
367}
368
369#[gpui::test]
370async fn test_linked_worktrees_sync(
371 executor: BackgroundExecutor,
372 cx_a: &mut TestAppContext,
373 cx_b: &mut TestAppContext,
374 cx_c: &mut TestAppContext,
375) {
376 let mut server = TestServer::start(executor.clone()).await;
377 let client_a = server.create_client(cx_a, "user_a").await;
378 let client_b = server.create_client(cx_b, "user_b").await;
379 let client_c = server.create_client(cx_c, "user_c").await;
380 server
381 .create_room(&mut [(&client_a, cx_a), (&client_b, cx_b), (&client_c, cx_c)])
382 .await;
383 let active_call_a = cx_a.read(ActiveCall::global);
384
385 // Set up a git repo with two linked worktrees already present.
386 client_a
387 .fs()
388 .insert_tree(
389 path!("/project"),
390 json!({ ".git": {}, "file.txt": "content" }),
391 )
392 .await;
393
394 client_a
395 .fs()
396 .with_git_state(Path::new(path!("/project/.git")), true, |state| {
397 state.worktrees.push(GitWorktree {
398 path: PathBuf::from(path!("/project")),
399 ref_name: "refs/heads/main".into(),
400 sha: "aaa111".into(),
401 });
402 state.worktrees.push(GitWorktree {
403 path: PathBuf::from(path!("/project/feature-branch")),
404 ref_name: "refs/heads/feature-branch".into(),
405 sha: "bbb222".into(),
406 });
407 state.worktrees.push(GitWorktree {
408 path: PathBuf::from(path!("/project/bugfix-branch")),
409 ref_name: "refs/heads/bugfix-branch".into(),
410 sha: "ccc333".into(),
411 });
412 })
413 .unwrap();
414
415 let (project_a, _) = client_a.build_local_project(path!("/project"), cx_a).await;
416
417 // Wait for git scanning to complete on the host.
418 executor.run_until_parked();
419
420 // Verify the host sees 2 linked worktrees (main worktree is filtered out).
421 let host_linked = project_a.read_with(cx_a, |project, cx| {
422 let repos = project.repositories(cx);
423 assert_eq!(repos.len(), 1, "host should have exactly 1 repository");
424 let repo = repos.values().next().unwrap();
425 repo.read(cx).linked_worktrees().to_vec()
426 });
427 assert_eq!(
428 host_linked.len(),
429 2,
430 "host should have 2 linked worktrees (main filtered out)"
431 );
432 assert_eq!(
433 host_linked[0].path,
434 PathBuf::from(path!("/project/feature-branch"))
435 );
436 assert_eq!(
437 host_linked[0].ref_name.as_ref(),
438 "refs/heads/feature-branch"
439 );
440 assert_eq!(host_linked[0].sha.as_ref(), "bbb222");
441 assert_eq!(
442 host_linked[1].path,
443 PathBuf::from(path!("/project/bugfix-branch"))
444 );
445 assert_eq!(host_linked[1].ref_name.as_ref(), "refs/heads/bugfix-branch");
446 assert_eq!(host_linked[1].sha.as_ref(), "ccc333");
447
448 // Share the project and have client B join.
449 let project_id = active_call_a
450 .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx))
451 .await
452 .unwrap();
453 let project_b = client_b.join_remote_project(project_id, cx_b).await;
454
455 executor.run_until_parked();
456
457 // Verify the guest sees the same linked worktrees as the host.
458 let guest_linked = project_b.read_with(cx_b, |project, cx| {
459 let repos = project.repositories(cx);
460 assert_eq!(repos.len(), 1, "guest should have exactly 1 repository");
461 let repo = repos.values().next().unwrap();
462 repo.read(cx).linked_worktrees().to_vec()
463 });
464 assert_eq!(
465 guest_linked, host_linked,
466 "guest's linked_worktrees should match host's after initial sync"
467 );
468
469 // Now mutate: add a third linked worktree on the host side.
470 client_a
471 .fs()
472 .with_git_state(Path::new(path!("/project/.git")), true, |state| {
473 state.worktrees.push(GitWorktree {
474 path: PathBuf::from(path!("/project/hotfix-branch")),
475 ref_name: "refs/heads/hotfix-branch".into(),
476 sha: "ddd444".into(),
477 });
478 })
479 .unwrap();
480
481 // Wait for the host to re-scan and propagate the update.
482 executor.run_until_parked();
483
484 // Verify host now sees 3 linked worktrees.
485 let host_linked_updated = project_a.read_with(cx_a, |project, cx| {
486 let repos = project.repositories(cx);
487 let repo = repos.values().next().unwrap();
488 repo.read(cx).linked_worktrees().to_vec()
489 });
490 assert_eq!(
491 host_linked_updated.len(),
492 3,
493 "host should now have 3 linked worktrees"
494 );
495 assert_eq!(
496 host_linked_updated[2].path,
497 PathBuf::from(path!("/project/hotfix-branch"))
498 );
499
500 // Verify the guest also received the update.
501 let guest_linked_updated = project_b.read_with(cx_b, |project, cx| {
502 let repos = project.repositories(cx);
503 let repo = repos.values().next().unwrap();
504 repo.read(cx).linked_worktrees().to_vec()
505 });
506 assert_eq!(
507 guest_linked_updated, host_linked_updated,
508 "guest's linked_worktrees should match host's after update"
509 );
510
511 // Now mutate: remove one linked worktree from the host side.
512 client_a
513 .fs()
514 .with_git_state(Path::new(path!("/project/.git")), true, |state| {
515 state
516 .worktrees
517 .retain(|wt| wt.ref_name.as_ref() != "refs/heads/bugfix-branch");
518 })
519 .unwrap();
520
521 executor.run_until_parked();
522
523 // Verify host now sees 2 linked worktrees (feature-branch and hotfix-branch).
524 let host_linked_after_removal = project_a.read_with(cx_a, |project, cx| {
525 let repos = project.repositories(cx);
526 let repo = repos.values().next().unwrap();
527 repo.read(cx).linked_worktrees().to_vec()
528 });
529 assert_eq!(
530 host_linked_after_removal.len(),
531 2,
532 "host should have 2 linked worktrees after removal"
533 );
534 assert!(
535 host_linked_after_removal
536 .iter()
537 .all(|wt| wt.ref_name.as_ref() != "refs/heads/bugfix-branch"),
538 "bugfix-branch should have been removed"
539 );
540
541 // Verify the guest also reflects the removal.
542 let guest_linked_after_removal = project_b.read_with(cx_b, |project, cx| {
543 let repos = project.repositories(cx);
544 let repo = repos.values().next().unwrap();
545 repo.read(cx).linked_worktrees().to_vec()
546 });
547 assert_eq!(
548 guest_linked_after_removal, host_linked_after_removal,
549 "guest's linked_worktrees should match host's after removal"
550 );
551
552 // Test DB roundtrip: client C joins late, getting state from the database.
553 // This verifies that linked_worktrees are persisted and restored correctly.
554 let project_c = client_c.join_remote_project(project_id, cx_c).await;
555 executor.run_until_parked();
556
557 let late_joiner_linked = project_c.read_with(cx_c, |project, cx| {
558 let repos = project.repositories(cx);
559 assert_eq!(
560 repos.len(),
561 1,
562 "late joiner should have exactly 1 repository"
563 );
564 let repo = repos.values().next().unwrap();
565 repo.read(cx).linked_worktrees().to_vec()
566 });
567 assert_eq!(
568 late_joiner_linked, host_linked_after_removal,
569 "late-joining client's linked_worktrees should match host's (DB roundtrip)"
570 );
571
572 // Test reconnection: disconnect client B (guest) and reconnect.
573 // After rejoining, client B should get linked_worktrees back from the DB.
574 server.disconnect_client(client_b.peer_id().unwrap());
575 executor.advance_clock(RECEIVE_TIMEOUT);
576 executor.run_until_parked();
577
578 // Client B reconnects automatically.
579 executor.advance_clock(RECEIVE_TIMEOUT);
580 executor.run_until_parked();
581
582 // Verify client B still has the correct linked worktrees after reconnection.
583 let guest_linked_after_reconnect = project_b.read_with(cx_b, |project, cx| {
584 let repos = project.repositories(cx);
585 assert_eq!(
586 repos.len(),
587 1,
588 "guest should still have exactly 1 repository after reconnect"
589 );
590 let repo = repos.values().next().unwrap();
591 repo.read(cx).linked_worktrees().to_vec()
592 });
593 assert_eq!(
594 guest_linked_after_reconnect, host_linked_after_removal,
595 "guest's linked_worktrees should survive guest disconnect/reconnect"
596 );
597}
598
599#[gpui::test]
600async fn test_diff_stat_sync_between_host_and_downstream_client(
601 cx_a: &mut TestAppContext,
602 cx_b: &mut TestAppContext,
603 cx_c: &mut TestAppContext,
604) {
605 let mut server = TestServer::start(cx_a.background_executor.clone()).await;
606 let client_a = server.create_client(cx_a, "user_a").await;
607 let client_b = server.create_client(cx_b, "user_b").await;
608 let client_c = server.create_client(cx_c, "user_c").await;
609
610 server
611 .create_room(&mut [(&client_a, cx_a), (&client_b, cx_b), (&client_c, cx_c)])
612 .await;
613
614 let fs = client_a.fs();
615 fs.insert_tree(
616 path!("/code"),
617 json!({
618 "project1": {
619 ".git": {},
620 "src": {
621 "lib.rs": "line1\nline2\nline3\n",
622 "new_file.rs": "added1\nadded2\n",
623 },
624 "README.md": "# project 1",
625 }
626 }),
627 )
628 .await;
629
630 let dot_git = Path::new(path!("/code/project1/.git"));
631 fs.set_head_for_repo(
632 dot_git,
633 &[
634 ("src/lib.rs", "line1\nold_line2\n".into()),
635 ("src/deleted.rs", "was_here\n".into()),
636 ],
637 "deadbeef",
638 );
639 fs.set_index_for_repo(
640 dot_git,
641 &[
642 ("src/lib.rs", "line1\nold_line2\nline3\nline4\n".into()),
643 ("src/staged_only.rs", "x\ny\n".into()),
644 ("src/new_file.rs", "added1\nadded2\n".into()),
645 ("README.md", "# project 1".into()),
646 ],
647 );
648
649 let (project_a, worktree_id) = client_a
650 .build_local_project(path!("/code/project1"), cx_a)
651 .await;
652 let active_call_a = cx_a.read(ActiveCall::global);
653 let project_id = active_call_a
654 .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx))
655 .await
656 .unwrap();
657 let project_b = client_b.join_remote_project(project_id, cx_b).await;
658 let _project_c = client_c.join_remote_project(project_id, cx_c).await;
659 cx_a.run_until_parked();
660
661 let (workspace_a, cx_a) = client_a.build_workspace(&project_a, cx_a);
662 let (workspace_b, cx_b) = client_b.build_workspace(&project_b, cx_b);
663
664 let panel_a = workspace_a.update_in(cx_a, GitPanel::new_test);
665 workspace_a.update_in(cx_a, |workspace, window, cx| {
666 workspace.add_panel(panel_a.clone(), window, cx);
667 });
668
669 let panel_b = workspace_b.update_in(cx_b, GitPanel::new_test);
670 workspace_b.update_in(cx_b, |workspace, window, cx| {
671 workspace.add_panel(panel_b.clone(), window, cx);
672 });
673
674 cx_a.run_until_parked();
675
676 let stats_a = collect_diff_stats(&panel_a, cx_a);
677 let stats_b = collect_diff_stats(&panel_b, cx_b);
678
679 let mut expected: HashMap<RepoPath, DiffStat> = HashMap::default();
680 expected.insert(
681 RepoPath::new("src/lib.rs").unwrap(),
682 DiffStat {
683 added: 3,
684 deleted: 2,
685 },
686 );
687 expected.insert(
688 RepoPath::new("src/deleted.rs").unwrap(),
689 DiffStat {
690 added: 0,
691 deleted: 1,
692 },
693 );
694 expected.insert(
695 RepoPath::new("src/new_file.rs").unwrap(),
696 DiffStat {
697 added: 2,
698 deleted: 0,
699 },
700 );
701 expected.insert(
702 RepoPath::new("README.md").unwrap(),
703 DiffStat {
704 added: 1,
705 deleted: 0,
706 },
707 );
708 assert_eq!(stats_a, expected, "host diff stats should match expected");
709 assert_eq!(stats_a, stats_b, "host and remote should agree");
710
711 let buffer_a = project_a
712 .update(cx_a, |p, cx| {
713 p.open_buffer((worktree_id, rel_path("src/lib.rs")), cx)
714 })
715 .await
716 .unwrap();
717
718 let _buffer_b = project_b
719 .update(cx_b, |p, cx| {
720 p.open_buffer((worktree_id, rel_path("src/lib.rs")), cx)
721 })
722 .await
723 .unwrap();
724 cx_a.run_until_parked();
725
726 buffer_a.update(cx_a, |buf, cx| {
727 buf.edit([(buf.len()..buf.len(), "line4\n")], None, cx);
728 });
729 project_a
730 .update(cx_a, |project, cx| {
731 project.save_buffer(buffer_a.clone(), cx)
732 })
733 .await
734 .unwrap();
735 cx_a.run_until_parked();
736
737 let stats_a = collect_diff_stats(&panel_a, cx_a);
738 let stats_b = collect_diff_stats(&panel_b, cx_b);
739
740 let mut expected_after_edit = expected.clone();
741 expected_after_edit.insert(
742 RepoPath::new("src/lib.rs").unwrap(),
743 DiffStat {
744 added: 4,
745 deleted: 2,
746 },
747 );
748 assert_eq!(
749 stats_a, expected_after_edit,
750 "host diff stats should reflect the edit"
751 );
752 assert_eq!(
753 stats_b, expected_after_edit,
754 "remote diff stats should reflect the host's edit"
755 );
756
757 let active_call_b = cx_b.read(ActiveCall::global);
758 active_call_b
759 .update(cx_b, |call, cx| call.hang_up(cx))
760 .await
761 .unwrap();
762 cx_a.run_until_parked();
763
764 let user_id_b = client_b.current_user_id(cx_b).to_proto();
765 active_call_a
766 .update(cx_a, |call, cx| call.invite(user_id_b, None, cx))
767 .await
768 .unwrap();
769 cx_b.run_until_parked();
770 let active_call_b = cx_b.read(ActiveCall::global);
771 active_call_b
772 .update(cx_b, |call, cx| call.accept_incoming(cx))
773 .await
774 .unwrap();
775 cx_a.run_until_parked();
776
777 let project_b = client_b.join_remote_project(project_id, cx_b).await;
778 cx_a.run_until_parked();
779
780 let (workspace_b, cx_b) = client_b.build_workspace(&project_b, cx_b);
781 let panel_b = workspace_b.update_in(cx_b, GitPanel::new_test);
782 workspace_b.update_in(cx_b, |workspace, window, cx| {
783 workspace.add_panel(panel_b.clone(), window, cx);
784 });
785 cx_b.run_until_parked();
786
787 let stats_b = collect_diff_stats(&panel_b, cx_b);
788 assert_eq!(
789 stats_b, expected_after_edit,
790 "remote diff stats should be restored from the database after rejoining the call"
791 );
792}