From 2a9160836bb87fdea3ae891563b0169c68d1c2ab Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 11 Dec 2025 16:53:03 +0000 Subject: fix: resolve all fmt and clippy warnings Main lib (src/): - Add #[allow(dead_code)] for build_info field (stored to prevent Prometheus unregistration) - Add #[allow(dead_code)] for first_seen field (reserved for future rate limiting) - Replace .or_insert_with(RelaySyncNeeds::default) with .or_default() - Replace manual div_ceil implementations with .div_ceil(100) Test code (tests/): - Replace .expect(&format!(...)) with .unwrap_or_else(|_| panic!(...)) - Remove needless borrows in fetch_metrics() calls - Add #[allow(dead_code)] and #[allow(unused_imports)] to test helpers module grasp-audit: - Apply cargo fmt to fix formatting --- grasp-audit/src/specs/grasp01/mod.rs | 4 +- grasp-audit/src/specs/grasp01/nip01_smoke.rs | 32 +++---- .../src/specs/grasp01/push_authorization.rs | 97 +++++++++++++++------- 3 files changed, 89 insertions(+), 44 deletions(-) (limited to 'grasp-audit/src/specs') diff --git a/grasp-audit/src/specs/grasp01/mod.rs b/grasp-audit/src/specs/grasp01/mod.rs index ba27fef..fa05f35 100644 --- a/grasp-audit/src/specs/grasp01/mod.rs +++ b/grasp-audit/src/specs/grasp01/mod.rs @@ -29,6 +29,6 @@ pub use nip11_document::Nip11DocumentTests; pub use push_authorization::PushAuthorizationTests; pub use repository_creation::RepositoryCreationTests; pub use spec_requirements::{ - get_requirement, get_requirements_for_section, get_sections, RequirementLevel, - SpecRequirement, GRASP_01_REQUIREMENTS, GRASP_COMMIT_ID, + get_requirement, get_requirements_for_section, get_sections, RequirementLevel, SpecRequirement, + GRASP_01_REQUIREMENTS, GRASP_COMMIT_ID, }; diff --git a/grasp-audit/src/specs/grasp01/nip01_smoke.rs b/grasp-audit/src/specs/grasp01/nip01_smoke.rs index 8a0a4d1..4dbcd3d 100644 --- a/grasp-audit/src/specs/grasp01/nip01_smoke.rs +++ b/grasp-audit/src/specs/grasp01/nip01_smoke.rs @@ -163,23 +163,27 @@ impl Nip01SmokeTests { /// Spec: NIP-01 CLOSE message /// Requirement: Relay MUST support CLOSE to end subscriptions pub async fn test_close_subscription(client: &AuditClient) -> TestResult { - TestResult::new("close_subscription", "GRASP-01:nostr-relay:7", "Can close subscriptions") - .run(|| async { - // For now, we just verify we can query events - // Full subscription management with CLOSE would require - // lower-level WebSocket access + TestResult::new( + "close_subscription", + "GRASP-01:nostr-relay:7", + "Can close subscriptions", + ) + .run(|| async { + // For now, we just verify we can query events + // Full subscription management with CLOSE would require + // lower-level WebSocket access - let filter = Filter::new().kind(Kind::TextNote).limit(1); + let filter = Filter::new().kind(Kind::TextNote).limit(1); - let _events = client - .subscribe(vec![filter], Some(std::time::Duration::from_secs(2))) - .await - .map_err(|e| format!("Failed to subscribe: {}", e))?; + let _events = client + .subscribe(vec![filter], Some(std::time::Duration::from_secs(2))) + .await + .map_err(|e| format!("Failed to subscribe: {}", e))?; - // If we got here, subscription worked - Ok(()) - }) - .await + // If we got here, subscription worked + Ok(()) + }) + .await } /// Test 5: Rejects events with invalid signatures diff --git a/grasp-audit/src/specs/grasp01/push_authorization.rs b/grasp-audit/src/specs/grasp01/push_authorization.rs index c06da0d..ec08032 100644 --- a/grasp-audit/src/specs/grasp01/push_authorization.rs +++ b/grasp-audit/src/specs/grasp01/push_authorization.rs @@ -407,8 +407,12 @@ impl PushAuthorizationTests { let repo = match ctx.get_fixture(FixtureKind::ValidRepo).await { Ok(r) => r, Err(e) => { - return TestResult::new(test_name, "GRASP-01:git-http:30", "Push rejected without state event") - .fail(format!("Failed to create repo: {}", e)) + return TestResult::new( + test_name, + "GRASP-01:git-http:30", + "Push rejected without state event", + ) + .fail(format!("Failed to create repo: {}", e)) } }; @@ -427,8 +431,12 @@ impl PushAuthorizationTests { let clone_path = match clone_repo(relay_domain, &npub, &repo_id) { Ok(p) => p, Err(e) => { - return TestResult::new(test_name, "GRASP-01:git-http:30", "Push rejected without state event") - .fail(&e) + return TestResult::new( + test_name, + "GRASP-01:git-http:30", + "Push rejected without state event", + ) + .fail(&e) } }; let cleanup = || { @@ -437,8 +445,12 @@ impl PushAuthorizationTests { if let Err(e) = create_commit(&clone_path, "Unauthorized commit") { cleanup(); - return TestResult::new(test_name, "GRASP-01:git-http:30", "Push rejected without state event") - .fail(&e); + return TestResult::new( + test_name, + "GRASP-01:git-http:30", + "Push rejected without state event", + ) + .fail(&e); } // Do NOT publish state event - push should be rejected @@ -446,14 +458,24 @@ impl PushAuthorizationTests { cleanup(); match push_result { - Ok(false) => { - TestResult::new(test_name, "GRASP-01:git-http:30", "Push rejected without state event").pass() - } - Ok(true) => TestResult::new(test_name, "GRASP-01:git-http:30", "Push rejected without state event") - .fail("Push accepted but should be rejected"), - Err(e) => { - TestResult::new(test_name, "GRASP-01:git-http:30", "Push rejected without state event").fail(&e) - } + Ok(false) => TestResult::new( + test_name, + "GRASP-01:git-http:30", + "Push rejected without state event", + ) + .pass(), + Ok(true) => TestResult::new( + test_name, + "GRASP-01:git-http:30", + "Push rejected without state event", + ) + .fail("Push accepted but should be rejected"), + Err(e) => TestResult::new( + test_name, + "GRASP-01:git-http:30", + "Push rejected without state event", + ) + .fail(&e), } } @@ -480,11 +502,18 @@ impl PushAuthorizationTests { // The OwnerStateDataPushed fixture handles all stages: // Generate → Send → Verify → DataPush match ctx.get_fixture(FixtureKind::OwnerStateDataPushed).await { - Ok(_state_event) => { - TestResult::new(test_name, "GRASP-01:git-http:30", "Push authorized with matching state").pass() - } - Err(e) => TestResult::new(test_name, "GRASP-01:git-http:30", "Push authorized with matching state") - .fail(format!("{}", e)), + Ok(_state_event) => TestResult::new( + test_name, + "GRASP-01:git-http:30", + "Push authorized with matching state", + ) + .pass(), + Err(e) => TestResult::new( + test_name, + "GRASP-01:git-http:30", + "Push authorized with matching state", + ) + .fail(format!("{}", e)), } } @@ -868,8 +897,12 @@ impl PushAuthorizationTests { // Send the rogue state event using the raw client to bypass AuditClient's key check if let Err(e) = client.client().send_event(&rogue_state).await { cleanup(); - return TestResult::new(test_name, "GRASP-01:git-http:30", "Non-maintainer state events ignored") - .fail(format!("Failed to send rogue state event: {}", e)); + return TestResult::new( + test_name, + "GRASP-01:git-http:30", + "Non-maintainer state events ignored", + ) + .fail(format!("Failed to send rogue state event: {}", e)); } // Wait for event to propagate @@ -1036,7 +1069,9 @@ impl PushAuthorizationTests { .await { Ok(_pr_event) => TestResult::new(test_name, "GRASP-01:git-http:34", desc).pass(), - Err(e) => TestResult::new(test_name, "GRASP-01:git-http:34", desc).fail(format!("{}", e)), + Err(e) => { + TestResult::new(test_name, "GRASP-01:git-http:34", desc).fail(format!("{}", e)) + } } } @@ -1062,7 +1097,8 @@ impl PushAuthorizationTests { { Ok(e) => e, Err(e) => { - return TestResult::new(test_name, "GRASP-01:git-http:34", desc).fail(format!("{}", e)); + return TestResult::new(test_name, "GRASP-01:git-http:34", desc) + .fail(format!("{}", e)); } }; @@ -1072,7 +1108,8 @@ impl PushAuthorizationTests { let repo = match ctx.get_fixture(FixtureKind::ValidRepo).await { Ok(r) => r, Err(e) => { - return TestResult::new(test_name, "GRASP-01:git-http:34", desc).fail(format!("{}", e)); + return TestResult::new(test_name, "GRASP-01:git-http:34", desc) + .fail(format!("{}", e)); } }; @@ -1146,7 +1183,8 @@ impl PushAuthorizationTests { { Ok(e) => e, Err(e) => { - return TestResult::new(test_name, "GRASP-01:git-http:34", desc).fail(format!("{}", e)); + return TestResult::new(test_name, "GRASP-01:git-http:34", desc) + .fail(format!("{}", e)); } }; @@ -1156,7 +1194,8 @@ impl PushAuthorizationTests { let repo = match ctx.get_fixture(FixtureKind::ValidRepo).await { Ok(r) => r, Err(e) => { - return TestResult::new(test_name, "GRASP-01:git-http:34", desc).fail(format!("{}", e)); + return TestResult::new(test_name, "GRASP-01:git-http:34", desc) + .fail(format!("{}", e)); } }; @@ -1233,7 +1272,8 @@ impl PushAuthorizationTests { { Ok(e) => e, Err(e) => { - return TestResult::new(test_name, "GRASP-01:git-http:34", desc).fail(format!("{}", e)); + return TestResult::new(test_name, "GRASP-01:git-http:34", desc) + .fail(format!("{}", e)); } }; @@ -1243,7 +1283,8 @@ impl PushAuthorizationTests { let repo = match ctx.get_fixture(FixtureKind::ValidRepo).await { Ok(r) => r, Err(e) => { - return TestResult::new(test_name, "GRASP-01:git-http:34", desc).fail(format!("{}", e)); + return TestResult::new(test_name, "GRASP-01:git-http:34", desc) + .fail(format!("{}", e)); } }; -- cgit v1.2.3