upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/grasp-audit/src/client.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-02-25 10:50:59 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-02-25 10:50:59 +0000
commitcd01c7379f23d9189beef840ddc523a3c90a9a10 (patch)
treed1a83d2b3cd8813f3ec586694158be70a026e091 /grasp-audit/src/client.rs
parent7f71a2e75a66bcacad9057f5e339e511e689b828 (diff)
add probe subcommand for end-to-end relay health checks
Implements grasp-audit probe with full write path (publish events, poll for repo init, push, verify refs match state) and read-only fallback (find existing announcement, fetch refs). Supports --nsec for whitelisted relays, --json output, and --watch for continuous monitoring.
Diffstat (limited to 'grasp-audit/src/client.rs')
-rw-r--r--grasp-audit/src/client.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/grasp-audit/src/client.rs b/grasp-audit/src/client.rs
index 5c263ad..e5f2021 100644
--- a/grasp-audit/src/client.rs
+++ b/grasp-audit/src/client.rs
@@ -112,6 +112,73 @@ impl AuditClient {
112 }) 112 })
113 } 113 }
114 114
115 /// Create a new audit client with explicit keys
116 ///
117 /// Identical to [`new()`] but accepts an explicit `Keys` parameter instead of
118 /// generating fresh ones. The maintainer, recursive maintainer, and PR author
119 /// keys are still generated fresh internally.
120 ///
121 /// This is useful for probe mode where the caller wants to use a specific
122 /// identity (e.g., from an `nsec` argument) for all events.
123 pub async fn new_with_keys(relay_url: &str, config: AuditConfig, keys: Keys) -> Result<Self> {
124 let maintainer_keys = Keys::generate();
125 let recursive_maintainer_keys = Keys::generate();
126 let pr_author_keys = Keys::generate();
127 let client = Client::new(keys.clone());
128
129 // Add relay and connect
130 client.add_relay(relay_url).await?;
131 client.connect().await;
132
133 // Wait for connection to establish (with retries)
134 let mut attempts = 0;
135 let mut connected = false;
136 while attempts < 20 {
137 tokio::time::sleep(Duration::from_millis(100)).await;
138
139 let relays = client.relays().await;
140 connected = relays.values().any(|r| r.is_connected());
141
142 if connected {
143 break;
144 }
145
146 attempts += 1;
147 }
148
149 // Verify we actually connected
150 if !connected {
151 return Err(anyhow!(
152 "Failed to connect to relay at '{}'\n\
153 \n\
154 Possible causes:\n\
155 • Relay is not running at this address\n\
156 • Network connectivity issues\n\
157 • Incorrect URL or port\n\
158 \n\
159 To start ngit-relay for testing:\n\
160 docker run --rm -p 18081:8081 ghcr.io/danconwaydev/ngit-relay:latest\n\
161 \n\
162 Or use the test script:\n\
163 cd grasp-audit && ./test-ngit-relay.sh",
164 relay_url
165 ));
166 }
167
168 // Give it a bit more time to stabilize
169 tokio::time::sleep(Duration::from_millis(200)).await;
170
171 Ok(Self {
172 client,
173 config,
174 keys,
175 maintainer_keys,
176 recursive_maintainer_keys,
177 pr_author_keys,
178 fixture_cache: Arc::new(Mutex::new(HashMap::new())),
179 })
180 }
181
115 /// Get the fixture cache for TestContext usage 182 /// Get the fixture cache for TestContext usage
116 /// 183 ///
117 /// This cache is shared across all TestContext instances created from this client. 184 /// This cache is shared across all TestContext instances created from this client.