diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-22 10:11:39 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-22 10:11:39 +0000 |
| commit | fdc15cb017b022a3b932ac5a337c649cb63df93c (patch) | |
| tree | a0883ab2e027042df43c15892f837fffe159cf49 /tests/list.rs | |
| parent | ea5aa6993d4c906c1703563ddc304c324c4ae079 (diff) | |
fix(list): support `--in-reply-to` latest revision
update list to support rebases via proposal revisions
as created by `ngit send --in-reply-to`
or upcoming change `ngit push --force`
Diffstat (limited to 'tests/list.rs')
| -rw-r--r-- | tests/list.rs | 311 |
1 files changed, 308 insertions, 3 deletions
diff --git a/tests/list.rs b/tests/list.rs index 7762b1c..eb6dc3d 100644 --- a/tests/list.rs +++ b/tests/list.rs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | use anyhow::Result; | 1 | use anyhow::Result; |
| 2 | use futures::join; | 2 | use futures::join; |
| 3 | use nostr_sdk::client::blocking::Client; | ||
| 3 | use serial_test::serial; | 4 | use serial_test::serial; |
| 4 | use test_utils::{git::GitTestRepo, relay::Relay, *}; | 5 | use test_utils::{git::GitTestRepo, relay::Relay, *}; |
| 5 | 6 | ||
| @@ -20,18 +21,21 @@ fn cli_tester_create_proposals() -> Result<GitTestRepo> { | |||
| 20 | FEATURE_BRANCH_NAME_1, | 21 | FEATURE_BRANCH_NAME_1, |
| 21 | "a", | 22 | "a", |
| 22 | Some((PROPOSAL_TITLE_1, "proposal a description")), | 23 | Some((PROPOSAL_TITLE_1, "proposal a description")), |
| 24 | None, | ||
| 23 | )?; | 25 | )?; |
| 24 | cli_tester_create_proposal( | 26 | cli_tester_create_proposal( |
| 25 | &git_repo, | 27 | &git_repo, |
| 26 | FEATURE_BRANCH_NAME_2, | 28 | FEATURE_BRANCH_NAME_2, |
| 27 | "b", | 29 | "b", |
| 28 | Some((PROPOSAL_TITLE_2, "proposal b description")), | 30 | Some((PROPOSAL_TITLE_2, "proposal b description")), |
| 31 | None, | ||
| 29 | )?; | 32 | )?; |
| 30 | cli_tester_create_proposal( | 33 | cli_tester_create_proposal( |
| 31 | &git_repo, | 34 | &git_repo, |
| 32 | FEATURE_BRANCH_NAME_3, | 35 | FEATURE_BRANCH_NAME_3, |
| 33 | "c", | 36 | "c", |
| 34 | Some((PROPOSAL_TITLE_3, "proposal c description")), | 37 | Some((PROPOSAL_TITLE_3, "proposal c description")), |
| 38 | None, | ||
| 35 | )?; | 39 | )?; |
| 36 | Ok(git_repo) | 40 | Ok(git_repo) |
| 37 | } | 41 | } |
| @@ -65,10 +69,27 @@ fn cli_tester_create_proposal( | |||
| 65 | branch_name: &str, | 69 | branch_name: &str, |
| 66 | prefix: &str, | 70 | prefix: &str, |
| 67 | cover_letter_title_and_description: Option<(&str, &str)>, | 71 | cover_letter_title_and_description: Option<(&str, &str)>, |
| 72 | in_reply_to: Option<String>, | ||
| 68 | ) -> Result<()> { | 73 | ) -> Result<()> { |
| 69 | create_and_populate_branch(test_repo, branch_name, prefix, false)?; | 74 | create_and_populate_branch(test_repo, branch_name, prefix, false)?; |
| 70 | 75 | ||
| 71 | if let Some((title, description)) = cover_letter_title_and_description { | 76 | if let Some(in_reply_to) = in_reply_to { |
| 77 | let mut p = CliTester::new_from_dir( | ||
| 78 | &test_repo.dir, | ||
| 79 | [ | ||
| 80 | "--nsec", | ||
| 81 | TEST_KEY_1_NSEC, | ||
| 82 | "--password", | ||
| 83 | TEST_PASSWORD, | ||
| 84 | "--disable-cli-spinners", | ||
| 85 | "send", | ||
| 86 | "--no-cover-letter", | ||
| 87 | "--in-reply-to", | ||
| 88 | in_reply_to.as_str(), | ||
| 89 | ], | ||
| 90 | ); | ||
| 91 | p.expect_end_eventually()?; | ||
| 92 | } else if let Some((title, description)) = cover_letter_title_and_description { | ||
| 72 | let mut p = CliTester::new_from_dir( | 93 | let mut p = CliTester::new_from_dir( |
| 73 | &test_repo.dir, | 94 | &test_repo.dir, |
| 74 | [ | 95 | [ |
| @@ -636,6 +657,7 @@ mod when_main_branch_is_uptodate { | |||
| 636 | FEATURE_BRANCH_NAME_4, | 657 | FEATURE_BRANCH_NAME_4, |
| 637 | "d", | 658 | "d", |
| 638 | None, | 659 | None, |
| 660 | None, | ||
| 639 | )?; | 661 | )?; |
| 640 | let test_repo = GitTestRepo::default(); | 662 | let test_repo = GitTestRepo::default(); |
| 641 | test_repo.populate()?; | 663 | test_repo.populate()?; |
| @@ -715,6 +737,7 @@ mod when_main_branch_is_uptodate { | |||
| 715 | FEATURE_BRANCH_NAME_4, | 737 | FEATURE_BRANCH_NAME_4, |
| 716 | "d", | 738 | "d", |
| 717 | None, | 739 | None, |
| 740 | None, | ||
| 718 | )?; | 741 | )?; |
| 719 | let test_repo = GitTestRepo::default(); | 742 | let test_repo = GitTestRepo::default(); |
| 720 | test_repo.populate()?; | 743 | test_repo.populate()?; |
| @@ -1193,8 +1216,290 @@ mod when_main_branch_is_uptodate { | |||
| 1193 | } | 1216 | } |
| 1194 | 1217 | ||
| 1195 | mod when_latest_event_rebases_branch { | 1218 | mod when_latest_event_rebases_branch { |
| 1196 | // use super::*; | 1219 | use std::time::Duration; |
| 1197 | // TODO | 1220 | |
| 1221 | use super::*; | ||
| 1222 | |||
| 1223 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 1224 | // fallback (51,52) user write (53, 55) repo (55, 56) | ||
| 1225 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 1226 | Relay::new(8051, None, None), | ||
| 1227 | Relay::new(8052, None, None), | ||
| 1228 | Relay::new(8053, None, None), | ||
| 1229 | Relay::new(8055, None, None), | ||
| 1230 | Relay::new(8056, None, None), | ||
| 1231 | ); | ||
| 1232 | |||
| 1233 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 1234 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 1235 | r51.events.push(generate_repo_ref_event()); | ||
| 1236 | |||
| 1237 | r55.events.push(generate_repo_ref_event()); | ||
| 1238 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 1239 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 1240 | |||
| 1241 | let cli_tester_handle = std::thread::spawn( | ||
| 1242 | move || -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 1243 | // create 3 proposals | ||
| 1244 | let _ = cli_tester_create_proposals()?; | ||
| 1245 | // get proposal id of first | ||
| 1246 | let client = Client::new(&nostr::Keys::generate()); | ||
| 1247 | client.add_relay("ws://localhost:8055")?; | ||
| 1248 | client.connect_relay("ws://localhost:8055")?; | ||
| 1249 | let proposals = client.get_events_of( | ||
| 1250 | vec![ | ||
| 1251 | nostr::Filter::default() | ||
| 1252 | .kind(nostr::Kind::Custom(PATCH_KIND)) | ||
| 1253 | .custom_tag(nostr::Alphabet::T, vec!["root"]), | ||
| 1254 | ], | ||
| 1255 | Some(Duration::from_millis(500)), | ||
| 1256 | )?; | ||
| 1257 | client.disconnect()?; | ||
| 1258 | |||
| 1259 | let proposal_1_id = proposals | ||
| 1260 | .iter() | ||
| 1261 | .find(|e| { | ||
| 1262 | e.tags | ||
| 1263 | .iter() | ||
| 1264 | .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1)) | ||
| 1265 | }) | ||
| 1266 | .unwrap() | ||
| 1267 | .id; | ||
| 1268 | // recreate proposal 1 on top of a another commit (like a rebase on top | ||
| 1269 | // of one extra commit) | ||
| 1270 | let second_originating_repo = GitTestRepo::default(); | ||
| 1271 | second_originating_repo.populate()?; | ||
| 1272 | std::fs::write( | ||
| 1273 | second_originating_repo.dir.join("amazing.md"), | ||
| 1274 | "some content", | ||
| 1275 | )?; | ||
| 1276 | second_originating_repo | ||
| 1277 | .stage_and_commit("commit for rebasing on top of")?; | ||
| 1278 | cli_tester_create_proposal( | ||
| 1279 | &second_originating_repo, | ||
| 1280 | FEATURE_BRANCH_NAME_1, | ||
| 1281 | "a", | ||
| 1282 | Some((PROPOSAL_TITLE_1, "proposal a description")), | ||
| 1283 | Some(proposal_1_id.to_string()), | ||
| 1284 | )?; | ||
| 1285 | |||
| 1286 | // pretend we have downloaded the origianl version of the first proposal | ||
| 1287 | let test_repo = GitTestRepo::default(); | ||
| 1288 | test_repo.populate()?; | ||
| 1289 | create_and_populate_branch( | ||
| 1290 | &test_repo, | ||
| 1291 | FEATURE_BRANCH_NAME_1, | ||
| 1292 | "a", | ||
| 1293 | false, | ||
| 1294 | )?; | ||
| 1295 | // pretend we have pulled the updated main branch | ||
| 1296 | test_repo.checkout("main")?; | ||
| 1297 | std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; | ||
| 1298 | test_repo.stage_and_commit("commit for rebasing on top of")?; | ||
| 1299 | |||
| 1300 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); | ||
| 1301 | p.expect("finding proposals...\r\n")?; | ||
| 1302 | let mut c = p.expect_choice( | ||
| 1303 | "all proposals", | ||
| 1304 | vec![ | ||
| 1305 | format!("\"{PROPOSAL_TITLE_1}\""), | ||
| 1306 | format!("\"{PROPOSAL_TITLE_2}\""), | ||
| 1307 | format!("\"{PROPOSAL_TITLE_3}\""), | ||
| 1308 | ], | ||
| 1309 | )?; | ||
| 1310 | c.succeeds_with(0, true, None)?; | ||
| 1311 | p.expect("finding commits...\r\n")?; | ||
| 1312 | p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?; | ||
| 1313 | // its got here but tmpgit-32.. indicates that creatubg the eature | ||
| 1314 | // branch in line 1291 didnt work so the choices will be different | ||
| 1315 | let mut c = p.expect_choice( | ||
| 1316 | "", | ||
| 1317 | vec![ | ||
| 1318 | format!("checkout and overwrite existing proposal branch"), | ||
| 1319 | format!("checkout existing outdated proposal branch"), | ||
| 1320 | format!("apply to current branch with `git am`"), | ||
| 1321 | format!("download to ./patches"), | ||
| 1322 | format!("back"), | ||
| 1323 | ], | ||
| 1324 | )?; | ||
| 1325 | c.succeeds_with(0, false, Some(0))?; | ||
| 1326 | p.expect("checked out new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?; | ||
| 1327 | p.expect_end()?; | ||
| 1328 | |||
| 1329 | for p in [51, 52, 53, 55, 56] { | ||
| 1330 | relay::shutdown_relay(8000 + p)?; | ||
| 1331 | } | ||
| 1332 | Ok((second_originating_repo, test_repo)) | ||
| 1333 | }, | ||
| 1334 | ); | ||
| 1335 | |||
| 1336 | // launch relay | ||
| 1337 | let _ = join!( | ||
| 1338 | r51.listen_until_close(), | ||
| 1339 | r52.listen_until_close(), | ||
| 1340 | r53.listen_until_close(), | ||
| 1341 | r55.listen_until_close(), | ||
| 1342 | r56.listen_until_close(), | ||
| 1343 | ); | ||
| 1344 | let res = cli_tester_handle.join().unwrap()?; | ||
| 1345 | |||
| 1346 | Ok(res) | ||
| 1347 | } | ||
| 1348 | |||
| 1349 | mod cli_prompts { | ||
| 1350 | use super::*; | ||
| 1351 | async fn run_async_prompts_to_choose_from_proposal_titles() -> Result<()> { | ||
| 1352 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 1353 | Relay::new(8051, None, None), | ||
| 1354 | Relay::new(8052, None, None), | ||
| 1355 | Relay::new(8053, None, None), | ||
| 1356 | Relay::new(8055, None, None), | ||
| 1357 | Relay::new(8056, None, None), | ||
| 1358 | ); | ||
| 1359 | |||
| 1360 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 1361 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 1362 | r51.events.push(generate_repo_ref_event()); | ||
| 1363 | |||
| 1364 | r55.events.push(generate_repo_ref_event()); | ||
| 1365 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 1366 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 1367 | |||
| 1368 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 1369 | // create 3 proposals | ||
| 1370 | let _ = cli_tester_create_proposals()?; | ||
| 1371 | // get proposal id of first | ||
| 1372 | let client = Client::new(&nostr::Keys::generate()); | ||
| 1373 | client.add_relay("ws://localhost:8055")?; | ||
| 1374 | client.connect_relay("ws://localhost:8055")?; | ||
| 1375 | let proposals = client.get_events_of( | ||
| 1376 | vec![ | ||
| 1377 | nostr::Filter::default() | ||
| 1378 | .kind(nostr::Kind::Custom(PATCH_KIND)) | ||
| 1379 | .custom_tag(nostr::Alphabet::T, vec!["root"]), | ||
| 1380 | ], | ||
| 1381 | Some(Duration::from_millis(500)), | ||
| 1382 | )?; | ||
| 1383 | client.disconnect()?; | ||
| 1384 | |||
| 1385 | let proposal_1_id = proposals | ||
| 1386 | .iter() | ||
| 1387 | .find(|e| { | ||
| 1388 | e.tags | ||
| 1389 | .iter() | ||
| 1390 | .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1)) | ||
| 1391 | }) | ||
| 1392 | .unwrap() | ||
| 1393 | .id; | ||
| 1394 | // recreate proposal 1 on top of a another commit (like a rebase on top | ||
| 1395 | // of one extra commit) | ||
| 1396 | let second_originating_repo = GitTestRepo::default(); | ||
| 1397 | second_originating_repo.populate()?; | ||
| 1398 | std::fs::write( | ||
| 1399 | second_originating_repo.dir.join("amazing.md"), | ||
| 1400 | "some content", | ||
| 1401 | )?; | ||
| 1402 | second_originating_repo | ||
| 1403 | .stage_and_commit("commit for rebasing on top of")?; | ||
| 1404 | cli_tester_create_proposal( | ||
| 1405 | &second_originating_repo, | ||
| 1406 | FEATURE_BRANCH_NAME_1, | ||
| 1407 | "a", | ||
| 1408 | Some((PROPOSAL_TITLE_1, "proposal a description")), | ||
| 1409 | Some(proposal_1_id.to_string()), | ||
| 1410 | )?; | ||
| 1411 | |||
| 1412 | // pretend we have downloaded the origianl version of the first proposal | ||
| 1413 | let test_repo = GitTestRepo::default(); | ||
| 1414 | test_repo.populate()?; | ||
| 1415 | create_and_populate_branch( | ||
| 1416 | &test_repo, | ||
| 1417 | FEATURE_BRANCH_NAME_1, | ||
| 1418 | "a", | ||
| 1419 | false, | ||
| 1420 | )?; | ||
| 1421 | // pretend we have pulled the updated main branch | ||
| 1422 | test_repo.checkout("main")?; | ||
| 1423 | std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; | ||
| 1424 | test_repo.stage_and_commit("commit for rebasing on top of")?; | ||
| 1425 | |||
| 1426 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); | ||
| 1427 | p.expect("finding proposals...\r\n")?; | ||
| 1428 | let mut c = p.expect_choice( | ||
| 1429 | "all proposals", | ||
| 1430 | vec![ | ||
| 1431 | format!("\"{PROPOSAL_TITLE_1}\""), | ||
| 1432 | format!("\"{PROPOSAL_TITLE_2}\""), | ||
| 1433 | format!("\"{PROPOSAL_TITLE_3}\""), | ||
| 1434 | ], | ||
| 1435 | )?; | ||
| 1436 | c.succeeds_with(0, true, None)?; | ||
| 1437 | p.expect("finding commits...\r\n")?; | ||
| 1438 | p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?; | ||
| 1439 | // its got here but tmpgit-32.. indicates that creatubg the eature | ||
| 1440 | // branch in line 1291 didnt work so the choices will be different | ||
| 1441 | let mut c = p.expect_choice( | ||
| 1442 | "", | ||
| 1443 | vec![ | ||
| 1444 | format!("checkout and overwrite existing proposal branch"), | ||
| 1445 | format!("checkout existing outdated proposal branch"), | ||
| 1446 | format!("apply to current branch with `git am`"), | ||
| 1447 | format!("download to ./patches"), | ||
| 1448 | format!("back"), | ||
| 1449 | ], | ||
| 1450 | )?; | ||
| 1451 | c.succeeds_with(0, false, Some(0))?; | ||
| 1452 | p.expect("checked out new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?; | ||
| 1453 | p.expect_end()?; | ||
| 1454 | |||
| 1455 | for p in [51, 52, 53, 55, 56] { | ||
| 1456 | relay::shutdown_relay(8000 + p)?; | ||
| 1457 | } | ||
| 1458 | Ok(()) | ||
| 1459 | }); | ||
| 1460 | |||
| 1461 | // launch relay | ||
| 1462 | let _ = join!( | ||
| 1463 | r51.listen_until_close(), | ||
| 1464 | r52.listen_until_close(), | ||
| 1465 | r53.listen_until_close(), | ||
| 1466 | r55.listen_until_close(), | ||
| 1467 | r56.listen_until_close(), | ||
| 1468 | ); | ||
| 1469 | cli_tester_handle.join().unwrap()?; | ||
| 1470 | println!("{:?}", r55.events); | ||
| 1471 | Ok(()) | ||
| 1472 | } | ||
| 1473 | |||
| 1474 | #[tokio::test] | ||
| 1475 | #[serial] | ||
| 1476 | async fn prompts_to_choose_from_proposal_titles() -> Result<()> { | ||
| 1477 | let _ = run_async_prompts_to_choose_from_proposal_titles().await; | ||
| 1478 | Ok(()) | ||
| 1479 | } | ||
| 1480 | } | ||
| 1481 | |||
| 1482 | #[tokio::test] | ||
| 1483 | #[serial] | ||
| 1484 | async fn proposal_branch_checked_out() -> Result<()> { | ||
| 1485 | let (_, test_repo) = prep_and_run().await?; | ||
| 1486 | assert_eq!( | ||
| 1487 | FEATURE_BRANCH_NAME_1, | ||
| 1488 | test_repo.get_checked_out_branch_name()?, | ||
| 1489 | ); | ||
| 1490 | Ok(()) | ||
| 1491 | } | ||
| 1492 | |||
| 1493 | #[tokio::test] | ||
| 1494 | #[serial] | ||
| 1495 | async fn proposal_branch_tip_is_most_recent_proposal_revision_tip() -> Result<()> { | ||
| 1496 | let (originating_repo, test_repo) = prep_and_run().await?; | ||
| 1497 | assert_eq!( | ||
| 1498 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | ||
| 1499 | test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | ||
| 1500 | ); | ||
| 1501 | Ok(()) | ||
| 1502 | } | ||
| 1198 | } | 1503 | } |
| 1199 | } | 1504 | } |
| 1200 | } | 1505 | } |