Files
ngit-grasp/grasp-audit/examples/simple_audit.rs
T
DanConwayDev 72683beea0 refactor: rename AuditMode variants and change CLI default to shared
Breaking change: Renamed AuditMode enum variants for clarity:
- AuditMode::CI -> AuditMode::Isolated (fresh fixtures per test)
- AuditMode::Production -> AuditMode::Shared (reuse fixtures across tests)

Config constructors renamed (with deprecated aliases):
- AuditConfig::ci() -> AuditConfig::isolated()
- AuditConfig::production() -> AuditConfig::shared()

CLI default changed from 'ci' to 'shared' mode, which enables
fixture caching across tests. This fixes the issue where fixtures
were being re-created for every test in CLI mode.

Fixture caching behavior:
- Shared mode (CLI default): Uses client's cache, fixtures reused
- Isolated mode (for cargo test): Local cache per TestContext
2025-12-02 21:20:17 +00:00

54 lines
1.4 KiB
Rust

//! Simple audit example
//!
//! Run with: cargo run --example simple_audit
use grasp_audit::*;
#[tokio::main]
async fn main() -> Result<()> {
// Create audit config with shared fixtures (default for CLI)
let config = AuditConfig::shared();
println!("GRASP Audit Example");
println!("==================");
println!("Audit Run ID: {}", config.run_id);
println!();
// Connect to relay
println!("Connecting to relay at ws://localhost:7000...");
let client = match AuditClient::new("ws://localhost:7000", config).await {
Ok(c) => c,
Err(e) => {
eprintln!("Failed to connect: {}", e);
eprintln!();
eprintln!("Make sure a Nostr relay is running at ws://localhost:7000");
eprintln!("You can use: https://github.com/rust-nostr/nostr/tree/master/crates/nostr-relay-builder");
return Err(e);
}
};
if !client.is_connected().await {
eprintln!("Not connected to relay");
return Err(anyhow!("Connection failed"));
}
println!("✓ Connected");
println!();
// Run NIP-01 smoke tests
println!("Running NIP-01 smoke tests...");
println!();
let results = specs::Nip01SmokeTests::run_all(&client).await;
// Print results
results.print_report();
// Exit with error if tests failed
if !results.all_passed() {
std::process::exit(1);
}
Ok(())
}