diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-23 15:41:32 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-23 15:41:32 +0000 |
| commit | c54ce061d6d278cce8362d5af085808ca60c239b (patch) | |
| tree | ec967d6195d9f7ec4f061449596611afe3a0950f /tests/common/purgatory_helpers.rs | |
| parent | e0ad39a489b3398f8208713bf728db0cb11475b0 (diff) | |
| parent | 113928aa84894ea8f65c247d9987527e792b32a9 (diff) | |
feat: announcement purgatory
Extends purgatory to hold repository announcements until git data arrives,
preventing empty repositories from being served to clients.
When an announcement is received, a bare repo is created immediately and the
announcement is held in purgatory. It is only promoted and served once a git
push confirms real content exists. If no push arrives before expiry, the bare
repo is deleted and the announcement is silently discarded.
Key behaviours:
- Soft expiry: announcements are hidden from clients but kept alive while git
pushes are in progress, reviving on successful push
- Expiry is extended when a matching state event or git push is observed
- NIP-09 deletion events remove announcements from purgatory
- Purgatory state (announcements, state events, PR events, expired set) is
persisted to disk on graceful shutdown and restored on startup, with elapsed
downtime subtracted from expiry deadlines
- Purgatory announcements drive StateOnly sync in the sync system so state
events are fetched from listed relays before promotion
- SyncLevel added to RepoSyncIndex to distinguish purgatory repos (StateOnly)
from promoted repos (Full L2+L3 sync)
Diffstat (limited to 'tests/common/purgatory_helpers.rs')
| -rw-r--r-- | tests/common/purgatory_helpers.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/common/purgatory_helpers.rs b/tests/common/purgatory_helpers.rs index 1d06f22..cfcea1c 100644 --- a/tests/common/purgatory_helpers.rs +++ b/tests/common/purgatory_helpers.rs | |||
| @@ -338,6 +338,44 @@ pub fn build_repo_coord(keys: &Keys, identifier: &str) -> String { | |||
| 338 | format!("30617:{}:{}", keys.public_key().to_hex(), identifier) | 338 | format!("30617:{}:{}", keys.public_key().to_hex(), identifier) |
| 339 | } | 339 | } |
| 340 | 340 | ||
| 341 | /// Create a repository announcement event (kind 30617) for purgatory tests. | ||
| 342 | /// | ||
| 343 | /// Creates a minimal but valid NIP-34 repository announcement with a `d` tag, | ||
| 344 | /// optional `clone` URLs, and optional `relays` URLs. | ||
| 345 | /// | ||
| 346 | /// # Arguments | ||
| 347 | /// * `keys` - Keys for signing | ||
| 348 | /// * `identifier` - Repository identifier (d-tag) | ||
| 349 | /// * `clone_urls` - Clone URLs to include (may be empty) | ||
| 350 | /// * `relay_urls` - Relay URLs to include (may be empty) | ||
| 351 | /// | ||
| 352 | /// # Returns | ||
| 353 | /// * `Ok(Event)` - Signed announcement event | ||
| 354 | /// * `Err(String)` - If signing fails | ||
| 355 | pub fn create_announcement_event( | ||
| 356 | keys: &Keys, | ||
| 357 | identifier: &str, | ||
| 358 | clone_urls: &[&str], | ||
| 359 | relay_urls: &[&str], | ||
| 360 | ) -> Result<Event, String> { | ||
| 361 | let mut tags = vec![Tag::identifier(identifier)]; | ||
| 362 | |||
| 363 | if !clone_urls.is_empty() { | ||
| 364 | let urls: Vec<String> = clone_urls.iter().map(|s| s.to_string()).collect(); | ||
| 365 | tags.push(Tag::custom(TagKind::custom("clone"), urls)); | ||
| 366 | } | ||
| 367 | |||
| 368 | if !relay_urls.is_empty() { | ||
| 369 | let urls: Vec<String> = relay_urls.iter().map(|s| s.to_string()).collect(); | ||
| 370 | tags.push(Tag::custom(TagKind::custom("relays"), urls)); | ||
| 371 | } | ||
| 372 | |||
| 373 | EventBuilder::new(Kind::GitRepoAnnouncement, "") | ||
| 374 | .tags(tags) | ||
| 375 | .sign_with_keys(keys) | ||
| 376 | .map_err(|e| format!("Failed to sign announcement event: {}", e)) | ||
| 377 | } | ||
| 378 | |||
| 341 | /// Wait for an event to be served by a relay (not in purgatory). | 379 | /// Wait for an event to be served by a relay (not in purgatory). |
| 342 | /// | 380 | /// |
| 343 | /// Polls the relay until the event is queryable, indicating it has | 381 | /// Polls the relay until the event is queryable, indicating it has |