diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-22 12:18:01 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-22 12:18:01 +0000 |
| commit | 312786fbdacd61fc9f3ed59612d9a6add9112b7f (patch) | |
| tree | 660300df36b970c46c69d59893856bb6f03142b0 /tests | |
| parent | 79896914357ee322b08b302c3dde08c7a24a0a09 (diff) | |
feat(pull): support `--in-reply-to` revisions
added tests to cover one of these rebase scenarios
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/pull.rs | 296 |
1 files changed, 270 insertions, 26 deletions
diff --git a/tests/pull.rs b/tests/pull.rs index c4bc169..39f3ef4 100644 --- a/tests/pull.rs +++ b/tests/pull.rs | |||
| @@ -18,22 +18,22 @@ fn cli_tester_create_proposals() -> Result<GitTestRepo> { | |||
| 18 | &git_repo, | 18 | &git_repo, |
| 19 | FEATURE_BRANCH_NAME_1, | 19 | FEATURE_BRANCH_NAME_1, |
| 20 | "a", | 20 | "a", |
| 21 | PROPOSAL_TITLE_1, | 21 | Some((PROPOSAL_TITLE_1, "proposal a description")), |
| 22 | "proposal a description", | 22 | None, |
| 23 | )?; | 23 | )?; |
| 24 | cli_tester_create_proposal( | 24 | cli_tester_create_proposal( |
| 25 | &git_repo, | 25 | &git_repo, |
| 26 | FEATURE_BRANCH_NAME_2, | 26 | FEATURE_BRANCH_NAME_2, |
| 27 | "b", | 27 | "b", |
| 28 | PROPOSAL_TITLE_2, | 28 | Some((PROPOSAL_TITLE_2, "proposal b description")), |
| 29 | "proposal b description", | 29 | None, |
| 30 | )?; | 30 | )?; |
| 31 | cli_tester_create_proposal( | 31 | cli_tester_create_proposal( |
| 32 | &git_repo, | 32 | &git_repo, |
| 33 | FEATURE_BRANCH_NAME_3, | 33 | FEATURE_BRANCH_NAME_3, |
| 34 | "c", | 34 | "c", |
| 35 | PROPOSAL_TITLE_3, | 35 | Some((PROPOSAL_TITLE_3, "proposal c description")), |
| 36 | "proposal c description", | 36 | None, |
| 37 | )?; | 37 | )?; |
| 38 | Ok(git_repo) | 38 | Ok(git_repo) |
| 39 | } | 39 | } |
| @@ -66,27 +66,59 @@ fn cli_tester_create_proposal( | |||
| 66 | test_repo: &GitTestRepo, | 66 | test_repo: &GitTestRepo, |
| 67 | branch_name: &str, | 67 | branch_name: &str, |
| 68 | prefix: &str, | 68 | prefix: &str, |
| 69 | title: &str, | 69 | cover_letter_title_and_description: Option<(&str, &str)>, |
| 70 | description: &str, | 70 | in_reply_to: Option<String>, |
| 71 | ) -> Result<()> { | 71 | ) -> Result<()> { |
| 72 | create_and_populate_branch(test_repo, branch_name, prefix, false)?; | 72 | create_and_populate_branch(test_repo, branch_name, prefix, false)?; |
| 73 | 73 | ||
| 74 | let mut p = CliTester::new_from_dir( | 74 | if let Some(in_reply_to) = in_reply_to { |
| 75 | &test_repo.dir, | 75 | let mut p = CliTester::new_from_dir( |
| 76 | [ | 76 | &test_repo.dir, |
| 77 | "--nsec", | 77 | [ |
| 78 | TEST_KEY_1_NSEC, | 78 | "--nsec", |
| 79 | "--password", | 79 | TEST_KEY_1_NSEC, |
| 80 | TEST_PASSWORD, | 80 | "--password", |
| 81 | "--disable-cli-spinners", | 81 | TEST_PASSWORD, |
| 82 | "send", | 82 | "--disable-cli-spinners", |
| 83 | "--title", | 83 | "send", |
| 84 | format!("\"{title}\"").as_str(), | 84 | "--no-cover-letter", |
| 85 | "--description", | 85 | "--in-reply-to", |
| 86 | format!("\"{description}\"").as_str(), | 86 | in_reply_to.as_str(), |
| 87 | ], | 87 | ], |
| 88 | ); | 88 | ); |
| 89 | p.expect_end_eventually()?; | 89 | p.expect_end_eventually()?; |
| 90 | } else if let Some((title, description)) = cover_letter_title_and_description { | ||
| 91 | let mut p = CliTester::new_from_dir( | ||
| 92 | &test_repo.dir, | ||
| 93 | [ | ||
| 94 | "--nsec", | ||
| 95 | TEST_KEY_1_NSEC, | ||
| 96 | "--password", | ||
| 97 | TEST_PASSWORD, | ||
| 98 | "--disable-cli-spinners", | ||
| 99 | "send", | ||
| 100 | "--title", | ||
| 101 | format!("\"{title}\"").as_str(), | ||
| 102 | "--description", | ||
| 103 | format!("\"{description}\"").as_str(), | ||
| 104 | ], | ||
| 105 | ); | ||
| 106 | p.expect_end_eventually()?; | ||
| 107 | } else { | ||
| 108 | let mut p = CliTester::new_from_dir( | ||
| 109 | &test_repo.dir, | ||
| 110 | [ | ||
| 111 | "--nsec", | ||
| 112 | TEST_KEY_1_NSEC, | ||
| 113 | "--password", | ||
| 114 | TEST_PASSWORD, | ||
| 115 | "--disable-cli-spinners", | ||
| 116 | "send", | ||
| 117 | "--no-cover-letter", | ||
| 118 | ], | ||
| 119 | ); | ||
| 120 | p.expect_end_eventually()?; | ||
| 121 | } | ||
| 90 | Ok(()) | 122 | Ok(()) |
| 91 | } | 123 | } |
| 92 | 124 | ||
| @@ -415,7 +447,219 @@ mod when_branch_is_checked_out { | |||
| 415 | } | 447 | } |
| 416 | 448 | ||
| 417 | mod when_latest_event_rebases_branch { | 449 | mod when_latest_event_rebases_branch { |
| 418 | // use super::*; | 450 | use std::time::Duration; |
| 419 | // TODO | 451 | |
| 452 | use nostr_sdk::blocking::Client; | ||
| 453 | |||
| 454 | use super::*; | ||
| 455 | |||
| 456 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 457 | // fallback (51,52) user write (53, 55) repo (55, 56) | ||
| 458 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 459 | Relay::new(8051, None, None), | ||
| 460 | Relay::new(8052, None, None), | ||
| 461 | Relay::new(8053, None, None), | ||
| 462 | Relay::new(8055, None, None), | ||
| 463 | Relay::new(8056, None, None), | ||
| 464 | ); | ||
| 465 | |||
| 466 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 467 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 468 | r51.events.push(generate_repo_ref_event()); | ||
| 469 | |||
| 470 | r55.events.push(generate_repo_ref_event()); | ||
| 471 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 472 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 473 | |||
| 474 | let cli_tester_handle = | ||
| 475 | std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 476 | // create 3 proposals | ||
| 477 | let _ = cli_tester_create_proposals()?; | ||
| 478 | // get proposal id of first | ||
| 479 | let client = Client::new(&nostr::Keys::generate()); | ||
| 480 | client.add_relay("ws://localhost:8055")?; | ||
| 481 | client.connect_relay("ws://localhost:8055")?; | ||
| 482 | let proposals = client.get_events_of( | ||
| 483 | vec![ | ||
| 484 | nostr::Filter::default() | ||
| 485 | .kind(nostr::Kind::Custom(PATCH_KIND)) | ||
| 486 | .custom_tag(nostr::Alphabet::T, vec!["root"]), | ||
| 487 | ], | ||
| 488 | Some(Duration::from_millis(500)), | ||
| 489 | )?; | ||
| 490 | client.disconnect()?; | ||
| 491 | |||
| 492 | let proposal_1_id = proposals | ||
| 493 | .iter() | ||
| 494 | .find(|e| { | ||
| 495 | e.tags | ||
| 496 | .iter() | ||
| 497 | .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1)) | ||
| 498 | }) | ||
| 499 | .unwrap() | ||
| 500 | .id; | ||
| 501 | // recreate proposal 1 on top of a another commit (like a rebase on top | ||
| 502 | // of one extra commit) | ||
| 503 | let second_originating_repo = GitTestRepo::default(); | ||
| 504 | second_originating_repo.populate()?; | ||
| 505 | std::fs::write( | ||
| 506 | second_originating_repo.dir.join("amazing.md"), | ||
| 507 | "some content", | ||
| 508 | )?; | ||
| 509 | second_originating_repo.stage_and_commit("commit for rebasing on top of")?; | ||
| 510 | cli_tester_create_proposal( | ||
| 511 | &second_originating_repo, | ||
| 512 | FEATURE_BRANCH_NAME_1, | ||
| 513 | "a", | ||
| 514 | Some((PROPOSAL_TITLE_1, "proposal a description")), | ||
| 515 | Some(proposal_1_id.to_string()), | ||
| 516 | )?; | ||
| 517 | |||
| 518 | // pretend we have downloaded the origianl version of the first proposal | ||
| 519 | let test_repo = GitTestRepo::default(); | ||
| 520 | test_repo.populate()?; | ||
| 521 | create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; | ||
| 522 | // pretend we have pulled the updated main branch | ||
| 523 | test_repo.checkout("main")?; | ||
| 524 | std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; | ||
| 525 | test_repo.stage_and_commit("commit for rebasing on top of")?; | ||
| 526 | test_repo.checkout(FEATURE_BRANCH_NAME_1)?; | ||
| 527 | |||
| 528 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 529 | p.expect_end_eventually_and_print()?; | ||
| 530 | |||
| 531 | for p in [51, 52, 53, 55, 56] { | ||
| 532 | relay::shutdown_relay(8000 + p)?; | ||
| 533 | } | ||
| 534 | Ok((second_originating_repo, test_repo)) | ||
| 535 | }); | ||
| 536 | |||
| 537 | // launch relay | ||
| 538 | let _ = join!( | ||
| 539 | r51.listen_until_close(), | ||
| 540 | r52.listen_until_close(), | ||
| 541 | r53.listen_until_close(), | ||
| 542 | r55.listen_until_close(), | ||
| 543 | r56.listen_until_close(), | ||
| 544 | ); | ||
| 545 | let res = cli_tester_handle.join().unwrap()?; | ||
| 546 | |||
| 547 | Ok(res) | ||
| 548 | } | ||
| 549 | |||
| 550 | mod cli_prompts { | ||
| 551 | use super::*; | ||
| 552 | async fn run_async_prompts_to_choose_from_proposal_titles() -> Result<()> { | ||
| 553 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 554 | Relay::new(8051, None, None), | ||
| 555 | Relay::new(8052, None, None), | ||
| 556 | Relay::new(8053, None, None), | ||
| 557 | Relay::new(8055, None, None), | ||
| 558 | Relay::new(8056, None, None), | ||
| 559 | ); | ||
| 560 | |||
| 561 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 562 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 563 | r51.events.push(generate_repo_ref_event()); | ||
| 564 | |||
| 565 | r55.events.push(generate_repo_ref_event()); | ||
| 566 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 567 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 568 | |||
| 569 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 570 | // create 3 proposals | ||
| 571 | let _ = cli_tester_create_proposals()?; | ||
| 572 | // get proposal id of first | ||
| 573 | let client = Client::new(&nostr::Keys::generate()); | ||
| 574 | client.add_relay("ws://localhost:8055")?; | ||
| 575 | client.connect_relay("ws://localhost:8055")?; | ||
| 576 | let proposals = client.get_events_of( | ||
| 577 | vec![ | ||
| 578 | nostr::Filter::default() | ||
| 579 | .kind(nostr::Kind::Custom(PATCH_KIND)) | ||
| 580 | .custom_tag(nostr::Alphabet::T, vec!["root"]), | ||
| 581 | ], | ||
| 582 | Some(Duration::from_millis(500)), | ||
| 583 | )?; | ||
| 584 | client.disconnect()?; | ||
| 585 | |||
| 586 | let proposal_1_id = proposals | ||
| 587 | .iter() | ||
| 588 | .find(|e| { | ||
| 589 | e.tags | ||
| 590 | .iter() | ||
| 591 | .any(|t| t.as_vec()[1].eq(&FEATURE_BRANCH_NAME_1)) | ||
| 592 | }) | ||
| 593 | .unwrap() | ||
| 594 | .id; | ||
| 595 | // recreate proposal 1 on top of a another commit (like a rebase on top | ||
| 596 | // of one extra commit) | ||
| 597 | let second_originating_repo = GitTestRepo::default(); | ||
| 598 | second_originating_repo.populate()?; | ||
| 599 | std::fs::write( | ||
| 600 | second_originating_repo.dir.join("amazing.md"), | ||
| 601 | "some content", | ||
| 602 | )?; | ||
| 603 | second_originating_repo.stage_and_commit("commit for rebasing on top of")?; | ||
| 604 | cli_tester_create_proposal( | ||
| 605 | &second_originating_repo, | ||
| 606 | FEATURE_BRANCH_NAME_1, | ||
| 607 | "a", | ||
| 608 | Some((PROPOSAL_TITLE_1, "proposal a description")), | ||
| 609 | Some(proposal_1_id.to_string()), | ||
| 610 | )?; | ||
| 611 | |||
| 612 | // pretend we have downloaded the origianl version of the first proposal | ||
| 613 | let test_repo = GitTestRepo::default(); | ||
| 614 | test_repo.populate()?; | ||
| 615 | create_and_populate_branch(&test_repo, FEATURE_BRANCH_NAME_1, "a", false)?; | ||
| 616 | // pretend we have pulled the updated main branch | ||
| 617 | test_repo.checkout("main")?; | ||
| 618 | std::fs::write(test_repo.dir.join("amazing.md"), "some content")?; | ||
| 619 | test_repo.stage_and_commit("commit for rebasing on top of")?; | ||
| 620 | test_repo.checkout(FEATURE_BRANCH_NAME_1)?; | ||
| 621 | |||
| 622 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["pull"]); | ||
| 623 | p.expect("finding proposal root event...\r\n")?; | ||
| 624 | p.expect("found proposal root event. finding commits...\r\n")?; | ||
| 625 | p.expect_end_with("pulled new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?; | ||
| 626 | |||
| 627 | for p in [51, 52, 53, 55, 56] { | ||
| 628 | relay::shutdown_relay(8000 + p)?; | ||
| 629 | } | ||
| 630 | Ok(()) | ||
| 631 | }); | ||
| 632 | |||
| 633 | // launch relay | ||
| 634 | let _ = join!( | ||
| 635 | r51.listen_until_close(), | ||
| 636 | r52.listen_until_close(), | ||
| 637 | r53.listen_until_close(), | ||
| 638 | r55.listen_until_close(), | ||
| 639 | r56.listen_until_close(), | ||
| 640 | ); | ||
| 641 | cli_tester_handle.join().unwrap()?; | ||
| 642 | println!("{:?}", r55.events); | ||
| 643 | Ok(()) | ||
| 644 | } | ||
| 645 | |||
| 646 | #[tokio::test] | ||
| 647 | #[serial] | ||
| 648 | async fn prompts_to_choose_from_proposal_titles() -> Result<()> { | ||
| 649 | let _ = run_async_prompts_to_choose_from_proposal_titles().await; | ||
| 650 | Ok(()) | ||
| 651 | } | ||
| 652 | } | ||
| 653 | |||
| 654 | #[tokio::test] | ||
| 655 | #[serial] | ||
| 656 | async fn proposal_branch_tip_is_most_recent_proposal_revision_tip() -> Result<()> { | ||
| 657 | let (originating_repo, test_repo) = prep_and_run().await?; | ||
| 658 | assert_eq!( | ||
| 659 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | ||
| 660 | test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | ||
| 661 | ); | ||
| 662 | Ok(()) | ||
| 663 | } | ||
| 420 | } | 664 | } |
| 421 | } | 665 | } |