nusy-kanban 0.15.2

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

use crate::item_type::ItemType;
use crate::schema::items_col;
use arrow::array::{Array, RecordBatch, StringArray};

// ─── Public Types ──────────────────────────────────────────────────────────

/// Severity of a validation violation.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Severity {
    /// Hard conformance failure (sh:minCount 1 violated on a required field).
    Error,
    /// Advisory warning — best practice not followed but item is usable.
    Warning,
}

/// A single constraint violation for an item field.
#[derive(Debug, Clone)]
pub struct Violation {
    /// The field name (e.g. "assignee", "body", "priority").
    pub field: String,
    /// Human-readable description (sh:message content).
    pub message: String,
    /// Severity level.
    pub severity: Severity,
}

/// Aggregated report for one item.
#[derive(Debug)]
pub struct ValidationReport {
    /// Item ID (e.g. "EX-3212").
    pub item_id: String,
    /// Item type string (e.g. "expedition").
    pub item_type: String,
    /// All constraint violations found.
    pub violations: Vec<Violation>,
}

impl ValidationReport {
    /// Returns `true` when there are no Error-severity violations.
    pub fn is_conformant(&self) -> bool {
        !self
            .violations
            .iter()
            .any(|v| v.severity == Severity::Error)
    }
}

// ─── Core Validation ───────────────────────────────────────────────────────

/// Validate a single item (one-row RecordBatch) against its type's shape rules.
///
/// Implements structural SHACL (sh:minCount checks only) — no SPARQL engine required.
pub fn validate_item(batch: &RecordBatch) -> ValidationReport {
    let item_id = get_string(batch, items_col::ID).unwrap_or_default();
    let item_type_str = get_string(batch, items_col::ITEM_TYPE).unwrap_or_default();
    let mut violations = Vec::new();

    let item_type = ItemType::from_str_loose(&item_type_str);

    // ── Body (required for most types) ────────────────────────────────────
    let body = get_nullable_string(batch, items_col::BODY);
    let body_empty = body.as_deref().map(|s| s.trim().is_empty()).unwrap_or(true);

    let body_severity = match item_type {
        // Hazard and Signal are ephemeral — body is advisory
        Some(ItemType::Hazard) | Some(ItemType::Signal) => Some(Severity::Warning),
        // All other types: body is required
        Some(_) => Some(Severity::Error),
        // Unknown type: treat as error
        None => Some(Severity::Error),
    };

    if body_empty && let Some(sev) = body_severity {
        violations.push(Violation {
            field: "body".to_string(),
            message: "body is empty — use: nk update <ID> --body-file /tmp/body.md".to_string(),
            severity: sev,
        });
    }

    // ── Priority (required for expedition, voyage, chore, feature) ─────────
    let priority = get_nullable_string(batch, items_col::PRIORITY);
    let priority_required = matches!(
        item_type,
        Some(ItemType::Expedition)
            | Some(ItemType::Voyage)
            | Some(ItemType::Chore)
            | Some(ItemType::Feature)
    );

    if priority_required && priority.is_none() {
        violations.push(Violation {
            field: "priority".to_string(),
            message: "priority required: low|medium|high|critical".to_string(),
            severity: Severity::Error,
        });
    }

    // ── Assignee (advisory for expedition + voyage) ────────────────────────
    let assignee = get_nullable_string(batch, items_col::ASSIGNEE);
    let assignee_required = matches!(
        item_type,
        Some(ItemType::Expedition) | Some(ItemType::Voyage)
    );

    if assignee_required && assignee.is_none() {
        violations.push(Violation {
            field: "assignee".to_string(),
            message: "assignee required: M5|DGX|Mini|unassigned".to_string(),
            severity: Severity::Warning,
        });
    }

    // ── Warn when assignee is "unassigned" for in-progress items ──────────
    let status = get_string(batch, items_col::STATUS).unwrap_or_default();
    if status == "in_progress"
        && let Some(ref a) = assignee
        && a == "unassigned"
    {
        violations.push(Violation {
            field: "assignee".to_string(),
            message: "item is in_progress but assignee is 'unassigned'".to_string(),
            severity: Severity::Warning,
        });
    }

    ValidationReport {
        item_id,
        item_type: item_type_str,
        violations,
    }
}

// ─── Fix Suggestions ───────────────────────────────────────────────────────

