aprender-orchestrate 0.31.2

Sovereign AI orchestration: autonomous agents, ML serving, code analysis, and transpilation pipelines
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
//! Stack Tree View - Visual hierarchical representation of PAIML stack
//!
//! Implements spec: docs/specifications/stack-tree-view.md

use serde::{Deserialize, Serialize};
use std::fmt;

// ============================================================================
// TREE-001: Core Types
// ============================================================================

/// Health status of a component
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum HealthStatus {
    /// Local and remote versions match
    Synced,
    /// Local version is behind remote
    Behind,
    /// Local version is ahead of remote
    Ahead,
    /// Crate not found on crates.io
    NotFound,
    /// Error checking status
    Error(String),
}

impl fmt::Display for HealthStatus {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Synced => write!(f, ""),
            Self::Behind => write!(f, ""),
            Self::Ahead => write!(f, ""),
            Self::NotFound => write!(f, "?"),
            Self::Error(_) => write!(f, ""),
        }
    }
}

/// A component in the PAIML stack
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Component {
    /// Crate name
    pub name: String,
    /// Short description
    pub description: String,
    /// Local version if found
    pub version_local: Option<semver::Version>,
    /// Remote version from crates.io
    pub version_remote: Option<semver::Version>,
    /// Health status
    pub health: HealthStatus,
}

impl Component {
    /// Create a new component
    pub fn new(name: impl Into<String>, description: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            description: description.into(),
            version_local: None,
            version_remote: None,
            health: HealthStatus::NotFound,
        }
    }

    /// Set local version
    pub fn with_local_version(mut self, version: semver::Version) -> Self {
        self.version_local = Some(version);
        self.update_health();
        self
    }

    /// Set remote version
    pub fn with_remote_version(mut self, version: semver::Version) -> Self {
        self.version_remote = Some(version);
        self.update_health();
        self
    }

    /// Update health based on versions
    fn update_health(&mut self) {
        self.health = match (&self.version_local, &self.version_remote) {
            (Some(local), Some(remote)) => {
                if local == remote {
                    HealthStatus::Synced
                } else if local < remote {
                    HealthStatus::Behind
                } else {
                    HealthStatus::Ahead
                }
            }
            (Some(_), None) => HealthStatus::NotFound,
            (None, Some(_)) => HealthStatus::NotFound,
            (None, None) => HealthStatus::NotFound,
        };
    }
}

/// A layer in the PAIML stack
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StackLayer {
    /// Layer name (e.g., "core", "ml")
    pub name: String,
    /// Components in this layer
    pub components: Vec<Component>,
}

impl StackLayer {
    /// Create a new layer
    pub fn new(name: impl Into<String>) -> Self {
        Self { name: name.into(), components: Vec::new() }
    }

    /// Add a component to this layer
    pub fn add_component(mut self, component: Component) -> Self {
        self.components.push(component);
        self
    }
}

/// The complete PAIML stack tree
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StackTree {
    /// Stack name
    pub name: String,
    /// Total crate count
    pub total_crates: usize,
    /// Layers in the stack
    pub layers: Vec<StackLayer>,
}

impl StackTree {
    /// Create a new stack tree
    pub fn new(name: impl Into<String>) -> Self {
        Self { name: name.into(), total_crates: 0, layers: Vec::new() }
    }

    /// Add a layer to the tree
    pub fn add_layer(mut self, layer: StackLayer) -> Self {
        self.total_crates += layer.components.len();
        self.layers.push(layer);
        self
    }

    /// Get total synced count
    pub fn synced_count(&self) -> usize {
        self.layers
            .iter()
            .flat_map(|l| &l.components)
            .filter(|c| c.health == HealthStatus::Synced)
            .count()
    }

    /// Get total behind count
    pub fn behind_count(&self) -> usize {
        self.layers
            .iter()
            .flat_map(|l| &l.components)
            .filter(|c| c.health == HealthStatus::Behind)
            .count()
    }
}

// ============================================================================
// TREE-002: Output Formats
// ============================================================================

/// Output format for the tree
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum OutputFormat {
    /// ASCII tree (default)
    #[default]
    Ascii,
    /// JSON output
    Json,
    /// Graphviz DOT format
    Dot,
}

impl std::str::FromStr for OutputFormat {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "ascii" => Ok(Self::Ascii),
            "json" => Ok(Self::Json),
            "dot" => Ok(Self::Dot),
            _ => Err(format!("Unknown format: {s}")),
        }
    }
}

