claude-agents-sdk 0.1.7

Rust SDK for building agents with Claude Code CLI
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
//! Tests for Claude SDK client options and configuration.
//!
//! This file consolidates all ClaudeAgentOptions builder tests
//! and message type discrimination tests.

use claude_agents_sdk::{
    AgentDefinition, AssistantMessage, ClaudeAgentOptions, ContentBlock, Effort, McpServerConfig,
    McpServersConfig, McpStdioServerConfig, Message, PermissionMode, ResultMessage,
    SandboxNetworkConfig, SandboxSettings, SettingSource, SystemPromptConfig, SystemPromptPreset,
    TextBlock, ThinkingConfig, ToolsConfig, ToolsPreset,
};
use std::collections::HashMap;
use std::path::PathBuf;

// ============================================================================
// ClaudeAgentOptions Default State Tests
// ============================================================================

#[test]
fn test_new_options_has_all_fields_unset() {
    let options = ClaudeAgentOptions::new();

    // Core fields
    assert!(options.model.is_none(), "model should be None by default");
    assert!(
        options.system_prompt.is_none(),
        "system_prompt should be None by default"
    );
    assert!(
        options.permission_mode.is_none(),
        "permission_mode should be None by default"
    );
    assert!(
        options.max_turns.is_none(),
        "max_turns should be None by default"
    );
    assert!(
        options.max_budget_usd.is_none(),
        "max_budget_usd should be None by default"
    );

    // Tool configuration
    assert!(options.tools.is_none(), "tools should be None by default");
    assert!(
        options.allowed_tools.is_empty(),
        "allowed_tools should be empty by default"
    );
    assert!(
        options.disallowed_tools.is_empty(),
        "disallowed_tools should be empty by default"
    );

    // Session management
    assert!(
        !options.continue_conversation,
        "continue_conversation should be false by default"
    );
    assert!(options.resume.is_none(), "resume should be None by default");
    assert!(
        !options.fork_session,
        "fork_session should be false by default"
    );

    // Callbacks
    assert!(
        options.can_use_tool.is_none(),
        "can_use_tool should be None by default"
    );
    assert!(options.hooks.is_none(), "hooks should be None by default");

    // Streaming
    assert!(
        !options.include_partial_messages,
        "include_partial_messages should be false by default"
    );
}

// ============================================================================
// Builder Chain Tests
// ============================================================================

#[test]
fn test_builder_chain_sets_all_fields_correctly() {
    let options = ClaudeAgentOptions::new()
        .with_model("claude-sonnet-4-5")
        .with_max_turns(10)
        .with_permission_mode(PermissionMode::AcceptEdits)
        .with_system_prompt("Be helpful and concise")
        .with_cwd("/test/path")
        .with_allowed_tools(vec!["Read".to_string(), "Write".to_string()])
        .with_timeout_secs(120)
        .with_partial_messages();

    assert_eq!(
        options.model,
        Some("claude-sonnet-4-5".to_string()),
        "model should match set value"
    );
    assert_eq!(
        options.max_turns,
        Some(10),
        "max_turns should match set value"
    );
    assert_eq!(
        options.permission_mode,
        Some(PermissionMode::AcceptEdits),
        "permission_mode should match set value"
    );
    assert_eq!(
        options.cwd,
        Some(PathBuf::from("/test/path")),
        "cwd should match set value"
    );
    assert_eq!(
        options.allowed_tools,
        vec!["Read", "Write"],
        "allowed_tools should match set value"
    );
    assert_eq!(
        options.timeout_secs,
        Some(120),
        "timeout_secs should match set value"
    );
    assert!(
        options.include_partial_messages,
        "include_partial_messages should be true"
    );

    match &options.system_prompt {
        Some(SystemPromptConfig::Text(text)) => {
            assert_eq!(
                text, "Be helpful and concise",
                "system_prompt text should match"
            )
        }
        _ => panic!(
            "Expected text system prompt, got {:?}",
            options.system_prompt
        ),
    }
}

