diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-05 07:35:02 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-05 07:35:02 +0000 |
| commit | 81d611004917afffe5af01925eee7e7695c54b3d (patch) | |
| tree | 2f3796f700d82fdf01ee2efad38452c601d7810f | |
| parent | cb466fbc02b83c5788def5fef73f93573f5c1f70 (diff) | |
docs: simplify README testing section, point to test script
- Remove duplicated setup/cleanup instructions from README
- Point to test-ngit-relay.sh for full details
- Add simple one-liner for manual testing
- Fix container name bug in test script (was using bare $)
| -rw-r--r-- | grasp-audit/README.md | 156 | ||||
| -rwxr-xr-x | grasp-audit/test-ngit-relay.sh | 6 |
2 files changed, 14 insertions, 148 deletions
diff --git a/grasp-audit/README.md b/grasp-audit/README.md index 7c0450b..b8b452e 100644 --- a/grasp-audit/README.md +++ b/grasp-audit/README.md | |||
| @@ -137,84 +137,22 @@ cargo test | |||
| 137 | 137 | ||
| 138 | Test against the reference GRASP implementation to ensure compatibility. | 138 | Test against the reference GRASP implementation to ensure compatibility. |
| 139 | 139 | ||
| 140 | **Note:** ngit-relay is a specialized GRASP relay that only accepts Git-related events (NIP-34). | 140 | **Automated Script (Recommended):** |
| 141 | Some NIP-01 smoke tests (like `send_receive_event`) will fail because ngit-relay rejects | ||
| 142 | non-Git events. This is expected behavior - the validation tests should still pass. | ||
| 143 | 141 | ||
| 144 | ```bash | 142 | ```bash |
| 145 | # 1. Create temporary directory with unique name for clean state | 143 | # Handles setup, testing, and cleanup automatically |
| 146 | TEST_DIR=$(mktemp -d -t grasp-audit-run-XXXXXXXXXX) | 144 | ./test-ngit-relay.sh |
| 147 | mkdir -p "$TEST_DIR"/{repos,blossom,relay-db,logs} | ||
| 148 | |||
| 149 | # 2. Pick a random port to avoid conflicts | ||
| 150 | PORT=$((20000 + RANDOM % 10000)) | ||
| 151 | |||
| 152 | # 3. Start ngit-relay with fresh data | ||
| 153 | CONTAINER_NAME="grasp-audit-run-$" | ||
| 154 | docker run --rm -d \ | ||
| 155 | --name "$CONTAINER_NAME" \ | ||
| 156 | -p "$PORT:8081" \ | ||
| 157 | -e NGIT_DOMAIN=localhost \ | ||
| 158 | -e NGIT_RELAY_NAME="ngit-relay test instance" \ | ||
| 159 | -e NGIT_RELAY_DESCRIPTION="Test instance for grasp-audit" \ | ||
| 160 | -e NGIT_OWNER_NPUB="npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr" \ | ||
| 161 | -e NGIT_PROACTIVE_SYNC_GIT=false \ | ||
| 162 | -e NGIT_PROACTIVE_SYNC_BLOSSOM=false \ | ||
| 163 | -e NGIT_PROACTIVE_SYNC_NOSTR=false \ | ||
| 164 | -e NGIT_LOG_LEVEL=INFO \ | ||
| 165 | -v "$TEST_DIR/repos:/srv/ngit-relay/repos" \ | ||
| 166 | -v "$TEST_DIR/blossom:/srv/ngit-relay/blossom" \ | ||
| 167 | -v "$TEST_DIR/relay-db:/srv/ngit-relay/relay-db" \ | ||
| 168 | -v "$TEST_DIR/logs:/var/log/ngit-relay" \ | ||
| 169 | ghcr.io/danconwaydev/ngit-relay:latest | ||
| 170 | |||
| 171 | # 4. Wait for relay to start | ||
| 172 | sleep 3 | ||
| 173 | |||
| 174 | # 5. Run tests against ngit-relay | ||
| 175 | RELAY_URL="ws://localhost:$PORT" cargo test --ignored | ||
| 176 | |||
| 177 | # Expected results when testing against ngit-relay: | ||
| 178 | # - ✓ websocket_connection (basic connectivity) | ||
| 179 | # - ✗ send_receive_event (ngit-relay rejects non-Git events - EXPECTED FAILURE) | ||
| 180 | # - ✗ create_subscription (depends on send_receive_event - EXPECTED FAILURE) | ||
| 181 | # - ✓ close_subscription (basic protocol) | ||
| 182 | # - ✓ reject_invalid_signature (validation works! - KEY TEST) | ||
| 183 | # - ✓ reject_invalid_event_id (validation works! - KEY TEST) | ||
| 184 | # | ||
| 185 | # Result: 4/6 passed (66.7%) | ||
| 186 | # | ||
| 187 | # This is CORRECT behavior! It shows ngit-relay: | ||
| 188 | # 1. Implements NIP-01 validation correctly (rejects invalid events) | ||
| 189 | # 2. Has restrictive acceptance policies (only accepts Git events) | ||
| 190 | # 3. Is a properly functioning GRASP relay | ||
| 191 | # | ||
| 192 | # The test will exit with an error, but the validation tests passing | ||
| 193 | # is what matters for GRASP compliance. | ||
| 194 | |||
| 195 | # 6. Stop and cleanup | ||
| 196 | docker stop "$CONTAINER_NAME" | ||
| 197 | docker run --rm -v "$TEST_DIR:/data" alpine sh -c "rm -rf /data/*" 2>/dev/null || true | ||
| 198 | rm -rf "$TEST_DIR" | ||
| 199 | ``` | 145 | ``` |
| 200 | 146 | ||
| 201 | **Why fresh directories?** | 147 | See `test-ngit-relay.sh` for full setup/cleanup details. |
| 202 | - Ensures clean state for each test run | ||
| 203 | - Prevents test pollution from previous runs | ||
| 204 | - Matches CI environment behavior | ||
| 205 | 148 | ||
| 206 | **Environment variables explained:** | 149 | **Manual One-Liner:** |
| 207 | - `NGIT_DOMAIN`: Domain name (localhost for testing) | ||
| 208 | - `NGIT_RELAY_NAME`: Relay name for NIP-11 | ||
| 209 | - `NGIT_RELAY_DESCRIPTION`: Relay description for NIP-11 | ||
| 210 | - `NGIT_OWNER_NPUB`: Relay owner's npub (uses reference impl owner) | ||
| 211 | - `NGIT_PROACTIVE_SYNC_*`: Disable proactive sync for testing | ||
| 212 | - `NGIT_LOG_LEVEL`: Set to INFO for debugging | ||
| 213 | 150 | ||
| 214 | **Port mapping:** | 151 | ```bash |
| 215 | - ngit-relay serves both WebSocket (relay) and HTTP (git) on port 8081 | 152 | # Start relay, then run: RELAY_URL="ws://localhost:$PORT" cargo test --lib -- --ignored --nocapture |
| 216 | - WebSocket endpoint: `ws://localhost:8081/` | 153 | ``` |
| 217 | - Git HTTP endpoint: `http://localhost:8081/<npub>/<identifier>.git` | 154 | |
| 155 | **Note:** ngit-relay only accepts Git-related events (NIP-34). Some NIP-01 smoke tests will fail (expected). Validation tests should pass. | ||
| 218 | 156 | ||
| 219 | ### Testing Against General-Purpose Relays | 157 | ### Testing Against General-Purpose Relays |
| 220 | 158 | ||
| @@ -233,80 +171,6 @@ docker stop nostr-test-relay | |||
| 233 | 171 | ||
| 234 | Expected: 6/6 tests passed (100%) | 172 | Expected: 6/6 tests passed (100%) |
| 235 | 173 | ||
| 236 | ### Quick Test Script | ||
| 237 | |||
| 238 | Save this as `test-ngit-relay.sh`: | ||
| 239 | |||
| 240 | ```bash | ||
| 241 | #!/bin/bash | ||
| 242 | set -e | ||
| 243 | |||
| 244 | # Create temporary directory with random name | ||
| 245 | TEST_DIR=$(mktemp -d -t grasp-audit-run-XXXXXXXXXX) | ||
| 246 | # Pick a random port in the range 20000-30000 | ||
| 247 | PORT=$((20000 + RANDOM % 10000)) | ||
| 248 | |||
| 249 | echo "🧹 Using temporary directory: $TEST_DIR" | ||
| 250 | echo "🔌 Using port: $PORT" | ||
| 251 | |||
| 252 | # Cleanup function | ||
| 253 | cleanup() { | ||
| 254 | echo "🛑 Stopping relay..." | ||
| 255 | docker stop "grasp-audit-run-$" 2>/dev/null || true | ||
| 256 | |||
| 257 | echo "🧹 Cleaning up temporary directory..." | ||
| 258 | docker run --rm -v "$TEST_DIR:/data" alpine sh -c "rm -rf /data/*" 2>/dev/null || true | ||
| 259 | rm -rf "$TEST_DIR" | ||
| 260 | } | ||
| 261 | |||
| 262 | # Set trap to cleanup on exit | ||
| 263 | trap cleanup EXIT | ||
| 264 | |||
| 265 | echo "📁 Creating data directories..." | ||
| 266 | mkdir -p "$TEST_DIR"/{repos,blossom,relay-db,logs} | ||
| 267 | |||
| 268 | echo "🚀 Starting ngit-relay..." | ||
| 269 | # Remove any existing container with this name | ||
| 270 | CONTAINER_NAME="grasp-audit-run-$" | ||
| 271 | docker rm -f "$CONTAINER_NAME" 2>/dev/null || true | ||
| 272 | docker run --rm -d \ | ||
| 273 | --name "$CONTAINER_NAME" \ | ||
| 274 | -p "$PORT:8081" \ | ||
| 275 | -e NGIT_DOMAIN=localhost \ | ||
| 276 | -e NGIT_RELAY_NAME="ngit-relay test instance" \ | ||
| 277 | -e NGIT_RELAY_DESCRIPTION="Test instance for grasp-audit" \ | ||
| 278 | -e NGIT_OWNER_NPUB="npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr" \ | ||
| 279 | -e NGIT_PROACTIVE_SYNC_GIT=false \ | ||
| 280 | -e NGIT_PROACTIVE_SYNC_BLOSSOM=false \ | ||
| 281 | -e NGIT_PROACTIVE_SYNC_NOSTR=false \ | ||
| 282 | -e NGIT_LOG_LEVEL=INFO \ | ||
| 283 | -v "$TEST_DIR/repos:/srv/ngit-relay/repos" \ | ||
| 284 | -v "$TEST_DIR/blossom:/srv/ngit-relay/blossom" \ | ||
| 285 | -v "$TEST_DIR/relay-db:/srv/ngit-relay/relay-db" \ | ||
| 286 | -v "$TEST_DIR/logs:/var/log/ngit-relay" \ | ||
| 287 | ghcr.io/danconwaydev/ngit-relay:latest | ||
| 288 | |||
| 289 | echo "⏳ Waiting for relay to start..." | ||
| 290 | sleep 3 | ||
| 291 | |||
| 292 | echo "🧪 Running tests..." | ||
| 293 | echo "" | ||
| 294 | echo "Note: ngit-relay only accepts Git-related events (NIP-34)." | ||
| 295 | echo "Some NIP-01 smoke tests will fail (expected behavior)." | ||
| 296 | echo "Validation tests should pass." | ||
| 297 | echo "" | ||
| 298 | RELAY_URL="ws://localhost:$PORT" cargo test --lib -- --ignored --nocapture | ||
| 299 | |||
| 300 | echo "✅ Done!" | ||
| 301 | ``` | ||
| 302 | |||
| 303 | Then run: | ||
| 304 | |||
| 305 | ```bash | ||
| 306 | chmod +x test-ngit-relay.sh | ||
| 307 | ./test-ngit-relay.sh | ||
| 308 | ``` | ||
| 309 | |||
| 310 | ## Architecture | 174 | ## Architecture |
| 311 | 175 | ||
| 312 | ``` | 176 | ``` |
diff --git a/grasp-audit/test-ngit-relay.sh b/grasp-audit/test-ngit-relay.sh index 9d5eb4a..5e94fdb 100755 --- a/grasp-audit/test-ngit-relay.sh +++ b/grasp-audit/test-ngit-relay.sh | |||
| @@ -5,6 +5,8 @@ set -e | |||
| 5 | TEST_DIR=$(mktemp -d -t grasp-audit-run-XXXXXXXXXX) | 5 | TEST_DIR=$(mktemp -d -t grasp-audit-run-XXXXXXXXXX) |
| 6 | # Pick a random port in the range 20000-30000 | 6 | # Pick a random port in the range 20000-30000 |
| 7 | PORT=$((20000 + RANDOM % 10000)) | 7 | PORT=$((20000 + RANDOM % 10000)) |
| 8 | # Generate a unique container name suffix | ||
| 9 | CONTAINER_SUFFIX=$RANDOM | ||
| 8 | 10 | ||
| 9 | echo "🧹 Using temporary directory: $TEST_DIR" | 11 | echo "🧹 Using temporary directory: $TEST_DIR" |
| 10 | echo "🔌 Using port: $PORT" | 12 | echo "🔌 Using port: $PORT" |
| @@ -12,7 +14,7 @@ echo "🔌 Using port: $PORT" | |||
| 12 | # Cleanup function | 14 | # Cleanup function |
| 13 | cleanup() { | 15 | cleanup() { |
| 14 | echo "🛑 Stopping relay..." | 16 | echo "🛑 Stopping relay..." |
| 15 | docker stop "grasp-audit-run-$" 2>/dev/null || true | 17 | docker stop "grasp-audit-run-$CONTAINER_SUFFIX" 2>/dev/null || true |
| 16 | 18 | ||
| 17 | echo "🧹 Cleaning up temporary directory..." | 19 | echo "🧹 Cleaning up temporary directory..." |
| 18 | docker run --rm -v "$TEST_DIR:/data" alpine sh -c "rm -rf /data/*" 2>/dev/null || true | 20 | docker run --rm -v "$TEST_DIR:/data" alpine sh -c "rm -rf /data/*" 2>/dev/null || true |
| @@ -27,7 +29,7 @@ mkdir -p "$TEST_DIR"/{repos,blossom,relay-db,logs} | |||
| 27 | 29 | ||
| 28 | echo "🚀 Starting ngit-relay..." | 30 | echo "🚀 Starting ngit-relay..." |
| 29 | # Remove any existing container with this name | 31 | # Remove any existing container with this name |
| 30 | CONTAINER_NAME="grasp-audit-run-$" | 32 | CONTAINER_NAME="grasp-audit-run-$CONTAINER_SUFFIX" |
| 31 | docker rm -f "$CONTAINER_NAME" 2>/dev/null || true | 33 | docker rm -f "$CONTAINER_NAME" 2>/dev/null || true |
| 32 | docker run --rm -d \ | 34 | docker run --rm -d \ |
| 33 | --name "$CONTAINER_NAME" \ | 35 | --name "$CONTAINER_NAME" \ |