From 3fd6ce4149d567c67009b0332ca76c0cd6f51055 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 12 Feb 2026 12:36:23 +0000 Subject: refactor(grasp-audit): introduce SpecRef enum for type-safe spec references Replace string-based spec references with typed SpecRef enum for compile-time validation and better IDE support. TestResult::new() now accepts SpecRef enum plus a requirement description string for test-specific context. --- grasp-audit/src/specs/grasp01/git_clone.rs | 43 +++++++++++++++--------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'grasp-audit/src/specs/grasp01/git_clone.rs') diff --git a/grasp-audit/src/specs/grasp01/git_clone.rs b/grasp-audit/src/specs/grasp01/git_clone.rs index e162558..fda472b 100644 --- a/grasp-audit/src/specs/grasp01/git_clone.rs +++ b/grasp-audit/src/specs/grasp01/git_clone.rs @@ -15,6 +15,7 @@ //! cd grasp-audit && nix develop -c bash test-ngit-relay.sh --mode test //! ``` +use crate::specs::grasp01::SpecRef; use crate::{AuditClient, FixtureKind, TestContext, TestResult}; use nostr_sdk::prelude::*; use std::fs; @@ -53,7 +54,7 @@ impl GitCloneTests { Err(e) => { return TestResult::new( test_name, - "GRASP-01:git-http:34", + SpecRef::GitServeRepository, "Repository must be cloneable via Git HTTP backend", ) .fail(format!("Failed to create repo fixture: {}", e)) @@ -74,7 +75,7 @@ impl GitCloneTests { None => { return TestResult::new( test_name, - "GRASP-01", + SpecRef::GitServeRepository, "Repository must be cloneable via Git HTTP backend", ) .fail("Repository announcement missing d tag") @@ -86,7 +87,7 @@ impl GitCloneTests { Err(e) => { return TestResult::new( test_name, - "GRASP-01:git-http:34", + SpecRef::GitServeRepository, "Repository must be cloneable via Git HTTP backend", ) .fail(format!("Failed to convert pubkey to npub: {}", e)) @@ -121,7 +122,7 @@ impl GitCloneTests { cleanup(); return TestResult::new( test_name, - "GRASP-01:git-http:34", + SpecRef::GitServeRepository, "Repository must be cloneable via Git HTTP backend", ) .fail(format!("Failed to execute git clone: {}", e)); @@ -133,7 +134,7 @@ impl GitCloneTests { let stderr = String::from_utf8_lossy(&output.stderr); return TestResult::new( test_name, - "GRASP-01:git-http:34", + SpecRef::GitServeRepository, "Repository must be cloneable via Git HTTP backend", ) .fail(format!("Git clone failed: {}", stderr)); @@ -144,7 +145,7 @@ impl GitCloneTests { cleanup(); return TestResult::new( test_name, - "GRASP-01:git-http:34", + SpecRef::GitServeRepository, "Repository must be cloneable via Git HTTP backend", ) .fail("Cloned repository missing .git directory"); @@ -153,7 +154,7 @@ impl GitCloneTests { cleanup(); TestResult::new( test_name, - "GRASP-01:git-http:34", + SpecRef::GitServeRepository, "Repository must be cloneable via Git HTTP backend", ) .pass() @@ -175,7 +176,7 @@ impl GitCloneTests { Err(e) => { return TestResult::new( test_name, - "GRASP-01:git-http:34", + SpecRef::GitServeRepository, "Clone URL must follow correct format", ) .fail(format!("Failed to create repo fixture: {}", e)) @@ -203,7 +204,7 @@ impl GitCloneTests { if !valid_url.contains(&npub) { return TestResult::new( test_name, - "GRASP-01:git-http:34", + SpecRef::GitServeRepository, "Clone URL must follow correct format", ) .fail("URL missing npub"); @@ -212,7 +213,7 @@ impl GitCloneTests { if !valid_url.contains(&format!("{}.git", repo_id)) { return TestResult::new( test_name, - "GRASP-01:git-http:34", + SpecRef::GitServeRepository, "Clone URL must follow correct format", ) .fail("URL missing repository identifier"); @@ -241,7 +242,7 @@ impl GitCloneTests { if output.status.success() { return TestResult::new( test_name, - "GRASP-01:git-http:34", + SpecRef::GitServeRepository, "Clone URL must follow correct format", ) .fail("Invalid URL was accepted (should have been rejected)"); @@ -249,7 +250,7 @@ impl GitCloneTests { TestResult::new( test_name, - "GRASP-01:git-http:34", + SpecRef::GitServeRepository, "Clone URL must follow correct format", ) .pass() @@ -278,7 +279,7 @@ impl GitCloneTests { Err(e) => { return TestResult::new( test_name, - "GRASP-01:git-http:42", + SpecRef::GitIncludeAllowSha1InWant, "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) .fail(format!("Failed to create repo fixture: {}", e)) @@ -299,7 +300,7 @@ impl GitCloneTests { None => { return TestResult::new( test_name, - "GRASP-01:git-http:42", + SpecRef::GitIncludeAllowSha1InWant, "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) .fail("Repository announcement missing d tag") @@ -311,7 +312,7 @@ impl GitCloneTests { Err(e) => { return TestResult::new( test_name, - "GRASP-01:git-http:42", + SpecRef::GitIncludeAllowSha1InWant, "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) .fail(format!("Failed to convert pubkey to npub: {}", e)) @@ -331,7 +332,7 @@ impl GitCloneTests { Err(e) => { return TestResult::new( test_name, - "GRASP-01:git-http:42", + SpecRef::GitIncludeAllowSha1InWant, "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) .fail(format!("HTTP request failed: {}", e)) @@ -341,7 +342,7 @@ impl GitCloneTests { if !response.status().is_success() { return TestResult::new( test_name, - "GRASP-01:git-http:42", + SpecRef::GitIncludeAllowSha1InWant, "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) .fail(format!( @@ -356,7 +357,7 @@ impl GitCloneTests { Err(e) => { return TestResult::new( test_name, - "GRASP-01:git-http:42", + SpecRef::GitIncludeAllowSha1InWant, "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) .fail(format!("Failed to read response body: {}", e)) @@ -370,7 +371,7 @@ impl GitCloneTests { if !has_allow_reachable { return TestResult::new( test_name, - "GRASP-01:git-http:42", + SpecRef::GitIncludeAllowSha1InWant, "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) .fail("Missing capability: allow-reachable-sha1-in-want"); @@ -379,7 +380,7 @@ impl GitCloneTests { if !has_allow_tip { return TestResult::new( test_name, - "GRASP-01:git-http:42", + SpecRef::GitIncludeAllowSha1InWant, "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) .fail("Missing capability: allow-tip-sha1-in-want"); @@ -387,7 +388,7 @@ impl GitCloneTests { TestResult::new( test_name, - "GRASP-01:git-http:42", + SpecRef::GitIncludeAllowSha1InWant, "MUST include allow-reachable-sha1-in-want and allow-tip-sha1-in-want in advertisement", ) .pass() -- cgit v1.2.3