#[test]
fn test_builder_methods_are_idempotent() {
    let options1 = ClaudeAgentOptions::new()
        .with_model("claude-3")
        .with_max_turns(5);

    let options2 = ClaudeAgentOptions::new()
        .with_model("claude-3")
        .with_max_turns(5);

    assert_eq!(
        options1.model, options2.model,
        "Same builder calls should produce same model"
    );
    assert_eq!(
        options1.max_turns, options2.max_turns,
        "Same builder calls should produce same max_turns"
    );
}

// ============================================================================
// System Prompt Configuration Tests
// ============================================================================

#[test]
fn test_system_prompt_text_configuration() {
    let options = ClaudeAgentOptions::new().with_system_prompt("Custom instructions");

    match options.system_prompt {
        Some(SystemPromptConfig::Text(text)) => {
            assert_eq!(text, "Custom instructions");
        }
        other => panic!("Expected SystemPromptConfig::Text, got {:?}", other),
    }
}

#[test]
fn test_system_prompt_preset_without_append() {
    let mut options = ClaudeAgentOptions::new();
    options.system_prompt = Some(SystemPromptConfig::Preset(SystemPromptPreset {
        preset_type: "preset".to_string(),
        preset: "claude_code".to_string(),
        append: None,
    }));

    match options.system_prompt {
        Some(SystemPromptConfig::Preset(preset)) => {
            assert_eq!(preset.preset, "claude_code");
            assert!(preset.append.is_none(), "append should be None");
        }
        other => panic!("Expected SystemPromptConfig::Preset, got {:?}", other),
    }
}

#[test]
fn test_system_prompt_preset_with_append() {
    let mut options = ClaudeAgentOptions::new();
    options.system_prompt = Some(SystemPromptConfig::Preset(SystemPromptPreset {
        preset_type: "preset".to_string(),
        preset: "claude_code".to_string(),
        append: Some("Be concise.".to_string()),
    }));

    match options.system_prompt {
        Some(SystemPromptConfig::Preset(preset)) => {
            assert_eq!(preset.preset, "claude_code");
            assert_eq!(preset.append, Some("Be concise.".to_string()));
        }
        other => panic!("Expected SystemPromptConfig::Preset, got {:?}", other),
    }
}

// ============================================================================
// Tools Configuration Tests
// ============================================================================

#[test]
fn test_tools_list_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.tools = Some(ToolsConfig::List(vec![
        "Read".to_string(),
        "Write".to_string(),
        "Bash".to_string(),
    ]));

    match &options.tools {
        Some(ToolsConfig::List(tools)) => {
            assert_eq!(tools.len(), 3);
            assert!(tools.contains(&"Read".to_string()));
            assert!(tools.contains(&"Write".to_string()));
            assert!(tools.contains(&"Bash".to_string()));
        }
        other => panic!("Expected ToolsConfig::List, got {:?}", other),
    }
}

#[test]
fn test_tools_empty_list_is_valid() {
    let mut options = ClaudeAgentOptions::new();
    options.tools = Some(ToolsConfig::List(vec![]));

    match &options.tools {
        Some(ToolsConfig::List(tools)) => {
            assert!(tools.is_empty(), "Empty tools list should be allowed");
        }
        other => panic!("Expected ToolsConfig::List, got {:?}", other),
    }
}

#[test]
fn test_tools_preset_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.tools = Some(ToolsConfig::Preset(ToolsPreset {
        preset_type: "preset".to_string(),
        preset: "claude_code".to_string(),
    }));

    match &options.tools {
        Some(ToolsConfig::Preset(preset)) => {
            assert_eq!(preset.preset, "claude_code");
        }
        other => panic!("Expected ToolsConfig::Preset, got {:?}", other),
    }
}

#[test]
fn test_allowed_and_disallowed_tools_both_set() {
    let mut options = ClaudeAgentOptions::new();
    options.allowed_tools = vec!["Read".to_string(), "Write".to_string()];
    options.disallowed_tools = vec!["Bash".to_string()];

    assert_eq!(options.allowed_tools, vec!["Read", "Write"]);
    assert_eq!(options.disallowed_tools, vec!["Bash"]);
}

// ============================================================================
// Session Management Tests
// ============================================================================