/// Generate suggested fix commands for all violations in a report.
///
/// Returns one `nk update ...` command per violation, formatted so the user
/// can copy-paste to fix the issue.
pub fn suggest_fixes(report: &ValidationReport) -> Vec<String> {
    report
        .violations
        .iter()
        .map(|v| match v.field.as_str() {
            "assignee" => format!("nk update {} --assign M5", report.item_id),
            "body" => format!("nk update {} --body-file /tmp/body.md", report.item_id),
            "priority" => format!("nk update {} --priority medium", report.item_id),
            _ => format!("nk update {} # fix {}", report.item_id, v.field),
        })
        .collect()
}

// ─── Board-Wide Validation ─────────────────────────────────────────────────

/// Validate all items in a slice of RecordBatches (one batch = one item row).
///
/// Returns one `ValidationReport` per item.
pub fn validate_all(batches: &[RecordBatch]) -> Vec<ValidationReport> {
    batches.iter().map(validate_item).collect()
}

// ─── Formatting ────────────────────────────────────────────────────────────

/// Format a single `ValidationReport` for terminal output.
pub fn format_report(report: &ValidationReport, show_fixes: bool) -> String {
    let mut lines = Vec::new();

    if report.violations.is_empty() {
        lines.push(format!("{} {} — OK", report.item_id, report.item_type));
    } else {
        let error_count = report
            .violations
            .iter()
            .filter(|v| v.severity == Severity::Error)
            .count();
        let warn_count = report
            .violations
            .iter()
            .filter(|v| v.severity == Severity::Warning)
            .count();

        let summary = match (error_count, warn_count) {
            (0, w) => format!("WARNINGS ({})", w),
            (e, 0) => format!("VIOLATIONS ({})", e),
            (e, w) => format!("VIOLATIONS ({} errors, {} warnings)", e, w),
        };

        lines.push(format!(
            "{} {}{}",
            report.item_id, report.item_type, summary
        ));

        for v in &report.violations {
            let label = match v.severity {
                Severity::Error => "  ERROR  ",
                Severity::Warning => "  WARNING",
            };
            lines.push(format!("{} {}: {}", label, v.field, v.message));
        }

        if show_fixes {
            let fixes = suggest_fixes(report);
            if !fixes.is_empty() {
                lines.push(String::new());
                lines.push("Suggested fixes:".to_string());
                for fix in &fixes {
                    lines.push(format!("  {fix}"));
                }
            }
        }
    }

    lines.join("\n")
}

/// Format a summary table for board-wide validation.
///
/// Shows conformant count, violation count, and lists violating items.
pub fn format_board_summary(reports: &[ValidationReport]) -> String {
    let conformant: Vec<&ValidationReport> = reports.iter().filter(|r| r.is_conformant()).collect();
    let violating: Vec<&ValidationReport> = reports.iter().filter(|r| !r.is_conformant()).collect();

    let mut lines = Vec::new();
    lines.push(format!(
        "Validation summary: {} conformant, {} with violations",
        conformant.len(),
        violating.len()
    ));

    if violating.is_empty() {
        lines.push("All items conform to their SHACL shapes.".to_string());
    } else {
        lines.push(String::new());
        lines.push("Items with violations:".to_string());
        for r in &violating {
            let error_count = r
                .violations
                .iter()
                .filter(|v| v.severity == Severity::Error)
                .count();
            let warn_count = r
                .violations
                .iter()
                .filter(|v| v.severity == Severity::Warning)
                .count();
            lines.push(format!(
                "  {} ({}) — {} errors, {} warnings",
                r.item_id, r.item_type, error_count, warn_count
            ));
        }
    }

    lines.join("\n")
}

// ─── Arrow Helpers ─────────────────────────────────────────────────────────

/// Extract a non-nullable string value from a column in a single-row batch.
fn get_string(batch: &RecordBatch, col_idx: usize) -> Option<String> {
    batch
        .column(col_idx)
        .as_any()
        .downcast_ref::<StringArray>()
        .and_then(|arr| {
            if arr.is_empty() {
                None
            } else {
                Some(arr.value(0).to_string())
            }
        })
}

