diff options
Diffstat (limited to 'src/purgatory')
| -rw-r--r-- | src/purgatory/mod.rs | 94 |
1 files changed, 80 insertions, 14 deletions
diff --git a/src/purgatory/mod.rs b/src/purgatory/mod.rs index d442ad8..8094450 100644 --- a/src/purgatory/mod.rs +++ b/src/purgatory/mod.rs | |||
| @@ -740,7 +740,10 @@ impl Purgatory { | |||
| 740 | for (event_id_str, event_opt, commit, source) in expired_prs { | 740 | for (event_id_str, event_opt, commit, source) in expired_prs { |
| 741 | // Log structured entry for PR events (not placeholders) | 741 | // Log structured entry for PR events (not placeholders) |
| 742 | if let Some(ref event) = event_opt { | 742 | if let Some(ref event) = event_opt { |
| 743 | let npub = event.pubkey.to_bech32().unwrap_or_else(|_| event.pubkey.to_hex()); | 743 | let npub = event |
| 744 | .pubkey | ||
| 745 | .to_bech32() | ||
| 746 | .unwrap_or_else(|_| event.pubkey.to_hex()); | ||
| 744 | let event_id_short = &event.id.to_hex()[..12]; | 747 | let event_id_short = &event.id.to_hex()[..12]; |
| 745 | let source_str = if source.is_direct() { "direct" } else { "sync" }; | 748 | let source_str = if source.is_direct() { "direct" } else { "sync" }; |
| 746 | 749 | ||
| @@ -751,7 +754,10 @@ impl Purgatory { | |||
| 751 | .iter() | 754 | .iter() |
| 752 | .filter_map(|tag| { | 755 | .filter_map(|tag| { |
| 753 | let tag_vec = tag.clone().to_vec(); | 756 | let tag_vec = tag.clone().to_vec(); |
| 754 | if tag_vec.len() >= 2 && tag_vec[0] == "a" && tag_vec[1].starts_with("30617:") { | 757 | if tag_vec.len() >= 2 |
| 758 | && tag_vec[0] == "a" | ||
| 759 | && tag_vec[1].starts_with("30617:") | ||
| 760 | { | ||
| 755 | // Format: 30617:<owner_pubkey>:<identifier> | 761 | // Format: 30617:<owner_pubkey>:<identifier> |
| 756 | let parts: Vec<&str> = tag_vec[1].split(':').collect(); | 762 | let parts: Vec<&str> = tag_vec[1].split(':').collect(); |
| 757 | if parts.len() >= 3 { | 763 | if parts.len() >= 3 { |
| @@ -1171,8 +1177,18 @@ mod tests { | |||
| 1171 | .sign_with_keys(&keys) | 1177 | .sign_with_keys(&keys) |
| 1172 | .unwrap(); | 1178 | .unwrap(); |
| 1173 | 1179 | ||
| 1174 | purgatory.add_state(event.clone(), "test-repo".to_string(), keys.public_key(), false); | 1180 | purgatory.add_state( |
| 1175 | purgatory.add_pr(event, "test-event-id".to_string(), "abc123".to_string(), false); | 1181 | event.clone(), |
| 1182 | "test-repo".to_string(), | ||
| 1183 | keys.public_key(), | ||
| 1184 | false, | ||
| 1185 | ); | ||
| 1186 | purgatory.add_pr( | ||
| 1187 | event, | ||
| 1188 | "test-event-id".to_string(), | ||
| 1189 | "abc123".to_string(), | ||
| 1190 | false, | ||
| 1191 | ); | ||
| 1176 | 1192 | ||
| 1177 | let (state_count, pr_count) = purgatory.count(); | 1193 | let (state_count, pr_count) = purgatory.count(); |
| 1178 | assert_eq!(state_count, 1); | 1194 | assert_eq!(state_count, 1); |
| @@ -1253,7 +1269,12 @@ mod tests { | |||
| 1253 | .sign_with_keys(&keys) | 1269 | .sign_with_keys(&keys) |
| 1254 | .unwrap(); | 1270 | .unwrap(); |
| 1255 | 1271 | ||
| 1256 | purgatory.add_pr(event, "pr-event-id".to_string(), "commit123".to_string(), false); | 1272 | purgatory.add_pr( |
| 1273 | event, | ||
| 1274 | "pr-event-id".to_string(), | ||
| 1275 | "commit123".to_string(), | ||
| 1276 | false, | ||
| 1277 | ); | ||
| 1257 | 1278 | ||
| 1258 | // Now should have pending events for test-repo | 1279 | // Now should have pending events for test-repo |
| 1259 | assert!(purgatory.has_pending_events("test-repo")); | 1280 | assert!(purgatory.has_pending_events("test-repo")); |
| @@ -1377,7 +1398,12 @@ fn test_cleanup_removes_expired_entries() { | |||
| 1377 | keys.public_key(), | 1398 | keys.public_key(), |
| 1378 | false, | 1399 | false, |
| 1379 | ); | 1400 | ); |
| 1380 | purgatory.add_pr(pr_event, "pr-123".to_string(), "commit-abc".to_string(), false); | 1401 | purgatory.add_pr( |
| 1402 | pr_event, | ||
| 1403 | "pr-123".to_string(), | ||
| 1404 | "commit-abc".to_string(), | ||
| 1405 | false, | ||
| 1406 | ); | ||
| 1381 | purgatory.add_pr_placeholder("pr-456".to_string(), "commit-def".to_string()); | 1407 | purgatory.add_pr_placeholder("pr-456".to_string(), "commit-def".to_string()); |
| 1382 | 1408 | ||
| 1383 | // Verify entries are there | 1409 | // Verify entries are there |
| @@ -1424,8 +1450,18 @@ fn test_cleanup_preserves_non_expired_entries() { | |||
| 1424 | .unwrap(); | 1450 | .unwrap(); |
| 1425 | 1451 | ||
| 1426 | // Add fresh entries | 1452 | // Add fresh entries |
| 1427 | purgatory.add_state(state_event, "test-repo".to_string(), keys.public_key(), false); | 1453 | purgatory.add_state( |
| 1428 | purgatory.add_pr(pr_event, "pr-123".to_string(), "commit-abc".to_string(), false); | 1454 | state_event, |
| 1455 | "test-repo".to_string(), | ||
| 1456 | keys.public_key(), | ||
| 1457 | false, | ||
| 1458 | ); | ||
| 1459 | purgatory.add_pr( | ||
| 1460 | pr_event, | ||
| 1461 | "pr-123".to_string(), | ||
| 1462 | "commit-abc".to_string(), | ||
| 1463 | false, | ||
| 1464 | ); | ||
| 1429 | 1465 | ||
| 1430 | // Run cleanup | 1466 | // Run cleanup |
| 1431 | let (state_removed, pr_removed) = purgatory.cleanup(); | 1467 | let (state_removed, pr_removed) = purgatory.cleanup(); |
| @@ -1757,8 +1793,18 @@ async fn test_save_and_restore_state_events() { | |||
| 1757 | let event1_id = event1.id; | 1793 | let event1_id = event1.id; |
| 1758 | let event2_id = event2.id; | 1794 | let event2_id = event2.id; |
| 1759 | 1795 | ||
| 1760 | purgatory.add_state(event1.clone(), "test-repo".to_string(), keys.public_key(), false); | 1796 | purgatory.add_state( |
| 1761 | purgatory.add_state(event2.clone(), "test-repo".to_string(), keys.public_key(), false); | 1797 | event1.clone(), |
| 1798 | "test-repo".to_string(), | ||
| 1799 | keys.public_key(), | ||
| 1800 | false, | ||
| 1801 | ); | ||
| 1802 | purgatory.add_state( | ||
| 1803 | event2.clone(), | ||
| 1804 | "test-repo".to_string(), | ||
| 1805 | keys.public_key(), | ||
| 1806 | false, | ||
| 1807 | ); | ||
| 1762 | 1808 | ||
| 1763 | // Save to disk | 1809 | // Save to disk |
| 1764 | purgatory.save_to_disk(&state_file).unwrap(); | 1810 | purgatory.save_to_disk(&state_file).unwrap(); |
| @@ -2283,8 +2329,18 @@ async fn test_comprehensive_roundtrip() { | |||
| 2283 | .sign_with_keys(&keys2) | 2329 | .sign_with_keys(&keys2) |
| 2284 | .unwrap(); | 2330 | .unwrap(); |
| 2285 | 2331 | ||
| 2286 | purgatory.add_state(state1.clone(), "repo1".to_string(), keys1.public_key(), false); | 2332 | purgatory.add_state( |
| 2287 | purgatory.add_state(state2.clone(), "repo2".to_string(), keys2.public_key(), false); | 2333 | state1.clone(), |
| 2334 | "repo1".to_string(), | ||
| 2335 | keys1.public_key(), | ||
| 2336 | false, | ||
| 2337 | ); | ||
| 2338 | purgatory.add_state( | ||
| 2339 | state2.clone(), | ||
| 2340 | "repo2".to_string(), | ||
| 2341 | keys2.public_key(), | ||
| 2342 | false, | ||
| 2343 | ); | ||
| 2288 | 2344 | ||
| 2289 | // Add PR event | 2345 | // Add PR event |
| 2290 | let tags = vec![Tag::custom( | 2346 | let tags = vec![Tag::custom( |
| @@ -2295,7 +2351,12 @@ async fn test_comprehensive_roundtrip() { | |||
| 2295 | .tags(tags) | 2351 | .tags(tags) |
| 2296 | .sign_with_keys(&keys1) | 2352 | .sign_with_keys(&keys1) |
| 2297 | .unwrap(); | 2353 | .unwrap(); |
| 2298 | purgatory.add_pr(pr_event.clone(), "pr-1".to_string(), "commit-1".to_string(), false); | 2354 | purgatory.add_pr( |
| 2355 | pr_event.clone(), | ||
| 2356 | "pr-1".to_string(), | ||
| 2357 | "commit-1".to_string(), | ||
| 2358 | false, | ||
| 2359 | ); | ||
| 2299 | 2360 | ||
| 2300 | // Add PR placeholder | 2361 | // Add PR placeholder |
| 2301 | purgatory.add_pr_placeholder("pr-2".to_string(), "commit-2".to_string()); | 2362 | purgatory.add_pr_placeholder("pr-2".to_string(), "commit-2".to_string()); |
| @@ -2305,7 +2366,12 @@ async fn test_comprehensive_roundtrip() { | |||
| 2305 | .sign_with_keys(&keys1) | 2366 | .sign_with_keys(&keys1) |
| 2306 | .unwrap(); | 2367 | .unwrap(); |
| 2307 | let expired_id = expired_event.id; | 2368 | let expired_id = expired_event.id; |
| 2308 | purgatory.add_state(expired_event, "repo3".to_string(), keys1.public_key(), false); | 2369 | purgatory.add_state( |
| 2370 | expired_event, | ||
| 2371 | "repo3".to_string(), | ||
| 2372 | keys1.public_key(), | ||
| 2373 | false, | ||
| 2374 | ); | ||
| 2309 | if let Some(mut entries) = purgatory.state_events.get_mut("repo3") { | 2375 | if let Some(mut entries) = purgatory.state_events.get_mut("repo3") { |
| 2310 | for entry in entries.iter_mut() { | 2376 | for entry in entries.iter_mut() { |
| 2311 | entry.expires_at = Instant::now() - Duration::from_secs(1); | 2377 | entry.expires_at = Instant::now() - Duration::from_secs(1); |