ralph-workflow 0.7.18

PROMPT-driven multi-agent orchestrator for git repos
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
// Tests for CCS (Claude Code Switch) alias resolution

use super::*;

fn default_ccs() -> CcsConfig {
    CcsConfig::default()
}

#[test]
fn test_parse_ccs_ref() {
    // Valid CCS references
    assert_eq!(parse_ccs_ref("ccs"), Some(""));
    assert_eq!(parse_ccs_ref("ccs/work"), Some("work"));
    assert_eq!(parse_ccs_ref("ccs/personal"), Some("personal"));
    assert_eq!(parse_ccs_ref("ccs/gemini"), Some("gemini"));
    assert_eq!(
        parse_ccs_ref("ccs/my-custom-alias"),
        Some("my-custom-alias")
    );

    // Not CCS references
    assert_eq!(parse_ccs_ref("claude"), None);
    assert_eq!(parse_ccs_ref("codex"), None);
    assert_eq!(parse_ccs_ref("ccs_work"), None);
    assert_eq!(parse_ccs_ref("cccs/work"), None);
    assert_eq!(parse_ccs_ref(""), None);
}

#[test]
fn test_is_ccs_ref() {
    assert!(is_ccs_ref("ccs"));
    assert!(is_ccs_ref("ccs/work"));
    assert!(is_ccs_ref("ccs/gemini"));
    assert!(!is_ccs_ref("claude"));
    assert!(!is_ccs_ref("codex"));
}

#[test]
fn test_resolve_ccs_agent_default() {
    let aliases = HashMap::new();
    let config = resolve_ccs_agent("", &aliases, &default_ccs());
    assert!(config.is_some());
    let config = config.unwrap();
    // When claude binary is found, it replaces "ccs" with the path to claude
    // The command should end with "claude"
    assert!(
        config.cmd.ends_with("claude") || config.cmd == "ccs",
        "cmd should be 'ccs' or a path ending with 'claude', got: {}",
        config.cmd
    );
    assert!(config.can_commit);
    assert_eq!(config.json_parser, JsonParserType::Claude);
}

#[test]
fn test_resolve_ccs_agent_with_alias() {
    let mut aliases = HashMap::new();
    aliases.insert(
        "work".to_string(),
        CcsAliasConfig {
            cmd: "ccs work".to_string(),
            ..CcsAliasConfig::default()
        },
    );
    aliases.insert(
        "gemini".to_string(),
        CcsAliasConfig {
            cmd: "ccs gemini".to_string(),
            ..CcsAliasConfig::default()
        },
    );

    let config = resolve_ccs_agent("work", &aliases, &default_ccs());
    assert!(config.is_some());
    let config = config.unwrap();
    // When claude binary is found, it replaces "ccs work" with the path to claude
    assert!(
        config.cmd.ends_with("claude") || config.cmd == "ccs work",
        "cmd should be 'ccs work' or a path ending with 'claude', got: {}",
        config.cmd
    );

    let config = resolve_ccs_agent("gemini", &aliases, &default_ccs());
    assert!(config.is_some());
    let config = config.unwrap();
    assert!(
        config.cmd.ends_with("claude") || config.cmd == "ccs gemini",
        "cmd should be 'ccs gemini' or a path ending with 'claude', got: {}",
        config.cmd
    );

    // Unknown alias returns None
    let config = resolve_ccs_agent("unknown", &aliases, &default_ccs());
    assert!(config.is_none());
}

#[test]
fn test_build_ccs_agent_config() {
    let config = build_ccs_agent_config(
        &CcsAliasConfig {
            cmd: "ccs work".to_string(),
            ..CcsAliasConfig::default()
        },
        &default_ccs(),
        "ccs-work".to_string(),
        "work",
    );
    // When claude binary is found, it replaces "ccs work" with the path to claude
    assert!(
        config.cmd.ends_with("claude") || config.cmd == "ccs work",
        "cmd should be 'ccs work' or a path ending with 'claude', got: {}",
        config.cmd
    );
    assert_eq!(config.output_flag, "--output-format=stream-json");
    assert_eq!(config.yolo_flag, "--dangerously-skip-permissions");
    assert_eq!(config.verbose_flag, "--verbose");
    assert!(config.can_commit);
    assert_eq!(config.json_parser, JsonParserType::Claude);
    assert!(config.model_flag.is_none());
    assert_eq!(config.display_name, Some("ccs-work".to_string()));
}

