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 /grasp-audit/src | |
| 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
Diffstat (limited to 'grasp-audit/src')
| -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 |
5 files changed, 18 insertions, 18 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"), |