nika 0.35.4

Semantic YAML workflow engine for AI tasks - DAG execution, MCP integration, multi-provider LLM support
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
//! Unit tests for the display module — icons, colors, formatting, detail levels.

use colored::Colorize;
use unicode_width::UnicodeWidthStr;

use super::colors;
use super::detail::DetailLevel;
use super::icons;
use super::renderer;

/// Strip ANSI CSI escape sequences (ESC [ ... final_byte) from a string.
///
/// Handles SGR, 256-color, and truecolor sequences by consuming
/// ESC + `[` + parameter/intermediate bytes + final byte.
fn strip_ansi(s: &str) -> String {
    let mut result = String::new();
    let mut in_escape = false;
    for ch in s.chars() {
        if ch == '\x1b' {
            in_escape = true;
        } else if in_escape && ch == 'm' {
            in_escape = false;
        } else if !in_escape {
            result.push(ch);
        }
    }
    result
}

// ═══════════════════════════════════════════════════════════════════════
// 1. Icon tests
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn all_verb_icons_are_single_column_wide() {
    for verb in &["infer", "exec", "fetch", "invoke", "agent"] {
        let plain = icons::verb_plain(verb);
        let width = UnicodeWidthStr::width(plain);
        assert_eq!(
            width, 1,
            "verb '{}' icon '{}' should be 1 column wide, got {}",
            verb, plain, width
        );
    }
}

#[test]
fn all_verb_icons_are_single_char() {
    for verb in &["infer", "exec", "fetch", "invoke", "agent"] {
        let plain = icons::verb_plain(verb);
        assert_eq!(
            plain.chars().count(),
            1,
            "verb '{}' icon should be 1 char",
            verb
        );
    }
}

