upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-02-22 12:58:12 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-02-22 12:58:12 +0000
commit70dd57966969f24fb81aabe412fb3667486f87b5 (patch)
treebe309b7252bb2d3e500b03e89656da08a88af390
parent312786fbdacd61fc9f3ed59612d9a6add9112b7f (diff)
test(list): local commits on uptodate proposal
add test for scenario and tweak copy
-rw-r--r--src/sub_commands/list.rs62
-rw-r--r--tests/list.rs203
2 files changed, 228 insertions, 37 deletions
diff --git a/src/sub_commands/list.rs b/src/sub_commands/list.rs
index fbf04a9..6c620ad 100644
--- a/src/sub_commands/list.rs
+++ b/src/sub_commands/list.rs
@@ -369,6 +369,7 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
369 }; 369 };
370 } 370 }
371 371
372 // new proposal revision / rebase
372 // tip of local in proposal history (new, ammended or rebased version but no 373 // tip of local in proposal history (new, ammended or rebased version but no
373 // local changes) 374 // local changes)
374 if commits_events.iter().any(|patch| { 375 if commits_events.iter().any(|patch| {
@@ -436,43 +437,42 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
436 }; 437 };
437 } 438 }
438 439
439 // TODO: write tests
440 // tip of proposal in branch in history (local appendments made to up-to-date 440 // tip of proposal in branch in history (local appendments made to up-to-date
441 // proposal) 441 // proposal)
442 if let Ok((local_ahead_of_proposal, _)) = 442 if let Ok((local_ahead_of_proposal, _)) =
443 git_repo.get_commits_ahead_behind(&proposal_tip, &local_branch_tip) 443 git_repo.get_commits_ahead_behind(&proposal_tip, &local_branch_tip)
444 { 444 {
445 println!( 445 println!(
446 "local proposal branch exists with {} unpublished commits on top of the most up-to-date version of the proposal", 446 "local proposal branch exists with {} unpublished commits on top of the most up-to-date version of the proposal ({} ahead {} behind '{main_branch_name}')",
447 local_ahead_of_proposal.len() 447 local_ahead_of_proposal.len(),
448 local_ahead_of_main.len(),
449 proposal_behind_main.len(),
448 ); 450 );
449 return match Interactor::default().choice( 451 return match Interactor::default().choice(
450 PromptChoiceParms::default().with_default(0) 452 PromptChoiceParms::default()
451 .with_choices( 453 .with_default(0)
452 vec![ 454 .with_choices(vec![
453 format!(
454 "checkout proposal branch with {} unpublished commits ({} ahead {} behind '{main_branch_name}')",
455 local_ahead_of_proposal.len(),
456 local_ahead_of_main.len(),
457 proposal_behind_main.len(),
458 ),
459 "back".to_string(),
460 ],
461 )
462 )? {
463 0 => {
464 git_repo.checkout(&cover_letter.branch_name)?;
465 format!( 455 format!(
466 "checked out proposal branch with {} unpublished commits ({} ahead {} behind '{main_branch_name}')", 456 "checkout proposal branch with {} unpublished commits",
467 local_ahead_of_proposal.len(), 457 local_ahead_of_proposal.len(),
468 local_ahead_of_main.len(), 458 ),
469 proposal_behind_main.len(), 459 "back".to_string(),
470 ); 460 ]),
471 Ok(()) 461 )? {
472 462 0 => {
473 }, 463 git_repo.checkout(&cover_letter.branch_name)?;
474 1 => { continue }, 464 println!(
475 _ => { bail!("unexpected choice")} 465 "checked out proposal branch with {} unpublished commits ({} ahead {} behind '{main_branch_name}')",
466 local_ahead_of_proposal.len(),
467 local_ahead_of_main.len(),
468 proposal_behind_main.len(),
469 );
470 Ok(())
471 }
472 1 => continue,
473 _ => {
474 bail!("unexpected choice")
475 }
476 }; 476 };
477 } 477 }
478 478
@@ -516,7 +516,7 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
516 0 => { 516 0 => {
517 check_clean(&git_repo)?; 517 check_clean(&git_repo)?;
518 git_repo.checkout(&cover_letter.branch_name)?; 518 git_repo.checkout(&cover_letter.branch_name)?;
519 format!( 519 println!(
520 "checked out old proposal in existing branch ({} ahead {} behind '{main_branch_name}')", 520 "checked out old proposal in existing branch ({} ahead {} behind '{main_branch_name}')",
521 local_ahead_of_main.len(), 521 local_ahead_of_main.len(),
522 local_beind_main.len(), 522 local_beind_main.len(),
@@ -531,7 +531,7 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
531 let _ = git_repo 531 let _ = git_repo
532 .apply_patch_chain(&cover_letter.branch_name, most_recent_proposal_patch_chain) 532 .apply_patch_chain(&cover_letter.branch_name, most_recent_proposal_patch_chain)
533 .context("cannot apply patch chain")?; 533 .context("cannot apply patch chain")?;
534 format!( 534 println!(
535 "checked out new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}')", 535 "checked out new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}')",
536 chain_length, 536 chain_length,
537 proposal_behind_main.len(), 537 proposal_behind_main.len(),
@@ -596,7 +596,7 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
596 0 => { 596 0 => {
597 check_clean(&git_repo)?; 597 check_clean(&git_repo)?;
598 git_repo.checkout(&cover_letter.branch_name)?; 598 git_repo.checkout(&cover_letter.branch_name)?;
599 format!( 599 println!(
600 "checked out old proposal in existing branch ({} ahead {} behind '{main_branch_name}')", 600 "checked out old proposal in existing branch ({} ahead {} behind '{main_branch_name}')",
601 local_ahead_of_main.len(), 601 local_ahead_of_main.len(),
602 local_beind_main.len(), 602 local_beind_main.len(),
@@ -611,7 +611,7 @@ pub async fn launch(_cli_args: &Cli, _args: &SubCommandArgs) -> Result<()> {
611 let _ = git_repo 611 let _ = git_repo
612 .apply_patch_chain(&cover_letter.branch_name, most_recent_proposal_patch_chain) 612 .apply_patch_chain(&cover_letter.branch_name, most_recent_proposal_patch_chain)
613 .context("cannot apply patch chain")?; 613 .context("cannot apply patch chain")?;
614 format!( 614 println!(
615 "checked out new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}'). consider creating a temporary branch with your existing unchanges first.", 615 "checked out new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}'). consider creating a temporary branch with your existing unchanges first.",
616 chain_length, 616 chain_length,
617 proposal_behind_main.len(), 617 proposal_behind_main.len(),
diff --git a/tests/list.rs b/tests/list.rs
index eb6dc3d..3f96da1 100644
--- a/tests/list.rs
+++ b/tests/list.rs
@@ -1208,14 +1208,205 @@ mod when_main_branch_is_uptodate {
1208 } 1208 }
1209 } 1209 }
1210 1210
1211 mod when_branch_is_ahead { 1211 mod when_local_commits_on_uptodate_proposal {
1212 // use super::*; 1212 use super::*;
1213 // TODO latest commit in proposal builds off an older commit in 1213 async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> {
1214 // proposal instead of previous. 1214 // fallback (51,52) user write (53, 55) repo (55, 56)
1215 // TODO current git user created commit on branch 1215 let (mut r51, mut r52, mut r53, mut r55, mut r56) = (
1216 Relay::new(8051, None, None),
1217 Relay::new(8052, None, None),
1218 Relay::new(8053, None, None),
1219 Relay::new(8055, None, None),
1220 Relay::new(8056, None, None),
1221 );
1222
1223 r51.events.push(generate_test_key_1_relay_list_event());
1224 r51.events.push(generate_test_key_1_metadata_event("fred"));
1225 r51.events.push(generate_repo_ref_event());
1226
1227 r55.events.push(generate_repo_ref_event());
1228 r55.events.push(generate_test_key_1_metadata_event("fred"));
1229 r55.events.push(generate_test_key_1_relay_list_event());
1230
1231 let cli_tester_handle = std::thread::spawn(
1232 move || -> Result<(GitTestRepo, GitTestRepo)> {
1233 let originating_repo = cli_tester_create_proposals()?;
1234
1235 let test_repo = GitTestRepo::default();
1236 test_repo.populate()?;
1237 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1238
1239 create_and_populate_branch(
1240 &test_repo,
1241 FEATURE_BRANCH_NAME_1,
1242 "a",
1243 false,
1244 )?;
1245 // add appended commit to local branch
1246 std::fs::write(test_repo.dir.join("appended.md"), "some content")?;
1247 test_repo.stage_and_commit("appended commit")?;
1248
1249 test_repo.checkout("main")?;
1250 p.expect("finding proposals...\r\n")?;
1251 let mut c = p.expect_choice(
1252 "all proposals",
1253 vec![
1254 format!("\"{PROPOSAL_TITLE_1}\""),
1255 format!("\"{PROPOSAL_TITLE_2}\""),
1256 format!("\"{PROPOSAL_TITLE_3}\""),
1257 ],
1258 )?;
1259 c.succeeds_with(0, true, None)?;
1260 p.expect("finding commits...\r\n")?;
1261 p.expect(
1262 "local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal (3 ahead 0 behind 'main')\r\n",
1263 )?;
1264
1265 let mut c = p.expect_choice(
1266 "",
1267 vec![
1268 format!("checkout proposal branch with 1 unpublished commits"),
1269 format!("back"),
1270 ],
1271 )?;
1272 c.succeeds_with(0, false, Some(0))?;
1273 p.expect("checked out proposal branch with 1 unpublished commits (3 ahead 0 behind 'main')\r\n")?;
1274 p.expect_end()?;
1275
1276 for p in [51, 52, 53, 55, 56] {
1277 relay::shutdown_relay(8000 + p)?;
1278 }
1279 Ok((originating_repo, test_repo))
1280 },
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 let res = cli_tester_handle.join().unwrap()?;
1292
1293 Ok(res)
1294 }
1295
1296 mod cli_prompts {
1297 use super::*;
1298 async fn run_async_prompts_to_choose_from_proposal_titles() -> Result<()> {
1299 let (mut r51, mut r52, mut r53, mut r55, mut r56) = (
1300 Relay::new(8051, None, None),
1301 Relay::new(8052, None, None),
1302 Relay::new(8053, None, None),
1303 Relay::new(8055, None, None),
1304 Relay::new(8056, None, None),
1305 );
1306
1307 r51.events.push(generate_test_key_1_relay_list_event());
1308 r51.events.push(generate_test_key_1_metadata_event("fred"));
1309 r51.events.push(generate_repo_ref_event());
1310
1311 r55.events.push(generate_repo_ref_event());
1312 r55.events.push(generate_test_key_1_metadata_event("fred"));
1313 r55.events.push(generate_test_key_1_relay_list_event());
1314
1315 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
1316 cli_tester_create_proposals()?;
1317
1318 let test_repo = GitTestRepo::default();
1319 test_repo.populate()?;
1320 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1321
1322 create_and_populate_branch(
1323 &test_repo,
1324 FEATURE_BRANCH_NAME_1,
1325 "a",
1326 false,
1327 )?;
1328 // add appended commit to local branch
1329 std::fs::write(test_repo.dir.join("appended.md"), "some content")?;
1330 test_repo.stage_and_commit("appended commit")?;
1331
1332 test_repo.checkout("main")?;
1333 p.expect("finding proposals...\r\n")?;
1334 let mut c = p.expect_choice(
1335 "all proposals",
1336 vec![
1337 format!("\"{PROPOSAL_TITLE_1}\""),
1338 format!("\"{PROPOSAL_TITLE_2}\""),
1339 format!("\"{PROPOSAL_TITLE_3}\""),
1340 ],
1341 )?;
1342 c.succeeds_with(0, true, None)?;
1343 p.expect("finding commits...\r\n")?;
1344 p.expect(
1345 "local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal (3 ahead 0 behind 'main')\r\n",
1346 )?;
1347
1348 let mut c = p.expect_choice(
1349 "",
1350 vec![
1351 format!("checkout proposal branch with 1 unpublished commits"),
1352 format!("back"),
1353 ],
1354 )?;
1355 c.succeeds_with(0, false, Some(0))?;
1356 p.expect("checked out proposal branch with 1 unpublished commits (3 ahead 0 behind 'main')\r\n")?;
1357 p.expect_end()?;
1358
1359 for p in [51, 52, 53, 55, 56] {
1360 relay::shutdown_relay(8000 + p)?;
1361 }
1362 Ok(())
1363 });
1364
1365 // launch relay
1366 let _ = join!(
1367 r51.listen_until_close(),
1368 r52.listen_until_close(),
1369 r53.listen_until_close(),
1370 r55.listen_until_close(),
1371 r56.listen_until_close(),
1372 );
1373 cli_tester_handle.join().unwrap()?;
1374 println!("{:?}", r55.events);
1375 Ok(())
1376 }
1377
1378 #[tokio::test]
1379 #[serial]
1380 async fn prompts_to_choose_from_proposal_titles() -> Result<()> {
1381 let _ = run_async_prompts_to_choose_from_proposal_titles().await;
1382 Ok(())
1383 }
1384 }
1385
1386 #[tokio::test]
1387 #[serial]
1388 async fn proposal_branch_checked_out() -> Result<()> {
1389 let (_, test_repo) = prep_and_run().await?;
1390 assert_eq!(
1391 FEATURE_BRANCH_NAME_1,
1392 test_repo.get_checked_out_branch_name()?,
1393 );
1394 Ok(())
1395 }
1396
1397 #[tokio::test]
1398 #[serial]
1399 async fn didnt_overwrite_local_appendments() -> Result<()> {
1400 let (originating_repo, test_repo) = prep_and_run().await?;
1401 assert_ne!(
1402 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
1403 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
1404 );
1405 Ok(())
1406 }
1216 } 1407 }
1217 1408
1218 mod when_latest_event_rebases_branch { 1409 mod when_latest_revision_rebases_branch {
1219 use std::time::Duration; 1410 use std::time::Duration;
1220 1411
1221 use super::*; 1412 use super::*;