From d2ac69816567f092fe0d4661723bc43778cb481b Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 1 Dec 2025 14:31:32 +0000 Subject: fix cargo clippy and fmt warnings --- grasp-audit/src/bin/grasp-audit.rs | 16 +++--- grasp-audit/src/lib.rs | 22 +++++--- grasp-audit/src/result.rs | 12 +++-- grasp-audit/src/specs/grasp01/cors.rs | 51 +++++------------- .../src/specs/grasp01/event_acceptance_policy.rs | 62 ++++++++-------------- grasp-audit/src/specs/grasp01/git_clone.rs | 54 +++++++------------ grasp-audit/src/specs/grasp01/mod.rs | 2 +- grasp-audit/src/specs/grasp01/nip01_smoke.rs | 32 +++++------ grasp-audit/src/specs/grasp01/nip11_document.rs | 61 ++++++++++++++------- .../src/specs/grasp01/push_authorization.rs | 10 +--- .../src/specs/grasp01/repository_creation.rs | 20 ++----- 11 files changed, 147 insertions(+), 195 deletions(-) (limited to 'grasp-audit/src') diff --git a/grasp-audit/src/bin/grasp-audit.rs b/grasp-audit/src/bin/grasp-audit.rs index 2aabefe..48c1580 100644 --- a/grasp-audit/src/bin/grasp-audit.rs +++ b/grasp-audit/src/bin/grasp-audit.rs @@ -47,14 +47,18 @@ async fn main() -> Result<()> { let cli = Cli::parse(); match cli.command { - Commands::Audit { relay, mode, spec, git_data_dir } => { - + Commands::Audit { + relay, + mode, + spec, + git_data_dir, + } => { let mut config = match mode.as_str() { "ci" => AuditConfig::ci(), "production" => AuditConfig::production(), _ => return Err(anyhow!("Invalid mode: {}. Use 'ci' or 'production'", mode)), }; - + // Audit needs to create events to test the relay, so disable read-only mode config.read_only = false; @@ -145,17 +149,17 @@ async fn main() -> Result<()> { println!(" → NIP-01 smoke tests..."); let nip01_results = specs::Nip01SmokeTests::run_all(&client).await; all_results.merge(nip01_results); - + // NIP-11 document tests println!(" → NIP-11 document tests..."); let nip11_results = specs::Nip11DocumentTests::run_all(&client).await; all_results.merge(nip11_results); - + // CORS tests println!(" → CORS tests..."); let cors_results = specs::CorsTests::run_all(&client, &relay_domain).await; all_results.merge(cors_results); - + println!(); all_results } diff --git a/grasp-audit/src/lib.rs b/grasp-audit/src/lib.rs index fb52ba7..6df240f 100644 --- a/grasp-audit/src/lib.rs +++ b/grasp-audit/src/lib.rs @@ -39,14 +39,24 @@ pub use audit::{AuditConfig, AuditEventBuilder, AuditMode}; pub use client::AuditClient; pub use fixtures::{ // Git operation helpers - clone_repo, create_commit, create_deterministic_commit, create_deterministic_commit_with_variant, - try_push, try_push_to_ref, + clone_repo, + create_commit, + create_deterministic_commit, + create_deterministic_commit_with_variant, // Verification helpers - send_and_verify_accepted, send_and_verify_rejected, + send_and_verify_accepted, + send_and_verify_rejected, + try_push, + try_push_to_ref, // Types and constants - CommitVariant, ContextMode, FixtureKind, TestContext, - DETERMINISTIC_COMMIT_HASH, MAINTAINER_DETERMINISTIC_COMMIT_HASH, - PR_TEST_COMMIT_HASH, RECURSIVE_MAINTAINER_DETERMINISTIC_COMMIT_HASH, + CommitVariant, + ContextMode, + FixtureKind, + TestContext, + DETERMINISTIC_COMMIT_HASH, + MAINTAINER_DETERMINISTIC_COMMIT_HASH, + PR_TEST_COMMIT_HASH, + RECURSIVE_MAINTAINER_DETERMINISTIC_COMMIT_HASH, }; pub use result::{AuditResult, TestResult}; diff --git a/grasp-audit/src/result.rs b/grasp-audit/src/result.rs index 2bec5c8..bc0008a 100644 --- a/grasp-audit/src/result.rs +++ b/grasp-audit/src/result.rs @@ -17,7 +17,12 @@ fn extract_spec_category(spec_ref: &str) -> String { if parts.len() >= 2 { // Check if the last part looks like a test number (starts with digit) if let Some(last) = parts.last() { - if last.chars().next().map(|c| c.is_ascii_digit()).unwrap_or(false) { + if last + .chars() + .next() + .map(|c| c.is_ascii_digit()) + .unwrap_or(false) + { // Remove the trailing number part return parts[..parts.len() - 1].join(":"); } @@ -146,10 +151,7 @@ impl AuditResult { for result in &self.results { // Extract category from spec_ref (e.g., "GRASP-01:event-acceptance:1.1" -> "GRASP-01:event-acceptance") let category = extract_spec_category(&result.spec_ref); - grouped - .entry(category) - .or_default() - .push(result); + grouped.entry(category).or_default().push(result); } // Print grouped results diff --git a/grasp-audit/src/specs/grasp01/cors.rs b/grasp-audit/src/specs/grasp01/cors.rs index 08c5ab6..c877c04 100644 --- a/grasp-audit/src/specs/grasp01/cors.rs +++ b/grasp-audit/src/specs/grasp01/cors.rs @@ -16,7 +16,6 @@ use crate::{AuditClient, AuditResult, FixtureKind, TestContext, TestResult}; use nostr_sdk::prelude::*; -use std::path::Path; pub struct CorsTests; @@ -42,10 +41,7 @@ impl CorsTests { /// /// Spec: Line 44 of ../grasp/01.md /// Requirement: Set `Access-Control-Allow-Origin: *` on ALL responses - pub async fn test_cors_allow_origin( - _client: &AuditClient, - relay_domain: &str, - ) -> TestResult { + pub async fn test_cors_allow_origin(_client: &AuditClient, relay_domain: &str) -> TestResult { TestResult::new( "cors_allow_origin", "GRASP-01:git-http:cors:44", @@ -91,10 +87,7 @@ impl CorsTests { /// /// Spec: Line 45 of ../grasp/01.md /// Requirement: Set `Access-Control-Allow-Methods: GET, POST` on ALL responses - pub async fn test_cors_allow_methods( - _client: &AuditClient, - relay_domain: &str, - ) -> TestResult { + pub async fn test_cors_allow_methods(_client: &AuditClient, relay_domain: &str) -> TestResult { TestResult::new( "cors_allow_methods", "GRASP-01:git-http:cors:45", @@ -138,10 +131,7 @@ impl CorsTests { /// /// Spec: Line 46 of ../grasp/01.md /// Requirement: Set `Access-Control-Allow-Headers: Content-Type` on ALL responses - pub async fn test_cors_allow_headers( - _client: &AuditClient, - relay_domain: &str, - ) -> TestResult { + pub async fn test_cors_allow_headers(_client: &AuditClient, relay_domain: &str) -> TestResult { TestResult::new( "cors_allow_headers", "GRASP-01:git-http:cors:46", @@ -212,10 +202,8 @@ impl CorsTests { check_options_response(&response, "root endpoint")?; // 2. Test OPTIONS on git-upload-pack endpoint - let repo_url = format!( - "http://{}/npub1test/test.git/git-upload-pack", - relay_domain - ); + let repo_url = + format!("http://{}/npub1test/test.git/git-upload-pack", relay_domain); let response = http_client .request(reqwest::Method::OPTIONS, &repo_url) .header("Origin", "https://example.com") @@ -227,10 +215,7 @@ impl CorsTests { check_options_response(&response, "git-upload-pack endpoint")?; // 3. Test OPTIONS on info/refs endpoint - let refs_url = format!( - "http://{}/npub1test/test.git/info/refs", - relay_domain - ); + let refs_url = format!("http://{}/npub1test/test.git/info/refs", relay_domain); let response = http_client .request(reqwest::Method::OPTIONS, &refs_url) .header("Origin", "https://example.com") @@ -255,10 +240,7 @@ impl CorsTests { /// Integration test: CORS Allow-Origin header with repository creation /// /// For integration tests that want to test against real repositories - pub async fn test_cors_on_real_repo( - client: &AuditClient, - relay_domain: &str, - ) -> TestResult { + pub async fn test_cors_on_real_repo(client: &AuditClient, relay_domain: &str) -> TestResult { let test_name = "test_cors_on_real_repo"; let ctx = TestContext::new(client); @@ -271,7 +253,7 @@ impl CorsTests { "GRASP-01", "CORS headers on real repository endpoint", ) - .fail(&format!("Failed to create repo fixture: {}", e)) + .fail(format!("Failed to create repo fixture: {}", e)) } }; @@ -304,7 +286,7 @@ impl CorsTests { "GRASP-01", "CORS headers on real repository endpoint", ) - .fail(&format!("Failed to convert pubkey to npub: {}", e)) + .fail(format!("Failed to convert pubkey to npub: {}", e)) } }; @@ -323,7 +305,7 @@ impl CorsTests { "GRASP-01", "CORS headers on real repository endpoint", ) - .fail(&format!("Failed to GET info/refs: {}", e)) + .fail(format!("Failed to GET info/refs: {}", e)) } }; @@ -492,15 +474,6 @@ mod tests { results.print_report(); // Assert all tests passed - assert!( - results.all_passed(), - "Some GRASP-01 CORS tests failed" - ); + assert!(results.all_passed(), "Some GRASP-01 CORS tests failed"); } - - #[test] - fn test_module_exists() { - // Simple compilation test - assert!(true); - } -} \ No newline at end of file +} diff --git a/grasp-audit/src/specs/grasp01/event_acceptance_policy.rs b/grasp-audit/src/specs/grasp01/event_acceptance_policy.rs index 3a8f18d..1fc7f73 100644 --- a/grasp-audit/src/specs/grasp01/event_acceptance_policy.rs +++ b/grasp-audit/src/specs/grasp01/event_acceptance_policy.rs @@ -247,7 +247,9 @@ impl EventAcceptancePolicyTests { /// /// Spec: Line 5 of ../grasp/01.md /// Requirement: MUST reject announcements not listing service (unless GRASP-05) - pub async fn test_reject_repo_announcement_missing_clone_tag(client: &AuditClient) -> TestResult { + pub async fn test_reject_repo_announcement_missing_clone_tag( + client: &AuditClient, + ) -> TestResult { TestResult::new( "reject_repo_announcement_missing_clone_tag", "GRASP-01:nostr-relay:5", @@ -321,7 +323,9 @@ impl EventAcceptancePolicyTests { /// /// Spec: Line 5 of ../grasp/01.md /// Requirement: MUST reject announcements not listing service in relays - pub async fn test_reject_repo_announcement_missing_relays_tag(client: &AuditClient) -> TestResult { + pub async fn test_reject_repo_announcement_missing_relays_tag( + client: &AuditClient, + ) -> TestResult { TestResult::new( "reject_repo_announcement_missing_relays_tag", "GRASP-01:nostr-relay:5", @@ -546,8 +550,7 @@ impl EventAcceptancePolicyTests { let issue = Self::create_issue_for_repo(client, &repo, "Test Issue 1")?; // 3. Send issue and verify it's accepted - send_and_verify_accepted(client, issue, "issue referencing repo via 'a' tag") - .await?; + send_and_verify_accepted(client, issue, "issue referencing repo via 'a' tag").await?; Ok(()) }) @@ -693,8 +696,7 @@ impl EventAcceptancePolicyTests { .map_err(|e| format!("Failed to build issue B: {}", e))?; // Send Issue B and verify it's ACCEPTED (via transitive quote to Issue A) - send_and_verify_accepted(client, issue_b, "issue B quoting accepted issue A") - .await?; + send_and_verify_accepted(client, issue_b, "issue B quoting accepted issue A").await?; Ok(()) }) @@ -772,8 +774,7 @@ impl EventAcceptancePolicyTests { .build(client.keys()) .map_err(|e| format!("Failed to build kind1 A: {}", e))?; - send_and_verify_accepted(client, kind1_a.clone(), "kind 1 A quoting repo") - .await?; + send_and_verify_accepted(client, kind1_a.clone(), "kind 1 A quoting repo").await?; // Create Kind 1 B that replies to Kind 1 A via 'e' tag let kind1_b = client @@ -783,12 +784,8 @@ impl EventAcceptancePolicyTests { .map_err(|e| format!("Failed to build kind1 B: {}", e))?; // Send Kind 1 B and verify it's accepted (via 'e' tag to accepted kind 1 A) - send_and_verify_accepted( - client, - kind1_b, - "kind 1 B replying to accepted kind 1 A", - ) - .await?; + send_and_verify_accepted(client, kind1_b, "kind 1 B replying to accepted kind 1 A") + .await?; Ok(()) }) @@ -828,17 +825,19 @@ impl EventAcceptancePolicyTests { .kind(Kind::GitRepoAnnouncement) .author(repo.pubkey) .identifier(repo_id); - + // Poll until repo is available (with timeout) for _ in 0..10 { - let events = client.query(verify_filter.clone()).await + let events = client + .query(verify_filter.clone()) + .await .map_err(|e| format!("Failed to verify repo: {}", e))?; if !events.is_empty() { break; } tokio::time::sleep(Duration::from_millis(50)).await; } - + // Extra delay to ensure relay's internal database is fully synchronized tokio::time::sleep(Duration::from_millis(200)).await; @@ -907,12 +906,7 @@ impl EventAcceptancePolicyTests { let issue = ctx .get_fixture(FixtureKind::RepoWithIssue) .await - .map_err(|e| { - format!( - "Test setup failed: could not get issue fixture: {}", - e - ) - })?; + .map_err(|e| format!("Test setup failed: could not get issue fixture: {}", e))?; // Create Comment A locally but DON'T send it yet let comment_a = Self::create_comment_for_event(client, &issue, "Comment A")?; @@ -997,16 +991,11 @@ impl EventAcceptancePolicyTests { .build(client.keys()) .map_err(|e| format!("Failed to build kind1 B: {}", e))?; - send_and_verify_accepted(client, kind1_b, "kind1 B mentioning unsent kind1 A") - .await?; + send_and_verify_accepted(client, kind1_b, "kind1 B mentioning unsent kind1 A").await?; // NOW send Kind 1 A - should be accepted because accepted Kind 1 B mentions it - send_and_verify_accepted( - client, - kind1_a, - "kind1 A referenced by accepted kind1 B", - ) - .await?; + send_and_verify_accepted(client, kind1_a, "kind1 A referenced by accepted kind1 B") + .await?; Ok(()) }) @@ -1033,12 +1022,8 @@ impl EventAcceptancePolicyTests { Self::create_issue_for_repo(client, &unaccepted_repo, "Orphan Issue")?; // 3. Send issue and verify it's REJECTED - send_and_verify_rejected( - client, - orphan_issue, - "issue referencing unaccepted repo", - ) - .await?; + send_and_verify_rejected(client, orphan_issue, "issue referencing unaccepted repo") + .await?; Ok(()) }) @@ -1060,8 +1045,7 @@ impl EventAcceptancePolicyTests { .map_err(|e| format!("Failed to build note: {}", e))?; // 2. Send note and verify it's REJECTED - send_and_verify_rejected(client, orphan_note, "kind 1 with no repo references") - .await?; + send_and_verify_rejected(client, orphan_note, "kind 1 with no repo references").await?; Ok(()) }) diff --git a/grasp-audit/src/specs/grasp01/git_clone.rs b/grasp-audit/src/specs/grasp01/git_clone.rs index 9ee6ed7..95338e4 100644 --- a/grasp-audit/src/specs/grasp01/git_clone.rs +++ b/grasp-audit/src/specs/grasp01/git_clone.rs @@ -25,10 +25,7 @@ pub struct GitCloneTests; impl GitCloneTests { /// Run all Git clone tests - pub async fn run_all( - client: &AuditClient, - relay_domain: &str, - ) -> crate::AuditResult { + pub async fn run_all(client: &AuditClient, relay_domain: &str) -> crate::AuditResult { let mut results = crate::AuditResult::new("GRASP-01 Git Clone Tests"); results.add(Self::test_basic_git_clone(client, relay_domain).await); @@ -45,10 +42,7 @@ impl GitCloneTests { /// 2. Waits for repository creation /// 3. Attempts to clone the repository using git clone /// 4. Verifies the clone succeeded - pub async fn test_basic_git_clone( - client: &AuditClient, - relay_domain: &str, - ) -> TestResult { + pub async fn test_basic_git_clone(client: &AuditClient, relay_domain: &str) -> TestResult { let test_name = "test_basic_git_clone"; let ctx = TestContext::new(client); @@ -61,7 +55,7 @@ impl GitCloneTests { "GRASP-01", "Repository must be cloneable via Git HTTP backend", ) - .fail(&format!("Failed to create repo fixture: {}", e)) + .fail(format!("Failed to create repo fixture: {}", e)) } }; @@ -94,7 +88,7 @@ impl GitCloneTests { "GRASP-01", "Repository must be cloneable via Git HTTP backend", ) - .fail(&format!("Failed to convert pubkey to npub: {}", e)) + .fail(format!("Failed to convert pubkey to npub: {}", e)) } }; @@ -102,7 +96,7 @@ impl GitCloneTests { let temp_base = std::env::temp_dir(); let clone_dir_name = format!("grasp-test-clone-{}", uuid::Uuid::new_v4()); let clone_path = temp_base.join(&clone_dir_name); - + // Ensure clean state let _ = fs::remove_dir_all(&clone_path); @@ -114,7 +108,7 @@ impl GitCloneTests { .args(["clone", &clone_url, clone_path.to_str().unwrap()]) .env("GIT_TERMINAL_PROMPT", "0") // Disable password prompts .output(); - + // Clean up on success or failure let cleanup = || { let _ = fs::remove_dir_all(&clone_path); @@ -129,7 +123,7 @@ impl GitCloneTests { "GRASP-01", "Repository must be cloneable via Git HTTP backend", ) - .fail(&format!("Failed to execute git clone: {}", e)) + .fail(format!("Failed to execute git clone: {}", e)); } }; @@ -141,7 +135,7 @@ impl GitCloneTests { "GRASP-01", "Repository must be cloneable via Git HTTP backend", ) - .fail(&format!("Git clone failed: {}", stderr)); + .fail(format!("Git clone failed: {}", stderr)); } // Verify clone succeeded by checking for .git directory @@ -169,10 +163,7 @@ impl GitCloneTests { /// This test verifies: /// 1. URLs follow the pattern http://domain/npub/identifier.git /// 2. Invalid URLs are rejected properly - pub async fn test_clone_url_format( - client: &AuditClient, - relay_domain: &str, - ) -> TestResult { + pub async fn test_clone_url_format(client: &AuditClient, relay_domain: &str) -> TestResult { let test_name = "test_clone_url_format"; let ctx = TestContext::new(client); @@ -185,7 +176,7 @@ impl GitCloneTests { "GRASP-01", "Clone URL must follow correct format", ) - .fail(&format!("Failed to create repo fixture: {}", e)) + .fail(format!("Failed to create repo fixture: {}", e)) } }; @@ -205,7 +196,7 @@ impl GitCloneTests { // Test valid URL format let valid_url = format!("http://{}/{}/{}.git", relay_domain, npub, repo_id); - + // Verify URL contains expected components if !valid_url.contains(&npub) { return TestResult::new( @@ -229,10 +220,10 @@ impl GitCloneTests { let temp_base = std::env::temp_dir(); let clone_dir_name = format!("grasp-test-invalid-{}", uuid::Uuid::new_v4()); let clone_path = temp_base.join(&clone_dir_name); - + // Ensure clean state let _ = fs::remove_dir_all(&clone_path); - + let invalid_url = format!("http://{}/invalid/path", relay_domain); let output = Command::new("git") @@ -287,7 +278,7 @@ impl GitCloneTests { "GRASP-01", "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) - .fail(&format!("Failed to create repo fixture: {}", e)) + .fail(format!("Failed to create repo fixture: {}", e)) } }; @@ -320,7 +311,7 @@ impl GitCloneTests { "GRASP-01", "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) - .fail(&format!("Failed to convert pubkey to npub: {}", e)) + .fail(format!("Failed to convert pubkey to npub: {}", e)) } }; @@ -340,7 +331,7 @@ impl GitCloneTests { "GRASP-01", "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) - .fail(&format!("HTTP request failed: {}", e)) + .fail(format!("HTTP request failed: {}", e)) } }; @@ -350,7 +341,7 @@ impl GitCloneTests { "GRASP-01", "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) - .fail(&format!( + .fail(format!( "info/refs request failed with status: {}", response.status() )); @@ -365,7 +356,7 @@ impl GitCloneTests { "GRASP-01", "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) - .fail(&format!("Failed to read response body: {}", e)) + .fail(format!("Failed to read response body: {}", e)) } }; @@ -399,12 +390,3 @@ impl GitCloneTests { .pass() } } - -#[cfg(test)] -mod tests { - #[test] - fn test_module_exists() { - // Simple compilation test - assert!(true); - } -} \ 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 6f58b96..e16a351 100644 --- a/grasp-audit/src/specs/grasp01/mod.rs +++ b/grasp-audit/src/specs/grasp01/mod.rs @@ -26,4 +26,4 @@ pub use git_clone::GitCloneTests; pub use nip01_smoke::Nip01SmokeTests; pub use nip11_document::Nip11DocumentTests; pub use push_authorization::PushAuthorizationTests; -pub use repository_creation::{RepositoryCreationTests}; +pub use repository_creation::RepositoryCreationTests; diff --git a/grasp-audit/src/specs/grasp01/nip01_smoke.rs b/grasp-audit/src/specs/grasp01/nip01_smoke.rs index b16d61a..5161da8 100644 --- a/grasp-audit/src/specs/grasp01/nip01_smoke.rs +++ b/grasp-audit/src/specs/grasp01/nip01_smoke.rs @@ -163,27 +163,23 @@ 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", - "NIP-01", - "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", "NIP-01", "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/nip11_document.rs b/grasp-audit/src/specs/grasp01/nip11_document.rs index bb864f2..51b147d 100644 --- a/grasp-audit/src/specs/grasp01/nip11_document.rs +++ b/grasp-audit/src/specs/grasp01/nip11_document.rs @@ -42,7 +42,9 @@ impl Nip11DocumentTests { ) .run(|| async { // 1. Extract HTTP(S) URL from client's WebSocket URL - let ws_url = client.relay_url().await + let ws_url = client + .relay_url() + .await .map_err(|e| format!("Failed to get relay URL: {}", e))?; let http_url = AuditClient::ws_to_http_url(&ws_url) .map_err(|e| format!("Failed to convert WebSocket URL to HTTP: {}", e))?; @@ -66,16 +68,18 @@ impl Nip11DocumentTests { } // 4. Verify response is valid JSON - let json_text = response.text().await + let json_text = response + .text() + .await .map_err(|e| format!("Failed to read response body: {}", e))?; - + let doc: serde_json::Value = serde_json::from_str(&json_text) .map_err(|e| format!("Response is not valid JSON: {}", e))?; // 5. Verify has required NIP-11 fields let required_fields = ["name", "description", "software", "version"]; for field in &required_fields { - if !doc.get(field).is_some() { + if doc.get(field).is_none() { return Err(format!("Missing required NIP-11 field: {}", field)); } } @@ -97,7 +101,9 @@ impl Nip11DocumentTests { ) .run(|| async { // 1. Fetch NIP-11 document - let ws_url = client.relay_url().await + let ws_url = client + .relay_url() + .await .map_err(|e| format!("Failed to get relay URL: {}", e))?; let http_url = AuditClient::ws_to_http_url(&ws_url) .map_err(|e| format!("Failed to convert WebSocket URL to HTTP: {}", e))?; @@ -110,18 +116,22 @@ impl Nip11DocumentTests { .await .map_err(|e| format!("Failed to fetch NIP-11 document: {}", e))?; - let json_text = response.text().await + let json_text = response + .text() + .await .map_err(|e| format!("Failed to read response body: {}", e))?; - + let doc: serde_json::Value = serde_json::from_str(&json_text) .map_err(|e| format!("Response is not valid JSON: {}", e))?; // 2. Verify `supported_grasps` field exists - let supported_grasps = doc.get("supported_grasps") + let supported_grasps = doc + .get("supported_grasps") .ok_or_else(|| "Missing required field: supported_grasps".to_string())?; // 3. Verify it's a JSON array - let grasps_array = supported_grasps.as_array() + let grasps_array = supported_grasps + .as_array() .ok_or_else(|| "supported_grasps must be an array".to_string())?; // 4. Verify array includes "GRASP-01" @@ -140,7 +150,7 @@ impl Nip11DocumentTests { // 5. Verify format: each entry should match pattern "GRASP-\d{2}" let grasp_pattern = regex::Regex::new(r"^GRASP-\d{2}$") .map_err(|e| format!("Failed to compile regex: {}", e))?; - + for grasp in &grasp_strings { if !grasp_pattern.is_match(grasp) { return Err(format!( @@ -167,7 +177,9 @@ impl Nip11DocumentTests { ) .run(|| async { // 1. Fetch NIP-11 document - let ws_url = client.relay_url().await + let ws_url = client + .relay_url() + .await .map_err(|e| format!("Failed to get relay URL: {}", e))?; let http_url = AuditClient::ws_to_http_url(&ws_url) .map_err(|e| format!("Failed to convert WebSocket URL to HTTP: {}", e))?; @@ -180,18 +192,22 @@ impl Nip11DocumentTests { .await .map_err(|e| format!("Failed to fetch NIP-11 document: {}", e))?; - let json_text = response.text().await + let json_text = response + .text() + .await .map_err(|e| format!("Failed to read response body: {}", e))?; - + let doc: serde_json::Value = serde_json::from_str(&json_text) .map_err(|e| format!("Response is not valid JSON: {}", e))?; // 2. Verify `repo_acceptance_criteria` field exists - let criteria = doc.get("repo_acceptance_criteria") + let criteria = doc + .get("repo_acceptance_criteria") .ok_or_else(|| "Missing required field: repo_acceptance_criteria".to_string())?; // 3. Verify it's a string - let criteria_str = criteria.as_str() + let criteria_str = criteria + .as_str() .ok_or_else(|| "repo_acceptance_criteria must be a string".to_string())?; // 4. Verify non-empty @@ -216,7 +232,9 @@ impl Nip11DocumentTests { ) .run(|| async { // 1. Fetch NIP-11 document - let ws_url = client.relay_url().await + let ws_url = client + .relay_url() + .await .map_err(|e| format!("Failed to get relay URL: {}", e))?; let http_url = AuditClient::ws_to_http_url(&ws_url) .map_err(|e| format!("Failed to convert WebSocket URL to HTTP: {}", e))?; @@ -229,16 +247,19 @@ impl Nip11DocumentTests { .await .map_err(|e| format!("Failed to fetch NIP-11 document: {}", e))?; - let json_text = response.text().await + let json_text = response + .text() + .await .map_err(|e| format!("Failed to read response body: {}", e))?; - + let doc: serde_json::Value = serde_json::from_str(&json_text) .map_err(|e| format!("Response is not valid JSON: {}", e))?; // 2. Check if `curation` field exists if let Some(curation) = doc.get("curation") { // 3. If present: verify it's a non-empty string - let curation_str = curation.as_str() + let curation_str = curation + .as_str() .ok_or_else(|| "curation field must be a string when present".to_string())?; if curation_str.trim().is_empty() { @@ -284,4 +305,4 @@ mod tests { // Don't assert all passed yet - tests not implemented // assert!(results.all_passed(), "Some GRASP-01 NIP-11 document tests failed"); } -} \ No newline at end of file +} diff --git a/grasp-audit/src/specs/grasp01/push_authorization.rs b/grasp-audit/src/specs/grasp01/push_authorization.rs index d8652ae..24eae1d 100644 --- a/grasp-audit/src/specs/grasp01/push_authorization.rs +++ b/grasp-audit/src/specs/grasp01/push_authorization.rs @@ -351,10 +351,7 @@ async fn setup_repo_with_wrong_commit_pushed( /// IMPORTANT: We must publish the EXACT same event that was used during setup, /// otherwise the event ID won't match the refs/nostr/ ref that was pushed. #[allow(dead_code)] -async fn publish_pr_event_and_wait( - ctx: &TestContext<'_>, - pr_event: &Event, -) -> Result<(), String> { +async fn publish_pr_event_and_wait(ctx: &TestContext<'_>, pr_event: &Event) -> Result<(), String> { // Publish the exact same PR event that was created during setup ctx.client() .send_event(pr_event.clone()) @@ -1892,11 +1889,6 @@ impl PushAuthorizationTests { mod tests { use super::*; - #[test] - fn test_module_exists() { - assert!(true); - } - /// Test to discover the PR test commit hash /// /// This test creates a deterministic commit with PR-specific parameters diff --git a/grasp-audit/src/specs/grasp01/repository_creation.rs b/grasp-audit/src/specs/grasp01/repository_creation.rs index 63b3dee..0b3eed5 100644 --- a/grasp-audit/src/specs/grasp01/repository_creation.rs +++ b/grasp-audit/src/specs/grasp01/repository_creation.rs @@ -23,10 +23,7 @@ pub struct RepositoryCreationTests; impl RepositoryCreationTests { /// Run all repository creation tests - pub async fn run_all( - client: &AuditClient, - relay_domain: &str, - ) -> crate::AuditResult { + pub async fn run_all(client: &AuditClient, relay_domain: &str) -> crate::AuditResult { let mut results = crate::AuditResult::new("GRASP-01 Repository Creation Tests"); results.add(Self::test_bare_repo_created_on_announcement(client, relay_domain).await); @@ -58,7 +55,7 @@ impl RepositoryCreationTests { "GRASP-01", "Bare repository must be created and accessible via Smart HTTP when announcement is accepted", ) - .fail(&format!("Failed to create repo fixture: {}", e)) + .fail(format!("Failed to create repo fixture: {}", e)) } }; @@ -91,7 +88,7 @@ impl RepositoryCreationTests { "GRASP-01", "Bare repository must be created and accessible via Smart HTTP when announcement is accepted", ) - .fail(&format!("Failed to convert pubkey to npub: {}", e)) + .fail(format!("Failed to convert pubkey to npub: {}", e)) } }; @@ -102,7 +99,7 @@ impl RepositoryCreationTests { "GRASP-01", "Bare repository must be created and accessible via Smart HTTP when announcement is accepted", ) - .fail(&format!("Repository not accessible via HTTP: {}", e)); + .fail(format!("Repository not accessible via HTTP: {}", e)); } TestResult::new( @@ -159,12 +156,3 @@ async fn check_repo_accessible_via_http( Ok(()) } - -#[cfg(test)] -mod tests { - #[test] - fn test_module_exists() { - // Simple compilation test - assert!(true); - } -} -- cgit v1.2.3