#[test]
fn test_ccs_alias_resolver_empty() {
    let resolver = CcsAliasResolver::empty();
    // Empty resolver has no aliases; only plain "ccs" should resolve to default
    assert!(resolver.try_resolve("ccs").is_some());
    // Any ccs/<alias> should still resolve with default config for direct execution
    assert!(resolver.try_resolve("ccs/unknown").is_some());
}

#[test]
fn test_ccs_alias_resolver_with_aliases_resolves() {
    // Behavioral test: resolver with configured aliases should resolve them
    let mut aliases = HashMap::new();
    aliases.insert(
        "work".to_string(),
        CcsAliasConfig {
            cmd: "ccs work".to_string(),
            ..CcsAliasConfig::default()
        },
    );
    aliases.insert(
        "personal".to_string(),
        CcsAliasConfig {
            cmd: "ccs personal".to_string(),
            ..CcsAliasConfig::default()
        },
    );
    let resolver = CcsAliasResolver::new(aliases, default_ccs());

    // Resolve ccs/work - should use configured alias
    let config = resolver.try_resolve("ccs/work");
    assert!(config.is_some());
    let work_cmd = config.unwrap().cmd;
    assert!(
        work_cmd.ends_with("claude") || work_cmd == "ccs work",
        "cmd should be 'ccs work' or a path ending with 'claude', got: {work_cmd}"
    );

    // Resolve ccs/personal - should use configured alias
    let config = resolver.try_resolve("ccs/personal");
    assert!(config.is_some());
    let personal_cmd = config.unwrap().cmd;
    assert!(
        personal_cmd.ends_with("claude") || personal_cmd == "ccs personal",
        "cmd should be 'ccs personal' or a path ending with 'claude', got: {personal_cmd}"
    );

    // Resolve plain "ccs" (default)
    let config = resolver.try_resolve("ccs");
    assert!(config.is_some());
    let default_cmd = config.unwrap().cmd;
    assert!(
        default_cmd.ends_with("claude") || default_cmd == "ccs",
        "cmd should be 'ccs' or a path ending with 'claude', got: {default_cmd}"
    );

    // Unknown alias - now resolves with default config for direct CCS execution
    let config = resolver.try_resolve("ccs/unknown");
    assert!(config.is_some());
    let unknown_cmd = config.unwrap().cmd;
    assert!(
        unknown_cmd.ends_with("claude") || unknown_cmd == "ccs unknown",
        "cmd should be 'ccs unknown' or a path ending with 'claude', got: {unknown_cmd}"
    );

    // Not a CCS ref
    let config = resolver.try_resolve("claude");
    assert!(config.is_none());
}

#[test]
fn test_ccs_references_resolve() {
    // Behavioral test: verify CCS references can be distinguished from non-CCS refs
    // by checking if try_resolve returns Some vs None
    let resolver = CcsAliasResolver::empty();

    // CCS references should resolve (including unregistered ones)
    assert!(resolver.try_resolve("ccs").is_some());
    assert!(resolver.try_resolve("ccs/work").is_some());
    assert!(resolver.try_resolve("ccs/unknown").is_some());

    // Non-CCS references should not resolve
    assert!(resolver.try_resolve("claude").is_none());
    assert!(resolver.try_resolve("codex").is_none());
}