/// Extract a nullable string value from a column in a single-row batch.
fn get_nullable_string(batch: &RecordBatch, col_idx: usize) -> Option<String> {
    batch
        .column(col_idx)
        .as_any()
        .downcast_ref::<StringArray>()
        .and_then(|arr| {
            if arr.is_empty() || arr.is_null(0) {
                None
            } else {
                let s = arr.value(0);
                if s.is_empty() {
                    None
                } else {
                    Some(s.to_string())
                }
            }
        })
}

// ─── Tests ─────────────────────────────────────────────────────────────────

#[cfg(test)]
mod tests {
    use super::*;
    use crate::crud::{CreateItemInput, KanbanStore};

    // ── Helper ──────────────────────────────────────────────────────────────

    /// Create a minimal item in a store and return the single-row RecordBatch.
    fn make_item(
        item_type: ItemType,
        priority: Option<&str>,
        assignee: Option<&str>,
        body: Option<&str>,
        status: &str,
    ) -> RecordBatch {
        let mut store = KanbanStore::new();
        let id = store
            .create_item(&CreateItemInput {
                title: "Test Item".to_string(),
                item_type,
                priority: priority.map(|s| s.to_string()),
                assignee: assignee.map(|s| s.to_string()),
                tags: vec![],
                related: vec![],
                depends_on: vec![],
                body: body.map(|s| s.to_string()),
            })
            .expect("create_item");

        if status != "backlog" {
            store
                .update_status(&id, status, None, true, None)
                .expect("update_status");
        }

        store.get_item(&id).expect("get_item")
    }

    // ── Body validation ─────────────────────────────────────────────────────

    #[test]
    fn test_expedition_without_body_produces_error() {
        let batch = make_item(
            ItemType::Expedition,
            Some("high"),
            Some("M5"),
            None,
            "backlog",
        );
        let report = validate_item(&batch);
        assert!(!report.is_conformant());
        assert!(report.violations.iter().any(|v| v.field == "body"));
        assert!(
            report
                .violations
                .iter()
                .any(|v| v.field == "body" && v.severity == Severity::Error)
        );
    }

    #[test]
    fn test_expedition_with_body_no_body_violation() {
        let batch = make_item(
            ItemType::Expedition,
            Some("high"),
            Some("M5"),
            Some("## Phase 1\nDo the thing."),
            "backlog",
        );
        let report = validate_item(&batch);
        assert!(
            !report.violations.iter().any(|v| v.field == "body"),
            "should have no body violation when body is set"
        );
    }

    #[test]
    fn test_chore_without_body_produces_error() {
        let batch = make_item(ItemType::Chore, Some("low"), None, None, "backlog");
        let report = validate_item(&batch);
        assert!(
            report
                .violations
                .iter()
                .any(|v| v.field == "body" && v.severity == Severity::Error)
        );
    }

    #[test]
    fn test_hazard_without_body_produces_warning_not_error() {
        let batch = make_item(ItemType::Hazard, None, None, None, "backlog");
        let report = validate_item(&batch);
        let body_violations: Vec<_> = report
            .violations
            .iter()
            .filter(|v| v.field == "body")
            .collect();
        assert!(
            !body_violations.is_empty(),
            "hazard without body should have a body violation"
        );
        // All body violations for hazard must be Warning, not Error
        assert!(
            body_violations
                .iter()
                .all(|v| v.severity == Severity::Warning)
        );
    }

    #[test]
    fn test_signal_without_body_produces_warning_not_error() {
        let batch = make_item(ItemType::Signal, None, None, None, "backlog");
        let report = validate_item(&batch);
        let body_violations: Vec<_> = report
            .violations
            .iter()
            .filter(|v| v.field == "body")
            .collect();
        assert!(
            body_violations
                .iter()
                .all(|v| v.severity == Severity::Warning)
        );
    }

    // ── Priority validation ─────────────────────────────────────────────────

    #[test]
    fn test_expedition_without_priority_produces_error() {
        let batch = make_item(
            ItemType::Expedition,
            None,
            Some("M5"),
            Some("body"),
            "backlog",
        );
        let report = validate_item(&batch);
        assert!(
            report
                .violations
                .iter()
                .any(|v| v.field == "priority" && v.severity == Severity::Error)
        );
    }

    #[test]
    fn test_voyage_without_priority_produces_error() {
        let batch = make_item(ItemType::Voyage, None, None, Some("body"), "backlog");
        let report = validate_item(&batch);
        assert!(
            report
                .violations
                .iter()
                .any(|v| v.field == "priority" && v.severity == Severity::Error)
        );
    }

