1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
|
# Implementation Checklist
**Date:** November 4, 2025
**Purpose:** Step-by-step checklist for actix-web integration
---
## ✅ Pre-Implementation (DONE)
- [x] Review GRASP-01 specification
- [x] Review ngit-relay reference implementation
- [x] Understand single-port architecture
- [x] Document architecture in work/architecture-diagram.md
- [x] Create detailed plan in work/NEXT_SESSION_START_HERE.md
- [x] Update work/current_status.md
---
## 📦 Phase 1: Dependencies & Setup
### 1.1 Update Cargo.toml
- [ ] Add `actix-web = "4"`
- [ ] Add `actix-cors = "0.7"`
- [ ] Add `actix-ws = "0.3"` (or use actix-web-actors)
- [ ] Add `git-http-backend = "0.2"` (check latest version)
- [ ] Run `cargo check` to verify dependencies
**Verification:**
```bash
cargo tree | grep actix
cargo tree | grep git-http-backend
```
### 1.2 Update .env.example (if needed)
- [x] Already has all required fields
- [x] NGIT_DOMAIN
- [x] NGIT_BIND_ADDRESS
- [x] NGIT_GIT_DATA_PATH
- [x] NGIT_RELAY_DATA_PATH
**Verification:**
```bash
cat .env.example
```
---
## 🏗️ Phase 2: HTTP Server Module
### 2.1 Create src/http/mod.rs
- [ ] Create module structure
- [ ] Add `pub mod git;`
- [ ] Add `pub mod nostr;`
- [ ] Create `run_server()` function
- [ ] Set up actix-web HttpServer
- [ ] Add CORS middleware
- [ ] Add routing for Git and Nostr
**Verification:**
```bash
cargo check
# Should compile without errors
```
**Test:**
```rust
// In src/http/mod.rs
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_module_exists() {
// Just verify module structure
assert!(true);
}
}
```
### 2.2 Create src/http/git.rs
- [ ] Create `handle_git_request()` function
- [ ] Parse npub and repo from path
- [ ] Construct repository path
- [ ] Check if repository exists (return 404 if not)
- [ ] Use git-http-backend crate
- [ ] Handle GET (clone/fetch)
- [ ] Handle POST (push)
- [ ] Return proper HTTP responses
**Verification:**
```bash
cargo check
# Should compile
```
**Test:**
```rust
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_repo_path() {
// Test path parsing logic
let path = "/npub1abc.../my-repo.git";
// ... verify parsing
}
}
```
### 2.3 Create src/http/nostr.rs
- [ ] Create `handle_websocket()` function
- [ ] Handle WebSocket upgrade
- [ ] Reuse existing Nostr message handling
- [ ] Create `handle_http_root()` function
- [ ] Serve HTML for browsers
- [ ] Serve NIP-11 JSON for Accept: application/nostr+json
**Verification:**
```bash
cargo check
```
**Test:**
```rust
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_nip11_response() {
// Test NIP-11 JSON generation
// ...
}
}
```
---
## 🔧 Phase 3: Update Existing Code
### 3.1 Update src/config.rs
- [x] Already has `git_data_path` field
- [x] Already has `from_env()` implementation
- [ ] Verify all fields are present
- [ ] Add any missing validation
**Verification:**
```bash
cargo check
```
### 3.2 Update src/main.rs
- [ ] Remove direct relay start
- [ ] Import `http` module
- [ ] Call `http::run_server(config, storage).await`
- [ ] Update logging messages
**Verification:**
```bash
cargo build
# Should build successfully
```
**Test:**
```bash
# Run server
NGIT_DOMAIN=localhost:8080 \
NGIT_BIND_ADDRESS=127.0.0.1:8080 \
cargo run
# In another terminal, check it's listening
curl -v http://localhost:8080/
```
### 3.3 Move Relay Logic to Library
- [ ] Extract relay logic from src/nostr/relay.rs
- [ ] Make it reusable by WebSocket handler
- [ ] Keep message handling separate from transport
- [ ] Create `handle_nostr_message()` function
**Structure:**
```rust
// src/nostr/relay.rs
pub async fn handle_nostr_message(
message: &str,
storage: &Storage,
) -> Result<Vec<String>> {
// Parse message
// Handle EVENT, REQ, CLOSE
// Return response messages
}
```
**Verification:**
```bash
cargo check
cargo test --lib
```
---
## 🧪 Phase 4: Update Tests
### 4.1 Update tests/common/relay.rs
- [ ] Verify NGIT_DOMAIN is set correctly
- [ ] Add NGIT_GIT_DATA_PATH env var
- [ ] Add NGIT_RELAY_DATA_PATH env var
- [ ] Use test-specific directories
- [ ] Clean up test data after tests
**Current Status:** Already sets NGIT_DOMAIN correctly!
**Add:**
```rust
.env("NGIT_GIT_DATA_PATH", "./test-data/repos")
.env("NGIT_RELAY_DATA_PATH", "./test-data/relay")
```
**Verification:**
```bash
cargo test --test nip01_compliance
# Should still pass
```
### 4.2 Create tests/grasp01_git_http.rs
- [ ] Create new test file
- [ ] Add basic Git clone test
- [ ] Add CORS headers test
- [ ] Add OPTIONS request test
- [ ] Add repository not found test
- [ ] Reference GRASP-01 line numbers in comments
**Template:**
```rust
//! GRASP-01 Git HTTP Integration Tests
//!
//! Reference: ../grasp/01.md lines 15-40
mod common;
use common::TestRelay;
#[tokio::test]
async fn test_git_http_basic() {
// Reference: ../grasp/01.md line 15
// MUST serve git repository via unauthenticated git smart http
let relay = TestRelay::start().await;
// TODO: Create test repo
// TODO: Try to clone it
relay.stop().await;
}
```
**Verification:**
```bash
cargo test --test grasp01_git_http
```
### 4.3 Update tests/nip01_compliance.rs
- [ ] Verify tests still pass with new architecture
- [ ] Update any broken tests
- [ ] Add comments referencing GRASP-01 where relevant
**Verification:**
```bash
cargo test --test nip01_compliance
```
---
## 🔍 Phase 5: Integration & Testing
### 5.1 Manual Testing
**Test 1: Server Starts**
```bash
cargo build
NGIT_DOMAIN=localhost:8080 \
NGIT_BIND_ADDRESS=127.0.0.1:8080 \
cargo run
```
**Expected:** Server starts without errors
---
**Test 2: WebSocket Connection**
```bash
# In grasp-audit directory
cargo run -- --url ws://localhost:8080
```
**Expected:** NIP-01 smoke tests pass
---
**Test 3: HTTP Root**
```bash
curl -v http://localhost:8080/
```
**Expected:**
- Status: 200 OK
- Content-Type: text/html
- CORS headers present
- HTML content
---
**Test 4: NIP-11**
```bash
curl -v http://localhost:8080/ \
-H "Accept: application/nostr+json"
```
**Expected:**
- Status: 200 OK
- Content-Type: application/json
- CORS headers present
- JSON with `supported_grasps` field
---
**Test 5: Git Repository (404)**
```bash
curl -v http://localhost:8080/npub1test/test-repo.git/info/refs?service=git-upload-pack
```
**Expected:**
- Status: 404 Not Found
- CORS headers present
---
**Test 6: Git Repository (Success)**
```bash
# Create test repo
mkdir -p ./data/repos/npub1test
cd ./data/repos/npub1test
git init --bare test-repo.git
# Try to access it
curl -v http://localhost:8080/npub1test/test-repo.git/info/refs?service=git-upload-pack
```
**Expected:**
- Status: 200 OK
- Content-Type: application/x-git-upload-pack-advertisement
- CORS headers present
- Git protocol data
---
**Test 7: Git Clone**
```bash
git clone http://localhost:8080/npub1test/test-repo.git /tmp/test-clone
```
**Expected:**
- Clone succeeds (even if empty repo)
- No errors
---
**Test 8: CORS Preflight**
```bash
curl -v -X OPTIONS http://localhost:8080/ \
-H "Origin: https://example.com" \
-H "Access-Control-Request-Method: POST"
```
**Expected:**
- Status: 204 No Content
- Access-Control-Allow-Origin: *
- Access-Control-Allow-Methods: GET, POST
- Access-Control-Allow-Headers: Content-Type
- Access-Control-Max-Age: 3600
---
### 5.2 Automated Testing
**Run All Tests:**
```bash
# Build first
cargo build
# Run all tests
cargo test
# Run specific test suites
cargo test --test nip01_compliance
cargo test --test grasp01_git_http
# With output
cargo test -- --nocapture
```
**Expected:** All tests pass
---
### 5.3 Performance Testing
**Test Concurrent Connections:**
```bash
# Start server
cargo run &
# Run multiple clients
for i in {1..10}; do
(cd grasp-audit && cargo run -- --url ws://localhost:8080) &
done
# Wait for all to complete
wait
```
**Expected:** All clients connect and pass tests
---
### 5.4 Error Handling Testing
**Test 1: Invalid Repository Path**
```bash
curl -v http://localhost:8080/invalid/path
```
**Expected:** 404 or appropriate error
---
**Test 2: Invalid WebSocket Message**
```bash
# Use websocat or similar
echo "invalid json" | websocat ws://localhost:8080/
```
**Expected:** NOTICE message with error
---
**Test 3: Large Git Push**
```bash
# Create repo with large files
# Try to push
# Verify it works or fails gracefully
```
---
## 📋 Acceptance Criteria
### Must Have (MVP)
- [ ] Server starts on single port
- [ ] WebSocket connects at `/`
- [ ] NIP-01 smoke tests pass
- [ ] Can access Git repo at `/<npub>/<id>.git`
- [ ] Returns 404 for missing repos
- [ ] CORS headers on all responses
- [ ] OPTIONS requests return 204
- [ ] Can clone existing Git repository
- [ ] All integration tests pass
### Should Have (Before Production)
- [ ] Can push to repository (basic, no auth yet)
- [ ] Repository provisioned from announcement
- [ ] NIP-11 includes GRASP fields
- [ ] Proper error messages
- [ ] Logging works correctly
- [ ] Clean shutdown
- [ ] Test data cleanup
### Could Have (Future)
- [ ] Push authorization
- [ ] Maintainer set validation
- [ ] PR ref support
- [ ] State synchronization
- [ ] Proactive sync (GRASP-02)
---
## 🐛 Known Issues to Watch For
### Issue 1: WebSocket Upgrade Timing
**Symptom:** WebSocket upgrade fails intermittently
**Debug:**
```bash
RUST_LOG=debug cargo run
# Check for upgrade-related logs
```
**Solution:** Ensure actix-ws is configured correctly
---
### Issue 2: Git HTTP Protocol Errors
**Symptom:** Git clone fails with protocol error
**Debug:**
```bash
GIT_TRACE_PACKET=1 git clone http://localhost:8080/...
# Shows Git protocol messages
```
**Solution:** Check git-http-backend configuration
---
### Issue 3: CORS Not Applied
**Symptom:** Browser shows CORS error
**Debug:**
```bash
curl -v http://localhost:8080/ -H "Origin: https://example.com"
# Check response headers
```
**Solution:** Verify CORS middleware is first in chain
---
### Issue 4: Port Already in Use
**Symptom:** "Address already in use" error
**Debug:**
```bash
lsof -i :8080
# Find process using port
```
**Solution:**
```bash
kill -9 <PID>
# Or use different port
```
---
### Issue 5: Test Relay Won't Start
**Symptom:** Integration tests fail to start relay
**Debug:**
```bash
# Run test with output
cargo test --test nip01_compliance -- --nocapture
# Check binary exists
ls -la target/debug/ngit-grasp
```
**Solution:** Run `cargo build` before tests
---
## 📚 Reference Commands
### Development
```bash
# Build
cargo build
# Run
cargo run
# Run with logging
RUST_LOG=debug cargo run
# Check without building
cargo check
# Format code
cargo fmt
# Lint
cargo clippy
```
### Testing
```bash
# All tests
cargo test
# Specific test file
cargo test --test nip01_compliance
# Specific test
cargo test --test nip01_compliance test_nip01_smoke
# With output
cargo test -- --nocapture
# With logging
RUST_LOG=debug cargo test -- --nocapture
```
### Debugging
```bash
# Check dependencies
cargo tree
# Check for unused dependencies
cargo +nightly udeps
# Check for outdated dependencies
cargo outdated
# Audit for security issues
cargo audit
```
### Git Testing
```bash
# Create test repo
mkdir -p ./data/repos/npub1test
cd ./data/repos/npub1test
git init --bare test-repo.git
# Clone it
git clone http://localhost:8080/npub1test/test-repo.git /tmp/test
# Push to it
cd /tmp/test
echo "test" > README.md
git add .
git commit -m "test"
git push origin main
```
---
## ✅ Completion Checklist
When all items are checked, Phase 1 (actix-web integration) is complete:
### Code
- [ ] Dependencies added to Cargo.toml
- [ ] src/http/mod.rs created
- [ ] src/http/git.rs created
- [ ] src/http/nostr.rs created
- [ ] src/main.rs updated
- [ ] src/config.rs verified
- [ ] Relay logic refactored
### Tests
- [ ] tests/common/relay.rs updated
- [ ] tests/grasp01_git_http.rs created
- [ ] tests/nip01_compliance.rs still passes
- [ ] All tests pass
### Manual Testing
- [ ] Server starts successfully
- [ ] WebSocket connects
- [ ] NIP-01 smoke tests pass
- [ ] Can access Git repos
- [ ] 404 for missing repos
- [ ] CORS headers present
- [ ] OPTIONS requests work
- [ ] Can clone repository
### Documentation
- [ ] Update README.md status
- [ ] Update work/current_status.md
- [ ] Document any issues found
- [ ] Update NEXT_SESSION_START_HERE.md for next phase
---
## 🎯 Next Phase Preview
After actix-web integration is complete, next phase will be:
**Phase 2: Repository Provisioning**
- Listen for NIP-34 repository announcements
- Create Git repositories automatically
- Initialize bare repositories
- Set up directory structure
- Handle repository deletion
**Estimated Time:** 2-3 hours
**Prerequisites:** Phase 1 complete
---
**Last Updated:** November 4, 2025
**Status:** Ready to begin Phase 1
|