#[test]
fn test_session_continuation_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.continue_conversation = true;
    options.resume = Some("session-abc123".to_string());

    assert!(options.continue_conversation);
    assert_eq!(options.resume, Some("session-abc123".to_string()));
}

#[test]
fn test_fork_session_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.resume = Some("session-xyz789".to_string());
    options.fork_session = true;

    assert!(options.fork_session);
    assert_eq!(options.resume, Some("session-xyz789".to_string()));
}

// ============================================================================
// Model Configuration Tests
// ============================================================================

#[test]
fn test_model_configuration() {
    let options = ClaudeAgentOptions::new().with_model("claude-opus-4-5");
    assert_eq!(options.model, Some("claude-opus-4-5".to_string()));
}

#[test]
fn test_fallback_model_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.model = Some("opus".to_string());
    options.fallback_model = Some("sonnet".to_string());

    assert_eq!(options.model, Some("opus".to_string()));
    assert_eq!(options.fallback_model, Some("sonnet".to_string()));
}

#[test]
fn test_max_thinking_tokens_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.max_thinking_tokens = Some(5000);

    assert_eq!(options.max_thinking_tokens, Some(5000));
}

// ============================================================================
// Directory and Path Configuration Tests
// ============================================================================

#[test]
fn test_add_dirs_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.add_dirs = vec![
        PathBuf::from("/path/to/dir1"),
        PathBuf::from("/path/to/dir2"),
    ];

    assert_eq!(options.add_dirs.len(), 2);
    assert!(options.add_dirs.contains(&PathBuf::from("/path/to/dir1")));
    assert!(options.add_dirs.contains(&PathBuf::from("/path/to/dir2")));
}

#[test]
fn test_cwd_configuration() {
    let options = ClaudeAgentOptions::new().with_cwd("/custom/working/dir");
    assert_eq!(options.cwd, Some(PathBuf::from("/custom/working/dir")));
}

#[test]
fn test_cli_path_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.cli_path = Some(PathBuf::from("/usr/local/bin/claude"));

    assert_eq!(
        options.cli_path,
        Some(PathBuf::from("/usr/local/bin/claude"))
    );
}

// ============================================================================
// Environment and Extra Args Configuration Tests
// ============================================================================

#[test]
fn test_env_vars_configuration() {
    let mut options = ClaudeAgentOptions::new();
    let mut env = HashMap::new();
    env.insert("MY_VAR".to_string(), "my_value".to_string());
    env.insert("ANOTHER_VAR".to_string(), "another_value".to_string());
    options.env = env;

    assert_eq!(options.env.len(), 2);
    assert_eq!(options.env.get("MY_VAR"), Some(&"my_value".to_string()));
    assert_eq!(
        options.env.get("ANOTHER_VAR"),
        Some(&"another_value".to_string())
    );
}

#[test]
fn test_extra_args_configuration() {
    let mut options = ClaudeAgentOptions::new();
    let mut extra_args = HashMap::new();
    extra_args.insert("new-flag".to_string(), Some("value".to_string()));
    extra_args.insert("boolean-flag".to_string(), None);
    options.extra_args = extra_args;

    assert_eq!(options.extra_args.len(), 2);
    assert_eq!(
        options.extra_args.get("new-flag"),
        Some(&Some("value".to_string()))
    );
    assert_eq!(options.extra_args.get("boolean-flag"), Some(&None));
}

// ============================================================================
// Settings Configuration Tests
// ============================================================================

#[test]
fn test_settings_string_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.settings = Some(r#"{"permissions": {"allow": ["Bash(ls:*)"]}}"#.to_string());

    let settings = options.settings.as_ref().expect("settings should be set");
    assert!(
        settings.contains("permissions"),
        "settings should contain 'permissions'"
    );
}

#[test]
fn test_setting_sources_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.setting_sources = Some(vec![SettingSource::User, SettingSource::Project]);

    let sources = options
        .setting_sources
        .as_ref()
        .expect("sources should be set");
    assert_eq!(sources.len(), 2);
    assert!(sources.contains(&SettingSource::User));
    assert!(sources.contains(&SettingSource::Project));
}

