trueno 0.17.3

High-performance SIMD compute library with GPU support for matrix operations
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
//! Coverage tests for analysis.rs: critical_path, critical_path_summary, format_node_name.
//!
//! Target uncovered functions:
//!   - critical_path (line 39, 84.4% cov) — Transfer edge handling, single-node path
//!   - critical_path_summary (line 273, 72.1% cov) — parallelization opportunities section
//!   - format_node_name (line 329, 30.8% cov) — Transfer, AsyncTask branches

use super::super::*;

// ========================================================================
// critical_path tests — cover Transfer edges, Sequence edges, single-node
// ========================================================================

/// Empty graph produces empty critical path.
#[test]
fn test_critical_path_empty_graph() {
    let graph = ExecutionGraph::new();
    let (path, total) = graph.critical_path();
    assert!(path.is_empty());
    assert_eq!(total, 0);
}

/// Single node graph — critical path is just that node.
#[test]
fn test_critical_path_single_node() {
    let mut graph = ExecutionGraph::new();
    graph.add_node(ExecutionNode::Brick { id: BrickId::RmsNorm, timing_ns: 5000, elements: 1024 });
    let (path, total) = graph.critical_path();
    assert_eq!(path.len(), 1);
    assert_eq!(total, 5000);
}

/// Linear chain with DependsOn edges — critical path follows the chain.
#[test]
fn test_critical_path_linear_depends_on() {
    let mut graph = ExecutionGraph::new();
    let a = graph.add_node(ExecutionNode::Brick {
        id: BrickId::RmsNorm,
        timing_ns: 1000,
        elements: 512,
    });
    let b = graph.add_node(ExecutionNode::Brick {
        id: BrickId::QkvProjection,
        timing_ns: 3000,
        elements: 2048,
    });
    let c = graph.add_node(ExecutionNode::Brick {
        id: BrickId::AttentionScore,
        timing_ns: 2000,
        elements: 1024,
    });
    graph.add_dependency(a, b);
    graph.add_dependency(b, c);

    let (path, total) = graph.critical_path();
    assert!(path.len() >= 2, "Path should include at least 2 nodes");
    assert!(total >= 5000, "Total should be at least 5000ns: got {}", total);
}

/// Sequence edges are included in critical path analysis.
#[test]
fn test_critical_path_sequence_edges() {
    let mut graph = ExecutionGraph::new();
    let a = graph.add_node(ExecutionNode::Brick {
        id: BrickId::RmsNorm,
        timing_ns: 1000,
        elements: 256,
    });
    let b = graph.add_node(ExecutionNode::Brick {
        id: BrickId::LayerNorm,
        timing_ns: 2000,
        elements: 256,
    });
    graph.add_edge(a, b, EdgeType::Sequence);

    let (path, total) = graph.critical_path();
    assert!(!path.is_empty());
    assert!(total >= 2000, "Total should include sequence weight");
}

/// Transfer edges (EdgeType::Transfer) are handled in critical path.
#[test]
fn test_critical_path_transfer_edge() {
    let mut graph = ExecutionGraph::new();
    let brick = graph.add_node(ExecutionNode::Brick {
        id: BrickId::QkvProjection,
        timing_ns: 2000,
        elements: 1024,
    });
    let transfer = graph.add_node(ExecutionNode::Transfer {
        src: "host".into(),
        dst: "gpu0".into(),
        bytes: 1_000_000,
        direction: TransferDirection::H2D,
        timing_ns: Some(500),
    });
    graph.add_edge(
        brick,
        transfer,
        EdgeType::Transfer { bytes: 1_000_000, direction: TransferDirection::H2D },
    );

    let (path, total) = graph.critical_path();
    assert!(!path.is_empty());
    // The total should include the transfer node timing
    assert!(total >= 500, "Total should include transfer timing: got {}", total);
}

