test-optimization
Test Optimization
Advanced test optimization with cargo-nextest, property testing, and benchmarking.
cargo-nextest (Primary Test Runner)
cargo nextest run --all # all tests
cargo nextest run --profile ci # CI with retries + JUnit XML
cargo nextest run --profile nightly # extended timeouts
cargo nextest run -E 'package(do-memory-core)' # filterset DSL
cargo test --doc --all # doctests (nextest limitation)
Configuration (.config/nextest.toml)
[profile.default]
retries = 0
slow-timeout = { period = "60s", terminate-after = 2 }
fail-fast = false
[profile.ci]
retries = 2
slow-timeout = { period = "30s", terminate-after = 3 }
failure-output = "immediate-final"
junit.path = "target/nextest/ci/junit.xml"
[profile.nightly]
retries = 3
slow-timeout = { period = "120s", terminate-after = 2 }
Mutation Testing (cargo-mutants)
Verifies tests actually catch bugs by injecting mutations:
cargo mutants -p do-memory-core --timeout 120 --jobs 4 -- --lib
- Acceptance: <20% missed mutants in core business logic
- Frequency: Nightly CI or pre-release
- Scope: Start with do-memory-core, expand incrementally
Property-Based Testing (proptest)
proptest! {
#[test]
fn serialization_roundtrip(episode in any_episode_strategy()) {
let bytes = postcard::to_allocvec(&episode).unwrap();
let decoded: Episode = postcard::from_bytes(&bytes).unwrap();
assert_eq!(episode, decoded);
}
}
Snapshot Testing (insta)
#[test]
fn test_mcp_response_format() {
let response = build_tool_response("search_patterns", ¶ms);
insta::assert_json_snapshot!(response);
}
cargo insta test # run snapshot tests
cargo insta review # accept/reject changes
Performance Targets
| Operation | Target | Actual |
|---|---|---|
| Episode Creation | < 50ms | ~2.5 µs |
| Step Logging | < 20ms | ~1.1 µs |
| Pattern Extraction | < 1000ms | ~10.4 µs |
| Memory Retrieval | < 100ms | ~721 µs |
Best Practices
- Use nextest profiles for dev/CI/nightly separation
- Implement property tests for serialization roundtrips and state machines
- Use snapshot tests for MCP responses, CLI output
- Run mutation testing before releases
- Monitor test duration and coverage trends
References
More from d-o-hub/rust-self-learning-memory
loop-agent
Execute workflow agents iteratively for refinement and progressive improvement until quality criteria are met. Use when tasks require repetitive refinement, multi-iteration improvements, progressive optimization, or feedback loops until convergence.
51web-search-researcher
Research topics using web search and content fetching to find accurate, current information. Use when you need modern information, official documentation, best practices, technical solutions, or comparisons beyond your training data.
46perplexity-researcher-reasoning-pro
Highest level of research and reasoning capabilities for complex decision-making with significant consequences, strategic planning, technical architecture decisions, multi-stakeholder problems, or high-complexity troubleshooting requiring expert-level judgment and sophisticated reasoning chains. Prioritizes actively maintained repositories and validates website sources for 2025 relevance.
44context-retrieval
Retrieve relevant episodic context from memory for informed decision-making. Use when you need past episodes, patterns, or solutions to similar tasks.
44rust-code-quality
Perform comprehensive Rust code quality reviews against best practices for async Rust, error handling, testing, and project structure
43codebase-analyzer
Analyze implementation details, trace data flow, explain technical workings, locate files, and consolidate codebases. Use when you need to understand HOW code works, find file locations, or assess technical debt.
40