tix-tracker 0.12.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
#[allow(clippy::wildcard_imports)]
use super::super::*;
#[allow(clippy::wildcard_imports)]
use super::helpers::*;
use std::fs;

#[test]
fn startup_shows_rollover_dialog_when_plan_exists() {
    let (_tmp, app) = make_app_with_rollover_dialog();
    assert!(matches!(app.mode, Mode::RolloverDialog));
    assert!(app.rollover_dialog.is_some());
}

#[test]
fn rollover_dialog_enter_applies_rollover() {
    let (_tmp, mut app) = make_app_with_rollover_dialog();
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();
    assert!(matches!(app.mode, Mode::Board));
    let issue = app.store.list().unwrap().into_iter().next().unwrap();
    let cycles = issue.cycles.unwrap_or_default();
    assert!(cycles.iter().any(|c| c == "Cycle 2"));
    assert!(!cycles.iter().any(|c| c == "Cycle 1"));
}

#[test]
fn cursor_clamp_empty_column() {
    let (_tmp, mut app) = make_app();
    app.board.move_left();
    assert_eq!(app.board.active_col, app.board.total_cols() - 1);
    app.board.move_right();
    assert_eq!(app.board.active_col, 0);
}

#[test]
fn cursor_clamp_single_card() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "todo", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    assert_eq!(app.board.column_cards(0).len(), 1);
    app.board.move_down();
    assert_eq!(app.board.selected, 0);
    app.board.move_up();
    assert_eq!(app.board.selected, 0);
}

#[test]
fn wrap_around_columns() {
    let (_tmp, mut app) = make_app();
    let total = app.board.total_cols();
    for _ in 0..total + 2 {
        app.board.move_right();
    }
    assert_eq!(app.board.active_col, 2 % total);
    for _ in 0..total + 2 {
        app.board.move_left();
    }
}

#[test]
fn d_opens_confirm_delete() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "todo", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    let _ = app.handle_key(press(KeyCode::Char('d'))).unwrap();
    assert!(matches!(app.mode, Mode::ConfirmDelete));
    assert!(app.confirm_delete_target.is_some());
}

#[test]
fn move_to_done_triggers_commit_prompt() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    // issue sits in "in review" (0-indexed column 2), target is "done" (3)
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "in review", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    app.board.select_column(2);
    app.board.selected = 0;

    let _ = app.handle_key(press(KeyCode::Char('>'))).unwrap();
    // Moving to done without a commit opens the hash prompt
    assert!(
        matches!(
            &app.mode,
            Mode::MoveIntoDone { buffer } if buffer.is_empty()
        ),
        "expected MoveIntoDone, got {:?}",
        app.mode
    );

    // Esc cancels the prompt and keeps the status unchanged
    let _ = app.handle_key(press(KeyCode::Esc)).unwrap();
    assert!(matches!(app.mode, Mode::Board));
    let issue = app
        .store
        .get(crate::storage::IssueSelector::Filename(
            "2026-01-01-a.md".into(),
        ))
        .unwrap();
    assert_eq!(issue.status.display(), "in review");
    assert!(issue.commit.is_none());
}

#[test]
fn move_into_done_with_commit_applies() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "in review", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    app.board.select_column(2);
    app.board.selected = 0;

    let _ = app.handle_key(press(KeyCode::Char('>'))).unwrap();
    assert!(matches!(&app.mode, Mode::MoveIntoDone { .. }));

    for c in "abc123".chars() {
        let _ = app.handle_key(press(KeyCode::Char(c))).unwrap();
    }
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();

    assert!(matches!(app.mode, Mode::Board));
    let issue = app
        .store
        .get(crate::storage::IssueSelector::Filename(
            "2026-01-01-a.md".into(),
        ))
        .unwrap();
    assert_eq!(issue.status.display(), "done");
    assert_eq!(issue.commit.as_deref(), Some("abc123"));
}