#[test]
fn test_ccs_alias_resolver_multiple_aliases_resolve_correctly() {
    // Behavioral test: multiple configured aliases all resolve correctly
    let mut aliases = HashMap::new();
    aliases.insert(
        "work".to_string(),
        CcsAliasConfig {
            cmd: "ccs work".to_string(),
            ..CcsAliasConfig::default()
        },
    );
    aliases.insert(
        "personal".to_string(),
        CcsAliasConfig {
            cmd: "ccs personal".to_string(),
            ..CcsAliasConfig::default()
        },
    );
    let resolver = CcsAliasResolver::new(aliases, default_ccs());

    // Each configured alias should resolve with its specific command
    let work_config = resolver.try_resolve("ccs/work").unwrap();
    assert!(
        work_config.cmd.contains("work") || work_config.cmd.ends_with("claude"),
        "work alias should resolve with 'work' in command or end with claude"
    );

    let personal_config = resolver.try_resolve("ccs/personal").unwrap();
    assert!(
        personal_config.cmd.contains("personal") || personal_config.cmd.ends_with("claude"),
        "personal alias should resolve with 'personal' in command or end with claude"
    );
}

// Additional tests for various CCS command patterns per Step 2 of plan

#[test]
fn test_ccs_command_variants() {
    // Tests for different CCS command patterns as used in the wild:
    // - ccs (default profile)
    // - ccs <profile> (named profile)
    // - ccs gemini / ccs codex / ccs glm (built-in providers)
    // - ccs api <custom> (custom API profiles)

    let mut aliases = HashMap::new();
    // Named profiles
    aliases.insert(
        "work".to_string(),
        CcsAliasConfig {
            cmd: "ccs work".to_string(),
            ..CcsAliasConfig::default()
        },
    );
    aliases.insert(
        "personal".to_string(),
        CcsAliasConfig {
            cmd: "ccs personal".to_string(),
            ..CcsAliasConfig::default()
        },
    );

    // Built-in provider profiles
    aliases.insert(
        "gemini".to_string(),
        CcsAliasConfig {
            cmd: "ccs gemini".to_string(),
            ..CcsAliasConfig::default()
        },
    );
    aliases.insert(
        "codex".to_string(),
        CcsAliasConfig {
            cmd: "ccs codex".to_string(),
            ..CcsAliasConfig::default()
        },
    );
    aliases.insert(
        "glm".to_string(),
        CcsAliasConfig {
            cmd: "ccs glm".to_string(),
            ..CcsAliasConfig::default()
        },
    );

    // Custom API profiles
    aliases.insert(
        "openrouter".to_string(),
        CcsAliasConfig {
            cmd: "ccs api openrouter".to_string(),
            ..CcsAliasConfig::default()
        },
    );
    aliases.insert(
        "custom-api".to_string(),
        CcsAliasConfig {
            cmd: "ccs api custom-profile".to_string(),
            ..CcsAliasConfig::default()
        },
    );

    let resolver = CcsAliasResolver::new(aliases, default_ccs());

    // Test named profiles - when claude binary is found, it replaces "ccs ..." with claude path
    let config = resolver.try_resolve("ccs/work").unwrap();
    assert!(
        config.cmd.ends_with("claude") || config.cmd == "ccs work",
        "cmd should be 'ccs work' or a path ending with 'claude', got: {}",
        config.cmd
    );

    // Test built-in providers
    let config = resolver.try_resolve("ccs/gemini").unwrap();
    assert!(
        config.cmd.ends_with("claude") || config.cmd == "ccs gemini",
        "cmd should be 'ccs gemini' or a path ending with 'claude', got: {}",
        config.cmd
    );

    let config = resolver.try_resolve("ccs/codex").unwrap();
    assert!(
        config.cmd.ends_with("claude") || config.cmd == "ccs codex",
        "cmd should be 'ccs codex' or a path ending with 'claude', got: {}",
        config.cmd
    );

    let config = resolver.try_resolve("ccs/glm").unwrap();
    assert!(
        config.cmd.ends_with("claude") || config.cmd == "ccs glm",
        "cmd should be 'ccs glm' or a path ending with 'claude', got: {}",
        config.cmd
    );

    // Test custom API profiles
    let config = resolver.try_resolve("ccs/openrouter").unwrap();
    assert!(
        config.cmd.ends_with("claude") || config.cmd == "ccs api openrouter",
        "cmd should be 'ccs api openrouter' or a path ending with 'claude', got: {}",
        config.cmd
    );

    let config = resolver.try_resolve("ccs/custom-api").unwrap();
    assert!(
        config.cmd.ends_with("claude") || config.cmd == "ccs api custom-profile",
        "cmd should be 'ccs api custom-profile' or a path ending with 'claude', got: {}",
        config.cmd
    );
}