// ============================================================================
// TREE-003: Formatters
// ============================================================================

/// Format a single component line for ASCII tree output.
fn format_component_line(
    comp: &Component,
    show_health: bool,
    comp_prefix: &str,
    comp_branch: &str,
) -> String {
    if !show_health {
        return format!("{}{}{}\n", comp_prefix, comp_branch, comp.name);
    }
    let version_str = match (&comp.version_local, &comp.version_remote) {
        (Some(local), Some(remote)) if local != remote => {
            format!("v{}{}", local, remote)
        }
        (Some(local), _) => format!("v{}", local),
        _ => String::new(),
    };
    format!("{}{}{} {} {}\n", comp_prefix, comp_branch, comp.name, comp.health, version_str)
}

/// Format tree as ASCII
pub fn format_ascii(tree: &StackTree, show_health: bool) -> String {
    let mut output = format!("{} ({} crates)\n", tree.name, tree.total_crates);

    for (layer_idx, layer) in tree.layers.iter().enumerate() {
        let is_last_layer = layer_idx == tree.layers.len() - 1;
        let layer_prefix = if is_last_layer { "└── " } else { "├── " };
        output.push_str(&format!("{}{}\n", layer_prefix, layer.name));

        let comp_prefix = if is_last_layer { "    " } else { "" };
        for (comp_idx, comp) in layer.components.iter().enumerate() {
            let comp_branch =
                if comp_idx == layer.components.len() - 1 { "└── " } else { "├── " };
            output.push_str(&format_component_line(comp, show_health, comp_prefix, comp_branch));
        }
    }

    output
}

/// Format tree as JSON
pub fn format_json(tree: &StackTree) -> Result<String, serde_json::Error> {
    serde_json::to_string_pretty(tree)
}

/// Format tree as Graphviz DOT
pub fn format_dot(tree: &StackTree) -> String {
    let mut output = String::from("digraph paiml_stack {\n");
    output.push_str("  rankdir=TB;\n");
    output.push_str("  node [shape=box];\n\n");

    for layer in &tree.layers {
        output.push_str(&format!("  subgraph cluster_{} {{\n", layer.name.replace(' ', "_")));
        output.push_str(&format!("    label=\"{}\";\n", layer.name));

        for comp in &layer.components {
            let color = match comp.health {
                HealthStatus::Synced => "green",
                HealthStatus::Behind => "orange",
                HealthStatus::Ahead => "blue",
                HealthStatus::NotFound => "gray",
                HealthStatus::Error(_) => "red",
            };
            output.push_str(&format!("    {} [color={}];\n", comp.name.replace('-', "_"), color));
        }

        output.push_str("  }\n\n");
    }

    output.push_str("}\n");
    output
}

// ============================================================================
// TREE-004: Builder
// ============================================================================

/// Layer definitions for PAIML stack
pub const LAYER_DEFINITIONS: &[(&str, &[&str])] = &[
    ("core", &["trueno", "trueno-viz", "trueno-db", "trueno-graph", "trueno-rag", "trueno-zram"]),
    ("ml", &["aprender", "aprender-shell", "aprender-tsp"]),
    ("inference", &["realizar", "renacer", "alimentar", "entrenar"]),
    ("orchestration", &["batuta", "certeza", "presentar", "pacha"]),
    ("distributed", &["repartir", "pepita"]),
    ("inference", &["whisper-apr"]),
    ("transpilation", &["ruchy", "decy", "depyler", "bashrs"]),
    ("docs", &["sovereign-ai-stack-book"]),
];

/// Component descriptions
pub fn get_component_description(name: &str) -> &'static str {
    match name {
        "trueno" => "SIMD tensor operations",
        "trueno-viz" => "Visualization",
        "trueno-db" => "Vector database",
        "trueno-graph" => "Graph algorithms",
        "trueno-rag" => "RAG framework",
        "trueno-zram" => "SIMD memory compression",
        "aprender" => "ML algorithms",
        "aprender-shell" => "REPL",
        "aprender-tsp" => "TSP solver",
        "realizar" => "Inference engine",
        "renacer" => "Model lifecycle",
        "alimentar" => "Data pipelines",
        "entrenar" => "Experiment tracking",
        "batuta" => "Orchestrator",
        "certeza" => "Quality gates",
        "presentar" => "Presentation",
        "pacha" => "Knowledge base",
        "repartir" => "Distributed computing",
        "pepita" => "io_uring kernel interfaces",
        "whisper-apr" => "Speech-to-text inference",
        "ruchy" => "Rust-Python bridge",
        "decy" => "Decision engine",
        "depyler" => "Python→Rust transpiler",
        "bashrs" => "Bash→Rust transpiler",
        "sovereign-ai-stack-book" => "Documentation",
        _ => "Unknown component",
    }
}

