upleb.uk

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

summaryrefslogtreecommitdiff
path: root/docs/tutorials
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-04 10:25:53 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-04 10:25:53 +0000
commit52bad9954cdddf55ab749fd0c6387edbc766632f (patch)
treed9dd2078b70a627a71d1adb9555cee83faec5cd0 /docs/tutorials
parentdb460efdd4cf34d3b6ac8c19b1b8f89f22bc279f (diff)
docs: use Diátaxis structure
Diffstat (limited to 'docs/tutorials')
-rw-r--r--docs/tutorials/README.md116
-rw-r--r--docs/tutorials/first-audit.md270
-rw-r--r--docs/tutorials/getting-started.md209
3 files changed, 595 insertions, 0 deletions
diff --git a/docs/tutorials/README.md b/docs/tutorials/README.md
new file mode 100644
index 0000000..3eb0c5c
--- /dev/null
+++ b/docs/tutorials/README.md
@@ -0,0 +1,116 @@
1# Tutorials
2
3**Learning-oriented documentation** - Learn by doing with step-by-step guidance.
4
5---
6
7## What Are Tutorials?
8
9Tutorials are **lessons** that teach you how to use ngit-grasp through practical, hands-on steps.
10
11**Characteristics:**
12- ✅ Learning-oriented (teach beginners)
13- ✅ Practical (you follow along)
14- ✅ Step-by-step with guaranteed outcomes
15- ✅ Complete from start to finish
16- ✅ Safe to experiment with
17
18**Not tutorials:**
19- ❌ Problem-solving guides (those are How-To)
20- ❌ Technical references (those are Reference)
21- ❌ Conceptual explanations (those are Explanation)
22
23---
24
25## Available Tutorials
26
27### [Getting Started](getting-started.md)
28**Time:** 15-20 minutes
29**Learn:** Set up ngit-grasp development environment, build and test the code
30
31**You'll accomplish:**
32- Clone and build the project
33- Set up Nix development environment
34- Run tests successfully
35- Understand project structure
36
37**Start here if:** You're brand new to ngit-grasp
38
39---
40
41### [Running Your First Audit](first-audit.md)
42**Time:** 10-15 minutes
43**Prerequisites:** [Getting Started](getting-started.md) completed
44**Learn:** Use grasp-audit to check GRASP compliance
45
46**You'll accomplish:**
47- Run compliance tests against a relay
48- Interpret audit results
49- Use the audit tool library
50- Understand GRASP requirements
51
52**Start here if:** You want to test GRASP compliance
53
54---
55
56## Planned Tutorials
57
58### Deploying Your First GRASP Relay
59**Status:** 🔜 Planned (waiting for main server implementation)
60
61**You'll learn:**
62- Deploy ngit-grasp to production
63- Configure for your domain
64- Set up HTTPS with reverse proxy
65- Create your first repository
66
67---
68
69### Contributing Your First PR
70**Status:** 🔜 Planned
71
72**You'll learn:**
73- Find an issue to work on
74- Set up development environment
75- Make changes and test
76- Submit a pull request
77
78---
79
80## How to Use Tutorials
81
821. **Follow in order** - Each step builds on previous ones
832. **Actually do the steps** - Don't just read, type the commands
843. **Expect success** - If something fails, check troubleshooting
854. **Learn by doing** - Understanding comes from practice
86
87**Not sure if this is what you need?**
88- Want to solve a specific problem? → [How-To Guides](../how-to/)
89- Looking for technical details? → [Reference](../reference/)
90- Want to understand the design? → [Explanation](../explanation/)
91
92---
93
94## Contributing Tutorials
95
96When writing a tutorial:
97
98**DO:**
99- ✅ Start with a clear learning goal
100- ✅ Provide complete, tested steps
101- ✅ Include expected output
102- ✅ Add troubleshooting section
103- ✅ Keep it focused (one topic)
104- ✅ Test with a beginner
105
106**DON'T:**
107- ❌ Assume prior knowledge (or state prerequisites clearly)
108- ❌ Skip steps ("obviously you would...")
109- ❌ Explain every detail (link to Explanation docs)
110- ❌ Try to cover everything (keep scope small)
111
112See [Diátaxis: Tutorials](https://diataxis.fr/tutorials/) for detailed guidance.
113
114---
115
116*Part of the [ngit-grasp documentation](../README.md) using the [Diátaxis](https://diataxis.fr/) framework.*
diff --git a/docs/tutorials/first-audit.md b/docs/tutorials/first-audit.md
new file mode 100644
index 0000000..194a976
--- /dev/null
+++ b/docs/tutorials/first-audit.md
@@ -0,0 +1,270 @@
1# Tutorial: Running Your First GRASP Audit
2
3**Purpose:** Learn how to use grasp-audit to check GRASP compliance
4**Time:** 10-15 minutes
5**Prerequisites:** [Getting Started Tutorial](getting-started.md) completed
6
7---
8
9## What You'll Learn
10
11By the end of this tutorial, you will:
12- ✅ Understand what GRASP compliance means
13- ✅ Run a compliance audit against a relay
14- ✅ Interpret audit results
15- ✅ Know how to use the audit tool in your own projects
16
17---
18
19## Step 1: Understanding GRASP Compliance
20
21GRASP (Git Relays Authorized via Signed-Nostr Proofs) defines requirements for Git hosting with Nostr authorization.
22
23**Key compliance areas:**
24- **NIP-01**: Basic Nostr relay functionality
25- **NIP-34**: Git repository events (kind 30317, 30318)
26- **Git HTTP**: Smart HTTP protocol support
27- **Authorization**: Push validation against state events
28
29The `grasp-audit` tool verifies all of these automatically.
30
31---
32
33## Step 2: Start a Test Relay
34
35For this tutorial, we'll use a standard Nostr relay:
36
37```bash
38# In a separate terminal window:
39docker run --rm -p 7000:7000 scsibug/nostr-rs-relay
40
41# Keep this running throughout the tutorial
42```
43
44**What this does:** Starts a NIP-01 compliant Nostr relay on port 7000.
45
46**Note:** This relay doesn't fully implement GRASP (no Git hosting), but we can test the Nostr parts.
47
48---
49
50## Step 3: Run the Audit Tool
51
52Navigate to the grasp-audit directory and run:
53
54```bash
55cd grasp-audit
56nix develop
57
58# Run the integration tests (which include audits)
59cargo test --ignored -- --test-threads=1
60```
61
62**What you'll see:**
63```
64running 3 tests
65test tests::test_isolation_basic ... ok
66test tests::test_isolation_cleanup ... ok
67test tests::test_isolation_concurrent ... ok
68
69test result: ok. 3 passed; 0 failed; 0 ignored
70```
71
72**What just happened?** The audit tool:
731. Connected to the relay on port 7000
742. Checked NIP-01 compliance (event submission, retrieval)
753. Tested isolation between test runs
764. Verified cleanup mechanisms
77
78---
79
80## Step 4: Use the Audit Library
81
82Let's write a simple audit script. Create a new file:
83
84```bash
85# From grasp-audit directory
86cat > examples/my_audit.rs << 'EOF'
87use grasp_audit::prelude::*;
88
89#[tokio::main]
90async fn main() -> Result<(), Box<dyn std::error::Error>> {
91 // Create an audit client
92 let client = AuditClient::new("ws://localhost:7000").await?;
93
94 println!("✅ Connected to relay");
95
96 // Test basic event submission
97 let test_event = client.create_test_event("Hello GRASP!").await?;
98 println!("✅ Created test event: {}", test_event.id);
99
100 // Verify we can retrieve it
101 let retrieved = client.get_event(&test_event.id).await?;
102 println!("✅ Retrieved event successfully");
103
104 println!("\n🎉 Basic audit passed!");
105
106 Ok(())
107}
108EOF
109```
110
111**Note:** This is a simplified example. The actual audit tool has more sophisticated checks.
112
113---
114
115## Step 5: Understanding Audit Results
116
117When audits fail, you'll see detailed error messages:
118
119```rust
120// Example failure output:
121Error: GRASP-01 compliance failed
122 - NIP-01: ✅ PASS
123 - NIP-34 kind 30317: ❌ FAIL - Relay rejected repository announcement
124 - NIP-34 kind 30318: ❌ FAIL - Relay rejected state event
125 - Git HTTP: ❌ NOT TESTED - No Git endpoint found
126```
127
128**How to interpret:**
129- ✅ **PASS**: Feature works correctly
130- ❌ **FAIL**: Feature broken or missing
131- ⚠️ **PARTIAL**: Works but with issues
132- ⏭️ **SKIPPED**: Couldn't test (dependency failed)
133
134---
135
136## Step 6: Audit a GRASP-Compliant Relay
137
138To audit a real GRASP relay (when available):
139
140```bash
141# Example (relay doesn't exist yet):
142cargo run --bin grasp-audit -- --relay wss://gitnostr.com
143
144# Or use the library:
145let client = AuditClient::new("wss://gitnostr.com").await?;
146let results = client.run_full_audit().await?;
147println!("{}", results.summary());
148```
149
150**What this would check:**
151- Nostr relay functionality (NIP-01)
152- Git event acceptance (NIP-34)
153- Git HTTP endpoint availability
154- Push authorization logic
155- Multi-maintainer support
156
157---
158
159## Step 7: Automated Testing
160
161The audit tool is designed for CI/CD integration:
162
163```bash
164# Run all tests (unit + integration)
165cargo test --all
166
167# Run only integration tests
168cargo test --ignored
169
170# Generate coverage report
171cargo tarpaulin --ignored --out Html
172```
173
174**Use in CI:**
175```yaml
176# Example GitHub Actions
177- name: Run GRASP Compliance Tests
178 run: |
179 docker run -d -p 7000:7000 scsibug/nostr-rs-relay
180 cd grasp-audit
181 cargo test --ignored
182```
183
184---
185
186## What You've Accomplished
187
188Congratulations! You now:
189
190✅ Understand GRASP compliance requirements
191✅ Can run the audit tool against a relay
192✅ Know how to interpret audit results
193✅ Can integrate audits into your workflow
194
195---
196
197## Next Steps
198
199### Learn more about testing:
200- Read [Compliance Testing How-To](../how-to/test-compliance.md)
201- Review [Test Strategy](../reference/test-strategy.md)
202
203### Understand the protocols:
204- Read [GRASP Protocol Reference](../reference/grasp-protocol.md)
205- Review [Git Protocol Reference](../reference/git-protocol.md)
206
207### Contribute to grasp-audit:
208- Check open issues
209- Add new compliance checks
210- Improve error messages
211
212---
213
214## Troubleshooting
215
216### "Connection refused" errors
217- Make sure the relay is running: `docker ps`
218- Check the port: `netstat -an | grep 7000`
219- Verify the URL: `ws://localhost:7000` (not `wss://`)
220
221### Tests timeout
222- Relay might be slow to start
223- Try running tests again after 5 seconds
224- Check Docker logs: `docker logs <container-id>`
225
226### "Event rejected" errors
227- Expected for non-GRASP relays
228- The relay might not support NIP-34
229- This is normal for the tutorial relay
230
231---
232
233## Deep Dive: How Audits Work
234
235The audit tool uses **isolated test environments**:
236
237```rust
238// Each test gets a unique identifier
239let isolation = IsolationContext::new("my-test");
240
241// Events are tagged with this identifier
242let event = isolation.create_event("test content").await?;
243
244// Cleanup removes only this test's events
245isolation.cleanup().await?;
246```
247
248**Why isolation matters:**
249- Tests don't interfere with each other
250- Can run tests in parallel
251- Easy cleanup (no leftover data)
252
253See [Test Strategy Reference](../reference/test-strategy.md) for details.
254
255---
256
257## Summary
258
259You've learned how to:
260- Run GRASP compliance audits
261- Interpret audit results
262- Use the audit library
263- Integrate audits into testing workflows
264
265**Next tutorial:** [Deploying ngit-grasp](../how-to/deploy.md) (when main server is ready)
266
267---
268
269*Part of the [ngit-grasp tutorials](./)*
270*Previous: [Getting Started](getting-started.md)*
diff --git a/docs/tutorials/getting-started.md b/docs/tutorials/getting-started.md
new file mode 100644
index 0000000..1a56985
--- /dev/null
+++ b/docs/tutorials/getting-started.md
@@ -0,0 +1,209 @@
1# Tutorial: Getting Started with ngit-grasp
2
3**Purpose:** Learn the basics of ngit-grasp through hands-on setup
4**Time:** 15-20 minutes
5**Prerequisites:** Basic Git and command-line knowledge
6
7---
8
9## What You'll Learn
10
11By the end of this tutorial, you will:
12- ✅ Have a working ngit-grasp development environment
13- ✅ Understand the basic project structure
14- ✅ Run the test suite successfully
15- ✅ Know where to go next
16
17---
18
19## Step 1: Clone the Repository
20
21First, get the source code:
22
23```bash
24git clone https://gitworkshop.dev/ngit-grasp
25cd ngit-grasp
26```
27
28**What just happened?** You cloned the ngit-grasp repository from the GRASP-enabled Git server.
29
30---
31
32## Step 2: Set Up Nix Development Environment
33
34ngit-grasp uses Nix flakes for reproducible development environments.
35
36```bash
37# Enter the development environment
38nix develop
39
40# You should see a new shell with all dependencies available
41```
42
43**What just happened?** Nix read `flake.nix` and created a shell with:
44- Rust toolchain (cargo, rustc)
45- Git
46- All required system libraries
47
48**Tip:** If `nix develop` doesn't work, you might be using an old Nix version. See the [Nix Flakes How-To](../how-to/nix-flakes.md) for help.
49
50---
51
52## Step 3: Explore the Project Structure
53
54Take a look around:
55
56```bash
57# View the project structure
58ls -la
59
60# Key directories:
61# - src/ - Main ngit-grasp source code (coming soon)
62# - grasp-audit/ - Compliance testing tool (working)
63# - docs/ - Documentation (you are here!)
64```
65
66**What you're seeing:**
67- `grasp-audit/` is a **subproject** with its own Cargo workspace
68- Main ngit-grasp server implementation is planned but not yet started
69- Documentation uses Diátaxis framework (tutorials, how-to, reference, explanation)
70
71---
72
73## Step 4: Work with grasp-audit
74
75The compliance testing tool is the first working component. Let's try it:
76
77```bash
78# Navigate to grasp-audit
79cd grasp-audit
80
81# Enter its development environment
82nix develop
83
84# Build the project
85cargo build
86
87# Run unit tests
88cargo test
89```
90
91**What just happened?**
92- `grasp-audit` has its own `flake.nix` for isolated dependencies
93- Unit tests run without external dependencies
94- Integration tests (marked `#[ignore]`) require a Nostr relay
95
96---
97
98## Step 5: Run Your First Audit (Optional)
99
100If you want to try the audit tool against a real relay:
101
102```bash
103# In a separate terminal, start a test relay:
104docker run --rm -p 7000:7000 scsibug/nostr-rs-relay
105
106# Back in grasp-audit directory:
107cargo test --ignored -- --test-threads=1
108```
109
110**What just happened?** Integration tests connected to the relay on port 7000 and verified GRASP compliance.
111
112**Note:** This step is optional. The relay must be running for these tests to pass.
113
114---
115
116## Step 6: Explore the Code
117
118Let's look at a simple example:
119
120```bash
121# From grasp-audit directory
122cat examples/simple_audit.rs
123```
124
125This shows how to use the `grasp-audit` library to check GRASP compliance.
126
127---
128
129## Step 7: Read the Documentation
130
131Now that you have a working setup, explore the documentation:
132
133```bash
134# From project root
135cd ..
136ls docs/
137```
138
139**Recommended reading order:**
1401. [Architecture Overview](../explanation/architecture.md) - Understand the design
1412. [Inline Authorization](../explanation/inline-authorization.md) - Key decision
1423. [Git Protocol Reference](../reference/git-protocol.md) - Technical details
143
144---
145
146## What You've Accomplished
147
148Congratulations! You now have:
149
150✅ A working Nix development environment
151✅ Built and tested the grasp-audit tool
152✅ Understanding of the project structure
153✅ Knowledge of where to find more information
154
155---
156
157## Next Steps
158
159### If you want to contribute:
1601. Read [Architecture Overview](../explanation/architecture.md)
1612. Check open issues on the repository
1623. Review [Design Decisions](../explanation/decisions.md)
163
164### If you want to deploy:
1651. Follow [Deployment How-To](../how-to/deploy.md)
1662. Review [Configuration Reference](../reference/configuration.md)
167
168### If you want to understand GRASP:
1691. Read [GRASP Protocol Reference](../reference/grasp-protocol.md)
1702. Review [Comparison with ngit-relay](../explanation/comparison.md)
171
172### If you want to run compliance tests:
1731. Follow [Running Your First Audit Tutorial](first-audit.md)
1742. Review [Compliance Testing How-To](../how-to/test-compliance.md)
175
176---
177
178## Troubleshooting
179
180### "nix develop" doesn't work
181- You might need Nix with flakes enabled
182- See [Nix Flakes How-To](../how-to/nix-flakes.md)
183
184### Build errors in grasp-audit
185- Make sure you're in the `grasp-audit` directory
186- Run `nix develop` first
187- Check that you have network access (Cargo needs to download crates)
188
189### Tests fail
190- Unit tests should always pass
191- Integration tests (`--ignored`) require a relay on port 7000
192- Use `--test-threads=1` for integration tests
193
194---
195
196## Summary
197
198You've successfully set up ngit-grasp and learned:
199- How to use Nix flakes for development
200- The project structure (main server + grasp-audit tool)
201- How to build and test the code
202- Where to find documentation
203
204**Ready for more?** Try the [First Audit Tutorial](first-audit.md) next!
205
206---
207
208*Part of the [ngit-grasp tutorials](./)*
209*Next: [Running Your First Audit](first-audit.md)*