#[test]
fn test_ccs_config_has_correct_flags() {
    // Verify that CCS agent configs default to Claude-compatible flags
    // (users can override these via the unified config).
    let config = build_ccs_agent_config(
        &CcsAliasConfig {
            cmd: "ccs gemini".to_string(),
            ..CcsAliasConfig::default()
        },
        &default_ccs(),
        "ccs-gemini".to_string(),
        "gemini",
    );

    // CCS wraps Claude Code, so it uses Claude's stream-json format
    assert_eq!(config.output_flag, "--output-format=stream-json");
    assert_eq!(config.yolo_flag, "--dangerously-skip-permissions");
    assert_eq!(config.verbose_flag, "--verbose");
    // IMPORTANT: CCS uses `-p/--prompt` for headless delegation.
    // When invoking Claude through CCS (e.g. `ccs codex`), we must use Claude's
    // `--print` flag instead of `-p` to avoid triggering CCS delegation.
    assert_eq!(config.print_flag, "--print");
    assert_eq!(config.session_flag, "--resume {}");
    assert!(config.can_commit);

    // CCS always outputs stream-json format, so always use Claude parser
    assert_eq!(config.json_parser, JsonParserType::Claude);
    assert_eq!(config.display_name, Some("ccs-gemini".to_string()));
}

#[test]
fn test_parse_ccs_ref_edge_cases() {
    // Test edge cases in CCS reference parsing
    assert_eq!(parse_ccs_ref("ccs/"), Some("")); // Empty after prefix
    assert_eq!(parse_ccs_ref("ccs/a"), Some("a")); // Single char
    assert_eq!(
        parse_ccs_ref("ccs/with-dashes-and_underscores"),
        Some("with-dashes-and_underscores")
    );
    assert_eq!(parse_ccs_ref("ccs/with.dots"), Some("with.dots"));
    assert_eq!(parse_ccs_ref("ccs/MixedCase"), Some("MixedCase"));
    assert_eq!(parse_ccs_ref("ccs/123numeric"), Some("123numeric"));

    // These should NOT be CCS refs
    assert_eq!(parse_ccs_ref("CCS"), None); // Case sensitive
    assert_eq!(parse_ccs_ref("CCS/work"), None);
    assert_eq!(parse_ccs_ref(" ccs"), None); // Leading space
    assert_eq!(parse_ccs_ref("ccs "), None); // Trailing space (invalid ref, not just "ccs")
}

#[test]
fn test_ccs_in_agent_chain_context() {
    // Simulate how CCS aliases would be used in agent chain context
    let mut aliases = HashMap::new();
    aliases.insert(
        "work".to_string(),
        CcsAliasConfig {
            cmd: "ccs work".to_string(),
            ..CcsAliasConfig::default()
        },
    );
    aliases.insert(
        "personal".to_string(),
        CcsAliasConfig {
            cmd: "ccs personal".to_string(),
            ..CcsAliasConfig::default()
        },
    );

    let resolver = CcsAliasResolver::new(aliases, default_ccs());

    // Simulate agent chain: ["ccs/work", "claude", "codex"]
    // Behavioral test: CCS refs resolve, non-CCS refs don't
    assert!(resolver.try_resolve("ccs/work").is_some());
    assert!(resolver.try_resolve("claude").is_none()); // Not a CCS ref
    assert!(resolver.try_resolve("codex").is_none()); // Not a CCS ref

    // The resolved config should be usable
    let config = resolver.try_resolve("ccs/work").unwrap();
    assert!(config.can_commit);
    assert!(!config.cmd.is_empty());
}