/// Contains edges contribute to critical path (hierarchical).
#[test]
fn test_critical_path_contains_edges() {
    let mut graph = ExecutionGraph::new();
    let layer = graph.add_node(ExecutionNode::Layer { index: 0 });
    let brick = graph.add_node(ExecutionNode::Brick {
        id: BrickId::RmsNorm,
        timing_ns: 5000,
        elements: 2048,
    });
    graph.add_edge(layer, brick, EdgeType::Contains);

    let (path, total) = graph.critical_path();
    assert!(path.len() >= 2, "Path should contain layer and brick");
    assert!(total >= 5000, "Total should include brick timing");
}

/// Calls edges contribute to critical path.
#[test]
fn test_critical_path_calls_edges() {
    let mut graph = ExecutionGraph::new();
    let func1 =
        graph.add_node(ExecutionNode::Function { name: "outer".into(), file: None, line: None });
    let func2 = graph.add_node(ExecutionNode::Brick {
        id: BrickId::GateProjection,
        timing_ns: 7000,
        elements: 4096,
    });
    graph.add_edge(func1, func2, EdgeType::Calls);

    let (path, total) = graph.critical_path();
    assert!(!path.is_empty());
    assert!(total >= 7000, "Total should include brick timing via Calls edge");
}

/// Launches edges contribute to critical path.
#[test]
fn test_critical_path_launches_edges() {
    let mut graph = ExecutionGraph::new();
    let brick = graph.add_node(ExecutionNode::Brick {
        id: BrickId::QkvProjection,
        timing_ns: 3000,
        elements: 1024,
    });
    let kernel = graph.add_node(ExecutionNode::Kernel {
        name: "gemv".into(),
        ptx_hash: 0xDEAD,
        grid: (4, 1, 1),
        block: (128, 1, 1),
        shared_mem: 2048,
        timing_ns: Some(1500),
        arithmetic_intensity: None,
        achieved_tflops: None,
    });
    graph.add_edge(brick, kernel, EdgeType::Launches);

    let (path, total) = graph.critical_path();
    assert!(path.len() >= 2);
    assert!(total >= 1500, "Total should include kernel timing via Launches edge");
}

/// Diamond graph — critical path picks the longer branch.
#[test]
fn test_critical_path_diamond() {
    let mut graph = ExecutionGraph::new();
    let start = graph.add_node(ExecutionNode::Brick {
        id: BrickId::Embedding,
        timing_ns: 100,
        elements: 64,
    });
    // Fast path
    let fast = graph.add_node(ExecutionNode::Brick {
        id: BrickId::RmsNorm,
        timing_ns: 1000,
        elements: 64,
    });
    // Slow path
    let slow = graph.add_node(ExecutionNode::Brick {
        id: BrickId::QkvProjection,
        timing_ns: 9000,
        elements: 64,
    });
    let end =
        graph.add_node(ExecutionNode::Brick { id: BrickId::LmHead, timing_ns: 200, elements: 64 });

    graph.add_dependency(start, fast);
    graph.add_dependency(start, slow);
    graph.add_dependency(fast, end);
    graph.add_dependency(slow, end);

    let (path, total) = graph.critical_path();
    // Should pick start -> slow -> end
    assert!(path.len() >= 2);
    assert!(total >= 9000, "Critical path should follow slow branch: got {}", total);
}

/// Kernel with no timing (timing_ns = None) contributes 0 to critical path.
#[test]
fn test_critical_path_kernel_no_timing() {
    let mut graph = ExecutionGraph::new();
    let brick = graph.add_node(ExecutionNode::Brick {
        id: BrickId::RmsNorm,
        timing_ns: 1000,
        elements: 256,
    });
    let kernel = graph.add_node(ExecutionNode::Kernel {
        name: "untimed_kernel".into(),
        ptx_hash: 0,
        grid: (1, 1, 1),
        block: (32, 1, 1),
        shared_mem: 0,
        timing_ns: None,
        arithmetic_intensity: None,
        achieved_tflops: None,
    });
    graph.add_edge(brick, kernel, EdgeType::Launches);

    let (path, total) = graph.critical_path();
    assert!(!path.is_empty());
    // Kernel with None timing contributes 0
    assert_eq!(total, 1000, "Kernel with no timing should contribute 0");
}

