stemedb/.claude/guides/local/testing.md
jordan d3a88585fe feat: Phase 6 UAT - Admission control, HLC recency, cluster coordination
This commit includes comprehensive work on Phase 6 features:

## Admission Control (Phase 6 admission middleware)
- AdmissionStore implementation backed by TrustRankStore
- PoW verification with tier-based difficulty computation
- Trust tier progression (Newcomer → Established → Trusted → Authority)
- API integration with admission status endpoints

## HLC Recency Lens (Phase 6C)
- HlcRecencyLens for distributed system ordering
- Hybrid logical clock integration with causality preservation

## Cluster Coordination (Phase 6C)
- Multi-node cluster tests (availability, partition tolerance)
- CRDT convergence tests for anti-entropy sync
- Gateway handler improvements

## Aphoria Code Linter (Phase 2A)
- RFC/OWASP corpus builders with network fetching and caching
- Concept hierarchy with auto-alias creation on conflict detection
- Multiple security extractors (TLS, JWT, CORS, secrets, rate limiting)

## Code Organization
- Split large files into modules to comply with 500-line limit
- Improved test organization with separate test modules
- Fixed rkyv serialization for EigenTrustState (AgentScore struct)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 00:43:37 -07:00

137 lines
2.4 KiB
Markdown

# Testing Guide
**When to use:** Running and writing tests for StemeDB.
## Quick Start
```bash
# Run all tests
cargo test --workspace
# Run specific crate
cargo test -p stemedb-core
# Run specific test
cargo test test_assertion_round_trips
# Run with output
cargo test -- --nocapture
```
## Test Types
### Unit Tests (in `src/`)
```rust
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_entity_id_equality() {
let a = EntityId("tesla".into());
let b = EntityId("tesla".into());
assert_eq!(a, b);
}
}
```
### Integration Tests (in `tests/`)
```rust
// tests/integration.rs
use stemedb_core::*;
#[test]
fn test_full_write_read_cycle() {
let store = MemoryStore::new();
let assertion = Assertion::new(/* ... */);
store.put(&assertion)?;
let loaded = store.get(&assertion.hash())?;
assert_eq!(assertion, loaded);
}
```
### Property Tests
Use `proptest` for invariant testing:
```rust
use proptest::prelude::*;
proptest! {
#[test]
fn hash_is_deterministic(subject in ".*", predicate in ".*") {
let a1 = Assertion::new(&subject, &predicate, /* ... */);
let a2 = Assertion::new(&subject, &predicate, /* ... */);
assert_eq!(a1.hash(), a2.hash());
}
}
```
## What to Test
### High Priority (Always Test)
- Crash recovery: write -> crash -> restart -> read
- Data integrity: serialization round-trips
- Hash determinism: same input = same hash
- Error paths: invalid signatures, missing data
### Medium Priority
- Index consistency: write assertion -> index updated
- Lens correctness: resolve returns expected winner
### Skip
- Trivial getters
- Compiler-enforced type safety
- Simple delegations
## Test Fixtures
Create shared fixtures in `tests/common/mod.rs`:
```rust
// tests/common/mod.rs
pub fn test_assertion() -> Assertion {
Assertion {
subject: EntityId("test_subject".into()),
predicate: RelationId("test_predicate".into()),
// ...
}
}
pub fn test_agent() -> AgentId {
AgentId([0u8; 32])
}
```
Use in tests:
```rust
mod common;
#[test]
fn test_something() {
let assertion = common::test_assertion();
// ...
}
```
## Coverage
Check coverage with `cargo-llvm-cov`:
```bash
cargo install cargo-llvm-cov
cargo llvm-cov --workspace --html
open target/llvm-cov/html/index.html
```
## Related
- [Setup Guide](./setup.md)
- [Rust Guidelines](../backend/rust-guidelines.md)
- [UAT Reports](./uat-reports.md)