tix-tracker 0.2.0

A terminal issue tracker: markdown + YAML frontmatter issues with a kanban TUI and CLI
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
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
use ratatui::Frame;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Borders, List, ListItem, ListState, Paragraph};

use crate::config::BoardConfiguration;
use crate::model::Priority;
use crate::search::{Corpus, StructuredFilter};
use crate::storage::Store;

use super::widgets;

#[derive(Debug, Clone)]
pub struct Card {
    pub number: u32,
    pub title: String,
    pub priority: Priority,
    pub labels: Vec<String>,
    pub assignee: Option<String>,
    pub filename: String,
    pub commit: Option<String>,
}

#[derive(Debug, Clone)]
pub struct BoardColumn {
    pub name: String,
    pub cards: Vec<Card>,
}

#[derive(Debug, Clone)]
pub struct BoardState {
    /// Visible columns only — configured columns not listed in the active
    /// board's `hidden_columns`, in declaration order (FR-002/FR-003). Hidden
    /// columns live in [`BoardState::hidden`].
    pub columns: Vec<BoardColumn>,
    /// Columns hidden from the active board configuration. Their cards stay
    /// in board state (keyed by column name) and remain reachable via
    /// filters/search (DM-01M2MHJB884WCTVCDHPD2T3GE7); they never render.
    pub hidden: Vec<BoardColumn>,
    pub mismatch: BoardColumn,
    /// Whether the computed "Mismatched" pseudo-column is part of the
    /// navigation/render surface (C-002 / FR-003). Cards in unknown statuses
    /// are always collected into [`BoardState::mismatch`]; the column is only
    /// shown when the effective configuration sets `show_mismatch`.
    pub show_mismatch: bool,
    pub active_col: usize,
    pub selected: usize,
    pub filter: Option<String>,
}

impl BoardState {
    pub fn build(store: &Store, board_config: &BoardConfiguration) -> Self {
        let issues = store.list().unwrap_or_default();
        let show_mismatch = board_config.show_mismatch;
        let hidden_names: Vec<&str> = board_config
            .hidden_columns
            .iter()
            .map(String::as_str)
            .collect();
        let mut column_map: Vec<Vec<Card>> =
            board_config.columns.iter().map(|_| Vec::new()).collect();
        let mut mismatch_cards = Vec::new();

        for issue in issues {
            let card = Card {
                number: issue.number,
                title: issue.title.clone(),
                priority: issue.priority.clone(),
                labels: issue.labels.clone(),
                assignee: issue.assignee.clone(),
                filename: issue.filename.clone(),
                commit: issue.commit.clone(),
            };
            if let Some(idx) = board_config
                .columns
                .iter()
                .position(|c| c == issue.status.display())
            {
                column_map[idx].push(card);
            } else {
                mismatch_cards.push(card);
            }
        }

        let mut columns: Vec<BoardColumn> = Vec::new();
        let mut hidden: Vec<BoardColumn> = Vec::new();
        for (cards, name) in column_map.into_iter().zip(board_config.columns.iter()) {
            let col = BoardColumn {
                name: name.clone(),
                cards,
            };
            if hidden_names.contains(&name.as_str()) {
                hidden.push(col);
            } else {
                columns.push(col);
            }
        }

        let mismatch = BoardColumn {
            name: "Mismatched".to_string(),
            cards: mismatch_cards,
        };

        BoardState {
            columns,
            hidden,
            mismatch,
            show_mismatch,
            active_col: 0,
            selected: 0,
            filter: None,
        }
    }