/// Transfer with no timing (timing_ns = None) contributes 0.
#[test]
fn test_critical_path_transfer_no_timing() {
    let mut graph = ExecutionGraph::new();
    let brick = graph.add_node(ExecutionNode::Brick {
        id: BrickId::RmsNorm,
        timing_ns: 2000,
        elements: 128,
    });
    let transfer = graph.add_node(ExecutionNode::Transfer {
        src: "host".into(),
        dst: "gpu0".into(),
        bytes: 4096,
        direction: TransferDirection::H2D,
        timing_ns: None,
    });
    graph.add_edge(brick, transfer, EdgeType::Contains);

    let (path, _total) = graph.critical_path();
    assert!(!path.is_empty());
}

/// Layer and Function nodes contribute 0 timing to critical path.
#[test]
fn test_critical_path_zero_timing_nodes() {
    let mut graph = ExecutionGraph::new();
    let layer = graph.add_node(ExecutionNode::Layer { index: 0 });
    let func =
        graph.add_node(ExecutionNode::Function { name: "setup".into(), file: None, line: None });
    graph.add_edge(layer, func, EdgeType::Contains);

    let (path, total) = graph.critical_path();
    assert!(!path.is_empty());
    assert_eq!(total, 0, "Layer and Function contribute 0 timing");
}

/// AsyncTask nodes contribute 0 timing to critical path.
#[test]
fn test_critical_path_async_task() {
    let mut graph = ExecutionGraph::new();
    let async_node = graph.add_node(ExecutionNode::AsyncTask {
        name: "prefetch".into(),
        poll_count: 5,
        yield_count: 2,
        total_poll_ns: 10_000,
    });
    let brick = graph.add_node(ExecutionNode::Brick {
        id: BrickId::Activation,
        timing_ns: 3000,
        elements: 512,
    });
    graph.add_dependency(async_node, brick);

    let (path, total) = graph.critical_path();
    assert!(!path.is_empty());
    // AsyncTask contributes 0 timing, brick contributes 3000
    assert!(total >= 3000);
}

// ========================================================================
// critical_path_summary tests — cover parallelization opportunities
// ========================================================================

/// Summary for empty graph.
#[test]
fn test_critical_path_summary_empty() {
    let graph = ExecutionGraph::new();
    let summary = graph.critical_path_summary();
    assert!(summary.contains("Critical Path:"));
    assert!(summary.contains("0 nodes"));
}

/// Summary for single-node graph (no parallelization opportunities).
#[test]
fn test_critical_path_summary_single_node() {
    let mut graph = ExecutionGraph::new();
    graph.add_node(ExecutionNode::Brick { id: BrickId::RmsNorm, timing_ns: 5000, elements: 1024 });

    let summary = graph.critical_path_summary();
    assert!(summary.contains("Critical Path:"));
    assert!(summary.contains("1 nodes"));
    // Single node on critical path means no parallelization opportunities
}

/// Summary for linear chain — shows node names and prefix characters.
#[test]
fn test_critical_path_summary_chain() {
    let mut graph = ExecutionGraph::new();
    let a = graph.add_node(ExecutionNode::Brick {
        id: BrickId::RmsNorm,
        timing_ns: 1000,
        elements: 256,
    });
    let b = graph.add_node(ExecutionNode::Brick {
        id: BrickId::QkvProjection,
        timing_ns: 3000,
        elements: 1024,
    });
    let c = graph.add_node(ExecutionNode::Brick {
        id: BrickId::AttentionScore,
        timing_ns: 2000,
        elements: 512,
    });
    graph.add_dependency(a, b);
    graph.add_dependency(b, c);

    let summary = graph.critical_path_summary();
    assert!(summary.contains("Critical Path:"));
    // Should show Unicode box-drawing characters for path rendering
    assert!(
        summary.contains("\u{250c}")
            || summary.contains("\u{2502}")
            || summary.contains("\u{2514}"),
        "Summary should contain box-drawing characters for path prefix"
    );
}

