diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/git_remote_helper.rs | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/tests/git_remote_helper.rs b/tests/git_remote_helper.rs index dc6d931..379954d 100644 --- a/tests/git_remote_helper.rs +++ b/tests/git_remote_helper.rs | |||
| @@ -1856,4 +1856,157 @@ mod push { | |||
| 1856 | 1856 | ||
| 1857 | Ok(()) | 1857 | Ok(()) |
| 1858 | } | 1858 | } |
| 1859 | |||
| 1860 | #[tokio::test] | ||
| 1861 | #[serial] | ||
| 1862 | async fn force_push_creates_proposal_revision() -> Result<()> { | ||
| 1863 | let (events, source_git_repo) = prep_source_repo_and_events_including_proposals().await?; | ||
| 1864 | let source_path = source_git_repo.dir.to_str().unwrap().to_string(); | ||
| 1865 | |||
| 1866 | let (mut r51, mut r52, mut r53, mut r55, mut r56, mut r57) = ( | ||
| 1867 | Relay::new(8051, None, None), | ||
| 1868 | Relay::new(8052, None, None), | ||
| 1869 | Relay::new(8053, None, None), | ||
| 1870 | Relay::new(8055, None, None), | ||
| 1871 | Relay::new(8056, None, None), | ||
| 1872 | Relay::new(8057, None, None), | ||
| 1873 | ); | ||
| 1874 | r51.events = events.clone(); | ||
| 1875 | r55.events = events.clone(); | ||
| 1876 | |||
| 1877 | let before = r55.events.iter().cloned().collect::<HashSet<Event>>(); | ||
| 1878 | |||
| 1879 | let cli_tester_handle = std::thread::spawn(move || -> Result<(String, String)> { | ||
| 1880 | let branch_name = get_proposal_branch_name_from_events(&events, FEATURE_BRANCH_NAME_1)?; | ||
| 1881 | |||
| 1882 | let git_repo = clone_git_repo_with_nostr_url()?; | ||
| 1883 | let oid = git_repo.checkout_remote_branch(&branch_name)?; | ||
| 1884 | // remove last commit | ||
| 1885 | git_repo.checkout("main")?; | ||
| 1886 | git_repo.git_repo.branch( | ||
| 1887 | &branch_name, | ||
| 1888 | &git_repo.git_repo.find_commit(oid)?.parent(0)?, | ||
| 1889 | true, | ||
| 1890 | )?; | ||
| 1891 | git_repo.checkout(&branch_name)?; | ||
| 1892 | |||
| 1893 | std::fs::write(git_repo.dir.join("new.md"), "some content")?; | ||
| 1894 | git_repo.stage_and_commit("new.md")?; | ||
| 1895 | |||
| 1896 | std::fs::write(git_repo.dir.join("new2.md"), "some content")?; | ||
| 1897 | git_repo.stage_and_commit("new2.md")?; | ||
| 1898 | |||
| 1899 | let mut p = | ||
| 1900 | CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, ["push", "--force"]); | ||
| 1901 | cli_expect_nostr_fetch(&mut p)?; | ||
| 1902 | p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; | ||
| 1903 | p.expect(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; | ||
| 1904 | let output = p.expect_end_eventually()?; | ||
| 1905 | |||
| 1906 | for p in [51, 52, 53, 55, 56, 57] { | ||
| 1907 | relay::shutdown_relay(8000 + p)?; | ||
| 1908 | } | ||
| 1909 | |||
| 1910 | Ok((output, branch_name)) | ||
| 1911 | }); | ||
| 1912 | // launch relays | ||
| 1913 | let _ = join!( | ||
| 1914 | r51.listen_until_close(), | ||
| 1915 | r52.listen_until_close(), | ||
| 1916 | r53.listen_until_close(), | ||
| 1917 | r55.listen_until_close(), | ||
| 1918 | r56.listen_until_close(), | ||
| 1919 | r57.listen_until_close(), | ||
| 1920 | ); | ||
| 1921 | |||
| 1922 | let (output, branch_name) = cli_tester_handle.join().unwrap()?; | ||
| 1923 | |||
| 1924 | assert_eq!( | ||
| 1925 | output, | ||
| 1926 | format!(" + eb5d678...8a296c8 {branch_name} -> {branch_name} (forced update)\r\n") | ||
| 1927 | .as_str(), | ||
| 1928 | ); | ||
| 1929 | |||
| 1930 | let new_events = r55 | ||
| 1931 | .events | ||
| 1932 | .iter() | ||
| 1933 | .cloned() | ||
| 1934 | .collect::<HashSet<Event>>() | ||
| 1935 | .difference(&before) | ||
| 1936 | .cloned() | ||
| 1937 | .collect::<Vec<Event>>(); | ||
| 1938 | assert_eq!(new_events.len(), 3); | ||
| 1939 | |||
| 1940 | let proposal = r55 | ||
| 1941 | .events | ||
| 1942 | .iter() | ||
| 1943 | .find(|e| { | ||
| 1944 | e.iter_tags() | ||
| 1945 | .find(|t| t.as_vec()[0].eq("branch-name")) | ||
| 1946 | .is_some_and(|t| t.as_vec()[1].eq(FEATURE_BRANCH_NAME_1)) | ||
| 1947 | }) | ||
| 1948 | .unwrap(); | ||
| 1949 | |||
| 1950 | let revision_root_patch = new_events | ||
| 1951 | .iter() | ||
| 1952 | .find(|e| e.iter_tags().any(|t| t.as_vec()[1].eq("revision-root"))) | ||
| 1953 | .unwrap(); | ||
| 1954 | |||
| 1955 | assert_eq!( | ||
| 1956 | proposal.id().to_string(), | ||
| 1957 | revision_root_patch | ||
| 1958 | .tags | ||
| 1959 | .iter() | ||
| 1960 | .find(|t| t.is_reply()) | ||
| 1961 | .unwrap() | ||
| 1962 | .as_vec()[1], | ||
| 1963 | "revision root patch replies to original proposal" | ||
| 1964 | ); | ||
| 1965 | |||
| 1966 | assert!( | ||
| 1967 | revision_root_patch.content.contains("[PATCH 1/3]"), | ||
| 1968 | "revision root labeled with [PATCH 1/3]" | ||
| 1969 | ); | ||
| 1970 | |||
| 1971 | let second_patch = new_events | ||
| 1972 | .iter() | ||
| 1973 | .find(|e| e.content.contains("new.md")) | ||
| 1974 | .unwrap(); | ||
| 1975 | let third_patch = new_events | ||
| 1976 | .iter() | ||
| 1977 | .find(|e| e.content.contains("new2.md")) | ||
| 1978 | .unwrap(); | ||
| 1979 | assert!( | ||
| 1980 | second_patch.content.contains("[PATCH 2/3]"), | ||
| 1981 | "second patch labeled with [PATCH 2/3]" | ||
| 1982 | ); | ||
| 1983 | assert!( | ||
| 1984 | third_patch.content.contains("[PATCH 3/3]"), | ||
| 1985 | "third patch labeled with [PATCH 3/3]" | ||
| 1986 | ); | ||
| 1987 | |||
| 1988 | assert_eq!( | ||
| 1989 | revision_root_patch.id().to_string(), | ||
| 1990 | second_patch | ||
| 1991 | .tags | ||
| 1992 | .iter() | ||
| 1993 | .find(|t| t.is_root()) | ||
| 1994 | .unwrap() | ||
| 1995 | .as_vec()[1], | ||
| 1996 | "second patch sets revision id as root" | ||
| 1997 | ); | ||
| 1998 | |||
| 1999 | assert_eq!( | ||
| 2000 | second_patch.id().to_string(), | ||
| 2001 | third_patch | ||
| 2002 | .tags | ||
| 2003 | .iter() | ||
| 2004 | .find(|t| t.is_reply()) | ||
| 2005 | .unwrap() | ||
| 2006 | .as_vec()[1], | ||
| 2007 | "third patch replies to the second new patch" | ||
| 2008 | ); | ||
| 2009 | |||
| 2010 | Ok(()) | ||
| 2011 | } | ||
| 1859 | } | 2012 | } |