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/specs/grasp01/nip11_document.rs | 61 +++++++++++++++++-------- 1 file changed, 41 insertions(+), 20 deletions(-) (limited to 'grasp-audit/src/specs/grasp01/nip11_document.rs') 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 +} -- cgit v1.2.3