// ============================================================================
// MCP Server Configuration Tests
// ============================================================================

#[test]
fn test_mcp_servers_map_configuration() {
    let mut mcp_servers = HashMap::new();
    mcp_servers.insert(
        "test-server".to_string(),
        McpServerConfig::Stdio(McpStdioServerConfig {
            server_type: "stdio".to_string(),
            command: "/path/to/server".to_string(),
            args: vec!["--option".to_string(), "value".to_string()],
            env: HashMap::new(),
        }),
    );

    let mut options = ClaudeAgentOptions::new();
    options.mcp_servers = McpServersConfig::Map(mcp_servers);

    match &options.mcp_servers {
        McpServersConfig::Map(servers) => {
            assert!(servers.contains_key("test-server"));
        }
        other => panic!("Expected McpServersConfig::Map, got {:?}", other),
    }
}

#[test]
fn test_mcp_servers_path_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.mcp_servers = McpServersConfig::Path(PathBuf::from("/path/to/mcp-config.json"));

    match &options.mcp_servers {
        McpServersConfig::Path(path) => {
            assert_eq!(path, &PathBuf::from("/path/to/mcp-config.json"));
        }
        other => panic!("Expected McpServersConfig::Path, got {:?}", other),
    }
}

// ============================================================================
// Sandbox Configuration Tests
// ============================================================================

#[test]
fn test_sandbox_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.sandbox = Some(SandboxSettings {
        enabled: true,
        auto_allow_bash_if_sandboxed: true,
        excluded_commands: vec!["docker".to_string()],
        allow_unsandboxed_commands: true,
        network: Some(SandboxNetworkConfig {
            allow_unix_sockets: vec!["/var/run/docker.sock".to_string()],
            allow_all_unix_sockets: false,
            allow_local_binding: true,
            http_proxy_port: None,
            socks_proxy_port: None,
        }),
        ignore_violations: None,
        enable_weaker_nested_sandbox: false,
    });

    let sandbox = options.sandbox.as_ref().expect("sandbox should be set");
    assert!(sandbox.enabled);
    assert!(sandbox.auto_allow_bash_if_sandboxed);
    assert!(sandbox.network.is_some());
}

// ============================================================================
// Agent Configuration Tests
// ============================================================================

#[test]
fn test_agents_configuration() {
    let mut agents = HashMap::new();
    agents.insert(
        "test-agent".to_string(),
        AgentDefinition {
            description: "A test agent".to_string(),
            prompt: "You are a test agent".to_string(),
            tools: Some(vec!["Read".to_string()]),
            model: None,
        },
    );

    let mut options = ClaudeAgentOptions::new();
    options.agents = Some(agents);

    let agents = options.agents.as_ref().expect("agents should be set");
    assert!(agents.contains_key("test-agent"));
    let agent = agents.get("test-agent").unwrap();
    assert_eq!(agent.description, "A test agent");
}

// ============================================================================
// Miscellaneous Configuration Tests
// ============================================================================

#[test]
fn test_partial_messages_configuration() {
    let options = ClaudeAgentOptions::new().with_partial_messages();
    assert!(options.include_partial_messages);
}

#[test]
fn test_user_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.user = Some("claude-user".to_string());

    assert_eq!(options.user, Some("claude-user".to_string()));
}

#[test]
fn test_max_buffer_size_configuration() {
    let mut options = ClaudeAgentOptions::new();
    options.max_buffer_size = Some(1024 * 1024); // 1MB

    assert_eq!(options.max_buffer_size, Some(1024 * 1024));
}

// ============================================================================
// Message Type Discrimination Tests
// ============================================================================

#[test]
fn test_message_is_assistant_returns_true_for_assistant_message() {
    let msg = Message::Assistant(AssistantMessage {
        content: vec![ContentBlock::Text(TextBlock {
            text: "Hello".to_string(),
        })],
        model: "claude-3".to_string(),
        parent_tool_use_id: None,
        error: None,
    });

    assert!(
        msg.is_assistant(),
        "is_assistant() should return true for Assistant message"
    );
    assert!(
        !msg.is_result(),
        "is_result() should return false for Assistant message"
    );
}

