diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-12 12:57:44 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-12 12:57:44 +0000 |
| commit | dcaaa0c44c46f963929ab0baa91f63759ec702dc (patch) | |
| tree | 1808621ff43eb01acaabe091033672d347bfbf67 /grasp-audit/src/client.rs | |
| parent | 3fd6ce4149d567c67009b0332ca76c0cd6f51055 (diff) | |
refactor(grasp-audit): split ValidRepo into Sent/Served, add tolerant purgatory
- Rename ValidRepo to ValidRepoSent (announcement sent, may be in purgatory)
- Add ValidRepoServed (announcement queryable after git data pushed)
- Add send_event_and_note_purgatory() for tolerant purgatory detection
- Update fixtures to use tolerant method instead of strict assertion
- Update event_acceptance_policy tests to use ValidRepoServed
This enables tests to pass regardless of purgatory implementation status
while still having explicit purgatory tests that verify the behavior.
Diffstat (limited to 'grasp-audit/src/client.rs')
| -rw-r--r-- | grasp-audit/src/client.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/grasp-audit/src/client.rs b/grasp-audit/src/client.rs index 91a93dc..5c263ad 100644 --- a/grasp-audit/src/client.rs +++ b/grasp-audit/src/client.rs | |||
| @@ -209,6 +209,36 @@ impl AuditClient { | |||
| 209 | Ok(event_id) | 209 | Ok(event_id) |
| 210 | } | 210 | } |
| 211 | 211 | ||
| 212 | /// Send event and note whether it entered purgatory (not served) or was served immediately. | ||
| 213 | /// | ||
| 214 | /// This is a tolerant version of `send_event_expect_purgatory_not_served` that doesn't | ||
| 215 | /// fail if purgatory is not observed. It returns whether purgatory was observed so | ||
| 216 | /// fixtures can proceed regardless of relay implementation status. | ||
| 217 | /// | ||
| 218 | /// Returns (EventId, bool) where bool = true if event was NOT served (purgatory observed). | ||
| 219 | pub async fn send_event_and_note_purgatory(&self, event: Event) -> Result<(EventId, bool)> { | ||
| 220 | if self.config.read_only { | ||
| 221 | return Err(anyhow!("Client is in read-only mode")); | ||
| 222 | } | ||
| 223 | |||
| 224 | let output = self.client.send_event(&event).await?; | ||
| 225 | let event_id = *output.id(); | ||
| 226 | |||
| 227 | // Check if any relay rejected the event and return the error message | ||
| 228 | if !output.failed.is_empty() { | ||
| 229 | let (relay_url, error) = output.failed.iter().next().unwrap(); | ||
| 230 | return Err(anyhow!("Relay {} rejected event: {}", relay_url, error)); | ||
| 231 | } | ||
| 232 | |||
| 233 | // Wait a bit for event to propagate | ||
| 234 | tokio::time::sleep(Duration::from_millis(300)).await; | ||
| 235 | |||
| 236 | // Check if event is served (not in purgatory) or not served (in purgatory) | ||
| 237 | let in_purgatory = !self.is_event_on_relay(event.id).await?; | ||
| 238 | |||
| 239 | Ok((event_id, in_purgatory)) | ||
| 240 | } | ||
| 241 | |||
| 212 | /// check if an event is on the relay | 242 | /// check if an event is on the relay |
| 213 | pub async fn is_event_on_relay(&self, id: EventId) -> Result<bool> { | 243 | pub async fn is_event_on_relay(&self, id: EventId) -> Result<bool> { |
| 214 | Ok(!self | 244 | Ok(!self |