upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/list.rs744
-rw-r--r--tests/pull.rs188
-rw-r--r--tests/push.rs30
3 files changed, 119 insertions, 843 deletions
diff --git a/tests/list.rs b/tests/list.rs
index 60c9423..c92390b 100644
--- a/tests/list.rs
+++ b/tests/list.rs
@@ -1,132 +1,49 @@
1use anyhow::Result; 1use anyhow::Result;
2use futures::join; 2use futures::join;
3use nostr_sdk::client::Client;
4use serial_test::serial; 3use serial_test::serial;
5use test_utils::{git::GitTestRepo, relay::Relay, *}; 4use test_utils::{git::GitTestRepo, relay::Relay, *};
6 5
7static FEATURE_BRANCH_NAME_1: &str = "feature-example-t"; 6async fn prep_proposals_repo_and_repo_with_proposal_pulled_and_checkedout(
8static FEATURE_BRANCH_NAME_2: &str = "feature-example-f"; 7 proposal_number: u16,
9static FEATURE_BRANCH_NAME_3: &str = "feature-example-c"; 8) -> Result<(GitTestRepo, GitTestRepo)> {
10static FEATURE_BRANCH_NAME_4: &str = "feature-example-d"; 9 // fallback (51,52) user write (53, 55) repo (55, 56)
11 10 let (mut r51, mut r52, mut r53, mut r55, mut r56) = (
12static PROPOSAL_TITLE_1: &str = "proposal a"; 11 Relay::new(8051, None, None),
13static PROPOSAL_TITLE_2: &str = "proposal b"; 12 Relay::new(8052, None, None),
14static PROPOSAL_TITLE_3: &str = "proposal c"; 13 Relay::new(8053, None, None),
15 14 Relay::new(8055, None, None),
16fn cli_tester_create_proposals() -> Result<GitTestRepo> { 15 Relay::new(8056, None, None),
17 let git_repo = GitTestRepo::default(); 16 );
18 git_repo.populate()?; 17
19 cli_tester_create_proposal( 18 r51.events.push(generate_test_key_1_relay_list_event());
20 &git_repo, 19 r51.events.push(generate_test_key_1_metadata_event("fred"));
21 FEATURE_BRANCH_NAME_1, 20 r51.events.push(generate_repo_ref_event());
22 "a", 21
23 Some((PROPOSAL_TITLE_1, "proposal a description")), 22 r55.events.push(generate_repo_ref_event());
24 None, 23 r55.events.push(generate_test_key_1_metadata_event("fred"));
25 )?; 24 r55.events.push(generate_test_key_1_relay_list_event());
26 std::thread::sleep(std::time::Duration::from_millis(1000)); 25
27 cli_tester_create_proposal( 26 let cli_tester_handle = std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> {
28 &git_repo, 27 let (originating_repo, test_repo) =
29 FEATURE_BRANCH_NAME_2, 28 create_proposals_and_repo_with_proposal_pulled_and_checkedout(proposal_number)?;
30 "b", 29
31 Some((PROPOSAL_TITLE_2, "proposal b description")), 30 for p in [51, 52, 53, 55, 56] {
32 None, 31 relay::shutdown_relay(8000 + p)?;
33 )?; 32 }
34 std::thread::sleep(std::time::Duration::from_millis(1000)); 33 Ok((originating_repo, test_repo))
35 cli_tester_create_proposal( 34 });
36 &git_repo, 35
37 FEATURE_BRANCH_NAME_3, 36 // launch relay
38 "c", 37 let _ = join!(
39 Some((PROPOSAL_TITLE_3, "proposal c description")), 38 r51.listen_until_close(),
40 None, 39 r52.listen_until_close(),
41 )?; 40 r53.listen_until_close(),
42 Ok(git_repo) 41 r55.listen_until_close(),
43} 42 r56.listen_until_close(),
44 43 );
45fn create_and_populate_branch( 44 let res = cli_tester_handle.join().unwrap()?;
46 test_repo: &GitTestRepo, 45
47 branch_name: &str, 46 Ok(res)
48 prefix: &str,
49 only_one_commit: bool,
50) -> Result<()> {
51 test_repo.checkout("main")?;
52 test_repo.create_branch(branch_name)?;
53 test_repo.checkout(branch_name)?;
54 std::fs::write(
55 test_repo.dir.join(format!("{}3.md", prefix)),
56 "some content",
57 )?;
58 test_repo.stage_and_commit(format!("add {}3.md", prefix).as_str())?;
59 if !only_one_commit {
60 std::fs::write(
61 test_repo.dir.join(format!("{}4.md", prefix)),
62 "some content",
63 )?;
64 test_repo.stage_and_commit(format!("add {}4.md", prefix).as_str())?;
65 }
66 Ok(())
67}
68
69fn cli_tester_create_proposal(
70 test_repo: &GitTestRepo,
71 branch_name: &str,
72 prefix: &str,
73 cover_letter_title_and_description: Option<(&str, &str)>,
74 in_reply_to: Option<String>,
75) -> Result<()> {
76 create_and_populate_branch(test_repo, branch_name, prefix, false)?;
77 std::thread::sleep(std::time::Duration::from_millis(1000));
78 if let Some(in_reply_to) = in_reply_to {
79 let mut p = CliTester::new_from_dir(
80 &test_repo.dir,
81 [
82 "--nsec",
83 TEST_KEY_1_NSEC,
84 "--password",
85 TEST_PASSWORD,
86 "--disable-cli-spinners",
87 "send",
88 "HEAD~2",
89 "--no-cover-letter",
90 "--in-reply-to",
91 in_reply_to.as_str(),
92 ],
93 );
94 p.expect_end_eventually()?;
95 } else if let Some((title, description)) = cover_letter_title_and_description {
96 let mut p = CliTester::new_from_dir(
97 &test_repo.dir,
98 [
99 "--nsec",
100 TEST_KEY_1_NSEC,
101 "--password",
102 TEST_PASSWORD,
103 "--disable-cli-spinners",
104 "send",
105 "HEAD~2",
106 "--title",
107 format!("\"{title}\"").as_str(),
108 "--description",
109 format!("\"{description}\"").as_str(),
110 ],
111 );
112 p.expect_end_eventually()?;
113 } else {
114 let mut p = CliTester::new_from_dir(
115 &test_repo.dir,
116 [
117 "--nsec",
118 TEST_KEY_1_NSEC,
119 "--password",
120 TEST_PASSWORD,
121 "--disable-cli-spinners",
122 "send",
123 "HEAD~2",
124 "--no-cover-letter",
125 ],
126 );
127 p.expect_end_eventually()?;
128 }
129 Ok(())
130} 47}
131 48
132mod cannot_find_repo_event { 49mod cannot_find_repo_event {
@@ -228,76 +145,6 @@ mod when_main_branch_is_uptodate {
228 145
229 // TODO: test when other proposals with the same name but from other 146 // TODO: test when other proposals with the same name but from other
230 // repositories are present on relays 147 // repositories are present on relays
231 async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> {
232 // fallback (51,52) user write (53, 55) repo (55, 56)
233 let (mut r51, mut r52, mut r53, mut r55, mut r56) = (
234 Relay::new(8051, None, None),
235 Relay::new(8052, None, None),
236 Relay::new(8053, None, None),
237 Relay::new(8055, None, None),
238 Relay::new(8056, None, None),
239 );
240
241 r51.events.push(generate_test_key_1_relay_list_event());
242 r51.events.push(generate_test_key_1_metadata_event("fred"));
243 r51.events.push(generate_repo_ref_event());
244
245 r55.events.push(generate_repo_ref_event());
246 r55.events.push(generate_test_key_1_metadata_event("fred"));
247 r55.events.push(generate_test_key_1_relay_list_event());
248
249 let cli_tester_handle = std::thread::spawn(
250 move || -> Result<(GitTestRepo, GitTestRepo)> {
251 let originating_repo = cli_tester_create_proposals()?;
252
253 let test_repo = GitTestRepo::default();
254 test_repo.populate()?;
255 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
256
257 p.expect("fetching updates...\r\n")?;
258 p.expect_eventually("\r\n")?; // some updates listed here
259 let mut c = p.expect_choice(
260 "all proposals",
261 vec![
262 format!("\"{PROPOSAL_TITLE_3}\""),
263 format!("\"{PROPOSAL_TITLE_2}\""),
264 format!("\"{PROPOSAL_TITLE_1}\""),
265 ],
266 )?;
267 c.succeeds_with(2, true, None)?;
268
269 let mut c = p.expect_choice(
270 "",
271 vec![
272 format!(
273 "create and checkout proposal branch (2 ahead 0 behind 'main')" ),
274 format!("apply to current branch with `git am`"),
275 format!("download to ./patches"),
276 format!("back"),
277 ],
278 )?;
279 c.succeeds_with(0, false, Some(0))?;
280 p.expect_end_eventually_and_print()?;
281
282 for p in [51, 52, 53, 55, 56] {
283 relay::shutdown_relay(8000 + p)?;
284 }
285 Ok((originating_repo, test_repo))
286 },
287 );
288
289 // launch relay
290 let _ = join!(
291 r51.listen_until_close(),
292 r52.listen_until_close(),
293 r53.listen_until_close(),
294 r55.listen_until_close(),
295 r56.listen_until_close(),
296 );
297 let res = cli_tester_handle.join().unwrap()?;
298
299 Ok(res)
300 }
301 148
302 mod cli_prompts { 149 mod cli_prompts {
303 use super::*; 150 use super::*;
@@ -378,7 +225,8 @@ mod when_main_branch_is_uptodate {
378 #[tokio::test] 225 #[tokio::test]
379 #[serial] 226 #[serial]
380 async fn proposal_branch_created_with_correct_name() -> Result<()> { 227 async fn proposal_branch_created_with_correct_name() -> Result<()> {
381 let (_, test_repo) = prep_and_run().await?; 228 let (_, test_repo) =
229 prep_proposals_repo_and_repo_with_proposal_pulled_and_checkedout(1).await?;
382 assert_eq!( 230 assert_eq!(
383 vec![ 231 vec![
384 "main", 232 "main",
@@ -392,7 +240,8 @@ mod when_main_branch_is_uptodate {
392 #[tokio::test] 240 #[tokio::test]
393 #[serial] 241 #[serial]
394 async fn proposal_branch_checked_out() -> Result<()> { 242 async fn proposal_branch_checked_out() -> Result<()> {
395 let (_, test_repo) = prep_and_run().await?; 243 let (_, test_repo) =
244 prep_proposals_repo_and_repo_with_proposal_pulled_and_checkedout(1).await?;
396 assert_eq!( 245 assert_eq!(
397 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?, 246 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_1)?,
398 test_repo.get_checked_out_branch_name()?, 247 test_repo.get_checked_out_branch_name()?,
@@ -403,7 +252,8 @@ mod when_main_branch_is_uptodate {
403 #[tokio::test] 252 #[tokio::test]
404 #[serial] 253 #[serial]
405 async fn proposal_branch_tip_is_most_recent_patch() -> Result<()> { 254 async fn proposal_branch_tip_is_most_recent_patch() -> Result<()> {
406 let (originating_repo, test_repo) = prep_and_run().await?; 255 let (originating_repo, test_repo) =
256 prep_proposals_repo_and_repo_with_proposal_pulled_and_checkedout(1).await?;
407 assert_eq!( 257 assert_eq!(
408 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, 258 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
409 test_repo.get_tip_of_local_branch(&get_proposal_branch_name( 259 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
@@ -417,77 +267,6 @@ mod when_main_branch_is_uptodate {
417 mod when_third_proposal_selected { 267 mod when_third_proposal_selected {
418 use super::*; 268 use super::*;
419 269
420 async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> {
421 // fallback (51,52) user write (53, 55) repo (55, 56)
422 let (mut r51, mut r52, mut r53, mut r55, mut r56) = (
423 Relay::new(8051, None, None),
424 Relay::new(8052, None, None),
425 Relay::new(8053, None, None),
426 Relay::new(8055, None, None),
427 Relay::new(8056, None, None),
428 );
429
430 r51.events.push(generate_test_key_1_relay_list_event());
431 r51.events.push(generate_test_key_1_metadata_event("fred"));
432 r51.events.push(generate_repo_ref_event());
433
434 r55.events.push(generate_repo_ref_event());
435 r55.events.push(generate_test_key_1_metadata_event("fred"));
436 r55.events.push(generate_test_key_1_relay_list_event());
437
438 let cli_tester_handle = std::thread::spawn(
439 move || -> Result<(GitTestRepo, GitTestRepo)> {
440 let originating_repo = cli_tester_create_proposals()?;
441
442 let test_repo = GitTestRepo::default();
443 test_repo.populate()?;
444 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
445
446 p.expect("fetching updates...\r\n")?;
447 p.expect_eventually("\r\n")?; // some updates listed here
448 let mut c = p.expect_choice(
449 "all proposals",
450 vec![
451 format!("\"{PROPOSAL_TITLE_3}\""),
452 format!("\"{PROPOSAL_TITLE_2}\""),
453 format!("\"{PROPOSAL_TITLE_1}\""),
454 ],
455 )?;
456 c.succeeds_with(0, true, None)?;
457
458 let mut c = p.expect_choice(
459 "",
460 vec![
461 format!(
462 "create and checkout proposal branch (2 ahead 0 behind 'main')" ),
463 format!("apply to current branch with `git am`"),
464 format!("download to ./patches"),
465 format!("back"),
466 ],
467 )?;
468 c.succeeds_with(0, false, Some(0))?;
469 p.expect_end_eventually_and_print()?;
470
471 for p in [51, 52, 53, 55, 56] {
472 relay::shutdown_relay(8000 + p)?;
473 }
474 Ok((originating_repo, test_repo))
475 },
476 );
477
478 // launch relay
479 let _ = join!(
480 r51.listen_until_close(),
481 r52.listen_until_close(),
482 r53.listen_until_close(),
483 r55.listen_until_close(),
484 r56.listen_until_close(),
485 );
486 let res = cli_tester_handle.join().unwrap()?;
487
488 Ok(res)
489 }
490
491 mod cli_prompts { 270 mod cli_prompts {
492 use super::*; 271 use super::*;
493 272
@@ -568,7 +347,8 @@ mod when_main_branch_is_uptodate {
568 #[tokio::test] 347 #[tokio::test]
569 #[serial] 348 #[serial]
570 async fn proposal_branch_created_with_correct_name() -> Result<()> { 349 async fn proposal_branch_created_with_correct_name() -> Result<()> {
571 let (_, test_repo) = prep_and_run().await?; 350 let (_, test_repo) =
351 prep_proposals_repo_and_repo_with_proposal_pulled_and_checkedout(3).await?;
572 assert_eq!( 352 assert_eq!(
573 vec![ 353 vec![
574 "main", 354 "main",
@@ -582,7 +362,8 @@ mod when_main_branch_is_uptodate {
582 #[tokio::test] 362 #[tokio::test]
583 #[serial] 363 #[serial]
584 async fn proposal_branch_checked_out() -> Result<()> { 364 async fn proposal_branch_checked_out() -> Result<()> {
585 let (_, test_repo) = prep_and_run().await?; 365 let (_, test_repo) =
366 prep_proposals_repo_and_repo_with_proposal_pulled_and_checkedout(3).await?;
586 assert_eq!( 367 assert_eq!(
587 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_3)?, 368 get_proposal_branch_name(&test_repo, FEATURE_BRANCH_NAME_3)?,
588 test_repo.get_checked_out_branch_name()?, 369 test_repo.get_checked_out_branch_name()?,
@@ -593,7 +374,8 @@ mod when_main_branch_is_uptodate {
593 #[tokio::test] 374 #[tokio::test]
594 #[serial] 375 #[serial]
595 async fn proposal_branch_tip_is_most_recent_patch() -> Result<()> { 376 async fn proposal_branch_tip_is_most_recent_patch() -> Result<()> {
596 let (originating_repo, test_repo) = prep_and_run().await?; 377 let (originating_repo, test_repo) =
378 prep_proposals_repo_and_repo_with_proposal_pulled_and_checkedout(3).await?;
597 assert_eq!( 379 assert_eq!(
598 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_3)?, 380 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_3)?,
599 test_repo.get_tip_of_local_branch(&get_proposal_branch_name( 381 test_repo.get_tip_of_local_branch(&get_proposal_branch_name(
@@ -1051,47 +833,15 @@ mod when_main_branch_is_uptodate {
1051 833
1052 let cli_tester_handle = std::thread::spawn( 834 let cli_tester_handle = std::thread::spawn(
1053 move || -> Result<(GitTestRepo, GitTestRepo)> { 835 move || -> Result<(GitTestRepo, GitTestRepo)> {
1054 let originating_repo = cli_tester_create_proposals()?; 836 let (originating_repo, test_repo) =
1055 let test_repo = GitTestRepo::default(); 837 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
1056 test_repo.populate()?;
1057 // create proposal branch
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()?;
1081 838
1082 // remove latest commit so it is behind 839 remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main(
1083 let branch_name = test_repo.get_checked_out_branch_name()?; 840 &test_repo,
1084 test_repo.checkout("main")?;
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)?,
1091 true,
1092 )?; 841 )?;
842
1093 // run test 843 // run test
1094 p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 844 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1095 p.expect("fetching updates...\r\n")?; 845 p.expect("fetching updates...\r\n")?;
1096 p.expect_eventually("\r\n")?; // some updates listed here 846 p.expect_eventually("\r\n")?; // some updates listed here
1097 let mut c = p.expect_choice( 847 let mut c = p.expect_choice(
@@ -1159,48 +909,15 @@ mod when_main_branch_is_uptodate {
1159 r55.events.push(generate_test_key_1_relay_list_event()); 909 r55.events.push(generate_test_key_1_relay_list_event());
1160 910
1161 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 911 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
1162 cli_tester_create_proposals()?; 912 let (_, test_repo) =
913 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
1163 914
1164 let test_repo = GitTestRepo::default(); 915 remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main(
1165 test_repo.populate()?; 916 &test_repo,
1166 // create proposal branch
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 )?; 917 )?;
1188 c.succeeds_with(0, false, Some(0))?;
1189 p.expect_end_eventually()?;
1190 918
1191 // remove latest commit so it is behind
1192 let branch_name = test_repo.get_checked_out_branch_name()?;
1193 test_repo.checkout("main")?;
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)?,
1200 true,
1201 )?;
1202 // run test 919 // run test
1203 p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 920 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1204 p.expect("fetching updates...\r\n")?; 921 p.expect("fetching updates...\r\n")?;
1205 p.expect_eventually("\r\n")?; // some updates listed here 922 p.expect_eventually("\r\n")?; // some updates listed here
1206 let mut c = p.expect_choice( 923 let mut c = p.expect_choice(
@@ -1292,48 +1009,17 @@ mod when_main_branch_is_uptodate {
1292 r55.events.push(generate_test_key_1_metadata_event("fred")); 1009 r55.events.push(generate_test_key_1_metadata_event("fred"));
1293 r55.events.push(generate_test_key_1_relay_list_event()); 1010 r55.events.push(generate_test_key_1_relay_list_event());
1294 1011
1295 let cli_tester_handle = std::thread::spawn( 1012 let cli_tester_handle =
1296 move || -> Result<(GitTestRepo, GitTestRepo)> { 1013 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> {
1297 let originating_repo = cli_tester_create_proposals()?; 1014 let (originating_repo, test_repo) =
1015 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
1298 1016
1299 let test_repo = GitTestRepo::default();
1300 test_repo.populate()?;
1301 // create proposal branch
1302 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1303 p.expect("fetching updates...\r\n")?;
1304 p.expect_eventually("\r\n")?; // some updates listed here
1305 let mut c = p.expect_choice(
1306 "all proposals",
1307 vec![
1308 format!("\"{PROPOSAL_TITLE_3}\""),
1309 format!("\"{PROPOSAL_TITLE_2}\""),
1310 format!("\"{PROPOSAL_TITLE_1}\""),
1311 ],
1312 )?;
1313 c.succeeds_with(2, true, None)?;
1314 let mut c = p.expect_choice(
1315 "",
1316 vec![
1317 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1318 format!("apply to current branch with `git am`"),
1319 format!("download to ./patches"),
1320 format!("back"),
1321 ],
1322 )?;
1323 c.succeeds_with(0, false, Some(0))?;
1324 p.expect_end_eventually()?;
1325
1326 // remove latest commit so it is behind
1327 let branch_name = test_repo.get_checked_out_branch_name()?; 1017 let branch_name = test_repo.get_checked_out_branch_name()?;
1328 test_repo.checkout("main")?; 1018
1329 test_repo.git_repo.branch( 1019 remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main(
1330 &branch_name, 1020 &test_repo,
1331 &test_repo
1332 .git_repo
1333 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
1334 .parent(0)?,
1335 true,
1336 )?; 1021 )?;
1022
1337 // add another commit (so we have an ammened local branch) 1023 // add another commit (so we have an ammened local branch)
1338 test_repo.checkout(&branch_name)?; 1024 test_repo.checkout(&branch_name)?;
1339 std::fs::write( 1025 std::fs::write(
@@ -1344,7 +1030,7 @@ mod when_main_branch_is_uptodate {
1344 test_repo.checkout("main")?; 1030 test_repo.checkout("main")?;
1345 1031
1346 // run test 1032 // run test
1347 p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1033 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1348 p.expect("fetching updates...\r\n")?; 1034 p.expect("fetching updates...\r\n")?;
1349 p.expect_eventually("\r\n")?; // some updates listed here 1035 p.expect_eventually("\r\n")?; // some updates listed here
1350 let mut c = p.expect_choice( 1036 let mut c = p.expect_choice(
@@ -1378,8 +1064,7 @@ mod when_main_branch_is_uptodate {
1378 relay::shutdown_relay(8000 + p)?; 1064 relay::shutdown_relay(8000 + p)?;
1379 } 1065 }
1380 Ok((originating_repo, test_repo)) 1066 Ok((originating_repo, test_repo))
1381 }, 1067 });
1382 );
1383 // launch relay 1068 // launch relay
1384 let _ = join!( 1069 let _ = join!(
1385 r51.listen_until_close(), 1070 r51.listen_until_close(),
@@ -1417,57 +1102,13 @@ mod when_main_branch_is_uptodate {
1417 r55.events.push(generate_test_key_1_relay_list_event()); 1102 r55.events.push(generate_test_key_1_relay_list_event());
1418 1103
1419 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 1104 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
1420 cli_tester_create_proposals()?; 1105 let (_, test_repo) =
1106 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
1421 1107
1422 let test_repo = GitTestRepo::default(); 1108 ammend_last_commit_and_checkout_main(&test_repo)?;
1423 test_repo.populate()?;
1424 // create proposal branch
1425 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1426 p.expect("fetching updates...\r\n")?;
1427 p.expect_eventually("\r\n")?; // some updates listed here
1428 let mut c = p.expect_choice(
1429 "all proposals",
1430 vec![
1431 format!("\"{PROPOSAL_TITLE_3}\""),
1432 format!("\"{PROPOSAL_TITLE_2}\""),
1433 format!("\"{PROPOSAL_TITLE_1}\""),
1434 ],
1435 )?;
1436 c.succeeds_with(2, true, None)?;
1437 let mut c = p.expect_choice(
1438 "",
1439 vec![
1440 format!("create and checkout proposal branch (2 ahead 0 behind 'main')"),
1441 format!("apply to current branch with `git am`"),
1442 format!("download to ./patches"),
1443 format!("back"),
1444 ],
1445 )?;
1446 c.succeeds_with(0, false, Some(0))?;
1447 p.expect_end_eventually()?;
1448
1449 // remove latest commit so it is behind
1450 let branch_name = test_repo.get_checked_out_branch_name()?;
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 1109
1469 // run test 1110 // run test
1470 p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1111 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1471 p.expect("fetching updates...\r\n")?; 1112 p.expect("fetching updates...\r\n")?;
1472 p.expect_eventually("\r\n")?; // some updates listed here 1113 p.expect_eventually("\r\n")?; // some updates listed here
1473 let mut c = p.expect_choice( 1114 let mut c = p.expect_choice(
@@ -1560,34 +1201,8 @@ mod when_main_branch_is_uptodate {
1560 1201
1561 let cli_tester_handle = std::thread::spawn( 1202 let cli_tester_handle = std::thread::spawn(
1562 move || -> Result<(GitTestRepo, GitTestRepo)> { 1203 move || -> Result<(GitTestRepo, GitTestRepo)> {
1563 let originating_repo = cli_tester_create_proposals()?; 1204 let (originating_repo, test_repo) =
1564 1205 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
1565 let test_repo = GitTestRepo::default();
1566 test_repo.populate()?;
1567 // create proposal branch
1568 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1569 p.expect("fetching updates...\r\n")?;
1570 p.expect_eventually("\r\n")?; // some updates listed here
1571 let mut c = p.expect_choice(
1572 "all proposals",
1573 vec![
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 ],
1588 )?;
1589 c.succeeds_with(0, false, Some(0))?;
1590 p.expect_end_eventually()?;
1591 1206
1592 // add another commit (so we have a local branch 1 ahead) 1207 // add another commit (so we have a local branch 1 ahead)
1593 std::fs::write( 1208 std::fs::write(
@@ -1598,7 +1213,7 @@ mod when_main_branch_is_uptodate {
1598 test_repo.checkout("main")?; 1213 test_repo.checkout("main")?;
1599 1214
1600 // run test 1215 // run test
1601 p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1216 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1602 p.expect("fetching updates...\r\n")?; 1217 p.expect("fetching updates...\r\n")?;
1603 p.expect_eventually("\r\n")?; // some updates listed here 1218 p.expect_eventually("\r\n")?; // some updates listed here
1604 let mut c = p.expect_choice( 1219 let mut c = p.expect_choice(
@@ -1668,34 +1283,8 @@ mod when_main_branch_is_uptodate {
1668 r55.events.push(generate_test_key_1_relay_list_event()); 1283 r55.events.push(generate_test_key_1_relay_list_event());
1669 1284
1670 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 1285 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
1671 cli_tester_create_proposals()?; 1286 let (_, test_repo) =
1672 1287 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
1673 let test_repo = GitTestRepo::default();
1674 test_repo.populate()?;
1675 // create proposal branch
1676 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1677 p.expect("fetching updates...\r\n")?;
1678 p.expect_eventually("\r\n")?; // some updates listed here
1679 let mut c = p.expect_choice(
1680 "all proposals",
1681 vec![
1682 format!("\"{PROPOSAL_TITLE_3}\""),
1683 format!("\"{PROPOSAL_TITLE_2}\""),
1684 format!("\"{PROPOSAL_TITLE_1}\""),
1685 ],
1686 )?;
1687 c.succeeds_with(2, true, None)?;
1688 let mut c = p.expect_choice(
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()?;
1699 1288
1700 // add another commit (so we have a local branch 1 ahead) 1289 // add another commit (so we have a local branch 1 ahead)
1701 std::fs::write( 1290 std::fs::write(
@@ -1706,7 +1295,7 @@ mod when_main_branch_is_uptodate {
1706 test_repo.checkout("main")?; 1295 test_repo.checkout("main")?;
1707 1296
1708 // run test 1297 // run test
1709 p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1298 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1710 p.expect("fetching updates...\r\n")?; 1299 p.expect("fetching updates...\r\n")?;
1711 p.expect_eventually("\r\n")?; // some updates listed here 1300 p.expect_eventually("\r\n")?; // some updates listed here
1712 let mut c = p.expect_choice( 1301 let mut c = p.expect_choice(
@@ -1780,9 +1369,8 @@ mod when_main_branch_is_uptodate {
1780 } 1369 }
1781 1370
1782 mod when_latest_revision_rebases_branch { 1371 mod when_latest_revision_rebases_branch {
1783 use std::time::Duration;
1784 1372
1785 use tokio::{runtime::Handle, task::JoinHandle}; 1373 use tokio::task::JoinHandle;
1786 1374
1787 use super::*; 1375 use super::*;
1788 1376
@@ -1806,85 +1394,8 @@ mod when_main_branch_is_uptodate {
1806 1394
1807 let cli_tester_handle: JoinHandle<Result<(GitTestRepo, GitTestRepo)>> = 1395 let cli_tester_handle: JoinHandle<Result<(GitTestRepo, GitTestRepo)>> =
1808 tokio::task::spawn_blocking(move || { 1396 tokio::task::spawn_blocking(move || {
1809 // create 3 proposals 1397 let (originating_repo, test_repo) = create_proposals_with_first_rebased_and_repo_with_latest_main_and_unrebased_proposal()?;
1810 let _ = cli_tester_create_proposals()?;
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
1839 // get proposal id of first
1840 let client = Client::default();
1841 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?;
1842 Handle::current()
1843 .block_on(client.connect_relay("ws://localhost:8055"))?;
1844 let proposals = Handle::current().block_on(client.get_events_of(
1845 vec![
1846 nostr::Filter::default()
1847 .kind(nostr::Kind::Custom(PATCH_KIND))
1848 .custom_tag(
1849 nostr::SingleLetterTag::lowercase(nostr::Alphabet::T),
1850 vec!["root"],
1851 ),
1852 ],
1853 Some(Duration::from_millis(500)),
1854 ))?;
1855 Handle::current().block_on(client.disconnect())?;
1856
1857 let proposal_1_id = proposals
1858 .iter()
1859 .find(|e| {
1860 e.tags
1861 .iter()
1862 .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1))
1863 })
1864 .unwrap()
1865 .id;
1866 // recreate proposal 1 on top of a another commit (like a rebase on top
1867 // of one extra commit)
1868 let second_originating_repo = GitTestRepo::default();
1869 second_originating_repo.populate()?;
1870 std::fs::write(
1871 second_originating_repo.dir.join("amazing.md"),
1872 "some content",
1873 )?;
1874 second_originating_repo
1875 .stage_and_commit("commit for rebasing on top of")?;
1876 cli_tester_create_proposal(
1877 &second_originating_repo,
1878 FEATURE_BRANCH_NAME_1,
1879 "a",
1880 Some((PROPOSAL_TITLE_1, "proposal a description")),
1881 Some(proposal_1_id.to_string()),
1882 )?;
1883
1884 // pretend we have pulled the updated main branch
1885 test_repo.checkout("main")?; 1398 test_repo.checkout("main")?;
1886 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
1887 test_repo.stage_and_commit("commit for rebasing on top of")?;
1888 1399
1889 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1400 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1890 p.expect("fetching updates...\r\n")?; 1401 p.expect("fetching updates...\r\n")?;
@@ -1916,7 +1427,7 @@ mod when_main_branch_is_uptodate {
1916 for p in [51, 52, 53, 55, 56] { 1427 for p in [51, 52, 53, 55, 56] {
1917 relay::shutdown_relay(8000 + p)?; 1428 relay::shutdown_relay(8000 + p)?;
1918 } 1429 }
1919 Ok((second_originating_repo, test_repo)) 1430 Ok((originating_repo, test_repo))
1920 }); 1431 });
1921 1432
1922 // launch relay 1433 // launch relay
@@ -1956,87 +1467,8 @@ mod when_main_branch_is_uptodate {
1956 1467
1957 let cli_tester_handle: JoinHandle<Result<()>> = tokio::task::spawn_blocking( 1468 let cli_tester_handle: JoinHandle<Result<()>> = tokio::task::spawn_blocking(
1958 move || { 1469 move || {
1959 // create 3 proposals 1470 let (_, test_repo) = create_proposals_with_first_rebased_and_repo_with_latest_main_and_unrebased_proposal()?;
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
1989 // get proposal id of first
1990 let client = Client::default();
1991 Handle::current()
1992 .block_on(client.add_relay("ws://localhost:8055"))?;
1993 Handle::current()
1994 .block_on(client.connect_relay("ws://localhost:8055"))?;
1995 let proposals =
1996 Handle::current().block_on(client.get_events_of(
1997 vec![
1998 nostr::Filter::default()
1999 .kind(nostr::Kind::Custom(PATCH_KIND))
2000 .custom_tag(
2001 nostr::SingleLetterTag::lowercase(nostr::Alphabet::T),
2002 vec!["root"],
2003 ),
2004 ],
2005 Some(Duration::from_millis(500)),
2006 ))?;
2007 Handle::current().block_on(client.disconnect())?;
2008
2009 let proposal_1_id = proposals
2010 .iter()
2011 .find(|e| {
2012 e.tags
2013 .iter()
2014 .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1))
2015 })
2016 .unwrap()
2017 .id;
2018 // recreate proposal 1 on top of a another commit (like a rebase on
2019 // top of one extra commit)
2020 let second_originating_repo = GitTestRepo::default();
2021 second_originating_repo.populate()?;
2022 std::fs::write(
2023 second_originating_repo.dir.join("amazing.md"),
2024 "some content",
2025 )?;
2026 second_originating_repo
2027 .stage_and_commit("commit for rebasing on top of")?;
2028 cli_tester_create_proposal(
2029 &second_originating_repo,
2030 FEATURE_BRANCH_NAME_1,
2031 "a",
2032 Some((PROPOSAL_TITLE_1, "proposal a description")),
2033 Some(proposal_1_id.to_string()),
2034 )?;
2035
2036 // pretend we have pulled the updated main branch
2037 test_repo.checkout("main")?; 1471 test_repo.checkout("main")?;
2038 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
2039 test_repo.stage_and_commit("commit for rebasing on top of")?;
2040 1472
2041 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1473 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
2042 p.expect("fetching updates...\r\n")?; 1474 p.expect("fetching updates...\r\n")?;
diff --git a/tests/pull.rs b/tests/pull.rs
index 70319bd..89b28c3 100644
--- a/tests/pull.rs
+++ b/tests/pull.rs
@@ -31,7 +31,7 @@ mod when_main_is_checked_out {
31 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 31 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
32 cli_tester_create_proposals()?; 32 cli_tester_create_proposals()?;
33 33
34 let test_repo = create_repo_with_first_proposal_branch_pulled_and_checkedout()?; 34 let test_repo = create_repo_with_proposal_branch_pulled_and_checkedout(1)?;
35 35
36 test_repo.checkout("main")?; 36 test_repo.checkout("main")?;
37 37
@@ -149,7 +149,7 @@ mod when_branch_is_checked_out {
149 149
150 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 150 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
151 let (_, test_repo) = 151 let (_, test_repo) =
152 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 152 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
153 153
154 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 154 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
155 p.expect("fetching updates...\r\n")?; 155 p.expect("fetching updates...\r\n")?;
@@ -201,18 +201,10 @@ mod when_branch_is_checked_out {
201 let cli_tester_handle = 201 let cli_tester_handle =
202 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { 202 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> {
203 let (originating_repo, test_repo) = 203 let (originating_repo, test_repo) =
204 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 204 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
205 205
206 // remove latest commit so it is behind 206 remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main(
207 let branch_name = test_repo.get_checked_out_branch_name()?; 207 &test_repo,
208 test_repo.checkout("main")?;
209 test_repo.git_repo.branch(
210 &branch_name,
211 &test_repo
212 .git_repo
213 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
214 .parent(0)?,
215 true,
216 )?; 208 )?;
217 209
218 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 210 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
@@ -263,18 +255,10 @@ mod when_branch_is_checked_out {
263 let cli_tester_handle = 255 let cli_tester_handle =
264 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { 256 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> {
265 let (originating_repo, test_repo) = 257 let (originating_repo, test_repo) =
266 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 258 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
267 259
268 // remove latest commit so it is behind 260 remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main(
269 let branch_name = test_repo.get_checked_out_branch_name()?; 261 &test_repo,
270 test_repo.checkout("main")?;
271 test_repo.git_repo.branch(
272 &branch_name,
273 &test_repo
274 .git_repo
275 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
276 .parent(0)?,
277 true,
278 )?; 262 )?;
279 263
280 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 264 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
@@ -344,24 +328,9 @@ mod when_branch_is_checked_out {
344 328
345 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 329 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
346 let (originating_repo, test_repo) = 330 let (originating_repo, test_repo) =
347 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 331 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
348 332
349 // remove latest commit so it is behind 333 let branch_name = ammend_last_commit_and_checkout_main(&test_repo)?;
350 let branch_name = test_repo.get_checked_out_branch_name()?;
351 test_repo.checkout("main")?;
352 test_repo.git_repo.branch(
353 &branch_name,
354 &test_repo
355 .git_repo
356 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
357 .parent(0)?,
358 true,
359 )?;
360 // add another commit (so we have an ammened local branch)
361 test_repo.checkout(&branch_name)?;
362 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
363 test_repo.stage_and_commit("add ammended-commit.md")?;
364 test_repo.checkout("main")?;
365 334
366 // create and send a revision from another repository 335 // create and send a revision from another repository
367 originating_repo.checkout("main")?; 336 originating_repo.checkout("main")?;
@@ -443,24 +412,9 @@ mod when_branch_is_checked_out {
443 412
444 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 413 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
445 let (_, test_repo) = 414 let (_, test_repo) =
446 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 415 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
447 416
448 // remove latest commit so it is behind 417 ammend_last_commit_and_checkout_main(&test_repo)?;
449 let branch_name = test_repo.get_checked_out_branch_name()?;
450 test_repo.checkout("main")?;
451 test_repo.git_repo.branch(
452 &branch_name,
453 &test_repo
454 .git_repo
455 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
456 .parent(0)?,
457 true,
458 )?;
459 // add another commit (so we have an ammened local branch)
460 test_repo.checkout(&branch_name)?;
461 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
462 test_repo.stage_and_commit("add ammended-commit.md")?;
463 test_repo.checkout("main")?;
464 418
465 // run test 419 // run test
466 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 420 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
@@ -520,7 +474,7 @@ mod when_branch_is_checked_out {
520 let cli_tester_handle = std::thread::spawn( 474 let cli_tester_handle = std::thread::spawn(
521 move || -> Result<(GitTestRepo, GitTestRepo)> { 475 move || -> Result<(GitTestRepo, GitTestRepo)> {
522 let (originating_repo, test_repo) = 476 let (originating_repo, test_repo) =
523 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 477 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
524 478
525 // add another commit (so we have a local branch 1 ahead) 479 // add another commit (so we have a local branch 1 ahead)
526 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; 480 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
@@ -578,7 +532,7 @@ mod when_branch_is_checked_out {
578 532
579 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 533 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
580 let (_, test_repo) = 534 let (_, test_repo) =
581 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 535 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
582 536
583 // add another commit (so we have a local branch 1 ahead) 537 // add another commit (so we have a local branch 1 ahead)
584 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; 538 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
@@ -627,10 +581,7 @@ mod when_branch_is_checked_out {
627 } 581 }
628 } 582 }
629 mod when_latest_event_rebases_branch { 583 mod when_latest_event_rebases_branch {
630 use std::time::Duration; 584 use tokio::task::JoinHandle;
631
632 use nostr_sdk::Client;
633 use tokio::{runtime::Handle, task::JoinHandle};
634 585
635 use super::*; 586 use super::*;
636 587
@@ -654,57 +605,7 @@ mod when_branch_is_checked_out {
654 605
655 let cli_tester_handle: JoinHandle<Result<(GitTestRepo, GitTestRepo)>> = 606 let cli_tester_handle: JoinHandle<Result<(GitTestRepo, GitTestRepo)>> =
656 tokio::task::spawn_blocking(move || { 607 tokio::task::spawn_blocking(move || {
657 let (_, test_repo) = 608 let (originating_repo, test_repo) = create_proposals_with_first_rebased_and_repo_with_latest_main_and_unrebased_proposal()?;
658 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?;
659
660 // get proposal id of first
661 let client = Client::default();
662 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?;
663 Handle::current().block_on(client.connect_relay("ws://localhost:8055"))?;
664 let proposals = Handle::current().block_on(client.get_events_of(
665 vec![
666 nostr::Filter::default()
667 .kind(nostr::Kind::Custom(PATCH_KIND))
668 .custom_tag(
669 nostr::SingleLetterTag::lowercase(nostr::Alphabet::T),
670 vec!["root"],
671 ),
672 ],
673 Some(Duration::from_millis(500)),
674 ))?;
675 Handle::current().block_on(client.disconnect())?;
676
677 let proposal_1_id = proposals
678 .iter()
679 .find(|e| {
680 e.tags
681 .iter()
682 .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1))
683 })
684 .unwrap()
685 .id;
686 // recreate proposal 1 on top of a another commit (like a rebase on top
687 // of one extra commit)
688 let second_originating_repo = GitTestRepo::default();
689 second_originating_repo.populate()?;
690 std::fs::write(
691 second_originating_repo.dir.join("amazing.md"),
692 "some content",
693 )?;
694 second_originating_repo.stage_and_commit("commit for rebasing on top of")?;
695 cli_tester_create_proposal(
696 &second_originating_repo,
697 FEATURE_BRANCH_NAME_1,
698 "a",
699 Some((PROPOSAL_TITLE_1, "proposal a description")),
700 Some(proposal_1_id.to_string()),
701 )?;
702
703 // pretend we have pulled the updated main branch
704 test_repo.checkout("main")?;
705 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
706 test_repo.stage_and_commit("commit for rebasing on top of")?;
707 test_repo.checkout(FEATURE_BRANCH_NAME_1)?;
708 609
709 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 610 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
710 p.expect_end_eventually_and_print()?; 611 p.expect_end_eventually_and_print()?;
@@ -712,7 +613,7 @@ mod when_branch_is_checked_out {
712 for p in [51, 52, 53, 55, 56] { 613 for p in [51, 52, 53, 55, 56] {
713 relay::shutdown_relay(8000 + p)?; 614 relay::shutdown_relay(8000 + p)?;
714 } 615 }
715 Ok((second_originating_repo, test_repo)) 616 Ok((originating_repo, test_repo))
716 }); 617 });
717 618
718 // launch relay 619 // launch relay
@@ -752,58 +653,7 @@ mod when_branch_is_checked_out {
752 653
753 let cli_tester_handle: JoinHandle<Result<()>> = tokio::task::spawn_blocking( 654 let cli_tester_handle: JoinHandle<Result<()>> = tokio::task::spawn_blocking(
754 move || { 655 move || {
755 let (_, test_repo) = 656 let (_, test_repo) = create_proposals_with_first_rebased_and_repo_with_latest_main_and_unrebased_proposal()?;
756 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?;
757
758 // get proposal id of first
759 let client = Client::default();
760 Handle::current().block_on(client.add_relay("ws://localhost:8055"))?;
761 Handle::current().block_on(client.connect_relay("ws://localhost:8055"))?;
762 let proposals = Handle::current().block_on(client.get_events_of(
763 vec![
764 nostr::Filter::default()
765 .kind(nostr::Kind::Custom(PATCH_KIND))
766 .custom_tag(
767 nostr::SingleLetterTag::lowercase(nostr::Alphabet::T),
768 vec!["root"],
769 ),
770 ],
771 Some(Duration::from_millis(500)),
772 ))?;
773 Handle::current().block_on(client.disconnect())?;
774
775 let proposal_1_id = proposals
776 .iter()
777 .find(|e| {
778 e.tags
779 .iter()
780 .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1))
781 })
782 .unwrap()
783 .id;
784 // recreate proposal 1 on top of a another commit (like a rebase on top
785 // of one extra commit)
786 let second_originating_repo = GitTestRepo::default();
787 second_originating_repo.populate()?;
788 std::fs::write(
789 second_originating_repo.dir.join("amazing.md"),
790 "some content",
791 )?;
792 second_originating_repo
793 .stage_and_commit("commit for rebasing on top of")?;
794 cli_tester_create_proposal(
795 &second_originating_repo,
796 FEATURE_BRANCH_NAME_1,
797 "a",
798 Some((PROPOSAL_TITLE_1, "proposal a description")),
799 Some(proposal_1_id.to_string()),
800 )?;
801
802 // pretend we have pulled the updated main branch
803 test_repo.checkout("main")?;
804 std::fs::write(test_repo.dir.join("amazing.md"), "some content")?;
805 test_repo.stage_and_commit("commit for rebasing on top of")?;
806 test_repo.checkout(FEATURE_BRANCH_NAME_1)?;
807 657
808 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); 658 let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]);
809 p.expect("fetching updates...\r\n")?; 659 p.expect("fetching updates...\r\n")?;
diff --git a/tests/push.rs b/tests/push.rs
index e300fe2..8ef7a30 100644
--- a/tests/push.rs
+++ b/tests/push.rs
@@ -109,7 +109,7 @@ mod when_branch_is_checked_out {
109 109
110 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 110 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
111 let (_, test_repo) = 111 let (_, test_repo) =
112 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 112 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
113 113
114 let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]); 114 let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]);
115 p.expect("fetching updates...\r\n")?; 115 p.expect("fetching updates...\r\n")?;
@@ -163,19 +163,13 @@ mod when_branch_is_checked_out {
163 163
164 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 164 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
165 let (_, test_repo) = 165 let (_, test_repo) =
166 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 166 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
167 167
168 // remove latest commit so it is behind 168 let branch_name =
169 let branch_name = test_repo.get_checked_out_branch_name()?; 169 remove_latest_commit_so_proposal_branch_is_behind_and_checkout_main(
170 test_repo.checkout("main")?; 170 &test_repo,
171 test_repo.git_repo.branch( 171 )?;
172 &branch_name, 172
173 &test_repo
174 .git_repo
175 .find_commit(test_repo.get_tip_of_local_branch(&branch_name)?)?
176 .parent(0)?,
177 true,
178 )?;
179 test_repo.checkout(&branch_name)?; 173 test_repo.checkout(&branch_name)?;
180 // run test 174 // run test
181 let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]); 175 let mut p = CliTester::new_from_dir(&test_repo.dir, ["push"]);
@@ -235,7 +229,7 @@ mod when_branch_is_checked_out {
235 let cli_tester_handle = 229 let cli_tester_handle =
236 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { 230 std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> {
237 let (originating_repo, test_repo) = 231 let (originating_repo, test_repo) =
238 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 232 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
239 233
240 // add another commit (so we have an ammened local branch) 234 // add another commit (so we have an ammened local branch)
241 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; 235 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
@@ -315,7 +309,7 @@ mod when_branch_is_checked_out {
315 309
316 let cli_tester_handle = std::thread::spawn(move || -> Result<GitTestRepo> { 310 let cli_tester_handle = std::thread::spawn(move || -> Result<GitTestRepo> {
317 let (_, test_repo) = 311 let (_, test_repo) =
318 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 312 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
319 313
320 // add another commit (so we have an ammened local branch) 314 // add another commit (so we have an ammened local branch)
321 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?; 315 std::fs::write(test_repo.dir.join("ammended-commit.md"), "some content")?;
@@ -398,7 +392,7 @@ mod when_branch_is_checked_out {
398 392
399 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 393 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
400 let (_, tmp_repo) = 394 let (_, tmp_repo) =
401 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 395 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
402 let branch_name = tmp_repo.get_checked_out_branch_name()?; 396 let branch_name = tmp_repo.get_checked_out_branch_name()?;
403 397
404 let test_repo = GitTestRepo::default(); 398 let test_repo = GitTestRepo::default();
@@ -464,7 +458,7 @@ mod when_branch_is_checked_out {
464 458
465 let cli_tester_handle = std::thread::spawn(move || -> Result<()> { 459 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
466 let (_, tmp_repo) = 460 let (_, tmp_repo) =
467 create_proposals_and_repo_with_first_proposal_pulled_and_checkedout()?; 461 create_proposals_and_repo_with_proposal_pulled_and_checkedout(1)?;
468 let branch_name = tmp_repo.get_checked_out_branch_name()?; 462 let branch_name = tmp_repo.get_checked_out_branch_name()?;
469 463
470 let test_repo = GitTestRepo::default(); 464 let test_repo = GitTestRepo::default();