#[test]
fn move_into_done_with_empty_commit_moves_without_hash() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "in review", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    app.board.select_column(2);
    app.board.selected = 0;

    let _ = app.handle_key(press(KeyCode::Char('>'))).unwrap();
    assert!(matches!(&app.mode, Mode::MoveIntoDone { .. }));
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();

    assert!(matches!(app.mode, Mode::Board));
    let issue = app
        .store
        .get(crate::storage::IssueSelector::Filename(
            "2026-01-01-a.md".into(),
        ))
        .unwrap();
    assert_eq!(issue.status.display(), "done");
    assert!(
        issue.commit.is_none(),
        "no commit recorded when moving to done without a hash"
    );
}

#[test]
fn move_out_of_done_clears_commit() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "done", Some("abc123"));
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    app.board.select_column(3);
    app.board.selected = 0;

    let _ = app.handle_key(press(KeyCode::Char('<'))).unwrap();
    assert!(matches!(app.mode, Mode::Board));
    let issue = app
        .store
        .get(crate::storage::IssueSelector::Filename(
            "2026-01-01-a.md".into(),
        ))
        .unwrap();
    assert_eq!(issue.status.display(), "in review");
    assert!(issue.commit.is_none());
}

#[test]
fn move_right_wraps_across_real_columns_skipping_mismatch() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "done", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    app.board.select_column(3); // done (last real column)
    app.board.selected = 0;
    let _ = app.handle_key(press(KeyCode::Char('>'))).unwrap();
    assert_eq!(app.board.active_col, 0);
    let issue = app
        .store
        .get(crate::storage::IssueSelector::Filename(
            "2026-01-01-a.md".into(),
        ))
        .unwrap();
    assert_eq!(issue.status.display(), "todo");
}

#[test]
fn move_left_wraps_across_real_columns_skipping_mismatch() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "todo", Some("abc"));
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    app.board.select_column(0);
    app.board.selected = 0;
    let _ = app.handle_key(press(KeyCode::Char('<'))).unwrap();
    assert_eq!(app.board.active_col, 3);
    let issue = app
        .store
        .get(crate::storage::IssueSelector::Filename(
            "2026-01-01-a.md".into(),
        ))
        .unwrap();
    assert_eq!(issue.status.display(), "done");
}

#[test]
fn move_left_right_board() {
    let (_tmp, mut app) = make_app();
    let initial = app.board.active_col;
    let _ = app.handle_key(press(KeyCode::Char('l'))).unwrap();
    assert_eq!(app.board.active_col, initial + 1);
    let _ = app.handle_key(press(KeyCode::Char('h'))).unwrap();
    assert_eq!(app.board.active_col, initial);
}

#[test]
fn confirm_delete_y_removes_issue() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "todo", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    let _ = app.handle_key(press(KeyCode::Char('d'))).unwrap();
    assert!(matches!(app.mode, Mode::ConfirmDelete));
    let _ = app.handle_key(press(KeyCode::Char('y'))).unwrap();
    assert!(matches!(app.mode, Mode::Board));
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    assert_eq!(app.board.column_cards(0).len(), 0);
}

#[test]
fn confirm_delete_n_cancels() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "todo", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    let _ = app.handle_key(press(KeyCode::Char('d'))).unwrap();
    let _ = app.handle_key(press(KeyCode::Char('n'))).unwrap();
    assert!(matches!(app.mode, Mode::Board));
    assert!(app.confirm_delete_target.is_none());
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    assert_eq!(app.board.column_cards(0).len(), 1);
}