    /// Build a board from the search corpus, keeping only cards whose full
    /// serialized text matches **both** the fuzzy `query` layer and the
    /// structured `filter` layer (FR-012/FR-013). Both predicates run in a
    /// single pass over the corpus via [`crate::search::matches`] (NFR-001).
    ///
    /// When a filter is active (non-empty query or structured criteria set),
    /// hidden columns' matching cards are **revealed** in the rendered surface
    /// (DM-01M2MHJB884WCTVCDHPD2T3GE7: hidden-column cards reachable via
    /// filters/search). When no filter is active, matching cards from hidden
    /// columns are stashed in [`BoardState::hidden`] (no visual presence).
    pub fn build_filtered(
        board_config: &BoardConfiguration,
        corpus: &Corpus,
        query: &str,
        filter: &StructuredFilter,
    ) -> Self {
        let show_mismatch = board_config.show_mismatch;
        let filtering = !query.is_empty() || filter.has_active_criteria();
        let hidden_names: Vec<&str> = board_config
            .hidden_columns
            .iter()
            .map(String::as_str)
            .collect();
        let mut column_map: Vec<Vec<Card>> =
            board_config.columns.iter().map(|_| Vec::new()).collect();
        let mut mismatch_cards = Vec::new();

        for (issue, text) in corpus.issues.iter().zip(corpus.texts.iter()) {
            if !crate::search::matches(query, filter, text) {
                continue;
            }
            let card = Card {
                number: issue.number,
                title: issue.title.clone(),
                priority: issue.priority.clone(),
                labels: issue.labels.clone(),
                assignee: issue.assignee.clone(),
                filename: issue.filename.clone(),
                commit: issue.commit.clone(),
            };
            if let Some(idx) = board_config
                .columns
                .iter()
                .position(|c| c == issue.status.display())
            {
                column_map[idx].push(card);
            } else {
                mismatch_cards.push(card);
            }
        }

        let mut columns: Vec<BoardColumn> = Vec::new();
        let mut hidden: Vec<BoardColumn> = Vec::new();
        for (cards, name) in column_map.into_iter().zip(board_config.columns.iter()) {
            let col = BoardColumn {
                name: name.clone(),
                cards,
            };
            if hidden_names.contains(&name.as_str()) {
                if filtering {
                    // Reveal hidden column when a filter is active so
                    // matching cards appear in the rendered surface
                    // (DM-01M2MHJB884WCTVCDHPD2T3GE7).
                    columns.push(col);
                } else {
                    hidden.push(col);
                }
            } else {
                columns.push(col);
            }
        }

        BoardState {
            columns,
            hidden,
            mismatch: BoardColumn {
                name: "Mismatched".to_string(),
                cards: mismatch_cards,
            },
            show_mismatch,
            active_col: 0,
            selected: 0,
            filter: Some(query.to_string()),
        }
    }

    /// True when no card anywhere is visible (used for zero-match feedback).
    pub fn is_empty(&self) -> bool {
        self.columns.iter().all(|c| c.cards.is_empty())
            && (!self.show_mismatch || self.mismatch.cards.is_empty())
    }

    pub fn total_cols(&self) -> usize {
        if self.show_mismatch {
            self.columns.len() + 1
        } else {
            self.columns.len()
        }
    }

    /// Columns a card can be moved into: the configured columns plus (when
    /// shown) the "Mismatched" sentinel, which is never a move target. The
    /// `</>` move keys navigate *among movable columns* only.
    pub fn real_cols(&self) -> usize {
        self.columns.len()
    }

    pub fn column_name(&self, idx: usize) -> &str {
        if idx < self.columns.len() {
            &self.columns[idx].name
        } else if idx == self.columns.len() && self.show_mismatch {
            &self.mismatch.name
        } else {
            "Unknown"
        }
    }

    /// The name under the active cursor, resolving **hidden** columns too
    /// (visible region first, then hidden, then Unknown). Lets `toggle` keep a
    /// logical cursor on a just-hidden column so a second press re-shows it
    /// (T017: "a second press on the same column re-shows it").
    pub fn active_column_name(&self) -> &str {
        let visible = self.columns.len();
        if self.active_col < visible {
            &self.columns[self.active_col].name
        } else {
            let hidden_idx = self.active_col - visible;
            if hidden_idx < self.hidden.len() {
                &self.hidden[hidden_idx].name
            } else {
                "Unknown"
            }
        }
    }

    pub fn column_cards(&self, idx: usize) -> &[Card] {
        if idx < self.columns.len() {
            &self.columns[idx].cards
        } else if idx == self.columns.len() && self.show_mismatch {
            &self.mismatch.cards
        } else {
            &[]
        }
    }

    pub fn get_selected_card(&self) -> Option<&Card> {
        self.column_cards(self.active_col).get(self.selected)
    }

    pub fn move_left(&mut self) {
        let total = self.real_cols();
        self.active_col = if total == 0 {
            0
        } else if self.active_col >= total {
            total - 1
        } else {
            (self.active_col + total - 1) % total
        };
        self.clamp_selection();
    }

    pub fn move_right(&mut self) {
        let total = self.real_cols();
        self.active_col = if total == 0 || self.active_col >= total {
            0
        } else {
            (self.active_col + 1) % total
        };
        self.clamp_selection();
    }

