mirror of
https://relay.ngit.dev/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit-grasp.git
synced 2026-10-05 15:08:24 +00:00
remove depricated audit mode label ci / production ~> isolated / shared
This commit is contained in:
@@ -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_
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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");
|
||||
|
||||
+1
-1
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user