#[test]
fn ctrl_up_and_down_reorder_the_selected_card() {
    let (_tmp, mut app) = make_mouse_app();
    app.board.active_col = 0;
    app.board.selected = 1;
    let up = app
        .handle_key(press_with_modifiers(
            KeyCode::Up,
            crossterm::event::KeyModifiers::CONTROL,
        ))
        .unwrap();
    assert_eq!(up, Action::None);
    assert_eq!(
        app.board
            .column_cards(0)
            .iter()
            .map(|c| c.title.as_str())
            .collect::<Vec<_>>(),
        ["Beta", "Alpha"],
        "ctrl-up moves the selected card one slot earlier"
    );
    assert_eq!(app.board.selected, 0);
    let down = app
        .handle_key(press_with_modifiers(
            KeyCode::Down,
            crossterm::event::KeyModifiers::CONTROL,
        ))
        .unwrap();
    assert_eq!(down, Action::None);
    assert_eq!(
        app.board
            .column_cards(0)
            .iter()
            .map(|c| c.title.as_str())
            .collect::<Vec<_>>(),
        ["Alpha", "Beta"],
        "ctrl-down restores the original order"
    );
}

/// `PgUp`/`PgDn` move the board selection by one screen of cards — and they move
/// it **at all**, which they did not before (tix #1442 follow-up): the keys were
/// unbound on the board, and an unbound key in a non-text context is rewritten to
/// `F(12)` before the handler sees it, so the key did nothing while the wheel next
/// to it worked.
#[test]
fn board_page_keys_move_the_selection_by_a_screen() {
    use ratatui::Terminal;
    use ratatui::backend::TestBackend;

    let (_tmp, mut app) = make_app_with_cards(30);
    // The page size is reported by the draw, exactly as in a session.
    let mut terminal = Terminal::new(TestBackend::new(70, 20)).unwrap();
    terminal.draw(|f| render(&app, f, f.area())).unwrap();
    let page = app.board_page.get();
    assert!(
        page > 1,
        "a 20-row column must hold more than one card, got {page}"
    );

    assert_eq!(app.board.selected, 0);
    app.handle_key(press(KeyCode::PageDown)).unwrap();
    assert_eq!(app.board.selected, page, "one screen down");
    app.handle_key(press(KeyCode::PageDown)).unwrap();
    assert_eq!(app.board.selected, page * 2, "two screens down");
    app.handle_key(press(KeyCode::PageUp)).unwrap();
    assert_eq!(app.board.selected, page, "and back one");

    for _ in 0..20 {
        app.handle_key(press(KeyCode::PageDown)).unwrap();
    }
    assert_eq!(
        app.board.selected, 29,
        "paging past the end lands on the last card"
    );
    for _ in 0..20 {
        app.handle_key(press(KeyCode::PageUp)).unwrap();
    }
    assert_eq!(app.board.selected, 0, "and paging up lands on the first");
}

/// An empty column has nothing to page, and the key says nothing rather than
/// moving a selection that is not there.
#[test]
fn board_page_keys_do_nothing_in_an_empty_column() {
    use ratatui::Terminal;
    use ratatui::backend::TestBackend;

    let (_tmp, mut app) = make_app();
    let mut terminal = Terminal::new(TestBackend::new(70, 20)).unwrap();
    terminal.draw(|f| render(&app, f, f.area())).unwrap();

    assert_eq!(app.board_page.get(), 0, "nothing to page");
    app.handle_key(press(KeyCode::PageDown)).unwrap();
    assert_eq!(app.board.selected, 0);
    assert!(matches!(app.mode, Mode::Board));
}

