use claude_runner_core::ClaudeCommand;
#[test]
fn temperature_nan_produces_nan_string() {
let cmd = ClaudeCommand::new()
.with_temperature( f64::NAN );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TEMPERATURE" ) );
println!( "✓ temperature(NaN) accepted (produces NaN string in env var)" );
}
#[test]
fn temperature_infinity_produces_inf_string() {
let cmd = ClaudeCommand::new()
.with_temperature( f64::INFINITY );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TEMPERATURE" ) );
println!( "✓ temperature(INFINITY) accepted (produces inf string in env var)" );
}
#[test]
fn temperature_negative_infinity_produces_neg_inf_string() {
let cmd = ClaudeCommand::new()
.with_temperature( f64::NEG_INFINITY );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TEMPERATURE" ) );
println!( "✓ temperature(NEG_INFINITY) accepted (produces -inf string in env var)" );
}
#[test]
fn temperature_negative_value() {
let cmd = ClaudeCommand::new()
.with_temperature( -0.5 );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TEMPERATURE" ) );
assert!( debug.contains( "-0.5" ) );
println!( "✓ temperature(-0.5) accepted (produces -0.5 in env var)" );
}
#[test]
fn temperature_above_one() {
let cmd = ClaudeCommand::new()
.with_temperature( 1.5 );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TEMPERATURE" ) );
assert!( debug.contains( "1.5" ) );
println!( "✓ temperature(1.5) accepted (outside documented 0.0-1.0 range)" );
}
#[test]
fn temperature_zero() {
let cmd = ClaudeCommand::new()
.with_temperature( 0.0 );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TEMPERATURE" ) );
assert!( debug.contains( "\"0\"" ) || debug.contains( "\"0.0\"" ) );
println!( "✓ temperature(0.0) handled correctly" );
}
#[test]
fn temperature_exactly_one() {
let cmd = ClaudeCommand::new()
.with_temperature( 1.0 );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TEMPERATURE" ) );
println!( "✓ temperature(1.0) handled correctly" );
}
#[test]
fn temperature_very_small_positive() {
let cmd = ClaudeCommand::new()
.with_temperature( f64::MIN_POSITIVE );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TEMPERATURE" ) );
println!( "✓ temperature(MIN_POSITIVE) handled correctly" );
}
#[test]
fn top_p_nan_produces_nan_string() {
let cmd = ClaudeCommand::new()
.with_top_p( f64::NAN );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TOP_P" ) );
println!( "✓ top_p(NaN) accepted (produces NaN string in env var)" );
}
#[test]
fn top_p_infinity_produces_inf_string() {
let cmd = ClaudeCommand::new()
.with_top_p( f64::INFINITY );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TOP_P" ) );
println!( "✓ top_p(INFINITY) accepted (produces inf string in env var)" );
}
#[test]
fn top_p_negative_infinity_produces_neg_inf_string() {
let cmd = ClaudeCommand::new()
.with_top_p( f64::NEG_INFINITY );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TOP_P" ) );
println!( "✓ top_p(NEG_INFINITY) accepted (produces -inf string in env var)" );
}
#[test]
fn top_p_negative_value() {
let cmd = ClaudeCommand::new()
.with_top_p( -0.3 );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TOP_P" ) );
assert!( debug.contains( "-0.3" ) );
println!( "✓ top_p(-0.3) accepted (produces -0.3 in env var)" );
}
#[test]
fn top_p_above_one() {
let cmd = ClaudeCommand::new()
.with_top_p( 2.5 );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TOP_P" ) );
assert!( debug.contains( "2.5" ) );
println!( "✓ top_p(2.5) accepted (outside documented 0.0-1.0 range)" );
}
#[test]
fn top_p_zero() {
let cmd = ClaudeCommand::new()
.with_top_p( 0.0 );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TOP_P" ) );
println!( "✓ top_p(0.0) handled correctly" );
}
#[test]
fn top_p_exactly_one() {
let cmd = ClaudeCommand::new()
.with_top_p( 1.0 );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TOP_P" ) );
println!( "✓ top_p(1.0) handled correctly" );
}
#[test]
fn top_p_very_small_positive() {
let cmd = ClaudeCommand::new()
.with_top_p( f64::MIN_POSITIVE );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TOP_P" ) );
println!( "✓ top_p(MIN_POSITIVE) handled correctly" );
}
#[test]
fn both_temperature_and_top_p_set() {
let cmd = ClaudeCommand::new()
.with_temperature( 0.7 )
.with_top_p( 0.9 );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "CLAUDE_CODE_TEMPERATURE" ) );
assert!( debug.contains( "CLAUDE_CODE_TOP_P" ) );
assert!( debug.contains( "0.7" ) );
assert!( debug.contains( "0.9" ) );
println!( "✓ Both temperature and top_p set correctly" );
}
#[test]
fn float_precision_preserved() {
let cmd = ClaudeCommand::new()
.with_temperature( 0.123_456_789 )
.with_top_p( 0.987_654_321 );
let built = cmd.build_command_for_test();
let debug = format!( "{built:?}" );
assert!( debug.contains( "0.123456789" ) ); assert!( debug.contains( "0.987654321" ) ); println!( "✓ Float precision preserved in string conversion" );
}
#[test]
fn temperature_one_exact_format_is_integer_string() {
let env = ClaudeCommand::new()
.with_temperature( 1.0 )
.describe_env();
let temp_line = env.lines()
.find( | l | l.starts_with( "CLAUDE_CODE_TEMPERATURE=" ) )
.unwrap_or( "NOT_FOUND" );
assert_eq!(
temp_line, "CLAUDE_CODE_TEMPERATURE=1",
"temperature=1.0 must produce env var value '1' (not '1.0'): Rust Display format for f64"
);
let built = ClaudeCommand::new()
.with_temperature( 1.0 )
.build_command_for_test();
let debug = format!( "{built:?}" );
assert!(
debug.contains( "CLAUDE_CODE_TEMPERATURE" ) && debug.contains( "\"1\"" ),
"build_command() must also produce '1' for temperature=1.0, got: {debug}"
);
}
#[test]
fn temperature_zero_exact_format_is_integer_string() {
let env = ClaudeCommand::new()
.with_temperature( 0.0 )
.describe_env();
let temp_line = env.lines()
.find( | l | l.starts_with( "CLAUDE_CODE_TEMPERATURE=" ) )
.unwrap_or( "NOT_FOUND" );
assert_eq!(
temp_line, "CLAUDE_CODE_TEMPERATURE=0",
"temperature=0.0 must produce env var value '0' (not '0.0'): Rust Display format for f64"
);
}
#[test]
fn top_p_one_exact_format_is_integer_string() {
let env = ClaudeCommand::new()
.with_top_p( 1.0 )
.describe_env();
let top_p_line = env.lines()
.find( | l | l.starts_with( "CLAUDE_CODE_TOP_P=" ) )
.unwrap_or( "NOT_FOUND" );
assert_eq!(
top_p_line, "CLAUDE_CODE_TOP_P=1",
"top_p=1.0 must produce env var value '1' (not '1.0')"
);
}
#[test]
fn top_p_zero_exact_format_is_integer_string() {
let env = ClaudeCommand::new()
.with_top_p( 0.0 )
.describe_env();
let top_p_line = env.lines()
.find( | l | l.starts_with( "CLAUDE_CODE_TOP_P=" ) )
.unwrap_or( "NOT_FOUND" );
assert_eq!(
top_p_line, "CLAUDE_CODE_TOP_P=0",
"top_p=0.0 must produce env var value '0' (not '0.0')"
);
}
#[test]
fn describe_env_and_build_command_float_values_are_consistent() {
let temp = 0.7_f64;
let top_p = 0.9_f64;
let env = ClaudeCommand::new()
.with_temperature( temp )
.with_top_p( top_p )
.describe_env();
let built = ClaudeCommand::new()
.with_temperature( temp )
.with_top_p( top_p )
.build_command_for_test();
let debug = format!( "{built:?}" );
assert!(
env.contains( "CLAUDE_CODE_TEMPERATURE=0.7" ),
"describe_env must show CLAUDE_CODE_TEMPERATURE=0.7"
);
assert!(
debug.contains( "CLAUDE_CODE_TEMPERATURE" ) && debug.contains( "\"0.7\"" ),
"build_command must also produce '0.7' for temperature=0.7"
);
assert!(
env.contains( "CLAUDE_CODE_TOP_P=0.9" ),
"describe_env must show CLAUDE_CODE_TOP_P=0.9"
);
assert!(
debug.contains( "CLAUDE_CODE_TOP_P" ) && debug.contains( "\"0.9\"" ),
"build_command must also produce '0.9' for top_p=0.9"
);
}