    pub fn move_up(&mut self) {
        if self.selected > 0 {
            self.selected -= 1;
        }
    }

    pub fn move_down(&mut self) {
        let cards = self.column_cards(self.active_col);
        if self.selected + 1 < cards.len() {
            self.selected += 1;
        }
    }

    pub fn clamp_selection(&mut self) {
        let cards = self.column_cards(self.active_col);
        if cards.is_empty() {
            self.selected = 0;
        } else if self.selected >= cards.len() {
            self.selected = cards.len() - 1;
        }
    }

    pub fn select_column(&mut self, col: usize) {
        let total = self.real_cols();
        if total > 0 {
            self.active_col = col % total;
        }
        self.clamp_selection();
    }
}

pub fn render(board: &BoardState, f: &mut Frame, area: Rect, status_msg: &Option<String>) {
    if area.height < 2 || area.width < 4 {
        return;
    }

    let status_height: u16 = if status_msg.is_some() { 1 } else { 0 };
    let board_height = area.height.saturating_sub(status_height);
    let board_area = Rect {
        height: board_height,
        ..area
    };
    let status_area = Rect {
        y: area.y + board_height,
        height: status_height,
        ..area
    };

    let total = board.total_cols();
    if total == 0 {
        return;
    }

    let chunks = Layout::default()
        .direction(Direction::Horizontal)
        .constraints(vec![Constraint::Ratio(1, total as u32); total])
        .split(board_area);

    for i in 0..total {
        let col = if i < board.columns.len() {
            &board.columns[i]
        } else {
            &board.mismatch
        };

        let is_active = i == board.active_col;
        let is_mismatch_col = i == board.columns.len();
        let is_mismatch_highlight = is_mismatch_col && !col.cards.is_empty();

        let items: Vec<ListItem> = col
            .cards
            .iter()
            .enumerate()
            .map(|(j, card)| {
                let line = widgets::card_line(card, chunks[i].width as usize);
                let style = if is_active && j == board.selected {
                    Style::default()
                        .bg(Color::DarkGray)
                        .add_modifier(Modifier::BOLD)
                } else if is_mismatch_highlight {
                    Style::default().fg(Color::Red)
                } else {
                    Style::default()
                };
                ListItem::new(line).style(style)
            })
            .collect();

        let title = format!("{} ({})", col.name, col.cards.len());
        let border_style = if is_active {
            Style::default().fg(Color::Cyan)
        } else if is_mismatch_highlight {
            Style::default().fg(Color::Red)
        } else {
            Style::default()
        };

        let block = Block::default()
            .borders(Borders::ALL)
            .title(title)
            .border_style(border_style);

        let list = List::new(items).block(block);

        if is_active {
            let mut state = ListState::default();
            if !col.cards.is_empty() {
                state.select(Some(board.selected));
            }
            f.render_stateful_widget(list, chunks[i], &mut state);
        } else {
            f.render_widget(list, chunks[i]);
        }
    }

    if let Some(msg) = status_msg {
        let para = Paragraph::new(Line::from(Span::raw(msg.clone())))
            .style(Style::default().fg(Color::Yellow));
        f.render_widget(para, status_area);
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::config::Config;

    #[test]
    fn total_cols_includes_mismatch() {
        let board = BoardState {
            columns: vec![
                BoardColumn {
                    name: "a".into(),
                    cards: vec![],
                },
                BoardColumn {
                    name: "b".into(),
                    cards: vec![],
                },
            ],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 0,
            filter: None,
            hidden: vec![],
            show_mismatch: true,
        };
        assert_eq!(board.total_cols(), 3);
    }

    #[test]
    fn column_name_mismatch_index() {
        let board = BoardState {
            columns: vec![BoardColumn {
                name: "todo".into(),
                cards: vec![],
            }],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 0,
            filter: None,
            hidden: vec![],
            show_mismatch: true,
        };
        assert_eq!(board.column_name(0), "todo");
        assert_eq!(board.column_name(1), "Mismatched");
    }

    #[test]
    fn move_left_wraps_around() {
        let mut board = BoardState {
            columns: vec![
                BoardColumn {
                    name: "a".into(),
                    cards: vec![],
                },
                BoardColumn {
                    name: "b".into(),
                    cards: vec![],
                },
            ],
            hidden: vec![],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 0,
            filter: None,
            show_mismatch: true,
        };
        board.move_left();
        assert_eq!(board.active_col, 1);
    }

    #[test]
    fn move_right_wraps_around() {
        let mut board = BoardState {
            columns: vec![
                BoardColumn {
                    name: "a".into(),
                    cards: vec![],
                },
                BoardColumn {
                    name: "b".into(),
                    cards: vec![],
                },
            ],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 2,
            selected: 0,
            filter: None,
            hidden: vec![],
            show_mismatch: true,
        };
        board.move_right();
        assert_eq!(board.active_col, 0);
    }

    #[test]
    fn clamp_selection_empty_column() {
        let mut board = BoardState {
            columns: vec![BoardColumn {
                name: "a".into(),
                cards: vec![],
            }],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 5,
            filter: None,
            hidden: vec![],
            show_mismatch: true,
        };
        board.clamp_selection();
        assert_eq!(board.selected, 0);
    }

    #[test]
    fn clamp_selection_single_card() {
        let mut board = BoardState {
            columns: vec![BoardColumn {
                name: "a".into(),
                cards: vec![Card {
                    number: 1,
                    title: "X".into(),
                    priority: crate::model::Priority::Medium,
                    labels: vec![],
                    assignee: None,
                    filename: "x.md".into(),
                    commit: None,
                }],
            }],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 5,
            filter: None,
            hidden: vec![],
            show_mismatch: true,
        };
        board.clamp_selection();
        assert_eq!(board.selected, 0);
    }

    #[test]
    fn move_up_clamps_at_top() {
        let mut board = BoardState {
            columns: vec![BoardColumn {
                name: "a".into(),
                cards: vec![Card {
                    number: 1,
                    title: "X".into(),
                    priority: crate::model::Priority::Medium,
                    labels: vec![],
                    assignee: None,
                    filename: "x.md".into(),
                    commit: None,
                }],
            }],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 0,
            filter: None,
            hidden: vec![],
            show_mismatch: true,
        };
        board.move_up();
        assert_eq!(board.selected, 0);
    }

    #[test]
    fn move_down_clamps_at_bottom() {
        let mut board = BoardState {
            columns: vec![BoardColumn {
                name: "a".into(),
                cards: vec![Card {
                    number: 1,
                    title: "X".into(),
                    priority: crate::model::Priority::Medium,
                    labels: vec![],
                    assignee: None,
                    filename: "x.md".into(),
                    commit: None,
                }],
            }],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 0,
            filter: None,
            hidden: vec![],
            show_mismatch: true,
        };
        board.move_down();
        assert_eq!(board.selected, 0);
    }

    #[test]
    fn render_smoke_does_not_panic_on_tiny_frame() {
        use ratatui::Terminal;
        use ratatui::backend::TestBackend;

        let backend = TestBackend::new(5, 3);
        let mut terminal = Terminal::new(backend).unwrap();
        let board = BoardState {
            columns: vec![],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 0,
            filter: None,
            hidden: vec![],
            show_mismatch: true,
        };
        terminal
            .draw(|f| render(&board, f, f.area(), &None))
            .unwrap();
    }

    #[test]
    fn render_smoke_full_board() {
        use ratatui::Terminal;
        use ratatui::backend::TestBackend;

        let backend = TestBackend::new(80, 24);
        let mut terminal = Terminal::new(backend).unwrap();
        let board = BoardState {
            columns: vec![
                BoardColumn {
                    name: "todo".into(),
                    cards: vec![],
                },
                BoardColumn {
                    name: "done".into(),
                    cards: vec![],
                },
            ],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 0,
            filter: None,
            hidden: vec![],
            show_mismatch: true,
        };
        terminal
            .draw(|f| render(&board, f, f.area(), &Some("test msg".into())))
            .unwrap();
    }

    #[test]
    fn build_filtered_keeps_only_fuzzy_matches() {
        use crate::model::Issue;
        use crate::search::Corpus;

        let to_issue = |number: u32, title: &str| Issue {
            number,
            title: title.to_string(),
            status: crate::model::Status::new("todo"),
            labels: vec![],
            priority: crate::model::Priority::Medium,
            assignee: None,
            estimate: None,
            commit: None,
            gitlab_id: None,
            linear_id: None,
            mission: None,
            task: None,
            created: "2026-01-01".into(),
            updated: "2026-01-01".into(),
            filename: format!("2026-01-01-{number}.md"),
            body: String::new(),
        };
        let corpus = Corpus {
            issues: vec![to_issue(1, "Fix login bug"), to_issue(2, "Polish exports")],
            texts: vec!["Fix login bug".to_string(), "Polish exports".to_string()],
        };
        let config = Config::default();
        let board_config = config.default_config();

        let board =
            BoardState::build_filtered(board_config, &corpus, "log", &StructuredFilter::default());
        assert_eq!(board.columns.len(), board_config.columns.len());
        assert_eq!(board.column_cards(0).len(), 1);
        assert_eq!(board.column_cards(0)[0].title, "Fix login bug");
        assert_eq!(board.filter.as_deref(), Some("log"));

        let none =
            BoardState::build_filtered(board_config, &corpus, "zzw", &StructuredFilter::default());
        assert!(none.is_empty());

        let empty =
            BoardState::build_filtered(board_config, &corpus, "", &StructuredFilter::default());
        assert_eq!(empty.column_cards(0).len(), 2, "empty query keeps all");
        assert!(empty.filter.is_some());
    }

    #[test]
    fn is_empty_true_only_with_no_cards_anywhere() {
        let board = BoardState {
            columns: vec![BoardColumn {
                name: "a".into(),
                cards: vec![],
            }],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 0,
            filter: None,
            hidden: vec![],
            show_mismatch: true,
        };
        assert!(board.is_empty());

        let populated = BoardState {
            columns: vec![BoardColumn {
                name: "a".into(),
                cards: vec![Card {
                    number: 1,
                    title: "X".into(),
                    priority: crate::model::Priority::Medium,
                    labels: vec![],
                    assignee: None,
                    filename: "x.md".into(),
                    commit: None,
                }],
            }],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 0,
            filter: None,
            hidden: vec![],
            show_mismatch: true,
        };
        assert!(!populated.is_empty());
    }

    #[test]
    fn build_splits_hidden_columns_out_of_visible_surface() {
        use crate::config::{BoardConfiguration, Config};

        let mut config = Config::default();
        config.kanban.configurations.insert(
            "default".to_string(),
            BoardConfiguration {
                columns: vec!["todo".into(), "done".into()],
                hidden_columns: vec!["done".into()],
                ..BoardConfiguration::default()
            },
        );
        let store = crate::storage::Store::open(&config).unwrap();
        let board = BoardState::build(&store, config.default_config());
        assert_eq!(board.columns.len(), 1);
        assert_eq!(board.columns[0].name, "todo");
        assert_eq!(board.hidden.len(), 1);
        assert_eq!(board.hidden[0].name, "done");
        assert_eq!(board.total_cols(), 1);
    }

    #[test]
    fn move_left_skips_hidden_column() {
        let mut board = BoardState {
            columns: vec![BoardColumn {
                name: "visible-a".into(),
                cards: vec![],
            }],
            hidden: vec![BoardColumn {
                name: "hidden-b".into(),
                cards: vec![],
            }],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 0,
            filter: None,
            show_mismatch: true,
        };
        board.move_left();
        assert_eq!(board.active_col, 0, "single visible column wraps to itself");
    }

    #[test]
    fn move_right_skips_hidden_column() {
        let mut board = BoardState {
            columns: vec![BoardColumn {
                name: "visible-a".into(),
                cards: vec![],
            }],
            hidden: vec![BoardColumn {
                name: "hidden-b".into(),
                cards: vec![],
            }],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 0,
            filter: None,
            show_mismatch: true,
        };
        board.move_right();
        assert_eq!(board.active_col, 0, "single visible column wraps to itself");
    }

    #[test]
    fn all_columns_hidden_board_is_displayable_and_navigation_safe() {
        let mut board = BoardState {
            columns: vec![],
            hidden: vec![BoardColumn {
                name: "only-hidden".into(),
                cards: vec![],
            }],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 0,
            filter: None,
            show_mismatch: false,
        };
        assert_eq!(board.total_cols(), 0);
        board.move_left();
        board.move_right();
        assert_eq!(board.active_col, 0, "zero-column board must not panic");
        let board2 = BoardState {
            columns: vec![],
            hidden: vec![],
            mismatch: BoardColumn {
                name: "Mismatched".into(),
                cards: vec![],
            },
            active_col: 0,
            selected: 0,
            filter: None,
            show_mismatch: false,
        };
        assert_eq!(board2.total_cols(), 0);
    }
}