#[test]
fn test_ccs_display_names() {
    // Test that CCS aliases get proper display names like "ccs-glm", "ccs-gemini"
    let mut aliases = HashMap::new();
    aliases.insert(
        "glm".to_string(),
        CcsAliasConfig {
            cmd: "ccs glm".to_string(),
            ..CcsAliasConfig::default()
        },
    );
    aliases.insert(
        "gemini".to_string(),
        CcsAliasConfig {
            cmd: "ccs gemini".to_string(),
            ..CcsAliasConfig::default()
        },
    );
    aliases.insert(
        "work".to_string(),
        CcsAliasConfig {
            cmd: "ccs work".to_string(),
            ..CcsAliasConfig::default()
        },
    );

    let resolver = CcsAliasResolver::new(aliases, default_ccs());

    // Test display names for various aliases
    let glm_config = resolver.try_resolve("ccs/glm").unwrap();
    assert_eq!(glm_config.display_name, Some("ccs-glm".to_string()));

    let gemini_config = resolver.try_resolve("ccs/gemini").unwrap();
    assert_eq!(gemini_config.display_name, Some("ccs-gemini".to_string()));

    let work_config = resolver.try_resolve("ccs/work").unwrap();
    assert_eq!(work_config.display_name, Some("ccs-work".to_string()));

    // Default CCS (no alias) should just be "ccs"
    let default_config = resolver.try_resolve("ccs").unwrap();
    assert_eq!(default_config.display_name, Some("ccs".to_string()));
}

// Step 7: Test coverage for GLM command building

#[test]
fn test_ccs_glm_command_has_print_flag() {
    // Verify that GLM commands include the print flag for non-interactive mode
    let mut aliases = HashMap::new();
    aliases.insert(
        "glm".to_string(),
        CcsAliasConfig {
            cmd: "ccs glm".to_string(),
            ..CcsAliasConfig::default()
        },
    );

    let resolver = CcsAliasResolver::new(aliases, default_ccs());
    let glm_config = resolver.try_resolve("ccs/glm").unwrap();

    // Verify print_flag is set (from defaults)
    assert_eq!(glm_config.print_flag, "--print");

    // Build the command and verify --print is included
    let cmd = glm_config.build_cmd(true, true, true);
    assert!(
        cmd.contains(" --print"),
        "GLM command must include --print flag"
    );
    // When claude binary is found, command should contain "claude" as the base command
    // The actual command is now "claude --print ..." instead of "ccs glm --print ..."
    // We check if the first word (before any space) ends with "claude"
    let first_word = cmd.split_whitespace().next().unwrap_or("");
    assert!(
        first_word.ends_with("claude") || cmd.contains("ccs glm"),
        "Command should start with a path ending in 'claude' or contain 'ccs glm', got: {cmd}"
    );
}

#[test]
fn test_ccs_glm_flag_ordering() {
    // Verify that flags are in the correct order for CCS GLM
    // The --print flag must come AFTER the command name
    let mut aliases = HashMap::new();
    aliases.insert(
        "glm".to_string(),
        CcsAliasConfig {
            cmd: "ccs glm".to_string(),
            ..CcsAliasConfig::default()
        },
    );

    let resolver = CcsAliasResolver::new(aliases, default_ccs());
    let glm_config = resolver.try_resolve("ccs/glm").unwrap();

    let cmd = glm_config.build_cmd(true, true, true);

    // Split command into parts and verify ordering
    let parts: Vec<&str> = cmd.split_whitespace().collect();

    // First part should be the claude command (path ending in "claude")
    // When using ccs directly, it would be "ccs" then "glm"
    // When using claude directly, it's just the path to claude
    let first_part = parts[0];
    assert!(
        first_part.ends_with("claude") || first_part == "ccs",
        "First part should end with 'claude' or be 'ccs', got: {first_part}"
    );

    // --print flag should come after the command name
    let p_index = parts.iter().position(|&s| s == "--print");
    assert!(p_index.is_some(), "--print flag must be present");
    assert!(
        p_index.unwrap() > 0,
        "--print flag must come after command name"
    );
}

