use serde_json::{json, Value};
pub fn generate_realistic_queries() -> Vec<(String, Value)> {
vec![
("observe", json!({
"query": "entities with Transform"
})),
("observe", json!({
"query": "entities with (Transform and Mesh)"
})),
("observe", json!({
"query": "entities with Name containing 'player'"
})),
("observe", json!({
"query": "entities with Health < 50"
})),
("observe", json!({
"query": "entities in range 10 of (0, 0, 0)"
})),
("experiment", json!({
"type": "performance",
"systems": ["movement", "physics", "rendering"],
"duration": 1000
})),
("experiment", json!({
"type": "memory",
"duration": 2000,
"include_entities": true
})),
("resource_metrics", json!({})),
("health_check", json!({})),
("observe", json!({
"query": "entities with (Combat and Health > 80) or (Merchant and Inventory.gold > 100)",
"sort": "health",
"limit": 50
})),
("observe", json!({
"query": "all entities in faction 'warriors'",
"include_relationships": true
})),
("diagnostic_report", json!({
"action": "generate",
"include_performance": true,
"include_memory": true
})),
("anomaly", json!({
"metric": "frame_time",
"threshold": 16.67,
"window": 1000
})),
("replay", json!({
"session_id": "debug_session_001",
"time_range": {"start": 0, "end": 30000}
})),
("checkpoint", json!({
"name": "before_optimization_test",
"include_world_state": true
})),
("orchestrate", json!({
"tool": "observe",
"arguments": {"query": "entities with Position.y > 10"},
"follow_up": "experiment"
})),
("pipeline", json!({
"template": "performance_analysis",
"parameters": {
"duration": 5000,
"entity_types": ["warrior", "merchant", "villager"]
}
})),
("stress", json!({
"type": "entity_spawn",
"count": 100,
"entity_type": "complex"
})),
("stress", json!({
"type": "continuous_spawn",
"intensity": 2,
"duration": 30000
})),
]
}
pub fn generate_stress_queries() -> Vec<(String, Value)> {
vec![
("observe", json!({
"query": "all entities",
"cache_ttl": 0 })),
("observe", json!({
"query": "entities with any component",
"include_all_data": true
})),
("observe", json!({
"query": "entities with relationships to entities with Combat > 50",
"recursive_depth": 3,
"include_relationship_data": true
})),
("observe", json!({
"query": "entities with Inventory",
"include_inventory_contents": true,
"expand_references": true
})),
("experiment", json!({
"type": "pathfinding_analysis",
"start_points": (0..20).map(|i| json!([i * 2, 0, i * 3])).collect::<Vec<_>>(),
"end_points": (0..20).map(|i| json!([i * -2, 0, i * -3])).collect::<Vec<_>>(),
"algorithm": "a_star"
})),
("observe", json!({
"query": "history of all entities over last 60 seconds",
"include_state_changes": true,
"resolution": "high"
})),
("observe", json!({
"query": format!("entities with id in range {} to {}", 0, 10000),
"batch_size": 1000
})),
("experiment", json!({
"type": "system_dependency_analysis",
"include_performance_impact": true,
"analyze_bottlenecks": true,
"correlation_analysis": true
})),
("diagnostic_report", json!({
"action": "export_all_data",
"format": "detailed_json",
"include_history": true,
"compression": false
})),
]
}
pub fn generate_optimization_test_queries() -> Vec<(String, Value)> {
vec![
("observe", json!({
"query": "entities with Transform",
"test_id": "cache_test_1"
})),
("observe", json!({
"query": "entities with Transform", "test_id": "cache_test_1_repeat"
})),
("observe", json!({
"query": "small dataset",
"expected_response_size": "small"
})),
("observe", json!({
"query": "entities with detailed data",
"include_all_components": true,
"expected_response_size": "large"
})),
("health_check", json!({
"initialize_components": false
})),
("observe", json!({
"query": "first entity access",
"force_initialization": true
})),
("observe", json!({
"query": "test basic functionality"
})),
("experiment", json!({
"type": "feature_flag_test",
"check_enabled_features": true
})),
]
}
pub fn generate_complexity_queries() -> Vec<(String, Value)> {
let mut queries = Vec::new();
for i in 0..10 {
queries.push(("observe", json!({
"query": format!("entities with component_type_{}", i),
"complexity": "simple"
})));
}
for i in 0..5 {
queries.push(("observe", json!({
"query": format!("entities with component_type_{} sorted by value", i),
"sort": "value",
"complexity": "medium"
})));
}
queries.push(("observe", json!({
"query": "entities with relationships to entities with relationships",
"recursive": true,
"max_depth": 3,
"complexity": "high"
})));
queries.push(("experiment", json!({
"type": "cross_reference_analysis",
"analyze_all_relationships": true,
"include_indirect_dependencies": true,
"complexity": "very_high"
})));
queries
}
pub fn generate_edge_case_queries() -> Vec<(String, Value)> {
vec![
("observe", json!({
"query": "entities with NonExistentComponent"
})),
("observe", json!({
"query": "invalid query syntax ((("
})),
("observe", json!({
"query": "all entities",
"limit": 1000000
})),
("experiment", json!({
"type": "nonexistent_experiment_type"
})),
("observe", json!({
"query": null
})),
("observe", json!({
"query": "a".repeat(10000)
})),
("observe", json!({
"query": {
"nested": {
"very": {
"deeply": {
"nested": "query"
}
}
}
}
})),
("experiment", json!({
"type": "circular_test",
"parameters": {
"reference": "self"
}
})),
]
}
pub fn generate_sequential_queries() -> Vec<Vec<(String, Value)>> {
vec![
vec![
("health_check", json!({})), ("resource_metrics", json!({})), ("observe", json!({"query": "entities with Transform"})), ("observe", json!({"query": "entities with Transform"})), ],
vec![
("observe", json!({"query": "entity count"})),
("observe", json!({"query": "entities with Transform"})),
("observe", json!({"query": "entities with (Transform and Mesh)"})),
("observe", json!({"query": "entities with (Transform and Mesh and Health)"})),
],
vec![
("observe", json!({"query": "all entities"})), ("stress", json!({"type": "entity_spawn", "count": 10})), ("observe", json!({"query": "all entities"})), ],
vec![
("checkpoint", json!({"name": "performance_baseline"})),
("experiment", json!({"type": "performance", "duration": 1000})),
("stress", json!({"type": "continuous_spawn", "intensity": 1})),
("experiment", json!({"type": "performance", "duration": 1000})),
("diagnostic_report", json!({"action": "compare_checkpoints"})),
],
]
}
pub fn generate_time_based_queries(duration_seconds: u64) -> Vec<(u64, String, Value)> {
let mut queries = Vec::new();
let mut time_offset = 0;
while time_offset < duration_seconds {
queries.push((time_offset, "health_check".to_string(), json!({})));
queries.push((time_offset + 2, "resource_metrics".to_string(), json!({})));
time_offset += 5;
}
time_offset = 1;
let entity_queries = [
"entities with Transform",
"entities with Health < 50",
"entities in combat",
"entities with Inventory",
];
let mut query_index = 0;
while time_offset < duration_seconds {
queries.push((
time_offset,
"observe".to_string(),
json!({"query": entity_queries[query_index % entity_queries.len()]}),
));
query_index += 1;
time_offset += 3;
}
time_offset = 10;
while time_offset < duration_seconds {
queries.push((
time_offset,
"experiment".to_string(),
json!({"type": "performance", "duration": 2000}),
));
time_offset += 15;
}
queries.sort_by_key(|(time, _, _)| *time);
queries
}
pub fn generate_workload_pattern(pattern_type: &str) -> Vec<(String, Value)> {
match pattern_type {
"debugging_session" => vec![
("health_check", json!({})),
("observe", json!({"query": "all entities", "limit": 10})),
("observe", json!({"query": "entities with Health < 30"})),
("experiment", json!({"type": "performance", "duration": 3000})),
("observe", json!({"query": "entities in combat"})),
("diagnostic_report", json!({"action": "generate"})),
("checkpoint", json!({"name": "debug_checkpoint"})),
],
"performance_analysis" => vec![
("resource_metrics", json!({})),
("experiment", json!({"type": "performance", "systems": ["movement", "physics"]})),
("observe", json!({"query": "entities with high CPU impact"})),
("experiment", json!({"type": "memory", "duration": 5000})),
("observe", json!({"query": "entities with large memory footprint"})),
("diagnostic_report", json!({"action": "performance_summary"})),
],
"stress_testing" => vec![
("health_check", json!({})),
("stress", json!({"type": "entity_spawn", "count": 100})),
("observe", json!({"query": "entity count"})),
("stress", json!({"type": "continuous_spawn", "intensity": 3})),
("experiment", json!({"type": "performance", "duration": 10000})),
("stress", json!({"type": "entity_despawn", "count": 50})),
("diagnostic_report", json!({"action": "stress_test_report"})),
],
"cache_warming" => {
let mut queries = Vec::new();
for query in ["entities with Transform", "entities with Health", "entities with Inventory"] {
queries.push(("observe", json!({"query": query})));
queries.push(("observe", json!({"query": query}))); }
queries
},
_ => generate_realistic_queries(),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_generate_realistic_queries() {
let queries = generate_realistic_queries();
assert!(!queries.is_empty(), "Should generate some queries");
let observe_count = queries.iter().filter(|(cmd, _)| cmd == "observe").count();
let experiment_count = queries.iter().filter(|(cmd, _)| cmd == "experiment").count();
assert!(observe_count > 0, "Should have observe queries");
assert!(experiment_count > 0, "Should have experiment queries");
}
#[test]
fn test_generate_complexity_queries() {
let queries = generate_complexity_queries();
assert!(!queries.is_empty(), "Should generate complexity queries");
let simple_count = queries.iter()
.filter(|(_, args)| args.get("complexity").and_then(|c| c.as_str()) == Some("simple"))
.count();
let complex_count = queries.iter()
.filter(|(_, args)| args.get("complexity").and_then(|c| c.as_str()).map_or(false, |c| c.contains("high")))
.count();
assert!(simple_count > 0, "Should have simple queries");
assert!(complex_count > 0, "Should have complex queries");
}
#[test]
fn test_generate_time_based_queries() {
let queries = generate_time_based_queries(30);
assert!(!queries.is_empty(), "Should generate time-based queries");
for i in 1..queries.len() {
assert!(queries[i].0 >= queries[i-1].0, "Times should be in ascending order");
}
for (time, _, _) in &queries {
assert!(*time < 30, "All times should be within duration");
}
}
#[test]
fn test_workload_patterns() {
let patterns = ["debugging_session", "performance_analysis", "stress_testing", "cache_warming"];
for pattern in patterns {
let queries = generate_workload_pattern(pattern);
assert!(!queries.is_empty(), "Pattern '{}' should generate queries", pattern);
}
}
}