#[test]
fn test_message_is_result_returns_true_for_result_message() {
    let msg = Message::Result(ResultMessage {
        subtype: "success".to_string(),
        duration_ms: 100,
        duration_api_ms: 80,
        is_error: false,
        num_turns: 1,
        session_id: "test".to_string(),
        total_cost_usd: None,
        usage: None,
        result: None,
        structured_output: None,
    });

    assert!(
        msg.is_result(),
        "is_result() should return true for Result message"
    );
    assert!(
        !msg.is_assistant(),
        "is_assistant() should return false for Result message"
    );
}

#[test]
fn test_message_as_assistant_returns_some_for_assistant_message() {
    let msg = Message::Assistant(AssistantMessage {
        content: vec![ContentBlock::Text(TextBlock {
            text: "Hello".to_string(),
        })],
        model: "claude-3".to_string(),
        parent_tool_use_id: None,
        error: None,
    });

    let asst = msg.as_assistant();
    assert!(
        asst.is_some(),
        "as_assistant() should return Some for Assistant message"
    );
    assert_eq!(
        asst.unwrap().text(),
        "Hello",
        "as_assistant() should return the correct message"
    );
}

#[test]
fn test_message_as_assistant_returns_none_for_non_assistant_message() {
    let msg = Message::Result(ResultMessage {
        subtype: "success".to_string(),
        duration_ms: 100,
        duration_api_ms: 80,
        is_error: false,
        num_turns: 1,
        session_id: "test".to_string(),
        total_cost_usd: Some(0.001),
        usage: None,
        result: None,
        structured_output: None,
    });

    assert!(
        msg.as_assistant().is_none(),
        "as_assistant() should return None for Result message"
    );
}

#[test]
fn test_message_as_result_returns_some_for_result_message() {
    let msg = Message::Result(ResultMessage {
        subtype: "success".to_string(),
        duration_ms: 100,
        duration_api_ms: 80,
        is_error: false,
        num_turns: 1,
        session_id: "test".to_string(),
        total_cost_usd: Some(0.001),
        usage: None,
        result: None,
        structured_output: None,
    });

    let result = msg.as_result();
    assert!(
        result.is_some(),
        "as_result() should return Some for Result message"
    );
    assert_eq!(
        result.unwrap().total_cost_usd,
        Some(0.001),
        "as_result() should return the correct message"
    );
}

#[test]
fn test_message_as_result_returns_none_for_non_result_message() {
    let msg = Message::Assistant(AssistantMessage {
        content: vec![ContentBlock::Text(TextBlock {
            text: "Hello".to_string(),
        })],
        model: "claude-3".to_string(),
        parent_tool_use_id: None,
        error: None,
    });

    assert!(
        msg.as_result().is_none(),
        "as_result() should return None for Assistant message"
    );
}

// ============================================================================
// Edge Case Tests
// ============================================================================

#[test]
fn test_empty_model_string_is_preserved() {
    let options = ClaudeAgentOptions::new().with_model("");
    assert_eq!(
        options.model,
        Some("".to_string()),
        "Empty model string should be preserved"
    );
}

#[test]
fn test_zero_max_turns_is_valid() {
    let mut options = ClaudeAgentOptions::new();
    options.max_turns = Some(0);
    assert_eq!(
        options.max_turns,
        Some(0),
        "Zero max_turns should be allowed"
    );
}

#[test]
fn test_zero_timeout_disables_timeout() {
    let options = ClaudeAgentOptions::new().with_timeout_secs(0);
    assert_eq!(
        options.timeout_secs,
        Some(0),
        "Zero timeout should be allowed (disables timeout)"
    );
}

#[test]
fn test_large_max_turns_value() {
    let mut options = ClaudeAgentOptions::new();
    options.max_turns = Some(u32::MAX);
    assert_eq!(
        options.max_turns,
        Some(u32::MAX),
        "Large max_turns should be allowed"
    );
}

