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/client.rs | 4 +- grasp-audit/src/fixtures.rs | 6 +- grasp-audit/src/result.rs | 41 +++++++-- grasp-audit/src/specs/grasp01/mod.rs | 4 +- grasp-audit/src/specs/grasp01/nip01_smoke.rs | 32 +++---- .../src/specs/grasp01/push_authorization.rs | 97 +++++++++++++++------- 6 files changed, 127 insertions(+), 57 deletions(-) (limited to 'grasp-audit/src') diff --git a/grasp-audit/src/client.rs b/grasp-audit/src/client.rs index 21c70be..259a317 100644 --- a/grasp-audit/src/client.rs +++ b/grasp-audit/src/client.rs @@ -585,7 +585,9 @@ mod tests { "Missing 'grasp-audit-test-event' tag" ); assert!( - tag_contents.iter().any(|t| t.starts_with("audit-isolated-")), + tag_contents + .iter() + .any(|t| t.starts_with("audit-isolated-")), "Missing 'audit-isolated-*' tag" ); assert!( diff --git a/grasp-audit/src/fixtures.rs b/grasp-audit/src/fixtures.rs index 174f83d..a15bd79 100644 --- a/grasp-audit/src/fixtures.rs +++ b/grasp-audit/src/fixtures.rs @@ -1973,11 +1973,11 @@ mod tests { #[test] fn test_context_mode_from_audit_mode() { - assert_eq!(ContextMode::from(AuditMode::Isolated), ContextMode::Isolated); assert_eq!( - ContextMode::from(AuditMode::Shared), - ContextMode::Shared + ContextMode::from(AuditMode::Isolated), + ContextMode::Isolated ); + assert_eq!(ContextMode::from(AuditMode::Shared), ContextMode::Shared); } #[test] diff --git a/grasp-audit/src/result.rs b/grasp-audit/src/result.rs index 0de16ae..f296633 100644 --- a/grasp-audit/src/result.rs +++ b/grasp-audit/src/result.rs @@ -38,7 +38,9 @@ fn parse_spec_lines(spec_ref: &str) -> Vec { if line_part.contains('-') { let range_parts: Vec<&str> = line_part.split('-').collect(); if range_parts.len() == 2 { - if let (Ok(start), Ok(end)) = (range_parts[0].parse::(), range_parts[1].parse::()) { + if let (Ok(start), Ok(end)) = + (range_parts[0].parse::(), range_parts[1].parse::()) + { return (start..=end).collect(); } } @@ -162,10 +164,19 @@ impl AuditResult { /// Print a detailed report aligned to GRASP-01 specification pub fn print_report(&self) { println!(); - println!("{}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{}", BOLD, RESET); + println!( + "{}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{}", + BOLD, RESET + ); println!("{}GRASP-01 Compliance Report{}", BOLD, RESET); - println!("Source: github.com/nostr-protocol/grasp (commit: {})", GRASP_COMMIT_ID); - println!("{}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{}", BOLD, RESET); + println!( + "Source: github.com/nostr-protocol/grasp (commit: {})", + GRASP_COMMIT_ID + ); + println!( + "{}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{}", + BOLD, RESET + ); // Build a map of spec line -> tests that cover it let mut tests_by_line: BTreeMap> = BTreeMap::new(); @@ -185,7 +196,10 @@ impl AuditResult { println!(); println!("{}{}## {}{}", CYAN, BOLD, section, RESET); - for req in GRASP_01_REQUIREMENTS.iter().filter(|r| r.section == section) { + for req in GRASP_01_REQUIREMENTS + .iter() + .filter(|r| r.section == section) + { println!(); // Print spec requirement in blue println!("{}📘 Line {}: {}{}", BLUE, req.line, req.text, RESET); @@ -218,7 +232,10 @@ impl AuditResult { } println!(); - println!("{}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{}", BOLD, RESET); + println!( + "{}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{}", + BOLD, RESET + ); // Summary statistics let passed = self.passed_count(); @@ -252,7 +269,10 @@ impl AuditResult { "{}Test results: {}/{} tests passed ({:.1}%){}", summary_color, passed, total_tests, pass_rate, RESET ); - println!("{}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{}", BOLD, RESET); + println!( + "{}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{}", + BOLD, RESET + ); println!(); } @@ -313,7 +333,10 @@ mod tests { #[test] fn test_parse_spec_lines_range() { assert_eq!(parse_spec_lines("GRASP-01:nostr-relay:7-9"), vec![7, 8, 9]); - assert_eq!(parse_spec_lines("GRASP-01:cors:44-47"), vec![44, 45, 46, 47]); + assert_eq!( + parse_spec_lines("GRASP-01:cors:44-47"), + vec![44, 45, 46, 47] + ); } #[test] @@ -327,4 +350,4 @@ mod tests { assert_eq!(parse_spec_lines("GRASP-01:invalid"), Vec::::new()); assert_eq!(parse_spec_lines("GRASP-01:test:abc"), Vec::::new()); } -} \ No newline at end of file +} 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