diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-03-08 14:37:56 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-03-08 14:39:21 +0000 |
| commit | 6b3aecbcbde669859533716225e9c3bbfd2023b2 (patch) | |
| tree | 06258c93893c57ae1ef3b3d709c364f00365fdb5 /tests/send.rs | |
| parent | 5622e384447fba354548aca0e39dcee3d95951c3 (diff) | |
feat(send): select commits from a list
when since_or_range isn't specified
adds resilience as assuming master..HEAD can cause some issues
eg when master is not up-to-date with origin/master
Diffstat (limited to 'tests/send.rs')
| -rw-r--r-- | tests/send.rs | 380 |
1 files changed, 48 insertions, 332 deletions
diff --git a/tests/send.rs b/tests/send.rs index 3c619a4..538f38a 100644 --- a/tests/send.rs +++ b/tests/send.rs | |||
| @@ -12,19 +12,8 @@ fn when_no_main_or_master_branch_return_error() -> Result<()> { | |||
| 12 | Ok(()) | 12 | Ok(()) |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | #[test] | 15 | // TODO when commits ahead of origin/master - test ask to proceed |
| 16 | fn when_no_commits_ahead_of_main_return_error() -> Result<()> { | 16 | // TODO when commits in origin/master - test ask to proceed |
| 17 | let test_repo = GitTestRepo::default(); | ||
| 18 | test_repo.populate()?; | ||
| 19 | // create feature branch with 1 commit ahead | ||
| 20 | test_repo.create_branch("feature")?; | ||
| 21 | test_repo.checkout("feature")?; | ||
| 22 | |||
| 23 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]); | ||
| 24 | p.expect("Error: 'feature' is 0 commits ahead of 'main' so no patches were created")?; | ||
| 25 | Ok(()) | ||
| 26 | } | ||
| 27 | |||
| 28 | mod when_commits_behind_ask_to_proceed { | 17 | mod when_commits_behind_ask_to_proceed { |
| 29 | use super::*; | 18 | use super::*; |
| 30 | 19 | ||
| @@ -46,16 +35,13 @@ mod when_commits_behind_ask_to_proceed { | |||
| 46 | test_repo.checkout("feature")?; | 35 | test_repo.checkout("feature")?; |
| 47 | Ok(test_repo) | 36 | Ok(test_repo) |
| 48 | } | 37 | } |
| 49 | static BEHIND_LEN: u8 = 1; | 38 | |
| 50 | static AHEAD_LEN: u8 = 2; | 39 | fn expect_confirm_prompt(p: &mut CliTester) -> Result<CliTesterConfirmPrompt> { |
| 51 | 40 | p.expect("creating proposal from 2 commits:\r\n")?; | |
| 52 | fn expect_confirm_prompt( | 41 | p.expect("fe973a8 add t4.md\r\n")?; |
| 53 | p: &mut CliTester, | 42 | p.expect("232efb3 add t3.md\r\n")?; |
| 54 | behind: u8, | ||
| 55 | ahead: u8, | ||
| 56 | ) -> Result<CliTesterConfirmPrompt> { | ||
| 57 | p.expect_confirm( | 43 | p.expect_confirm( |
| 58 | format!("'feature' is {behind} commits behind 'main' and {ahead} ahead. Consider rebasing before sending patches. Proceed anyway?").as_str(), | 44 | "proposal is 1 behind 'main'. consider rebasing before submission. proceed anyway?", |
| 59 | Some(false), | 45 | Some(false), |
| 60 | ) | 46 | ) |
| 61 | } | 47 | } |
| @@ -64,8 +50,8 @@ mod when_commits_behind_ask_to_proceed { | |||
| 64 | fn asked_with_default_no() -> Result<()> { | 50 | fn asked_with_default_no() -> Result<()> { |
| 65 | let test_repo = prep_test_repo()?; | 51 | let test_repo = prep_test_repo()?; |
| 66 | 52 | ||
| 67 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]); | 53 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "HEAD~2"]); |
| 68 | expect_confirm_prompt(&mut p, BEHIND_LEN, AHEAD_LEN)?; | 54 | expect_confirm_prompt(&mut p)?; |
| 69 | p.exit()?; | 55 | p.exit()?; |
| 70 | Ok(()) | 56 | Ok(()) |
| 71 | } | 57 | } |
| @@ -74,11 +60,11 @@ mod when_commits_behind_ask_to_proceed { | |||
| 74 | fn when_response_is_false_aborts() -> Result<()> { | 60 | fn when_response_is_false_aborts() -> Result<()> { |
| 75 | let test_repo = prep_test_repo()?; | 61 | let test_repo = prep_test_repo()?; |
| 76 | 62 | ||
| 77 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]); | 63 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "HEAD~2"]); |
| 78 | 64 | ||
| 79 | expect_confirm_prompt(&mut p, BEHIND_LEN, AHEAD_LEN)?.succeeds_with(Some(false))?; | 65 | expect_confirm_prompt(&mut p)?.succeeds_with(Some(false))?; |
| 80 | 66 | ||
| 81 | p.expect_end_with("Error: aborting so branch can be rebased\r\n")?; | 67 | p.expect_end_with("Error: aborting so commits can be rebased\r\n")?; |
| 82 | 68 | ||
| 83 | Ok(()) | 69 | Ok(()) |
| 84 | } | 70 | } |
| @@ -87,37 +73,14 @@ mod when_commits_behind_ask_to_proceed { | |||
| 87 | fn when_response_is_true_proceeds() -> Result<()> { | 73 | fn when_response_is_true_proceeds() -> Result<()> { |
| 88 | let test_repo = prep_test_repo()?; | 74 | let test_repo = prep_test_repo()?; |
| 89 | 75 | ||
| 90 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]); | 76 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "HEAD~2"]); |
| 91 | expect_confirm_prompt(&mut p, BEHIND_LEN, AHEAD_LEN)?.succeeds_with(Some(true))?; | 77 | expect_confirm_prompt(&mut p)?.succeeds_with(Some(true))?; |
| 92 | p.expect( | 78 | p.expect("? include cover letter")?; |
| 93 | format!("creating patch for {AHEAD_LEN} commits from 'feature' that are {BEHIND_LEN} behind 'main'",) | ||
| 94 | .as_str(), | ||
| 95 | )?; | ||
| 96 | p.exit()?; | 79 | p.exit()?; |
| 97 | Ok(()) | 80 | Ok(()) |
| 98 | } | 81 | } |
| 99 | } | 82 | } |
| 100 | 83 | ||
| 101 | #[test] | ||
| 102 | #[serial] | ||
| 103 | fn cli_message_creating_patches() -> Result<()> { | ||
| 104 | let test_repo = GitTestRepo::default(); | ||
| 105 | test_repo.populate()?; | ||
| 106 | // create feature branch with 2 commit ahead | ||
| 107 | test_repo.create_branch("feature")?; | ||
| 108 | test_repo.checkout("feature")?; | ||
| 109 | std::fs::write(test_repo.dir.join("t3.md"), "some content")?; | ||
| 110 | test_repo.stage_and_commit("add t3.md")?; | ||
| 111 | std::fs::write(test_repo.dir.join("t4.md"), "some content")?; | ||
| 112 | test_repo.stage_and_commit("add t4.md")?; | ||
| 113 | |||
| 114 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]); | ||
| 115 | |||
| 116 | p.expect("creating patch for 2 commits from 'feature' that can be merged into 'main'")?; | ||
| 117 | p.exit()?; | ||
| 118 | Ok(()) | ||
| 119 | } | ||
| 120 | |||
| 121 | fn is_cover_letter(event: &nostr::Event) -> bool { | 84 | fn is_cover_letter(event: &nostr::Event) -> bool { |
| 122 | event.kind.as_u64().eq(&PATCH_KIND) | 85 | event.kind.as_u64().eq(&PATCH_KIND) |
| 123 | && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter")) | 86 | && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter")) |
| @@ -149,6 +112,7 @@ fn cli_tester_create_proposal(git_repo: &GitTestRepo, include_cover_letter: bool | |||
| 149 | TEST_PASSWORD, | 112 | TEST_PASSWORD, |
| 150 | "--disable-cli-spinners", | 113 | "--disable-cli-spinners", |
| 151 | "send", | 114 | "send", |
| 115 | "HEAD~2", | ||
| 152 | ]; | 116 | ]; |
| 153 | if include_cover_letter { | 117 | if include_cover_letter { |
| 154 | for arg in [ | 118 | for arg in [ |
| @@ -166,7 +130,9 @@ fn cli_tester_create_proposal(git_repo: &GitTestRepo, include_cover_letter: bool | |||
| 166 | } | 130 | } |
| 167 | 131 | ||
| 168 | fn expect_msgs_first(p: &mut CliTester, include_cover_letter: bool) -> Result<()> { | 132 | fn expect_msgs_first(p: &mut CliTester, include_cover_letter: bool) -> Result<()> { |
| 169 | p.expect("creating patch for 2 commits from 'feature' that can be merged into 'main'\r\n")?; | 133 | p.expect("creating proposal from 2 commits:\r\n")?; |
| 134 | p.expect("fe973a8 add t4.md\r\n")?; | ||
| 135 | p.expect("232efb3 add t3.md\r\n")?; | ||
| 170 | p.expect("searching for profile and relay updates...\r\n")?; | 136 | p.expect("searching for profile and relay updates...\r\n")?; |
| 171 | p.expect("\r")?; | 137 | p.expect("\r")?; |
| 172 | p.expect("logged in as fred\r\n")?; | 138 | p.expect("logged in as fred\r\n")?; |
| @@ -247,7 +213,7 @@ async fn prep_run_create_proposal( | |||
| 247 | Ok((r51, r52, r53, r55, r56)) | 213 | Ok((r51, r52, r53, r55, r56)) |
| 248 | } | 214 | } |
| 249 | 215 | ||
| 250 | mod sends_cover_letter_and_2_patches_to_3_relays { | 216 | mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_and_2_patches_to_3_relays { |
| 251 | 217 | ||
| 252 | use super::*; | 218 | use super::*; |
| 253 | #[tokio::test] | 219 | #[tokio::test] |
| @@ -937,7 +903,7 @@ mod sends_cover_letter_and_2_patches_to_3_relays { | |||
| 937 | } | 903 | } |
| 938 | } | 904 | } |
| 939 | 905 | ||
| 940 | mod sends_2_patches_without_cover_letter { | 906 | mod when_no_cover_letter_flag_set_with_range_of_head_2_sends_2_patches_without_cover_letter { |
| 941 | use super::*; | 907 | use super::*; |
| 942 | 908 | ||
| 943 | mod cli_ouput { | 909 | mod cli_ouput { |
| @@ -1118,206 +1084,9 @@ mod sends_2_patches_without_cover_letter { | |||
| 1118 | } | 1084 | } |
| 1119 | } | 1085 | } |
| 1120 | 1086 | ||
| 1121 | mod when_on_main_branch_defaults_to_last_commit { | 1087 | mod when_range_ommited_prompts_for_selection_defaulting_ahead_of_main { |
| 1122 | use super::*; | ||
| 1123 | |||
| 1124 | fn prep_git_repo() -> Result<GitTestRepo> { | ||
| 1125 | let test_repo = GitTestRepo::default(); | ||
| 1126 | test_repo.populate()?; | ||
| 1127 | // dont checkout feature branch | ||
| 1128 | std::fs::write(test_repo.dir.join("t3.md"), "some content")?; | ||
| 1129 | test_repo.stage_and_commit("add t3.md")?; | ||
| 1130 | std::fs::write(test_repo.dir.join("t4.md"), "some content")?; | ||
| 1131 | test_repo.stage_and_commit("add t4.md")?; | ||
| 1132 | Ok(test_repo) | ||
| 1133 | } | ||
| 1134 | |||
| 1135 | fn cli_tester_create_proposal(git_repo: &GitTestRepo) -> CliTester { | ||
| 1136 | let args = vec![ | ||
| 1137 | "--nsec", | ||
| 1138 | TEST_KEY_1_NSEC, | ||
| 1139 | "--password", | ||
| 1140 | TEST_PASSWORD, | ||
| 1141 | "--disable-cli-spinners", | ||
| 1142 | "send", | ||
| 1143 | "--no-cover-letter", | ||
| 1144 | ]; | ||
| 1145 | CliTester::new_from_dir(&git_repo.dir, args) | ||
| 1146 | } | ||
| 1147 | fn expect_msgs_first(p: &mut CliTester) -> Result<()> { | ||
| 1148 | p.expect("creating 1 patch from latest commit\r\n")?; | ||
| 1149 | p.expect("searching for profile and relay updates...\r\n")?; | ||
| 1150 | p.expect("\r")?; | ||
| 1151 | p.expect("logged in as fred\r\n")?; | ||
| 1152 | p.expect("posting 1 patch without a covering letter...\r\n")?; | ||
| 1153 | Ok(()) | ||
| 1154 | } | ||
| 1155 | async fn prep_run_create_proposal() -> Result<( | ||
| 1156 | Relay<'static>, | ||
| 1157 | Relay<'static>, | ||
| 1158 | Relay<'static>, | ||
| 1159 | Relay<'static>, | ||
| 1160 | Relay<'static>, | ||
| 1161 | )> { | ||
| 1162 | let git_repo = prep_git_repo()?; | ||
| 1163 | |||
| 1164 | // fallback (51,52) user write (53, 55) repo (55, 56) | ||
| 1165 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 1166 | Relay::new( | ||
| 1167 | 8051, | ||
| 1168 | None, | ||
| 1169 | Some(&|relay, client_id, subscription_id, _| -> Result<()> { | ||
| 1170 | relay.respond_events( | ||
| 1171 | client_id, | ||
| 1172 | &subscription_id, | ||
| 1173 | &vec![ | ||
| 1174 | generate_test_key_1_metadata_event("fred"), | ||
| 1175 | generate_test_key_1_relay_list_event(), | ||
| 1176 | ], | ||
| 1177 | )?; | ||
| 1178 | Ok(()) | ||
| 1179 | }), | ||
| 1180 | ), | ||
| 1181 | Relay::new(8052, None, None), | ||
| 1182 | Relay::new(8053, None, None), | ||
| 1183 | Relay::new( | ||
| 1184 | 8055, | ||
| 1185 | None, | ||
| 1186 | Some(&|relay, client_id, subscription_id, _| -> Result<()> { | ||
| 1187 | relay.respond_events( | ||
| 1188 | client_id, | ||
| 1189 | &subscription_id, | ||
| 1190 | &vec![generate_repo_ref_event()], | ||
| 1191 | )?; | ||
| 1192 | Ok(()) | ||
| 1193 | }), | ||
| 1194 | ), | ||
| 1195 | Relay::new(8056, None, None), | ||
| 1196 | ); | ||
| 1197 | |||
| 1198 | // // check relay had the right number of events | ||
| 1199 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 1200 | let mut p = cli_tester_create_proposal(&git_repo); | ||
| 1201 | p.expect_end_eventually()?; | ||
| 1202 | for p in [51, 52, 53, 55, 56] { | ||
| 1203 | relay::shutdown_relay(8000 + p)?; | ||
| 1204 | } | ||
| 1205 | Ok(()) | ||
| 1206 | }); | ||
| 1207 | |||
| 1208 | // launch relay | ||
| 1209 | let _ = join!( | ||
| 1210 | r51.listen_until_close(), | ||
| 1211 | r52.listen_until_close(), | ||
| 1212 | r53.listen_until_close(), | ||
| 1213 | r55.listen_until_close(), | ||
| 1214 | r56.listen_until_close(), | ||
| 1215 | ); | ||
| 1216 | cli_tester_handle.join().unwrap()?; | ||
| 1217 | Ok((r51, r52, r53, r55, r56)) | ||
| 1218 | } | ||
| 1219 | mod cli_ouput { | ||
| 1220 | use super::*; | ||
| 1221 | |||
| 1222 | #[tokio::test] | ||
| 1223 | #[serial] | ||
| 1224 | async fn check_cli_output() -> Result<()> { | ||
| 1225 | let git_repo = prep_git_repo()?; | ||
| 1226 | |||
| 1227 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 1228 | Relay::new( | ||
| 1229 | 8051, | ||
| 1230 | None, | ||
| 1231 | Some(&|relay, client_id, subscription_id, _| -> Result<()> { | ||
| 1232 | relay.respond_events( | ||
| 1233 | client_id, | ||
| 1234 | &subscription_id, | ||
| 1235 | &vec![ | ||
| 1236 | generate_test_key_1_metadata_event("fred"), | ||
| 1237 | generate_test_key_1_relay_list_event(), | ||
| 1238 | ], | ||
| 1239 | )?; | ||
| 1240 | Ok(()) | ||
| 1241 | }), | ||
| 1242 | ), | ||
| 1243 | Relay::new(8052, None, None), | ||
| 1244 | Relay::new(8053, None, None), | ||
| 1245 | Relay::new( | ||
| 1246 | 8055, | ||
| 1247 | None, | ||
| 1248 | Some(&|relay, client_id, subscription_id, _| -> Result<()> { | ||
| 1249 | relay.respond_events( | ||
| 1250 | client_id, | ||
| 1251 | &subscription_id, | ||
| 1252 | &vec![generate_repo_ref_event()], | ||
| 1253 | )?; | ||
| 1254 | Ok(()) | ||
| 1255 | }), | ||
| 1256 | ), | ||
| 1257 | Relay::new(8056, None, None), | ||
| 1258 | ); | ||
| 1259 | |||
| 1260 | // // check relay had the right number of events | ||
| 1261 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 1262 | let mut p = cli_tester_create_proposal(&git_repo); | ||
| 1263 | |||
| 1264 | expect_msgs_first(&mut p)?; | ||
| 1265 | relay::expect_send_with_progress( | ||
| 1266 | &mut p, | ||
| 1267 | vec![ | ||
| 1268 | (" [my-relay] [repo-relay] ws://localhost:8055", true, ""), | ||
| 1269 | (" [my-relay] ws://localhost:8053", true, ""), | ||
| 1270 | (" [repo-relay] ws://localhost:8056", true, ""), | ||
| 1271 | (" [default] ws://localhost:8051", true, ""), | ||
| 1272 | (" [default] ws://localhost:8052", true, ""), | ||
| 1273 | ], | ||
| 1274 | 1, | ||
| 1275 | )?; | ||
| 1276 | p.expect_end_with_whitespace()?; | ||
| 1277 | for p in [51, 52, 53, 55, 56] { | ||
| 1278 | relay::shutdown_relay(8000 + p)?; | ||
| 1279 | } | ||
| 1280 | Ok(()) | ||
| 1281 | }); | ||
| 1282 | |||
| 1283 | // launch relay | ||
| 1284 | let _ = join!( | ||
| 1285 | r51.listen_until_close(), | ||
| 1286 | r52.listen_until_close(), | ||
| 1287 | r53.listen_until_close(), | ||
| 1288 | r55.listen_until_close(), | ||
| 1289 | r56.listen_until_close(), | ||
| 1290 | ); | ||
| 1291 | cli_tester_handle.join().unwrap()?; | ||
| 1292 | Ok(()) | ||
| 1293 | } | ||
| 1294 | } | ||
| 1295 | |||
| 1296 | #[tokio::test] | ||
| 1297 | #[serial] | ||
| 1298 | async fn one_patch_event_sent() -> Result<()> { | ||
| 1299 | let (_, _, r53, r55, r56) = prep_run_create_proposal().await?; | ||
| 1300 | for relay in [&r53, &r55, &r56] { | ||
| 1301 | assert_eq!(relay.events.iter().filter(|e| is_patch(e)).count(), 1); | ||
| 1302 | } | ||
| 1303 | Ok(()) | ||
| 1304 | } | ||
| 1305 | } | ||
| 1306 | |||
| 1307 | mod specify_starting_commits_whist_on_main_branch { | ||
| 1308 | use super::*; | 1088 | use super::*; |
| 1309 | 1089 | ||
| 1310 | fn prep_git_repo() -> Result<GitTestRepo> { | ||
| 1311 | let test_repo = GitTestRepo::default(); | ||
| 1312 | test_repo.populate()?; | ||
| 1313 | // dont checkout feature branch | ||
| 1314 | std::fs::write(test_repo.dir.join("t3.md"), "some content")?; | ||
| 1315 | test_repo.stage_and_commit("add t3.md")?; | ||
| 1316 | std::fs::write(test_repo.dir.join("t4.md"), "some content")?; | ||
| 1317 | test_repo.stage_and_commit("add t4.md")?; | ||
| 1318 | Ok(test_repo) | ||
| 1319 | } | ||
| 1320 | |||
| 1321 | fn cli_tester_create_proposal(git_repo: &GitTestRepo) -> CliTester { | 1090 | fn cli_tester_create_proposal(git_repo: &GitTestRepo) -> CliTester { |
| 1322 | let args = vec![ | 1091 | let args = vec![ |
| 1323 | "--nsec", | 1092 | "--nsec", |
| @@ -1326,17 +1095,29 @@ mod specify_starting_commits_whist_on_main_branch { | |||
| 1326 | TEST_PASSWORD, | 1095 | TEST_PASSWORD, |
| 1327 | "--disable-cli-spinners", | 1096 | "--disable-cli-spinners", |
| 1328 | "send", | 1097 | "send", |
| 1329 | "HEAD~3", | ||
| 1330 | "--no-cover-letter", | 1098 | "--no-cover-letter", |
| 1331 | ]; | 1099 | ]; |
| 1332 | CliTester::new_from_dir(&git_repo.dir, args) | 1100 | CliTester::new_from_dir(&git_repo.dir, args) |
| 1333 | } | 1101 | } |
| 1334 | fn expect_msgs_first(p: &mut CliTester) -> Result<()> { | 1102 | fn expect_msgs_first(p: &mut CliTester) -> Result<()> { |
| 1335 | p.expect("creating patch for 3 commits\r\n")?; | 1103 | let mut selector = p.expect_multi_select( |
| 1104 | "select commits for proposal", | ||
| 1105 | vec![ | ||
| 1106 | "(Joe Bloggs) add t4.md [feature] fe973a8".to_string(), | ||
| 1107 | "(Joe Bloggs) add t3.md 232efb3".to_string(), | ||
| 1108 | "(Joe Bloggs) add t2.md [main] 431b84e".to_string(), | ||
| 1109 | "(Joe Bloggs) add t1.md af474d8".to_string(), | ||
| 1110 | "(Joe Bloggs) Initial commit 9ee507f".to_string(), | ||
| 1111 | ], | ||
| 1112 | )?; | ||
| 1113 | selector.succeeds_with(vec![0, 1], false, vec![0, 1])?; | ||
| 1114 | p.expect("creating proposal from 2 commits:\r\n")?; | ||
| 1115 | p.expect("fe973a8 add t4.md\r\n")?; | ||
| 1116 | p.expect("232efb3 add t3.md\r\n")?; | ||
| 1336 | p.expect("searching for profile and relay updates...\r\n")?; | 1117 | p.expect("searching for profile and relay updates...\r\n")?; |
| 1337 | p.expect("\r")?; | 1118 | p.expect("\r")?; |
| 1338 | p.expect("logged in as fred\r\n")?; | 1119 | p.expect("logged in as fred\r\n")?; |
| 1339 | p.expect("posting 3 patches without a covering letter...\r\n")?; | 1120 | p.expect("posting 2 patches without a covering letter...\r\n")?; |
| 1340 | Ok(()) | 1121 | Ok(()) |
| 1341 | } | 1122 | } |
| 1342 | async fn prep_run_create_proposal() -> Result<( | 1123 | async fn prep_run_create_proposal() -> Result<( |
| @@ -1385,6 +1166,7 @@ mod specify_starting_commits_whist_on_main_branch { | |||
| 1385 | // // check relay had the right number of events | 1166 | // // check relay had the right number of events |
| 1386 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 1167 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 1387 | let mut p = cli_tester_create_proposal(&git_repo); | 1168 | let mut p = cli_tester_create_proposal(&git_repo); |
| 1169 | expect_msgs_first(&mut p)?; | ||
| 1388 | p.expect_end_eventually()?; | 1170 | p.expect_end_eventually()?; |
| 1389 | for p in [51, 52, 53, 55, 56] { | 1171 | for p in [51, 52, 53, 55, 56] { |
| 1390 | relay::shutdown_relay(8000 + p)?; | 1172 | relay::shutdown_relay(8000 + p)?; |
| @@ -1444,7 +1226,6 @@ mod specify_starting_commits_whist_on_main_branch { | |||
| 1444 | Relay::new(8056, None, None), | 1226 | Relay::new(8056, None, None), |
| 1445 | ); | 1227 | ); |
| 1446 | 1228 | ||
| 1447 | // // check relay had the right number of events | ||
| 1448 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 1229 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 1449 | let mut p = cli_tester_create_proposal(&git_repo); | 1230 | let mut p = cli_tester_create_proposal(&git_repo); |
| 1450 | 1231 | ||
| @@ -1458,7 +1239,7 @@ mod specify_starting_commits_whist_on_main_branch { | |||
| 1458 | (" [default] ws://localhost:8051", true, ""), | 1239 | (" [default] ws://localhost:8051", true, ""), |
| 1459 | (" [default] ws://localhost:8052", true, ""), | 1240 | (" [default] ws://localhost:8052", true, ""), |
| 1460 | ], | 1241 | ], |
| 1461 | 3, | 1242 | 2, |
| 1462 | )?; | 1243 | )?; |
| 1463 | p.expect_end_with_whitespace()?; | 1244 | p.expect_end_with_whitespace()?; |
| 1464 | for p in [51, 52, 53, 55, 56] { | 1245 | for p in [51, 52, 53, 55, 56] { |
| @@ -1482,84 +1263,16 @@ mod specify_starting_commits_whist_on_main_branch { | |||
| 1482 | 1263 | ||
| 1483 | #[tokio::test] | 1264 | #[tokio::test] |
| 1484 | #[serial] | 1265 | #[serial] |
| 1485 | async fn three_patch_events() -> Result<()> { | 1266 | async fn two_patch_events_sent() -> Result<()> { |
| 1486 | let (_, _, r53, r55, r56) = prep_run_create_proposal().await?; | 1267 | let (_, _, r53, r55, r56) = prep_run_create_proposal().await?; |
| 1487 | for relay in [&r53, &r55, &r56] { | 1268 | for relay in [&r53, &r55, &r56] { |
| 1488 | assert_eq!(relay.events.iter().filter(|e| is_patch(e)).count(), 3); | 1269 | assert_eq!(relay.events.iter().filter(|e| is_patch(e)).count(), 2); |
| 1489 | } | ||
| 1490 | Ok(()) | ||
| 1491 | } | ||
| 1492 | |||
| 1493 | #[tokio::test] | ||
| 1494 | #[serial] | ||
| 1495 | async fn root_patch_doesnt_have_a_branch_name_tag() -> Result<()> { | ||
| 1496 | let (_, _, r53, r55, r56) = prep_run_create_proposal().await?; | ||
| 1497 | for relay in [&r53, &r55, &r56] { | ||
| 1498 | let patch_events = relay | ||
| 1499 | .events | ||
| 1500 | .iter() | ||
| 1501 | .filter(|e| is_patch(e)) | ||
| 1502 | .collect::<Vec<&nostr::Event>>(); | ||
| 1503 | |||
| 1504 | assert!( | ||
| 1505 | !patch_events[0] | ||
| 1506 | .iter_tags() | ||
| 1507 | .any(|t| t.as_vec()[0].eq("branch-name")) | ||
| 1508 | ); | ||
| 1509 | } | ||
| 1510 | Ok(()) | ||
| 1511 | } | ||
| 1512 | |||
| 1513 | #[tokio::test] | ||
| 1514 | #[serial] | ||
| 1515 | async fn first_patch_is_ancestor_and_root_others_in_correct_order() -> Result<()> { | ||
| 1516 | let (_, _, r53, r55, r56) = prep_run_create_proposal().await?; | ||
| 1517 | for relay in [&r53, &r55, &r56] { | ||
| 1518 | let patch_events = relay | ||
| 1519 | .events | ||
| 1520 | .iter() | ||
| 1521 | .filter(|e| is_patch(e)) | ||
| 1522 | .collect::<Vec<&nostr::Event>>(); | ||
| 1523 | |||
| 1524 | // first patch tagged as root | ||
| 1525 | assert!( | ||
| 1526 | patch_events[0] | ||
| 1527 | .iter_tags() | ||
| 1528 | .any(|t| t.as_vec()[0].eq("t") && t.as_vec()[1].eq("root")) | ||
| 1529 | ); | ||
| 1530 | // first patch is ancestor | ||
| 1531 | assert_eq!( | ||
| 1532 | patch_events[0] | ||
| 1533 | .iter_tags() | ||
| 1534 | .find(|t| t.as_vec()[0].eq("commit")) | ||
| 1535 | .unwrap() | ||
| 1536 | .as_vec()[1], | ||
| 1537 | "431b84edc0d2fa118d63faa3c2db9c73d630a5ae" | ||
| 1538 | ); | ||
| 1539 | // second patch not tagged as root | ||
| 1540 | assert_eq!( | ||
| 1541 | patch_events[1] | ||
| 1542 | .iter_tags() | ||
| 1543 | .find(|t| t.as_vec()[0].eq("commit")) | ||
| 1544 | .unwrap() | ||
| 1545 | .as_vec()[1], | ||
| 1546 | "232efb37ebc67692c9e9ff58b83c0d3d63971a0a" | ||
| 1547 | ); | ||
| 1548 | // second patch not tagged as root | ||
| 1549 | assert_eq!( | ||
| 1550 | patch_events[2] | ||
| 1551 | .iter_tags() | ||
| 1552 | .find(|t| t.as_vec()[0].eq("commit")) | ||
| 1553 | .unwrap() | ||
| 1554 | .as_vec()[1], | ||
| 1555 | "fe973a840fba2a8ab37dd505c154854a69a6505c" | ||
| 1556 | ); | ||
| 1557 | } | 1270 | } |
| 1558 | Ok(()) | 1271 | Ok(()) |
| 1559 | } | 1272 | } |
| 1560 | } | 1273 | } |
| 1561 | 1274 | ||
| 1562 | mod specify_in_reply_to { | 1275 | mod in_reply_to_specified_with_range_of_head_2_and_cover_letter_details_specified { |
| 1563 | use super::*; | 1276 | use super::*; |
| 1564 | fn cli_tester_create_proposal(git_repo: &GitTestRepo) -> CliTester { | 1277 | fn cli_tester_create_proposal(git_repo: &GitTestRepo) -> CliTester { |
| 1565 | let args = vec![ | 1278 | let args = vec![ |
| @@ -1569,6 +1282,7 @@ mod specify_in_reply_to { | |||
| 1569 | TEST_PASSWORD, | 1282 | TEST_PASSWORD, |
| 1570 | "--disable-cli-spinners", | 1283 | "--disable-cli-spinners", |
| 1571 | "send", | 1284 | "send", |
| 1285 | "HEAD~2", | ||
| 1572 | "--in-reply-to", | 1286 | "--in-reply-to", |
| 1573 | "nevent1qqsypm62fzw7qynvlc4gjl3tr0jw4vmh659nvr2cc5qyhdg92a5yy0qzypumuen7l8wthtz45p3ftn58pvrs9xlumvkuu2xet8egzkcklqtesxygzam", | 1287 | "nevent1qqsypm62fzw7qynvlc4gjl3tr0jw4vmh659nvr2cc5qyhdg92a5yy0qzypumuen7l8wthtz45p3ftn58pvrs9xlumvkuu2xet8egzkcklqtesxygzam", |
| 1574 | "--title", | 1288 | "--title", |
| @@ -1579,8 +1293,10 @@ mod specify_in_reply_to { | |||
| 1579 | CliTester::new_from_dir(&git_repo.dir, args) | 1293 | CliTester::new_from_dir(&git_repo.dir, args) |
| 1580 | } | 1294 | } |
| 1581 | fn expect_msgs_first(p: &mut CliTester, include_cover_letter: bool) -> Result<()> { | 1295 | fn expect_msgs_first(p: &mut CliTester, include_cover_letter: bool) -> Result<()> { |
| 1582 | p.expect("creating patch for 2 commits from 'feature' that can be merged into 'main'\r\n")?; | 1296 | p.expect("creating proposal revision for: nevent1qqsypm62fzw7qynvlc4gjl3tr0jw4vmh659nvr2cc5qyhdg92a5yy0qzypumuen7l8wthtz45p3ftn58pvrs9xlumvkuu2xet8egzkcklqtesxygzam\r\n")?; |
| 1583 | p.expect("as a revision to proposal: nevent1qqsypm62fzw7qynvlc4gjl3tr0jw4vmh659nvr2cc5qyhdg92a5yy0qzypumuen7l8wthtz45p3ftn58pvrs9xlumvkuu2xet8egzkcklqtesxygzam\r\n")?; | 1297 | p.expect("creating proposal from 2 commits:\r\n")?; |
| 1298 | p.expect("fe973a8 add t4.md\r\n")?; | ||
| 1299 | p.expect("232efb3 add t3.md\r\n")?; | ||
| 1584 | p.expect("searching for profile and relay updates...\r\n")?; | 1300 | p.expect("searching for profile and relay updates...\r\n")?; |
| 1585 | p.expect("\r")?; | 1301 | p.expect("\r")?; |
| 1586 | p.expect("logged in as fred\r\n")?; | 1302 | p.expect("logged in as fred\r\n")?; |