#[test]
fn test_negative_budget_is_representable() {
    // Note: Negative budgets probably shouldn't be allowed semantically,
    // but we test that the type can represent them
    let mut options = ClaudeAgentOptions::new();
    options.max_budget_usd = Some(-1.0);
    assert!(
        options.max_budget_usd.unwrap() < 0.0,
        "Negative budget value is representable"
    );
}

#[test]
fn test_whitespace_only_system_prompt() {
    let options = ClaudeAgentOptions::new().with_system_prompt("   ");
    match options.system_prompt {
        Some(SystemPromptConfig::Text(text)) => {
            assert_eq!(text, "   ", "Whitespace-only prompt should be preserved");
        }
        other => panic!("Expected text system prompt, got {:?}", other),
    }
}

#[test]
fn test_unicode_in_system_prompt() {
    let options = ClaudeAgentOptions::new().with_system_prompt("你好世界 🌍 مرحبا");
    match options.system_prompt {
        Some(SystemPromptConfig::Text(text)) => {
            assert_eq!(text, "你好世界 🌍 مرحبا", "Unicode should be preserved");
        }
        other => panic!("Expected text system prompt, got {:?}", other),
    }
}

#[test]
fn test_very_long_allowed_tools_list() {
    let tools: Vec<String> = (0..1000).map(|i| format!("Tool{}", i)).collect();
    let options = ClaudeAgentOptions::new().with_allowed_tools(tools.clone());
    assert_eq!(
        options.allowed_tools.len(),
        1000,
        "Large tools list should be handled"
    );
}

#[test]
fn test_duplicate_tools_in_allowed_tools() {
    let options = ClaudeAgentOptions::new().with_allowed_tools(vec![
        "Read".to_string(),
        "Read".to_string(),
        "Write".to_string(),
    ]);
    assert_eq!(
        options.allowed_tools.len(),
        3,
        "Duplicate tools should be preserved (not deduplicated)"
    );
}

#[test]
fn test_overlapping_allowed_and_disallowed_tools() {
    let mut options = ClaudeAgentOptions::new();
    options.allowed_tools = vec!["Bash".to_string()];
    options.disallowed_tools = vec!["Bash".to_string()];

    // Both can be set - validation would happen at a higher level
    assert!(options.allowed_tools.contains(&"Bash".to_string()));
    assert!(options.disallowed_tools.contains(&"Bash".to_string()));
}

// ============================================================================
// ThinkingConfig and Effort Builder Tests
// ============================================================================

#[test]
fn test_thinking_config_adaptive_builder() {
    let options = ClaudeAgentOptions::new().with_thinking(ThinkingConfig::Adaptive);
    assert!(matches!(options.thinking, Some(ThinkingConfig::Adaptive)));
}

#[test]
fn test_thinking_config_enabled_builder() {
    let options = ClaudeAgentOptions::new().with_thinking(ThinkingConfig::Enabled {
        budget_tokens: 50000,
    });
    match options.thinking {
        Some(ThinkingConfig::Enabled { budget_tokens }) => assert_eq!(budget_tokens, 50000),
        _ => panic!("Expected Enabled variant"),
    }
}

#[test]
fn test_thinking_config_disabled_builder() {
    let options = ClaudeAgentOptions::new().with_thinking(ThinkingConfig::Disabled);
    assert!(matches!(options.thinking, Some(ThinkingConfig::Disabled)));
}

#[test]
fn test_effort_builder() {
    let options = ClaudeAgentOptions::new().with_effort(Effort::High);
    assert_eq!(options.effort, Some(Effort::High));
}

#[test]
fn test_effort_builder_all_variants() {
    for effort in [Effort::Low, Effort::Medium, Effort::High, Effort::Max] {
        let options = ClaudeAgentOptions::new().with_effort(effort);
        assert_eq!(options.effort, Some(effort));
    }
}

#[test]
fn test_thinking_and_effort_combined() {
    let options = ClaudeAgentOptions::new()
        .with_thinking(ThinkingConfig::Adaptive)
        .with_effort(Effort::High);
    assert!(matches!(options.thinking, Some(ThinkingConfig::Adaptive)));
    assert_eq!(options.effort, Some(Effort::High));
}