/// Summary shows parallelization opportunities (nodes with slack > 0).
#[test]
fn test_critical_path_summary_with_slack() {
    let mut graph = ExecutionGraph::new();

    // Create a diamond so the off-path branch has slack
    let start = graph.add_node(ExecutionNode::Brick {
        id: BrickId::Embedding,
        timing_ns: 100,
        elements: 32,
    });
    let fast = graph.add_node(ExecutionNode::Brick {
        id: BrickId::RmsNorm,
        timing_ns: 1000,
        elements: 64,
    });
    let slow = graph.add_node(ExecutionNode::Brick {
        id: BrickId::QkvProjection,
        timing_ns: 10_000,
        elements: 2048,
    });
    let end =
        graph.add_node(ExecutionNode::Brick { id: BrickId::LmHead, timing_ns: 200, elements: 32 });

    graph.add_dependency(start, fast);
    graph.add_dependency(start, slow);
    graph.add_dependency(fast, end);
    graph.add_dependency(slow, end);

    let summary = graph.critical_path_summary();
    assert!(summary.contains("Critical Path:"));
    // The fast path node should have slack -> parallelization opportunities
    assert!(
        summary.contains("Parallelization Opportunities"),
        "Should show parallelization opportunities when slack exists: {}",
        summary
    );
    assert!(summary.contains("slack="), "Should show slack values: {}", summary);
}

/// Summary with Transfer node in the path exercises format_node_name for Transfer.
#[test]
fn test_critical_path_summary_with_transfer() {
    let mut graph = ExecutionGraph::new();
    let brick = graph.add_node(ExecutionNode::Brick {
        id: BrickId::QkvProjection,
        timing_ns: 2000,
        elements: 1024,
    });
    let transfer = graph.add_node(ExecutionNode::Transfer {
        src: "host".into(),
        dst: "gpu0".into(),
        bytes: 1_000_000,
        direction: TransferDirection::H2D,
        timing_ns: Some(5000),
    });
    graph.add_edge(brick, transfer, EdgeType::Contains);

    let summary = graph.critical_path_summary();
    assert!(summary.contains("Critical Path:"));
    // Transfer format_node_name should show "H2D host -> gpu0"
    assert!(
        summary.contains("H2D") || summary.contains("QkvProjection"),
        "Summary should mention transfer or brick name: {}",
        summary
    );
}

/// Summary with AsyncTask node exercises format_node_name for AsyncTask.
#[test]
fn test_critical_path_summary_with_async_task() {
    let mut graph = ExecutionGraph::new();
    let async_node = graph.add_node(ExecutionNode::AsyncTask {
        name: "prefetch_weights".into(),
        poll_count: 5,
        yield_count: 3,
        total_poll_ns: 10_000,
    });
    let brick = graph.add_node(ExecutionNode::Brick {
        id: BrickId::RmsNorm,
        timing_ns: 3000,
        elements: 512,
    });
    graph.add_dependency(async_node, brick);

    let summary = graph.critical_path_summary();
    assert!(summary.contains("Critical Path:"));
}

/// Summary with Kernel and Function nodes exercises those format_node_name branches.
#[test]
fn test_critical_path_summary_kernel_and_function() {
    let mut graph = ExecutionGraph::new();
    let func = graph.add_node(ExecutionNode::Function {
        name: "forward".into(),
        file: Some("model.rs".into()),
        line: Some(42),
    });
    let kernel = graph.add_node(ExecutionNode::Kernel {
        name: "matmul_kernel".into(),
        ptx_hash: 0xABCD,
        grid: (8, 1, 1),
        block: (256, 1, 1),
        shared_mem: 4096,
        timing_ns: Some(5000),
        arithmetic_intensity: None,
        achieved_tflops: None,
    });
    graph.add_edge(func, kernel, EdgeType::Launches);

    let summary = graph.critical_path_summary();
    assert!(summary.contains("matmul_kernel") || summary.contains("forward"));
}

