From 9372ad649b6c438b1e4645f1dbe95c0f648bb80d Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 19 Jan 2026 14:25:27 +0000 Subject: fix: archive_read_only creates bare repos for archived announcements Combined Accept and AcceptArchive match arms in builder.rs to ensure bare repositories are created for both cases. Previously AcceptArchive had duplicate code that didn't call ensure_bare_repository(). Also includes: - Config fix: effective_git_data_path() respects explicit paths with memory backend - TestRelay: Added git_data_path() and archive config support for testing - Integration tests for archive_read_only behavior --- src/config.rs | 21 ++++++++++++++++++--- src/nostr/builder.rs | 30 +----------------------------- 2 files changed, 19 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 320661f..0a867e3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -562,9 +562,10 @@ impl Config { } /// Get effective git data path - /// Returns a temp directory when using memory backend, otherwise the configured path + /// Returns a temp directory when using memory backend with default path, otherwise the configured path pub fn effective_git_data_path(&self) -> String { - if self.database_backend == DatabaseBackend::Memory { + if self.database_backend == DatabaseBackend::Memory && self.git_data_path == "./data/git" { + // Only use default temp directory if git_data_path is still the default value std::env::temp_dir() .join("ngit-grasp-git") .to_string_lossy() @@ -733,15 +734,29 @@ mod tests { } #[test] - fn test_memory_backend_uses_temp_dir() { + fn test_memory_backend_uses_temp_dir_with_default_path() { + // When git_data_path is the default value, memory backend uses temp dir let config = Config { database_backend: DatabaseBackend::Memory, + git_data_path: "./data/git".to_string(), // Default value ..Config::for_testing() }; let git_path = config.effective_git_data_path(); assert!(git_path.contains("ngit-grasp-git")); } + #[test] + fn test_memory_backend_respects_custom_path() { + // When git_data_path is explicitly set, memory backend respects it + let config = Config { + database_backend: DatabaseBackend::Memory, + git_data_path: "./custom/git/path".to_string(), + ..Config::for_testing() + }; + let git_path = config.effective_git_data_path(); + assert_eq!(git_path, "./custom/git/path"); + } + #[test] fn test_lmdb_backend_uses_configured_path() { let config = Config { diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs index ef1b700..34014db 100644 --- a/src/nostr/builder.rs +++ b/src/nostr/builder.rs @@ -103,7 +103,7 @@ impl Nip34WritePolicy { let event_id_str = event.id.to_bech32().unwrap_or_else(|_| event.id.to_hex()); match self.announcement_policy.validate(event).await { - AnnouncementResult::Accept => { + AnnouncementResult::Accept | AnnouncementResult::AcceptArchive => { // Parse announcement to get repository details match RepositoryAnnouncement::from_event(event.clone()) { Ok(announcement) => { @@ -166,34 +166,6 @@ impl Nip34WritePolicy { } } } - AnnouncementResult::AcceptArchive => { - // GRASP-05: Archive mode - accept announcement but don't create bare repository - match RepositoryAnnouncement::from_event(event.clone()) { - Ok(announcement) => { - tracing::info!( - "Accepted archive announcement {} for {}/{} (GRASP-05 read-only mirror)", - event_id_str, - announcement.owner_npub(), - announcement.identifier - ); - // Don't create bare repository for archived announcements - - // Check purgatory for state events that might now be authorized - self.check_purgatory_state_events_for_identifier(&announcement.identifier) - .await; - - WritePolicyResult::Accept - } - Err(e) => { - tracing::warn!( - "Failed to parse archive announcement {}: {}", - event_id_str, - e - ); - WritePolicyResult::reject(format!("Failed to parse announcement: {}", e)) - } - } - } AnnouncementResult::Reject(reason) => { tracing::warn!( "Rejected repository announcement {}: {}", -- cgit v1.2.3