@@ -2481,4 +2481,144 @@ mod tests {
24812481 session. iterations = 50 ;
24822482 assert ! ( session. should_stop( ) ) ;
24832483 }
2484+
2485+ #[ test]
2486+ fn timeout_calculation_edge_cases ( ) {
2487+ let test_cases = vec ! [
2488+ ( 0_u64 , 1_u64 ) ,
2489+ ( 500_u64 , 1_u64 ) ,
2490+ ( 1000_u64 , 1_u64 ) ,
2491+ ( 5000_u64 , 5_u64 ) ,
2492+ ] ;
2493+ for ( ms, expected) in test_cases {
2494+ assert_eq ! ( ( ms / 1000 ) . max( 1 ) , expected) ;
2495+ }
2496+ }
2497+
2498+ #[ test]
2499+ fn all_fuzz_methods ( ) {
2500+ for m in [
2501+ "initialize" ,
2502+ "tools/list" ,
2503+ "tools/call" ,
2504+ "resources/list" ,
2505+ "resources/read" ,
2506+ "prompts/list" ,
2507+ "prompts/get" ,
2508+ "ping" ,
2509+ ] {
2510+ assert_eq ! ( FuzzInput :: new( m, None ) . method, m) ;
2511+ }
2512+ }
2513+
2514+ #[ test]
2515+ fn response_types_all ( ) {
2516+ let _s = FuzzResponse :: success ( serde_json:: json!( { } ) ) ;
2517+ let _e = FuzzResponse :: error ( -1 , "e" ) ;
2518+ let _t = FuzzResponse :: timeout ( ) ;
2519+ let _c = FuzzResponse :: connection_lost ( "c" ) ;
2520+ let _w = _s. with_time ( 1000 ) ;
2521+ }
2522+
2523+ #[ test]
2524+ fn crash_types_strings ( ) {
2525+ for ct in [
2526+ CrashType :: Panic ,
2527+ CrashType :: Segfault ,
2528+ CrashType :: OutOfMemory ,
2529+ CrashType :: ConnectionDrop ,
2530+ CrashType :: AssertionFailure ,
2531+ ] {
2532+ assert ! ( !ct. to_string( ) . is_empty( ) ) ;
2533+ }
2534+ }
2535+
2536+ #[ test]
2537+ fn connection_errors ( ) {
2538+ assert ! ( "connection refused" . contains( "connection" ) ) ;
2539+ assert ! ( "broken pipe" . contains( "broken pipe" ) ) ;
2540+ }
2541+
2542+ #[ test]
2543+ fn failure_limits ( ) {
2544+ let config = FuzzConfig :: default ( ) ;
2545+ let mut s = FuzzSession :: new ( "test" , & [ ] , config) ;
2546+ for i in 0 ..6 {
2547+ s. connection_failures = i;
2548+ assert_eq ! ( s. connection_failures >= 5 , i >= 5 ) ;
2549+ }
2550+ }
2551+
2552+ #[ test]
2553+ fn records_creation ( ) {
2554+ use uuid:: Uuid ;
2555+ let i = FuzzInput :: new ( "t" , None ) ;
2556+ let cr = CrashRecord {
2557+ id : Uuid :: new_v4 ( ) . to_string ( ) ,
2558+ input : i. clone ( ) ,
2559+ crash_type : CrashType :: Panic ,
2560+ error_message : "e" . into ( ) ,
2561+ stack_trace : None ,
2562+ iteration : 1 ,
2563+ timestamp : chrono:: Utc :: now ( ) . to_rfc3339 ( ) ,
2564+ } ;
2565+ assert ! ( !cr. id. is_empty( ) ) ;
2566+ }
2567+
2568+ #[ test]
2569+ fn iterations_checking ( ) {
2570+ assert ! ( 10_u64 . is_multiple_of( 10 ) ) ;
2571+ assert ! ( !5_u64 . is_multiple_of( 10 ) ) ;
2572+ }
2573+
2574+ #[ test]
2575+ fn coverage_hash_stable ( ) {
2576+ let c = FuzzConfig :: default ( ) ;
2577+ let s = FuzzSession :: new ( "t" , & [ ] , c) ;
2578+ let i = FuzzInput :: new ( "t" , None ) ;
2579+ let r = FuzzResponse :: success ( serde_json:: json!( { } ) ) ;
2580+ assert_eq ! (
2581+ s. coverage. hash_response( & i, & r) ,
2582+ s. coverage. hash_response( & i, & r)
2583+ ) ;
2584+ }
2585+
2586+ #[ test]
2587+ fn tools_cache ( ) {
2588+ use crate :: protocol:: mcp:: Tool ;
2589+ let c = FuzzConfig :: default ( ) ;
2590+ let mut s = FuzzSession :: new ( "t" , & [ ] , c) ;
2591+ s. engine . cache_tools ( & vec ! [ Tool {
2592+ name: "t" . into( ) ,
2593+ description: None ,
2594+ input_schema: serde_json:: json!( { } ) ,
2595+ } ] ) ;
2596+ }
2597+
2598+ #[ test]
2599+ fn config_builder ( ) {
2600+ let c = FuzzConfig :: default ( )
2601+ . with_duration ( 600 )
2602+ . with_iterations ( 10000 )
2603+ . with_timeout ( 5000 ) ;
2604+ assert_eq ! ( c. duration_secs, 600 ) ;
2605+ }
2606+
2607+ #[ test]
2608+ fn limits_builder ( ) {
2609+ use crate :: fuzzer:: limits:: ResourceLimits ;
2610+ let l = ResourceLimits :: default ( ) . with_max_executions ( 1000 ) ;
2611+ assert_eq ! ( l. max_executions, Some ( 1000 ) ) ;
2612+ }
2613+
2614+ #[ test]
2615+ fn stop_reason_set ( ) {
2616+ use crate :: fuzzer:: limits:: ResourceLimits ;
2617+ let l = ResourceLimits :: default ( ) . with_max_executions ( 10 ) ;
2618+ let c = FuzzConfig :: default ( ) . with_resource_limits ( l) ;
2619+ let mut s = FuzzSession :: new ( "t" , & [ ] , c) ;
2620+ s. start_time = Some ( Instant :: now ( ) ) ;
2621+ s. iterations = 10 ;
2622+ let _ = s. should_stop ( ) ;
2623+ }
24842624}
0 commit comments