/// Summary with Layer node exercises the Layer branch of format_node_name.
#[test]
fn test_critical_path_summary_layer() {
    let mut graph = ExecutionGraph::new();
    let layer = graph.add_node(ExecutionNode::Layer { index: 3 });
    let brick = graph.add_node(ExecutionNode::Brick {
        id: BrickId::RmsNorm,
        timing_ns: 1000,
        elements: 64,
    });
    graph.add_edge(layer, brick, EdgeType::Contains);

    let summary = graph.critical_path_summary();
    assert!(summary.contains("Layer 3") || summary.contains("RmsNorm"));
}

// ========================================================================
// format_node_name tests — exercise all branches via critical_path_summary
// ========================================================================

/// format_node_name: Transfer node with D2H direction.
#[test]
fn test_format_node_name_via_summary_transfer_d2h() {
    let mut graph = ExecutionGraph::new();
    // Only node — will be on critical path, exercising format_node_name
    graph.add_node(ExecutionNode::Transfer {
        src: "gpu0".into(),
        dst: "host".into(),
        bytes: 2048,
        direction: TransferDirection::D2H,
        timing_ns: Some(1000),
    });

    let summary = graph.critical_path_summary();
    assert!(
        summary.contains("D2H"),
        "Summary should contain D2H from format_node_name: {}",
        summary
    );
    assert!(summary.contains("gpu0"), "Summary should contain src: {}", summary);
}

/// format_node_name: Transfer node with D2D direction.
#[test]
fn test_format_node_name_via_summary_transfer_d2d() {
    let mut graph = ExecutionGraph::new();
    graph.add_node(ExecutionNode::Transfer {
        src: "gpu0".into(),
        dst: "gpu1".into(),
        bytes: 4096,
        direction: TransferDirection::D2D,
        timing_ns: Some(500),
    });

    let summary = graph.critical_path_summary();
    assert!(summary.contains("D2D"), "Summary should contain D2D: {}", summary);
}

/// format_node_name: AsyncTask node with poll_count.
#[test]
fn test_format_node_name_via_summary_async_task() {
    let mut graph = ExecutionGraph::new();
    graph.add_node(ExecutionNode::AsyncTask {
        name: "fetch_data".into(),
        poll_count: 7,
        yield_count: 4,
        total_poll_ns: 15_000,
    });

    let summary = graph.critical_path_summary();
    assert!(summary.contains("fetch_data"), "Summary should contain async task name: {}", summary);
    assert!(
        summary.contains("7polls"),
        "Summary should contain poll count from format_node_name: {}",
        summary
    );
}

/// format_node_name: Layer node.
#[test]
fn test_format_node_name_via_summary_layer() {
    let mut graph = ExecutionGraph::new();
    graph.add_node(ExecutionNode::Layer { index: 42 });

    let summary = graph.critical_path_summary();
    assert!(summary.contains("Layer 42"), "Summary should contain Layer name: {}", summary);
}

/// format_node_name: Brick node (exercises id.name()).
#[test]
fn test_format_node_name_via_summary_brick() {
    let mut graph = ExecutionGraph::new();
    graph.add_node(ExecutionNode::Brick {
        id: BrickId::DownProjection,
        timing_ns: 6000,
        elements: 4096,
    });

    let summary = graph.critical_path_summary();
    assert!(summary.contains("DownProjection"), "Summary should contain brick name: {}", summary);
}

/// format_node_name: Kernel node (exercises name clone).
#[test]
fn test_format_node_name_via_summary_kernel() {
    let mut graph = ExecutionGraph::new();
    graph.add_node(ExecutionNode::Kernel {
        name: "softmax_warp".into(),
        ptx_hash: 0xFF,
        grid: (4, 1, 1),
        block: (128, 1, 1),
        shared_mem: 1024,
        timing_ns: Some(3000),
        arithmetic_intensity: None,
        achieved_tflops: None,
    });

    let summary = graph.critical_path_summary();
    assert!(summary.contains("softmax_warp"), "Summary should contain kernel name: {}", summary);
}

/// format_node_name: Function node.
#[test]
fn test_format_node_name_via_summary_function() {
    let mut graph = ExecutionGraph::new();
    graph.add_node(ExecutionNode::Function {
        name: "inference".into(),
        file: Some("main.rs".into()),
        line: Some(10),
    });

    let summary = graph.critical_path_summary();
    assert!(summary.contains("inference"), "Summary should contain function name: {}", summary);
}