#[test]
fn sub_issues_are_shown_by_default_and_u_toggles_them() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-parent.md", 1, "Parent", "todo", None);
    fs::write(
            dir.join("2026-01-02-child.md"),
            "---\nnumber: 2\ntitle: \"Child\"\nstatus: \"todo\"\nlabels: []\npriority: \"medium\"\ncreated: \"2026-01-02\"\nupdated: \"2026-01-02\"\nparent: 1\n---\n\nBody text.",
        )
        .unwrap();
    app.refresh_corpus().unwrap();

    let shape = |app: &App| -> Vec<(u32, u8)> {
        app.board
            .column_cards(0)
            .iter()
            .map(|c| (c.number, c.depth))
            .collect()
    };
    assert!(app.show_children, "sub-issues are shown by default");
    assert_eq!(
        shape(&app),
        vec![(1, 0), (2, 1)],
        "the default build nests the sub-issue beneath its parent"
    );

    let _ = app.handle_key(press(KeyCode::Char('u'))).unwrap();
    assert!(!app.show_children);
    assert_eq!(app.status_msg.as_deref(), Some("Hiding sub-issues"));
    assert_eq!(
        shape(&app),
        vec![(2, 0), (1, 0)],
        "toggling off restores the flat order"
    );

    let _ = app.handle_key(press(KeyCode::Char('u'))).unwrap();
    assert!(app.show_children);
    assert_eq!(app.status_msg.as_deref(), Some("Showing sub-issues"));
    assert_eq!(
        shape(&app),
        vec![(1, 0), (2, 1)],
        "toggling back nests the sub-issue again"
    );
}

/// Status and Priority are reachable from the keyboard (tix #1508): `Enter`
/// and `F2` both open their dropdown, and `Enter` on those rows never submits.
#[test]
fn enter_and_f2_open_the_status_and_priority_dropdowns() {
    let (_tmp, mut app) = make_app();
    app.handle_key(press(KeyCode::F(1))).unwrap();
    app.handle_key(press(KeyCode::Down)).unwrap(); // Title -> Status
    assert_eq!(
        app.form.as_ref().unwrap().focus,
        crate::ui::form::FormFocus::Status
    );

    app.handle_key(press(KeyCode::Enter)).unwrap();
    assert!(
        app.form_picker
            .as_ref()
            .is_some_and(|p| p.field == FormPickerField::Status),
        "Enter on Status opens its dropdown"
    );
    assert!(
        matches!(app.mode, Mode::Form),
        "Enter on Status must not submit the form"
    );
    assert!(app.store.list().unwrap().is_empty(), "nothing was written");
    let picker = app.form_picker.as_ref().unwrap();
    assert_eq!(
        match &picker.state.selection {
            SelectionModel::Single(current) => current.clone(),
            SelectionModel::Multi(_) => panic!("Status must be single-select"),
        },
        Some("todo".to_string()),
        "the dropdown opens on the row's current value"
    );
    app.handle_key(press(KeyCode::Esc)).unwrap();
    assert!(app.form_picker.is_none(), "Esc closes the dropdown");

    app.handle_key(press(KeyCode::F(2))).unwrap();
    assert!(
        app.form_picker
            .as_ref()
            .is_some_and(|p| p.field == FormPickerField::Status),
        "F2 opens the Status dropdown too"
    );
    app.handle_key(press(KeyCode::Esc)).unwrap();

    app.handle_key(press(KeyCode::Down)).unwrap(); // Status -> Priority
    assert_eq!(
        app.form.as_ref().unwrap().focus,
        crate::ui::form::FormFocus::Priority
    );
    app.handle_key(press(KeyCode::Enter)).unwrap();
    assert!(
        app.form_picker
            .as_ref()
            .is_some_and(|p| p.field == FormPickerField::Priority),
        "Enter on Priority opens its dropdown"
    );
    assert!(
        matches!(app.mode, Mode::Form),
        "Enter on Priority must not submit"
    );
    app.handle_key(press(KeyCode::Esc)).unwrap();
    app.handle_key(press(KeyCode::F(2))).unwrap();
    assert!(
        app.form_picker
            .as_ref()
            .is_some_and(|p| p.field == FormPickerField::Priority),
        "F2 opens the Priority dropdown too"
    );
}