#[test]
fn cosmic_palette_characters() {
    assert_eq!(icons::verb_plain("infer"), "\u{2727}"); //    assert_eq!(icons::verb_plain("exec"), "\u{2388}"); //    assert_eq!(icons::verb_plain("fetch"), "\u{2604}"); //    assert_eq!(icons::verb_plain("invoke"), "\u{229B}"); //    assert_eq!(icons::verb_plain("agent"), "\u{274B}"); //}

#[test]
fn unknown_verb_gives_fallback_icon() {
    let plain = icons::verb_plain("unknown");
    assert_eq!(plain, "\u{25CF}"); //    assert_eq!(UnicodeWidthStr::width(plain), 1);
}

#[test]
fn verb_colored_icons_return_colored_string() {
    // The colored variant should return a ColoredString (not just &str)
    let colored = icons::verb("infer");
    // When serialized, it contains the icon character regardless of color mode
    let s = colored.to_string();
    assert!(
        s.contains('\u{2727}'),
        "colored infer icon should contain star"
    );
}

#[test]
fn all_subsystem_icons_are_single_column_wide() {
    let subsystem_icons = vec![
        ("provider", "\u{22C8}"),   //        ("mcp", "\u{229E}"),        //        ("guardrail", "\u{22A0}"),  //        ("artifact", "\u{229A}"),   //        ("media", "\u{22A1}"),      //        ("structured", "\u{2B21}"), //        ("vision", "\u{27D0}"),     //        ("http", "\u{21C4}"),       //        ("retry", "\u{21AF}"),      //        ("agent_meta", "\u{2297}"), //        ("log", "\u{25AA}"),        //    ];

    for (name, ch) in &subsystem_icons {
        let width = UnicodeWidthStr::width(*ch);
        assert_eq!(
            width, 1,
            "subsystem '{}' icon '{}' should be 1 column wide, got {}",
            name, ch, width
        );
    }
}

#[test]
fn status_icons_are_single_column_wide() {
    let statuses = vec![
        ("pending", "\u{25CB}"), //        ("running", "\u{25CF}"), //        ("success", "\u{2713}"), //        ("failed", "\u{2717}"),  //        ("skipped", "\u{2298}"), //    ];

    for (name, ch) in &statuses {
        let width = UnicodeWidthStr::width(*ch);
        assert_eq!(
            width, 1,
            "status '{}' icon '{}' should be 1 column wide, got {}",
            name, ch, width
        );
    }
}

// ═══════════════════════════════════════════════════════════════════════
// 2. Token formatting
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn tokens_under_1000_are_plain() {
    assert_eq!(colors::tokens(0), "0");
    assert_eq!(colors::tokens(42), "42");
    assert_eq!(colors::tokens(842), "842");
    assert_eq!(colors::tokens(999), "999");
}

#[test]
fn tokens_1k_to_10k_have_decimal() {
    assert_eq!(colors::tokens(1000), "1.0k");
    assert_eq!(colors::tokens(1200), "1.2k");
    assert_eq!(colors::tokens(9999), "10.0k");
}

#[test]
fn tokens_above_10k_are_integer_k() {
    assert_eq!(colors::tokens(10_000), "10k");
    assert_eq!(colors::tokens(15_000), "15k");
    assert_eq!(colors::tokens(100_000), "100k");
    assert_eq!(colors::tokens(999_999), "999k");
    assert_eq!(colors::tokens(1_000_000), "1.0M");
    assert_eq!(colors::tokens(1_500_000), "1.5M");
    assert_eq!(colors::tokens(10_000_000), "10.0M");
}

// ═══════════════════════════════════════════════════════════════════════
// 3. Byte formatting
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn format_bytes_under_1kb() {
    assert_eq!(renderer::format_bytes(0), "0 B");
    assert_eq!(renderer::format_bytes(500), "500 B");
    assert_eq!(renderer::format_bytes(1023), "1023 B");
}

#[test]
fn format_bytes_kilobytes() {
    assert_eq!(renderer::format_bytes(1024), "1.0 KB");
    assert_eq!(renderer::format_bytes(1536), "1.5 KB");
    assert_eq!(renderer::format_bytes(10240), "10.0 KB");
}

#[test]
fn format_bytes_megabytes() {
    assert_eq!(renderer::format_bytes(1024 * 1024), "1.0 MB");
    assert_eq!(renderer::format_bytes(1_500_000), "1.4 MB");
    assert_eq!(renderer::format_bytes(10 * 1024 * 1024), "10.0 MB");
}

// ═══════════════════════════════════════════════════════════════════════
// 4. JSON preview
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn json_preview_truncation() {
    let json = r#"{"key":"value","long":"very long string here that goes on and on"}"#;
    let preview = colors::json_preview(json, 20);
    // The preview contains the key text
    assert!(preview.contains("key"), "preview should contain 'key'");
    // Should contain the ellipsis character (truncation indicator)
    assert!(
        preview.contains('\u{2026}'),
        "truncated preview should contain ellipsis"
    );
}

#[test]
fn json_preview_no_truncation_for_short_input() {
    let json = r#"{"a":1}"#;
    let preview = colors::json_preview(json, 100);
    let stripped = strip_ansi(&preview);
    // All content should be present, no ellipsis
    assert!(stripped.contains("\"a\""));
    assert!(stripped.contains("1"));
    assert!(!stripped.contains('\u{2026}')); // no ellipsis
}

#[test]
fn json_preview_no_panic_on_multibyte_utf8() {
    // Test with accented characters that are multi-byte in UTF-8
    let json = r#"{"title":"résumé","café":"latte"}"#;
    // Truncate in the middle of potential multi-byte sequences
    let preview = colors::json_preview(json, 15);
    // Should not panic and should produce valid UTF-8
    assert!(!preview.is_empty());
    // Verify it's valid UTF-8 by checking we can iterate chars
    let _ = preview.chars().count();
}

#[test]
fn json_preview_unicode_boundary_safety() {
    // Test with CJK characters (3-byte UTF-8) and emoji (4-byte UTF-8)
    let json = r#"{"emoji":"hello"}"#;
    // Truncate at various positions near multi-byte boundaries
    for max in 1..=20 {
        let preview = colors::json_preview(json, max);
        // Must never panic and always produce valid UTF-8
        let _ = preview.chars().count();
    }
}

#[test]
fn json_preview_empty_input() {
    let preview = colors::json_preview("", 20);
    let stripped = strip_ansi(&preview);
    // Should not panic, result should be mostly reset codes
    assert!(stripped.is_empty() || stripped.len() < 5);
}

#[test]
fn json_preview_contains_syntax_colors() {
    // json_preview embeds raw ANSI escape codes for syntax highlighting
    let json = r#"{"name":"value"}"#;
    let preview = colors::json_preview(json, 100);
    // Should contain ANSI escape sequences (raw ESC character)
    assert!(
        preview.contains('\x1b'),
        "json_preview should contain ANSI color codes"
    );
    // Blue for keys (\x1b[34m) and green for string values (\x1b[32m)
    assert!(preview.contains("\x1b[34m"), "keys should be blue");
    assert!(
        preview.contains("\x1b[32m"),
        "string values should be green"
    );
}

#[test]
fn json_preview_numbers_are_yellow() {
    let json = r#"{"count":42}"#;
    let preview = colors::json_preview(json, 100);
    // Numbers get yellow highlighting (\x1b[33m)
    assert!(preview.contains("\x1b[33m"), "numbers should be yellow");
}

// ═══════════════════════════════════════════════════════════════════════
// 5. Budget bar
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn budget_bar_contains_percentage_text() {
    let bar_30 = colors::budget_bar(30.0, 20);
    assert!(
        strip_ansi(&bar_30).contains("30%"),
        "bar should contain '30%'"
    );

    let bar_75 = colors::budget_bar(75.0, 20);
    assert!(
        strip_ansi(&bar_75).contains("75%"),
        "bar should contain '75%'"
    );

    let bar_95 = colors::budget_bar(95.0, 20);
    assert!(
        strip_ansi(&bar_95).contains("95%"),
        "bar should contain '95%'"
    );
}

#[test]
fn budget_bar_zero_and_full() {
    let zero = colors::budget_bar(0.0, 20);
    assert!(strip_ansi(&zero).contains("0%"));

    let full = colors::budget_bar(100.0, 20);
    assert!(strip_ansi(&full).contains("100%"));
}

#[test]
fn budget_bar_green_threshold() {
    // <70 should produce green. The `colored` crate's `.green()` produces
    // "\x1b[32m...\x1b[0m" when colors are enabled. We test the function's
    // color logic by verifying the ColoredString variant.
    //
    // Since budget_bar returns a String with embedded ColoredStrings, we
    // verify the threshold logic via the visible content and bar structure.
    let bar = colors::budget_bar(30.0, 20);
    let stripped = strip_ansi(&bar);
    // Should have filled blocks + empty blocks + percentage
    assert!(stripped.contains("30%"));
    // 30% of 20 = 6 filled blocks
    let filled_count = stripped.chars().filter(|&c| c == '\u{2593}').count();
    assert_eq!(filled_count, 6, "30% of 20 = 6 filled blocks");
}

#[test]
fn budget_bar_yellow_threshold() {
    let bar = colors::budget_bar(75.0, 20);
    let stripped = strip_ansi(&bar);
    assert!(stripped.contains("75%"));
    // 75% of 20 = 15 filled blocks
    let filled_count = stripped.chars().filter(|&c| c == '\u{2593}').count();
    assert_eq!(filled_count, 15, "75% of 20 = 15 filled blocks");
}

#[test]
fn budget_bar_red_threshold() {
    let bar = colors::budget_bar(95.0, 20);
    let stripped = strip_ansi(&bar);
    assert!(stripped.contains("95%"));
    // 95% of 20 = 19 filled blocks
    let filled_count = stripped.chars().filter(|&c| c == '\u{2593}').count();
    assert_eq!(filled_count, 19, "95% of 20 = 19 filled blocks");
}

#[test]
fn budget_bar_width_matches() {
    // Total bar should always be exactly `width` block characters
    for pct in [0.0, 25.0, 50.0, 75.0, 100.0] {
        let bar = colors::budget_bar(pct, 20);
        let stripped = strip_ansi(&bar);
        let blocks: usize = stripped
            .chars()
            .filter(|&c| c == '\u{2593}' || c == '\u{2591}')
            .count();
        assert_eq!(blocks, 20, "bar width should be 20 at {}%", pct);
    }
}

// ═══════════════════════════════════════════════════════════════════════
// 6. pad_colored
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn pad_colored_reaches_target_width() {
    let cs = "hello".green();
    let padded = colors::pad_colored(&cs, 20);
    let visible = colors::stripped_len(&padded);
    assert_eq!(visible, 20, "padded string should be 20 visible chars wide");
}

#[test]
fn pad_colored_no_truncation_when_already_wide() {
    let cs = "this is a long string".cyan();
    let padded = colors::pad_colored(&cs, 5);
    let visible = colors::stripped_len(&padded);
    // Should not truncate, just not add padding
    assert!(
        visible >= 21,
        "pad_colored should not truncate, visible={}",
        visible
    );
}

#[test]
fn pad_colored_exact_width() {
    let cs = "12345".normal();
    let padded = colors::pad_colored(&cs, 5);
    let visible = colors::stripped_len(&padded);
    assert_eq!(
        visible, 5,
        "should be exactly 5 when text is already 5 chars"
    );
}

#[test]
fn pad_colored_empty_string() {
    let cs = "".normal();
    let padded = colors::pad_colored(&cs, 10);
    let visible = colors::stripped_len(&padded);
    assert_eq!(visible, 10, "padding empty string to width 10");
}

// ═══════════════════════════════════════════════════════════════════════
// 7. stripped_len (colors module)
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn stripped_len_plain_text() {
    assert_eq!(colors::stripped_len("hello"), 5);
    assert_eq!(colors::stripped_len(""), 0);
    assert_eq!(colors::stripped_len("ab cd"), 5);
}

#[test]
fn stripped_len_with_colored_crate() {
    // The colored crate may or may not emit ANSI codes depending on the
    // terminal environment. stripped_len must return the correct visible
    // length either way.
    let s = "test".green().bold().to_string();
    let len = colors::stripped_len(&s);
    // In test (non-TTY) mode: "test" has no ANSI codes, len = 4
    // If colors forced by another test: the function has a known limitation
    // with CSI sequences but len >= 4 (visible content is always counted)
    assert!(
        len >= 4,
        "stripped_len should count at least the visible text"
    );
}

#[test]
fn stripped_len_consistent_with_pad_colored() {
    // pad_colored uses stripped_len internally, so they must be consistent
    let cs = "hello world".green();
    let padded = colors::pad_colored(&cs, 30);
    let visible = colors::stripped_len(&padded);
    assert_eq!(visible, 30, "pad + strip should agree on width");
}

#[test]
fn stripped_len_handles_json_preview_output() {
    // json_preview uses raw ANSI codes (\x1b[34m etc.)
    // Verify stripped_len handles these correctly
    let preview = colors::json_preview(r#"{"a":1}"#, 100);
    let len = colors::stripped_len(&preview);
    // The visible content is {"a":1} = 7 chars
    // stripped_len may not perfectly strip raw CSI codes (known limitation),
    // but it should produce a reasonable result
    assert!(
        len >= 7,
        "should count at least the JSON content, got {}",
        len
    );
}

// ═══════════════════════════════════════════════════════════════════════
// 8. DetailLevel
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn detail_level_max_shows_everything() {
    let d = DetailLevel::Max;
    assert!(d.show_sub_events());
    assert!(d.show_previews());
    assert!(d.show_sparklines());
    assert!(d.show_full_summary());
    assert!(d.show_layer_separators());
    assert!(d.show_template_events());
    assert!(!d.is_json());
}

#[test]
fn detail_level_default_shows_sub_events_but_not_previews() {
    let d = DetailLevel::Default;
    assert!(d.show_sub_events());
    assert!(!d.show_previews());
    assert!(!d.show_sparklines());
    assert!(d.show_full_summary());
    assert!(!d.show_layer_separators());
    assert!(!d.show_template_events());
    assert!(!d.is_json());
}

#[test]
fn detail_level_min_shows_nothing_extra() {
    let d = DetailLevel::Min;
    assert!(!d.show_sub_events());
    assert!(!d.show_previews());
    assert!(!d.show_sparklines());
    assert!(!d.show_full_summary());
    assert!(!d.show_layer_separators());
    assert!(!d.show_template_events());
    assert!(!d.is_json());
}

#[test]
fn detail_level_json_is_special() {
    let d = DetailLevel::Json;
    assert!(d.is_json());
    assert!(!d.show_sub_events());
    assert!(!d.show_previews());
    assert!(!d.show_sparklines());
    assert!(!d.show_full_summary());
}

#[test]
fn detail_level_default_variant_is_max() {
    assert_eq!(DetailLevel::default(), DetailLevel::Max);
}

#[test]
fn detail_level_display_roundtrip() {
    for variant in &[
        DetailLevel::Max,
        DetailLevel::Default,
        DetailLevel::Min,
        DetailLevel::Json,
    ] {
        let s = variant.to_string();
        let parsed: DetailLevel = s.parse().unwrap();
        assert_eq!(*variant, parsed, "roundtrip failed for {:?}", variant);
    }
}

#[test]
fn detail_level_parse_case_insensitive() {
    assert_eq!("MAX".parse::<DetailLevel>().unwrap(), DetailLevel::Max);
    assert_eq!("Json".parse::<DetailLevel>().unwrap(), DetailLevel::Json);
    assert_eq!("MIN".parse::<DetailLevel>().unwrap(), DetailLevel::Min);
}

#[test]
fn detail_level_parse_invalid() {
    assert!("verbose".parse::<DetailLevel>().is_err());
    assert!("".parse::<DetailLevel>().is_err());
    assert!("quiet".parse::<DetailLevel>().is_err());
}

// ═══════════════════════════════════════════════════════════════════════
// 9. Duration formatting
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn duration_sub_millisecond_shows_microseconds() {
    let d = colors::duration(0.0005);
    let stripped = strip_ansi(&d.to_string());
    assert!(
        stripped.contains("\u{00B5}s"),
        "sub-ms should show microseconds, got: {}",
        stripped
    );
}

#[test]
fn duration_milliseconds() {
    let d = colors::duration(0.5);
    let stripped = strip_ansi(&d.to_string());
    assert_eq!(stripped, "500ms", "0.5s = 500ms");
}

#[test]
fn duration_seconds() {
    let d = colors::duration(2.5);
    let stripped = strip_ansi(&d.to_string());
    assert_eq!(stripped, "2.5s");
}

#[test]
fn duration_above_60s_shows_minutes() {
    let d = colors::duration(90.0);
    let stripped = strip_ansi(&d.to_string());
    assert_eq!(stripped, "1m30.0s", "90s = 1m30.0s");
}

#[test]
fn duration_text_format_at_boundaries() {
    // Sub-millisecond
    let d = strip_ansi(&colors::duration(0.0005).to_string());
    assert!(d.ends_with("\u{00B5}s"), "got: {}", d);

    // Exactly 1ms
    let d = strip_ansi(&colors::duration(0.001).to_string());
    assert_eq!(d, "1ms");

    // Just under 1s
    let d = strip_ansi(&colors::duration(0.999).to_string());
    assert_eq!(d, "999ms");

    // Exactly 1s
    let d = strip_ansi(&colors::duration(1.0).to_string());
    assert_eq!(d, "1.0s");

    // Exactly 60s
    let d = strip_ansi(&colors::duration(60.0).to_string());
    assert_eq!(d, "1m0.0s");

    // 125s = 2m5.0s
    let d = strip_ansi(&colors::duration(125.0).to_string());
    assert_eq!(d, "2m5.0s");
}

#[test]
fn duration_color_thresholds() {
    // Test color thresholds: <1s green, 1-5s yellow, >=5s red.
    // We verify by checking the ColoredString's fgcolor field via Debug output,
    // since the colored crate may not emit ANSI codes in test (non-TTY) mode.
    let green_dur = colors::duration(0.5);
    let green_dbg = format!("{:?}", green_dur);
    assert!(
        green_dbg.contains("Green") || green_dbg.contains("green"),
        "0.5s should be green, debug: {}",
        green_dbg
    );

    let yellow_dur = colors::duration(2.5);
    let yellow_dbg = format!("{:?}", yellow_dur);
    assert!(
        yellow_dbg.contains("Yellow") || yellow_dbg.contains("yellow"),
        "2.5s should be yellow, debug: {}",
        yellow_dbg
    );

    let red_dur = colors::duration(10.0);
    let red_dbg = format!("{:?}", red_dur);
    assert!(
        red_dbg.contains("Red") || red_dbg.contains("red"),
        "10s should be red, debug: {}",
        red_dbg
    );
}

#[test]
fn duration_color_at_exact_boundaries() {
    // Exactly 1.0s: >= 1.0, < 5.0 -> yellow
    let at_1s = format!("{:?}", colors::duration(1.0));
    assert!(
        at_1s.contains("Yellow") || at_1s.contains("yellow"),
        "1.0s should be yellow, debug: {}",
        at_1s
    );

    // Exactly 5.0s: >= 5.0 -> red
    let at_5s = format!("{:?}", colors::duration(5.0));
    assert!(
        at_5s.contains("Red") || at_5s.contains("red"),
        "5.0s should be red, debug: {}",
        at_5s
    );

    // Just under 1.0s -> green
    let under_1s = format!("{:?}", colors::duration(0.999));
    assert!(
        under_1s.contains("Green") || under_1s.contains("green"),
        "0.999s should be green, debug: {}",
        under_1s
    );
}

// ═══════════════════════════════════════════════════════════════════════
// 10. Sparkline
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn sparkline_zero_max_does_not_panic() {
    let s = colors::sparkline(0, 0);
    let stripped = strip_ansi(&s.to_string());
    assert_eq!(
        stripped.chars().count(),
        8,
        "sparkline should be 8 chars wide"
    );
}

#[test]
fn sparkline_full_ratio() {
    let s = colors::sparkline(100, 100);
    let stripped = strip_ansi(&s.to_string());
    // At 100% ratio, all 8 cells should be the highest block char
    assert_eq!(stripped.chars().count(), 8);
    // Should contain full block characters (U+2588)
    assert!(
        stripped.contains('\u{2588}'),
        "full ratio should have full blocks"
    );
}

// ═══════════════════════════════════════════════════════════════════════
// 11. Cost formatting
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn cost_formatting() {
    let tiny = strip_ansi(&colors::cost(0.0001).to_string());
    assert!(tiny.starts_with('$'), "cost should start with $");

    let small = strip_ansi(&colors::cost(0.005).to_string());
    assert!(small.starts_with('$'));

    let large = strip_ansi(&colors::cost(1.23).to_string());
    assert_eq!(large, "$1.23");
}

// ═══════════════════════════════════════════════════════════════════════
// 12. TTFT formatting
// ═══════════════════════════════════════════════════════════════════════

#[test]
fn ttft_formatting() {
    let fast = strip_ansi(&colors::ttft(100).to_string());
    assert_eq!(fast, "100ms");

    let medium = strip_ansi(&colors::ttft(300).to_string());
    assert_eq!(medium, "300ms");

    let slow = strip_ansi(&colors::ttft(600).to_string());
    assert_eq!(slow, "600ms");
}