upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/list.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/list.rs')
-rw-r--r--tests/list.rs539
1 files changed, 397 insertions, 142 deletions
diff --git a/tests/list.rs b/tests/list.rs
index 22d82fd..60c9423 100644
--- a/tests/list.rs
+++ b/tests/list.rs
@@ -277,10 +277,8 @@ mod when_main_branch_is_uptodate {
277 ], 277 ],
278 )?; 278 )?;
279 c.succeeds_with(0, false, Some(0))?; 279 c.succeeds_with(0, false, Some(0))?;
280 p.expect(format!( 280 p.expect_end_eventually_and_print()?;
281 "checked out proposal as '{FEATURE_BRANCH_NAME_1}' branch\r\n" 281
282 ))?;
283 p.expect_end()?;
284 for p in [51, 52, 53, 55, 56] { 282 for p in [51, 52, 53, 55, 56] {
285 relay::shutdown_relay(8000 + p)?; 283 relay::shutdown_relay(8000 + p)?;
286 } 284 }
@@ -351,10 +349,11 @@ mod when_main_branch_is_uptodate {
351 ], 349 ],
352 )?; 350 )?;
353 c.succeeds_with(0, false, None)?; 351 c.succeeds_with(0, false, None)?;
354 p.expect(format!( 352 p.expect(&format!(
355 "checked out proposal as '{FEATURE_BRANCH_NAME_1}' branch\r\n" 353 "checked out proposal as 'prs/{}(",
354 FEATURE_BRANCH_NAME_1,
356 ))?; 355 ))?;
357 p.expect_end()?; 356 p.expect_end_eventually_with(")' branch\r\n")?;
358 357
359 for p in [51, 52, 53, 55, 56] { 358 for p in [51, 52, 53, 55, 56] {
360 relay::shutdown_relay(8000 + p)?; 359 relay::shutdown_relay(8000 + p)?;
@@ -381,7 +380,10 @@ mod when_main_branch_is_uptodate {
381 async fn proposal_branch_created_with_correct_name() -> Result<()> { 380 async fn proposal_branch_created_with_correct_name() -> Result<()> {
382 let (_, test_repo) = prep_and_run().await?; 381 let (_, test_repo) = prep_and_run().await?;
383 assert_eq!( 382 assert_eq!(
384 vec![FEATURE_BRANCH_NAME_1, "main"], 383 vec![
384 "main",
385 &get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?,
386 ],
385 test_repo.get_local_branch_names()? 387 test_repo.get_local_branch_names()?
386 ); 388 );
387 Ok(()) 389 Ok(())
@@ -392,7 +394,7 @@ mod when_main_branch_is_uptodate {
392 async fn proposal_branch_checked_out() -> Result<()> { 394 async fn proposal_branch_checked_out() -> Result<()> {
393 let (_, test_repo) = prep_and_run().await?; 395 let (_, test_repo) = prep_and_run().await?;
394 assert_eq!( 396 assert_eq!(
395 FEATURE_BRANCH_NAME_1, 397 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?,
396 test_repo.get_checked_out_branch_name()?, 398 test_repo.get_checked_out_branch_name()?,
397 ); 399 );
398 Ok(()) 400 Ok(())
@@ -404,7 +406,10 @@ mod when_main_branch_is_uptodate {
404 let (originating_repo, test_repo) = prep_and_run().await?; 406 let (originating_repo, test_repo) = prep_and_run().await?;
405 assert_eq!( 407 assert_eq!(
406 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 408 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
407 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 409 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
410 &test_repo,
411 FEATURE_BRANCH_NAME_1
412 )?)?,
408 ); 413 );
409 Ok(()) 414 Ok(())
410 } 415 }
@@ -461,11 +466,8 @@ mod when_main_branch_is_uptodate {
461 ], 466 ],
462 )?; 467 )?;
463 c.succeeds_with(0, false, Some(0))?; 468 c.succeeds_with(0, false, Some(0))?;
464 p.expect(format!( 469 p.expect_end_eventually_and_print()?;
465 "checked out proposal as '{FEATURE_BRANCH_NAME_3}' branch\r\n" 470
466 ))?;
467 p.expect_end()?;
468 println!("blablagothere");
469 for p in [51, 52, 53, 55, 56] { 471 for p in [51, 52, 53, 55, 56] {
470 relay::shutdown_relay(8000 + p)?; 472 relay::shutdown_relay(8000 + p)?;
471 } 473 }
@@ -537,10 +539,11 @@ mod when_main_branch_is_uptodate {
537 ], 539 ],
538 )?; 540 )?;
539 c.succeeds_with(0, false, Some(0))?; 541 c.succeeds_with(0, false, Some(0))?;
540 p.expect(format!( 542 p.expect(&format!(
541 "checked out proposal as '{FEATURE_BRANCH_NAME_3}' branch\r\n" 543 "checked out proposal as 'prs/{}(",
544 FEATURE_BRANCH_NAME_3,
542 ))?; 545 ))?;
543 p.expect_end()?; 546 p.expect_end_eventually_with(")' branch\r\n")?;
544 547
545 for p in [51, 52, 53, 55, 56] { 548 for p in [51, 52, 53, 55, 56] {
546 relay::shutdown_relay(8000 + p)?; 549 relay::shutdown_relay(8000 + p)?;
@@ -567,7 +570,10 @@ mod when_main_branch_is_uptodate {
567 async fn proposal_branch_created_with_correct_name() -> Result<()> { 570 async fn proposal_branch_created_with_correct_name() -> Result<()> {
568 let (_, test_repo) = prep_and_run().await?; 571 let (_, test_repo) = prep_and_run().await?;
569 assert_eq!( 572 assert_eq!(
570 vec![FEATURE_BRANCH_NAME_3, "main"], 573 vec![
574 "main",
575 &get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_3)?,
576 ],
571 test_repo.get_local_branch_names()? 577 test_repo.get_local_branch_names()?
572 ); 578 );
573 Ok(()) 579 Ok(())
@@ -578,7 +584,7 @@ mod when_main_branch_is_uptodate {
578 async fn proposal_branch_checked_out() -> Result<()> { 584 async fn proposal_branch_checked_out() -> Result<()> {
579 let (_, test_repo) = prep_and_run().await?; 585 let (_, test_repo) = prep_and_run().await?;
580 assert_eq!( 586 assert_eq!(
581 FEATURE_BRANCH_NAME_3, 587 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_3)?,
582 test_repo.get_checked_out_branch_name()?, 588 test_repo.get_checked_out_branch_name()?,
583 ); 589 );
584 Ok(()) 590 Ok(())
@@ -590,7 +596,10 @@ mod when_main_branch_is_uptodate {
590 let (originating_repo, test_repo) = prep_and_run().await?; 596 let (originating_repo, test_repo) = prep_and_run().await?;
591 assert_eq!( 597 assert_eq!(
592 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_3)?, 598 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_3)?,
593 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_3)?, 599 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
600 &test_repo,
601 FEATURE_BRANCH_NAME_3
602 )?)?,
594 ); 603 );
595 Ok(()) 604 Ok(())
596 } 605 }
@@ -653,10 +662,7 @@ mod when_main_branch_is_uptodate {
653 ], 662 ],
654 )?; 663 )?;
655 c.succeeds_with(0, false, Some(0))?; 664 c.succeeds_with(0, false, Some(0))?;
656 p.expect(format!( 665 p.expect_end_eventually_and_print()?;
657 "checked out proposal as '{FEATURE_BRANCH_NAME_4}' branch\r\n"
658 ))?;
659 p.expect_end()?;
660 666
661 for p in [51, 52, 53, 55, 56] { 667 for p in [51, 52, 53, 55, 56] {
662 relay::shutdown_relay(8000 + p)?; 668 relay::shutdown_relay(8000 + p)?;
@@ -737,10 +743,11 @@ mod when_main_branch_is_uptodate {
737 ], 743 ],
738 )?; 744 )?;
739 c.succeeds_with(0, false, Some(0))?; 745 c.succeeds_with(0, false, Some(0))?;
740 p.expect(format!( 746 p.expect(&format!(
741 "checked out proposal as '{FEATURE_BRANCH_NAME_4}' branch\r\n" 747 "checked out proposal as 'prs/{}(",
748 FEATURE_BRANCH_NAME_4,
742 ))?; 749 ))?;
743 p.expect_end()?; 750 p.expect_end_eventually_with(")' branch\r\n")?;
744 751
745 for p in [51, 52, 53, 55, 56] { 752 for p in [51, 52, 53, 55, 56] {
746 relay::shutdown_relay(8000 + p)?; 753 relay::shutdown_relay(8000 + p)?;
@@ -767,7 +774,10 @@ mod when_main_branch_is_uptodate {
767 async fn proposal_branch_created_with_correct_name() -> Result<()> { 774 async fn proposal_branch_created_with_correct_name() -> Result<()> {
768 let (_, test_repo) = prep_and_run().await?; 775 let (_, test_repo) = prep_and_run().await?;
769 assert_eq!( 776 assert_eq!(
770 vec![FEATURE_BRANCH_NAME_4, "main"], 777 vec![
778 "main",
779 &get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_4)?,
780 ],
771 test_repo.get_local_branch_names()? 781 test_repo.get_local_branch_names()?
772 ); 782 );
773 Ok(()) 783 Ok(())
@@ -778,7 +788,7 @@ mod when_main_branch_is_uptodate {
778 async fn proposal_branch_checked_out() -> Result<()> { 788 async fn proposal_branch_checked_out() -> Result<()> {
779 let (_, test_repo) = prep_and_run().await?; 789 let (_, test_repo) = prep_and_run().await?;
780 assert_eq!( 790 assert_eq!(
781 FEATURE_BRANCH_NAME_4, 791 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_4)?,
782 test_repo.get_checked_out_branch_name()?, 792 test_repo.get_checked_out_branch_name()?,
783 ); 793 );
784 Ok(()) 794 Ok(())
@@ -790,7 +800,10 @@ mod when_main_branch_is_uptodate {
790 let (originating_repo, test_repo) = prep_and_run().await?; 800 let (originating_repo, test_repo) = prep_and_run().await?;
791 assert_eq!( 801 assert_eq!(
792 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_4)?, 802 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_4)?,
793 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_4)?, 803 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
804 &test_repo,
805 FEATURE_BRANCH_NAME_4
806 )?)?,
794 ); 807 );
795 Ok(()) 808 Ok(())
796 } 809 }
@@ -824,21 +837,40 @@ mod when_main_branch_is_uptodate {
824 r55.events.push(generate_test_key_1_metadata_event("fred")); 837 r55.events.push(generate_test_key_1_metadata_event("fred"));
825 r55.events.push(generate_test_key_1_relay_list_event()); 838 r55.events.push(generate_test_key_1_relay_list_event());
826 839
827 let cli_tester_handle = 840 let cli_tester_handle = std::thread::spawn(
828 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { 841 move || -> Result<(GitTestRepo, GitTestRepo)> {
829 let originating_repo = cli_tester_create_proposals()?; 842 let originating_repo = cli_tester_create_proposals()?;
830 843
831 let test_repo = GitTestRepo::default(); 844 let test_repo = GitTestRepo::default();
832 test_repo.populate()?; 845 test_repo.populate()?;
846 // create proposal branch
833 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 847 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
834 848 p.expect("fetching updates...\r\n")?;
835 create_and_populate_branch( 849 p.expect_eventually("\r\n")?; // some updates listed here
836 &test_repo, 850 let mut c = p.expect_choice(
837 FEATURE_BRANCH_NAME_1, 851 "all proposals",
838 "a", 852 vec![
839 false, 853 format!("\"{PROPOSAL_TITLE_3}\""),
854 format!("\"{PROPOSAL_TITLE_2}\""),
855 format!("\"{PROPOSAL_TITLE_1}\""),
856 ],
840 )?; 857 )?;
858 c.succeeds_with(2, true, None)?;
859 let mut c = p.expect_choice(
860 "",
861 vec![
862 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
863 format!("apply to current branch with `git am`"),
864 format!("download to ./patches"),
865 format!("back"),
866 ],
867 )?;
868 c.succeeds_with(0, false, Some(0))?;
869 p.expect_end_eventually()?;
870
841 test_repo.checkout("main")?; 871 test_repo.checkout("main")?;
872 // run test
873 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
842 p.expect("fetching updates...\r\n")?; 874 p.expect("fetching updates...\r\n")?;
843 p.expect_eventually("\r\n")?; // some updates listed here 875 p.expect_eventually("\r\n")?; // some updates listed here
844 let mut c = p.expect_choice( 876 let mut c = p.expect_choice(
@@ -860,16 +892,14 @@ mod when_main_branch_is_uptodate {
860 ], 892 ],
861 )?; 893 )?;
862 c.succeeds_with(0, false, Some(0))?; 894 c.succeeds_with(0, false, Some(0))?;
863 p.expect(format!( 895 p.expect_end_eventually_and_print()?;
864 "checked out proposal as '{FEATURE_BRANCH_NAME_1}' branch\r\n"
865 ))?;
866 p.expect_end()?;
867 896
868 for p in [51, 52, 53, 55, 56] { 897 for p in [51, 52, 53, 55, 56] {
869 relay::shutdown_relay(8000 + p)?; 898 relay::shutdown_relay(8000 + p)?;
870 } 899 }
871 Ok((originating_repo, test_repo)) 900 Ok((originating_repo, test_repo))
872 }); 901 },
902 );
873 903
874 // launch relay 904 // launch relay
875 let _ = join!( 905 let _ = join!(
@@ -911,16 +941,34 @@ mod when_main_branch_is_uptodate {
911 941
912 let test_repo = GitTestRepo::default(); 942 let test_repo = GitTestRepo::default();
913 test_repo.populate()?; 943 test_repo.populate()?;
944 // create proposal branch
914 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 945 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
915 946 p.expect("fetching updates...\r\n")?;
916 create_and_populate_branch( 947 p.expect_eventually("\r\n")?; // some updates listed here
917 &test_repo, 948 let mut c = p.expect_choice(
918 FEATURE_BRANCH_NAME_1, 949 "all proposals",
919 "a", 950 vec![
920 false, 951 format!("\"{PROPOSAL_TITLE_3}\""),
952 format!("\"{PROPOSAL_TITLE_2}\""),
953 format!("\"{PROPOSAL_TITLE_1}\""),
954 ],
921 )?; 955 )?;
922 test_repo.checkout("main")?; 956 c.succeeds_with(2, true, None)?;
957 let mut c = p.expect_choice(
958 "",
959 vec![
960 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
961 format!("apply to current branch with `git am`"),
962 format!("download to ./patches"),
963 format!("back"),
964 ],
965 )?;
966 c.succeeds_with(0, false, Some(0))?;
967 p.expect_end_eventually()?;
923 968
969 test_repo.checkout("main")?;
970 // run test
971 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
924 p.expect("fetching updates...\r\n")?; 972 p.expect("fetching updates...\r\n")?;
925 p.expect_eventually("\r\n")?; // some updates listed here 973 p.expect_eventually("\r\n")?; // some updates listed here
926 let mut c = p.expect_choice( 974 let mut c = p.expect_choice(
@@ -942,10 +990,11 @@ mod when_main_branch_is_uptodate {
942 ], 990 ],
943 )?; 991 )?;
944 c.succeeds_with(0, false, Some(0))?; 992 c.succeeds_with(0, false, Some(0))?;
945 p.expect(format!( 993 p.expect(&format!(
946 "checked out proposal as '{FEATURE_BRANCH_NAME_1}' branch\r\n" 994 "checked out proposal as 'prs/{}(",
995 FEATURE_BRANCH_NAME_1,
947 ))?; 996 ))?;
948 p.expect_end()?; 997 p.expect_end_eventually_with(")' branch\r\n")?;
949 998
950 for p in [51, 52, 53, 55, 56] { 999 for p in [51, 52, 53, 55, 56] {
951 relay::shutdown_relay(8000 + p)?; 1000 relay::shutdown_relay(8000 + p)?;
@@ -972,7 +1021,7 @@ mod when_main_branch_is_uptodate {
972 async fn proposal_branch_checked_out() -> Result<()> { 1021 async fn proposal_branch_checked_out() -> Result<()> {
973 let (_, test_repo) = prep_and_run().await?; 1022 let (_, test_repo) = prep_and_run().await?;
974 assert_eq!( 1023 assert_eq!(
975 FEATURE_BRANCH_NAME_1, 1024 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?,
976 test_repo.get_checked_out_branch_name()?, 1025 test_repo.get_checked_out_branch_name()?,
977 ); 1026 );
978 Ok(()) 1027 Ok(())
@@ -1003,19 +1052,46 @@ mod when_main_branch_is_uptodate {
1003 let cli_tester_handle = std::thread::spawn( 1052 let cli_tester_handle = std::thread::spawn(
1004 move || -> Result<(GitTestRepo, GitTestRepo)> { 1053 move || -> Result<(GitTestRepo, GitTestRepo)> {
1005 let originating_repo = cli_tester_create_proposals()?; 1054 let originating_repo = cli_tester_create_proposals()?;
1006
1007 let test_repo = GitTestRepo::default(); 1055 let test_repo = GitTestRepo::default();
1008 test_repo.populate()?; 1056 test_repo.populate()?;
1057 // create proposal branch
1009 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1058 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1059 p.expect("fetching updates...\r\n")?;
1060 p.expect_eventually("\r\n")?; // some updates listed here
1061 let mut c = p.expect_choice(
1062 "all proposals",
1063 vec![
1064 format!("\"{PROPOSAL_TITLE_3}\""),
1065 format!("\"{PROPOSAL_TITLE_2}\""),
1066 format!("\"{PROPOSAL_TITLE_1}\""),
1067 ],
1068 )?;
1069 c.succeeds_with(2, true, None)?;
1070 let mut c = p.expect_choice(
1071 "",
1072 vec![
1073 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1074 format!("apply to current branch with `git am`"),
1075 format!("download to ./patches"),
1076 format!("back"),
1077 ],
1078 )?;
1079 c.succeeds_with(0, false, Some(0))?;
1080 p.expect_end_eventually()?;
1010 1081
1011 create_and_populate_branch( 1082 // remove latest commit so it is behind
1012 &test_repo, 1083 let branch_name = test_repo.get_checked_out_branch_name()?;
1013 FEATURE_BRANCH_NAME_1, 1084 test_repo.checkout("main")?;
1014 "a", 1085 test_repo.git_repo.branch(
1086 &branch_name,
1087 &test_repo
1088 .git_repo
1089 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
1090 .parent(0)?,
1015 true, 1091 true,
1016 )?; 1092 )?;
1017 test_repo.checkout("main")?; 1093 // run test
1018 1094 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1019 p.expect("fetching updates...\r\n")?; 1095 p.expect("fetching updates...\r\n")?;
1020 p.expect_eventually("\r\n")?; // some updates listed here 1096 p.expect_eventually("\r\n")?; // some updates listed here
1021 let mut c = p.expect_choice( 1097 let mut c = p.expect_choice(
@@ -1087,16 +1163,44 @@ mod when_main_branch_is_uptodate {
1087 1163
1088 let test_repo = GitTestRepo::default(); 1164 let test_repo = GitTestRepo::default();
1089 test_repo.populate()?; 1165 test_repo.populate()?;
1166 // create proposal branch
1090 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1167 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1168 p.expect("fetching updates...\r\n")?;
1169 p.expect_eventually("\r\n")?; // some updates listed here
1170 let mut c = p.expect_choice(
1171 "all proposals",
1172 vec![
1173 format!("\"{PROPOSAL_TITLE_3}\""),
1174 format!("\"{PROPOSAL_TITLE_2}\""),
1175 format!("\"{PROPOSAL_TITLE_1}\""),
1176 ],
1177 )?;
1178 c.succeeds_with(2, true, None)?;
1179 let mut c = p.expect_choice(
1180 "",
1181 vec![
1182 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1183 format!("apply to current branch with `git am`"),
1184 format!("download to ./patches"),
1185 format!("back"),
1186 ],
1187 )?;
1188 c.succeeds_with(0, false, Some(0))?;
1189 p.expect_end_eventually()?;
1091 1190
1092 create_and_populate_branch( 1191 // remove latest commit so it is behind
1093 &test_repo, 1192 let branch_name = test_repo.get_checked_out_branch_name()?;
1094 FEATURE_BRANCH_NAME_1, 1193 test_repo.checkout("main")?;
1095 "a", 1194 test_repo.git_repo.branch(
1195 &branch_name,
1196 &test_repo
1197 .git_repo
1198 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
1199 .parent(0)?,
1096 true, 1200 true,
1097 )?; 1201 )?;
1098 test_repo.checkout("main")?; 1202 // run test
1099 1203 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1100 p.expect("fetching updates...\r\n")?; 1204 p.expect("fetching updates...\r\n")?;
1101 p.expect_eventually("\r\n")?; // some updates listed here 1205 p.expect_eventually("\r\n")?; // some updates listed here
1102 let mut c = p.expect_choice( 1206 let mut c = p.expect_choice(
@@ -1146,7 +1250,7 @@ mod when_main_branch_is_uptodate {
1146 async fn proposal_branch_checked_out() -> Result<()> { 1250 async fn proposal_branch_checked_out() -> Result<()> {
1147 let (_, test_repo) = prep_and_run().await?; 1251 let (_, test_repo) = prep_and_run().await?;
1148 assert_eq!( 1252 assert_eq!(
1149 FEATURE_BRANCH_NAME_1, 1253 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?,
1150 test_repo.get_checked_out_branch_name()?, 1254 test_repo.get_checked_out_branch_name()?,
1151 ); 1255 );
1152 Ok(()) 1256 Ok(())
@@ -1158,7 +1262,10 @@ mod when_main_branch_is_uptodate {
1158 let (originating_repo, test_repo) = prep_and_run().await?; 1262 let (originating_repo, test_repo) = prep_and_run().await?;
1159 assert_eq!( 1263 assert_eq!(
1160 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1264 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
1161 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1265 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
1266 &test_repo,
1267 FEATURE_BRANCH_NAME_1
1268 )?)?,
1162 ); 1269 );
1163 Ok(()) 1270 Ok(())
1164 } 1271 }
@@ -1185,30 +1292,59 @@ mod when_main_branch_is_uptodate {
1185 r55.events.push(generate_test_key_1_metadata_event("fred")); 1292 r55.events.push(generate_test_key_1_metadata_event("fred"));
1186 r55.events.push(generate_test_key_1_relay_list_event()); 1293 r55.events.push(generate_test_key_1_relay_list_event());
1187 1294
1188 let cli_tester_handle = 1295 let cli_tester_handle = std::thread::spawn(
1189 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { 1296 move || -> Result<(GitTestRepo, GitTestRepo)> {
1190 let originating_repo = cli_tester_create_proposals()?; 1297 let originating_repo = cli_tester_create_proposals()?;
1191 1298
1192 let test_repo = GitTestRepo::default(); 1299 let test_repo = GitTestRepo::default();
1193 test_repo.populate()?; 1300 test_repo.populate()?;
1301 // create proposal branch
1194 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1302 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1195 1303 p.expect("fetching updates...\r\n")?;
1196 // simulating checking out the proposal (the commits_ids will match) 1304 p.expect_eventually("\r\n")?; // some updates listed here
1197 create_and_populate_branch( 1305 let mut c = p.expect_choice(
1198 &test_repo, 1306 "all proposals",
1199 "different-branch-name", 1307 vec![
1200 "a", 1308 format!("\"{PROPOSAL_TITLE_3}\""),
1201 false, 1309 format!("\"{PROPOSAL_TITLE_2}\""),
1310 format!("\"{PROPOSAL_TITLE_1}\""),
1311 ],
1202 )?; 1312 )?;
1203 // simulating amending the proposal 1313 c.succeeds_with(2, true, None)?;
1204 create_and_populate_branch( 1314 let mut c = p.expect_choice(
1205 &test_repo, 1315 "",
1206 FEATURE_BRANCH_NAME_1, 1316 vec![
1207 "a-changed", 1317 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1208 false, 1318 format!("apply to current branch with `git am`"),
1319 format!("download to ./patches"),
1320 format!("back"),
1321 ],
1209 )?; 1322 )?;
1323 c.succeeds_with(0, false, Some(0))?;
1324 p.expect_end_eventually()?;
1210 1325
1326 // remove latest commit so it is behind
1327 let branch_name = test_repo.get_checked_out_branch_name()?;
1328 test_repo.checkout("main")?;
1329 test_repo.git_repo.branch(
1330 &branch_name,
1331 &test_repo
1332 .git_repo
1333 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
1334 .parent(0)?,
1335 true,
1336 )?;
1337 // add another commit (so we have an ammened local branch)
1338 test_repo.checkout(&branch_name)?;
1339 std::fs::write(
1340 test_repo.dir.join("ammended-commit.md"),
1341 "some content",
1342 )?;
1343 test_repo.stage_and_commit("add ammended-commit.md")?;
1211 test_repo.checkout("main")?; 1344 test_repo.checkout("main")?;
1345
1346 // run test
1347 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1212 p.expect("fetching updates...\r\n")?; 1348 p.expect("fetching updates...\r\n")?;
1213 p.expect_eventually("\r\n")?; // some updates listed here 1349 p.expect_eventually("\r\n")?; // some updates listed here
1214 let mut c = p.expect_choice( 1350 let mut c = p.expect_choice(
@@ -1242,7 +1378,8 @@ mod when_main_branch_is_uptodate {
1242 relay::shutdown_relay(8000 + p)?; 1378 relay::shutdown_relay(8000 + p)?;
1243 } 1379 }
1244 Ok((originating_repo, test_repo)) 1380 Ok((originating_repo, test_repo))
1245 }); 1381 },
1382 );
1246 // launch relay 1383 // launch relay
1247 let _ = join!( 1384 let _ = join!(
1248 r51.listen_until_close(), 1385 r51.listen_until_close(),
@@ -1284,24 +1421,53 @@ mod when_main_branch_is_uptodate {
1284 1421
1285 let test_repo = GitTestRepo::default(); 1422 let test_repo = GitTestRepo::default();
1286 test_repo.populate()?; 1423 test_repo.populate()?;
1424 // create proposal branch
1287 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1425 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1288 1426 p.expect("fetching updates...\r\n")?;
1289 // simulating checking out the proposal (the commits_ids will match) 1427 p.expect_eventually("\r\n")?; // some updates listed here
1290 create_and_populate_branch( 1428 let mut c = p.expect_choice(
1291 &test_repo, 1429 "all proposals",
1292 "different-branch-name", 1430 vec![
1293 "a", 1431 format!("\"{PROPOSAL_TITLE_3}\""),
1294 false, 1432 format!("\"{PROPOSAL_TITLE_2}\""),
1433 format!("\"{PROPOSAL_TITLE_1}\""),
1434 ],
1295 )?; 1435 )?;
1296 // simulating amending the proposal 1436 c.succeeds_with(2, true, None)?;
1297 create_and_populate_branch( 1437 let mut c = p.expect_choice(
1298 &test_repo, 1438 "",
1299 FEATURE_BRANCH_NAME_1, 1439 vec![
1300 "a-changed", 1440 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1301 false, 1441 format!("apply to current branch with `git am`"),
1442 format!("download to ./patches"),
1443 format!("back"),
1444 ],
1302 )?; 1445 )?;
1446 c.succeeds_with(0, false, Some(0))?;
1447 p.expect_end_eventually()?;
1303 1448
1449 // remove latest commit so it is behind
1450 let branch_name = test_repo.get_checked_out_branch_name()?;
1304 test_repo.checkout("main")?; 1451 test_repo.checkout("main")?;
1452 test_repo.git_repo.branch(
1453 &branch_name,
1454 &test_repo
1455 .git_repo
1456 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
1457 .parent(0)?,
1458 true,
1459 )?;
1460 // add another commit (so we have an ammened local branch)
1461 test_repo.checkout(&branch_name)?;
1462 std::fs::write(
1463 test_repo.dir.join("ammended-commit.md"),
1464 "some content",
1465 )?;
1466 test_repo.stage_and_commit("add ammended-commit.md")?;
1467 test_repo.checkout("main")?;
1468
1469 // run test
1470 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1305 p.expect("fetching updates...\r\n")?; 1471 p.expect("fetching updates...\r\n")?;
1306 p.expect_eventually("\r\n")?; // some updates listed here 1472 p.expect_eventually("\r\n")?; // some updates listed here
1307 let mut c = p.expect_choice( 1473 let mut c = p.expect_choice(
@@ -1362,7 +1528,10 @@ mod when_main_branch_is_uptodate {
1362 let (originating_repo, test_repo) = prep_and_run().await?; 1528 let (originating_repo, test_repo) = prep_and_run().await?;
1363 println!("test_dir: {:?}", test_repo.dir); 1529 println!("test_dir: {:?}", test_repo.dir);
1364 assert_eq!( 1530 assert_eq!(
1365 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1531 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
1532 &test_repo,
1533 FEATURE_BRANCH_NAME_1
1534 )?)?,
1366 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1535 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
1367 ); 1536 );
1368 Ok(()) 1537 Ok(())
@@ -1395,19 +1564,41 @@ mod when_main_branch_is_uptodate {
1395 1564
1396 let test_repo = GitTestRepo::default(); 1565 let test_repo = GitTestRepo::default();
1397 test_repo.populate()?; 1566 test_repo.populate()?;
1567 // create proposal branch
1398 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1568 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1399 1569 p.expect("fetching updates...\r\n")?;
1400 create_and_populate_branch( 1570 p.expect_eventually("\r\n")?; // some updates listed here
1401 &test_repo, 1571 let mut c = p.expect_choice(
1402 FEATURE_BRANCH_NAME_1, 1572 "all proposals",
1403 "a", 1573 vec![
1404 false, 1574 format!("\"{PROPOSAL_TITLE_3}\""),
1575 format!("\"{PROPOSAL_TITLE_2}\""),
1576 format!("\"{PROPOSAL_TITLE_1}\""),
1577 ],
1578 )?;
1579 c.succeeds_with(2, true, None)?;
1580 let mut c = p.expect_choice(
1581 "",
1582 vec![
1583 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1584 format!("apply to current branch with `git am`"),
1585 format!("download to ./patches"),
1586 format!("back"),
1587 ],
1405 )?; 1588 )?;
1406 // add appended commit to local branch 1589 c.succeeds_with(0, false, Some(0))?;
1407 std::fs::write(test_repo.dir.join("appended.md"), "some content")?; 1590 p.expect_end_eventually()?;
1408 test_repo.stage_and_commit("appended commit")?;
1409 1591
1592 // add another commit (so we have a local branch 1 ahead)
1593 std::fs::write(
1594 test_repo.dir.join("ammended-commit.md"),
1595 "some content",
1596 )?;
1597 test_repo.stage_and_commit("add ammended-commit.md")?;
1410 test_repo.checkout("main")?; 1598 test_repo.checkout("main")?;
1599
1600 // run test
1601 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1411 p.expect("fetching updates...\r\n")?; 1602 p.expect("fetching updates...\r\n")?;
1412 p.expect_eventually("\r\n")?; // some updates listed here 1603 p.expect_eventually("\r\n")?; // some updates listed here
1413 let mut c = p.expect_choice( 1604 let mut c = p.expect_choice(
@@ -1481,19 +1672,41 @@ mod when_main_branch_is_uptodate {
1481 1672
1482 let test_repo = GitTestRepo::default(); 1673 let test_repo = GitTestRepo::default();
1483 test_repo.populate()?; 1674 test_repo.populate()?;
1675 // create proposal branch
1484 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1676 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1485 1677 p.expect("fetching updates...\r\n")?;
1486 create_and_populate_branch( 1678 p.expect_eventually("\r\n")?; // some updates listed here
1487 &test_repo, 1679 let mut c = p.expect_choice(
1488 FEATURE_BRANCH_NAME_1, 1680 "all proposals",
1489 "a", 1681 vec![
1490 false, 1682 format!("\"{PROPOSAL_TITLE_3}\""),
1683 format!("\"{PROPOSAL_TITLE_2}\""),
1684 format!("\"{PROPOSAL_TITLE_1}\""),
1685 ],
1491 )?; 1686 )?;
1492 // add appended commit to local branch 1687 c.succeeds_with(2, true, None)?;
1493 std::fs::write(test_repo.dir.join("appended.md"), "some content")?; 1688 let mut c = p.expect_choice(
1494 test_repo.stage_and_commit("appended commit")?; 1689 "",
1690 vec![
1691 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1692 format!("apply to current branch with `git am`"),
1693 format!("download to ./patches"),
1694 format!("back"),
1695 ],
1696 )?;
1697 c.succeeds_with(0, false, Some(0))?;
1698 p.expect_end_eventually()?;
1495 1699
1700 // add another commit (so we have a local branch 1 ahead)
1701 std::fs::write(
1702 test_repo.dir.join("ammended-commit.md"),
1703 "some content",
1704 )?;
1705 test_repo.stage_and_commit("add ammended-commit.md")?;
1496 test_repo.checkout("main")?; 1706 test_repo.checkout("main")?;
1707
1708 // run test
1709 p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1497 p.expect("fetching updates...\r\n")?; 1710 p.expect("fetching updates...\r\n")?;
1498 p.expect_eventually("\r\n")?; // some updates listed here 1711 p.expect_eventually("\r\n")?; // some updates listed here
1499 let mut c = p.expect_choice( 1712 let mut c = p.expect_choice(
@@ -1545,7 +1758,7 @@ mod when_main_branch_is_uptodate {
1545 async fn proposal_branch_checked_out() -> Result<()> { 1758 async fn proposal_branch_checked_out() -> Result<()> {
1546 let (_, test_repo) = prep_and_run().await?; 1759 let (_, test_repo) = prep_and_run().await?;
1547 assert_eq!( 1760 assert_eq!(
1548 FEATURE_BRANCH_NAME_1, 1761 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?,
1549 test_repo.get_checked_out_branch_name()?, 1762 test_repo.get_checked_out_branch_name()?,
1550 ); 1763 );
1551 Ok(()) 1764 Ok(())
@@ -1556,7 +1769,10 @@ mod when_main_branch_is_uptodate {
1556 async fn didnt_overwrite_local_appendments() -> Result<()> { 1769 async fn didnt_overwrite_local_appendments() -> Result<()> {
1557 let (originating_repo, test_repo) = prep_and_run().await?; 1770 let (originating_repo, test_repo) = prep_and_run().await?;
1558 assert_ne!( 1771 assert_ne!(
1559 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1772 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
1773 &test_repo,
1774 FEATURE_BRANCH_NAME_1
1775 )?)?,
1560 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 1776 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
1561 ); 1777 );
1562 Ok(()) 1778 Ok(())
@@ -1592,7 +1808,34 @@ mod when_main_branch_is_uptodate {
1592 tokio::task::spawn_blocking(move || { 1808 tokio::task::spawn_blocking(move || {
1593 // create 3 proposals 1809 // create 3 proposals
1594 let _ = cli_tester_create_proposals()?; 1810 let _ = cli_tester_create_proposals()?;
1595 // get proposal id of first 1811 // download the origianl version of the first proposal
1812 let test_repo = GitTestRepo::default();
1813 test_repo.populate()?;
1814
1815 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1816 p.expect("fetching updates...\r\n")?;
1817 p.expect_eventually("\r\n")?; // some updates listed here
1818 let mut c = p.expect_choice(
1819 "all proposals",
1820 vec![
1821 format!("\"{PROPOSAL_TITLE_3}\""),
1822 format!("\"{PROPOSAL_TITLE_2}\""),
1823 format!("\"{PROPOSAL_TITLE_1}\""),
1824 ],
1825 )?;
1826 c.succeeds_with(2, true, None)?;
1827 let mut c = p.expect_choice(
1828 "",
1829 vec![
1830 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1831 format!("apply to current branch with `git am`"),
1832 format!("download to ./patches"),
1833 format!("back"),
1834 ],
1835 )?;
1836 c.succeeds_with(0, false, Some(0))?;
1837 p.expect_end_eventually()?;
1838
1596 // get proposal id of first 1839 // get proposal id of first
1597 let client = Client::default(); 1840 let client = Client::default();
1598 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?; 1841 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?;
@@ -1638,15 +1881,6 @@ mod when_main_branch_is_uptodate {
1638 Some(proposal_1_id.to_string()), 1881 Some(proposal_1_id.to_string()),
1639 )?; 1882 )?;
1640 1883
1641 // pretend we have downloaded the origianl version of the first proposal
1642 let test_repo = GitTestRepo::default();
1643 test_repo.populate()?;
1644 create_and_populate_branch(
1645 &test_repo,
1646 FEATURE_BRANCH_NAME_1,
1647 "a",
1648 false,
1649 )?;
1650 // pretend we have pulled the updated main branch 1884 // pretend we have pulled the updated main branch
1651 test_repo.checkout("main")?; 1885 test_repo.checkout("main")?;
1652 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; 1886 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
@@ -1724,6 +1958,34 @@ mod when_main_branch_is_uptodate {
1724 move || { 1958 move || {
1725 // create 3 proposals 1959 // create 3 proposals
1726 let _ = cli_tester_create_proposals()?; 1960 let _ = cli_tester_create_proposals()?;
1961 // download the origianl version of the first proposal
1962 let test_repo = GitTestRepo::default();
1963 test_repo.populate()?;
1964
1965 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1966 p.expect("fetching updates...\r\n")?;
1967 p.expect_eventually("\r\n")?; // some updates listed here
1968 let mut c = p.expect_choice(
1969 "all proposals",
1970 vec![
1971 format!("\"{PROPOSAL_TITLE_3}\""),
1972 format!("\"{PROPOSAL_TITLE_2}\""),
1973 format!("\"{PROPOSAL_TITLE_1}\""),
1974 ],
1975 )?;
1976 c.succeeds_with(2, true, None)?;
1977 let mut c = p.expect_choice(
1978 "",
1979 vec![
1980 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1981 format!("apply to current branch with `git am`"),
1982 format!("download to ./patches"),
1983 format!("back"),
1984 ],
1985 )?;
1986 c.succeeds_with(0, false, Some(0))?;
1987 p.expect_end_eventually()?;
1988
1727 // get proposal id of first 1989 // get proposal id of first
1728 let client = Client::default(); 1990 let client = Client::default();
1729 Handle::current() 1991 Handle::current()
@@ -1771,16 +2033,6 @@ mod when_main_branch_is_uptodate {
1771 Some(proposal_1_id.to_string()), 2033 Some(proposal_1_id.to_string()),
1772 )?; 2034 )?;
1773 2035
1774 // pretend we have downloaded the origianl version of the first
1775 // proposal
1776 let test_repo = GitTestRepo::default();
1777 test_repo.populate()?;
1778 create_and_populate_branch(
1779 &test_repo,
1780 FEATURE_BRANCH_NAME_1,
1781 "a",
1782 false,
1783 )?;
1784 // pretend we have pulled the updated main branch 2036 // pretend we have pulled the updated main branch
1785 test_repo.checkout("main")?; 2037 test_repo.checkout("main")?;
1786 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; 2038 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
@@ -1839,7 +2091,7 @@ mod when_main_branch_is_uptodate {
1839 async fn proposal_branch_checked_out() -> Result<()> { 2091 async fn proposal_branch_checked_out() -> Result<()> {
1840 let (_, test_repo) = prep_and_run().await?; 2092 let (_, test_repo) = prep_and_run().await?;
1841 assert_eq!( 2093 assert_eq!(
1842 FEATURE_BRANCH_NAME_1, 2094 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?,
1843 test_repo.get_checked_out_branch_name()?, 2095 test_repo.get_checked_out_branch_name()?,
1844 ); 2096 );
1845 Ok(()) 2097 Ok(())
@@ -1851,7 +2103,10 @@ mod when_main_branch_is_uptodate {
1851 let (originating_repo, test_repo) = prep_and_run().await?; 2103 let (originating_repo, test_repo) = prep_and_run().await?;
1852 assert_eq!( 2104 assert_eq!(
1853 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 2105 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
1854 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 2106 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
2107 &test_repo,
2108 FEATURE_BRANCH_NAME_1
2109 )?)?,
1855 ); 2110 );
1856 Ok(()) 2111 Ok(())
1857 } 2112 }