diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-04 12:34:20 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-04 13:02:59 +0000 |
| commit | d9bc5ed7fddef3a26de8e69a7124e1dbe5b8602f (patch) | |
| tree | c76ffcbf246c8bef7545337316c0afb90433bbf5 /AGENTS.md | |
| parent | 40831a9025d05fa354b7d8386eeebd902092ea86 (diff) | |
docs: update based on current implementation
Diffstat (limited to 'AGENTS.md')
| -rw-r--r-- | AGENTS.md | 119 |
1 files changed, 43 insertions, 76 deletions
| @@ -28,95 +28,69 @@ nix-shell | |||
| 28 | nix-shell --run "cargo build" | 28 | nix-shell --run "cargo build" |
| 29 | ``` | 29 | ``` |
| 30 | 30 | ||
| 31 | ### Running Tests | 31 | ### Testing ngit-grasp (Main Project) |
| 32 | 32 | ||
| 33 | **Integration tests require relay running:** | 33 | **ngit-grasp integration tests use the [`TestRelay`](tests/common/relay.rs:14) fixture:** |
| 34 | |||
| 35 | The `TestRelay` fixture automatically starts an instance of ngit-grasp itself and manages its lifecycle: | ||
| 34 | 36 | ||
| 35 | ```bash | 37 | ```bash |
| 36 | # Start ngit-relay first (use any available port to avoid conflicts) | 38 | # Run all ngit-grasp tests (from project root) |
| 37 | docker run --rm -p 18081:8081 ghcr.io/danconwaydev/ngit-relay:latest | 39 | cargo test |
| 38 | 40 | ||
| 39 | # From grasp-audit directory, set RELAY_URL to match your port | 41 | # Run integration tests only |
| 40 | # Run all ignored tests (includes GRASP-01 and other relay-dependent tests) | 42 | cargo test --test '*' |
| 41 | RELAY_URL="ws://localhost:18081" nix develop -c cargo test --lib -- --ignored --nocapture | ||
| 42 | 43 | ||
| 43 | # Or run a specific test | 44 | # Run specific test file |
| 44 | RELAY_URL="ws://localhost:18081" nix develop -c cargo test --lib test_grasp01_nostr_relay_against_relay -- --ignored --nocapture | 45 | cargo test --test nip01_compliance |
| 45 | ``` | 46 | ``` |
| 46 | 47 | ||
| 47 | Tests marked `#[ignore]` need relay - unit tests don't. | 48 | **How TestRelay works:** |
| 48 | |||
| 49 | **Note:** Always use a random available port for the relay to avoid conflicts with existing services. | ||
| 50 | |||
| 51 | ### Standard Testing Process (Recommended) | ||
| 52 | 49 | ||
| 53 | **Use test-ngit-relay.sh for automated relay management:** | 50 | - Spawns `ngit-grasp` binary on a random available port |
| 51 | - Creates temporary directories for git and relay data | ||
| 52 | - Provides `url()` and `domain()` methods for test clients | ||
| 53 | - Automatically cleans up on drop | ||
| 54 | 54 | ||
| 55 | This script handles all relay lifecycle management automatically: | 55 | **Example test pattern:** |
| 56 | - Starts ngit-relay in isolated Docker container | ||
| 57 | - Uses random port to avoid conflicts | ||
| 58 | - Creates isolated temporary directories | ||
| 59 | - Ensures cleanup on exit (success or failure) | ||
| 60 | - Supports both audit and test modes | ||
| 61 | |||
| 62 | **Basic Usage:** | ||
| 63 | |||
| 64 | ```bash | ||
| 65 | # Run cargo test suite (recommended for GRASP-01 development) | ||
| 66 | cd grasp-audit && nix develop -c bash test-ngit-relay.sh --mode test | ||
| 67 | 56 | ||
| 68 | # Run audit CLI tool (for quick validation) | 57 | ```rust |
| 69 | cd grasp-audit && nix develop -c bash test-ngit-relay.sh | 58 | use common::TestRelay; |
| 70 | 59 | ||
| 71 | # Get help | 60 | #[tokio::test] |
| 72 | cd grasp-audit && ./test-ngit-relay.sh --help | 61 | async fn test_something() { |
| 62 | let relay = TestRelay::start().await; | ||
| 63 | // relay.url() returns "ws://127.0.0.1:{port}" | ||
| 64 | // ... run test against ngit-grasp ... | ||
| 65 | relay.stop().await; | ||
| 66 | } | ||
| 73 | ``` | 67 | ``` |
| 74 | 68 | ||
| 75 | **Benefits:** | 69 | ### Summary: Which Test Command for What |
| 76 | - No manual relay startup required | ||
| 77 | - Automatic cleanup prevents leftover containers | ||
| 78 | - Random port selection avoids conflicts | ||
| 79 | - Consistent environment across all runs | ||
| 80 | - Proper test isolation | ||
| 81 | 70 | ||
| 82 | **Note:** Manual relay setup is still available but test-ngit-relay.sh is recommended for development workflows. | 71 | | What you're testing | Command | |
| 72 | | --------------------------- | ---------------------------------------------------------------------- | | ||
| 73 | | ngit-grasp (this project) | `cargo test` from project root | | ||
| 74 | | ngit-relay (reference impl) | `cd grasp-audit && nix develop -c bash test-ngit-relay.sh --mode test` | | ||
| 75 | | grasp-audit unit tests | `cd grasp-audit && nix develop -c cargo test --lib` | | ||
| 83 | 76 | ||
| 84 | ### Running Single Test | 77 | ### Running Single Test |
| 85 | 78 | ||
| 86 | ```bash | 79 | ```bash |
| 87 | # From grasp-audit/ | 80 | # ngit-grasp test (from project root) |
| 88 | nix develop -c cargo test --lib specific_test_name -- --nocapture | 81 | cargo test --test nip01_compliance test_websocket_connection -- --nocapture |
| 89 | ``` | ||
| 90 | |||
| 91 | ### Quick Test Verification | ||
| 92 | |||
| 93 | To verify GRASP-01 compliance tests are working correctly: | ||
| 94 | |||
| 95 | ```bash | ||
| 96 | # Run all ignored library tests (includes GRASP-01) | ||
| 97 | cd grasp-audit && RELAY_URL="ws://localhost:18081" nix develop -c cargo test --lib -- --ignored --nocapture 2>&1 | tail -60 | ||
| 98 | 82 | ||
| 99 | # Or run specific GRASP-01 test | 83 | # grasp-audit test (from grasp-audit/) |
| 100 | cd grasp-audit && RELAY_URL="ws://localhost:18081" nix develop -c cargo test --lib test_grasp01_nostr_relay_against_relay -- --ignored --nocapture 2>&1 | tail -60 | 84 | nix develop -c cargo test --lib specific_test_name -- --nocapture |
| 101 | ``` | 85 | ``` |
| 102 | 86 | ||
| 103 | **Expected Output:** | ||
| 104 | - 2-3 tests passing | ||
| 105 | - 15+ tests showing "Not implemented yet" | ||
| 106 | |||
| 107 | ### Troubleshooting | 87 | ### Troubleshooting |
| 108 | 88 | ||
| 109 | **Buffer Size Errors:** | 89 | **Buffer Size Errors:** |
| 110 | If you see mpsc channel buffer size panics on first test run, this is usually transient. Simply run the tests again. | 90 | If you see mpsc channel buffer size panics on first test run, this is usually transient. Simply run the tests again. |
| 111 | 91 | ||
| 112 | **Verify Relay is Running:** | ||
| 113 | Check if relay is accessible before running tests: | ||
| 114 | ```bash | ||
| 115 | nak req -l 1 ws://localhost:18081 # Replace port with your chosen port | ||
| 116 | ``` | ||
| 117 | |||
| 118 | **Port Conflicts:** | 92 | **Port Conflicts:** |
| 119 | Always use a random available port to avoid conflicts with existing services. If a port is busy, choose a different one for docker. | 93 | Both `TestRelay` and `test-ngit-relay.sh` use random ports to avoid conflicts. If you see port errors, ensure no stale processes are running. |
| 120 | 94 | ||
| 121 | ## Code Patterns | 95 | ## Code Patterns |
| 122 | 96 | ||
| @@ -156,8 +130,6 @@ EventBuilder::new(kind, content, &[tags]) | |||
| 156 | EventBuilder::new(kind, content).tags(tags) | 130 | EventBuilder::new(kind, content).tags(tags) |
| 157 | ``` | 131 | ``` |
| 158 | 132 | ||
| 159 | See `docs/archive/2025-11-04-nostr-sdk-upgrade.md` for full migration. | ||
| 160 | |||
| 161 | ### Audit Event Tagging (grasp-audit) | 133 | ### Audit Event Tagging (grasp-audit) |
| 162 | 134 | ||
| 163 | **All audit events automatically include cleanup tags:** | 135 | **All audit events automatically include cleanup tags:** |
| @@ -218,10 +190,10 @@ fn test_audit_tags_automatically_added() { | |||
| 218 | 1. **Workspace compilation:** Can't `cargo build` from root for grasp-audit | 190 | 1. **Workspace compilation:** Can't `cargo build` from root for grasp-audit |
| 219 | 2. **Nix environment:** Must use `nix develop`, not `nix-shell` | 191 | 2. **Nix environment:** Must use `nix develop`, not `nix-shell` |
| 220 | 3. **nostr-sdk API:** Fields not methods in 0.43 | 192 | 3. **nostr-sdk API:** Fields not methods in 0.43 |
| 221 | 4. **Test isolation:** Integration tests need relay, marked with `#[ignore]` | 193 | 4. **Test isolation:** Integration tests use `TestRelay` (ngit-grasp) or `test-ngit-relay.sh` (ngit-relay) |
| 222 | 5. **Work directory:** All session docs go in `work/`, NOT root | 194 | 5. **Work directory:** All session docs go in `work/`, NOT root |
| 223 | 6. **Archive naming:** Use `YYYY-MM-DD-description.md` format | 195 | 6. **Archive naming:** Use `YYYY-MM-DD-description.md` format |
| 224 | 7. **Use test-ngit-relay.sh**: Always use the test script for GRASP-01 tests - it handles cleanup and port management automatically | 196 | 7. **test-ngit-relay.sh tests ngit-relay**: This script tests the reference implementation, NOT ngit-grasp |
| 225 | 197 | ||
| 226 | ## File Restrictions by Mode | 198 | ## File Restrictions by Mode |
| 227 | 199 | ||
| @@ -234,19 +206,14 @@ Code mode can only edit files matching specific patterns (enforced by system): | |||
| 234 | ## Quick Reference | 206 | ## Quick Reference |
| 235 | 207 | ||
| 236 | ```bash | 208 | ```bash |
| 237 | # Recommended: Use test-ngit-relay.sh for all testing | 209 | # Test ngit-grasp (main project) |
| 238 | cd grasp-audit && nix develop -c bash test-ngit-relay.sh --mode test | 210 | cargo test |
| 239 | 211 | ||
| 240 | # Build grasp-audit | 212 | # Build grasp-audit |
| 241 | cd grasp-audit && nix develop -c cargo build | 213 | cd grasp-audit && nix develop -c cargo build |
| 242 | 214 | ||
| 243 | # Manual relay testing (if needed) | 215 | # Run grasp-audit unit tests |
| 244 | # 1. Start relay: docker run --rm -p 18081:8081 ghcr.io/danconwaydev/ngit-relay:latest | 216 | cd grasp-audit && nix develop -c cargo test --lib |
| 245 | # 2. Run all ignored tests: RELAY_URL="ws://localhost:18081" nix develop -c cargo test --lib -- --ignored --nocapture | ||
| 246 | # 3. Or specific test: RELAY_URL="ws://localhost:18081" nix develop -c cargo test --lib test_grasp01_nostr_relay_against_relay -- --ignored --nocapture | ||
| 247 | |||
| 248 | # Run single test | ||
| 249 | cd grasp-audit && nix develop -c cargo test --lib test_name -- --nocapture | ||
| 250 | 217 | ||
| 251 | # Check session files | 218 | # Check session files |
| 252 | ls work/ # Should only have README.md when clean | 219 | ls work/ # Should only have README.md when clean |