#[test]
fn test_ccs_glm_with_empty_print_override() {
    // Test that if user explicitly sets print_flag to empty, it stays empty
    let mut aliases = HashMap::new();
    aliases.insert(
        "glm".to_string(),
        CcsAliasConfig {
            cmd: "ccs glm".to_string(),
            print_flag: Some(String::new()), // Explicit empty override
            ..CcsAliasConfig::default()
        },
    );

    let resolver = CcsAliasResolver::new(aliases, default_ccs());
    let glm_config = resolver.try_resolve("ccs/glm").unwrap();

    // User override should take precedence
    assert_eq!(glm_config.print_flag, "");

    // Command should NOT include --print (user explicitly disabled it)
    let cmd = glm_config.build_cmd(true, true, true);
    assert!(
        !cmd.contains(" --print"),
        "Command should not include --print when explicitly disabled"
    );
}

#[test]
fn test_glm_error_classification() {
    // GLM exit code 1 behavior:
    // - Empty/unknown stderr -> RetryableAgentQuirk (should retry)
    // - Known problematic patterns -> AgentSpecificQuirk or ToolExecutionFailed (both trigger fallback)
    use crate::agents::error::AgentErrorKind;

    // Empty stderr with GLM agent - treat as retryable quirk
    let error = AgentErrorKind::classify_with_agent(1, "", Some("ccs/glm"), None);
    assert_eq!(error, AgentErrorKind::RetryableAgentQuirk);

    // Generic error message with CCS GLM agent - unknown pattern, should retry
    let error = AgentErrorKind::classify_with_agent(1, "some error", Some("ccs/glm"), None);
    assert_eq!(error, AgentErrorKind::RetryableAgentQuirk);

    // GLM mentioned in stderr - known issue, should fallback
    let error = AgentErrorKind::classify_with_agent(1, "glm failed", Some("ccs"), Some("glm"));
    assert_eq!(error, AgentErrorKind::AgentSpecificQuirk);

    // Permission denied - caught by check_tool_failures first, should fallback
    // (ToolExecutionFailed also triggers fallback, just via a different code path)
    let error = AgentErrorKind::classify_with_agent(1, "permission denied", Some("ccs/glm"), None);
    assert_eq!(error, AgentErrorKind::ToolExecutionFailed);

    // CCS/GLM with failed message - known issue, should fallback
    let error = AgentErrorKind::classify_with_agent(1, "ccs glm failed", Some("ccs/glm"), None);
    assert_eq!(error, AgentErrorKind::AgentSpecificQuirk);
}

// Tests for profile fuzzy matching (choose_best_profile_guess)

#[test]
fn test_choose_best_profile_guess_exact_match() {
    let suggestions = vec!["work".to_string(), "personal".to_string()];
    let result = choose_best_profile_guess("work", &suggestions);
    assert_eq!(result, Some("work"));
}

#[test]
fn test_choose_best_profile_guess_case_insensitive() {
    let suggestions = vec!["Work".to_string(), "Personal".to_string()];
    let result = choose_best_profile_guess("work", &suggestions);
    assert_eq!(result, Some("Work"));
}

#[test]
fn test_choose_best_profile_guess_single_suggestion() {
    let suggestions = vec!["only-option".to_string()];
    let result = choose_best_profile_guess("typo", &suggestions);
    assert_eq!(result, Some("only-option"));
}

#[test]
fn test_choose_best_profile_guess_prefix_match() {
    let suggestions = vec!["work-main".to_string(), "personal".to_string()];
    let result = choose_best_profile_guess("work", &suggestions);
    assert_eq!(result, Some("work-main"));
}

#[test]
fn test_choose_best_profile_guess_no_match_returns_first() {
    let suggestions = vec!["first".to_string(), "second".to_string()];
    let result = choose_best_profile_guess("nomatch", &suggestions);
    assert_eq!(result, Some("first"));
}

#[test]
fn test_choose_best_profile_guess_empty_suggestions() {
    let suggestions: Vec<String> = vec![];
    let result = choose_best_profile_guess("work", &suggestions);
    assert_eq!(result, None);
}