    #[test]
    fn test_hypothesis_does_not_require_priority() {
        // Hypothesis is a research type — no priority requirement
        let batch = make_item(ItemType::Hypothesis, None, None, Some("body"), "backlog");
        let report = validate_item(&batch);
        assert!(
            !report.violations.iter().any(|v| v.field == "priority"),
            "hypothesis should not require priority"
        );
    }

    // ── Assignee validation ─────────────────────────────────────────────────

    #[test]
    fn test_expedition_without_assignee_produces_warning() {
        let batch = make_item(
            ItemType::Expedition,
            Some("high"),
            None,
            Some("body"),
            "backlog",
        );
        let report = validate_item(&batch);
        assert!(
            report
                .violations
                .iter()
                .any(|v| v.field == "assignee" && v.severity == Severity::Warning)
        );
    }

    #[test]
    fn test_chore_without_assignee_no_violation() {
        // Chore doesn't require assignee
        let batch = make_item(ItemType::Chore, Some("low"), None, Some("body"), "backlog");
        let report = validate_item(&batch);
        assert!(
            !report.violations.iter().any(|v| v.field == "assignee"),
            "chore should not require assignee"
        );
    }

    #[test]
    fn test_in_progress_with_unassigned_produces_warning() {
        let batch = make_item(
            ItemType::Expedition,
            Some("high"),
            Some("unassigned"),
            Some("body"),
            "in_progress",
        );
        let report = validate_item(&batch);
        assert!(
            report
                .violations
                .iter()
                .any(|v| v.field == "assignee" && v.severity == Severity::Warning),
            "in_progress item with 'unassigned' should produce assignee warning"
        );
    }

    // ── Conformance ─────────────────────────────────────────────────────────

    #[test]
    fn test_fully_conformant_expedition() {
        let batch = make_item(
            ItemType::Expedition,
            Some("high"),
            Some("M5"),
            Some("## Phase 1\nDo the thing."),
            "backlog",
        );
        let report = validate_item(&batch);
        // No errors (warnings are ok for conformance)
        assert!(
            report.is_conformant(),
            "fully-set expedition should be conformant (no errors)"
        );
        assert!(
            !report
                .violations
                .iter()
                .any(|v| v.severity == Severity::Error)
        );
    }

    #[test]
    fn test_is_conformant_false_when_errors_exist() {
        let batch = make_item(ItemType::Expedition, None, None, None, "backlog");
        let report = validate_item(&batch);
        assert!(!report.is_conformant());
    }

    // ── suggest_fixes ───────────────────────────────────────────────────────

    #[test]
    fn test_suggest_fixes_returns_nk_update_commands() {
        let batch = make_item(ItemType::Expedition, None, None, None, "backlog");
        let report = validate_item(&batch);
        let fixes = suggest_fixes(&report);
        assert!(!fixes.is_empty());
        assert!(
            fixes.iter().all(|f| f.starts_with("nk update ")),
            "all fix suggestions should start with 'nk update'"
        );
    }

    #[test]
    fn test_suggest_fixes_assignee_command() {
        let batch = make_item(
            ItemType::Expedition,
            Some("high"),
            None,
            Some("body"),
            "backlog",
        );
        let report = validate_item(&batch);
        let fixes = suggest_fixes(&report);
        assert!(
            fixes.iter().any(|f| f.contains("--assign")),
            "should suggest --assign fix"
        );
    }

    #[test]
    fn test_suggest_fixes_body_command() {
        let batch = make_item(
            ItemType::Expedition,
            Some("high"),
            Some("M5"),
            None,
            "backlog",
        );
        let report = validate_item(&batch);
        let fixes = suggest_fixes(&report);
        assert!(
            fixes.iter().any(|f| f.contains("--body-file")),
            "should suggest --body-file fix"
        );
    }

    #[test]
    fn test_suggest_fixes_priority_command() {
        let batch = make_item(
            ItemType::Expedition,
            None,
            Some("M5"),
            Some("body"),
            "backlog",
        );
        let report = validate_item(&batch);
        let fixes = suggest_fixes(&report);
        assert!(
            fixes.iter().any(|f| f.contains("--priority")),
            "should suggest --priority fix"
        );
    }

    // ── Board-wide validation ───────────────────────────────────────────────

