upleb.uk

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

summaryrefslogtreecommitdiff
path: root/test_utils/src/lib.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-02-10 13:10:18 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-02-10 13:10:18 +0000
commit1e7aeb4d7972d29c6586df18128a8a4f7667845a (patch)
tree0f7e5fcaa5a005aeec7ae2d9f35b2c473ef8f785 /test_utils/src/lib.rs
parentd2412565334f48bd31e57d29d7959c24258ccd98 (diff)
parentaae452697d152694a8f163219f707356e84b420b (diff)
Make ngit non-interactive by default
Implements non-interactive mode as the default behavior for ngit. Users must now use -i flag for interactive prompts, or provide all required arguments explicitly. Adds -d flag for sensible defaults and -f flag for force operations. Changes: - CLI interactor infrastructure supports non-interactive mode - Global flags: -i (interactive), --defaults (use defaults), -f (force) - ngit init: requires --name or --identifier, supports --defaults - ngit account: new signup command, login supports non-interactive - ngit send: validates required fields, supports --defaults - git-remote-nostr: fixed to prevent interactive prompts during push - Comprehensive test coverage: 234 unit tests + integration tests
Diffstat (limited to 'test_utils/src/lib.rs')
-rw-r--r--test_utils/src/lib.rs78
1 files changed, 77 insertions, 1 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs
index bdfc550..a9a6d1e 100644
--- a/test_utils/src/lib.rs
+++ b/test_utils/src/lib.rs
@@ -208,6 +208,82 @@ pub fn generate_repo_ref_event_with_git_server_with_keys(
208 .sign_with_keys(keys) 208 .sign_with_keys(keys)
209 .unwrap() 209 .unwrap()
210} 210}
211
212/// Generate a repo announcement event signed by TEST_KEY_2 that lists
213/// TEST_KEY_1 as a maintainer. Used for State D tests (co-maintainer scenario).
214pub fn generate_repo_ref_event_as_key_2_listing_key_1() -> nostr::Event {
215 generate_repo_ref_event_as_key_2_with_maintainers(vec![
216 TEST_KEY_2_KEYS.public_key().to_string(),
217 TEST_KEY_1_KEYS.public_key().to_string(),
218 ])
219}
220
221/// Generate a repo announcement event signed by TEST_KEY_2 that does NOT list
222/// TEST_KEY_1. Used for State E tests (not listed scenario).
223pub fn generate_repo_ref_event_as_key_2_not_listing_key_1() -> nostr::Event {
224 generate_repo_ref_event_as_key_2_with_maintainers(vec![
225 TEST_KEY_2_KEYS.public_key().to_string(),
226 ])
227}
228
229/// Generate a repo announcement event signed by TEST_KEY_2 with specific
230/// maintainers.
231fn generate_repo_ref_event_as_key_2_with_maintainers(maintainers: Vec<String>) -> nostr::Event {
232 let root_commit = "9ee507fc4357d7ee16a5d8901bedcd103f23c17d";
233 nostr::event::EventBuilder::new(nostr::Kind::GitRepoAnnouncement, "")
234 .tags([
235 Tag::identifier(format!("{root_commit}-consider-it-random")),
236 Tag::from_standardized(TagStandard::Reference(root_commit.to_string())),
237 Tag::from_standardized(TagStandard::Name("example name".into())),
238 Tag::from_standardized(TagStandard::Description("example description".into())),
239 Tag::custom(
240 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("clone")),
241 vec!["git:://123.gitexample.com/test".to_string()],
242 ),
243 Tag::custom(
244 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("web")),
245 vec![
246 "https://exampleproject.xyz".to_string(),
247 "https://gitworkshop.dev/123".to_string(),
248 ],
249 ),
250 Tag::custom(
251 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("relays")),
252 vec![
253 "ws://localhost:8055".to_string(),
254 "ws://localhost:8056".to_string(),
255 ],
256 ),
257 Tag::custom(
258 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("maintainers")),
259 maintainers,
260 ),
261 ])
262 .sign_with_keys(&TEST_KEY_2_KEYS)
263 .unwrap()
264}
265
266/// Generate relay list event for TEST_KEY_2 (same relays as KEY_1 for
267/// simplicity)
268pub fn generate_test_key_2_relay_list_event() -> nostr::Event {
269 nostr::event::EventBuilder::new(nostr::Kind::RelayList, "")
270 .tags([
271 nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata {
272 relay_url: nostr::RelayUrl::from_str("ws://localhost:8053").unwrap(),
273 metadata: Some(RelayMetadata::Write),
274 }),
275 nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata {
276 relay_url: nostr::RelayUrl::from_str("ws://localhost:8054").unwrap(),
277 metadata: Some(RelayMetadata::Read),
278 }),
279 nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata {
280 relay_url: nostr::RelayUrl::from_str("ws://localhost:8055").unwrap(),
281 metadata: None,
282 }),
283 ])
284 .sign_with_keys(&TEST_KEY_2_KEYS)
285 .unwrap()
286}
211/// enough to fool event_is_patch_set_root 287/// enough to fool event_is_patch_set_root
212pub fn get_pretend_proposal_root_event() -> nostr::Event { 288pub fn get_pretend_proposal_root_event() -> nostr::Event {
213 serde_json::from_str(r#"{"id":"000c104861e34a453481ab23e7de21a6baf475b394479705363b035936732528","pubkey":"f53e4bcd7a9cdef049cf6467d638a1321958acd3b71eb09823fd6fadb023d768","created_at":1754322009,"kind":1617,"tags":[["a","30617:f53e4bcd7a9cdef049cf6467d638a1321958acd3b71eb09823fd6fadb023d768:9ee507fc4357d7ee16a5d8901bedcd103f23c17d-consider-it-random","ws://localhost:8055"],["a","30617:ba882566eff14f3baa976103998c452d27fe95b65a796a6a9f92628bced76fe5:9ee507fc4357d7ee16a5d8901bedcd103f23c17d-consider-it-random","ws://localhost:8055"],["r","9ee507fc4357d7ee16a5d8901bedcd103f23c17d"],["r","232efb37ebc67692c9e9ff58b83c0d3d63971a0a"],["alt","git patch: add t3.md"],["t","root"],["branch-name","feature"],["p","ba882566eff14f3baa976103998c452d27fe95b65a796a6a9f92628bced76fe5"],["commit","232efb37ebc67692c9e9ff58b83c0d3d63971a0a"],["parent-commit","431b84edc0d2fa118d63faa3c2db9c73d630a5ae"],["commit-pgp-sig",""],["description","add t3.md"],["author","Joe Bloggs","joe.bloggs@pm.me","0","0"],["committer","Joe Bloggs","joe.bloggs@pm.me","0","0"]],"content":"From 232efb37ebc67692c9e9ff58b83c0d3d63971a0a Mon Sep 17 00:00:00 2001\nFrom: Joe Bloggs <joe.bloggs@pm.me>\nDate: Thu, 1 Jan 1970 00:00:00 +0000\nSubject: [PATCH 1/2] add t3.md\n\n---\n t3.md | 1 +\n 1 file changed, 1 insertion(+)\n create mode 100644 t3.md\n\ndiff --git a/t3.md b/t3.md\nnew file mode 100644\nindex 0000000..f0eec86\n--- /dev/null\n+++ b/t3.md\n@@ -0,0 +1 @@\n+some content\n\\ No newline at end of file\n--\nlibgit2 1.9.1\n\n","sig":"65577fea803ea464bb073273a3fbfbdb5bfdaa64fb3b1d029ee8f3729fde051ad90610d08e441335f365b6c1d6f2270909bc37d12433ca82f0b2928b7a503e31"}"#).unwrap() 289 serde_json::from_str(r#"{"id":"000c104861e34a453481ab23e7de21a6baf475b394479705363b035936732528","pubkey":"f53e4bcd7a9cdef049cf6467d638a1321958acd3b71eb09823fd6fadb023d768","created_at":1754322009,"kind":1617,"tags":[["a","30617:f53e4bcd7a9cdef049cf6467d638a1321958acd3b71eb09823fd6fadb023d768:9ee507fc4357d7ee16a5d8901bedcd103f23c17d-consider-it-random","ws://localhost:8055"],["a","30617:ba882566eff14f3baa976103998c452d27fe95b65a796a6a9f92628bced76fe5:9ee507fc4357d7ee16a5d8901bedcd103f23c17d-consider-it-random","ws://localhost:8055"],["r","9ee507fc4357d7ee16a5d8901bedcd103f23c17d"],["r","232efb37ebc67692c9e9ff58b83c0d3d63971a0a"],["alt","git patch: add t3.md"],["t","root"],["branch-name","feature"],["p","ba882566eff14f3baa976103998c452d27fe95b65a796a6a9f92628bced76fe5"],["commit","232efb37ebc67692c9e9ff58b83c0d3d63971a0a"],["parent-commit","431b84edc0d2fa118d63faa3c2db9c73d630a5ae"],["commit-pgp-sig",""],["description","add t3.md"],["author","Joe Bloggs","joe.bloggs@pm.me","0","0"],["committer","Joe Bloggs","joe.bloggs@pm.me","0","0"]],"content":"From 232efb37ebc67692c9e9ff58b83c0d3d63971a0a Mon Sep 17 00:00:00 2001\nFrom: Joe Bloggs <joe.bloggs@pm.me>\nDate: Thu, 1 Jan 1970 00:00:00 +0000\nSubject: [PATCH 1/2] add t3.md\n\n---\n t3.md | 1 +\n 1 file changed, 1 insertion(+)\n create mode 100644 t3.md\n\ndiff --git a/t3.md b/t3.md\nnew file mode 100644\nindex 0000000..f0eec86\n--- /dev/null\n+++ b/t3.md\n@@ -0,0 +1 @@\n+some content\n\\ No newline at end of file\n--\nlibgit2 1.9.1\n\n","sig":"65577fea803ea464bb073273a3fbfbdb5bfdaa64fb3b1d029ee8f3729fde051ad90610d08e441335f365b6c1d6f2270909bc37d12433ca82f0b2928b7a503e31"}"#).unwrap()
@@ -1416,7 +1492,7 @@ pub fn use_ngit_list_to_download_and_checkout_proposal_branch(
1416 test_repo: &GitTestRepo, 1492 test_repo: &GitTestRepo,
1417 proposal_number: u16, 1493 proposal_number: u16,
1418) -> Result<()> { 1494) -> Result<()> {
1419 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 1495 let mut p = CliTester::new_from_dir(&test_repo.dir, ["-i", "list"]);
1420 p.expect("fetching updates...\r\n")?; 1496 p.expect("fetching updates...\r\n")?;
1421 p.expect_eventually("\r\n")?; // some updates listed here 1497 p.expect_eventually("\r\n")?; // some updates listed here
1422 let mut c = p.expect_choice( 1498 let mut c = p.expect_choice(