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>
2.4 KiB
2.4 KiB
Testing Guide
When to use: Running and writing tests for StemeDB.
Quick Start
# 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/)
#[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/)
// 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:
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:
// 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:
mod common;
#[test]
fn test_something() {
let assertion = common::test_assertion();
// ...
}
Coverage
Check coverage with cargo-llvm-cov:
cargo install cargo-llvm-cov
cargo llvm-cov --workspace --html
open target/llvm-cov/html/index.html