From 2eaff5b79fed364d5eba5eb38e4b7bf76326884d Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 3 Dec 2025 11:19:40 +0000 Subject: remove docs archive --- docs/archive/2025-11-04-compilation-fixes.md | 421 --------------------------- 1 file changed, 421 deletions(-) delete mode 100644 docs/archive/2025-11-04-compilation-fixes.md (limited to 'docs/archive/2025-11-04-compilation-fixes.md') diff --git a/docs/archive/2025-11-04-compilation-fixes.md b/docs/archive/2025-11-04-compilation-fixes.md deleted file mode 100644 index 18584eb..0000000 --- a/docs/archive/2025-11-04-compilation-fixes.md +++ /dev/null @@ -1,421 +0,0 @@ -# Compilation Fixes for grasp-audit - -**Date:** November 4, 2025 -**Status:** ✅ SUPERSEDED - See NOSTR_SDK_0.43_UPGRADE.md -**Build Status:** ✅ Successful -**Unit Tests:** ✅ 12 passed, 0 failed, 1 ignored - ---- - -## ⚠️ NOTE: This document is obsolete - -This document described fixes for nostr-sdk 0.35. The project has been upgraded to **nostr-sdk 0.43**. - -**See:** [NOSTR_SDK_0.43_UPGRADE.md](NOSTR_SDK_0.43_UPGRADE.md) for current status. - ---- - -# Original Documentation (nostr-sdk 0.35) - ---- - -## Summary - -Fixed all compilation errors in the `grasp-audit` crate caused by API changes in `nostr-sdk` v0.35. The project now builds successfully and all unit tests pass. - ---- - -## Issues Fixed - -### 1. EventBuilder::to_event() No Longer Async - -**Error:** -``` -error[E0277]: `Result` is not a future - --> src/audit.rs:122:14 - | -122 | .await?; - | ^^^^^ `Result<...>` is not a future -``` - -**Fix:** -- Changed `AuditEventBuilder::build()` from `async fn` to regular `fn` -- Removed `.await` from `EventBuilder::to_event()` calls -- Updated all call sites in tests - -**Files Changed:** -- `src/audit.rs` - Changed function signature and removed `.await` -- `src/specs/nip01_smoke.rs` - Removed `.await` from all event building calls -- `src/audit.rs` (tests) - Changed test from `#[tokio::test]` to `#[test]` - ---- - -### 2. Relay::is_connected() Now Async - -**Error:** -``` -error[E0308]: mismatched types - --> src/client.rs:43:33 - | -43 | relays.values().any(|r| r.is_connected()) - | ^^^^^^^^^^^^^^^^ expected `bool`, found future -``` - -**Fix:** -```rust -// Before: -relays.values().any(|r| r.is_connected()) - -// After: -for relay in relays.values() { - if relay.is_connected().await { - return true; - } -} -false -``` - -**Files Changed:** -- `src/client.rs` - Rewrote `is_connected()` to properly await async calls - ---- - -### 3. Client::send_event() Returns Output - -**Error:** -``` -error[E0308]: mismatched types - --> src/client.rs:57:12 - | -57 | Ok(event_id) - | -- ^^^^^^^^ expected `EventId`, found `Output` -``` - -**Fix:** -```rust -// Before: -let event_id = self.client.send_event(event).await?; -Ok(event_id) - -// After: -let output = self.client.send_event(event).await?; -let event_id = *output.id(); -Ok(event_id) -``` - -**Files Changed:** -- `src/client.rs` - Extract EventId from Output wrapper - ---- - -### 4. Client::get_events_of() Signature Changed - -**Error:** -``` -error[E0308]: mismatched types - --> src/client.rs:82:42 - | - 82 | .get_events_of(vec![filter], Some(Duration::from_secs(5))) - | ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `EventSource`, found `Option` -``` - -**Fix:** -```rust -// Before: -.get_events_of(vec![filter], Some(Duration::from_secs(5))) - -// After: -.get_events_of(vec![filter], EventSource::relays(Some(Duration::from_secs(5)))) -``` - -**Files Changed:** -- `src/client.rs` - Updated both `query()` and `subscribe()` methods - ---- - -### 5. Event Struct Cannot Be Constructed Directly - -**Error:** -``` -error: cannot construct `nostr_sdk::Event` with struct literal syntax due to private fields - --> src/specs/nip01_smoke.rs:216:21 - | -216 | event = Event { - | ^^^^^ - | - = note: ...and other private fields `deser_order` and `tags_indexes` that were not provided -``` - -**Fix:** -Changed from direct struct construction to JSON serialization/deserialization: - -```rust -// Before: -event = Event { - id: event.id, - pubkey: event.pubkey, - // ... other fields - sig: wrong_event.sig, // Wrong signature! -}; - -// After: -let invalid_event_json = serde_json::json!({ - "id": event.id.to_hex(), - "pubkey": event.pubkey.to_hex(), - "created_at": event.created_at.as_u64(), - "kind": event.kind.as_u16(), - "tags": event.tags, - "content": event.content, - "sig": wrong_event.sig.to_string(), // Wrong signature! -}); - -let invalid_event: Event = serde_json::from_value(invalid_event_json) - .map_err(|e| format!("Failed to create invalid event: {}", e))?; -``` - -**Files Changed:** -- `src/specs/nip01_smoke.rs` - Updated `test_reject_invalid_signature()` and `test_reject_invalid_event_id()` - ---- - -### 6. Kind::as_u64() Deprecated - -**Warning:** -``` -warning: use of deprecated method `nostr_sdk::Kind::as_u64` - --> src/specs/nip01_smoke.rs:216:36 - | -216 | "kind": event.kind.as_u64(), - | ^^^^^^ -``` - -**Fix:** -```rust -// Before: -event.kind.as_u64() - -// After: -event.kind.as_u16() -``` - -**Files Changed:** -- `src/specs/nip01_smoke.rs` - Changed to `as_u16()` in JSON serialization - ---- - -### 7. Signature::to_hex() Method Not Found - -**Error:** -``` -error[E0599]: no method named `to_hex` found for struct `nostr_sdk::secp256k1::schnorr::Signature` - --> src/specs/nip01_smoke.rs:219:40 - | -219 | "sig": wrong_event.sig.to_hex(), - | ^^^^^^ method not found -``` - -**Fix:** -```rust -// Before: -wrong_event.sig.to_hex() - -// After: -wrong_event.sig.to_string() -``` - -**Files Changed:** -- `src/specs/nip01_smoke.rs` - Changed to `to_string()` for signature serialization - ---- - -### 8. Future Type Mismatch in Test Collection - -**Error:** -``` -error[E0308]: mismatched types - --> src/specs/nip01_smoke.rs:20:13 - | -20 | Self::test_send_receive_event(client), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected future, found a different future -``` - -**Fix:** -Changed from parallel execution with `join_all` to sequential execution: - -```rust -// Before: -let tests = vec![ - Self::test_websocket_connection(client), - Self::test_send_receive_event(client), - // ... -]; -let test_results = futures::future::join_all(tests).await; - -// After: -results.add(Self::test_websocket_connection(client).await); -results.add(Self::test_send_receive_event(client).await); -// ... -``` - -**Files Changed:** -- `src/specs/nip01_smoke.rs` - Simplified `run_all()` to sequential execution - ---- - -### 9. Test Accessing Private Field - -**Error:** -``` -error[E0616]: field `config` of struct `audit::AuditEventBuilder` is private - --> src/client.rs:150:28 - | -150 | assert_eq!(builder.config.run_id, config.run_id); - | ^^^^^^ private field -``` - -**Fix:** -```rust -// Before: -assert_eq!(builder.config.run_id, config.run_id); - -// After: -let _builder = client.event_builder(Kind::TextNote, "test content"); -// Builder should be created successfully -// (We can't test the internal config field as it's private, which is correct) -``` - -**Files Changed:** -- `src/client.rs` - Simplified test to not access private fields - ---- - -### 10. Unused Import Warning - -**Warning:** -``` -warning: unused import: `std::time::Duration` - --> src/audit.rs:4:5 - | -4 | use std::time::Duration; -``` - -**Fix:** -Removed unused import since `Duration` is no longer needed in `audit.rs`. - -**Files Changed:** -- `src/audit.rs` - Removed unused import - ---- - -## Build Results - -### Successful Build -```bash -cd grasp-audit && nix develop --command cargo build -# ✅ Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.65s -``` - -### Unit Tests Pass -```bash -cd grasp-audit && nix develop --command cargo test --lib -# ✅ test result: ok. 12 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out -``` - -### CLI Works -```bash -./target/debug/grasp-audit --help -# ✅ Shows help text correctly - -./target/debug/grasp-audit audit --help -# ✅ Shows audit command options -``` - ---- - -## Files Modified - -1. **src/audit.rs** - - Changed `build()` from async to sync - - Removed unused `Duration` import - - Changed test from `#[tokio::test]` to `#[test]` - -2. **src/client.rs** - - Fixed `is_connected()` to properly await async calls - - Fixed `send_event()` to extract EventId from Output - - Fixed `query()` and `subscribe()` to use `EventSource::relays()` - - Simplified test to not access private fields - -3. **src/specs/nip01_smoke.rs** - - Removed `.await` from all `build()` calls - - Changed `run_all()` from parallel to sequential execution - - Changed Event construction to use JSON serialization - - Changed `Kind::as_u64()` to `as_u16()` - - Changed `Signature::to_hex()` to `to_string()` - ---- - -## Next Steps - -### Immediate Testing -1. ✅ Unit tests pass (12/12) -2. ⏳ Integration tests (need relay) -3. ⏳ CLI testing (need relay) - -### To Run Integration Tests -```bash -# Terminal 1: Start a test relay -docker run -p 7000:7000 scsibug/nostr-rs-relay - -# Terminal 2: Run integration tests -cd grasp-audit -nix develop --command cargo test --ignored -``` - -### To Run CLI -```bash -cd grasp-audit -nix develop --command cargo run -- audit --relay ws://localhost:7000 --mode ci --spec nip01-smoke -``` - ---- - -## Compatibility Notes - -### nostr-sdk v0.35 API Changes -The fixes address the following breaking changes in nostr-sdk v0.35: - -1. **EventBuilder** - `to_event()` is no longer async -2. **Relay** - `is_connected()` is now async -3. **Client** - `send_event()` returns `Output` wrapper -4. **Client** - `get_events_of()` requires `EventSource` parameter -5. **Event** - Cannot be constructed directly (private fields) -6. **Kind** - `as_u64()` deprecated in favor of `as_u16()` -7. **Signature** - Uses `to_string()` instead of `to_hex()` - -### Backward Compatibility -These changes are **breaking** and the code is not compatible with older versions of nostr-sdk. The minimum version is now `nostr-sdk = "0.35"`. - ---- - -## Testing Status - -| Test Suite | Status | Count | Notes | -|------------|--------|-------|-------| -| Unit Tests | ✅ Pass | 12/12 | All pass without relay | -| Integration Tests | ⏳ Pending | 6/6 | Require running relay | -| Build | ✅ Pass | - | Clean build with no warnings | -| CLI | ✅ Pass | - | Help text works correctly | - ---- - -## Conclusion - -All compilation errors have been successfully fixed. The `grasp-audit` crate now: - -- ✅ Compiles cleanly with nostr-sdk v0.35 -- ✅ Passes all unit tests (12/12) -- ✅ CLI binary builds and shows help -- ✅ Example builds successfully -- ⏳ Ready for integration testing (requires relay) - -The next step is to run the integration tests against a live Nostr relay to verify the smoke tests work correctly. -- cgit v1.2.3