From dcaaa0c44c46f963929ab0baa91f63759ec702dc Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 12 Feb 2026 12:57:44 +0000 Subject: 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. --- grasp-audit/src/client.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'grasp-audit/src/client.rs') 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 { Ok(event_id) } + /// Send event and note whether it entered purgatory (not served) or was served immediately. + /// + /// This is a tolerant version of `send_event_expect_purgatory_not_served` that doesn't + /// fail if purgatory is not observed. It returns whether purgatory was observed so + /// fixtures can proceed regardless of relay implementation status. + /// + /// Returns (EventId, bool) where bool = true if event was NOT served (purgatory observed). + pub async fn send_event_and_note_purgatory(&self, event: Event) -> Result<(EventId, bool)> { + if self.config.read_only { + return Err(anyhow!("Client is in read-only mode")); + } + + let output = self.client.send_event(&event).await?; + let event_id = *output.id(); + + // Check if any relay rejected the event and return the error message + if !output.failed.is_empty() { + let (relay_url, error) = output.failed.iter().next().unwrap(); + return Err(anyhow!("Relay {} rejected event: {}", relay_url, error)); + } + + // Wait a bit for event to propagate + tokio::time::sleep(Duration::from_millis(300)).await; + + // Check if event is served (not in purgatory) or not served (in purgatory) + let in_purgatory = !self.is_event_on_relay(event.id).await?; + + Ok((event_id, in_purgatory)) + } + /// check if an event is on the relay pub async fn is_event_on_relay(&self, id: EventId) -> Result { Ok(!self -- cgit v1.2.3