    #[test]
    fn test_validate_all_returns_one_report_per_item() {
        let mut store = KanbanStore::new();
        store
            .create_item(&CreateItemInput {
                title: "A".to_string(),
                item_type: ItemType::Expedition,
                priority: None,
                assignee: None,
                tags: vec![],
                related: vec![],
                depends_on: vec![],
                body: None,
            })
            .unwrap();
        store
            .create_item(&CreateItemInput {
                title: "B".to_string(),
                item_type: ItemType::Chore,
                priority: Some("low".to_string()),
                assignee: None,
                tags: vec![],
                related: vec![],
                depends_on: vec![],
                body: Some("body".to_string()),
            })
            .unwrap();

        let batches = store.query_items(None, None, None, None);
        let reports = validate_all(&batches);
        assert_eq!(reports.len(), 2);
    }

    #[test]
    fn test_validate_all_conformant_item_passes() {
        let mut store = KanbanStore::new();
        store
            .create_item(&CreateItemInput {
                title: "Good".to_string(),
                item_type: ItemType::Expedition,
                priority: Some("high".to_string()),
                assignee: Some("M5".to_string()),
                tags: vec![],
                related: vec![],
                depends_on: vec![],
                body: Some("## Phase 1\nDo the thing.".to_string()),
            })
            .unwrap();

        let batches = store.query_items(None, None, None, None);
        let reports = validate_all(&batches);
        assert_eq!(reports.len(), 1);
        assert!(reports[0].is_conformant());
    }

    // ── format_report ───────────────────────────────────────────────────────

    #[test]
    fn test_format_report_conformant_shows_ok() {
        let batch = make_item(
            ItemType::Expedition,
            Some("high"),
            Some("M5"),
            Some("body"),
            "backlog",
        );
        let report = validate_item(&batch);
        let out = format_report(&report, false);
        assert!(out.contains("OK"), "conformant item should show OK");
    }

    #[test]
    fn test_format_report_violations_shows_error_label() {
        let batch = make_item(ItemType::Expedition, None, None, None, "backlog");
        let report = validate_item(&batch);
        let out = format_report(&report, false);
        assert!(out.contains("ERROR"), "report should show ERROR label");
        assert!(
            out.contains("VIOLATIONS"),
            "report header should say VIOLATIONS"
        );
    }

    #[test]
    fn test_format_report_with_fixes_shows_suggestions() {
        let batch = make_item(ItemType::Expedition, None, None, None, "backlog");
        let report = validate_item(&batch);
        let out = format_report(&report, true);
        assert!(out.contains("Suggested fixes:"));
        assert!(out.contains("nk update "));
    }

    // ── format_board_summary ────────────────────────────────────────────────

    #[test]
    fn test_format_board_summary_all_ok() {
        let mut store = KanbanStore::new();
        store
            .create_item(&CreateItemInput {
                title: "Good".to_string(),
                item_type: ItemType::Expedition,
                priority: Some("high".to_string()),
                assignee: Some("M5".to_string()),
                tags: vec![],
                related: vec![],
                depends_on: vec![],
                body: Some("body".to_string()),
            })
            .unwrap();

        let batches = store.query_items(None, None, None, None);
        let reports = validate_all(&batches);
        let summary = format_board_summary(&reports);
        assert!(summary.contains("1 conformant"));
        assert!(summary.contains("0 with violations"));
        assert!(summary.contains("All items conform"));
    }

    #[test]
    fn test_format_board_summary_with_violations() {
        let mut store = KanbanStore::new();
        // One bad item (no body, no priority)
        store
            .create_item(&CreateItemInput {
                title: "Bad".to_string(),
                item_type: ItemType::Expedition,
                priority: None,
                assignee: None,
                tags: vec![],
                related: vec![],
                depends_on: vec![],
                body: None,
            })
            .unwrap();
        // One good item
        store
            .create_item(&CreateItemInput {
                title: "Good".to_string(),
                item_type: ItemType::Chore,
                priority: Some("low".to_string()),
                assignee: None,
                tags: vec![],
                related: vec![],
                depends_on: vec![],
                body: Some("body".to_string()),
            })
            .unwrap();

        let batches = store.query_items(None, None, None, None);
        let reports = validate_all(&batches);
        let summary = format_board_summary(&reports);
        assert!(summary.contains("1 conformant"));
        assert!(summary.contains("1 with violations"));
    }
}