// ========================================================================
// compute_slack tests — exercise the slack computation paths
// ========================================================================

/// Slack for empty graph.
#[test]
fn test_compute_slack_empty() {
    let graph = ExecutionGraph::new();
    let slack = graph.compute_slack();
    assert!(slack.is_empty());
}

/// Single node on critical path has slack = 0.
#[test]
fn test_compute_slack_single_node() {
    let mut graph = ExecutionGraph::new();
    graph.add_node(ExecutionNode::Brick { id: BrickId::RmsNorm, timing_ns: 1000, elements: 64 });

    let slack = graph.compute_slack();
    assert_eq!(slack.len(), 1);
    assert_eq!(slack[&ExecutionNodeId(0)], 0);
}

/// Diamond graph — off-critical-path node has slack > 0.
#[test]
fn test_compute_slack_diamond() {
    let mut graph = ExecutionGraph::new();
    let start = graph.add_node(ExecutionNode::Brick {
        id: BrickId::Embedding,
        timing_ns: 100,
        elements: 32,
    });
    let fast = graph.add_node(ExecutionNode::Brick {
        id: BrickId::RmsNorm,
        timing_ns: 1000,
        elements: 64,
    });
    let slow = graph.add_node(ExecutionNode::Brick {
        id: BrickId::QkvProjection,
        timing_ns: 10_000,
        elements: 2048,
    });
    let end =
        graph.add_node(ExecutionNode::Brick { id: BrickId::LmHead, timing_ns: 200, elements: 32 });

    graph.add_dependency(start, fast);
    graph.add_dependency(start, slow);
    graph.add_dependency(fast, end);
    graph.add_dependency(slow, end);

    let slack = graph.compute_slack();
    // The "fast" path should have non-zero slack
    let fast_slack = slack[&fast];
    assert!(fast_slack > 0, "Fast branch should have positive slack: got {}", fast_slack);
}

// ========================================================================
// critical_path_summary prefix rendering — two-node path has start/end
// ========================================================================

/// Two-node path should render with start (box-drawing top) and end (box-drawing bottom).
#[test]
fn test_critical_path_summary_two_node_prefix() {
    let mut graph = ExecutionGraph::new();
    let a = graph.add_node(ExecutionNode::Brick {
        id: BrickId::RmsNorm,
        timing_ns: 1000,
        elements: 64,
    });
    let b = graph.add_node(ExecutionNode::Brick {
        id: BrickId::QkvProjection,
        timing_ns: 2000,
        elements: 128,
    });
    graph.add_dependency(a, b);

    let summary = graph.critical_path_summary();
    // Two-node path: first gets "top-left corner", last gets "bottom-left corner"
    assert!(
        summary.contains("\u{250c}"),
        "First node should have top-left corner prefix: {}",
        summary
    );
    assert!(
        summary.contains("\u{2514}"),
        "Last node should have bottom-left corner prefix: {}",
        summary
    );
}

/// Three-node path has middle prefix character.
#[test]
fn test_critical_path_summary_three_node_prefix() {
    let mut graph = ExecutionGraph::new();
    let a = graph.add_node(ExecutionNode::Brick {
        id: BrickId::RmsNorm,
        timing_ns: 1000,
        elements: 64,
    });
    let b = graph.add_node(ExecutionNode::Brick {
        id: BrickId::QkvProjection,
        timing_ns: 3000,
        elements: 128,
    });
    let c = graph.add_node(ExecutionNode::Brick {
        id: BrickId::AttentionScore,
        timing_ns: 2000,
        elements: 256,
    });
    graph.add_dependency(a, b);
    graph.add_dependency(b, c);

    let summary = graph.critical_path_summary();
    // Three-node path: middle gets pipe character
    assert!(
        summary.contains("\u{2502}"),
        "Middle node should have pipe prefix in 3-node path: {}",
        summary
    );
}