diff options
Diffstat (limited to 'tests/sync/maintainer_reprocessing.rs')
| -rw-r--r-- | tests/sync/maintainer_reprocessing.rs | 235 |
1 files changed, 147 insertions, 88 deletions
diff --git a/tests/sync/maintainer_reprocessing.rs b/tests/sync/maintainer_reprocessing.rs index 266a437..61d8e14 100644 --- a/tests/sync/maintainer_reprocessing.rs +++ b/tests/sync/maintainer_reprocessing.rs | |||
| @@ -2,51 +2,61 @@ | |||
| 2 | //! | 2 | //! |
| 3 | //! Tests the two-tier rejected events index and immediate re-processing of | 3 | //! Tests the two-tier rejected events index and immediate re-processing of |
| 4 | //! maintainer announcements when owner announcements are accepted. | 4 | //! maintainer announcements when owner announcements are accepted. |
| 5 | //! | ||
| 6 | //! ## Test design | ||
| 7 | //! | ||
| 8 | //! Announcements now require git data before they are released from purgatory and | ||
| 9 | //! served to other relays. The hot-cache re-processing path we want to exercise is: | ||
| 10 | //! | ||
| 11 | //! relay_b syncs maintainer announcement from relay_a | ||
| 12 | //! → write policy rejects it (no owner announcement in DB yet) | ||
| 13 | //! → event stored in hot cache | ||
| 14 | //! owner git push to relay_b promotes owner announcement from purgatory | ||
| 15 | //! → our new code calls rejected_events_index.invalidate_and_get() | ||
| 16 | //! → maintainer announcement re-processed and accepted | ||
| 17 | //! | ||
| 18 | //! To guarantee the maintainer announcements arrive at relay_b *before* the owner | ||
| 19 | //! git push, relay_b is started with relay_a as its bootstrap relay. That way | ||
| 20 | //! relay_b's SyncManager connects to relay_a immediately and syncs whatever is | ||
| 21 | //! already in relay_a's DB. We push the maintainer git data first (so the | ||
| 22 | //! announcements are in relay_a's DB), wait briefly for the sync round-trip, then | ||
| 23 | //! send the owner announcement + git push. | ||
| 5 | 24 | ||
| 6 | use std::time::Duration; | 25 | use std::time::Duration; |
| 7 | 26 | ||
| 8 | use nostr_sdk::prelude::*; | 27 | use nostr_sdk::prelude::*; |
| 9 | 28 | ||
| 10 | use crate::common::{ | 29 | use crate::common::{sync_helpers::*, TestRelay}; |
| 11 | sync_helpers::*, | ||
| 12 | TestRelay, | ||
| 13 | }; | ||
| 14 | 30 | ||
| 15 | /// Test that maintainer announcements are re-processed immediately when owner announcement accepted | 31 | /// Test that a maintainer announcement is re-processed immediately when the owner |
| 32 | /// announcement is promoted from purgatory via a git push. | ||
| 16 | /// | 33 | /// |
| 17 | /// Flow: | 34 | /// Flow: |
| 18 | /// 1. relay_a: Maintainer sends announcement (gets rejected - doesn't list relay_b) | 35 | /// 1. relay_a: Maintainer sends announcement + git data → accepted into relay_a's DB |
| 19 | /// 2. relay_b: Owner sends announcement (lists relay_a + maintainer) | 36 | /// 2. relay_b (bootstrapped from relay_a): SyncManager syncs maintainer announcement |
| 20 | /// 3. relay_b syncs from relay_a, maintainer announcement enters rejected index | 37 | /// → rejected by write policy (no owner in DB) → stored in hot cache |
| 21 | /// 4. relay_b processes owner announcement, invalidates and re-processes maintainer announcement | 38 | /// 3. relay_b: Owner sends announcement → purgatory (no git data yet) |
| 39 | /// 4. relay_b: Owner git push → owner announcement promoted from purgatory | ||
| 40 | /// → hot-cache re-processing fires → maintainer announcement accepted | ||
| 22 | /// 5. Both announcements should be in relay_b's database | 41 | /// 5. Both announcements should be in relay_b's database |
| 23 | /// | ||
| 24 | /// Expected time: <5 seconds (vs 24 hours without hot cache) | ||
| 25 | #[tokio::test] | 42 | #[tokio::test] |
| 26 | async fn test_maintainer_announcement_reprocessed_immediately() { | 43 | async fn test_maintainer_announcement_reprocessed_immediately() { |
| 27 | // Start relay_a (where maintainer announcement will be sent) | 44 | // Start relay_a (where maintainer announcement will be sent) |
| 28 | let relay_a = TestRelay::start().await; | 45 | let relay_a = TestRelay::start().await; |
| 29 | println!("relay_a started at {}", relay_a.url()); | 46 | println!("relay_a started at {}", relay_a.url()); |
| 30 | 47 | ||
| 31 | // Start relay_b with sync enabled (will sync from relay_a) | ||
| 32 | let relay_b = TestRelay::start_with_sync(None).await; | ||
| 33 | println!("relay_b started at {}", relay_b.url()); | ||
| 34 | |||
| 35 | // Create keys | 48 | // Create keys |
| 36 | let owner_keys = Keys::generate(); | 49 | let owner_keys = Keys::generate(); |
| 37 | let maintainer_keys = Keys::generate(); | 50 | let maintainer_keys = Keys::generate(); |
| 38 | |||
| 39 | let identifier = "test-repo"; | 51 | let identifier = "test-repo"; |
| 40 | 52 | ||
| 41 | let start = std::time::Instant::now(); | 53 | // Step 1: Send maintainer announcement to relay_a then push git data so it lands in |
| 42 | 54 | // relay_a's DB. The announcement lists relay_a only (not relay_b), so relay_b's write | |
| 43 | // Step 1: Send maintainer announcement to relay_a (will be rejected by relay_b - doesn't list relay_b) | 55 | // policy will reject it when it arrives via sync. |
| 44 | // Use HTTP clone URL pointing to relay_a's git endpoint so it can be released from purgatory | ||
| 45 | let maintainer_npub = maintainer_keys | 56 | let maintainer_npub = maintainer_keys |
| 46 | .public_key() | 57 | .public_key() |
| 47 | .to_bech32() | 58 | .to_bech32() |
| 48 | .expect("Failed to get npub"); | 59 | .expect("Failed to get npub"); |
| 49 | |||
| 50 | let maintainer_announcement = | 60 | let maintainer_announcement = |
| 51 | EventBuilder::new(Kind::GitRepoAnnouncement, "Maintainer's repository") | 61 | EventBuilder::new(Kind::GitRepoAnnouncement, "Maintainer's repository") |
| 52 | .tags(vec![ | 62 | .tags(vec![ |
| @@ -60,27 +70,33 @@ async fn test_maintainer_announcement_reprocessed_immediately() { | |||
| 60 | identifier | 70 | identifier |
| 61 | )], | 71 | )], |
| 62 | ), | 72 | ), |
| 63 | Tag::custom(TagKind::custom("relays"), vec![relay_a.url().to_string()]), | 73 | Tag::custom( |
| 74 | TagKind::custom("relays"), | ||
| 75 | vec![relay_a.url().to_string()], | ||
| 76 | ), | ||
| 64 | ]) | 77 | ]) |
| 65 | .sign_with_keys(&maintainer_keys) | 78 | .sign_with_keys(&maintainer_keys) |
| 66 | .unwrap(); | 79 | .unwrap(); |
| 80 | send_to_relay(&relay_a, &maintainer_announcement).await.unwrap(); | ||
| 81 | let _git_dir_maintainer = | ||
| 82 | push_git_data_to_relay(&relay_a, &maintainer_keys, identifier, &[&relay_a.domain()]) | ||
| 83 | .await; | ||
| 84 | println!("✓ Maintainer announcement + git data pushed to relay_a"); | ||
| 85 | |||
| 86 | // Step 2: Start relay_b with relay_a as bootstrap so its SyncManager connects immediately. | ||
| 87 | // relay_b's initial negentropy sync will pick up the maintainer announcement and reject it | ||
| 88 | // (no owner announcement in relay_b's DB yet), storing it in the hot cache. | ||
| 89 | let relay_b = TestRelay::start_with_sync(Some(relay_a.url().to_string())).await; | ||
| 90 | println!("relay_b started at {}", relay_b.url()); | ||
| 67 | 91 | ||
| 68 | send_to_relay(&relay_a, &maintainer_announcement) | 92 | // Give relay_b's SyncManager time to complete the initial negentropy sync with relay_a. |
| 69 | .await | 93 | tokio::time::sleep(Duration::from_secs(3)).await; |
| 70 | .unwrap(); | 94 | println!("✓ relay_b synced from relay_a (maintainer announcement should be in hot cache)"); |
| 71 | println!("✓ Maintainer announcement sent to relay_a"); | 95 | |
| 72 | 96 | let start = std::time::Instant::now(); | |
| 73 | // Push git data for maintainer's repo to relay_a → releases maintainer announcement from purgatory | 97 | |
| 74 | let _git_dir_maintainer = push_git_data_to_relay( | 98 | // Step 3: Send owner announcement to relay_b → goes to purgatory (no git data yet). |
| 75 | &relay_a, | 99 | // The announcement lists relay_a + relay_b and names the maintainer. |
| 76 | &maintainer_keys, | ||
| 77 | identifier, | ||
| 78 | &[&relay_a.domain()], | ||
| 79 | ) | ||
| 80 | .await; | ||
| 81 | println!("✓ Maintainer git data pushed to relay_a (announcement released from purgatory)"); | ||
| 82 | |||
| 83 | // Step 2: Set up owner announcement on relay_b (lists relay_a + maintainer) with git data | ||
| 84 | let owner_npub = owner_keys | 100 | let owner_npub = owner_keys |
| 85 | .public_key() | 101 | .public_key() |
| 86 | .to_bech32() | 102 | .to_bech32() |
| @@ -111,19 +127,21 @@ async fn test_maintainer_announcement_reprocessed_immediately() { | |||
| 111 | .unwrap(); | 127 | .unwrap(); |
| 112 | 128 | ||
| 113 | send_to_relay(&relay_b, &owner_announcement).await.unwrap(); | 129 | send_to_relay(&relay_b, &owner_announcement).await.unwrap(); |
| 114 | println!("✓ Owner announcement sent to relay_b"); | 130 | println!("✓ Owner announcement sent to relay_b (now in purgatory)"); |
| 115 | 131 | ||
| 116 | // Push git data for owner's repo to relay_b → releases owner announcement from purgatory | 132 | // Step 4: Push owner git data to relay_b. |
| 133 | // This promotes the owner announcement from purgatory, which triggers hot-cache | ||
| 134 | // re-processing of the maintainer announcement via our new code path. | ||
| 117 | let _git_dir_owner = | 135 | let _git_dir_owner = |
| 118 | push_git_data_to_relay(&relay_b, &owner_keys, identifier, &[&relay_b.domain()]).await; | 136 | push_git_data_to_relay(&relay_b, &owner_keys, identifier, &[&relay_b.domain()]).await; |
| 119 | println!("✓ Owner git data pushed to relay_b (announcement released from purgatory)"); | 137 | println!("✓ Owner git data pushed to relay_b (owner announcement promoted, hot cache re-processed)"); |
| 120 | 138 | ||
| 121 | // Step 3: Wait for sync and re-processing (relay_b discovers relay_a, syncs, re-processes) | 139 | // Step 5: Wait briefly for async processing to complete. |
| 122 | tokio::time::sleep(Duration::from_secs(3)).await; | 140 | tokio::time::sleep(Duration::from_secs(1)).await; |
| 123 | 141 | ||
| 124 | let elapsed = start.elapsed(); | 142 | let elapsed = start.elapsed(); |
| 125 | 143 | ||
| 126 | // Step 4: Verify both announcements are in relay_b's database | 144 | // Step 6: Verify both announcements are in relay_b's database. |
| 127 | let owner_filter = Filter::new() | 145 | let owner_filter = Filter::new() |
| 128 | .kind(Kind::GitRepoAnnouncement) | 146 | .kind(Kind::GitRepoAnnouncement) |
| 129 | .author(owner_keys.public_key()) | 147 | .author(owner_keys.public_key()) |
| @@ -145,7 +163,6 @@ async fn test_maintainer_announcement_reprocessed_immediately() { | |||
| 145 | "Maintainer announcement should be re-processed and accepted in relay_b" | 163 | "Maintainer announcement should be re-processed and accepted in relay_b" |
| 146 | ); | 164 | ); |
| 147 | 165 | ||
| 148 | // Step 5: Verify it happened quickly (not 24 hours!) | ||
| 149 | assert!( | 166 | assert!( |
| 150 | elapsed.as_secs() < 15, | 167 | elapsed.as_secs() < 15, |
| 151 | "Re-processing should happen in <15 seconds, took {:?}", | 168 | "Re-processing should happen in <15 seconds, took {:?}", |
| @@ -258,13 +275,16 @@ async fn test_maintainer_announcement_cold_index_prevents_refetch() { | |||
| 258 | relay.stop().await; | 275 | relay.stop().await; |
| 259 | } | 276 | } |
| 260 | 277 | ||
| 261 | /// Test multiple maintainers are all re-processed when owner announcement accepted | 278 | /// Test that all maintainer announcements are re-processed when the owner announcement |
| 279 | /// is promoted from purgatory via a git push. | ||
| 262 | /// | 280 | /// |
| 263 | /// Flow: | 281 | /// Flow: |
| 264 | /// 1. relay_a: Three maintainers send announcements (get rejected - don't list relay_b) | 282 | /// 1. relay_a: Three maintainers send announcements + git data → in relay_a's DB |
| 265 | /// 2. relay_b: Owner sends announcement (lists relay_a + all three maintainers) | 283 | /// 2. relay_b (bootstrapped from relay_a): SyncManager syncs all three maintainer |
| 266 | /// 3. relay_b syncs from relay_a, all maintainer announcements enter rejected index | 284 | /// announcements → all rejected (no owner in DB) → all in hot cache |
| 267 | /// 4. relay_b processes owner announcement, invalidates and re-processes all maintainer announcements | 285 | /// 3. relay_b: Owner sends announcement → purgatory |
| 286 | /// 4. relay_b: Owner git push → owner promoted → hot-cache re-processing fires for | ||
| 287 | /// all three maintainers | ||
| 268 | /// 5. All four announcements should be in relay_b's database | 288 | /// 5. All four announcements should be in relay_b's database |
| 269 | #[tokio::test] | 289 | #[tokio::test] |
| 270 | async fn test_multiple_maintainers_all_reprocessed() { | 290 | async fn test_multiple_maintainers_all_reprocessed() { |
| @@ -272,21 +292,23 @@ async fn test_multiple_maintainers_all_reprocessed() { | |||
| 272 | let relay_a = TestRelay::start().await; | 292 | let relay_a = TestRelay::start().await; |
| 273 | println!("relay_a started at {}", relay_a.url()); | 293 | println!("relay_a started at {}", relay_a.url()); |
| 274 | 294 | ||
| 275 | // Start relay_b with sync enabled (will sync from relay_a) | ||
| 276 | let relay_b = TestRelay::start_with_sync(None).await; | ||
| 277 | println!("relay_b started at {}", relay_b.url()); | ||
| 278 | |||
| 279 | // Create keys | 295 | // Create keys |
| 280 | let owner_keys = Keys::generate(); | 296 | let owner_keys = Keys::generate(); |
| 281 | let maintainer1_keys = Keys::generate(); | 297 | let maintainer1_keys = Keys::generate(); |
| 282 | let maintainer2_keys = Keys::generate(); | 298 | let maintainer2_keys = Keys::generate(); |
| 283 | let maintainer3_keys = Keys::generate(); | 299 | let maintainer3_keys = Keys::generate(); |
| 284 | 300 | ||
| 285 | let identifier = "multi-maintainer-repo"; | 301 | // Use a unique identifier per test run to avoid cross-test interference when |
| 302 | // tests run in parallel (each test gets its own namespace on relay_a). | ||
| 303 | let identifier = &format!( | ||
| 304 | "multi-maintainer-repo-{}", | ||
| 305 | owner_keys.public_key().to_hex()[..8].to_string() | ||
| 306 | ); | ||
| 286 | 307 | ||
| 287 | // Step 1: Send three maintainer announcements to relay_a with git data | 308 | // Step 1: Send each maintainer announcement to relay_a then push git data so all three |
| 288 | // (purgatory requires git data before announcements are accepted) | 309 | // land in relay_a's DB. Each announcement lists relay_a only, so relay_b will reject |
| 289 | let mut git_dirs_maintainers = Vec::new(); | 310 | // them when syncing (no owner announcement in relay_b's DB yet). |
| 311 | let mut git_dirs = Vec::new(); | ||
| 290 | for (idx, maintainer_keys) in [&maintainer1_keys, &maintainer2_keys, &maintainer3_keys] | 312 | for (idx, maintainer_keys) in [&maintainer1_keys, &maintainer2_keys, &maintainer3_keys] |
| 291 | .iter() | 313 | .iter() |
| 292 | .enumerate() | 314 | .enumerate() |
| @@ -295,13 +317,12 @@ async fn test_multiple_maintainers_all_reprocessed() { | |||
| 295 | .public_key() | 317 | .public_key() |
| 296 | .to_bech32() | 318 | .to_bech32() |
| 297 | .expect("Failed to get npub"); | 319 | .expect("Failed to get npub"); |
| 298 | |||
| 299 | let announcement = EventBuilder::new( | 320 | let announcement = EventBuilder::new( |
| 300 | Kind::GitRepoAnnouncement, | 321 | Kind::GitRepoAnnouncement, |
| 301 | format!("Maintainer {} repository", idx + 1), | 322 | format!("Maintainer {} repository", idx + 1), |
| 302 | ) | 323 | ) |
| 303 | .tags(vec![ | 324 | .tags(vec![ |
| 304 | Tag::identifier(identifier), | 325 | Tag::identifier(identifier.as_str()), |
| 305 | Tag::custom( | 326 | Tag::custom( |
| 306 | TagKind::custom("clone"), | 327 | TagKind::custom("clone"), |
| 307 | vec![format!( | 328 | vec![format!( |
| @@ -315,18 +336,53 @@ async fn test_multiple_maintainers_all_reprocessed() { | |||
| 315 | ]) | 336 | ]) |
| 316 | .sign_with_keys(maintainer_keys) | 337 | .sign_with_keys(maintainer_keys) |
| 317 | .unwrap(); | 338 | .unwrap(); |
| 318 | |||
| 319 | send_to_relay(&relay_a, &announcement).await.unwrap(); | 339 | send_to_relay(&relay_a, &announcement).await.unwrap(); |
| 340 | // Use push_unique_git_data_to_relay so each maintainer gets a distinct commit | ||
| 341 | // hash. Identical hashes cause git to skip pack transfer when the object | ||
| 342 | // already exists on the server, leaving the announcement in purgatory. | ||
| 343 | let git_dir = push_unique_git_data_to_relay( | ||
| 344 | &relay_a, | ||
| 345 | maintainer_keys, | ||
| 346 | identifier, | ||
| 347 | &[&relay_a.domain()], | ||
| 348 | &m_npub, | ||
| 349 | ) | ||
| 350 | .await; | ||
| 351 | git_dirs.push(git_dir); | ||
| 352 | } | ||
| 353 | println!("✓ Three maintainer announcements + git data pushed to relay_a"); | ||
| 320 | 354 | ||
| 321 | // Push git data to release each maintainer's announcement from purgatory | 355 | // Confirm all three announcements are queryable on relay_a before starting relay_b. |
| 322 | let git_dir = | 356 | // This eliminates the race between relay_a's DB writes and relay_b's initial negentropy sync. |
| 323 | push_git_data_to_relay(&relay_a, maintainer_keys, identifier, &[&relay_a.domain()]) | 357 | for (name, keys) in [ |
| 324 | .await; | 358 | ("maintainer1", &maintainer1_keys), |
| 325 | git_dirs_maintainers.push(git_dir); | 359 | ("maintainer2", &maintainer2_keys), |
| 360 | ("maintainer3", &maintainer3_keys), | ||
| 361 | ] { | ||
| 362 | let filter = Filter::new() | ||
| 363 | .kind(Kind::GitRepoAnnouncement) | ||
| 364 | .author(keys.public_key()) | ||
| 365 | .identifier(identifier); | ||
| 366 | let found = | ||
| 367 | wait_for_event_on_relay(relay_a.url(), filter, Duration::from_secs(10)).await; | ||
| 368 | assert!(found, "{} announcement should be in relay_a before starting relay_b", name); | ||
| 326 | } | 369 | } |
| 327 | println!("✓ Three maintainer announcements sent to relay_a with git data"); | 370 | println!("✓ All three maintainer announcements confirmed in relay_a's DB"); |
| 371 | |||
| 372 | // Step 2: Start relay_b with relay_a as bootstrap so its SyncManager connects immediately. | ||
| 373 | // Because all three maintainer announcements are confirmed in relay_a's DB, relay_b's | ||
| 374 | // initial negentropy sync will pick them all up and reject them (no owner announcement | ||
| 375 | // in relay_b's DB yet), storing them in the hot cache. | ||
| 376 | let relay_b = TestRelay::start_with_sync(Some(relay_a.url().to_string())).await; | ||
| 377 | println!("relay_b started at {}", relay_b.url()); | ||
| 378 | |||
| 379 | // Give relay_b's SyncManager time to complete the initial negentropy sync with relay_a. | ||
| 380 | // The negentropy sync completes within ~200ms (NGIT_SYNC_BATCH_WINDOW_MS=200), but we | ||
| 381 | // allow extra time for slow CI environments. | ||
| 382 | tokio::time::sleep(Duration::from_secs(3)).await; | ||
| 383 | println!("✓ relay_b synced from relay_a (maintainer announcements should be in hot cache)"); | ||
| 328 | 384 | ||
| 329 | // Step 2: Send owner announcement to relay_b (lists relay_a + all three maintainers) | 385 | // Step 3: Send owner announcement to relay_b → goes to purgatory. |
| 330 | let owner_npub = owner_keys | 386 | let owner_npub = owner_keys |
| 331 | .public_key() | 387 | .public_key() |
| 332 | .to_bech32() | 388 | .to_bech32() |
| @@ -361,17 +417,19 @@ async fn test_multiple_maintainers_all_reprocessed() { | |||
| 361 | .unwrap(); | 417 | .unwrap(); |
| 362 | 418 | ||
| 363 | send_to_relay(&relay_b, &owner_announcement).await.unwrap(); | 419 | send_to_relay(&relay_b, &owner_announcement).await.unwrap(); |
| 364 | println!("✓ Owner announcement sent to relay_b"); | 420 | println!("✓ Owner announcement sent to relay_b (now in purgatory)"); |
| 365 | 421 | ||
| 366 | // Push git data for owner to relay_b → releases owner announcement from purgatory | 422 | // Step 4: Push owner git data to relay_b. |
| 423 | // This promotes the owner announcement from purgatory and triggers hot-cache | ||
| 424 | // re-processing for all three maintainer announcements. | ||
| 367 | let _git_dir_owner = | 425 | let _git_dir_owner = |
| 368 | push_git_data_to_relay(&relay_b, &owner_keys, identifier, &[&relay_b.domain()]).await; | 426 | push_git_data_to_relay(&relay_b, &owner_keys, identifier, &[&relay_b.domain()]).await; |
| 369 | println!("✓ Owner git data pushed to relay_b (announcement released from purgatory)"); | 427 | println!("✓ Owner git data pushed to relay_b (hot-cache re-processing should fire)"); |
| 370 | 428 | ||
| 371 | // Step 3: Wait for sync and re-processing | 429 | // Step 5: Wait briefly for async processing to complete. |
| 372 | tokio::time::sleep(Duration::from_secs(3)).await; | 430 | tokio::time::sleep(Duration::from_secs(1)).await; |
| 373 | 431 | ||
| 374 | // Step 4: Verify all four announcements are in relay_b's database | 432 | // Step 6: Verify all four announcements are in relay_b's database. |
| 375 | for (name, keys) in [ | 433 | for (name, keys) in [ |
| 376 | ("owner", &owner_keys), | 434 | ("owner", &owner_keys), |
| 377 | ("maintainer1", &maintainer1_keys), | 435 | ("maintainer1", &maintainer1_keys), |
| @@ -396,10 +454,10 @@ async fn test_multiple_maintainers_all_reprocessed() { | |||
| 396 | /// Test that invalid maintainer public keys don't cause panics | 454 | /// Test that invalid maintainer public keys don't cause panics |
| 397 | /// | 455 | /// |
| 398 | /// Flow: | 456 | /// Flow: |
| 399 | /// 1. Maintainer announcement arrives → Rejected | 457 | /// 1. Maintainer announcement arrives → Rejected (doesn't list our relay) |
| 400 | /// 2. Owner announcement arrives with INVALID maintainer hex → Should handle gracefully | 458 | /// 2. Owner announcement + git push → accepted, with INVALID maintainer hex in maintainers tag |
| 401 | /// 3. Owner announcement should still be accepted | 459 | /// 3. Owner announcement should be accepted |
| 402 | /// 4. Maintainer announcement should NOT be re-processed (invalid pubkey) | 460 | /// 4. Maintainer announcement should NOT be re-processed (invalid pubkey can't be parsed) |
| 403 | #[tokio::test] | 461 | #[tokio::test] |
| 404 | async fn test_invalid_maintainer_pubkey_handled_gracefully() { | 462 | async fn test_invalid_maintainer_pubkey_handled_gracefully() { |
| 405 | let relay = TestRelay::start().await; | 463 | let relay = TestRelay::start().await; |
| @@ -410,8 +468,12 @@ async fn test_invalid_maintainer_pubkey_handled_gracefully() { | |||
| 410 | 468 | ||
| 411 | let identifier = "invalid-maintainer-repo"; | 469 | let identifier = "invalid-maintainer-repo"; |
| 412 | 470 | ||
| 471 | // Create client using TestClient helper | ||
| 472 | let client = TestClient::new(relay.url(), owner_keys.clone()) | ||
| 473 | .await | ||
| 474 | .expect("Failed to connect to relay"); | ||
| 475 | |||
| 413 | // Step 1: Send maintainer announcement (will be rejected - doesn't list our relay) | 476 | // Step 1: Send maintainer announcement (will be rejected - doesn't list our relay) |
| 414 | // This one uses example.com clone URL - it goes to purgatory on relay, never promoted | ||
| 415 | let maintainer_announcement = | 477 | let maintainer_announcement = |
| 416 | EventBuilder::new(Kind::GitRepoAnnouncement, "Maintainer's repository") | 478 | EventBuilder::new(Kind::GitRepoAnnouncement, "Maintainer's repository") |
| 417 | .tags(vec![ | 479 | .tags(vec![ |
| @@ -428,12 +490,13 @@ async fn test_invalid_maintainer_pubkey_handled_gracefully() { | |||
| 428 | .sign_with_keys(&maintainer_keys) | 490 | .sign_with_keys(&maintainer_keys) |
| 429 | .unwrap(); | 491 | .unwrap(); |
| 430 | 492 | ||
| 431 | // Send maintainer announcement - expect it to be rejected (purgatory / policy) | 493 | // Send maintainer announcement - expect it to be rejected |
| 432 | send_to_relay(&relay, &maintainer_announcement).await.ok(); | 494 | let _ = client.send_event(&maintainer_announcement).await; |
| 433 | tokio::time::sleep(Duration::from_millis(200)).await; | 495 | tokio::time::sleep(Duration::from_millis(200)).await; |
| 434 | 496 | ||
| 435 | // Step 2: Set up owner announcement with INVALID maintainer hex and git data | 497 | // Step 2: Send owner announcement with INVALID maintainer hex, then push git data. |
| 436 | // Use HTTP clone URL to relay's git endpoint so it can be released from purgatory | 498 | // The announcement goes to purgatory first; the git push promotes it. |
| 499 | // The invalid maintainer hex should be handled gracefully (no panic). | ||
| 437 | let owner_npub = owner_keys | 500 | let owner_npub = owner_keys |
| 438 | .public_key() | 501 | .public_key() |
| 439 | .to_bech32() | 502 | .to_bech32() |
| @@ -461,13 +524,8 @@ async fn test_invalid_maintainer_pubkey_handled_gracefully() { | |||
| 461 | .unwrap(); | 524 | .unwrap(); |
| 462 | 525 | ||
| 463 | send_to_relay(&relay, &owner_announcement).await.unwrap(); | 526 | send_to_relay(&relay, &owner_announcement).await.unwrap(); |
| 464 | |||
| 465 | // Push git data to relay → releases owner announcement from purgatory | ||
| 466 | let _git_dir = | 527 | let _git_dir = |
| 467 | push_git_data_to_relay(&relay, &owner_keys, identifier, &[&relay.domain()]).await; | 528 | push_git_data_to_relay(&relay, &owner_keys, identifier, &[&relay.domain()]).await; |
| 468 | println!("✓ Owner git data pushed to relay (announcement released from purgatory)"); | ||
| 469 | |||
| 470 | // Wait for processing | ||
| 471 | tokio::time::sleep(Duration::from_millis(500)).await; | 529 | tokio::time::sleep(Duration::from_millis(500)).await; |
| 472 | 530 | ||
| 473 | // Step 3: Verify owner announcement accepted, maintainer not re-processed | 531 | // Step 3: Verify owner announcement accepted, maintainer not re-processed |
| @@ -497,5 +555,6 @@ async fn test_invalid_maintainer_pubkey_handled_gracefully() { | |||
| 497 | 555 | ||
| 498 | println!("✅ Invalid maintainer pubkey handled gracefully without panic"); | 556 | println!("✅ Invalid maintainer pubkey handled gracefully without panic"); |
| 499 | 557 | ||
| 558 | client.disconnect().await; | ||
| 500 | relay.stop().await; | 559 | relay.stop().await; |
| 501 | } | 560 | } |