/// Build the default PAIML stack tree (without version info)
pub fn build_tree() -> StackTree {
    let mut tree = StackTree::new("PAIML Stack");

    for (layer_name, components) in LAYER_DEFINITIONS {
        let mut layer = StackLayer::new(*layer_name);
        for comp_name in *components {
            let component = Component::new(*comp_name, get_component_description(comp_name));
            layer = layer.add_component(component);
        }
        tree = tree.add_layer(layer);
    }

    tree
}

// ============================================================================
// Tests - Extreme TDD
// ============================================================================

#[cfg(test)]
#[allow(non_snake_case)]
mod tests {
    use super::*;

    // ========================================================================
    // TREE-001: HealthStatus Tests
    // ========================================================================

    #[test]
    fn test_TREE_001_health_status_display_synced() {
        assert_eq!(format!("{}", HealthStatus::Synced), "");
    }

    #[test]
    fn test_TREE_001_health_status_display_behind() {
        assert_eq!(format!("{}", HealthStatus::Behind), "");
    }

    #[test]
    fn test_TREE_001_health_status_display_ahead() {
        assert_eq!(format!("{}", HealthStatus::Ahead), "");
    }

    #[test]
    fn test_TREE_001_health_status_display_not_found() {
        assert_eq!(format!("{}", HealthStatus::NotFound), "?");
    }

    #[test]
    fn test_TREE_001_health_status_display_error() {
        assert_eq!(format!("{}", HealthStatus::Error("test".into())), "");
    }

    #[test]
    fn test_TREE_001_health_status_serialize() {
        let json = serde_json::to_string(&HealthStatus::Synced).expect("json serialize failed");
        assert_eq!(json, "\"synced\"");
    }

    #[test]
    fn test_TREE_001_health_status_deserialize() {
        let status: HealthStatus =
            serde_json::from_str("\"behind\"").expect("json deserialize failed");
        assert_eq!(status, HealthStatus::Behind);
    }

    // ========================================================================
    // TREE-002: Component Tests
    // ========================================================================

    #[test]
    fn test_TREE_002_component_new() {
        let comp = Component::new("trueno", "SIMD ops");
        assert_eq!(comp.name, "trueno");
        assert_eq!(comp.description, "SIMD ops");
        assert_eq!(comp.health, HealthStatus::NotFound);
    }

    #[test]
    fn test_TREE_002_component_with_local_version() {
        let comp =
            Component::new("trueno", "SIMD").with_local_version(semver::Version::new(1, 0, 0));
        assert_eq!(comp.version_local, Some(semver::Version::new(1, 0, 0)));
    }

    #[test]
    fn test_TREE_002_component_health_synced() {
        let comp = Component::new("trueno", "SIMD")
            .with_local_version(semver::Version::new(1, 0, 0))
            .with_remote_version(semver::Version::new(1, 0, 0));
        assert_eq!(comp.health, HealthStatus::Synced);
    }

    #[test]
    fn test_TREE_002_component_health_behind() {
        let comp = Component::new("trueno", "SIMD")
            .with_local_version(semver::Version::new(1, 0, 0))
            .with_remote_version(semver::Version::new(1, 1, 0));
        assert_eq!(comp.health, HealthStatus::Behind);
    }

    #[test]
    fn test_TREE_002_component_health_ahead() {
        let comp = Component::new("trueno", "SIMD")
            .with_local_version(semver::Version::new(2, 0, 0))
            .with_remote_version(semver::Version::new(1, 0, 0));
        assert_eq!(comp.health, HealthStatus::Ahead);
    }

    // ========================================================================
    // TREE-003: StackLayer Tests
    // ========================================================================

    #[test]
    fn test_TREE_003_stack_layer_new() {
        let layer = StackLayer::new("core");
        assert_eq!(layer.name, "core");
        assert!(layer.components.is_empty());
    }

