From 4ee83e2fe5335a8afd78439c35f029c4a472e797 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 16 Dec 2024 09:00:46 +0000 Subject: chore: bump nix flake rust nightly `fmt` overlay update the rust nightly `fmt` overlay which needs to be pinned to a specific version (this case by date) update formatting in main files via `cargo fmt` --- flake.nix | 2 +- rustfmt.toml | 2 +- src/bin/git_remote_nostr/fetch.rs | 10 +- src/bin/git_remote_nostr/list.rs | 6 +- src/bin/git_remote_nostr/main.rs | 6 +- src/bin/git_remote_nostr/push.rs | 62 ++-- src/bin/git_remote_nostr/utils.rs | 17 +- src/bin/ngit/cli.rs | 2 +- src/bin/ngit/sub_commands/export_keys.rs | 2 +- src/bin/ngit/sub_commands/init.rs | 12 +- src/bin/ngit/sub_commands/list.rs | 19 +- src/bin/ngit/sub_commands/login.rs | 4 +- src/bin/ngit/sub_commands/logout.rs | 2 +- src/bin/ngit/sub_commands/send.rs | 17 +- src/lib/cli_interactor.rs | 2 +- src/lib/client.rs | 140 ++++----- src/lib/git/identify_ahead_behind.rs | 8 +- src/lib/git/mod.rs | 87 +++--- src/lib/git/nostr_url.rs | 136 ++++----- src/lib/git_events.rs | 22 +- src/lib/login/existing.rs | 8 +- src/lib/login/fresh.rs | 10 +- src/lib/login/mod.rs | 14 +- src/lib/login/user.rs | 4 +- src/lib/mod.rs | 2 +- src/lib/repo_ref.rs | 46 ++- test_utils/src/lib.rs | 203 ++++++------- test_utils/src/relay.rs | 2 +- tests/git_remote_nostr/main.rs | 2 +- tests/git_remote_nostr/push.rs | 30 +- tests/ngit_init.rs | 36 +-- tests/ngit_list.rs | 488 +++++++++++++------------------ tests/ngit_login.rs | 352 +++++++++------------- tests/ngit_send.rs | 246 ++++++---------- 34 files changed, 830 insertions(+), 1171 deletions(-) diff --git a/flake.nix b/flake.nix index 096727d..a642221 100644 --- a/flake.nix +++ b/flake.nix @@ -23,7 +23,7 @@ # ideally this wouldn't be pinned to a specific nightly version but # selectLatestNightlyWith isn't support with mixed toolchains # https://github.com/oxalica/rust-overlay/issues/136 - (lib.hiPrio rust-bin.nightly."2024-09-17".rustfmt) + (lib.hiPrio rust-bin.nightly."2024-12-15".rustfmt) # (rust-bin.stable.latest.override { extensions = [ "rust-analyzer" ]; }) rust-bin.stable.latest.default ]; diff --git a/rustfmt.toml b/rustfmt.toml index bcf7279..0869bdf 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,5 +1,5 @@ unstable_features = true -version = "Two" +style_edition = "2024" # Imports imports_granularity = "Crate" diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs index 458c6d8..7012955 100644 --- a/src/bin/git_remote_nostr/fetch.rs +++ b/src/bin/git_remote_nostr/fetch.rs @@ -6,15 +6,15 @@ use std::{ time::Instant, }; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{Context, Result, anyhow, bail}; use auth_git2::GitAuthenticator; use git2::{Progress, Repository}; use ngit::{ cli_interactor::count_lines_per_msg_vec, git::{ + Repo, RepoActions, nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, utils::check_ssh_keys, - Repo, RepoActions, }, git_events::tag_value, login::get_curent_user, @@ -24,9 +24,9 @@ use nostr::nips::nip19; use nostr_sdk::{Event, ToBech32}; use crate::utils::{ - fetch_or_list_error_is_not_authentication_failure, find_proposal_and_patches_by_branch_name, - get_oids_from_fetch_batch, get_open_proposals, get_read_protocols_to_try, join_with_and, - set_protocol_preference, Direction, + Direction, fetch_or_list_error_is_not_authentication_failure, + find_proposal_and_patches_by_branch_name, get_oids_from_fetch_batch, get_open_proposals, + get_read_protocols_to_try, join_with_and, set_protocol_preference, }; pub async fn run_fetch( diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs index 9171544..bba15aa 100644 --- a/src/bin/git_remote_nostr/list.rs +++ b/src/bin/git_remote_nostr/list.rs @@ -1,7 +1,7 @@ use core::str; use std::collections::HashMap; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use auth_git2::GitAuthenticator; use client::get_state_from_cache; use git::RepoActions; @@ -22,9 +22,9 @@ use crate::{ fetch::{fetch_from_git_server, make_commits_for_proposal}, git::Repo, utils::{ - fetch_or_list_error_is_not_authentication_failure, get_open_proposals, + Direction, fetch_or_list_error_is_not_authentication_failure, get_open_proposals, get_read_protocols_to_try, get_short_git_server_name, join_with_and, - set_protocol_preference, Direction, + set_protocol_preference, }, }; diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs index 1a21341..e6f7af3 100644 --- a/src/bin/git_remote_nostr/main.rs +++ b/src/bin/git_remote_nostr/main.rs @@ -11,9 +11,9 @@ use std::{ path::{Path, PathBuf}, }; -use anyhow::{bail, Context, Result}; -use client::{consolidate_fetch_reports, get_repo_ref_from_cache, Connect}; -use git::{nostr_url::NostrUrlDecoded, RepoActions}; +use anyhow::{Context, Result, bail}; +use client::{Connect, consolidate_fetch_reports, get_repo_ref_from_cache}; +use git::{RepoActions, nostr_url::NostrUrlDecoded}; use ngit::{client, git, login::existing::load_existing_login}; use nostr::nips::nip01::Coordinate; use utils::read_line; diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index f2ac169..e8e1587 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs @@ -6,17 +6,17 @@ use std::{ time::Instant, }; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{Context, Result, anyhow, bail}; use auth_git2::GitAuthenticator; use client::{ - get_events_from_local_cache, get_state_from_cache, send_events, sign_event, STATE_KIND, + STATE_KIND, get_events_from_local_cache, get_state_from_cache, send_events, sign_event, }; use console::Term; -use git::{sha1_to_oid, RepoActions}; -use git2::{Oid, Repository}; +use git::{RepoActions, sha1_to_oid}; use git_events::{ generate_cover_letter_and_patch_events, generate_patch_event, get_commit_id_from_patch, }; +use git2::{Oid, Repository}; use ngit::{ cli_interactor::count_lines_per_msg_vec, client::{self, get_event_from_cache_by_id}, @@ -32,8 +32,8 @@ use ngit::{ }; use nostr::nips::nip10::Marker; use nostr_sdk::{ - hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, Kind, NostrSigner, PublicKey, - RelayUrl, Tag, + Event, EventBuilder, EventId, Kind, NostrSigner, PublicKey, RelayUrl, Tag, + hashes::sha1::Hash as Sha1Hash, }; use repo_ref::RepoRef; use repo_state::RepoState; @@ -43,9 +43,10 @@ use crate::{ git::Repo, list::list_from_remotes, utils::{ - find_proposal_and_patches_by_branch_name, get_all_proposals, get_remote_name_by_url, - get_short_git_server_name, get_write_protocols_to_try, join_with_and, - push_error_is_not_authentication_failure, read_line, set_protocol_preference, Direction, + Direction, find_proposal_and_patches_by_branch_name, get_all_proposals, + get_remote_name_by_url, get_short_git_server_name, get_write_protocols_to_try, + join_with_and, push_error_is_not_authentication_failure, read_line, + set_protocol_preference, }, }; @@ -1023,13 +1024,10 @@ async fn get_merged_status_events( let (ahead, _) = git_repo.get_commits_ahead_behind(&tip_of_remote_branch, &tip_of_pushed_branch)?; - let commit_events = get_events_from_local_cache( - git_repo.get_path()?, - vec![ - nostr::Filter::default().kind(nostr::Kind::GitPatch), - // TODO: limit by repo_ref - ], - ) + let commit_events = get_events_from_local_cache(git_repo.get_path()?, vec![ + nostr::Filter::default().kind(nostr::Kind::GitPatch), + // TODO: limit by repo_ref + ]) .await?; let merged_proposals_info = @@ -1106,12 +1104,9 @@ async fn get_merged_proposals_info( proposals.entry(proposal_id).or_default(); // ignore revisions without all the merged commits if entry_revision_id == &revision_id { - merged_patches.insert( - *commit_hash, - MergedPRCommitType::PatchCommit { - event_id: patch_event.id, - }, - ); + merged_patches.insert(*commit_hash, MergedPRCommitType::PatchCommit { + event_id: patch_event.id, + }); } } } @@ -1136,12 +1131,9 @@ async fn get_merged_proposals_info( proposals.entry(proposal_id).or_default(); // ignore revisions without all the applied commits if entry_revision_id == &revision_id { - merged_patches.insert( - *commit_hash, - MergedPRCommitType::PatchApplied { - event_id: patch_event.id, - }, - ); + merged_patches.insert(*commit_hash, MergedPRCommitType::PatchApplied { + event_id: patch_event.id, + }); } } } @@ -1379,10 +1371,9 @@ async fn get_proposal_and_revision_root_from_patch( .clone(), )?; - get_events_from_local_cache( - git_repo.get_path()?, - vec![nostr::Filter::default().id(proposal_or_revision_id)], - ) + get_events_from_local_cache(git_repo.get_path()?, vec![ + nostr::Filter::default().id(proposal_or_revision_id), + ]) .await? .first() .unwrap() @@ -1538,10 +1529,9 @@ impl BuildRepoState for RepoState { ) -> Result { let mut tags = vec![Tag::identifier(identifier.clone())]; for (name, value) in &state { - tags.push(Tag::custom( - nostr_sdk::TagKind::Custom(name.into()), - vec![value.clone()], - )); + tags.push(Tag::custom(nostr_sdk::TagKind::Custom(name.into()), vec![ + value.clone(), + ])); } let event = sign_event(EventBuilder::new(STATE_KIND, "").tags(tags), signer).await?; Ok(RepoState { diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs index 8e89652..15ebb10 100644 --- a/src/bin/git_remote_nostr/utils.rs +++ b/src/bin/git_remote_nostr/utils.rs @@ -6,7 +6,7 @@ use std::{ str::FromStr, }; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use git2::Repository; use ngit::{ client::{ @@ -14,8 +14,8 @@ use ngit::{ get_proposals_and_revisions_from_cache, }, git::{ - nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, Repo, RepoActions, + nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, }, git_events::{ event_is_revision_root, get_most_recent_patch_with_ancestors, @@ -108,14 +108,11 @@ pub async fn get_open_proposals( .collect(); let statuses: Vec = { - let mut statuses = get_events_from_local_cache( - git_repo_path, - vec![ - nostr::Filter::default() - .kinds(status_kinds().clone()) - .events(proposals.iter().map(|e| e.id)), - ], - ) + let mut statuses = get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::default() + .kinds(status_kinds().clone()) + .events(proposals.iter().map(|e| e.id)), + ]) .await?; statuses.sort_by_key(|e| e.created_at); statuses.reverse(); diff --git a/src/bin/ngit/cli.rs b/src/bin/ngit/cli.rs index 1737a9f..60bc5d2 100644 --- a/src/bin/ngit/cli.rs +++ b/src/bin/ngit/cli.rs @@ -1,4 +1,4 @@ -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use clap::{Parser, Subcommand}; use ngit::login::SignerInfo; diff --git a/src/bin/ngit/sub_commands/export_keys.rs b/src/bin/ngit/sub_commands/export_keys.rs index 54a716f..45b1b89 100644 --- a/src/bin/ngit/sub_commands/export_keys.rs +++ b/src/bin/ngit/sub_commands/export_keys.rs @@ -2,9 +2,9 @@ use anyhow::{Context, Result}; use ngit::{ cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms}, login::{ + SignerInfo, SignerInfoSource, existing::{get_signer_info, load_existing_login}, fresh::generate_qr, - SignerInfo, SignerInfoSource, }, }; diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 0894f41..80e182b 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs @@ -3,18 +3,18 @@ use std::collections::HashMap; use anyhow::{Context, Result}; use console::Style; use ngit::{cli_interactor::PromptConfirmParms, git::nostr_url::NostrUrlDecoded}; -use nostr::{nips::nip01::Coordinate, FromBech32, PublicKey, ToBech32}; +use nostr::{FromBech32, PublicKey, ToBech32, nips::nip01::Coordinate}; use nostr_sdk::{Kind, RelayUrl}; use crate::{ - cli::{extract_signer_cli_arguments, Cli}, + cli::{Cli, extract_signer_cli_arguments}, cli_interactor::{Interactor, InteractorPrompt, PromptInputParms}, - client::{fetching_with_report, get_repo_ref_from_cache, send_events, Client, Connect}, - git::{nostr_url::convert_clone_url_to_https, Repo, RepoActions}, + client::{Client, Connect, fetching_with_report, get_repo_ref_from_cache, send_events}, + git::{Repo, RepoActions, nostr_url::convert_clone_url_to_https}, login, repo_ref::{ - extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, - try_and_get_repo_coordinates_when_remote_unknown, RepoRef, + RepoRef, extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, + try_and_get_repo_coordinates_when_remote_unknown, }, }; diff --git a/src/bin/ngit/sub_commands/list.rs b/src/bin/ngit/sub_commands/list.rs index ee015ef..9b84c1b 100644 --- a/src/bin/ngit/sub_commands/list.rs +++ b/src/bin/ngit/sub_commands/list.rs @@ -1,6 +1,6 @@ use std::{io::Write, ops::Add}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use ngit::{ client::{get_all_proposal_patch_events_from_cache, get_proposals_and_revisions_from_cache}, git_events::{ @@ -12,9 +12,9 @@ use nostr_sdk::Kind; use crate::{ cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms, PromptConfirmParms}, client::{ - fetching_with_report, get_events_from_local_cache, get_repo_ref_from_cache, Client, Connect, + Client, Connect, fetching_with_report, get_events_from_local_cache, get_repo_ref_from_cache, }, - git::{str_to_sha1, Repo, RepoActions}, + git::{Repo, RepoActions, str_to_sha1}, git_events::{ commit_msg_from_patch_oneliner, event_is_revision_root, event_to_cover_letter, patch_supports_commit_ids, @@ -47,14 +47,11 @@ pub async fn launch() -> Result<()> { } let statuses: Vec = { - let mut statuses = get_events_from_local_cache( - git_repo_path, - vec![ - nostr::Filter::default() - .kinds(status_kinds().clone()) - .events(proposals_and_revisions.iter().map(|e| e.id)), - ], - ) + let mut statuses = get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::default() + .kinds(status_kinds().clone()) + .events(proposals_and_revisions.iter().map(|e| e.id)), + ]) .await?; statuses.sort_by_key(|e| e.created_at); statuses.reverse(); diff --git a/src/bin/ngit/sub_commands/login.rs b/src/bin/ngit/sub_commands/login.rs index ccbdf01..06236ec 100644 --- a/src/bin/ngit/sub_commands/login.rs +++ b/src/bin/ngit/sub_commands/login.rs @@ -3,11 +3,11 @@ use clap; use ngit::{ cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms}, git::{get_git_config_item, remove_git_config_item}, - login::{existing::load_existing_login, SignerInfoSource}, + login::{SignerInfoSource, existing::load_existing_login}, }; use crate::{ - cli::{extract_signer_cli_arguments, Cli}, + cli::{Cli, extract_signer_cli_arguments}, client::{Client, Connect}, git::Repo, login::fresh::fresh_login_or_signup, diff --git a/src/bin/ngit/sub_commands/logout.rs b/src/bin/ngit/sub_commands/logout.rs index f3f9620..2df96c8 100644 --- a/src/bin/ngit/sub_commands/logout.rs +++ b/src/bin/ngit/sub_commands/logout.rs @@ -1,7 +1,7 @@ use anyhow::{Context, Result}; use ngit::{ git::remove_git_config_item, - login::{existing::load_existing_login, SignerInfoSource}, + login::{SignerInfoSource, existing::load_existing_login}, }; use crate::{ diff --git a/src/bin/ngit/sub_commands/send.rs b/src/bin/ngit/sub_commands/send.rs index c6c75c9..7c898bc 100644 --- a/src/bin/ngit/sub_commands/send.rs +++ b/src/bin/ngit/sub_commands/send.rs @@ -1,23 +1,23 @@ use std::path::Path; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use console::Style; use ngit::{client::send_events, git_events::generate_cover_letter_and_patch_events}; use nostr::{ - nips::{nip10::Marker, nip19::Nip19Event}, ToBech32, + nips::{nip10::Marker, nip19::Nip19Event}, }; use nostr_sdk::hashes::sha1::Hash as Sha1Hash; use crate::{ - cli::{extract_signer_cli_arguments, Cli}, + cli::{Cli, extract_signer_cli_arguments}, cli_interactor::{ Interactor, InteractorPrompt, PromptConfirmParms, PromptInputParms, PromptMultiChoiceParms, }, client::{ - fetching_with_report, get_events_from_local_cache, get_repo_ref_from_cache, Client, Connect, + Client, Connect, fetching_with_report, get_events_from_local_cache, get_repo_ref_from_cache, }, - git::{identify_ahead_behind, Repo, RepoActions}, + git::{Repo, RepoActions, identify_ahead_behind}, git_events::{event_is_patch_set_root, event_tag_from_nip19_or_hex}, login, repo_ref::get_repo_coordinates_when_remote_unknown, @@ -369,10 +369,9 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to( public_key: _, uppercase: false, }) => { - let events = get_events_from_local_cache( - git_repo_path, - vec![nostr::Filter::new().id(*event_id)], - ) + let events = get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::new().id(*event_id), + ]) .await?; if let Some(first) = events.iter().find(|e| e.id.eq(event_id)) { diff --git a/src/lib/cli_interactor.rs b/src/lib/cli_interactor.rs index 50a0f0c..1b74101 100644 --- a/src/lib/cli_interactor.rs +++ b/src/lib/cli_interactor.rs @@ -1,5 +1,5 @@ use anyhow::{Context, Result}; -use dialoguer::{theme::ColorfulTheme, Confirm, Input, Password}; +use dialoguer::{Confirm, Input, Password, theme::ColorfulTheme}; use indicatif::TermLike; #[cfg(test)] use mockall::*; diff --git a/src/lib/client.rs b/src/lib/client.rs index 32f5bd7..59ec583 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs @@ -19,7 +19,7 @@ use std::{ time::Duration, }; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use async_trait::async_trait; use console::Style; use futures::{ @@ -29,12 +29,12 @@ use futures::{ use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressState, ProgressStyle}; #[cfg(test)] use mockall::*; -use nostr::{nips::nip01::Coordinate, signer::SignerBackend, Event}; +use nostr::{Event, nips::nip01::Coordinate, signer::SignerBackend}; use nostr_database::NostrEventsDatabase; use nostr_lmdb::NostrLMDB; use nostr_sdk::{ - prelude::RelayLimits, EventBuilder, EventId, Kind, NostrSigner, Options, PublicKey, RelayUrl, - SingleLetterTag, Timestamp, + EventBuilder, EventId, Kind, NostrSigner, Options, PublicKey, RelayUrl, SingleLetterTag, + Timestamp, prelude::RelayLimits, }; use crate::{ @@ -894,18 +894,16 @@ pub async fn get_state_from_cache( ) -> Result { if let Some(git_repo_path) = git_repo_path { RepoState::try_from( - get_events_from_local_cache( - git_repo_path, - vec![get_filter_state_events(&repo_ref.coordinates())], - ) + get_events_from_local_cache(git_repo_path, vec![get_filter_state_events( + &repo_ref.coordinates(), + )]) .await?, ) } else { RepoState::try_from( - get_event_from_global_cache( - git_repo_path, - vec![get_filter_state_events(&repo_ref.coordinates())], - ) + get_event_from_global_cache(git_repo_path, vec![get_filter_state_events( + &repo_ref.coordinates(), + )]) .await?, ) } @@ -975,20 +973,17 @@ async fn create_relays_request( } if let Some(git_repo_path) = git_repo_path { - for event in &get_events_from_local_cache( - git_repo_path, - vec![ - nostr::Filter::default() - .kinds(vec![Kind::GitPatch]) - .custom_tag( - SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), - repo_coordinates_without_relays - .iter() - .map(std::string::ToString::to_string) - .collect::>(), - ), - ], - ) + for event in &get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::default() + .kinds(vec![Kind::GitPatch]) + .custom_tag( + SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), + repo_coordinates_without_relays + .iter() + .map(std::string::ToString::to_string) + .collect::>(), + ), + ]) .await? { if event_is_patch_set_root(event) || event_is_revision_root(event) { @@ -998,11 +993,11 @@ async fn create_relays_request( } } - let profile_events = get_event_from_global_cache( - git_repo_path, - vec![get_filter_contributor_profiles(contributors.clone())], - ) - .await?; + let profile_events = + get_event_from_global_cache(git_repo_path, vec![get_filter_contributor_profiles( + contributors.clone(), + )]) + .await?; for c in &contributors { if let Some(event) = profile_events .iter() @@ -1564,20 +1559,17 @@ pub async fn get_proposals_and_revisions_from_cache( git_repo_path: &Path, repo_coordinates: HashSet, ) -> Result> { - let mut proposals = get_events_from_local_cache( - git_repo_path, - vec![ - nostr::Filter::default() - .kind(nostr::Kind::GitPatch) - .custom_tag( - nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), - repo_coordinates - .iter() - .map(std::string::ToString::to_string) - .collect::>(), - ), - ], - ) + let mut proposals = get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::default() + .kind(nostr::Kind::GitPatch) + .custom_tag( + nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), + repo_coordinates + .iter() + .map(std::string::ToString::to_string) + .collect::>(), + ), + ]) .await? .iter() .filter(|e| event_is_patch_set_root(e)) @@ -1593,29 +1585,23 @@ pub async fn get_all_proposal_patch_events_from_cache( repo_ref: &RepoRef, proposal_id: &nostr::EventId, ) -> Result> { - let mut commit_events = get_events_from_local_cache( - git_repo_path, - vec![ - nostr::Filter::default() - .kind(nostr::Kind::GitPatch) - .event(*proposal_id), - nostr::Filter::default() - .kind(nostr::Kind::GitPatch) - .id(*proposal_id), - ], - ) + let mut commit_events = get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::default() + .kind(nostr::Kind::GitPatch) + .event(*proposal_id), + nostr::Filter::default() + .kind(nostr::Kind::GitPatch) + .id(*proposal_id), + ]) .await?; - let permissioned_users: HashSet = [ - repo_ref.maintainers.clone(), - vec![ - commit_events - .iter() - .find(|e| e.id.eq(proposal_id)) - .context("proposal not in cache")? - .pubkey, - ], - ] + let permissioned_users: HashSet = [repo_ref.maintainers.clone(), vec![ + commit_events + .iter() + .find(|e| e.id.eq(proposal_id)) + .context("proposal not in cache")? + .pubkey, + ]] .concat() .iter() .copied() @@ -1629,15 +1615,12 @@ pub async fn get_all_proposal_patch_events_from_cache( .collect(); if !revision_roots.is_empty() { - for event in get_events_from_local_cache( - git_repo_path, - vec![ - nostr::Filter::default() - .kind(nostr::Kind::GitPatch) - .events(revision_roots) - .authors(permissioned_users.clone()), - ], - ) + for event in get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::default() + .kind(nostr::Kind::GitPatch) + .events(revision_roots) + .authors(permissioned_users.clone()), + ]) .await? { commit_events.push(event); @@ -1652,10 +1635,9 @@ pub async fn get_all_proposal_patch_events_from_cache( } pub async fn get_event_from_cache_by_id(git_repo: &Repo, event_id: &EventId) -> Result { - Ok(get_events_from_local_cache( - git_repo.get_path()?, - vec![nostr::Filter::default().id(*event_id)], - ) + Ok(get_events_from_local_cache(git_repo.get_path()?, vec![ + nostr::Filter::default().id(*event_id), + ]) .await? .first() .context("failed to find event in cache")? diff --git a/src/lib/git/identify_ahead_behind.rs b/src/lib/git/identify_ahead_behind.rs index d736522..baea687 100644 --- a/src/lib/git/identify_ahead_behind.rs +++ b/src/lib/git/identify_ahead_behind.rs @@ -184,10 +184,10 @@ mod tests { identify_ahead_behind(&git_repo, &Some("feature".to_string()), &None)?; assert_eq!(from_branch, "feature"); - assert_eq!( - ahead, - vec![oid_to_sha1(&feature_oid), oid_to_sha1(&dev_oid_first)] - ); + assert_eq!(ahead, vec![ + oid_to_sha1(&feature_oid), + oid_to_sha1(&dev_oid_first) + ]); assert_eq!(to_branch, "main"); assert_eq!(behind, vec![]); diff --git a/src/lib/git/mod.rs b/src/lib/git/mod.rs index 7a7ad5d..2b78f38 100644 --- a/src/lib/git/mod.rs +++ b/src/lib/git/mod.rs @@ -3,12 +3,12 @@ use std::{ path::{Path, PathBuf}, }; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use git2::{DiffOptions, Oid, Revwalk}; pub use identify_ahead_behind::identify_ahead_behind; use nostr_sdk::{ - hashes::{sha1::Hash as Sha1Hash, Hash}, Tags, + hashes::{Hash, sha1::Hash as Sha1Hash}, }; use crate::git_events::{get_commit_id_from_patch, tag_value}; @@ -1493,10 +1493,10 @@ mod tests { &oid_to_sha1(&feature_oid), )?; assert_eq!(ahead, vec![]); - assert_eq!( - behind, - vec![oid_to_sha1(&behind_2_oid), oid_to_sha1(&behind_1_oid),], - ); + assert_eq!(behind, vec![ + oid_to_sha1(&behind_2_oid), + oid_to_sha1(&behind_1_oid), + ],); Ok(()) } @@ -1518,10 +1518,10 @@ mod tests { &oid_to_sha1(&main_oid), &oid_to_sha1(&ahead_2_oid), )?; - assert_eq!( - ahead, - vec![oid_to_sha1(&ahead_2_oid), oid_to_sha1(&ahead_1_oid),], - ); + assert_eq!(ahead, vec![ + oid_to_sha1(&ahead_2_oid), + oid_to_sha1(&ahead_1_oid), + ],); assert_eq!(behind, vec![]); Ok(()) } @@ -1550,14 +1550,14 @@ mod tests { &oid_to_sha1(&behind_2_oid), &oid_to_sha1(&ahead_2_oid), )?; - assert_eq!( - ahead, - vec![oid_to_sha1(&ahead_2_oid), oid_to_sha1(&ahead_1_oid)], - ); - assert_eq!( - behind, - vec![oid_to_sha1(&behind_2_oid), oid_to_sha1(&behind_1_oid)], - ); + assert_eq!(ahead, vec![ + oid_to_sha1(&ahead_2_oid), + oid_to_sha1(&ahead_1_oid) + ],); + assert_eq!(behind, vec![ + oid_to_sha1(&behind_2_oid), + oid_to_sha1(&behind_1_oid) + ],); Ok(()) } } @@ -2212,10 +2212,9 @@ mod tests { test_repo.populate_with_test_branch()?; test_repo.checkout("main")?; - assert_eq!( - git_repo.parse_starting_commits("HEAD~1")?, - vec![str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?], - ); + assert_eq!(git_repo.parse_starting_commits("HEAD~1")?, vec![ + str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")? + ],); Ok(()) } @@ -2225,10 +2224,9 @@ mod tests { let git_repo = Repo::from_path(&test_repo.dir)?; test_repo.populate_with_test_branch()?; - assert_eq!( - git_repo.parse_starting_commits("HEAD~1")?, - vec![str_to_sha1("82ff2bcc9aa94d1bd8faee723d4c8cc190d6061c")?], - ); + assert_eq!(git_repo.parse_starting_commits("HEAD~1")?, vec![ + str_to_sha1("82ff2bcc9aa94d1bd8faee723d4c8cc190d6061c")? + ],); Ok(()) } } @@ -2242,13 +2240,10 @@ mod tests { test_repo.populate_with_test_branch()?; test_repo.checkout("main")?; - assert_eq!( - git_repo.parse_starting_commits("HEAD~2")?, - vec![ - str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?, - str_to_sha1("af474d8d271490e5c635aad337abdc050034b16a")?, - ], - ); + assert_eq!(git_repo.parse_starting_commits("HEAD~2")?, vec![ + str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?, + str_to_sha1("af474d8d271490e5c635aad337abdc050034b16a")?, + ],); Ok(()) } } @@ -2261,14 +2256,11 @@ mod tests { let git_repo = Repo::from_path(&test_repo.dir)?; test_repo.populate_with_test_branch()?; - assert_eq!( - git_repo.parse_starting_commits("HEAD~3")?, - vec![ - str_to_sha1("82ff2bcc9aa94d1bd8faee723d4c8cc190d6061c")?, - str_to_sha1("a23e6b05aaeb7d1471b4a838b51f337d5644eeb0")?, - str_to_sha1("7ab82116068982671a8111f27dc10599172334b2")?, - ], - ); + assert_eq!(git_repo.parse_starting_commits("HEAD~3")?, vec![ + str_to_sha1("82ff2bcc9aa94d1bd8faee723d4c8cc190d6061c")?, + str_to_sha1("a23e6b05aaeb7d1471b4a838b51f337d5644eeb0")?, + str_to_sha1("7ab82116068982671a8111f27dc10599172334b2")?, + ],); Ok(()) } } @@ -2282,14 +2274,11 @@ mod tests { test_repo.populate_with_test_branch()?; test_repo.checkout("main")?; - assert_eq!( - git_repo.parse_starting_commits("af474d8..a23e6b0")?, - vec![ - str_to_sha1("a23e6b05aaeb7d1471b4a838b51f337d5644eeb0")?, - str_to_sha1("7ab82116068982671a8111f27dc10599172334b2")?, - str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?, - ], - ); + assert_eq!(git_repo.parse_starting_commits("af474d8..a23e6b0")?, vec![ + str_to_sha1("a23e6b05aaeb7d1471b4a838b51f337d5644eeb0")?, + str_to_sha1("7ab82116068982671a8111f27dc10599172334b2")?, + str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?, + ],); Ok(()) } } diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs index 4fbc786..6b38a93 100644 --- a/src/lib/git/nostr_url.rs +++ b/src/lib/git/nostr_url.rs @@ -1,11 +1,11 @@ use core::fmt; use std::{collections::HashMap, str::FromStr}; -use anyhow::{anyhow, bail, Context, Error, Result}; +use anyhow::{Context, Error, Result, anyhow, bail}; use nostr::nips::{nip01::Coordinate, nip05}; use nostr_sdk::{PublicKey, RelayUrl, ToBech32, Url}; -use super::{get_git_config_item, save_git_config_item, Repo}; +use super::{Repo, get_git_config_item, save_git_config_item}; #[derive(Debug, PartialEq, Default, Clone)] pub enum ServerProtocol { @@ -961,24 +961,21 @@ mod tests { #[test] fn standard() -> Result<()> { assert_eq!( - format!( - "{}", - NostrUrlDecoded { - original_string: String::new(), - coordinate: Coordinate { - identifier: "ngit".to_string(), - public_key: PublicKey::parse( - "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", - ) - .unwrap(), - kind: nostr_sdk::Kind::GitRepoAnnouncement, - relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], - }, - protocol: None, - user: None, - nip05: None, - } - ), + format!("{}", NostrUrlDecoded { + original_string: String::new(), + coordinate: Coordinate { + identifier: "ngit".to_string(), + public_key: PublicKey::parse( + "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", + ) + .unwrap(), + kind: nostr_sdk::Kind::GitRepoAnnouncement, + relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], + }, + protocol: None, + user: None, + nip05: None, + }), "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", ); Ok(()) @@ -987,24 +984,21 @@ mod tests { #[test] fn no_relay() -> Result<()> { assert_eq!( - format!( - "{}", - NostrUrlDecoded { - original_string: String::new(), - coordinate: Coordinate { - identifier: "ngit".to_string(), - public_key: PublicKey::parse( - "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", - ) - .unwrap(), - kind: nostr_sdk::Kind::GitRepoAnnouncement, - relays: vec![], - }, - protocol: None, - user: None, - nip05: None, - } - ), + format!("{}", NostrUrlDecoded { + original_string: String::new(), + coordinate: Coordinate { + identifier: "ngit".to_string(), + public_key: PublicKey::parse( + "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", + ) + .unwrap(), + kind: nostr_sdk::Kind::GitRepoAnnouncement, + relays: vec![], + }, + protocol: None, + user: None, + nip05: None, + }), "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit", ); Ok(()) @@ -1013,24 +1007,21 @@ mod tests { #[test] fn with_protocol() -> Result<()> { assert_eq!( - format!( - "{}", - NostrUrlDecoded { - original_string: String::new(), - coordinate: Coordinate { - identifier: "ngit".to_string(), - public_key: PublicKey::parse( - "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", - ) - .unwrap(), - kind: nostr_sdk::Kind::GitRepoAnnouncement, - relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], - }, - protocol: Some(ServerProtocol::Ssh), - user: None, - nip05: None, - } - ), + format!("{}", NostrUrlDecoded { + original_string: String::new(), + coordinate: Coordinate { + identifier: "ngit".to_string(), + public_key: PublicKey::parse( + "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", + ) + .unwrap(), + kind: nostr_sdk::Kind::GitRepoAnnouncement, + relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], + }, + protocol: Some(ServerProtocol::Ssh), + user: None, + nip05: None, + }), "nostr://ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", ); Ok(()) @@ -1039,24 +1030,21 @@ mod tests { #[test] fn with_protocol_and_user() -> Result<()> { assert_eq!( - format!( - "{}", - NostrUrlDecoded { - original_string: String::new(), - coordinate: Coordinate { - identifier: "ngit".to_string(), - public_key: PublicKey::parse( - "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", - ) - .unwrap(), - kind: nostr_sdk::Kind::GitRepoAnnouncement, - relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], - }, - protocol: Some(ServerProtocol::Ssh), - user: Some("bla".to_string()), - nip05: None, - } - ), + format!("{}", NostrUrlDecoded { + original_string: String::new(), + coordinate: Coordinate { + identifier: "ngit".to_string(), + public_key: PublicKey::parse( + "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", + ) + .unwrap(), + kind: nostr_sdk::Kind::GitRepoAnnouncement, + relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], + }, + protocol: Some(ServerProtocol::Ssh), + user: Some("bla".to_string()), + nip05: None, + }), "nostr://bla@ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", ); Ok(()) diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index d8564ae..af469d3 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs @@ -1,10 +1,10 @@ use std::{str::FromStr, sync::Arc}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}; use nostr_sdk::{ - hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, FromBech32, Kind, NostrSigner, - PublicKey, RelayUrl, Tag, TagKind, TagStandard, + Event, EventBuilder, EventId, FromBech32, Kind, NostrSigner, PublicKey, RelayUrl, Tag, TagKind, + TagStandard, hashes::sha1::Hash as Sha1Hash, }; use crate::{ @@ -131,15 +131,14 @@ pub async fn generate_patch_event( // code that makes it into the main branch, assuming // the commit id is correct Tag::from_standardized(TagStandard::Reference(commit.to_string())), - Tag::custom( - TagKind::Custom(std::borrow::Cow::Borrowed("alt")), - vec![format!( + Tag::custom(TagKind::Custom(std::borrow::Cow::Borrowed("alt")), vec![ + format!( "git patch: {}", git_repo .get_commit_message_summary(commit) .unwrap_or_default() - )], - ), + ), + ]), ], if let Some(thread_event_id) = thread_event_id { vec![Tag::from_standardized(nostr_sdk::TagStandard::Event { @@ -203,10 +202,9 @@ pub async fn generate_patch_event( .collect(), vec![ // a fallback is now in place to extract this from the patch - Tag::custom( - TagKind::Custom(std::borrow::Cow::Borrowed("commit")), - vec![commit.to_string()], - ), + Tag::custom(TagKind::Custom(std::borrow::Cow::Borrowed("commit")), vec![ + commit.to_string(), + ]), // this is required as patches cannot be relied upon to include the 'base // commit' Tag::custom( diff --git a/src/lib/login/existing.rs b/src/lib/login/existing.rs index 4606c22..efe187e 100644 --- a/src/lib/login/existing.rs +++ b/src/lib/login/existing.rs @@ -1,15 +1,15 @@ use std::{str::FromStr, sync::Arc, time::Duration}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use nostr::nips::nip46::NostrConnectURI; use nostr_connect::client::NostrConnect; use nostr_sdk::{NostrSigner, PublicKey}; use super::{ + SignerInfo, SignerInfoSource, key_encryption::decrypt_key, print_logged_in_as, - user::{get_user_details, UserRef}, - SignerInfo, SignerInfoSource, + user::{UserRef, get_user_details}, }; #[cfg(not(test))] use crate::client::Client; @@ -18,7 +18,7 @@ use crate::client::MockConnect; use crate::{ cli_interactor::{Interactor, InteractorPrompt, PromptPasswordParms}, client::fetch_public_key, - git::{get_git_config_item, Repo, RepoActions}, + git::{Repo, RepoActions, get_git_config_item}, }; /// load signer from git config and UserProfile from cache or relays diff --git a/src/lib/login/fresh.rs b/src/lib/login/fresh.rs index 7cdbde8..635c0b3 100644 --- a/src/lib/login/fresh.rs +++ b/src/lib/login/fresh.rs @@ -1,6 +1,6 @@ use std::{str::FromStr, sync::Arc, time::Duration}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use console::Style; use dialoguer::theme::{ColorfulTheme, Theme}; use nostr::nips::{nip05, nip46::NostrConnectURI}; @@ -10,11 +10,11 @@ use qrcode::QrCode; use tokio::{signal, sync::Mutex}; use super::{ + SignerInfo, SignerInfoSource, existing::load_existing_login, key_encryption::decrypt_key, print_logged_in_as, - user::{get_user_details, UserRef}, - SignerInfo, SignerInfoSource, + user::{UserRef, get_user_details}, }; #[cfg(not(test))] use crate::client::Client; @@ -25,8 +25,8 @@ use crate::{ Interactor, InteractorPrompt, Printer, PromptChoiceParms, PromptConfirmParms, PromptInputParms, PromptPasswordParms, }, - client::{send_events, Connect}, - git::{remove_git_config_item, save_git_config_item, Repo, RepoActions}, + client::{Connect, send_events}, + git::{Repo, RepoActions, remove_git_config_item, save_git_config_item}, }; pub async fn fresh_login_or_signup( diff --git a/src/lib/login/mod.rs b/src/lib/login/mod.rs index 0be1e5d..a1c45d5 100644 --- a/src/lib/login/mod.rs +++ b/src/lib/login/mod.rs @@ -79,15 +79,11 @@ fn print_logged_in_as( "failed to find your relay list. consider using another nostr client to create one to enhance your nostr experience." ); } - eprintln!( - "logged in as {}{}", - user_ref.metadata.name, - match source { - SignerInfoSource::CommandLineArguments => " via cli arguments", - SignerInfoSource::GitLocal => " to local repository", - SignerInfoSource::GitGlobal => "", - } - ); + eprintln!("logged in as {}{}", user_ref.metadata.name, match source { + SignerInfoSource::CommandLineArguments => " via cli arguments", + SignerInfoSource::GitLocal => " to local repository", + SignerInfoSource::GitGlobal => "", + }); Ok(()) } diff --git a/src/lib/login/user.rs b/src/lib/login/user.rs index de4a2d9..107e765 100644 --- a/src/lib/login/user.rs +++ b/src/lib/login/user.rs @@ -1,6 +1,6 @@ use std::{collections::HashSet, path::Path}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use nostr::PublicKey; use nostr_sdk::{Alphabet, JsonUtil, Kind, SingleLetterTag, Timestamp, ToBech32}; use serde::{self, Deserialize, Serialize}; @@ -9,7 +9,7 @@ use serde::{self, Deserialize, Serialize}; use crate::client::Client; #[cfg(test)] use crate::client::MockConnect; -use crate::client::{get_event_from_global_cache, Connect}; +use crate::client::{Connect, get_event_from_global_cache}; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct UserRef { diff --git a/src/lib/mod.rs b/src/lib/mod.rs index 6e6f6fe..2072a80 100644 --- a/src/lib/mod.rs +++ b/src/lib/mod.rs @@ -6,7 +6,7 @@ pub mod login; pub mod repo_ref; pub mod repo_state; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use directories::ProjectDirs; pub fn get_dirs() -> Result { diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs index 5d6f4eb..a9d1186 100644 --- a/src/lib/repo_ref.rs +++ b/src/lib/repo_ref.rs @@ -6,9 +6,9 @@ use std::{ sync::Arc, }; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use console::Style; -use nostr::{nips::nip01::Coordinate, FromBech32, PublicKey, Tag, TagStandard, ToBech32}; +use nostr::{FromBech32, PublicKey, Tag, TagStandard, ToBech32, nips::nip01::Coordinate}; use nostr_sdk::{Kind, NostrSigner, RelayUrl, Timestamp}; use serde::{Deserialize, Serialize}; @@ -18,10 +18,10 @@ use crate::{ cli_interactor::{ Interactor, InteractorPrompt, PromptChoiceParms, PromptConfirmParms, PromptInputParms, }, - client::{consolidate_fetch_reports, get_repo_ref_from_cache, sign_event, Connect}, + client::{Connect, consolidate_fetch_reports, get_repo_ref_from_cache, sign_event}, git::{ - nostr_url::{use_nip05_git_config_cache_to_find_nip05_from_public_key, NostrUrlDecoded}, Repo, RepoActions, + nostr_url::{NostrUrlDecoded, use_nip05_git_config_cache_to_find_nip05_from_public_key}, }, login::user::get_user_details, }; @@ -237,20 +237,17 @@ impl RepoRef { pub fn to_nostr_git_url(&self, git_repo: &Option<&Repo>) -> String { let c = self.coordinate_with_hint(); - format!( - "{}", - NostrUrlDecoded { - original_string: String::new(), - nip05: use_nip05_git_config_cache_to_find_nip05_from_public_key( - &c.public_key, - git_repo, - ) - .unwrap_or_default(), - coordinate: c, - protocol: None, - user: None, - } - ) + format!("{}", NostrUrlDecoded { + original_string: String::new(), + nip05: use_nip05_git_config_cache_to_find_nip05_from_public_key( + &c.public_key, + git_repo, + ) + .unwrap_or_default(), + coordinate: c, + protocol: None, + user: None, + }) } } @@ -521,14 +518,11 @@ pub fn save_repo_config_to_yaml( .context("failed to convert public key into npub")?, ); } - serde_yaml::to_writer( - file, - &RepoConfigYaml { - identifier: Some(identifier), - maintainers: maintainers_npubs, - relays, - }, - ) + serde_yaml::to_writer(file, &RepoConfigYaml { + identifier: Some(identifier), + maintainers: maintainers_npubs, + relays, + }) .context("failed to write maintainers to maintainers.yaml file serde_yaml") } diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 5079c26..5c8d7a5 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs @@ -6,15 +6,15 @@ use std::{ time::Duration, }; -use anyhow::{bail, ensure, Context, Result}; +use anyhow::{Context, Result, bail, ensure}; use dialoguer::theme::{ColorfulTheme, Theme}; use futures::executor::block_on; use git::GitTestRepo; use git2::{Signature, Time}; -use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; +use nostr::{self, Kind, Tag, nips::nip65::RelayMetadata}; use nostr_database::NostrEventsDatabase; use nostr_lmdb::NostrLMDB; -use nostr_sdk::{serde_json, Client, NostrSigner, TagStandard}; +use nostr_sdk::{Client, NostrSigner, TagStandard, serde_json}; use once_cell::sync::Lazy; use rexpect::session::{Options, PtySession}; use strip_ansi_escapes::strip_str; @@ -530,14 +530,10 @@ impl CliTesterConfirmPrompt<'_> { let mut s = String::new(); self.tester .formatter - .format_confirm_prompt_selection( - &mut s, - self.prompt.as_str(), - match input { - None => self.default, - Some(_) => input, - }, - ) + .format_confirm_prompt_selection(&mut s, self.prompt.as_str(), match input { + None => self.default, + Some(_) => input, + }) .expect("diagluer theme formatter should succeed"); if !s.contains(self.prompt.as_str()) { panic!("dialoguer must be broken as formatted prompt success doesnt contain prompt"); @@ -1007,13 +1003,10 @@ where cmd.env("RUST_BACKTRACE", "0"); cmd.args(args); // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes - rexpect::session::spawn_with_options( - cmd, - Options { - timeout_ms: Some(timeout_ms), - strip_ansi_escape_codes: true, - }, - ) + rexpect::session::spawn_with_options(cmd, Options { + timeout_ms: Some(timeout_ms), + strip_ansi_escape_codes: true, + }) } pub fn rexpect_with_from_dir( @@ -1031,13 +1024,10 @@ where cmd.current_dir(dir); cmd.args(args); // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes - rexpect::session::spawn_with_options( - cmd, - Options { - timeout_ms: Some(timeout_ms), - strip_ansi_escape_codes: true, - }, - ) + rexpect::session::spawn_with_options(cmd, Options { + timeout_ms: Some(timeout_ms), + strip_ansi_escape_codes: true, + }) } pub fn remote_helper_rexpect_with_from_dir( @@ -1052,13 +1042,10 @@ pub fn remote_helper_rexpect_with_from_dir( cmd.current_dir(dir); cmd.args([dir.as_os_str().to_str().unwrap(), nostr_remote_url]); // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes - rexpect::session::spawn_with_options( - cmd, - Options { - timeout_ms: Some(timeout_ms), - strip_ansi_escape_codes: true, - }, - ) + rexpect::session::spawn_with_options(cmd, Options { + timeout_ms: Some(timeout_ms), + strip_ansi_escape_codes: true, + }) } pub fn git_with_remote_helper_rexpect_with_from_dir( @@ -1102,13 +1089,10 @@ where cmd.current_dir(dir); cmd.args(args); // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes - rexpect::session::spawn_with_options( - cmd, - Options { - timeout_ms: Some(timeout_ms), - strip_ansi_escape_codes: true, - }, - ) + rexpect::session::spawn_with_options(cmd, Options { + timeout_ms: Some(timeout_ms), + strip_ansi_escape_codes: true, + }) .context("spawning failed") } @@ -1137,14 +1121,11 @@ pub fn get_proposal_branch_name( test_repo: &GitTestRepo, branch_name_in_event: &str, ) -> Result { - let events = block_on(get_events_from_cache( - &test_repo.dir, - vec![ - nostr::Filter::default() - .kind(nostr_sdk::Kind::GitPatch) - .hashtag("root"), - ], - ))?; + let events = block_on(get_events_from_cache(&test_repo.dir, vec![ + nostr::Filter::default() + .kind(nostr_sdk::Kind::GitPatch) + .hashtag("root"), + ]))?; get_proposal_branch_name_from_events(&events, branch_name_in_event) } @@ -1296,54 +1277,45 @@ pub fn cli_tester_create_proposal( create_and_populate_branch(test_repo, branch_name, prefix, false, None)?; std::thread::sleep(std::time::Duration::from_millis(1000)); if let Some(in_reply_to) = in_reply_to { - let mut p = CliTester::new_from_dir( - &test_repo.dir, - [ - "--nsec", - TEST_KEY_1_NSEC, - "--password", - TEST_PASSWORD, - "--disable-cli-spinners", - "send", - "HEAD~2", - "--no-cover-letter", - "--in-reply-to", - in_reply_to.as_str(), - ], - ); + let mut p = CliTester::new_from_dir(&test_repo.dir, [ + "--nsec", + TEST_KEY_1_NSEC, + "--password", + TEST_PASSWORD, + "--disable-cli-spinners", + "send", + "HEAD~2", + "--no-cover-letter", + "--in-reply-to", + in_reply_to.as_str(), + ]); p.expect_end_eventually()?; } else if let Some((title, description)) = cover_letter_title_and_description { - let mut p = CliTester::new_from_dir( - &test_repo.dir, - [ - "--nsec", - TEST_KEY_1_NSEC, - "--password", - TEST_PASSWORD, - "--disable-cli-spinners", - "send", - "HEAD~2", - "--title", - format!("\"{title}\"").as_str(), - "--description", - format!("\"{description}\"").as_str(), - ], - ); + let mut p = CliTester::new_from_dir(&test_repo.dir, [ + "--nsec", + TEST_KEY_1_NSEC, + "--password", + TEST_PASSWORD, + "--disable-cli-spinners", + "send", + "HEAD~2", + "--title", + format!("\"{title}\"").as_str(), + "--description", + format!("\"{description}\"").as_str(), + ]); p.expect_end_eventually()?; } else { - let mut p = CliTester::new_from_dir( - &test_repo.dir, - [ - "--nsec", - TEST_KEY_1_NSEC, - "--password", - TEST_PASSWORD, - "--disable-cli-spinners", - "send", - "HEAD~2", - "--no-cover-letter", - ], - ); + let mut p = CliTester::new_from_dir(&test_repo.dir, [ + "--nsec", + TEST_KEY_1_NSEC, + "--password", + TEST_PASSWORD, + "--disable-cli-spinners", + "send", + "HEAD~2", + "--no-cover-letter", + ]); p.expect_end_eventually()?; } Ok(()) @@ -1375,14 +1347,11 @@ pub fn use_ngit_list_to_download_and_checkout_proposal_branch( let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with( if proposal_number == 3 { 0 @@ -1394,15 +1363,12 @@ pub fn use_ngit_list_to_download_and_checkout_proposal_branch( true, None, )?; - let mut c = p.expect_choice( - "", - vec![ - format!("create and checkout proposal branch (2 ahead 0 behind 'main')"), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!("create and checkout proposal branch (2 ahead 0 behind 'main')"), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect_end_eventually()?; Ok(()) @@ -1505,18 +1471,15 @@ pub fn create_proposals_with_first_revised_and_repo_with_unrevised_proposal_chec amend_last_commit(&originating_repo, "add some ammended-commit.md")?; - let mut p = CliTester::new_from_dir( - &originating_repo.dir, - [ - "--nsec", - TEST_KEY_1_NSEC, - "--password", - TEST_PASSWORD, - "--disable-cli-spinners", - "push", - "--force", - ], - ); + let mut p = CliTester::new_from_dir(&originating_repo.dir, [ + "--nsec", + TEST_KEY_1_NSEC, + "--password", + TEST_PASSWORD, + "--disable-cli-spinners", + "push", + "--force", + ]); p.expect_end_eventually()?; Ok((originating_repo, test_repo)) diff --git a/test_utils/src/relay.rs b/test_utils/src/relay.rs index d767a5a..634b2d6 100644 --- a/test_utils/src/relay.rs +++ b/test_utils/src/relay.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use nostr::{ClientMessage, JsonUtil, RelayMessage}; use crate::CliTester; diff --git a/tests/git_remote_nostr/main.rs b/tests/git_remote_nostr/main.rs index 5a1d416..686a5df 100644 --- a/tests/git_remote_nostr/main.rs +++ b/tests/git_remote_nostr/main.rs @@ -4,7 +4,7 @@ use anyhow::{Context, Result}; use futures::join; use git2::Oid; use nostr::nips::nip01::Coordinate; -use nostr_sdk::{secp256k1::rand, Event, JsonUtil, Kind, RelayUrl, ToBech32}; +use nostr_sdk::{Event, JsonUtil, Kind, RelayUrl, ToBech32, secp256k1::rand}; use relay::Relay; use serial_test::serial; use test_utils::{git::GitTestRepo, *}; diff --git a/tests/git_remote_nostr/push.rs b/tests/git_remote_nostr/push.rs index 30602c9..4e44642 100644 --- a/tests/git_remote_nostr/push.rs +++ b/tests/git_remote_nostr/push.rs @@ -925,10 +925,12 @@ async fn proposal_three_way_merge_commit_pushed_to_main_leads_to_status_event_is std::fs::write(git_repo.dir.join("new.md"), "some content")?; git_repo.stage_and_commit("new.md")?; - CliTester::new_git_with_remote_helper_from_dir( - &git_repo.dir, - ["merge", &branch_name, "-m", "proposal merge commit message"], - ) + CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, [ + "merge", + &branch_name, + "-m", + "proposal merge commit message", + ]) .expect_end_eventually_and_print()?; let oid = git_repo.get_tip_of_local_branch("main")?; @@ -1079,10 +1081,12 @@ async fn proposal_fast_forward_merge_commits_pushed_to_main_leads_to_status_even git_repo.checkout_remote_branch(&branch_name)?; git_repo.checkout("refs/heads/main")?; - CliTester::new_git_with_remote_helper_from_dir( - &git_repo.dir, - ["merge", &branch_name, "-m", "proposal merge commit message"], - ) + CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, [ + "merge", + &branch_name, + "-m", + "proposal merge commit message", + ]) .expect_end_eventually_and_print()?; let oid = git_repo.get_tip_of_local_branch("main")?; @@ -1736,10 +1740,12 @@ async fn push_new_pr_branch_creates_proposal() -> Result<()> { std::fs::write(git_repo.dir.join("new2.md"), "some content")?; git_repo.stage_and_commit("new2.md")?; - let mut p = CliTester::new_git_with_remote_helper_from_dir( - &git_repo.dir, - ["push", "-u", "origin", branch_name], - ); + let mut p = CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, [ + "push", + "-u", + "origin", + branch_name, + ]); cli_expect_nostr_fetch(&mut p)?; p.expect(format!("fetching {} ref list over filesystem...\r\n", source_path).as_str())?; p.expect("list: connecting...\r\n\r\r\r")?; diff --git a/tests/ngit_init.rs b/tests/ngit_init.rs index da4091f..4b61559 100644 --- a/tests/ngit_init.rs +++ b/tests/ngit_init.rs @@ -84,14 +84,10 @@ mod when_repo_not_previously_claimed { 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + ])?; Ok(()) }), ), @@ -211,14 +207,10 @@ mod when_repo_not_previously_claimed { 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + ])?; Ok(()) }), ), @@ -471,14 +463,10 @@ mod when_repo_not_previously_claimed { 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + ])?; Ok(()) }), ), diff --git a/tests/ngit_list.rs b/tests/ngit_list.rs index 1d297b6..4a3aad5 100644 --- a/tests/ngit_list.rs +++ b/tests/ngit_list.rs @@ -49,7 +49,7 @@ async fn prep_proposals_repo_and_repo_with_proposal_pulled_and_checkedout( mod cannot_find_repo_event { use super::*; mod cli_prompts { - use nostr::{nips::nip01::Coordinate, ToBech32}; + use nostr::{ToBech32, nips::nip01::Coordinate}; use nostr_sdk::RelayUrl; use super::*; @@ -196,25 +196,20 @@ mod when_main_branch_is_uptodate { p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(2, true, None)?; - let mut c = p.expect_choice( - "", - vec![ - format!( - "create and checkout proposal branch (2 ahead 0 behind 'main')" ), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!( + "create and checkout proposal branch (2 ahead 0 behind 'main')" + ), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + format!("back"), + ])?; c.succeeds_with(0, true, None)?; p.expect(format!( "checked out proposal as 'pr/{}(", @@ -318,25 +313,20 @@ mod when_main_branch_is_uptodate { p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(0, true, None)?; - let mut c = p.expect_choice( - "", - vec![ - format!( - "create and checkout proposal branch (2 ahead 0 behind 'main')" ), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!( + "create and checkout proposal branch (2 ahead 0 behind 'main')" + ), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect(format!( "checked out proposal as 'pr/{}(", @@ -427,8 +417,8 @@ mod when_main_branch_is_uptodate { r55.events.push(generate_test_key_1_metadata_event("fred")); r55.events.push(generate_test_key_1_relay_list_event()); - let cli_tester_handle = std::thread::spawn( - move || -> Result<(GitTestRepo, GitTestRepo)> { + let cli_tester_handle = + std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { let originating_repo = cli_tester_create_proposals()?; cli_tester_create_proposal( &originating_repo, @@ -443,26 +433,21 @@ mod when_main_branch_is_uptodate { p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("add d3.md"), // commit msg title - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("add d3.md"), // commit msg title + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(0, true, None)?; - let mut c = p.expect_choice( - "", - vec![ - format!( - "create and checkout proposal branch (2 ahead 0 behind 'main')" ), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!( + "create and checkout proposal branch (2 ahead 0 behind 'main')" + ), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect_end_eventually_and_print()?; @@ -470,8 +455,7 @@ mod when_main_branch_is_uptodate { relay::shutdown_relay(8000 + p)?; } Ok((originating_repo, test_repo)) - }, - ); + }); // launch relay let _ = join!( @@ -524,26 +508,21 @@ mod when_main_branch_is_uptodate { p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("add d3.md"), // commit msg title - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("add d3.md"), // commit msg title + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(0, true, None)?; - let mut c = p.expect_choice( - "", - vec![ - format!( - "create and checkout proposal branch (2 ahead 0 behind 'main')" ), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!( + "create and checkout proposal branch (2 ahead 0 behind 'main')" + ), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect(format!( "checked out proposal as 'pr/{}(", @@ -639,8 +618,8 @@ mod when_main_branch_is_uptodate { r55.events.push(generate_test_key_1_metadata_event("fred")); r55.events.push(generate_test_key_1_relay_list_event()); - let cli_tester_handle = std::thread::spawn( - move || -> Result<(GitTestRepo, GitTestRepo)> { + let cli_tester_handle = + std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { let originating_repo = cli_tester_create_proposals()?; let test_repo = GitTestRepo::default(); @@ -649,24 +628,20 @@ mod when_main_branch_is_uptodate { let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(2, true, None)?; - let mut c = p.expect_choice( - "", - vec![ - format!("create and checkout proposal branch (2 ahead 0 behind 'main')"), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!( + "create and checkout proposal branch (2 ahead 0 behind 'main')" + ), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect_end_eventually()?; @@ -675,24 +650,18 @@ mod when_main_branch_is_uptodate { p = CliTester::new_from_dir(&test_repo.dir, ["list"]); p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(2, true, None)?; - let mut c = p.expect_choice( - "", - vec![ - format!("checkout proposal branch (2 ahead 0 behind 'main')"), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!("checkout proposal branch (2 ahead 0 behind 'main')"), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect_end_eventually_and_print()?; @@ -700,8 +669,7 @@ mod when_main_branch_is_uptodate { relay::shutdown_relay(8000 + p)?; } Ok((originating_repo, test_repo)) - }, - ); + }); // launch relay let _ = join!( @@ -747,24 +715,20 @@ mod when_main_branch_is_uptodate { let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(2, true, None)?; - let mut c = p.expect_choice( - "", - vec![ - format!("create and checkout proposal branch (2 ahead 0 behind 'main')"), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!( + "create and checkout proposal branch (2 ahead 0 behind 'main')" + ), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect_end_eventually()?; @@ -773,24 +737,18 @@ mod when_main_branch_is_uptodate { p = CliTester::new_from_dir(&test_repo.dir, ["list"]); p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(2, true, None)?; - let mut c = p.expect_choice( - "", - vec![ - format!("checkout proposal branch (2 ahead 0 behind 'main')"), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!("checkout proposal branch (2 ahead 0 behind 'main')"), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect(format!( "checked out proposal as 'pr/{}(", @@ -864,24 +822,18 @@ mod when_main_branch_is_uptodate { let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(2, true, None)?; - let mut c = p.expect_choice( - "", - vec![ - format!("checkout proposal branch and apply 1 appendments"), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!("checkout proposal branch and apply 1 appendments"), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect("checked out proposal branch and applied 1 appendments (2 ahead 0 behind 'main')\r\n")?; p.expect_end()?; @@ -940,24 +892,18 @@ mod when_main_branch_is_uptodate { let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(2, true, None)?; - let mut c = p.expect_choice( - "", - vec![ - format!("checkout proposal branch and apply 1 appendments"), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!("checkout proposal branch and apply 1 appendments"), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect("checked out proposal branch and applied 1 appendments (2 ahead 0 behind 'main')\r\n")?; p.expect_end()?; @@ -1053,29 +999,21 @@ mod when_main_branch_is_uptodate { let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(2, true, None)?; p.expect_eventually("--force`\r\n")?; - let mut c = p.expect_choice( - "", - vec![ - format!("checkout local branch with unpublished changes"), - format!( - "discard unpublished changes and checkout new revision" - ), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - "back".to_string(), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!("checkout local branch with unpublished changes"), + format!("discard unpublished changes and checkout new revision"), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + "back".to_string(), + ])?; c.succeeds_with(1, true, Some(0))?; p.expect_end_eventually_and_print()?; @@ -1132,14 +1070,11 @@ mod when_main_branch_is_uptodate { let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(2, true, None)?; p.expect("you have an amended/rebase version the proposal that is unpublished\r\n")?; p.expect("you have previously applied the latest version of the proposal (2 ahead 0 behind 'main') but your local proposal branch has amended or rebased it (2 ahead 0 behind 'main')\r\n")?; @@ -1148,18 +1083,13 @@ mod when_main_branch_is_uptodate { p.expect(" 2) run `ngit list` and checkout the latest published version of this proposal\r\n")?; p.expect("if you are confident in your changes consider running `ngit push --force`\r\n")?; - let mut c = p.expect_choice( - "", - vec![ - format!("checkout local branch with unpublished changes"), - format!( - "discard unpublished changes and checkout new revision" - ), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - "back".to_string(), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!("checkout local branch with unpublished changes"), + format!("discard unpublished changes and checkout new revision"), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + "back".to_string(), + ])?; c.succeeds_with(1, true, Some(1))?; p.expect_end_with("checked out latest version of proposal (2 ahead 0 behind 'main'), replacing unpublished version (2 ahead 0 behind 'main')\r\n")?; @@ -1237,26 +1167,20 @@ mod when_main_branch_is_uptodate { let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(2, true, None)?; p.expect( "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", )?; - let mut c = p.expect_choice( - "", - vec![ - format!("checkout proposal branch with 1 unpublished commits"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!("checkout proposal branch with 1 unpublished commits"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect("checked out proposal branch with 1 unpublished commits (3 ahead 0 behind 'main')\r\n")?; p.expect_end()?; @@ -1319,26 +1243,20 @@ mod when_main_branch_is_uptodate { let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(2, true, None)?; p.expect( "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", )?; - let mut c = p.expect_choice( - "", - vec![ - format!("checkout proposal branch with 1 unpublished commits"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!("checkout proposal branch with 1 unpublished commits"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect("checked out proposal branch with 1 unpublished commits (3 ahead 0 behind 'main')\r\n")?; p.expect_end()?; @@ -1421,26 +1339,20 @@ mod when_main_branch_is_uptodate { let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(2, true, None)?; p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?; - let mut c = p.expect_choice( - "", - vec![ - format!("checkout and overwrite existing proposal branch"), - format!("checkout existing outdated proposal branch"), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!("checkout and overwrite existing proposal branch"), + format!("checkout existing outdated proposal branch"), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect("checked out new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?; p.expect_end()?; @@ -1494,26 +1406,20 @@ mod when_main_branch_is_uptodate { let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // some updates listed here - let mut c = p.expect_choice( - "all proposals", - vec![ - format!("\"{PROPOSAL_TITLE_3}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_1}\""), - ], - )?; + let mut c = p.expect_choice("all proposals", vec![ + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), + ])?; c.succeeds_with(2, true, None)?; p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?; - let mut c = p.expect_choice( - "", - vec![ - format!("checkout and overwrite existing proposal branch"), - format!("checkout existing outdated proposal branch"), - format!("apply to current branch with `git am`"), - format!("download to ./patches"), - format!("back"), - ], - )?; + let mut c = p.expect_choice("", vec![ + format!("checkout and overwrite existing proposal branch"), + format!("checkout existing outdated proposal branch"), + format!("apply to current branch with `git am`"), + format!("download to ./patches"), + format!("back"), + ])?; c.succeeds_with(0, true, Some(0))?; p.expect("checked out new version of proposal (2 ahead 0 behind 'main'), replacing old version (2 ahead 1 behind 'main')\r\n")?; p.expect_end()?; diff --git a/tests/ngit_login.rs b/tests/ngit_login.rs index 78a160c..b1e2676 100644 --- a/tests/ngit_login.rs +++ b/tests/ngit_login.rs @@ -6,27 +6,21 @@ use test_utils::*; static EXPECTED_NSEC_PROMPT: &str = "nsec"; fn show_first_time_login_choices(p: &mut CliTester) -> Result { - p.expect_choice( - "login to nostr", - vec![ - "secret key (nsec / ncryptsec)".to_string(), - "nostr connect (remote signer)".to_string(), - "create account".to_string(), - "help".to_string(), - ], - ) + p.expect_choice("login to nostr", vec![ + "secret key (nsec / ncryptsec)".to_string(), + "nostr connect (remote signer)".to_string(), + "create account".to_string(), + "help".to_string(), + ]) } fn first_time_login_choices_succeeds_with_nsec(p: &mut CliTester, nsec: &str) -> Result<()> { - p.expect_choice( - "login to nostr", - vec![ - "secret key (nsec / ncryptsec)".to_string(), - "nostr connect (remote signer)".to_string(), - "create account".to_string(), - "help".to_string(), - ], - )? + p.expect_choice("login to nostr", vec![ + "secret key (nsec / ncryptsec)".to_string(), + "nostr connect (remote signer)".to_string(), + "create account".to_string(), + "help".to_string(), + ])? .succeeds_with(0, false, Some(0))?; p.expect_input(EXPECTED_NSEC_PROMPT)? @@ -49,7 +43,7 @@ fn standard_first_time_login_with_nsec() -> Result { mod with_relays { use anyhow::Ok; use futures::join; - use test_utils::relay::{shutdown_relay, ListenerReqFunc, Relay}; + use test_utils::relay::{ListenerReqFunc, Relay, shutdown_relay}; use super::*; @@ -137,25 +131,17 @@ mod with_relays { async fn when_latest_metadata_and_relay_list_on_all_relays() -> Result<()> { run_test_displays_correct_name( Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event_same_as_fallback(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event_same_as_fallback(), + ])?; Ok(()) }), Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event_same_as_fallback(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event_same_as_fallback(), + ])?; Ok(()) }), ) @@ -170,18 +156,14 @@ mod with_relays { async fn when_metadata_contains_only_display_name() -> Result<()> { run_test_displays_correct_name( Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - nostr::event::EventBuilder::metadata( - &nostr::Metadata::new().display_name("fred"), - ) - .sign_with_keys(&TEST_KEY_1_KEYS) - .unwrap(), - generate_test_key_1_relay_list_event_same_as_fallback(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + nostr::event::EventBuilder::metadata( + &nostr::Metadata::new().display_name("fred"), + ) + .sign_with_keys(&TEST_KEY_1_KEYS) + .unwrap(), + generate_test_key_1_relay_list_event_same_as_fallback(), + ])?; Ok(()) }), None, @@ -207,19 +189,14 @@ mod with_relays { run_test_displays_correct_name( Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - nostr::event::EventBuilder::metadata( - &nostr::Metadata::new() - .custom_field("displayName", "fred"), - ) - .sign_with_keys(&TEST_KEY_1_KEYS) - .unwrap(), - generate_test_key_1_relay_list_event_same_as_fallback(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + nostr::event::EventBuilder::metadata( + &nostr::Metadata::new().custom_field("displayName", "fred"), + ) + .sign_with_keys(&TEST_KEY_1_KEYS) + .unwrap(), + generate_test_key_1_relay_list_event_same_as_fallback(), + ])?; Ok(()) }), None, @@ -233,18 +210,14 @@ mod with_relays { -> Result<()> { run_test_displays_fallback_to_npub( Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - nostr::event::EventBuilder::metadata( - &nostr::Metadata::new().about("other info in metadata"), - ) - .sign_with_keys(&TEST_KEY_1_KEYS) - .unwrap(), - generate_test_key_1_relay_list_event_same_as_fallback(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + nostr::event::EventBuilder::metadata( + &nostr::Metadata::new().about("other info in metadata"), + ) + .sign_with_keys(&TEST_KEY_1_KEYS) + .unwrap(), + generate_test_key_1_relay_list_event_same_as_fallback(), + ])?; Ok(()) }), None, @@ -259,14 +232,10 @@ mod with_relays { -> Result<()> { run_test_displays_correct_name( Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event_same_as_fallback(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event_same_as_fallback(), + ])?; Ok(()) }), None, @@ -280,19 +249,15 @@ mod with_relays { { run_test_displays_correct_name( Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_test_key_1_metadata_event("fred")], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + ])?; Ok(()) }), Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_test_key_1_relay_list_event_same_as_fallback()], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_relay_list_event_same_as_fallback(), + ])?; Ok(()) }), ) @@ -304,22 +269,16 @@ mod with_relays { async fn when_some_relays_return_old_metadata_event() -> Result<()> { run_test_displays_correct_name( Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event_same_as_fallback(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event_same_as_fallback(), + ])?; Ok(()) }), Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_test_key_1_metadata_event_old("fred old")], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event_old("fred old"), + ])?; Ok(()) }), ) @@ -331,22 +290,16 @@ mod with_relays { async fn when_some_relays_return_other_users_metadata() -> Result<()> { run_test_displays_correct_name( Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_test_key_2_metadata_event("carole")], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_2_metadata_event("carole"), + ])?; Ok(()) }), Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event_old("fred"), - generate_test_key_1_relay_list_event_same_as_fallback(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event_old("fred"), + generate_test_key_1_relay_list_event_same_as_fallback(), + ])?; Ok(()) }), ) @@ -359,22 +312,16 @@ mod with_relays { run_test_displays_correct_name( Some(&|relay, client_id, subscription_id, _| -> Result<()> { let event = generate_test_key_1_kind_event(nostr::Kind::TextNote); - relay.respond_events( - client_id, - &subscription_id, - &vec![make_event_old_or_change_user(event, &TEST_KEY_1_KEYS, 0)], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + make_event_old_or_change_user(event, &TEST_KEY_1_KEYS, 0), + ])?; Ok(()) }), Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event_old("fred"), - generate_test_key_1_relay_list_event_same_as_fallback(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event_old("fred"), + generate_test_key_1_relay_list_event_same_as_fallback(), + ])?; Ok(()) }), ) @@ -389,14 +336,10 @@ mod with_relays { async fn displays_correct_name() -> Result<()> { run_test_when_specifying_command_line_nsec_only_displays_correct_name( Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event_same_as_fallback(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event_same_as_fallback(), + ])?; Ok(()) }), None, @@ -414,10 +357,12 @@ mod with_relays { let cli_tester_handle = std::thread::spawn(move || -> Result<()> { let test_repo = GitTestRepo::default(); - let mut p = CliTester::new_from_dir( - &test_repo.dir, - ["account", "login", "--nsec", TEST_KEY_1_NSEC], - ); + let mut p = CliTester::new_from_dir(&test_repo.dir, [ + "account", + "login", + "--nsec", + TEST_KEY_1_NSEC, + ]); p.expect("saved login details to local git config. you are only logged in to this local repository.\r\n")?; @@ -489,11 +434,9 @@ mod with_relays { async fn warm_user_and_displays_name() -> Result<()> { run_test_when_no_relay_list_found_warns_user_and_uses_npub( Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_test_key_1_metadata_event("fred")], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + ])?; Ok(()) }), None, @@ -584,25 +527,17 @@ mod with_relays { async fn displays_correct_name() -> Result<()> { run_test_displays_correct_name( Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event_old("Fred"), - generate_test_key_1_relay_list_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event_old("Fred"), + generate_test_key_1_relay_list_event(), + ])?; Ok(()) }), Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + ])?; Ok(()) }), ) @@ -674,10 +609,10 @@ mod with_offline_flag { true, )?; - p.expect_choice( - "login to nostr", - vec!["try again with nsec".to_string(), "back".to_string()], - )? + p.expect_choice("login to nostr", vec![ + "try again with nsec".to_string(), + "back".to_string(), + ])? .succeeds_with(0, false, Some(0))?; } @@ -697,10 +632,13 @@ mod with_offline_flag { #[test] fn valid_nsec_param_succeeds_without_prompts() -> Result<()> { let test_repo = GitTestRepo::default(); - let mut p = CliTester::new_from_dir( - &test_repo.dir, - ["account", "login", "--offline", "--nsec", TEST_KEY_1_NSEC], - ); + let mut p = CliTester::new_from_dir(&test_repo.dir, [ + "account", + "login", + "--offline", + "--nsec", + TEST_KEY_1_NSEC, + ]); p.expect("saved login details to local git config. you are only logged in to this local repository.\r\n")?; @@ -712,10 +650,13 @@ mod with_offline_flag { #[test] fn invalid_nsec_param_fails_without_prompts() -> Result<()> { let test_repo = GitTestRepo::default(); - let mut p = CliTester::new_from_dir( - &test_repo.dir, - ["account", "login", "--offline", "--nsec", TEST_INVALID_NSEC], - ); + let mut p = CliTester::new_from_dir(&test_repo.dir, [ + "account", + "login", + "--offline", + "--nsec", + TEST_INVALID_NSEC, + ]); p.expect_end_with( "Error: invalid nsec parameter\r\n\r\nCaused by:\r\n Invalid secret key\r\n", @@ -729,18 +670,15 @@ mod with_offline_flag { #[test] fn valid_nsec_param_succeeds_without_prompts() -> Result<()> { let test_repo = GitTestRepo::default(); - let mut p = CliTester::new_from_dir( - &test_repo.dir, - [ - "account", - "login", - "--offline", - "--nsec", - TEST_KEY_1_NSEC, - "--password", - TEST_PASSWORD, - ], - ); + let mut p = CliTester::new_from_dir(&test_repo.dir, [ + "account", + "login", + "--offline", + "--nsec", + TEST_KEY_1_NSEC, + "--password", + TEST_PASSWORD, + ]); p.expect("saved login details to local git config. you are only logged in to this local repository.\r\n")?; p.expect_end_with( @@ -751,18 +689,15 @@ mod with_offline_flag { #[test] fn parameters_can_be_called_globally() -> Result<()> { let test_repo = GitTestRepo::default(); - let mut p = CliTester::new_from_dir( - &test_repo.dir, - [ - "--nsec", - TEST_KEY_1_NSEC, - "--password", - TEST_PASSWORD, - "account", - "login", - "--offline", - ], - ); + let mut p = CliTester::new_from_dir(&test_repo.dir, [ + "--nsec", + TEST_KEY_1_NSEC, + "--password", + TEST_PASSWORD, + "account", + "login", + "--offline", + ]); p.expect("saved login details to local git config. you are only logged in to this local repository.\r\n")?; p.expect_end_with( @@ -777,18 +712,15 @@ mod with_offline_flag { fn valid_nsec_param_succeeds_without_prompts_and_logs_in() -> Result<()> { standard_first_time_login_with_nsec()?.exit()?; let test_repo = GitTestRepo::default(); - let mut p = CliTester::new_from_dir( - &test_repo.dir, - [ - "account", - "login", - "--offline", - "--nsec", - TEST_KEY_2_NSEC, - "--password", - TEST_PASSWORD, - ], - ); + let mut p = CliTester::new_from_dir(&test_repo.dir, [ + "account", + "login", + "--offline", + "--nsec", + TEST_KEY_2_NSEC, + "--password", + TEST_PASSWORD, + ]); p.expect("saved login details to local git config. you are only logged in to this local repository.\r\n")?; p.expect_end_with( diff --git a/tests/ngit_send.rs b/tests/ngit_send.rs index 1ffb515..d728d9c 100644 --- a/tests/ngit_send.rs +++ b/tests/ngit_send.rs @@ -181,14 +181,10 @@ async fn prep_run_create_proposal( 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + ])?; Ok(()) }), ), @@ -198,11 +194,9 @@ async fn prep_run_create_proposal( 8055, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_repo_ref_event()], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_repo_ref_event(), + ])?; Ok(()) }), ), @@ -764,14 +758,10 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + ])?; Ok(()) }), ), @@ -781,11 +771,9 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ 8055, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_repo_ref_event()], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_repo_ref_event(), + ])?; Ok(()) }), ), @@ -844,14 +832,10 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + ])?; Ok(()) }), ), @@ -861,11 +845,9 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ 8055, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_repo_ref_event()], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_repo_ref_event(), + ])?; Ok(()) }), ), @@ -918,14 +900,10 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + ])?; Ok(()) }), ), @@ -935,11 +913,9 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ 8055, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_repo_ref_event()], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_repo_ref_event(), + ])?; Ok(()) }), ), @@ -1012,14 +988,10 @@ mod when_no_cover_letter_flag_set_with_range_of_head_2_sends_2_patches_without_c 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + ])?; Ok(()) }), ), @@ -1029,11 +1001,9 @@ mod when_no_cover_letter_flag_set_with_range_of_head_2_sends_2_patches_without_c 8055, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_repo_ref_event()], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_repo_ref_event(), + ])?; Ok(()) }), ), @@ -1200,16 +1170,13 @@ mod when_range_ommited_prompts_for_selection_defaulting_ahead_of_main { fn expect_msgs_first(p: &mut CliTester) -> Result<()> { p.expect("fetching updates...\r\n")?; p.expect_eventually("\r\n")?; // may be 'no updates' or some updates - let mut selector = p.expect_multi_select( - "select commits for proposal", - vec![ - "(Joe Bloggs) add t4.md [feature] fe973a8".to_string(), - "(Joe Bloggs) add t3.md 232efb3".to_string(), - "(Joe Bloggs) add t2.md [main] 431b84e".to_string(), - "(Joe Bloggs) add t1.md af474d8".to_string(), - "(Joe Bloggs) Initial commit 9ee507f".to_string(), - ], - )?; + let mut selector = p.expect_multi_select("select commits for proposal", vec![ + "(Joe Bloggs) add t4.md [feature] fe973a8".to_string(), + "(Joe Bloggs) add t3.md 232efb3".to_string(), + "(Joe Bloggs) add t2.md [main] 431b84e".to_string(), + "(Joe Bloggs) add t1.md af474d8".to_string(), + "(Joe Bloggs) Initial commit 9ee507f".to_string(), + ])?; selector.succeeds_with(vec![0, 1], false, vec![0, 1])?; p.expect("creating proposal from 2 commits:\r\n")?; p.expect("fe973a8 add t4.md\r\n")?; @@ -1234,14 +1201,10 @@ mod when_range_ommited_prompts_for_selection_defaulting_ahead_of_main { 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + ])?; Ok(()) }), ), @@ -1251,11 +1214,9 @@ mod when_range_ommited_prompts_for_selection_defaulting_ahead_of_main { 8055, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_repo_ref_event()], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_repo_ref_event(), + ])?; Ok(()) }), ), @@ -1297,14 +1258,10 @@ mod when_range_ommited_prompts_for_selection_defaulting_ahead_of_main { 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + ])?; Ok(()) }), ), @@ -1314,11 +1271,9 @@ mod when_range_ommited_prompts_for_selection_defaulting_ahead_of_main { 8055, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_repo_ref_event()], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_repo_ref_event(), + ])?; Ok(()) }), ), @@ -1435,15 +1390,11 @@ mod root_proposal_specified_using_in_reply_to_with_range_of_head_2_and_cover_let 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - get_pretend_proposal_root_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + get_pretend_proposal_root_event(), + ])?; Ok(()) }), ), @@ -1453,11 +1404,10 @@ mod root_proposal_specified_using_in_reply_to_with_range_of_head_2_and_cover_let 8055, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_repo_ref_event(), get_pretend_proposal_root_event()], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_repo_ref_event(), + get_pretend_proposal_root_event(), + ])?; Ok(()) }), ), @@ -1498,15 +1448,11 @@ mod root_proposal_specified_using_in_reply_to_with_range_of_head_2_and_cover_let 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - get_pretend_proposal_root_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + get_pretend_proposal_root_event(), + ])?; Ok(()) }), ), @@ -1516,11 +1462,10 @@ mod root_proposal_specified_using_in_reply_to_with_range_of_head_2_and_cover_let 8055, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_repo_ref_event(), get_pretend_proposal_root_event()], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_repo_ref_event(), + get_pretend_proposal_root_event(), + ])?; Ok(()) }), ), @@ -1697,15 +1642,11 @@ mod in_reply_to_mentions_issue { 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - get_pretend_issue_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + get_pretend_issue_event(), + ])?; Ok(()) }), ), @@ -1715,11 +1656,10 @@ mod in_reply_to_mentions_issue { 8055, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_repo_ref_event(), get_pretend_issue_event()], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_repo_ref_event(), + get_pretend_issue_event(), + ])?; Ok(()) }), ), @@ -1821,14 +1761,10 @@ mod in_reply_to_mentions_npub_and_nprofile_which_get_mentioned_in_proposal_root 8051, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![ - generate_test_key_1_metadata_event("fred"), - generate_test_key_1_relay_list_event(), - ], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_test_key_1_metadata_event("fred"), + generate_test_key_1_relay_list_event(), + ])?; Ok(()) }), ), @@ -1838,11 +1774,9 @@ mod in_reply_to_mentions_npub_and_nprofile_which_get_mentioned_in_proposal_root 8055, None, Some(&|relay, client_id, subscription_id, _| -> Result<()> { - relay.respond_events( - client_id, - &subscription_id, - &vec![generate_repo_ref_event()], - )?; + relay.respond_events(client_id, &subscription_id, &vec![ + generate_repo_ref_event(), + ])?; Ok(()) }), ), -- cgit v1.2.3