diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-08 11:20:35 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-08 11:23:28 +0000 |
| commit | 5d02ad6b893f9059044914c115d77cf9d8e589c3 (patch) | |
| tree | b727f9c44d2f2d4e203dc2344e4c9bd5144a77dd | |
| parent | 075307804bf66bba10f5bc55cb40e2e6a98a65ee (diff) | |
refactor: replace hardcoded Kind constants with rust-nostr variants
- Replace KIND_REPOSITORY_ANNOUNCEMENT with Kind::GitRepoAnnouncement
- Replace KIND_REPOSITORY_STATE with Kind::RepoState
- Replace KIND_PR with Kind::GitPullRequest
- Replace KIND_PR_UPDATE with Kind::GitPullRequestUpdate
- Replace KIND_USER_GRASP_LIST with Kind::GitUserGraspList
- Replace KIND_PATCH with Kind::GitPatch
- Replace KIND_ISSUE with Kind::GitIssue
- Replace KIND_COMMENT with Kind::Comment
- Replace all Kind::Custom(30617|30618|1617|1618|1619|1621|1111|10317) patterns
- Remove all hardcoded KIND_* constants from events.rs
- Update all match statements to use Kind enum directly
- Update all filter builders to use Kind variants
- Update all test helpers and assertions
Benefits:
- Type safety: compiler prevents wrong kind numbers
- Readability: Kind::GitRepoAnnouncement is self-documenting
- Maintainability: single source of truth (rust-nostr)
- IDE support: full autocompletion and refactoring
- Standards: aligns with rust-nostr best practices
Files modified: 21
Constants removed: 9
Patterns replaced: 100+
Tests passing: 222/222
| -rw-r--r-- | grasp-audit/src/client.rs | 4 | ||||
| -rw-r--r-- | grasp-audit/src/fixtures.rs | 14 | ||||
| -rw-r--r-- | grasp-audit/src/specs/grasp01/event_acceptance_policy.rs | 8 | ||||
| -rw-r--r-- | grasp-audit/src/specs/grasp01/nip01_smoke.rs | 6 | ||||
| -rw-r--r-- | grasp-audit/src/specs/grasp01/push_authorization.rs | 4 | ||||
| -rw-r--r-- | src/git/authorization.rs | 32 | ||||
| -rw-r--r-- | src/nostr/builder.rs | 17 | ||||
| -rw-r--r-- | src/nostr/events.rs | 56 | ||||
| -rw-r--r-- | src/nostr/policy/announcement.rs | 14 | ||||
| -rw-r--r-- | src/sync/filters.rs | 6 | ||||
| -rw-r--r-- | src/sync/self_subscriber.rs | 24 | ||||
| -rw-r--r-- | tests/common/purgatory_helpers.rs | 20 | ||||
| -rw-r--r-- | tests/common/sync_helpers.rs | 43 | ||||
| -rw-r--r-- | tests/nip77_negentropy.rs | 11 | ||||
| -rw-r--r-- | tests/purgatory_sync.rs | 2 | ||||
| -rw-r--r-- | tests/sync/discovery.rs | 28 | ||||
| -rw-r--r-- | tests/sync/historic_sync.rs | 16 | ||||
| -rw-r--r-- | tests/sync/live_sync.rs | 14 | ||||
| -rw-r--r-- | tests/sync/metrics.rs | 14 | ||||
| -rw-r--r-- | tests/sync/tag_variations.rs | 14 |
20 files changed, 154 insertions, 193 deletions
diff --git a/grasp-audit/src/client.rs b/grasp-audit/src/client.rs index 60ce918..91a93dc 100644 --- a/grasp-audit/src/client.rs +++ b/grasp-audit/src/client.rs | |||
| @@ -492,7 +492,7 @@ impl AuditClient { | |||
| 492 | // Add any additional tags | 492 | // Add any additional tags |
| 493 | tags.extend(additional_tags); | 493 | tags.extend(additional_tags); |
| 494 | 494 | ||
| 495 | self.event_builder(Kind::Custom(1621), content) | 495 | self.event_builder(Kind::GitIssue, content) |
| 496 | .tags(tags) | 496 | .tags(tags) |
| 497 | .build(self.keys()) | 497 | .build(self.keys()) |
| 498 | .map_err(|e| anyhow!("Failed to build issue event: {}", e)) | 498 | .map_err(|e| anyhow!("Failed to build issue event: {}", e)) |
| @@ -530,7 +530,7 @@ impl AuditClient { | |||
| 530 | // Add any additional tags | 530 | // Add any additional tags |
| 531 | tags.extend(additional_tags); | 531 | tags.extend(additional_tags); |
| 532 | 532 | ||
| 533 | self.event_builder(Kind::Custom(1111), content) | 533 | self.event_builder(Kind::Comment, content) |
| 534 | .tags(tags) | 534 | .tags(tags) |
| 535 | .build(self.keys()) | 535 | .build(self.keys()) |
| 536 | .map_err(|e| anyhow!("Failed to build comment event: {}", e)) | 536 | .map_err(|e| anyhow!("Failed to build comment event: {}", e)) |
diff --git a/grasp-audit/src/fixtures.rs b/grasp-audit/src/fixtures.rs index 30df6e3..bbc7740 100644 --- a/grasp-audit/src/fixtures.rs +++ b/grasp-audit/src/fixtures.rs | |||
| @@ -677,7 +677,7 @@ impl<'a> TestContext<'a> { | |||
| 677 | // Tag format: ["refs/heads/main", "<commit_hash>"] | 677 | // Tag format: ["refs/heads/main", "<commit_hash>"] |
| 678 | // Note: We build the state but DON'T send it here - the caller will send it | 678 | // Note: We build the state but DON'T send it here - the caller will send it |
| 679 | self.client | 679 | self.client |
| 680 | .event_builder(Kind::Custom(30618), "") | 680 | .event_builder(Kind::RepoState, "") |
| 681 | .tag(Tag::identifier(&repo_id)) | 681 | .tag(Tag::identifier(&repo_id)) |
| 682 | .tag(Tag::custom( | 682 | .tag(Tag::custom( |
| 683 | TagKind::custom("refs/heads/main"), | 683 | TagKind::custom("refs/heads/main"), |
| @@ -713,7 +713,7 @@ impl<'a> TestContext<'a> { | |||
| 713 | // Build NIP-34 PR event (kind 1618) | 713 | // Build NIP-34 PR event (kind 1618) |
| 714 | self.client | 714 | self.client |
| 715 | .event_builder( | 715 | .event_builder( |
| 716 | Kind::Custom(1618), // NIP-34 PR kind (has 'c' tag for commit) | 716 | Kind::GitPullRequest, // NIP-34 PR kind (has 'c' tag for commit) |
| 717 | "Test PR for GRASP validation", | 717 | "Test PR for GRASP validation", |
| 718 | ) | 718 | ) |
| 719 | .tag(Tag::custom( | 719 | .tag(Tag::custom( |
| @@ -756,7 +756,7 @@ impl<'a> TestContext<'a> { | |||
| 756 | // Build NIP-34 PR event (kind 1618) | 756 | // Build NIP-34 PR event (kind 1618) |
| 757 | self.client | 757 | self.client |
| 758 | .event_builder( | 758 | .event_builder( |
| 759 | Kind::Custom(1618), // NIP-34 PR kind (has 'c' tag for commit) | 759 | Kind::GitPullRequest, // NIP-34 PR kind (has 'c' tag for commit) |
| 760 | "Test PR for GRASP validation", | 760 | "Test PR for GRASP validation", |
| 761 | ) | 761 | ) |
| 762 | .tag(Tag::custom( | 762 | .tag(Tag::custom( |
| @@ -884,7 +884,7 @@ impl<'a> TestContext<'a> { | |||
| 884 | 884 | ||
| 885 | let state_event = self | 885 | let state_event = self |
| 886 | .client | 886 | .client |
| 887 | .event_builder(Kind::Custom(30618), "") | 887 | .event_builder(Kind::RepoState, "") |
| 888 | .tag(Tag::identifier(&repo_id)) | 888 | .tag(Tag::identifier(&repo_id)) |
| 889 | .tag(Tag::custom( | 889 | .tag(Tag::custom( |
| 890 | TagKind::custom("refs/heads/main"), | 890 | TagKind::custom("refs/heads/main"), |
| @@ -1057,7 +1057,7 @@ impl<'a> TestContext<'a> { | |||
| 1057 | 1057 | ||
| 1058 | let maintainer_state_event = self | 1058 | let maintainer_state_event = self |
| 1059 | .client | 1059 | .client |
| 1060 | .event_builder(Kind::Custom(30618), "") | 1060 | .event_builder(Kind::RepoState, "") |
| 1061 | .tag(Tag::identifier(&repo_id)) | 1061 | .tag(Tag::identifier(&repo_id)) |
| 1062 | .tag(Tag::custom( | 1062 | .tag(Tag::custom( |
| 1063 | TagKind::custom("refs/heads/main"), | 1063 | TagKind::custom("refs/heads/main"), |
| @@ -1230,7 +1230,7 @@ impl<'a> TestContext<'a> { | |||
| 1230 | 1230 | ||
| 1231 | let recursive_maintainer_state_event = self | 1231 | let recursive_maintainer_state_event = self |
| 1232 | .client | 1232 | .client |
| 1233 | .event_builder(Kind::Custom(30618), "") | 1233 | .event_builder(Kind::RepoState, "") |
| 1234 | .tag(Tag::identifier(&repo_id)) | 1234 | .tag(Tag::identifier(&repo_id)) |
| 1235 | .tag(Tag::custom( | 1235 | .tag(Tag::custom( |
| 1236 | TagKind::custom("refs/heads/main"), | 1236 | TagKind::custom("refs/heads/main"), |
| @@ -1397,7 +1397,7 @@ impl<'a> TestContext<'a> { | |||
| 1397 | 1397 | ||
| 1398 | let develop_state_event = self | 1398 | let develop_state_event = self |
| 1399 | .client | 1399 | .client |
| 1400 | .event_builder(Kind::Custom(30618), "") | 1400 | .event_builder(Kind::RepoState, "") |
| 1401 | .tag(Tag::identifier(&repo_id)) | 1401 | .tag(Tag::identifier(&repo_id)) |
| 1402 | .tag(Tag::custom( | 1402 | .tag(Tag::custom( |
| 1403 | TagKind::custom("HEAD"), | 1403 | TagKind::custom("HEAD"), |
diff --git a/grasp-audit/src/specs/grasp01/event_acceptance_policy.rs b/grasp-audit/src/specs/grasp01/event_acceptance_policy.rs index 3db1446..5b697d8 100644 --- a/grasp-audit/src/specs/grasp01/event_acceptance_policy.rs +++ b/grasp-audit/src/specs/grasp01/event_acceptance_policy.rs | |||
| @@ -659,7 +659,7 @@ impl EventAcceptancePolicyTests { | |||
| 659 | ]; | 659 | ]; |
| 660 | 660 | ||
| 661 | let comment = client | 661 | let comment = client |
| 662 | .event_builder(Kind::Custom(1111), "Comment on repo") | 662 | .event_builder(Kind::Comment, "Comment on repo") |
| 663 | .tags(tags) | 663 | .tags(tags) |
| 664 | .build(client.keys()) | 664 | .build(client.keys()) |
| 665 | .map_err(|e| format!("Failed to build comment: {}", e))?; | 665 | .map_err(|e| format!("Failed to build comment: {}", e))?; |
| @@ -935,7 +935,7 @@ impl EventAcceptancePolicyTests { | |||
| 935 | ]; | 935 | ]; |
| 936 | 936 | ||
| 937 | let issue = client | 937 | let issue = client |
| 938 | .event_builder(Kind::Custom(1621), "issue content") | 938 | .event_builder(Kind::GitIssue, "issue content") |
| 939 | .tags(issue_tags) | 939 | .tags(issue_tags) |
| 940 | .build(client.keys()) | 940 | .build(client.keys()) |
| 941 | .map_err(|e| format!("Failed to build issue: {}", e))?; | 941 | .map_err(|e| format!("Failed to build issue: {}", e))?; |
| @@ -995,7 +995,7 @@ impl EventAcceptancePolicyTests { | |||
| 995 | ]; | 995 | ]; |
| 996 | 996 | ||
| 997 | let comment_b = client | 997 | let comment_b = client |
| 998 | .event_builder(Kind::Custom(1111), "Comment B quoting Comment A") | 998 | .event_builder(Kind::Comment, "Comment B quoting Comment A") |
| 999 | .tags(comment_b_tags) | 999 | .tags(comment_b_tags) |
| 1000 | .build(client.keys()) | 1000 | .build(client.keys()) |
| 1001 | .map_err(|e| format!("Failed to build comment B: {}", e))?; | 1001 | .map_err(|e| format!("Failed to build comment B: {}", e))?; |
| @@ -1172,7 +1172,7 @@ impl EventAcceptancePolicyTests { | |||
| 1172 | ]; | 1172 | ]; |
| 1173 | 1173 | ||
| 1174 | let comment = client | 1174 | let comment = client |
| 1175 | .event_builder(Kind::Custom(1111), "Comment on unaccepted repo") | 1175 | .event_builder(Kind::Comment, "Comment on unaccepted repo") |
| 1176 | .tags(tags) | 1176 | .tags(tags) |
| 1177 | .build(client.keys()) | 1177 | .build(client.keys()) |
| 1178 | .map_err(|e| format!("Failed to build comment: {}", e))?; | 1178 | .map_err(|e| format!("Failed to build comment: {}", e))?; |
diff --git a/grasp-audit/src/specs/grasp01/nip01_smoke.rs b/grasp-audit/src/specs/grasp01/nip01_smoke.rs index bd45ea4..4d0b8a4 100644 --- a/grasp-audit/src/specs/grasp01/nip01_smoke.rs +++ b/grasp-audit/src/specs/grasp01/nip01_smoke.rs | |||
| @@ -78,7 +78,7 @@ impl Nip01SmokeTests { | |||
| 78 | tokio::time::sleep(std::time::Duration::from_millis(100)).await; | 78 | tokio::time::sleep(std::time::Duration::from_millis(100)).await; |
| 79 | 79 | ||
| 80 | // Step 2: VERIFY - Query event back | 80 | // Step 2: VERIFY - Query event back |
| 81 | let filter = Filter::new().kind(Kind::Custom(30617)).id(event_id); | 81 | let filter = Filter::new().kind(Kind::GitRepoAnnouncement).id(event_id); |
| 82 | 82 | ||
| 83 | let events = client | 83 | let events = client |
| 84 | .query(filter) | 84 | .query(filter) |
| @@ -88,7 +88,7 @@ impl Nip01SmokeTests { | |||
| 88 | if events.is_empty() { | 88 | if events.is_empty() { |
| 89 | // Debug: try querying without audit client filtering | 89 | // Debug: try querying without audit client filtering |
| 90 | eprintln!("Event not found with audit client query, trying direct client query..."); | 90 | eprintln!("Event not found with audit client query, trying direct client query..."); |
| 91 | let direct_filter = Filter::new().kind(Kind::Custom(30617)).id(event_id); | 91 | let direct_filter = Filter::new().kind(Kind::GitRepoAnnouncement).id(event_id); |
| 92 | let direct_events = client | 92 | let direct_events = client |
| 93 | .client() | 93 | .client() |
| 94 | .fetch_events(direct_filter, std::time::Duration::from_secs(5)) | 94 | .fetch_events(direct_filter, std::time::Duration::from_secs(5)) |
| @@ -140,7 +140,7 @@ impl Nip01SmokeTests { | |||
| 140 | 140 | ||
| 141 | // Step 2: VERIFY - Subscribe to NIP-34 announcements from this author | 141 | // Step 2: VERIFY - Subscribe to NIP-34 announcements from this author |
| 142 | let filter = Filter::new() | 142 | let filter = Filter::new() |
| 143 | .kind(Kind::Custom(30617)) | 143 | .kind(Kind::GitRepoAnnouncement) |
| 144 | .author(client.public_key()); | 144 | .author(client.public_key()); |
| 145 | 145 | ||
| 146 | let events = client | 146 | let events = client |
diff --git a/grasp-audit/src/specs/grasp01/push_authorization.rs b/grasp-audit/src/specs/grasp01/push_authorization.rs index 23eb735..4c7720b 100644 --- a/grasp-audit/src/specs/grasp01/push_authorization.rs +++ b/grasp-audit/src/specs/grasp01/push_authorization.rs | |||
| @@ -877,7 +877,7 @@ impl PushAuthorizationTests { | |||
| 877 | // Create a rogue state event announcing the new commit | 877 | // Create a rogue state event announcing the new commit |
| 878 | // This event has the correct repo_id but is signed by a non-maintainer | 878 | // This event has the correct repo_id but is signed by a non-maintainer |
| 879 | let rogue_state = match client | 879 | let rogue_state = match client |
| 880 | .event_builder(Kind::Custom(30618), "") | 880 | .event_builder(Kind::RepoState, "") |
| 881 | .tag(Tag::identifier(&repo_id)) | 881 | .tag(Tag::identifier(&repo_id)) |
| 882 | .tag(Tag::custom( | 882 | .tag(Tag::custom( |
| 883 | TagKind::custom("refs/heads/main"), | 883 | TagKind::custom("refs/heads/main"), |
| @@ -1591,7 +1591,7 @@ impl PushAuthorizationTests { | |||
| 1591 | // This references a commit that doesn't yet exist on the relay | 1591 | // This references a commit that doesn't yet exist on the relay |
| 1592 | // ============================================================ | 1592 | // ============================================================ |
| 1593 | let state_event = match client | 1593 | let state_event = match client |
| 1594 | .event_builder(Kind::Custom(30618), "") | 1594 | .event_builder(Kind::RepoState, "") |
| 1595 | .tag(Tag::identifier(&repo_id)) | 1595 | .tag(Tag::identifier(&repo_id)) |
| 1596 | .tag(Tag::custom( | 1596 | .tag(Tag::custom( |
| 1597 | TagKind::custom("HEAD"), | 1597 | TagKind::custom("HEAD"), |
diff --git a/src/git/authorization.rs b/src/git/authorization.rs index 7502a52..e174b51 100644 --- a/src/git/authorization.rs +++ b/src/git/authorization.rs | |||
| @@ -36,11 +36,9 @@ use std::sync::Arc; | |||
| 36 | use tracing::{debug, info, warn}; | 36 | use tracing::{debug, info, warn}; |
| 37 | 37 | ||
| 38 | use crate::nostr::builder::SharedDatabase; | 38 | use crate::nostr::builder::SharedDatabase; |
| 39 | use crate::nostr::events::{ | 39 | use crate::nostr::events::{RepositoryAnnouncement, RepositoryState}; |
| 40 | RepositoryAnnouncement, RepositoryState, KIND_PR, KIND_PR_UPDATE, KIND_REPOSITORY_ANNOUNCEMENT, | ||
| 41 | KIND_REPOSITORY_STATE, | ||
| 42 | }; | ||
| 43 | use crate::purgatory::Purgatory; | 40 | use crate::purgatory::Purgatory; |
| 41 | use nostr_sdk::Kind; | ||
| 44 | 42 | ||
| 45 | /// Perform GRASP authorization for a push operation | 43 | /// Perform GRASP authorization for a push operation |
| 46 | /// | 44 | /// |
| @@ -241,10 +239,7 @@ pub async fn fetch_repository_data( | |||
| 241 | identifier: &str, | 239 | identifier: &str, |
| 242 | ) -> Result<RepositoryData> { | 240 | ) -> Result<RepositoryData> { |
| 243 | let filter = Filter::new() | 241 | let filter = Filter::new() |
| 244 | .kinds([ | 242 | .kinds([Kind::GitRepoAnnouncement, Kind::RepoState]) |
| 245 | Kind::from(KIND_REPOSITORY_ANNOUNCEMENT), | ||
| 246 | Kind::from(KIND_REPOSITORY_STATE), | ||
| 247 | ]) | ||
| 248 | .custom_tag( | 243 | .custom_tag( |
| 249 | SingleLetterTag::lowercase(Alphabet::D), | 244 | SingleLetterTag::lowercase(Alphabet::D), |
| 250 | identifier.to_string(), | 245 | identifier.to_string(), |
| @@ -268,11 +263,11 @@ pub async fn fetch_repository_data( | |||
| 268 | let mut states = Vec::new(); | 263 | let mut states = Vec::new(); |
| 269 | 264 | ||
| 270 | for event in events { | 265 | for event in events { |
| 271 | if event.kind == Kind::from(KIND_REPOSITORY_ANNOUNCEMENT) { | 266 | if event.kind == Kind::GitRepoAnnouncement { |
| 272 | if let Ok(announcement) = RepositoryAnnouncement::from_event(event) { | 267 | if let Ok(announcement) = RepositoryAnnouncement::from_event(event) { |
| 273 | announcements.push(announcement); | 268 | announcements.push(announcement); |
| 274 | } | 269 | } |
| 275 | } else if event.kind == Kind::from(KIND_REPOSITORY_STATE) { | 270 | } else if event.kind == Kind::RepoState { |
| 276 | if let Ok(state) = RepositoryState::from_event(event) { | 271 | if let Ok(state) = RepositoryState::from_event(event) { |
| 277 | states.push(state); | 272 | states.push(state); |
| 278 | } | 273 | } |
| @@ -714,10 +709,7 @@ impl AuthorizationContext { | |||
| 714 | /// This matches the reference implementation's filter logic | 709 | /// This matches the reference implementation's filter logic |
| 715 | pub fn create_filter(identifier: &str) -> Filter { | 710 | pub fn create_filter(identifier: &str) -> Filter { |
| 716 | Filter::new() | 711 | Filter::new() |
| 717 | .kinds([ | 712 | .kinds([Kind::GitRepoAnnouncement, Kind::RepoState]) |
| 718 | Kind::from(KIND_REPOSITORY_ANNOUNCEMENT), | ||
| 719 | Kind::from(KIND_REPOSITORY_STATE), | ||
| 720 | ]) | ||
| 721 | .custom_tag( | 713 | .custom_tag( |
| 722 | SingleLetterTag::lowercase(Alphabet::D), | 714 | SingleLetterTag::lowercase(Alphabet::D), |
| 723 | identifier.to_string(), | 715 | identifier.to_string(), |
| @@ -754,7 +746,7 @@ impl AuthorizationContext { | |||
| 754 | 746 | ||
| 755 | for event in &self.events { | 747 | for event in &self.events { |
| 756 | // Check if it's a repository state event | 748 | // Check if it's a repository state event |
| 757 | if event.kind != Kind::from(KIND_REPOSITORY_STATE) { | 749 | if event.kind != Kind::RepoState { |
| 758 | continue; | 750 | continue; |
| 759 | } | 751 | } |
| 760 | 752 | ||
| @@ -806,7 +798,7 @@ impl AuthorizationContext { | |||
| 806 | 798 | ||
| 807 | for event in &self.events { | 799 | for event in &self.events { |
| 808 | // Only look at announcements | 800 | // Only look at announcements |
| 809 | if event.kind != Kind::from(KIND_REPOSITORY_ANNOUNCEMENT) { | 801 | if event.kind != Kind::GitRepoAnnouncement { |
| 810 | continue; | 802 | continue; |
| 811 | } | 803 | } |
| 812 | 804 | ||
| @@ -838,7 +830,7 @@ impl AuthorizationContext { | |||
| 838 | pub fn is_state_authorized(&self, state_pubkey: &str, identifier: &str) -> bool { | 830 | pub fn is_state_authorized(&self, state_pubkey: &str, identifier: &str) -> bool { |
| 839 | for event in &self.events { | 831 | for event in &self.events { |
| 840 | // Only look at announcements | 832 | // Only look at announcements |
| 841 | if event.kind != Kind::from(KIND_REPOSITORY_ANNOUNCEMENT) { | 833 | if event.kind != Kind::GitRepoAnnouncement { |
| 842 | continue; | 834 | continue; |
| 843 | } | 835 | } |
| 844 | 836 | ||
| @@ -1093,7 +1085,7 @@ pub async fn get_event_commit_tag( | |||
| 1093 | // Query for PR (1618) and PR Update (1619) events with this ID | 1085 | // Query for PR (1618) and PR Update (1619) events with this ID |
| 1094 | let filter = Filter::new() | 1086 | let filter = Filter::new() |
| 1095 | .ids([*event_id]) | 1087 | .ids([*event_id]) |
| 1096 | .kinds([Kind::from(KIND_PR), Kind::from(KIND_PR_UPDATE)]); | 1088 | .kinds([Kind::GitPullRequest, Kind::GitPullRequestUpdate]); |
| 1097 | 1089 | ||
| 1098 | let events: Vec<Event> = database | 1090 | let events: Vec<Event> = database |
| 1099 | .query(filter) | 1091 | .query(filter) |
| @@ -1224,7 +1216,7 @@ mod tests { | |||
| 1224 | vec!["wss://example.com".to_string()], | 1216 | vec!["wss://example.com".to_string()], |
| 1225 | )); | 1217 | )); |
| 1226 | 1218 | ||
| 1227 | EventBuilder::new(Kind::from(KIND_REPOSITORY_ANNOUNCEMENT), "Test repo") | 1219 | EventBuilder::new(Kind::GitRepoAnnouncement, "Test repo") |
| 1228 | .tags(tags) | 1220 | .tags(tags) |
| 1229 | .sign_with_keys(keys) | 1221 | .sign_with_keys(keys) |
| 1230 | .unwrap() | 1222 | .unwrap() |
| @@ -1240,7 +1232,7 @@ mod tests { | |||
| 1240 | )); | 1232 | )); |
| 1241 | } | 1233 | } |
| 1242 | 1234 | ||
| 1243 | EventBuilder::new(Kind::from(KIND_REPOSITORY_STATE), "") | 1235 | EventBuilder::new(Kind::RepoState, "") |
| 1244 | .tags(tags) | 1236 | .tags(tags) |
| 1245 | .sign_with_keys(keys) | 1237 | .sign_with_keys(keys) |
| 1246 | .unwrap() | 1238 | .unwrap() |
diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs index 81f7fbb..939ccef 100644 --- a/src/nostr/builder.rs +++ b/src/nostr/builder.rs | |||
| @@ -12,10 +12,7 @@ use nostr_lmdb::NostrLmdb; | |||
| 12 | use nostr_relay_builder::prelude::*; | 12 | use nostr_relay_builder::prelude::*; |
| 13 | 13 | ||
| 14 | use crate::config::{Config, DatabaseBackend}; | 14 | use crate::config::{Config, DatabaseBackend}; |
| 15 | use crate::nostr::events::{ | 15 | use crate::nostr::events::RepositoryAnnouncement; |
| 16 | RepositoryAnnouncement, KIND_PR, KIND_PR_UPDATE, KIND_REPOSITORY_ANNOUNCEMENT, | ||
| 17 | KIND_REPOSITORY_STATE, KIND_USER_GRASP_LIST, | ||
| 18 | }; | ||
| 19 | use crate::nostr::policy::{ | 16 | use crate::nostr::policy::{ |
| 20 | AnnouncementPolicy, AnnouncementResult, PolicyContext, PrEventPolicy, ReferenceResult, | 17 | AnnouncementPolicy, AnnouncementResult, PolicyContext, PrEventPolicy, ReferenceResult, |
| 21 | RelatedEventPolicy, StatePolicy, StateResult, | 18 | RelatedEventPolicy, StatePolicy, StateResult, |
| @@ -377,11 +374,13 @@ impl WritePolicy for Nip34WritePolicy { | |||
| 377 | // Sync uses localhost:0 as a dummy address | 374 | // Sync uses localhost:0 as a dummy address |
| 378 | let is_synced = addr.ip().is_loopback() && addr.port() == 0; | 375 | let is_synced = addr.ip().is_loopback() && addr.port() == 0; |
| 379 | 376 | ||
| 380 | match event.kind.as_u16() { | 377 | match event.kind { |
| 381 | KIND_REPOSITORY_ANNOUNCEMENT => self.handle_announcement(event).await, | 378 | Kind::GitRepoAnnouncement => self.handle_announcement(event).await, |
| 382 | KIND_REPOSITORY_STATE => self.handle_state(event, is_synced).await, | 379 | Kind::RepoState => self.handle_state(event, is_synced).await, |
| 383 | KIND_PR | KIND_PR_UPDATE => self.handle_pr_event(event, is_synced).await, | 380 | Kind::GitPullRequest | Kind::GitPullRequestUpdate => { |
| 384 | KIND_USER_GRASP_LIST => { | 381 | self.handle_pr_event(event, is_synced).await |
| 382 | } | ||
| 383 | Kind::GitUserGraspList => { | ||
| 385 | // Accept all kind 10317 (User Grasp List) events | 384 | // Accept all kind 10317 (User Grasp List) events |
| 386 | // for better GRASP repository discovery | 385 | // for better GRASP repository discovery |
| 387 | tracing::debug!( | 386 | tracing::debug!( |
diff --git a/src/nostr/events.rs b/src/nostr/events.rs index 1fcb75e..4f7c907 100644 --- a/src/nostr/events.rs +++ b/src/nostr/events.rs | |||
| @@ -9,20 +9,12 @@ | |||
| 9 | use anyhow::{anyhow, Result}; | 9 | use anyhow::{anyhow, Result}; |
| 10 | use nostr_sdk::{Event, Kind, TagKind, ToBech32}; | 10 | use nostr_sdk::{Event, Kind, TagKind, ToBech32}; |
| 11 | 11 | ||
| 12 | /// NIP-34 Repository Announcement (kind 30617) | 12 | // NOTE: Using rust-nostr Kind variants instead of hardcoded constants: |
| 13 | pub const KIND_REPOSITORY_ANNOUNCEMENT: u16 = 30617; | 13 | // - KIND_REPOSITORY_ANNOUNCEMENT -> Kind::GitRepoAnnouncement (30617) |
| 14 | 14 | // - KIND_REPOSITORY_STATE -> Kind::RepoState (30618) | |
| 15 | /// NIP-34 Repository State Announcement (kind 30618) | 15 | // - KIND_PR -> Kind::GitPullRequest (1618) |
| 16 | pub const KIND_REPOSITORY_STATE: u16 = 30618; | 16 | // - KIND_PR_UPDATE -> Kind::GitPullRequestUpdate (1619) |
| 17 | 17 | // - KIND_USER_GRASP_LIST -> Kind::GitUserGraspList (10317) | |
| 18 | /// NIP-34 Pull Request (kind 1618) - has `c` tag for commit | ||
| 19 | pub const KIND_PR: u16 = 1618; | ||
| 20 | |||
| 21 | /// NIP-34 Pull Request Update (kind 1619) - has `c` tag for commit | ||
| 22 | pub const KIND_PR_UPDATE: u16 = 1619; | ||
| 23 | |||
| 24 | /// User Grasp List (kind 10317) - user's personal list of GRASP repositories | ||
| 25 | pub const KIND_USER_GRASP_LIST: u16 = 10317; | ||
| 26 | 18 | ||
| 27 | /// Repository announcement details extracted from NIP-34 event | 19 | /// Repository announcement details extracted from NIP-34 event |
| 28 | #[derive(Debug, Clone)] | 20 | #[derive(Debug, Clone)] |
| @@ -40,10 +32,10 @@ pub struct RepositoryAnnouncement { | |||
| 40 | impl RepositoryAnnouncement { | 32 | impl RepositoryAnnouncement { |
| 41 | /// Parse a repository announcement from a NIP-34 kind 30617 event | 33 | /// Parse a repository announcement from a NIP-34 kind 30617 event |
| 42 | pub fn from_event(event: Event) -> Result<Self> { | 34 | pub fn from_event(event: Event) -> Result<Self> { |
| 43 | if event.kind != Kind::from(KIND_REPOSITORY_ANNOUNCEMENT) { | 35 | if event.kind != Kind::GitRepoAnnouncement { |
| 44 | return Err(anyhow!( | 36 | return Err(anyhow!( |
| 45 | "Invalid event kind: expected {}, got {}", | 37 | "Invalid event kind: expected {}, got {}", |
| 46 | KIND_REPOSITORY_ANNOUNCEMENT, | 38 | Kind::GitRepoAnnouncement, |
| 47 | event.kind | 39 | event.kind |
| 48 | )); | 40 | )); |
| 49 | } | 41 | } |
| @@ -197,10 +189,10 @@ pub struct TagState { | |||
| 197 | impl RepositoryState { | 189 | impl RepositoryState { |
| 198 | /// Parse a repository state from a NIP-34 kind 30618 event | 190 | /// Parse a repository state from a NIP-34 kind 30618 event |
| 199 | pub fn from_event(event: Event) -> Result<Self> { | 191 | pub fn from_event(event: Event) -> Result<Self> { |
| 200 | if event.kind != Kind::from(KIND_REPOSITORY_STATE) { | 192 | if event.kind != Kind::RepoState { |
| 201 | return Err(anyhow!( | 193 | return Err(anyhow!( |
| 202 | "Invalid event kind: expected {}, got {}", | 194 | "Invalid event kind: expected {}, got {}", |
| 203 | KIND_REPOSITORY_STATE, | 195 | Kind::RepoState, |
| 204 | event.kind | 196 | event.kind |
| 205 | )); | 197 | )); |
| 206 | } | 198 | } |
| @@ -346,10 +338,10 @@ impl RepositoryState { | |||
| 346 | /// Returns Ok(()) if valid, Err with reason if invalid. | 338 | /// Returns Ok(()) if valid, Err with reason if invalid. |
| 347 | pub fn validate_announcement(event: &Event, domain: &str) -> Result<()> { | 339 | pub fn validate_announcement(event: &Event, domain: &str) -> Result<()> { |
| 348 | // Must be kind 30617 | 340 | // Must be kind 30617 |
| 349 | if event.kind != Kind::from(KIND_REPOSITORY_ANNOUNCEMENT) { | 341 | if event.kind != Kind::GitRepoAnnouncement { |
| 350 | return Err(anyhow!( | 342 | return Err(anyhow!( |
| 351 | "Invalid kind: expected {}", | 343 | "Invalid kind: expected {}", |
| 352 | KIND_REPOSITORY_ANNOUNCEMENT | 344 | Kind::GitRepoAnnouncement |
| 353 | )); | 345 | )); |
| 354 | } | 346 | } |
| 355 | 347 | ||
| @@ -381,8 +373,8 @@ pub fn validate_announcement(event: &Event, domain: &str) -> Result<()> { | |||
| 381 | /// Returns Ok(()) if valid, Err with reason if invalid. | 373 | /// Returns Ok(()) if valid, Err with reason if invalid. |
| 382 | pub fn validate_state(event: &Event) -> Result<()> { | 374 | pub fn validate_state(event: &Event) -> Result<()> { |
| 383 | // Must be kind 30618 | 375 | // Must be kind 30618 |
| 384 | if event.kind != Kind::from(KIND_REPOSITORY_STATE) { | 376 | if event.kind != Kind::RepoState { |
| 385 | return Err(anyhow!("Invalid kind: expected {}", KIND_REPOSITORY_STATE)); | 377 | return Err(anyhow!("Invalid kind: expected {}", Kind::RepoState)); |
| 386 | } | 378 | } |
| 387 | 379 | ||
| 388 | // Must have identifier | 380 | // Must have identifier |
| @@ -433,7 +425,7 @@ mod tests { | |||
| 433 | )); | 425 | )); |
| 434 | } | 426 | } |
| 435 | 427 | ||
| 436 | EventBuilder::new(Kind::from(KIND_REPOSITORY_ANNOUNCEMENT), "Test repository") | 428 | EventBuilder::new(Kind::GitRepoAnnouncement, "Test repository") |
| 437 | .tags(tags) | 429 | .tags(tags) |
| 438 | .sign_with_keys(keys) | 430 | .sign_with_keys(keys) |
| 439 | .unwrap() | 431 | .unwrap() |
| @@ -454,7 +446,7 @@ mod tests { | |||
| 454 | )); | 446 | )); |
| 455 | } | 447 | } |
| 456 | 448 | ||
| 457 | EventBuilder::new(Kind::from(KIND_REPOSITORY_STATE), "") | 449 | EventBuilder::new(Kind::RepoState, "") |
| 458 | .tags(tags) | 450 | .tags(tags) |
| 459 | .sign_with_keys(keys) | 451 | .sign_with_keys(keys) |
| 460 | .unwrap() | 452 | .unwrap() |
| @@ -483,7 +475,7 @@ mod tests { | |||
| 483 | #[test] | 475 | #[test] |
| 484 | fn test_parse_announcement_missing_identifier() { | 476 | fn test_parse_announcement_missing_identifier() { |
| 485 | let keys = create_test_keys(); | 477 | let keys = create_test_keys(); |
| 486 | let event = EventBuilder::new(Kind::from(KIND_REPOSITORY_ANNOUNCEMENT), "Test repository") | 478 | let event = EventBuilder::new(Kind::GitRepoAnnouncement, "Test repository") |
| 487 | .sign_with_keys(&keys) | 479 | .sign_with_keys(&keys) |
| 488 | .unwrap(); | 480 | .unwrap(); |
| 489 | 481 | ||
| @@ -579,7 +571,7 @@ mod tests { | |||
| 579 | #[test] | 571 | #[test] |
| 580 | fn test_validate_state_missing_identifier() { | 572 | fn test_validate_state_missing_identifier() { |
| 581 | let keys = create_test_keys(); | 573 | let keys = create_test_keys(); |
| 582 | let event = EventBuilder::new(Kind::from(KIND_REPOSITORY_STATE), "") | 574 | let event = EventBuilder::new(Kind::RepoState, "") |
| 583 | .sign_with_keys(&keys) | 575 | .sign_with_keys(&keys) |
| 584 | .unwrap(); | 576 | .unwrap(); |
| 585 | 577 | ||
| @@ -614,7 +606,7 @@ mod tests { | |||
| 614 | vec![maintainer_keys.public_key().to_hex()], | 606 | vec![maintainer_keys.public_key().to_hex()], |
| 615 | )); | 607 | )); |
| 616 | 608 | ||
| 617 | let event = EventBuilder::new(Kind::from(KIND_REPOSITORY_ANNOUNCEMENT), "Test repository") | 609 | let event = EventBuilder::new(Kind::GitRepoAnnouncement, "Test repository") |
| 618 | .tags(tags) | 610 | .tags(tags) |
| 619 | .sign_with_keys(&keys) | 611 | .sign_with_keys(&keys) |
| 620 | .unwrap(); | 612 | .unwrap(); |
| @@ -649,7 +641,7 @@ mod tests { | |||
| 649 | vec!["e5f6g7h8".to_string()], | 641 | vec!["e5f6g7h8".to_string()], |
| 650 | )); | 642 | )); |
| 651 | 643 | ||
| 652 | let event = EventBuilder::new(Kind::from(KIND_REPOSITORY_STATE), "") | 644 | let event = EventBuilder::new(Kind::RepoState, "") |
| 653 | .tags(tags) | 645 | .tags(tags) |
| 654 | .sign_with_keys(&keys) | 646 | .sign_with_keys(&keys) |
| 655 | .unwrap(); | 647 | .unwrap(); |
| @@ -683,7 +675,7 @@ mod tests { | |||
| 683 | vec!["ref: refs/heads/main".to_string()], | 675 | vec!["ref: refs/heads/main".to_string()], |
| 684 | )); | 676 | )); |
| 685 | 677 | ||
| 686 | let event = EventBuilder::new(Kind::from(KIND_REPOSITORY_STATE), "") | 678 | let event = EventBuilder::new(Kind::RepoState, "") |
| 687 | .tags(tags) | 679 | .tags(tags) |
| 688 | .sign_with_keys(&keys) | 680 | .sign_with_keys(&keys) |
| 689 | .unwrap(); | 681 | .unwrap(); |
| @@ -716,7 +708,7 @@ mod tests { | |||
| 716 | vec!["refs/heads/develop".to_string()], | 708 | vec!["refs/heads/develop".to_string()], |
| 717 | )); | 709 | )); |
| 718 | 710 | ||
| 719 | let event = EventBuilder::new(Kind::from(KIND_REPOSITORY_STATE), "") | 711 | let event = EventBuilder::new(Kind::RepoState, "") |
| 720 | .tags(tags) | 712 | .tags(tags) |
| 721 | .sign_with_keys(&keys) | 713 | .sign_with_keys(&keys) |
| 722 | .unwrap(); | 714 | .unwrap(); |
| @@ -740,7 +732,7 @@ mod tests { | |||
| 740 | ), | 732 | ), |
| 741 | ]; | 733 | ]; |
| 742 | 734 | ||
| 743 | let event = EventBuilder::new(Kind::from(KIND_REPOSITORY_STATE), "") | 735 | let event = EventBuilder::new(Kind::RepoState, "") |
| 744 | .tags(tags) | 736 | .tags(tags) |
| 745 | .sign_with_keys(&keys) | 737 | .sign_with_keys(&keys) |
| 746 | .unwrap(); | 738 | .unwrap(); |
| @@ -773,7 +765,7 @@ mod tests { | |||
| 773 | vec!["refs/heads/develop".to_string()], | 765 | vec!["refs/heads/develop".to_string()], |
| 774 | )); | 766 | )); |
| 775 | 767 | ||
| 776 | let event = EventBuilder::new(Kind::from(KIND_REPOSITORY_STATE), "") | 768 | let event = EventBuilder::new(Kind::RepoState, "") |
| 777 | .tags(tags) | 769 | .tags(tags) |
| 778 | .sign_with_keys(&keys) | 770 | .sign_with_keys(&keys) |
| 779 | .unwrap(); | 771 | .unwrap(); |
diff --git a/src/nostr/policy/announcement.rs b/src/nostr/policy/announcement.rs index 353738b..61840fb 100644 --- a/src/nostr/policy/announcement.rs +++ b/src/nostr/policy/announcement.rs | |||
| @@ -5,9 +5,7 @@ | |||
| 5 | use nostr_relay_builder::prelude::{Alphabet, Event, Filter, Kind, PublicKey, SingleLetterTag}; | 5 | use nostr_relay_builder::prelude::{Alphabet, Event, Filter, Kind, PublicKey, SingleLetterTag}; |
| 6 | 6 | ||
| 7 | use super::PolicyContext; | 7 | use super::PolicyContext; |
| 8 | use crate::nostr::events::{ | 8 | use crate::nostr::events::{validate_announcement, RepositoryAnnouncement}; |
| 9 | validate_announcement, RepositoryAnnouncement, KIND_REPOSITORY_ANNOUNCEMENT, | ||
| 10 | }; | ||
| 11 | 9 | ||
| 12 | /// Result of announcement policy evaluation | 10 | /// Result of announcement policy evaluation |
| 13 | #[derive(Debug)] | 11 | #[derive(Debug)] |
| @@ -121,12 +119,10 @@ impl AnnouncementPolicy { | |||
| 121 | author: &PublicKey, | 119 | author: &PublicKey, |
| 122 | ) -> Result<bool, String> { | 120 | ) -> Result<bool, String> { |
| 123 | // Query all announcements with this identifier that are already in the database | 121 | // Query all announcements with this identifier that are already in the database |
| 124 | let filter = Filter::new() | 122 | let filter = Filter::new().kind(Kind::GitRepoAnnouncement).custom_tag( |
| 125 | .kind(Kind::from(KIND_REPOSITORY_ANNOUNCEMENT)) | 123 | SingleLetterTag::lowercase(Alphabet::D), |
| 126 | .custom_tag( | 124 | identifier.to_string(), |
| 127 | SingleLetterTag::lowercase(Alphabet::D), | 125 | ); |
| 128 | identifier.to_string(), | ||
| 129 | ); | ||
| 130 | 126 | ||
| 131 | let announcements: Vec<Event> = match self.ctx.database.query(filter).await { | 127 | let announcements: Vec<Event> = match self.ctx.database.query(filter).await { |
| 132 | Ok(events) => events.into_iter().collect(), | 128 | Ok(events) => events.into_iter().collect(), |
diff --git a/src/sync/filters.rs b/src/sync/filters.rs index dddc49c..c4e20e7 100644 --- a/src/sync/filters.rs +++ b/src/sync/filters.rs | |||
| @@ -20,9 +20,9 @@ use nostr_sdk::prelude::*; | |||
| 20 | /// Note: 10317 (User Grasp List) is synced for better GRASP discovery. | 20 | /// Note: 10317 (User Grasp List) is synced for better GRASP discovery. |
| 21 | pub fn build_announcement_filter(since: Option<Timestamp>) -> Filter { | 21 | pub fn build_announcement_filter(since: Option<Timestamp>) -> Filter { |
| 22 | let filter = Filter::new().kinds([ | 22 | let filter = Filter::new().kinds([ |
| 23 | Kind::Custom(30617), // Repository announcements | 23 | Kind::GitRepoAnnouncement, // Repository announcements |
| 24 | Kind::Custom(30618), // Maintainer lists | 24 | Kind::RepoState, // Repository state |
| 25 | Kind::Custom(10317), // User Grasp List | 25 | Kind::GitUserGraspList, // User Grasp List |
| 26 | ]); | 26 | ]); |
| 27 | 27 | ||
| 28 | match since { | 28 | match since { |
diff --git a/src/sync/self_subscriber.rs b/src/sync/self_subscriber.rs index 09e3b56..9f6fa70 100644 --- a/src/sync/self_subscriber.rs +++ b/src/sync/self_subscriber.rs | |||
| @@ -149,7 +149,7 @@ impl SelfSubscriber { | |||
| 149 | match notification { | 149 | match notification { |
| 150 | Ok(RelayPoolNotification::Event { event, .. }) => { | 150 | Ok(RelayPoolNotification::Event { event, .. }) => { |
| 151 | // Only process 30617 events that list our relay | 151 | // Only process 30617 events that list our relay |
| 152 | if event.kind == Kind::Custom(30617) { | 152 | if event.kind == Kind::GitRepoAnnouncement { |
| 153 | if !self.lists_our_relay(&event) { | 153 | if !self.lists_our_relay(&event) { |
| 154 | return LoopControl::Continue; | 154 | return LoopControl::Continue; |
| 155 | } | 155 | } |
| @@ -236,7 +236,7 @@ impl SelfSubscriber { | |||
| 236 | /// Format: 30617:pubkey:identifier | 236 | /// Format: 30617:pubkey:identifier |
| 237 | fn extract_repo_id(event: &Event) -> Option<String> { | 237 | fn extract_repo_id(event: &Event) -> Option<String> { |
| 238 | // For kind 30617, extract d tag and build addressable ref | 238 | // For kind 30617, extract d tag and build addressable ref |
| 239 | if event.kind == Kind::Custom(30617) { | 239 | if event.kind == Kind::GitRepoAnnouncement { |
| 240 | for tag in event.tags.iter() { | 240 | for tag in event.tags.iter() { |
| 241 | let tag_vec = tag.as_slice(); | 241 | let tag_vec = tag.as_slice(); |
| 242 | if tag_vec.len() >= 2 && tag_vec[0] == "d" { | 242 | if tag_vec.len() >= 2 && tag_vec[0] == "d" { |
| @@ -296,21 +296,21 @@ impl SelfSubscriber { | |||
| 296 | ); | 296 | ); |
| 297 | Filter::new() | 297 | Filter::new() |
| 298 | .kinds(vec![ | 298 | .kinds(vec![ |
| 299 | Kind::Custom(30617), // Repository Announcements | 299 | Kind::GitRepoAnnouncement, // Repository Announcements |
| 300 | Kind::Custom(1617), // Patches | 300 | Kind::GitPatch, // Patches |
| 301 | Kind::Custom(1621), // Issues | 301 | Kind::GitIssue, // Issues |
| 302 | Kind::Custom(1618), // Pull Requests | 302 | Kind::GitPullRequest, // Pull Requests |
| 303 | Kind::Custom(10317), // User Grasp List | 303 | Kind::GitUserGraspList, // User Grasp List |
| 304 | ]) | 304 | ]) |
| 305 | .since(since) | 305 | .since(since) |
| 306 | } else { | 306 | } else { |
| 307 | // First connection - no since filter | 307 | // First connection - no since filter |
| 308 | Filter::new().kinds(vec![ | 308 | Filter::new().kinds(vec![ |
| 309 | Kind::Custom(30617), // Repository Announcements | 309 | Kind::GitRepoAnnouncement, // Repository Announcements |
| 310 | Kind::Custom(1617), // Patches | 310 | Kind::GitPatch, // Patches |
| 311 | Kind::Custom(1621), // Issues | 311 | Kind::GitIssue, // Issues |
| 312 | Kind::Custom(1618), // Pull Requests | 312 | Kind::GitPullRequest, // Pull Requests |
| 313 | Kind::Custom(10317), // User Grasp List | 313 | Kind::GitUserGraspList, // User Grasp List |
| 314 | ]) | 314 | ]) |
| 315 | }; | 315 | }; |
| 316 | 316 | ||
diff --git a/tests/common/purgatory_helpers.rs b/tests/common/purgatory_helpers.rs index b39982e..1d06f22 100644 --- a/tests/common/purgatory_helpers.rs +++ b/tests/common/purgatory_helpers.rs | |||
| @@ -16,11 +16,9 @@ use std::path::Path; | |||
| 16 | use std::process::Command; | 16 | use std::process::Command; |
| 17 | use std::time::Duration; | 17 | use std::time::Duration; |
| 18 | 18 | ||
| 19 | /// NIP-34 Repository State (kind 30618) | 19 | // NOTE: Using rust-nostr Kind variants: |
| 20 | pub const KIND_STATE: u16 = 30618; | 20 | // - Kind::RepoState.as_u16() -> Kind::RepoState (30618) |
| 21 | 21 | // - Kind::GitPullRequest.as_u16() -> Kind::GitPullRequest (1618) | |
| 22 | /// NIP-34 Pull Request (kind 1618) | ||
| 23 | pub const KIND_PR: u16 = 1618; | ||
| 24 | 22 | ||
| 25 | /// Commit variants for deterministic test commits | 23 | /// Commit variants for deterministic test commits |
| 26 | #[derive(Debug, Clone, Copy)] | 24 | #[derive(Debug, Clone, Copy)] |
| @@ -236,7 +234,7 @@ pub fn create_state_event( | |||
| 236 | )); | 234 | )); |
| 237 | } | 235 | } |
| 238 | 236 | ||
| 239 | EventBuilder::new(Kind::Custom(KIND_STATE), "") | 237 | EventBuilder::new(Kind::RepoState, "") |
| 240 | .tags(event_tags) | 238 | .tags(event_tags) |
| 241 | .sign_with_keys(keys) | 239 | .sign_with_keys(keys) |
| 242 | .map_err(|e| format!("Failed to sign state event: {}", e)) | 240 | .map_err(|e| format!("Failed to sign state event: {}", e)) |
| @@ -269,7 +267,7 @@ pub fn create_pr_event( | |||
| 269 | Tag::custom(TagKind::custom("c"), vec![commit_hash.to_string()]), | 267 | Tag::custom(TagKind::custom("c"), vec![commit_hash.to_string()]), |
| 270 | ]; | 268 | ]; |
| 271 | 269 | ||
| 272 | EventBuilder::new(Kind::Custom(KIND_PR), title) | 270 | EventBuilder::new(Kind::GitPullRequest, title) |
| 273 | .tags(tags) | 271 | .tags(tags) |
| 274 | .sign_with_keys(keys) | 272 | .sign_with_keys(keys) |
| 275 | .map_err(|e| format!("Failed to sign PR event: {}", e)) | 273 | .map_err(|e| format!("Failed to sign PR event: {}", e)) |
| @@ -323,7 +321,7 @@ pub fn create_pr_event_with_clone( | |||
| 323 | tags.push(Tag::custom(TagKind::Clone, urls)); | 321 | tags.push(Tag::custom(TagKind::Clone, urls)); |
| 324 | } | 322 | } |
| 325 | 323 | ||
| 326 | EventBuilder::new(Kind::Custom(KIND_PR), title) | 324 | EventBuilder::new(Kind::GitPullRequest, title) |
| 327 | .tags(tags) | 325 | .tags(tags) |
| 328 | .sign_with_keys(keys) | 326 | .sign_with_keys(keys) |
| 329 | .map_err(|e| format!("Failed to sign PR event: {}", e)) | 327 | .map_err(|e| format!("Failed to sign PR event: {}", e)) |
| @@ -705,7 +703,7 @@ mod tests { | |||
| 705 | ) | 703 | ) |
| 706 | .expect("Failed to create state event"); | 704 | .expect("Failed to create state event"); |
| 707 | 705 | ||
| 708 | assert_eq!(event.kind.as_u16(), KIND_STATE); | 706 | assert_eq!(event.kind.as_u16(), Kind::RepoState.as_u16()); |
| 709 | 707 | ||
| 710 | // Check d-tag | 708 | // Check d-tag |
| 711 | let has_d_tag = event.tags.iter().any(|tag| { | 709 | let has_d_tag = event.tags.iter().any(|tag| { |
| @@ -747,7 +745,7 @@ mod tests { | |||
| 747 | let event = create_pr_event(&keys, &repo_coord, "def456abc123", "Test PR") | 745 | let event = create_pr_event(&keys, &repo_coord, "def456abc123", "Test PR") |
| 748 | .expect("Failed to create PR event"); | 746 | .expect("Failed to create PR event"); |
| 749 | 747 | ||
| 750 | assert_eq!(event.kind.as_u16(), KIND_PR); | 748 | assert_eq!(event.kind.as_u16(), Kind::GitPullRequest.as_u16()); |
| 751 | 749 | ||
| 752 | // Check a-tag | 750 | // Check a-tag |
| 753 | let has_a_tag = event.tags.iter().any(|tag| { | 751 | let has_a_tag = event.tags.iter().any(|tag| { |
| @@ -815,7 +813,7 @@ mod tests { | |||
| 815 | ) | 813 | ) |
| 816 | .expect("Failed to create PR event with clone"); | 814 | .expect("Failed to create PR event with clone"); |
| 817 | 815 | ||
| 818 | assert_eq!(event.kind.as_u16(), KIND_PR); | 816 | assert_eq!(event.kind.as_u16(), Kind::GitPullRequest.as_u16()); |
| 819 | 817 | ||
| 820 | // Check a-tag | 818 | // Check a-tag |
| 821 | let has_a_tag = event.tags.iter().any(|tag| { | 819 | let has_a_tag = event.tags.iter().any(|tag| { |
diff --git a/tests/common/sync_helpers.rs b/tests/common/sync_helpers.rs index acf8c87..27422e9 100644 --- a/tests/common/sync_helpers.rs +++ b/tests/common/sync_helpers.rs | |||
| @@ -17,14 +17,10 @@ use nostr_sdk::prelude::*; | |||
| 17 | 17 | ||
| 18 | use super::relay::TestRelay; | 18 | use super::relay::TestRelay; |
| 19 | 19 | ||
| 20 | /// Kind 1618 - Issue (NIP-34 git-related event) | 20 | // NOTE: Using rust-nostr Kind variants: |
| 21 | pub const KIND_ISSUE: u16 = 1621; | 21 | // - Kind::GitIssue.as_u16() -> Kind::GitIssue (1621) |
| 22 | 22 | // - Kind::Comment.as_u16() -> Kind::Comment (1111) | |
| 23 | /// Kind 1111 - NIP-22 Comment | 23 | // - Kind::GitRepoAnnouncement.as_u16() -> Kind::GitRepoAnnouncement (30617) |
| 24 | pub const KIND_COMMENT: u16 = 1111; | ||
| 25 | |||
| 26 | /// Kind 30617 - Repository state/announcement (NIP-34) | ||
| 27 | pub const KIND_REPOSITORY_STATE: u16 = 30617; | ||
| 28 | 24 | ||
| 29 | /// Test client with built-in retry logic for connect and send operations. | 25 | /// Test client with built-in retry logic for connect and send operations. |
| 30 | /// | 26 | /// |
| @@ -225,7 +221,7 @@ fn build_layer2_issue_with_tag( | |||
| 225 | 221 | ||
| 226 | let tags = vec![tag]; | 222 | let tags = vec![tag]; |
| 227 | 223 | ||
| 228 | EventBuilder::new(Kind::Custom(KIND_ISSUE), title) | 224 | EventBuilder::new(Kind::GitIssue, title) |
| 229 | .tags(tags) | 225 | .tags(tags) |
| 230 | .sign_with_keys(keys) | 226 | .sign_with_keys(keys) |
| 231 | .map_err(|e| format!("Failed to sign Layer 2 issue event: {}", e)) | 227 | .map_err(|e| format!("Failed to sign Layer 2 issue event: {}", e)) |
| @@ -240,7 +236,7 @@ fn build_layer2_issue_with_tag( | |||
| 240 | /// * `keys` - Keys for signing the event | 236 | /// * `keys` - Keys for signing the event |
| 241 | /// * `parent_event_id` - Event ID being referenced (e.g., an issue or patch) | 237 | /// * `parent_event_id` - Event ID being referenced (e.g., an issue or patch) |
| 242 | /// * `content` - Comment content | 238 | /// * `content` - Comment content |
| 243 | /// * `kind` - Event kind (Kind::Custom(1) for reply, Kind::Custom(1111) for NIP-22 comment) | 239 | /// * `kind` - Event kind (Kind::TextNote for reply, Kind::Comment for NIP-22 comment) |
| 244 | /// | 240 | /// |
| 245 | /// # Tag Types | 241 | /// # Tag Types |
| 246 | /// - For kind 1111: Uses uppercase 'E' tag (NIP-22 style) | 242 | /// - For kind 1111: Uses uppercase 'E' tag (NIP-22 style) |
| @@ -258,7 +254,7 @@ pub fn build_layer3_comment_event( | |||
| 258 | let kind_num = kind.as_u16(); | 254 | let kind_num = kind.as_u16(); |
| 259 | 255 | ||
| 260 | // Choose tag based on kind (NIP-22 uses E, NIP-10 style uses e) | 256 | // Choose tag based on kind (NIP-22 uses E, NIP-10 style uses e) |
| 261 | let tag = if kind_num == KIND_COMMENT { | 257 | let tag = if kind_num == Kind::Comment.as_u16() { |
| 262 | // NIP-22 comment: uppercase 'E' tag | 258 | // NIP-22 comment: uppercase 'E' tag |
| 263 | Tag::custom(TagKind::custom("E"), vec![parent_event_id.to_hex()]) | 259 | Tag::custom(TagKind::custom("E"), vec![parent_event_id.to_hex()]) |
| 264 | } else { | 260 | } else { |
| @@ -302,7 +298,7 @@ pub fn build_layer3_comment_with_uppercase_e_tag( | |||
| 302 | ) -> Result<Event, String> { | 298 | ) -> Result<Event, String> { |
| 303 | let tag = Tag::custom(TagKind::custom("E"), vec![parent_event_id.to_hex()]); | 299 | let tag = Tag::custom(TagKind::custom("E"), vec![parent_event_id.to_hex()]); |
| 304 | 300 | ||
| 305 | EventBuilder::new(Kind::Custom(KIND_COMMENT), content) | 301 | EventBuilder::new(Kind::Comment, content) |
| 306 | .tags(vec![tag]) | 302 | .tags(vec![tag]) |
| 307 | .sign_with_keys(keys) | 303 | .sign_with_keys(keys) |
| 308 | .map_err(|e| format!("Failed to sign Layer 3 comment event: {}", e)) | 304 | .map_err(|e| format!("Failed to sign Layer 3 comment event: {}", e)) |
| @@ -362,7 +358,7 @@ pub fn create_repo_announcement(keys: &Keys, domains: &[&str], identifier: &str) | |||
| 362 | Tag::custom(TagKind::custom("relays"), relay_urls), | 358 | Tag::custom(TagKind::custom("relays"), relay_urls), |
| 363 | ]; | 359 | ]; |
| 364 | 360 | ||
| 365 | EventBuilder::new(Kind::Custom(KIND_REPOSITORY_STATE), "Repository state") | 361 | EventBuilder::new(Kind::GitRepoAnnouncement, "Repository state") |
| 366 | .tags(tags) | 362 | .tags(tags) |
| 367 | .sign_with_keys(keys) | 363 | .sign_with_keys(keys) |
| 368 | .expect("Failed to sign repo announcement") | 364 | .expect("Failed to sign repo announcement") |
| @@ -503,7 +499,7 @@ fn check_sync_connections_in_metrics(metrics: &str, expected: usize) -> bool { | |||
| 503 | /// # Example | 499 | /// # Example |
| 504 | /// ```ignore | 500 | /// ```ignore |
| 505 | /// let filter = Filter::new() | 501 | /// let filter = Filter::new() |
| 506 | /// .kind(Kind::Custom(1618)) | 502 | /// .kind(Kind::GitPullRequest) |
| 507 | /// .author(keys.public_key()) | 503 | /// .author(keys.public_key()) |
| 508 | /// .id(event.id); | 504 | /// .id(event.id); |
| 509 | /// | 505 | /// |
| @@ -559,7 +555,7 @@ pub async fn wait_for_event_on_relay(relay_url: &str, filter: Filter, timeout: D | |||
| 559 | pub fn repo_coord(keys: &Keys, identifier: &str) -> String { | 555 | pub fn repo_coord(keys: &Keys, identifier: &str) -> String { |
| 560 | format!( | 556 | format!( |
| 561 | "{}:{}:{}", | 557 | "{}:{}:{}", |
| 562 | KIND_REPOSITORY_STATE, | 558 | Kind::GitRepoAnnouncement.as_u16(), |
| 563 | keys.public_key().to_hex(), | 559 | keys.public_key().to_hex(), |
| 564 | identifier | 560 | identifier |
| 565 | ) | 561 | ) |
| @@ -897,7 +893,7 @@ mod tests { | |||
| 897 | build_layer2_issue_event(&keys, &coord, "Test Issue").expect("Should create event"); | 893 | build_layer2_issue_event(&keys, &coord, "Test Issue").expect("Should create event"); |
| 898 | 894 | ||
| 899 | // nostr-sdk 0.43: use field access | 895 | // nostr-sdk 0.43: use field access |
| 900 | assert_eq!(event.kind.as_u16(), KIND_ISSUE); | 896 | assert_eq!(event.kind.as_u16(), Kind::GitIssue.as_u16()); |
| 901 | 897 | ||
| 902 | // Check the tag exists | 898 | // Check the tag exists |
| 903 | let has_a_tag = event.tags.iter().any(|tag| { | 899 | let has_a_tag = event.tags.iter().any(|tag| { |
| @@ -942,15 +938,10 @@ mod tests { | |||
| 942 | let keys = Keys::generate(); | 938 | let keys = Keys::generate(); |
| 943 | let parent_id = EventId::all_zeros(); | 939 | let parent_id = EventId::all_zeros(); |
| 944 | 940 | ||
| 945 | let event = build_layer3_comment_event( | 941 | let event = build_layer3_comment_event(&keys, &parent_id, "Test comment", Kind::Comment) |
| 946 | &keys, | 942 | .expect("Should create event"); |
| 947 | &parent_id, | ||
| 948 | "Test comment", | ||
| 949 | Kind::Custom(KIND_COMMENT), | ||
| 950 | ) | ||
| 951 | .expect("Should create event"); | ||
| 952 | 943 | ||
| 953 | assert_eq!(event.kind.as_u16(), KIND_COMMENT); | 944 | assert_eq!(event.kind.as_u16(), Kind::Comment.as_u16()); |
| 954 | 945 | ||
| 955 | // NIP-22 comment should have uppercase 'E' tag | 946 | // NIP-22 comment should have uppercase 'E' tag |
| 956 | let has_e_tag = event.tags.iter().any(|tag| { | 947 | let has_e_tag = event.tags.iter().any(|tag| { |
| @@ -1003,7 +994,7 @@ mod tests { | |||
| 1003 | let event = build_layer3_comment_with_uppercase_e_tag(&keys, &parent_id, "Comment content") | 994 | let event = build_layer3_comment_with_uppercase_e_tag(&keys, &parent_id, "Comment content") |
| 1004 | .expect("Should create event"); | 995 | .expect("Should create event"); |
| 1005 | 996 | ||
| 1006 | assert_eq!(event.kind.as_u16(), KIND_COMMENT); | 997 | assert_eq!(event.kind.as_u16(), Kind::Comment.as_u16()); |
| 1007 | 998 | ||
| 1008 | let has_upper_e_tag = event.tags.iter().any(|tag| { | 999 | let has_upper_e_tag = event.tags.iter().any(|tag| { |
| 1009 | let slice = tag.as_slice(); | 1000 | let slice = tag.as_slice(); |
| @@ -1123,7 +1114,7 @@ async fn send_to_relay(relay: &TestRelay, event: &Event) -> Result<(), String> { | |||
| 1123 | /// // Assert issue synced to result.syncing_relay | 1114 | /// // Assert issue synced to result.syncing_relay |
| 1124 | /// | 1115 | /// |
| 1125 | /// // Live sync test | 1116 | /// // Live sync test |
| 1126 | /// let comment = build_layer3_comment_event(&keys, &issue.id, "Live Comment", Kind::Custom(1111))?; | 1117 | /// let comment = build_layer3_comment_event(&keys, &issue.id, "Live Comment", Kind::Comment)?; |
| 1127 | /// let result = run_sync_test(&[], &[comment]).await; | 1118 | /// let result = run_sync_test(&[], &[comment]).await; |
| 1128 | /// // Assert comment synced to result.syncing_relay | 1119 | /// // Assert comment synced to result.syncing_relay |
| 1129 | /// ``` | 1120 | /// ``` |
diff --git a/tests/nip77_negentropy.rs b/tests/nip77_negentropy.rs index 5293754..fccfe67 100644 --- a/tests/nip77_negentropy.rs +++ b/tests/nip77_negentropy.rs | |||
| @@ -56,7 +56,7 @@ async fn test_nip77_negentropy_sync_finds_events() { | |||
| 56 | // Create a second event (issue referencing the repo) | 56 | // Create a second event (issue referencing the repo) |
| 57 | let repo_coord = format!( | 57 | let repo_coord = format!( |
| 58 | "{}:{}:{}", | 58 | "{}:{}:{}", |
| 59 | KIND_REPOSITORY_STATE, | 59 | Kind::GitRepoAnnouncement.as_u16(), |
| 60 | keys.public_key().to_hex(), | 60 | keys.public_key().to_hex(), |
| 61 | "test-repo-nip77" | 61 | "test-repo-nip77" |
| 62 | ); | 62 | ); |
| @@ -103,10 +103,9 @@ async fn test_nip77_negentropy_sync_finds_events() { | |||
| 103 | tokio::time::sleep(Duration::from_millis(500)).await; | 103 | tokio::time::sleep(Duration::from_millis(500)).await; |
| 104 | 104 | ||
| 105 | // 6. Perform negentropy sync with filter matching our events | 105 | // 6. Perform negentropy sync with filter matching our events |
| 106 | let filter = Filter::new().author(keys.public_key()).kinds(vec![ | 106 | let filter = Filter::new() |
| 107 | Kind::Custom(KIND_REPOSITORY_STATE), | 107 | .author(keys.public_key()) |
| 108 | Kind::Custom(KIND_ISSUE), | 108 | .kinds(vec![Kind::GitRepoAnnouncement, Kind::GitIssue]); |
| 109 | ]); | ||
| 110 | 109 | ||
| 111 | println!("Starting negentropy sync with filter: {:?}", filter); | 110 | println!("Starting negentropy sync with filter: {:?}", filter); |
| 112 | 111 | ||
| @@ -183,7 +182,7 @@ async fn test_nip77_negentropy_sync_empty_result() { | |||
| 183 | // 3. Sync with filter that won't match anything | 182 | // 3. Sync with filter that won't match anything |
| 184 | let filter = Filter::new() | 183 | let filter = Filter::new() |
| 185 | .author(keys.public_key()) // Random new key, no events exist | 184 | .author(keys.public_key()) // Random new key, no events exist |
| 186 | .kind(Kind::Custom(KIND_REPOSITORY_STATE)); | 185 | .kind(Kind::GitRepoAnnouncement); |
| 187 | 186 | ||
| 188 | println!("Starting negentropy sync with empty filter"); | 187 | println!("Starting negentropy sync with empty filter"); |
| 189 | 188 | ||
diff --git a/tests/purgatory_sync.rs b/tests/purgatory_sync.rs index 3f52e4c..72f3d81 100644 --- a/tests/purgatory_sync.rs +++ b/tests/purgatory_sync.rs | |||
| @@ -795,7 +795,7 @@ async fn test_pr_event_clone_tag_sync_with_partial_oid_aggregation_from_multiple | |||
| 795 | // Clone URLs: source_grasp + syncing (NOT git_server - PR commit only via PR's clone tag) | 795 | // Clone URLs: source_grasp + syncing (NOT git_server - PR commit only via PR's clone tag) |
| 796 | // Relay URLs: source_grasp + mock_relay + syncing | 796 | // Relay URLs: source_grasp + mock_relay + syncing |
| 797 | let announcement = nostr_sdk::EventBuilder::new( | 797 | let announcement = nostr_sdk::EventBuilder::new( |
| 798 | nostr_sdk::Kind::Custom(30617), | 798 | Kind::GitRepoAnnouncement, |
| 799 | "Repository for PR clone tag + partial OID test", | 799 | "Repository for PR clone tag + partial OID test", |
| 800 | ) | 800 | ) |
| 801 | .tags(vec![ | 801 | .tags(vec![ |
diff --git a/tests/sync/discovery.rs b/tests/sync/discovery.rs index 3aa6dda..8ed80b5 100644 --- a/tests/sync/discovery.rs +++ b/tests/sync/discovery.rs | |||
| @@ -14,8 +14,8 @@ use nostr_sdk::prelude::*; | |||
| 14 | 14 | ||
| 15 | use crate::common::{sync_helpers::*, TestRelay}; | 15 | use crate::common::{sync_helpers::*, TestRelay}; |
| 16 | 16 | ||
| 17 | /// Kind 1617 - Patch event (NIP-34) | 17 | // NOTE: Using rust-nostr Kind variant: |
| 18 | const KIND_PATCH: u16 = 1617; | 18 | // - Kind::GitPatch.as_u16() -> Kind::GitPatch (1617) |
| 19 | 19 | ||
| 20 | /// Create an event referencing a repository coordinate via 'a' tag. | 20 | /// Create an event referencing a repository coordinate via 'a' tag. |
| 21 | /// | 21 | /// |
| @@ -26,7 +26,7 @@ fn create_event_referencing_repo(keys: &Keys, repo_coord: &str, kind: u16, conte | |||
| 26 | vec![repo_coord.to_string()], | 26 | vec![repo_coord.to_string()], |
| 27 | )]; | 27 | )]; |
| 28 | 28 | ||
| 29 | EventBuilder::new(Kind::Custom(kind), content) | 29 | EventBuilder::new(Kind::from_u16(kind), content) |
| 30 | .tags(tags) | 30 | .tags(tags) |
| 31 | .sign_with_keys(keys) | 31 | .sign_with_keys(keys) |
| 32 | .expect("Failed to sign event") | 32 | .expect("Failed to sign event") |
| @@ -82,14 +82,18 @@ async fn test_discovers_layer3_via_layer2() { | |||
| 82 | // 5. Build the repo coordinate for the 'a' tag in the patch | 82 | // 5. Build the repo coordinate for the 'a' tag in the patch |
| 83 | let repo_coord = format!( | 83 | let repo_coord = format!( |
| 84 | "{}:{}:{}", | 84 | "{}:{}:{}", |
| 85 | KIND_REPOSITORY_STATE, | 85 | Kind::GitRepoAnnouncement.as_u16(), |
| 86 | keys.public_key().to_hex(), | 86 | keys.public_key().to_hex(), |
| 87 | "test-repo-discovery" | 87 | "test-repo-discovery" |
| 88 | ); | 88 | ); |
| 89 | 89 | ||
| 90 | // 6. Create a patch event (Layer 2) that references the announcement | 90 | // 6. Create a patch event (Layer 2) that references the announcement |
| 91 | let patch = | 91 | let patch = create_event_referencing_repo( |
| 92 | create_event_referencing_repo(&keys, &repo_coord, KIND_PATCH, "Test patch proposal"); | 92 | &keys, |
| 93 | &repo_coord, | ||
| 94 | Kind::GitPatch.as_u16(), | ||
| 95 | "Test patch proposal", | ||
| 96 | ); | ||
| 93 | let patch_id = patch.id; | 97 | let patch_id = patch.id; |
| 94 | 98 | ||
| 95 | println!("Created patch {} (kind {})", patch_id, patch.kind.as_u16()); | 99 | println!("Created patch {} (kind {})", patch_id, patch.kind.as_u16()); |
| @@ -134,9 +138,7 @@ async fn test_discovers_layer3_via_layer2() { | |||
| 134 | tokio::time::sleep(Duration::from_secs(3)).await; | 138 | tokio::time::sleep(Duration::from_secs(3)).await; |
| 135 | 139 | ||
| 136 | // 10. Verify patch was synced to relay_b | 140 | // 10. Verify patch was synced to relay_b |
| 137 | let filter = Filter::new() | 141 | let filter = Filter::new().kind(Kind::GitPatch).author(keys.public_key()); |
| 138 | .kind(Kind::Custom(KIND_PATCH)) | ||
| 139 | .author(keys.public_key()); | ||
| 140 | 142 | ||
| 141 | let patch_synced = wait_for_event_on_relay(relay_b.url(), filter, Duration::from_secs(5)).await; | 143 | let patch_synced = wait_for_event_on_relay(relay_b.url(), filter, Duration::from_secs(5)).await; |
| 142 | 144 | ||
| @@ -250,9 +252,7 @@ async fn test_relay_discovery_via_announcements_with_historic_sync() { | |||
| 250 | tokio::time::sleep(Duration::from_secs(3)).await; | 252 | tokio::time::sleep(Duration::from_secs(3)).await; |
| 251 | 253 | ||
| 252 | // 8. Verify Layer 2 event synced to relay_b | 254 | // 8. Verify Layer 2 event synced to relay_b |
| 253 | let issue_filter = Filter::new() | 255 | let issue_filter = Filter::new().kind(Kind::GitIssue).author(keys.public_key()); |
| 254 | .kind(Kind::Custom(KIND_ISSUE)) | ||
| 255 | .author(keys.public_key()); | ||
| 256 | let issue_synced = | 256 | let issue_synced = |
| 257 | wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await; | 257 | wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await; |
| 258 | 258 | ||
| @@ -389,7 +389,7 @@ async fn test_recursive_relay_discovery_via_announcements_with_historic_sync() { | |||
| 389 | 389 | ||
| 390 | // 8. Verify announcement_x was synced to relay_a (from bootstrap relay_b) | 390 | // 8. Verify announcement_x was synced to relay_a (from bootstrap relay_b) |
| 391 | let filter_x = Filter::new() | 391 | let filter_x = Filter::new() |
| 392 | .kind(Kind::Custom(KIND_REPOSITORY_STATE)) | 392 | .kind(Kind::GitRepoAnnouncement) |
| 393 | .author(keys_x.public_key()); | 393 | .author(keys_x.public_key()); |
| 394 | 394 | ||
| 395 | let announcement_x_synced = | 395 | let announcement_x_synced = |
| @@ -402,7 +402,7 @@ async fn test_recursive_relay_discovery_via_announcements_with_historic_sync() { | |||
| 402 | 402 | ||
| 403 | // 9. Verify announcement_y was synced to relay_a (from discovered relay_c) | 403 | // 9. Verify announcement_y was synced to relay_a (from discovered relay_c) |
| 404 | let filter_y = Filter::new() | 404 | let filter_y = Filter::new() |
| 405 | .kind(Kind::Custom(KIND_REPOSITORY_STATE)) | 405 | .kind(Kind::GitRepoAnnouncement) |
| 406 | .author(keys_y.public_key()); | 406 | .author(keys_y.public_key()); |
| 407 | 407 | ||
| 408 | let announcement_y_synced = | 408 | let announcement_y_synced = |
diff --git a/tests/sync/historic_sync.rs b/tests/sync/historic_sync.rs index c388a7f..aec2819 100644 --- a/tests/sync/historic_sync.rs +++ b/tests/sync/historic_sync.rs | |||
| @@ -29,7 +29,7 @@ async fn test_bootstrap_syncs_existing_layer2_events() { | |||
| 29 | 29 | ||
| 30 | // Verify announcement synced to syncing relay | 30 | // Verify announcement synced to syncing relay |
| 31 | let filter = Filter::new() | 31 | let filter = Filter::new() |
| 32 | .kind(Kind::Custom(KIND_REPOSITORY_STATE)) | 32 | .kind(Kind::GitRepoAnnouncement) |
| 33 | .author(result.maintainer_keys.public_key()); | 33 | .author(result.maintainer_keys.public_key()); |
| 34 | 34 | ||
| 35 | let synced = | 35 | let synced = |
| @@ -64,7 +64,7 @@ async fn test_relay_replays_events_after_restart() { | |||
| 64 | 64 | ||
| 65 | // Verify announcement synced on first run | 65 | // Verify announcement synced on first run |
| 66 | let filter = Filter::new() | 66 | let filter = Filter::new() |
| 67 | .kind(Kind::Custom(KIND_REPOSITORY_STATE)) | 67 | .kind(Kind::GitRepoAnnouncement) |
| 68 | .author(result.maintainer_keys.public_key()); | 68 | .author(result.maintainer_keys.public_key()); |
| 69 | 69 | ||
| 70 | let synced_first = wait_for_event_on_relay( | 70 | let synced_first = wait_for_event_on_relay( |
| @@ -173,7 +173,7 @@ async fn test_announcement_not_listing_relay_is_not_synced() { | |||
| 173 | 173 | ||
| 174 | // Verify announcement did NOT sync to syncing relay | 174 | // Verify announcement did NOT sync to syncing relay |
| 175 | let filter = Filter::new() | 175 | let filter = Filter::new() |
| 176 | .kind(Kind::Custom(KIND_REPOSITORY_STATE)) | 176 | .kind(Kind::GitRepoAnnouncement) |
| 177 | .author(keys.public_key()); | 177 | .author(keys.public_key()); |
| 178 | 178 | ||
| 179 | let synced = wait_for_event_on_relay(syncing.url(), filter, Duration::from_secs(2)).await; | 179 | let synced = wait_for_event_on_relay(syncing.url(), filter, Duration::from_secs(2)).await; |
| @@ -274,7 +274,7 @@ async fn test_history_sync_without_negentropy() { | |||
| 274 | 274 | ||
| 275 | // Verify announcement synced to syncing relay via HISTORY sync | 275 | // Verify announcement synced to syncing relay via HISTORY sync |
| 276 | let filter = Filter::new() | 276 | let filter = Filter::new() |
| 277 | .kind(Kind::Custom(KIND_REPOSITORY_STATE)) | 277 | .kind(Kind::GitRepoAnnouncement) |
| 278 | .author(keys.public_key()); | 278 | .author(keys.public_key()); |
| 279 | 279 | ||
| 280 | let synced = wait_for_event_on_relay(syncing.url(), filter, Duration::from_secs(5)).await; | 280 | let synced = wait_for_event_on_relay(syncing.url(), filter, Duration::from_secs(5)).await; |
| @@ -339,7 +339,7 @@ async fn test_pagination_for_large_historic_sync() { | |||
| 339 | // Create 40 issue events to test pagination (with limit=10, threshold=7) | 339 | // Create 40 issue events to test pagination (with limit=10, threshold=7) |
| 340 | let repo_coord = format!( | 340 | let repo_coord = format!( |
| 341 | "{}:{}:{}", | 341 | "{}:{}:{}", |
| 342 | KIND_REPOSITORY_STATE, | 342 | Kind::GitRepoAnnouncement.as_u16(), |
| 343 | keys.public_key().to_hex(), | 343 | keys.public_key().to_hex(), |
| 344 | repo_id | 344 | repo_id |
| 345 | ); | 345 | ); |
| @@ -416,16 +416,14 @@ async fn test_pagination_for_large_historic_sync() { | |||
| 416 | 416 | ||
| 417 | // Verify announcement synced | 417 | // Verify announcement synced |
| 418 | let announcement_filter = Filter::new() | 418 | let announcement_filter = Filter::new() |
| 419 | .kind(Kind::Custom(KIND_REPOSITORY_STATE)) | 419 | .kind(Kind::GitRepoAnnouncement) |
| 420 | .author(keys.public_key()); | 420 | .author(keys.public_key()); |
| 421 | 421 | ||
| 422 | let announcement_synced = | 422 | let announcement_synced = |
| 423 | wait_for_event_on_relay(syncing.url(), announcement_filter, Duration::from_secs(3)).await; | 423 | wait_for_event_on_relay(syncing.url(), announcement_filter, Duration::from_secs(3)).await; |
| 424 | 424 | ||
| 425 | // Verify ALL 40 issues synced | 425 | // Verify ALL 40 issues synced |
| 426 | let issues_filter = Filter::new() | 426 | let issues_filter = Filter::new().kind(Kind::GitIssue).author(keys.public_key()); |
| 427 | .kind(Kind::Custom(KIND_ISSUE)) | ||
| 428 | .author(keys.public_key()); | ||
| 429 | 427 | ||
| 430 | // Query for all issues | 428 | // Query for all issues |
| 431 | let temp_keys = Keys::generate(); | 429 | let temp_keys = Keys::generate(); |
diff --git a/tests/sync/live_sync.rs b/tests/sync/live_sync.rs index 7fa08a0..8ee3119 100644 --- a/tests/sync/live_sync.rs +++ b/tests/sync/live_sync.rs | |||
| @@ -115,7 +115,7 @@ async fn test_live_sync_layer2_events() { | |||
| 115 | 115 | ||
| 116 | // 9. Wait and verify event syncs to relay_b | 116 | // 9. Wait and verify event syncs to relay_b |
| 117 | let filter = Filter::new() | 117 | let filter = Filter::new() |
| 118 | .kind(Kind::Custom(KIND_ISSUE)) | 118 | .kind(Kind::GitIssue) |
| 119 | .author(keys.public_key()) | 119 | .author(keys.public_key()) |
| 120 | .id(issue_id); | 120 | .id(issue_id); |
| 121 | 121 | ||
| @@ -237,7 +237,7 @@ async fn test_live_sync_layer3_events() { | |||
| 237 | // 6. Now wait for issue to sync to relay_b (this triggers Layer 3 filter creation) | 237 | // 6. Now wait for issue to sync to relay_b (this triggers Layer 3 filter creation) |
| 238 | tokio::time::sleep(Duration::from_secs(2)).await; | 238 | tokio::time::sleep(Duration::from_secs(2)).await; |
| 239 | 239 | ||
| 240 | let issue_filter = Filter::new().kind(Kind::Custom(KIND_ISSUE)).id(issue_id); | 240 | let issue_filter = Filter::new().kind(Kind::GitIssue).id(issue_id); |
| 241 | let issue_synced = | 241 | let issue_synced = |
| 242 | wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(3)).await; | 242 | wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(3)).await; |
| 243 | println!("Issue synced to relay_b: {}", issue_synced); | 243 | println!("Issue synced to relay_b: {}", issue_synced); |
| @@ -247,7 +247,7 @@ async fn test_live_sync_layer3_events() { | |||
| 247 | 247 | ||
| 248 | // 7. Wait and verify comment syncs to relay_b | 248 | // 7. Wait and verify comment syncs to relay_b |
| 249 | let comment_filter = Filter::new() | 249 | let comment_filter = Filter::new() |
| 250 | .kind(Kind::Custom(KIND_COMMENT)) | 250 | .kind(Kind::Comment) |
| 251 | .author(keys.public_key()) | 251 | .author(keys.public_key()) |
| 252 | .id(comment_id); | 252 | .id(comment_id); |
| 253 | 253 | ||
| @@ -267,9 +267,7 @@ async fn test_live_sync_layer3_events() { | |||
| 267 | client.connect().await; | 267 | client.connect().await; |
| 268 | tokio::time::sleep(Duration::from_millis(500)).await; | 268 | tokio::time::sleep(Duration::from_millis(500)).await; |
| 269 | 269 | ||
| 270 | let fetch_filter = Filter::new() | 270 | let fetch_filter = Filter::new().kind(Kind::Comment).id(comment_id); |
| 271 | .kind(Kind::Custom(KIND_COMMENT)) | ||
| 272 | .id(comment_id); | ||
| 273 | 271 | ||
| 274 | if let Ok(events) = client | 272 | if let Ok(events) = client |
| 275 | .fetch_events(fetch_filter, Duration::from_secs(2)) | 273 | .fetch_events(fetch_filter, Duration::from_secs(2)) |
| @@ -418,9 +416,7 @@ async fn test_live_sync_event_ordering() { | |||
| 418 | client.connect().await; | 416 | client.connect().await; |
| 419 | tokio::time::sleep(Duration::from_millis(500)).await; | 417 | tokio::time::sleep(Duration::from_millis(500)).await; |
| 420 | 418 | ||
| 421 | let filter = Filter::new() | 419 | let filter = Filter::new().kind(Kind::GitIssue).author(keys.public_key()); |
| 422 | .kind(Kind::Custom(KIND_ISSUE)) | ||
| 423 | .author(keys.public_key()); | ||
| 424 | 420 | ||
| 425 | match client.fetch_events(filter, Duration::from_secs(3)).await { | 421 | match client.fetch_events(filter, Duration::from_secs(3)).await { |
| 426 | Ok(events) => { | 422 | Ok(events) => { |
diff --git a/tests/sync/metrics.rs b/tests/sync/metrics.rs index 987b83a..e8c75c7 100644 --- a/tests/sync/metrics.rs +++ b/tests/sync/metrics.rs | |||
| @@ -17,7 +17,7 @@ use nostr_sdk::prelude::*; | |||
| 17 | use crate::common::{ | 17 | use crate::common::{ |
| 18 | sync_helpers::{ | 18 | sync_helpers::{ |
| 19 | create_repo_announcement, fetch_metrics, wait_for_sync_connection, MetricsTestHarness, | 19 | create_repo_announcement, fetch_metrics, wait_for_sync_connection, MetricsTestHarness, |
| 20 | ParsedMetrics, TestClient, KIND_REPOSITORY_STATE, | 20 | ParsedMetrics, TestClient, |
| 21 | }, | 21 | }, |
| 22 | TestRelay, | 22 | TestRelay, |
| 23 | }; | 23 | }; |
| @@ -175,8 +175,8 @@ async fn test_metric_values_are_numeric() { | |||
| 175 | // Phase 2: Real Metrics Tests (Using MetricsTestHarness) | 175 | // Phase 2: Real Metrics Tests (Using MetricsTestHarness) |
| 176 | // ============================================================================ | 176 | // ============================================================================ |
| 177 | 177 | ||
| 178 | /// Kind 1617 - Patch event (NIP-34) | 178 | // NOTE: Using rust-nostr Kind variant: |
| 179 | const KIND_PATCH: u16 = 1617; | 179 | // - Kind::GitPatch.as_u16() -> Kind::GitPatch (1617) |
| 180 | 180 | ||
| 181 | /// Create an event referencing a repository coordinate via 'a' tag. | 181 | /// Create an event referencing a repository coordinate via 'a' tag. |
| 182 | /// | 182 | /// |
| @@ -187,7 +187,7 @@ fn create_event_referencing_repo(keys: &Keys, repo_coord: &str, kind: u16, conte | |||
| 187 | vec![repo_coord.to_string()], | 187 | vec![repo_coord.to_string()], |
| 188 | )]; | 188 | )]; |
| 189 | 189 | ||
| 190 | EventBuilder::new(Kind::Custom(kind), content) | 190 | EventBuilder::new(Kind::from_u16(kind), content) |
| 191 | .tags(tags) | 191 | .tags(tags) |
| 192 | .sign_with_keys(keys) | 192 | .sign_with_keys(keys) |
| 193 | .expect("Failed to sign event") | 193 | .expect("Failed to sign event") |
| @@ -239,7 +239,7 @@ async fn test_startup_sync_event_count() { | |||
| 239 | // 5. Build the repo coordinate for the 'a' tag in the patches | 239 | // 5. Build the repo coordinate for the 'a' tag in the patches |
| 240 | let repo_coord = format!( | 240 | let repo_coord = format!( |
| 241 | "{}:{}:{}", | 241 | "{}:{}:{}", |
| 242 | KIND_REPOSITORY_STATE, | 242 | Kind::GitRepoAnnouncement.as_u16(), |
| 243 | keys.public_key().to_hex(), | 243 | keys.public_key().to_hex(), |
| 244 | "test-repo-metrics" | 244 | "test-repo-metrics" |
| 245 | ); | 245 | ); |
| @@ -250,7 +250,7 @@ async fn test_startup_sync_event_count() { | |||
| 250 | create_event_referencing_repo( | 250 | create_event_referencing_repo( |
| 251 | &keys, | 251 | &keys, |
| 252 | &repo_coord, | 252 | &repo_coord, |
| 253 | KIND_PATCH, | 253 | Kind::GitPatch.as_u16(), |
| 254 | &format!("Test patch {}", i), | 254 | &format!("Test patch {}", i), |
| 255 | ) | 255 | ) |
| 256 | }) | 256 | }) |
| @@ -320,7 +320,7 @@ async fn test_startup_sync_event_count() { | |||
| 320 | 320 | ||
| 321 | // 12. Verify patches actually synced (functional check) | 321 | // 12. Verify patches actually synced (functional check) |
| 322 | let filter = Filter::new() | 322 | let filter = Filter::new() |
| 323 | .kind(Kind::Custom(KIND_PATCH)) | 323 | .kind(Kind::Custom(Kind::GitPatch.as_u16())) |
| 324 | .author(keys.public_key()); | 324 | .author(keys.public_key()); |
| 325 | 325 | ||
| 326 | let patches_synced = crate::common::sync_helpers::wait_for_event_on_relay( | 326 | let patches_synced = crate::common::sync_helpers::wait_for_event_on_relay( |
diff --git a/tests/sync/tag_variations.rs b/tests/sync/tag_variations.rs index 7153104..46b1203 100644 --- a/tests/sync/tag_variations.rs +++ b/tests/sync/tag_variations.rs | |||
| @@ -110,7 +110,7 @@ async fn test_layer2_sync_with_lowercase_a_tag() { | |||
| 110 | 110 | ||
| 111 | // 5. Wait and verify event syncs to relay_b | 111 | // 5. Wait and verify event syncs to relay_b |
| 112 | let filter = Filter::new() | 112 | let filter = Filter::new() |
| 113 | .kind(Kind::Custom(KIND_ISSUE)) | 113 | .kind(Kind::GitIssue) |
| 114 | .author(keys.public_key()) | 114 | .author(keys.public_key()) |
| 115 | .id(issue_id); | 115 | .id(issue_id); |
| 116 | 116 | ||
| @@ -212,7 +212,7 @@ async fn test_layer2_sync_with_uppercase_a_tag() { | |||
| 212 | 212 | ||
| 213 | // 5. Wait and verify event syncs to relay_b | 213 | // 5. Wait and verify event syncs to relay_b |
| 214 | let filter = Filter::new() | 214 | let filter = Filter::new() |
| 215 | .kind(Kind::Custom(KIND_ISSUE)) | 215 | .kind(Kind::GitIssue) |
| 216 | .author(keys.public_key()) | 216 | .author(keys.public_key()) |
| 217 | .id(issue_id); | 217 | .id(issue_id); |
| 218 | 218 | ||
| @@ -309,7 +309,7 @@ async fn test_layer2_sync_with_q_tag() { | |||
| 309 | 309 | ||
| 310 | // 5. Wait and verify event syncs to relay_b | 310 | // 5. Wait and verify event syncs to relay_b |
| 311 | let filter = Filter::new() | 311 | let filter = Filter::new() |
| 312 | .kind(Kind::Custom(KIND_ISSUE)) | 312 | .kind(Kind::GitIssue) |
| 313 | .author(keys.public_key()) | 313 | .author(keys.public_key()) |
| 314 | .id(issue_id); | 314 | .id(issue_id); |
| 315 | 315 | ||
| @@ -403,7 +403,7 @@ async fn test_layer3_sync_with_lowercase_e_tag() { | |||
| 403 | println!("Layer 2 issue {} sent to relay_a", issue_id); | 403 | println!("Layer 2 issue {} sent to relay_a", issue_id); |
| 404 | 404 | ||
| 405 | // 5. Wait for issue to sync to relay_b | 405 | // 5. Wait for issue to sync to relay_b |
| 406 | let issue_filter = Filter::new().kind(Kind::Custom(KIND_ISSUE)).id(issue_id); | 406 | let issue_filter = Filter::new().kind(Kind::GitIssue).id(issue_id); |
| 407 | let issue_synced = | 407 | let issue_synced = |
| 408 | wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await; | 408 | wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await; |
| 409 | println!("Issue synced to relay_b: {}", issue_synced); | 409 | println!("Issue synced to relay_b: {}", issue_synced); |
| @@ -527,7 +527,7 @@ async fn test_layer3_sync_with_uppercase_e_tag() { | |||
| 527 | println!("Layer 2 issue {} sent to relay_a", issue_id); | 527 | println!("Layer 2 issue {} sent to relay_a", issue_id); |
| 528 | 528 | ||
| 529 | // 5. Wait for issue to sync to relay_b | 529 | // 5. Wait for issue to sync to relay_b |
| 530 | let issue_filter = Filter::new().kind(Kind::Custom(KIND_ISSUE)).id(issue_id); | 530 | let issue_filter = Filter::new().kind(Kind::GitIssue).id(issue_id); |
| 531 | let issue_synced = | 531 | let issue_synced = |
| 532 | wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await; | 532 | wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await; |
| 533 | println!("Issue synced to relay_b: {}", issue_synced); | 533 | println!("Issue synced to relay_b: {}", issue_synced); |
| @@ -567,7 +567,7 @@ async fn test_layer3_sync_with_uppercase_e_tag() { | |||
| 567 | 567 | ||
| 568 | // 7. Wait and verify comment syncs to relay_b | 568 | // 7. Wait and verify comment syncs to relay_b |
| 569 | let comment_filter = Filter::new() | 569 | let comment_filter = Filter::new() |
| 570 | .kind(Kind::Custom(KIND_COMMENT)) // Kind 1111 | 570 | .kind(Kind::Comment) // Kind 1111 |
| 571 | .author(keys.public_key()) | 571 | .author(keys.public_key()) |
| 572 | .id(comment_id); | 572 | .id(comment_id); |
| 573 | 573 | ||
| @@ -655,7 +655,7 @@ async fn test_layer3_sync_with_q_tag() { | |||
| 655 | println!("Layer 2 issue {} sent to relay_a", issue_id); | 655 | println!("Layer 2 issue {} sent to relay_a", issue_id); |
| 656 | 656 | ||
| 657 | // 5. Wait for issue to sync to relay_b | 657 | // 5. Wait for issue to sync to relay_b |
| 658 | let issue_filter = Filter::new().kind(Kind::Custom(KIND_ISSUE)).id(issue_id); | 658 | let issue_filter = Filter::new().kind(Kind::GitIssue).id(issue_id); |
| 659 | let issue_synced = | 659 | let issue_synced = |
| 660 | wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await; | 660 | wait_for_event_on_relay(relay_b.url(), issue_filter, Duration::from_secs(5)).await; |
| 661 | println!("Issue synced to relay_b: {}", issue_synced); | 661 | println!("Issue synced to relay_b: {}", issue_synced); |