    #[test]
    fn test_TREE_003_stack_layer_add_component() {
        let layer =
            StackLayer::new("core").add_component(Component::new("trueno", "SIMD tensor ops"));
        assert_eq!(layer.components.len(), 1);
        assert_eq!(layer.components[0].name, "trueno");
    }

    // ========================================================================
    // TREE-004: StackTree Tests
    // ========================================================================

    #[test]
    fn test_TREE_004_stack_tree_new() {
        let tree = StackTree::new("PAIML Stack");
        assert_eq!(tree.name, "PAIML Stack");
        assert_eq!(tree.total_crates, 0);
        assert!(tree.layers.is_empty());
    }

    #[test]
    fn test_TREE_004_stack_tree_add_layer() {
        let layer =
            StackLayer::new("core").add_component(Component::new("trueno", "SIMD tensor ops"));
        let tree = StackTree::new("PAIML Stack").add_layer(layer);
        assert_eq!(tree.total_crates, 1);
        assert_eq!(tree.layers.len(), 1);
    }

    #[test]
    fn test_TREE_004_stack_tree_synced_count() {
        let layer = StackLayer::new("core").add_component(
            Component::new("trueno", "SIMD")
                .with_local_version(semver::Version::new(1, 0, 0))
                .with_remote_version(semver::Version::new(1, 0, 0)),
        );
        let tree = StackTree::new("Test").add_layer(layer);
        assert_eq!(tree.synced_count(), 1);
    }

    #[test]
    fn test_TREE_004_stack_tree_behind_count() {
        let layer = StackLayer::new("core").add_component(
            Component::new("trueno", "SIMD")
                .with_local_version(semver::Version::new(1, 0, 0))
                .with_remote_version(semver::Version::new(2, 0, 0)),
        );
        let tree = StackTree::new("Test").add_layer(layer);
        assert_eq!(tree.behind_count(), 1);
    }

    // ========================================================================
    // TREE-005: OutputFormat Tests
    // ========================================================================

    #[test]
    fn test_TREE_005_output_format_from_str_ascii() {
        assert_eq!("ascii".parse::<OutputFormat>().expect("parse failed"), OutputFormat::Ascii);
    }

    #[test]
    fn test_TREE_005_output_format_from_str_json() {
        assert_eq!("json".parse::<OutputFormat>().expect("parse failed"), OutputFormat::Json);
    }

    #[test]
    fn test_TREE_005_output_format_from_str_dot() {
        assert_eq!("dot".parse::<OutputFormat>().expect("parse failed"), OutputFormat::Dot);
    }

    #[test]
    fn test_TREE_005_output_format_from_str_case_insensitive() {
        assert_eq!("JSON".parse::<OutputFormat>().expect("parse failed"), OutputFormat::Json);
    }

    #[test]
    fn test_TREE_005_output_format_from_str_invalid() {
        assert!("xml".parse::<OutputFormat>().is_err());
    }

    #[test]
    fn test_TREE_005_output_format_default() {
        assert_eq!(OutputFormat::default(), OutputFormat::Ascii);
    }

    // ========================================================================
    // TREE-006: ASCII Formatter Tests
    // ========================================================================

    #[test]
    fn test_TREE_006_format_ascii_header() {
        let tree = StackTree::new("Test Stack");
        let output = format_ascii(&tree, false);
        assert!(output.starts_with("Test Stack (0 crates)"));
    }

    #[test]
    fn test_TREE_006_format_ascii_with_layer() {
        let layer = StackLayer::new("core").add_component(Component::new("trueno", "SIMD"));
        let tree = StackTree::new("Test").add_layer(layer);
        let output = format_ascii(&tree, false);
        assert!(output.contains("└── core"));
        assert!(output.contains("trueno"));
    }

    #[test]
    fn test_TREE_006_format_ascii_with_health() {
        let layer = StackLayer::new("core").add_component(
            Component::new("trueno", "SIMD")
                .with_local_version(semver::Version::new(1, 0, 0))
                .with_remote_version(semver::Version::new(1, 0, 0)),
        );
        let tree = StackTree::new("Test").add_layer(layer);
        let output = format_ascii(&tree, true);
        assert!(output.contains(""));
        assert!(output.contains("v1.0.0"));
    }