/// Choosing an option writes the row, and the created issue lands in that
/// column (tix #1508).
#[test]
fn choosing_a_status_creates_the_issue_in_that_column() {
    let (_tmp, mut app) = make_app();
    app.handle_key(press(KeyCode::F(1))).unwrap();
    type_text(&mut app, "Placed");

    app.handle_key(press(KeyCode::Down)).unwrap(); // Title -> Status
    app.handle_key(press(KeyCode::Enter)).unwrap(); // open the dropdown
    // The options are the board's columns; the cursor starts on the first
    // (`todo`), so one `Down` lands on `in progress`.
    app.handle_key(press(KeyCode::Down)).unwrap();
    app.handle_key(press(KeyCode::Enter)).unwrap();
    assert_eq!(app.form.as_ref().unwrap().status, "in progress");

    app.handle_key(press(KeyCode::Esc)).unwrap(); // close the dropdown
    // Submit from a row Enter still submits from.
    app.form.as_mut().unwrap().focus = crate::ui::form::FormFocus::Body;
    app.handle_key(press(KeyCode::Enter)).unwrap();

    assert!(matches!(app.mode, Mode::Board));
    let issue = app
        .store
        .list()
        .unwrap()
        .into_iter()
        .find(|i| i.title == "Placed")
        .expect("the mode created the issue");
    assert_eq!(issue.status.to_string(), "in progress");

    // And the card really sits in that column on the board, not just in the
    // file: the chosen status is the created issue's column.
    let names: Vec<String> = (0..app.board.total_cols())
        .map(|i| app.board.column_name(i).to_string())
        .collect();
    let idx = names
        .iter()
        .position(|n| n == "in progress")
        .expect("in progress column exists");
    assert_eq!(
        app.board.column_cards(idx).len(),
        1,
        "the chosen status lands the issue in 'in progress'"
    );
}

/// Trunk labels pluralize by configured count; the chord never changes.
#[test]
fn mode_labels_pluralize_by_configured_count() {
    let (_tmp, mut app) = make_app();
    assert_eq!(app.mode_label(TopMode::Board), "Board");
    assert_eq!(app.mode_label(TopMode::Cycle), "Cycle");
    assert_eq!(app.mode_label(TopMode::Milestones), "Milestone");
    let cells = draw_board(&app, 80, 24);
    assert!(
        flush_line(&cells, 80, 2).starts_with("F3 Board"),
        "{:?}",
        flush_line(&cells, 80, 2)
    );
    assert!(
        flush_line(&cells, 80, 4).starts_with("F4 Cycle"),
        "{:?}",
        flush_line(&cells, 80, 4)
    );
    assert!(
        flush_line(&cells, 80, 5).starts_with("F5 Milestone"),
        "{:?}",
        flush_line(&cells, 80, 5)
    );

    // The boundary is `count > 1`: one cycle stays singular, two pluralize.
    app.store
        .config
        .cycles
        .insert("Solo".into(), crate::config::PlanningCycle::default());
    assert_eq!(app.mode_label(TopMode::Cycle), "Cycle");
    app.store
        .config
        .cycles
        .insert("Pair".into(), crate::config::PlanningCycle::default());
    assert_eq!(app.mode_label(TopMode::Cycle), "Cycles");

    // Two boards pluralize the Board trunk.
    let (_tmp, app) = make_branchy_app();
    assert_eq!(app.mode_label(TopMode::Board), "Boards");
    let cells = draw_board(&app, 80, 24);
    let board_row = (0..24u16)
        .find(|row| flush_line(&cells, 80, *row).starts_with("F3 "))
        .expect("the Board trunk is drawn");
    assert!(
        flush_line(&cells, 80, board_row).starts_with("F3 Boards"),
        "{:?}",
        flush_line(&cells, 80, board_row)
    );

    // Milestones follow the same rule.
    let (_tmp, app) = make_app();
    let planner =
        crate::planning::Planner::from_config(app.store.config.clone(), app.project_root());
    planner
        .create_milestone_file("Backlog", None, None)
        .unwrap();
    assert_eq!(app.mode_label(TopMode::Milestones), "Milestone");
    planner.create_milestone_file("Q4", None, None).unwrap();
    assert_eq!(app.mode_label(TopMode::Milestones), "Milestones");
}