# ThinkTool Edge Case Generator
This tool generates comprehensive test cases for boundary conditions in ThinkTool protocols, focusing on scenarios that could cause system failures or infinite loops.
## Boundary Conditions Detected
### 🔄 Infinite Recursion Scenarios
- **Self-refine loops** that never converge (max iterations exceeded)
- **Circular dependencies** in BedRock principle reconstruction
- **Protocol step cycles** that reference each other infinitely
- **Oscillation patterns** that don't terminate
### 🔁 Circular Logic Scenarios
- **Circular reasoning** detection in LaserLogic arguments
- **Self-referential statements** where premises restate conclusions
- **Validation loops** where outputs validate themselves
### 💥 Stack Overflow Scenarios
- **Deep recursion** in principle dependency chains
- **Very long reasoning chains** in protocols
- **Nested protocol execution** exceeding stack limits
- **Deep synthesis** of many perspectives
### ⚠️ Other Boundary Conditions
- **Query length limits** (too short/long for processing)
- **Insufficient perspectives** generated by expansive thinking
- **Confidence thresholds** not met
- **Cross-validation failures** between reasoning steps
- **Memory exhaustion** from large datasets
## Usage
### Basic Usage
```rust
use reasonkit::thinktool::edge_cases::{EdgeCaseGenerator, EdgeCaseGeneratorConfig};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create generator
let mut generator = EdgeCaseGenerator::new();
// Generate all edge cases
let test_cases = generator.generate_all_cases()?;
println!("Generated {} edge case tests", test_cases.len());
// Filter by risk level
let critical_cases = generator.filter_by_risk_level(RiskLevel::Critical);
Ok(())
}
```
### Custom Configuration
```rust
let config = EdgeCaseGeneratorConfig {
max_recursion_depth: 200,
max_query_length: 50000,
min_perspectives_threshold: 5,
low_confidence_threshold: 0.2,
include_memory_tests: true,
include_timeout_tests: true,
};
let mut generator = EdgeCaseGenerator::with_config(config);
```
### Export/Import Test Cases
```rust
// Export to JSON
let json = generator.export_to_json()?;
// Import from JSON
let mut new_generator = EdgeCaseGenerator::new();
new_generator.import_from_json(&json)?;
```
## Test Case Structure
Each generated test case includes:
- **Case Type**: The type of edge case (recursion, circular logic, etc.)
- **Description**: Human-readable explanation
- **Input Context**: ThinkToolContext that triggers the condition
- **Expected Behavior**: How the system should respond
- **Risk Level**: Impact severity (Low/Medium/High/Critical)
- **Target Module**: Which ThinkTool this test targets
## Risk Levels
- **Low**: Minor performance issues, easily handled
- **Medium**: Significant slowdowns or memory usage
- **High**: Potential crashes or infinite loops
- **Critical**: System instability or data corruption
## Running the Demo
```bash
cd reasonkit-core
cargo run --example edge_case_generator_demo
```
## Integration with Testing
The edge case generator is designed to integrate with automated testing:
```rust
#[cfg(test)]
mod edge_case_tests {
use super::*;
use reasonkit::thinktool::edge_cases::{EdgeCaseGenerator, EdgeCaseRunner};
#[test]
fn test_all_edge_cases() {
let config = EdgeCaseGeneratorConfig::default();
let mut runner = EdgeCaseRunner::new(config);
let report = runner.run_all_tests().await?;
assert_eq!(report.failed, 0, "All edge cases should pass");
}
}
```
## Safety Features
- **Recursion Prevention**: Automatic detection of circular dependencies
- **Stack Depth Limits**: Configurable maximum recursion depths
- **Memory Bounds**: Controlled resource usage during testing
- **Timeout Protection**: Automatic termination of long-running tests
- **Graceful Degradation**: Fallback behavior for boundary violations
## Contributing
When adding new ThinkTools or protocols, update the edge case generator to include:
1. Module-specific boundary conditions
2. New recursion scenarios
3. Protocol interaction edge cases
4. Memory usage limits
5. Performance degradation tests