    #[test]
    fn test_TREE_006_format_ascii_version_diff() {
        let layer = StackLayer::new("core").add_component(
            Component::new("trueno", "SIMD")
                .with_local_version(semver::Version::new(1, 0, 0))
                .with_remote_version(semver::Version::new(2, 0, 0)),
        );
        let tree = StackTree::new("Test").add_layer(layer);
        let output = format_ascii(&tree, true);
        assert!(output.contains("v1.0.0 → 2.0.0"));
    }

    // ========================================================================
    // TREE-007: JSON Formatter Tests
    // ========================================================================

    #[test]
    fn test_TREE_007_format_json_valid() {
        let tree = StackTree::new("Test");
        let json = format_json(&tree).expect("unexpected failure");
        assert!(json.contains("\"name\": \"Test\""));
    }

    #[test]
    fn test_TREE_007_format_json_roundtrip() {
        let layer = StackLayer::new("core").add_component(Component::new("trueno", "SIMD"));
        let tree = StackTree::new("Test").add_layer(layer);
        let json = format_json(&tree).expect("unexpected failure");
        let parsed: StackTree = serde_json::from_str(&json).expect("json deserialize failed");
        assert_eq!(parsed.name, "Test");
        assert_eq!(parsed.layers[0].components[0].name, "trueno");
    }

    // ========================================================================
    // TREE-008: DOT Formatter Tests
    // ========================================================================

    #[test]
    fn test_TREE_008_format_dot_header() {
        let tree = StackTree::new("Test");
        let dot = format_dot(&tree);
        assert!(dot.starts_with("digraph paiml_stack {"));
        assert!(dot.contains("rankdir=TB"));
    }

    #[test]
    fn test_TREE_008_format_dot_cluster() {
        let layer = StackLayer::new("core").add_component(Component::new("trueno", "SIMD"));
        let tree = StackTree::new("Test").add_layer(layer);
        let dot = format_dot(&tree);
        assert!(dot.contains("subgraph cluster_core"));
        assert!(dot.contains("label=\"core\""));
    }

    #[test]
    fn test_TREE_008_format_dot_health_colors() {
        let layer = StackLayer::new("core").add_component(
            Component::new("trueno", "SIMD")
                .with_local_version(semver::Version::new(1, 0, 0))
                .with_remote_version(semver::Version::new(1, 0, 0)),
        );
        let tree = StackTree::new("Test").add_layer(layer);
        let dot = format_dot(&tree);
        assert!(dot.contains("color=green"));
    }

    // ========================================================================
    // TREE-009: Builder Tests
    // ========================================================================

    #[test]
    fn test_TREE_009_build_tree_creates_all_layers() {
        let tree = build_tree();
        assert_eq!(tree.layers.len(), 8);
    }

    #[test]
    fn test_TREE_009_build_tree_total_crates() {
        let tree = build_tree();
        assert_eq!(tree.total_crates, 25);
    }

    #[test]
    fn test_TREE_009_build_tree_core_layer() {
        let tree = build_tree();
        let core = &tree.layers[0];
        assert_eq!(core.name, "core");
        assert_eq!(core.components.len(), 6);
        assert_eq!(core.components[0].name, "trueno");
    }

    #[test]
    fn test_TREE_009_get_component_description() {
        assert_eq!(get_component_description("trueno"), "SIMD tensor operations");
        assert_eq!(get_component_description("batuta"), "Orchestrator");
        assert_eq!(get_component_description("unknown"), "Unknown component");
    }

    // ========================================================================
    // TREE-010: Integration Tests
    // ========================================================================

    #[test]
    fn test_TREE_010_full_tree_ascii_output() {
        let tree = build_tree();
        let output = format_ascii(&tree, false);
        assert!(output.contains("PAIML Stack (25 crates)"));
        assert!(output.contains("core"));
        assert!(output.contains("ml"));
        assert!(output.contains("orchestration"));
        assert!(output.contains("trueno"));
        assert!(output.contains("batuta"));
    }

    #[test]
    fn test_TREE_010_full_tree_json_output() {
        let tree = build_tree();
        let json = format_json(&tree).expect("unexpected failure");
        let parsed: serde_json::Value =
            serde_json::from_str(&json).expect("json deserialize failed");
        assert_eq!(parsed["total_crates"], 25);
    }

    #[test]
    fn test_TREE_010_full_tree_dot_output() {
        let tree = build_tree();
        let dot = format_dot(&tree);
        assert!(dot.contains("digraph"));
        assert!(dot.contains("cluster_core"));
        assert!(dot.contains("cluster_ml"));
    }
}