From e30dfd5e5abb96cdc89b80f1d085466e55c347e0 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 3 Dec 2025 11:38:07 +0000 Subject: remove depricated audit mode label ci / production ~> isolated / shared --- docs/learnings/grasp-audit.md | 46 ++++++++++++++++++++++++++------------ grasp-audit/QUICK_START.md | 16 ++++++++----- grasp-audit/src/audit.rs | 12 ---------- grasp-audit/src/bin/grasp-audit.rs | 12 ++++++---- tests/cors.rs | 2 +- tests/git_clone.rs | 2 +- tests/nip01_compliance.rs | 6 ++--- tests/nip11_document.rs | 2 +- tests/nip34_announcements.rs | 2 +- tests/push_authorization.rs | 2 +- tests/repository_creation.rs | 2 +- 11 files changed, 60 insertions(+), 44 deletions(-) diff --git a/docs/learnings/grasp-audit.md b/docs/learnings/grasp-audit.md index 531ebda..14e5a2b 100644 --- a/docs/learnings/grasp-audit.md +++ b/docs/learnings/grasp-audit.md @@ -18,6 +18,7 @@ **Decision:** Build `grasp-audit` as a separate crate from `ngit-grasp` **Why:** + 1. **Parallel Development**: Can build tests before implementation 2. **Isolated Testing**: Tests run in isolation (CI/CD safe) 3. **Production Auditing**: Can audit live production services @@ -43,6 +44,7 @@ ``` **Benefits:** + - ✅ **Queryable**: Can find all audit events via tag filter - ✅ **Isolated**: Each test run has unique run ID - ✅ **Self-cleaning**: Cleanup timestamp indicates when to delete @@ -56,10 +58,12 @@ ### Standard "t" Tags vs Custom Tags **Evolution:** + 1. **Original**: Custom single-letter tags (`g`, `r`, `c`) 2. **Current**: Standard NIP-01 "t" tags with prefixed values **Why we changed:** + - ❌ Custom tags could conflict with other systems - ✅ "t" tag is standard for categorization/topics - ✅ Multiple "t" tags are expected and supported @@ -78,17 +82,18 @@ use grasp_audit::audit::AuditConfig; // CI mode - isolated test runs -let config = AuditConfig::ci(); +let config = AuditConfig::isolated(); // Generates UUID run ID: "ci-{uuid}" // Cleanup after 1 hour // Production mode - persistent run ID -let config = AuditConfig::production("prod-server-1"); +let config = AuditConfig::shared(); // Uses provided run ID // Cleanup after 24 hours ``` **When to use:** + - **CI mode**: Automated testing, parallel runs, temporary - **Production mode**: Manual audits, monitoring, persistent @@ -100,7 +105,7 @@ let config = AuditConfig::production("prod-server-1"); use grasp_audit::audit::{AuditConfig, AuditEventBuilder}; use nostr_sdk::prelude::*; -let config = AuditConfig::ci(); +let config = AuditConfig::isolated(); let keys = Keys::generate(); // Create audit event @@ -121,7 +126,7 @@ let event = AuditEventBuilder::new(&config, Kind::TextNote, "test content") use grasp_audit::client::AuditClient; use grasp_audit::audit::AuditConfig; -let config = AuditConfig::ci(); +let config = AuditConfig::isolated(); let client = AuditClient::new(config, keys); // Connect to relay @@ -144,14 +149,15 @@ let events = client.query().await?; ```rust // CI mode generates unique UUID per run -let config1 = AuditConfig::ci(); -let config2 = AuditConfig::ci(); +let config1 = AuditConfig::isolated(); +let config2 = AuditConfig::isolated(); // config1.run_id != config2.run_id // Tests won't interfere with each other ``` **Benefits:** + - ✅ Parallel CI/CD runs don't conflict - ✅ Can run multiple test suites simultaneously - ✅ Easy to identify which run created which events @@ -194,18 +200,20 @@ grasp-audit/src/specs/ ### Unit vs Integration Tests **Unit Tests** (no relay required): + ```rust #[cfg(test)] mod tests { #[test] fn test_audit_config() { - let config = AuditConfig::ci(); + let config = AuditConfig::isolated(); assert!(config.run_id.starts_with("ci-")); } } ``` **Integration Tests** (relay required): + ```rust #[cfg(test)] mod tests { @@ -218,6 +226,7 @@ mod tests { ``` **Running tests:** + ```bash # Unit tests (fast, no dependencies) cargo test --lib @@ -248,7 +257,7 @@ for result in &results { // Summary let passed = results.iter().filter(|r| r.is_pass()).count(); let total = results.len(); -println!("Results: {}/{} passed ({:.1}%)", +println!("Results: {}/{} passed ({:.1}%)", passed, total, (passed as f64 / total as f64) * 100.0); ``` @@ -300,6 +309,7 @@ grasp-audit audit --relay ws://localhost:7000 **Impact:** Events created with old tags won't be found by new queries. **Mitigation:** + - ✅ Accept breaking changes in alpha stage - ✅ Document migration clearly - ✅ Old events auto-expire via cleanup @@ -316,6 +326,7 @@ grasp-audit audit --relay ws://localhost:7000 **Solution:** Built-in cleanup strategy from day one. **Implementation:** + - Every event has cleanup timestamp - Relay can cleanup expired events - No deletion event pollution (direct DB cleanup) @@ -329,9 +340,10 @@ grasp-audit audit --relay ws://localhost:7000 **Benefit:** CI/CD can run multiple test suites simultaneously. **Pattern:** + ```rust // Each CI run gets unique ID -let config = AuditConfig::ci(); +let config = AuditConfig::isolated(); // run_id = "ci-{uuid}" // Tests isolated by run ID @@ -346,6 +358,7 @@ let events = client.query().await?; **Lesson:** Using standard NIP-01 "t" tags instead of custom tags. **Benefits:** + - ✅ No conflicts with other systems - ✅ Standard relay filtering works - ✅ Better interoperability @@ -382,11 +395,13 @@ let events = client.query().await?; **Symptoms:** Tests timeout or fail to connect **Causes:** + 1. No relay running 2. Wrong relay URL 3. Firewall blocking connection **Solution:** + ```bash # Start relay docker run --rm -p 7000:7000 scsibug/nostr-rs-relay @@ -405,14 +420,16 @@ cargo test -- --ignored **Symptoms:** Query returns empty even though events were sent **Causes:** + 1. Wrong run ID (querying different run) 2. Connection timing (query before event propagated) 3. Tag mismatch (uppercase vs lowercase) **Solution:** + ```rust // Use same config for send and query -let config = AuditConfig::ci(); +let config = AuditConfig::isolated(); // Wait for event to propagate tokio::time::sleep(Duration::from_millis(500)).await; @@ -430,6 +447,7 @@ let t_tag = SingleLetterTag::lowercase(Alphabet::T); // Lowercase! **Cause:** Not in Nix dev environment **Solution:** + ```bash # Enter Nix environment first cd grasp-audit @@ -447,10 +465,10 @@ cargo build ```rust // CI mode -let config = AuditConfig::ci(); +let config = AuditConfig::isolated(); // Production mode -let config = AuditConfig::production("run-id"); +let config = AuditConfig::shared(); ``` ### Event Creation @@ -494,5 +512,5 @@ cargo run -- audit --relay ws://localhost:7000 --- -*Last updated: November 4, 2025* -*Status: Living document - update as grasp-audit evolves* +_Last updated: November 4, 2025_ +_Status: Living document - update as grasp-audit evolves_ diff --git a/grasp-audit/QUICK_START.md b/grasp-audit/QUICK_START.md index d4ee494..cb6d8a7 100644 --- a/grasp-audit/QUICK_START.md +++ b/grasp-audit/QUICK_START.md @@ -108,21 +108,21 @@ use grasp_audit::*; #[tokio::main] async fn main() -> Result<()> { // Create audit client - let config = AuditConfig::ci(); + let config = AuditConfig::isolated(); let client = AuditClient::new("ws://localhost:7000", config).await?; - + // Run smoke tests let results = specs::Nip01SmokeTests::run_all(&client).await; - + // Print results results.print_report(); - + // Check if passed if !results.all_passed() { eprintln!("Some tests failed!"); std::process::exit(1); } - + Ok(()) } ``` @@ -134,17 +134,20 @@ async fn main() -> Result<()> { **Error:** `linker 'cc' not found` **Solution (NixOS):** + ```bash nix develop # Use the provided flake.nix ``` **Solution (Other Linux):** + ```bash sudo apt-get install build-essential # Debian/Ubuntu sudo yum install gcc # RedHat/CentOS ``` **Solution (macOS):** + ```bash xcode-select --install ``` @@ -154,6 +157,7 @@ xcode-select --install **Error:** `Failed to connect to relay` **Solutions:** + 1. Make sure a relay is running at the specified URL 2. Check firewall settings 3. Try a different relay URL @@ -164,6 +168,7 @@ xcode-select --install **Error:** Tests fail with timeout **Solutions:** + 1. Increase timeout in test code 2. Check relay is responding (try with `websocat`) 3. Check network connectivity @@ -216,6 +221,7 @@ xcode-select --install ## Support For issues or questions: + 1. Check the documentation in this directory 2. Review the examples 3. Check the test code for usage patterns diff --git a/grasp-audit/src/audit.rs b/grasp-audit/src/audit.rs index 713c948..0a4df42 100644 --- a/grasp-audit/src/audit.rs +++ b/grasp-audit/src/audit.rs @@ -68,18 +68,6 @@ impl AuditConfig { } } - /// Alias for isolated() - for backwards compatibility - #[deprecated(since = "0.2.0", note = "Use isolated() instead")] - pub fn ci() -> Self { - Self::isolated() - } - - /// Alias for shared() - for backwards compatibility - #[deprecated(since = "0.2.0", note = "Use shared() instead")] - pub fn production() -> Self { - Self::shared() - } - /// Create config with custom run ID pub fn with_run_id(run_id: String, mode: AuditMode) -> Self { Self { diff --git a/grasp-audit/src/bin/grasp-audit.rs b/grasp-audit/src/bin/grasp-audit.rs index 0d88bce..08a92c7 100644 --- a/grasp-audit/src/bin/grasp-audit.rs +++ b/grasp-audit/src/bin/grasp-audit.rs @@ -56,14 +56,18 @@ async fn main() -> Result<()> { spec, git_data_dir, } => { - #[allow(deprecated)] let mut config = match mode.as_str() { "shared" => AuditConfig::shared(), "isolated" => AuditConfig::isolated(), // Backwards compatibility aliases - "ci" => AuditConfig::ci(), - "production" => AuditConfig::production(), - _ => return Err(anyhow!("Invalid mode: {}. Use 'shared' or 'isolated'", mode)), + "ci" => AuditConfig::isolated(), + "production" => AuditConfig::shared(), + _ => { + return Err(anyhow!( + "Invalid mode: {}. Use 'shared' or 'isolated'", + mode + )) + } }; // Audit needs to create events to test the relay, so disable read-only mode diff --git a/tests/cors.rs b/tests/cors.rs index b5a0a87..a4e92bc 100644 --- a/tests/cors.rs +++ b/tests/cors.rs @@ -36,7 +36,7 @@ macro_rules! isolated_cors_test { #[tokio::test] async fn $test_name() { let relay = TestRelay::start().await; - let config = AuditConfig::ci(); + let config = AuditConfig::isolated(); let client = AuditClient::new(relay.url(), config) .await .expect("Failed to create audit client"); diff --git a/tests/git_clone.rs b/tests/git_clone.rs index c8a91a2..a6d810b 100644 --- a/tests/git_clone.rs +++ b/tests/git_clone.rs @@ -37,7 +37,7 @@ macro_rules! isolated_test { #[tokio::test] async fn $test_name() { let relay = TestRelay::start().await; - let config = AuditConfig::ci(); + let config = AuditConfig::isolated(); let client = AuditClient::new(relay.url(), config) .await .expect("Failed to create audit client"); diff --git a/tests/nip01_compliance.rs b/tests/nip01_compliance.rs index 6fb721a..045bddb 100644 --- a/tests/nip01_compliance.rs +++ b/tests/nip01_compliance.rs @@ -36,7 +36,7 @@ macro_rules! isolated_test { #[tokio::test] async fn $test_name() { let relay = TestRelay::start().await; - let config = AuditConfig::ci(); + let config = AuditConfig::isolated(); let client = AuditClient::new(relay.url(), config) .await .expect("Failed to create audit client"); @@ -73,7 +73,7 @@ async fn test_relay_lifecycle() { let url = relay.url().to_string(); // Verify we can connect - let config = AuditConfig::ci(); + let config = AuditConfig::isolated(); let client = AuditClient::new(&url, config) .await .expect("Failed to connect to relay"); @@ -101,7 +101,7 @@ async fn test_parallel_relays() { ); // Both should be connectable - let config = AuditConfig::ci(); + let config = AuditConfig::isolated(); let client1 = AuditClient::new(relay1.url(), config.clone()) .await diff --git a/tests/nip11_document.rs b/tests/nip11_document.rs index 2104ad0..147bb26 100644 --- a/tests/nip11_document.rs +++ b/tests/nip11_document.rs @@ -36,7 +36,7 @@ macro_rules! isolated_test { #[tokio::test] async fn $test_name() { let relay = TestRelay::start().await; - let config = AuditConfig::ci(); + let config = AuditConfig::isolated(); let client = AuditClient::new(relay.url(), config) .await .expect("Failed to create audit client"); diff --git a/tests/nip34_announcements.rs b/tests/nip34_announcements.rs index 2a83886..aa623d3 100644 --- a/tests/nip34_announcements.rs +++ b/tests/nip34_announcements.rs @@ -36,7 +36,7 @@ macro_rules! isolated_test { #[tokio::test] async fn $test_name() { let relay = TestRelay::start().await; - let config = AuditConfig::ci(); + let config = AuditConfig::isolated(); let client = AuditClient::new(relay.url(), config) .await .expect("Failed to create audit client"); diff --git a/tests/push_authorization.rs b/tests/push_authorization.rs index b9e0545..df291d5 100644 --- a/tests/push_authorization.rs +++ b/tests/push_authorization.rs @@ -38,7 +38,7 @@ macro_rules! isolated_push_test { #[tokio::test] async fn $test_name() { let relay = TestRelay::start().await; - let config = AuditConfig::ci(); + let config = AuditConfig::isolated(); let client = AuditClient::new(relay.url(), config) .await .expect("Failed to create audit client"); diff --git a/tests/repository_creation.rs b/tests/repository_creation.rs index 352e2cc..a1cca11 100644 --- a/tests/repository_creation.rs +++ b/tests/repository_creation.rs @@ -38,7 +38,7 @@ macro_rules! isolated_test { #[tokio::test] async fn $test_name() { let relay = TestRelay::start().await; - let config = AuditConfig::ci(); + let config = AuditConfig::isolated(); let client = AuditClient::new(relay.url(), config) .await .expect("Failed to create audit client"); -- cgit v1.2.3