upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests/common
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-01-19 14:25:27 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-01-19 15:04:00 +0000
commit9372ad649b6c438b1e4645f1dbe95c0f648bb80d (patch)
treea2f95431711bde64713aeb72f3a7dcc65ffe58cc /tests/common
parent16833501a1004a5a661a729e4fd2dbcbeaecd1d5 (diff)
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
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/relay.rs92
1 files changed, 91 insertions, 1 deletions
diff --git a/tests/common/relay.rs b/tests/common/relay.rs
index fb5d421..227849a 100644
--- a/tests/common/relay.rs
+++ b/tests/common/relay.rs
@@ -3,6 +3,7 @@
3//! Provides automatic relay lifecycle management for integration tests. 3//! Provides automatic relay lifecycle management for integration tests.
4 4
5use nostr_sdk::ToBech32; 5use nostr_sdk::ToBech32;
6use std::path::PathBuf;
6use std::process::{Child, Command, Stdio}; 7use std::process::{Child, Command, Stdio};
7use std::time::Duration; 8use std::time::Duration;
8use tokio::time::sleep; 9use tokio::time::sleep;
@@ -15,6 +16,11 @@ pub struct TestRelay {
15 process: Child, 16 process: Child,
16 url: String, 17 url: String,
17 port: u16, 18 port: u16,
19 /// Temporary directory for git repositories
20 /// Kept alive for the lifetime of the relay
21 _git_data_dir: tempfile::TempDir,
22 /// Path to git data directory (for test assertions)
23 git_data_path: PathBuf,
18} 24}
19 25
20impl TestRelay { 26impl TestRelay {
@@ -98,6 +104,37 @@ impl TestRelay {
98 Self::start_with_full_options(Self::find_free_port(), bootstrap_relay_url, true).await 104 Self::start_with_full_options(Self::find_free_port(), bootstrap_relay_url, true).await
99 } 105 }
100 106
107 /// Start relay with archive configuration
108 ///
109 /// This is useful for testing GRASP-05 archive mode behavior.
110 ///
111 /// # Arguments
112 /// * `archive_all` - Accept all repository announcements (GRASP-05)
113 /// * `archive_read_only` - Reject git pushes (read-only archive mode)
114 ///
115 /// # Example
116 ///
117 /// ```no_run
118 /// use common::TestRelay;
119 ///
120 /// #[tokio::test]
121 /// async fn test_archive_mode() {
122 /// let relay = TestRelay::start_with_archive_config(true, true).await;
123 /// // ... test archive behavior ...
124 /// relay.stop().await;
125 /// }
126 /// ```
127 pub async fn start_with_archive_config(archive_all: bool, archive_read_only: bool) -> Self {
128 Self::start_with_archive_and_sync(
129 Self::find_free_port(),
130 None,
131 false,
132 archive_all,
133 archive_read_only,
134 )
135 .await
136 }
137
101 /// Start relay with options (internal, maintains backward compatibility) 138 /// Start relay with options (internal, maintains backward compatibility)
102 async fn start_with_options(port: u16, bootstrap_relay_url: Option<String>) -> Self { 139 async fn start_with_options(port: u16, bootstrap_relay_url: Option<String>) -> Self {
103 Self::start_with_full_options(port, bootstrap_relay_url, false).await 140 Self::start_with_full_options(port, bootstrap_relay_url, false).await
@@ -109,6 +146,34 @@ impl TestRelay {
109 bootstrap_relay_url: Option<String>, 146 bootstrap_relay_url: Option<String>,
110 disable_negentropy: bool, 147 disable_negentropy: bool,
111 ) -> Self { 148 ) -> Self {
149 Self::start_with_archive_and_sync(
150 port,
151 bootstrap_relay_url,
152 disable_negentropy,
153 false,
154 false,
155 )
156 .await
157 }
158
159 /// Start relay with all options including archive configuration and sync
160 ///
161 /// This is the most flexible method for starting a test relay with all options.
162 /// Use this when you need both archive mode AND sync from a bootstrap relay.
163 ///
164 /// # Arguments
165 /// * `port` - Port to bind to
166 /// * `bootstrap_relay_url` - URL of relay to sync from (optional)
167 /// * `disable_negentropy` - Whether to disable NIP-77 negentropy sync
168 /// * `archive_all` - Accept all repository announcements (GRASP-05)
169 /// * `archive_read_only` - Reject git pushes (read-only archive mode)
170 pub async fn start_with_archive_and_sync(
171 port: u16,
172 bootstrap_relay_url: Option<String>,
173 disable_negentropy: bool,
174 archive_all: bool,
175 archive_read_only: bool,
176 ) -> Self {
112 let bind_address = format!("127.0.0.1:{}", port); 177 let bind_address = format!("127.0.0.1:{}", port);
113 let url = format!("ws://127.0.0.1:{}", port); 178 let url = format!("ws://127.0.0.1:{}", port);
114 179
@@ -161,9 +226,26 @@ impl TestRelay {
161 cmd.env("NGIT_SYNC_DISABLE_NEGENTROPY", "true"); 226 cmd.env("NGIT_SYNC_DISABLE_NEGENTROPY", "true");
162 } 227 }
163 228
229 // Add archive configuration if requested
230 if archive_all {
231 cmd.env("NGIT_ARCHIVE_ALL", "true");
232 }
233 if archive_read_only {
234 cmd.env("NGIT_ARCHIVE_READ_ONLY", "true");
235 }
236
164 let process = cmd.spawn().expect("Failed to start relay process"); 237 let process = cmd.spawn().expect("Failed to start relay process");
165 238
166 let relay = Self { process, url, port }; 239 // Store git data path for test assertions
240 let git_data_path = git_data_dir.path().to_path_buf();
241
242 let relay = Self {
243 process,
244 url,
245 port,
246 _git_data_dir: git_data_dir,
247 git_data_path,
248 };
167 249
168 // Wait for relay to be ready 250 // Wait for relay to be ready
169 relay.wait_for_ready().await; 251 relay.wait_for_ready().await;
@@ -181,6 +263,14 @@ impl TestRelay {
181 format!("127.0.0.1:{}", self.port) 263 format!("127.0.0.1:{}", self.port)
182 } 264 }
183 265
266 /// Get the git data directory path
267 ///
268 /// This is useful for test assertions that need to verify
269 /// git repositories were created correctly.
270 pub fn git_data_path(&self) -> &PathBuf {
271 &self.git_data_path
272 }
273
184 /// Wait for the relay to be ready to accept connections 274 /// Wait for the relay to be ready to accept connections
185 async fn wait_for_ready(&self) { 275 async fn wait_for_ready(&self) {
186 let max_attempts = 50; // 5 seconds total 276 let max_attempts = 50; // 5 seconds total