upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/grasp-audit/src
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-20 22:15:03 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-20 22:20:28 +0000
commit519fdc66930280cd1772417dca327ed858333d64 (patch)
tree4b20e18ccbc7406106bc72316dc3e26f2b58495f /grasp-audit/src
parentca50f5b98f30d0933a510c05db86b608afee73a0 (diff)
refactor: isolate each grasp-audit lib test with minimal boilerplate
- Add isolated_test! macro pattern to nip34_announcements.rs and nip01_compliance.rs - Each test runs with its own fresh relay instance for complete isolation - Make all individual test functions public in grasp-audit library (nip01_smoke.rs, event_acceptance_policy.rs) - Eliminates 122 lines of boilerplate across integration tests - Tests: 15 GRASP-01 event acceptance policy tests + 6 NIP-01 smoke tests - Ensures tests don't interfere with each other, preventing flakiness
Diffstat (limited to 'grasp-audit/src')
-rw-r--r--grasp-audit/src/specs/grasp01/event_acceptance_policy.rs32
-rw-r--r--grasp-audit/src/specs/grasp01/nip01_smoke.rs12
2 files changed, 22 insertions, 22 deletions
diff --git a/grasp-audit/src/specs/grasp01/event_acceptance_policy.rs b/grasp-audit/src/specs/grasp01/event_acceptance_policy.rs
index c257155..638ae5f 100644
--- a/grasp-audit/src/specs/grasp01/event_acceptance_policy.rs
+++ b/grasp-audit/src/specs/grasp01/event_acceptance_policy.rs
@@ -143,7 +143,7 @@ impl EventAcceptancePolicyTests {
143 /// **Using TestContext pattern:** 143 /// **Using TestContext pattern:**
144 /// - In CI mode: Creates fresh repo for full isolation 144 /// - In CI mode: Creates fresh repo for full isolation
145 /// - In Production mode: Reuses cached repo to minimize events 145 /// - In Production mode: Reuses cached repo to minimize events
146 async fn test_accept_valid_repo_announcement(client: &AuditClient) -> TestResult { 146 pub async fn test_accept_valid_repo_announcement(client: &AuditClient) -> TestResult {
147 TestResult::new( 147 TestResult::new(
148 "accept_valid_repo_announcement", 148 "accept_valid_repo_announcement",
149 "GRASP-01:nostr-relay:3-5", 149 "GRASP-01:nostr-relay:3-5",
@@ -246,7 +246,7 @@ impl EventAcceptancePolicyTests {
246 /// 246 ///
247 /// Spec: Line 5 of ../grasp/01.md 247 /// Spec: Line 5 of ../grasp/01.md
248 /// Requirement: MUST reject announcements not listing service (unless GRASP-05) 248 /// Requirement: MUST reject announcements not listing service (unless GRASP-05)
249 async fn test_reject_repo_announcement_missing_clone_tag(client: &AuditClient) -> TestResult { 249 pub async fn test_reject_repo_announcement_missing_clone_tag(client: &AuditClient) -> TestResult {
250 TestResult::new( 250 TestResult::new(
251 "reject_repo_announcement_missing_clone_tag", 251 "reject_repo_announcement_missing_clone_tag",
252 "GRASP-01:nostr-relay:5", 252 "GRASP-01:nostr-relay:5",
@@ -320,7 +320,7 @@ impl EventAcceptancePolicyTests {
320 /// 320 ///
321 /// Spec: Line 5 of ../grasp/01.md 321 /// Spec: Line 5 of ../grasp/01.md
322 /// Requirement: MUST reject announcements not listing service in relays 322 /// Requirement: MUST reject announcements not listing service in relays
323 async fn test_reject_repo_announcement_missing_relays_tag(client: &AuditClient) -> TestResult { 323 pub async fn test_reject_repo_announcement_missing_relays_tag(client: &AuditClient) -> TestResult {
324 TestResult::new( 324 TestResult::new(
325 "reject_repo_announcement_missing_relays_tag", 325 "reject_repo_announcement_missing_relays_tag",
326 "GRASP-01:nostr-relay:5", 326 "GRASP-01:nostr-relay:5",
@@ -412,7 +412,7 @@ impl EventAcceptancePolicyTests {
412 /// This test demonstrates the new TestContext pattern: 412 /// This test demonstrates the new TestContext pattern:
413 /// - In CI mode: Creates fresh repo for full isolation 413 /// - In CI mode: Creates fresh repo for full isolation
414 /// - In Production mode: Reuses cached repo to minimize events 414 /// - In Production mode: Reuses cached repo to minimize events
415 async fn test_accept_valid_repo_state_announcement(client: &AuditClient) -> TestResult { 415 pub async fn test_accept_valid_repo_state_announcement(client: &AuditClient) -> TestResult {
416 TestResult::new( 416 TestResult::new(
417 "accept_valid_repo_state_announcement", 417 "accept_valid_repo_state_announcement",
418 "GRASP-01:nostr-relay:6-7", 418 "GRASP-01:nostr-relay:6-7",
@@ -579,7 +579,7 @@ impl EventAcceptancePolicyTests {
579 /// 579 ///
580 /// **EXAMPLE: Using TestContext for prerequisite events** 580 /// **EXAMPLE: Using TestContext for prerequisite events**
581 /// Demonstrates how TestContext simplifies test setup while supporting dual modes 581 /// Demonstrates how TestContext simplifies test setup while supporting dual modes
582 async fn test_accept_issue_via_a_tag(client: &AuditClient) -> TestResult { 582 pub async fn test_accept_issue_via_a_tag(client: &AuditClient) -> TestResult {
583 TestResult::new( 583 TestResult::new(
584 "accept_issue_via_a_tag", 584 "accept_issue_via_a_tag",
585 "GRASP-01:event-acceptance:1.1", 585 "GRASP-01:event-acceptance:1.1",
@@ -614,7 +614,7 @@ impl EventAcceptancePolicyTests {
614 /// **Using TestContext pattern:** 614 /// **Using TestContext pattern:**
615 /// - In CI mode: Creates fresh repo for full isolation 615 /// - In CI mode: Creates fresh repo for full isolation
616 /// - In Production mode: Reuses cached repo to minimize events 616 /// - In Production mode: Reuses cached repo to minimize events
617 async fn test_accept_comment_via_capital_a_tag(client: &AuditClient) -> TestResult { 617 pub async fn test_accept_comment_via_capital_a_tag(client: &AuditClient) -> TestResult {
618 TestResult::new( 618 TestResult::new(
619 "accept_comment_via_A_tag", 619 "accept_comment_via_A_tag",
620 "GRASP-01:event-acceptance:1.2", 620 "GRASP-01:event-acceptance:1.2",
@@ -666,7 +666,7 @@ impl EventAcceptancePolicyTests {
666 /// **Using TestContext pattern:** 666 /// **Using TestContext pattern:**
667 /// - In CI mode: Creates fresh repo for full isolation 667 /// - In CI mode: Creates fresh repo for full isolation
668 /// - In Production mode: Reuses cached repo to minimize events 668 /// - In Production mode: Reuses cached repo to minimize events
669 async fn test_accept_kind1_via_q_tag(client: &AuditClient) -> TestResult { 669 pub async fn test_accept_kind1_via_q_tag(client: &AuditClient) -> TestResult {
670 TestResult::new( 670 TestResult::new(
671 "accept_kind1_via_q_tag", 671 "accept_kind1_via_q_tag",
672 "GRASP-01:event-acceptance:1.3", 672 "GRASP-01:event-acceptance:1.3",
@@ -715,7 +715,7 @@ impl EventAcceptancePolicyTests {
715 /// **Using TestContext pattern:** 715 /// **Using TestContext pattern:**
716 /// - In CI mode: Creates fresh repo+issue for full isolation 716 /// - In CI mode: Creates fresh repo+issue for full isolation
717 /// - In Production mode: Reuses cached repo+issue to minimize events 717 /// - In Production mode: Reuses cached repo+issue to minimize events
718 async fn test_accept_issue_quoting_issue_via_q(client: &AuditClient) -> TestResult { 718 pub async fn test_accept_issue_quoting_issue_via_q(client: &AuditClient) -> TestResult {
719 TestResult::new( 719 TestResult::new(
720 "accept_issue_quoting_issue_via_q", 720 "accept_issue_quoting_issue_via_q",
721 "GRASP-01:event-acceptance:2.1", 721 "GRASP-01:event-acceptance:2.1",
@@ -761,7 +761,7 @@ impl EventAcceptancePolicyTests {
761 /// **Using TestContext pattern:** 761 /// **Using TestContext pattern:**
762 /// - In CI mode: Creates fresh repo+issue for full isolation 762 /// - In CI mode: Creates fresh repo+issue for full isolation
763 /// - In Production mode: Reuses cached repo+issue to minimize events 763 /// - In Production mode: Reuses cached repo+issue to minimize events
764 async fn test_accept_comment_via_capital_e_tag(client: &AuditClient) -> TestResult { 764 pub async fn test_accept_comment_via_capital_e_tag(client: &AuditClient) -> TestResult {
765 TestResult::new( 765 TestResult::new(
766 "accept_comment_via_E_tag", 766 "accept_comment_via_E_tag",
767 "GRASP-01:event-acceptance:2.2", 767 "GRASP-01:event-acceptance:2.2",
@@ -799,7 +799,7 @@ impl EventAcceptancePolicyTests {
799 /// **Using TestContext pattern:** 799 /// **Using TestContext pattern:**
800 /// - In CI mode: Creates fresh repo for full isolation 800 /// - In CI mode: Creates fresh repo for full isolation
801 /// - In Production mode: Reuses cached repo to minimize events 801 /// - In Production mode: Reuses cached repo to minimize events
802 async fn test_accept_kind1_via_e_tag(client: &AuditClient) -> TestResult { 802 pub async fn test_accept_kind1_via_e_tag(client: &AuditClient) -> TestResult {
803 TestResult::new( 803 TestResult::new(
804 "accept_kind1_via_e_tag", 804 "accept_kind1_via_e_tag",
805 "GRASP-01:event-acceptance:2.3", 805 "GRASP-01:event-acceptance:2.3",
@@ -859,7 +859,7 @@ impl EventAcceptancePolicyTests {
859 /// **Using TestContext pattern:** 859 /// **Using TestContext pattern:**
860 /// - In CI mode: Creates fresh repo for full isolation 860 /// - In CI mode: Creates fresh repo for full isolation
861 /// - In Production mode: Reuses cached repo to minimize events 861 /// - In Production mode: Reuses cached repo to minimize events
862 async fn test_accept_kind1_referenced_in_issue(client: &AuditClient) -> TestResult { 862 pub async fn test_accept_kind1_referenced_in_issue(client: &AuditClient) -> TestResult {
863 TestResult::new( 863 TestResult::new(
864 "accept_kind1_referenced_in_issue", 864 "accept_kind1_referenced_in_issue",
865 "GRASP-01:event-acceptance:3.1", 865 "GRASP-01:event-acceptance:3.1",
@@ -928,7 +928,7 @@ impl EventAcceptancePolicyTests {
928 /// **Using TestContext pattern:** 928 /// **Using TestContext pattern:**
929 /// - In CI mode: Creates fresh repo+issue for full isolation 929 /// - In CI mode: Creates fresh repo+issue for full isolation
930 /// - In Production mode: Reuses cached repo+issue to minimize events 930 /// - In Production mode: Reuses cached repo+issue to minimize events
931 async fn test_accept_comment_referenced_in_comment(client: &AuditClient) -> TestResult { 931 pub async fn test_accept_comment_referenced_in_comment(client: &AuditClient) -> TestResult {
932 TestResult::new( 932 TestResult::new(
933 "accept_comment_referenced_in_comment", 933 "accept_comment_referenced_in_comment",
934 "GRASP-01:event-acceptance:3.2", 934 "GRASP-01:event-acceptance:3.2",
@@ -1010,7 +1010,7 @@ impl EventAcceptancePolicyTests {
1010 /// **Using TestContext pattern:** 1010 /// **Using TestContext pattern:**
1011 /// - In CI mode: Creates fresh repo for full isolation 1011 /// - In CI mode: Creates fresh repo for full isolation
1012 /// - In Production mode: Reuses cached repo to minimize events 1012 /// - In Production mode: Reuses cached repo to minimize events
1013 async fn test_accept_kind1_referenced_in_kind1(client: &AuditClient) -> TestResult { 1013 pub async fn test_accept_kind1_referenced_in_kind1(client: &AuditClient) -> TestResult {
1014 TestResult::new( 1014 TestResult::new(
1015 "accept_kind1_referenced_in_kind1", 1015 "accept_kind1_referenced_in_kind1",
1016 "GRASP-01:event-acceptance:3.3", 1016 "GRASP-01:event-acceptance:3.3",
@@ -1070,7 +1070,7 @@ impl EventAcceptancePolicyTests {
1070 // ============================================================ 1070 // ============================================================
1071 1071
1072 /// Test 4.1: Issue referencing unaccepted repo should be rejected 1072 /// Test 4.1: Issue referencing unaccepted repo should be rejected
1073 async fn test_reject_orphan_issue(client: &AuditClient) -> TestResult { 1073 pub async fn test_reject_orphan_issue(client: &AuditClient) -> TestResult {
1074 TestResult::new( 1074 TestResult::new(
1075 "reject_orphan_issue", 1075 "reject_orphan_issue",
1076 "GRASP-01:event-acceptance:4.1", 1076 "GRASP-01:event-acceptance:4.1",
@@ -1098,7 +1098,7 @@ impl EventAcceptancePolicyTests {
1098 } 1098 }
1099 1099
1100 /// Test 4.2: Generic kind 1 note with no repo references should be rejected 1100 /// Test 4.2: Generic kind 1 note with no repo references should be rejected
1101 async fn test_reject_orphan_kind1(client: &AuditClient) -> TestResult { 1101 pub async fn test_reject_orphan_kind1(client: &AuditClient) -> TestResult {
1102 TestResult::new( 1102 TestResult::new(
1103 "reject_orphan_kind1", 1103 "reject_orphan_kind1",
1104 "GRASP-01:event-acceptance:4.2", 1104 "GRASP-01:event-acceptance:4.2",
@@ -1126,7 +1126,7 @@ impl EventAcceptancePolicyTests {
1126 /// - In CI mode: Creates fresh accepted repo for full isolation 1126 /// - In CI mode: Creates fresh accepted repo for full isolation
1127 /// - In Production mode: Reuses cached accepted repo to minimize events 1127 /// - In Production mode: Reuses cached accepted repo to minimize events
1128 /// - Note: Unaccepted repo B is always created fresh (not cached) since it must remain unaccepted 1128 /// - Note: Unaccepted repo B is always created fresh (not cached) since it must remain unaccepted
1129 async fn test_reject_comment_quoting_other_repo(client: &AuditClient) -> TestResult { 1129 pub async fn test_reject_comment_quoting_other_repo(client: &AuditClient) -> TestResult {
1130 TestResult::new( 1130 TestResult::new(
1131 "reject_comment_quoting_other_repo", 1131 "reject_comment_quoting_other_repo",
1132 "GRASP-01:event-acceptance:4.3", 1132 "GRASP-01:event-acceptance:4.3",
diff --git a/grasp-audit/src/specs/grasp01/nip01_smoke.rs b/grasp-audit/src/specs/grasp01/nip01_smoke.rs
index 204ee60..79220e5 100644
--- a/grasp-audit/src/specs/grasp01/nip01_smoke.rs
+++ b/grasp-audit/src/specs/grasp01/nip01_smoke.rs
@@ -29,7 +29,7 @@ impl Nip01SmokeTests {
29 /// 29 ///
30 /// Spec: NIP-01 basic requirement 30 /// Spec: NIP-01 basic requirement
31 /// Requirement: MUST serve a relay at / via WebSocket 31 /// Requirement: MUST serve a relay at / via WebSocket
32 async fn test_websocket_connection(client: &AuditClient) -> TestResult { 32 pub async fn test_websocket_connection(client: &AuditClient) -> TestResult {
33 TestResult::new( 33 TestResult::new(
34 "websocket_connection", 34 "websocket_connection",
35 "NIP-01:basic", 35 "NIP-01:basic",
@@ -52,7 +52,7 @@ impl Nip01SmokeTests {
52 /// 52 ///
53 /// For GRASP servers, we send a NIP-34 repository announcement that lists 53 /// For GRASP servers, we send a NIP-34 repository announcement that lists
54 /// the GRASP server in clone and relays tags (required for acceptance). 54 /// the GRASP server in clone and relays tags (required for acceptance).
55 async fn test_send_receive_event(client: &AuditClient) -> TestResult { 55 pub async fn test_send_receive_event(client: &AuditClient) -> TestResult {
56 TestResult::new( 56 TestResult::new(
57 "send_receive_event", 57 "send_receive_event",
58 "NIP-01:event-message", 58 "NIP-01:event-message",
@@ -123,7 +123,7 @@ impl Nip01SmokeTests {
123 /// 123 ///
124 /// Spec: NIP-01 REQ message 124 /// Spec: NIP-01 REQ message
125 /// Requirement: Relay MUST support REQ subscriptions 125 /// Requirement: Relay MUST support REQ subscriptions
126 async fn test_create_subscription(client: &AuditClient) -> TestResult { 126 pub async fn test_create_subscription(client: &AuditClient) -> TestResult {
127 TestResult::new( 127 TestResult::new(
128 "create_subscription", 128 "create_subscription",
129 "NIP-01:req-message", 129 "NIP-01:req-message",
@@ -165,7 +165,7 @@ impl Nip01SmokeTests {
165 /// 165 ///
166 /// Spec: NIP-01 CLOSE message 166 /// Spec: NIP-01 CLOSE message
167 /// Requirement: Relay MUST support CLOSE to end subscriptions 167 /// Requirement: Relay MUST support CLOSE to end subscriptions
168 async fn test_close_subscription(client: &AuditClient) -> TestResult { 168 pub async fn test_close_subscription(client: &AuditClient) -> TestResult {
169 TestResult::new( 169 TestResult::new(
170 "close_subscription", 170 "close_subscription",
171 "NIP-01:close-message", 171 "NIP-01:close-message",
@@ -193,7 +193,7 @@ impl Nip01SmokeTests {
193 /// 193 ///
194 /// Spec: NIP-01 event validation 194 /// Spec: NIP-01 event validation
195 /// Requirement: Relay MUST reject events with invalid signatures 195 /// Requirement: Relay MUST reject events with invalid signatures
196 async fn test_reject_invalid_signature(client: &AuditClient) -> TestResult { 196 pub async fn test_reject_invalid_signature(client: &AuditClient) -> TestResult {
197 TestResult::new( 197 TestResult::new(
198 "reject_invalid_signature", 198 "reject_invalid_signature",
199 "NIP-01:validation", 199 "NIP-01:validation",
@@ -247,7 +247,7 @@ impl Nip01SmokeTests {
247 /// 247 ///
248 /// Spec: NIP-01 event ID validation 248 /// Spec: NIP-01 event ID validation
249 /// Requirement: Relay MUST reject events where ID doesn't match hash 249 /// Requirement: Relay MUST reject events where ID doesn't match hash
250 async fn test_reject_invalid_event_id(client: &AuditClient) -> TestResult { 250 pub async fn test_reject_invalid_event_id(client: &AuditClient) -> TestResult {
251 TestResult::new( 251 TestResult::new(
252 "reject_invalid_event_id", 252 "reject_invalid_event_id",
253 "NIP-01:validation", 253 "NIP-01:validation",