From 5d02ad6b893f9059044914c115d77cf9d8e589c3 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 8 Jan 2026 11:20:35 +0000 Subject: 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 --- grasp-audit/src/client.rs | 4 ++-- grasp-audit/src/fixtures.rs | 14 +++++++------- grasp-audit/src/specs/grasp01/event_acceptance_policy.rs | 8 ++++---- grasp-audit/src/specs/grasp01/nip01_smoke.rs | 6 +++--- grasp-audit/src/specs/grasp01/push_authorization.rs | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) (limited to 'grasp-audit/src') 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 { // Add any additional tags tags.extend(additional_tags); - self.event_builder(Kind::Custom(1621), content) + self.event_builder(Kind::GitIssue, content) .tags(tags) .build(self.keys()) .map_err(|e| anyhow!("Failed to build issue event: {}", e)) @@ -530,7 +530,7 @@ impl AuditClient { // Add any additional tags tags.extend(additional_tags); - self.event_builder(Kind::Custom(1111), content) + self.event_builder(Kind::Comment, content) .tags(tags) .build(self.keys()) .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> { // Tag format: ["refs/heads/main", ""] // Note: We build the state but DON'T send it here - the caller will send it self.client - .event_builder(Kind::Custom(30618), "") + .event_builder(Kind::RepoState, "") .tag(Tag::identifier(&repo_id)) .tag(Tag::custom( TagKind::custom("refs/heads/main"), @@ -713,7 +713,7 @@ impl<'a> TestContext<'a> { // Build NIP-34 PR event (kind 1618) self.client .event_builder( - Kind::Custom(1618), // NIP-34 PR kind (has 'c' tag for commit) + Kind::GitPullRequest, // NIP-34 PR kind (has 'c' tag for commit) "Test PR for GRASP validation", ) .tag(Tag::custom( @@ -756,7 +756,7 @@ impl<'a> TestContext<'a> { // Build NIP-34 PR event (kind 1618) self.client .event_builder( - Kind::Custom(1618), // NIP-34 PR kind (has 'c' tag for commit) + Kind::GitPullRequest, // NIP-34 PR kind (has 'c' tag for commit) "Test PR for GRASP validation", ) .tag(Tag::custom( @@ -884,7 +884,7 @@ impl<'a> TestContext<'a> { let state_event = self .client - .event_builder(Kind::Custom(30618), "") + .event_builder(Kind::RepoState, "") .tag(Tag::identifier(&repo_id)) .tag(Tag::custom( TagKind::custom("refs/heads/main"), @@ -1057,7 +1057,7 @@ impl<'a> TestContext<'a> { let maintainer_state_event = self .client - .event_builder(Kind::Custom(30618), "") + .event_builder(Kind::RepoState, "") .tag(Tag::identifier(&repo_id)) .tag(Tag::custom( TagKind::custom("refs/heads/main"), @@ -1230,7 +1230,7 @@ impl<'a> TestContext<'a> { let recursive_maintainer_state_event = self .client - .event_builder(Kind::Custom(30618), "") + .event_builder(Kind::RepoState, "") .tag(Tag::identifier(&repo_id)) .tag(Tag::custom( TagKind::custom("refs/heads/main"), @@ -1397,7 +1397,7 @@ impl<'a> TestContext<'a> { let develop_state_event = self .client - .event_builder(Kind::Custom(30618), "") + .event_builder(Kind::RepoState, "") .tag(Tag::identifier(&repo_id)) .tag(Tag::custom( 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 { ]; let comment = client - .event_builder(Kind::Custom(1111), "Comment on repo") + .event_builder(Kind::Comment, "Comment on repo") .tags(tags) .build(client.keys()) .map_err(|e| format!("Failed to build comment: {}", e))?; @@ -935,7 +935,7 @@ impl EventAcceptancePolicyTests { ]; let issue = client - .event_builder(Kind::Custom(1621), "issue content") + .event_builder(Kind::GitIssue, "issue content") .tags(issue_tags) .build(client.keys()) .map_err(|e| format!("Failed to build issue: {}", e))?; @@ -995,7 +995,7 @@ impl EventAcceptancePolicyTests { ]; let comment_b = client - .event_builder(Kind::Custom(1111), "Comment B quoting Comment A") + .event_builder(Kind::Comment, "Comment B quoting Comment A") .tags(comment_b_tags) .build(client.keys()) .map_err(|e| format!("Failed to build comment B: {}", e))?; @@ -1172,7 +1172,7 @@ impl EventAcceptancePolicyTests { ]; let comment = client - .event_builder(Kind::Custom(1111), "Comment on unaccepted repo") + .event_builder(Kind::Comment, "Comment on unaccepted repo") .tags(tags) .build(client.keys()) .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 { tokio::time::sleep(std::time::Duration::from_millis(100)).await; // Step 2: VERIFY - Query event back - let filter = Filter::new().kind(Kind::Custom(30617)).id(event_id); + let filter = Filter::new().kind(Kind::GitRepoAnnouncement).id(event_id); let events = client .query(filter) @@ -88,7 +88,7 @@ impl Nip01SmokeTests { if events.is_empty() { // Debug: try querying without audit client filtering eprintln!("Event not found with audit client query, trying direct client query..."); - let direct_filter = Filter::new().kind(Kind::Custom(30617)).id(event_id); + let direct_filter = Filter::new().kind(Kind::GitRepoAnnouncement).id(event_id); let direct_events = client .client() .fetch_events(direct_filter, std::time::Duration::from_secs(5)) @@ -140,7 +140,7 @@ impl Nip01SmokeTests { // Step 2: VERIFY - Subscribe to NIP-34 announcements from this author let filter = Filter::new() - .kind(Kind::Custom(30617)) + .kind(Kind::GitRepoAnnouncement) .author(client.public_key()); 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 { // Create a rogue state event announcing the new commit // This event has the correct repo_id but is signed by a non-maintainer let rogue_state = match client - .event_builder(Kind::Custom(30618), "") + .event_builder(Kind::RepoState, "") .tag(Tag::identifier(&repo_id)) .tag(Tag::custom( TagKind::custom("refs/heads/main"), @@ -1591,7 +1591,7 @@ impl PushAuthorizationTests { // This references a commit that doesn't yet exist on the relay // ============================================================ let state_event = match client - .event_builder(Kind::Custom(30618), "") + .event_builder(Kind::RepoState, "") .tag(Tag::identifier(&repo_id)) .tag(Tag::custom( TagKind::custom("HEAD"), -- cgit v1.2.3