tix-tracker 0.11.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
#[allow(clippy::wildcard_imports)]
use super::*;
use crate::model::*;

fn sample_issue() -> Issue {
    Issue {
        projects: None,
        id: None,
        number: 1,
        title: "Test Issue".into(),
        status: Status::new("todo"),
        labels: vec!["bug".into()],
        priority: Priority::High,
        assignee: Some("alice".into()),
        estimate: Some("2".into()),
        commit: None,
        gitlab_id: None,
        linear_id: None,
        mission: None,
        task: None,
        relationships: vec![crate::relationships::Relationship::new(
            1,
            12,
            crate::relationships::RelationKind::Related,
            "Twelve",
        )],
        related_issues: vec![],
        history: crate::model::History::new(),
        has_retired_links_key: false,
        time_entries: vec![],
        parent: None,
        series: None,
        health: None,
        files: vec!["openspec/changes/x/proposal.md".into()],
        cycles: None,
        milestones: None,
        reviewer: None,
        start_date: None,
        due_date: None,
        created: "2026-01-01".into(),
        type_: None,
        updated: "2026-01-01".into(),
        filename: "test.md".into(),
        body: "Line one\n\nLine two".into(),
        epics: None,
        extra_frontmatter: std::collections::BTreeMap::new(),
        archived: false,
        entered_at: None,
        source: None,
    }
}

/// Render a `DetailState` and return the pane's text.
fn render_text(detail: &DetailState) -> String {
    use ratatui::Terminal;
    use ratatui::backend::TestBackend;
    let backend = TestBackend::new(120, 40);
    let mut terminal = Terminal::new(backend).unwrap();
    terminal
        .draw(|f| render(detail, f, f.area(), &crate::ui::color::Theme::default()))
        .unwrap();
    let buf = terminal.backend().buffer();
    buf.content()
        .iter()
        .map(|c| c.symbol())
        .collect::<Vec<_>>()
        .chunks(120)
        .map(|row| {
            row.iter()
                .copied()
                .collect::<String>()
                .trim_end()
                .to_string()
        })
        .collect::<Vec<_>>()
        .join("\n")
}

fn detail_with(
    relationships: Vec<crate::relationships::Relationship>,
    chain: crate::relationships::DependencyChain,
    blocked: Option<String>,
) -> DetailState {
    let issue = sample_issue();
    DetailState {
        health: None,
        health_diagnostics: Vec::new(),
        wip: None,
        category: None,
        // `sample_issue()` has no parent and no children, so the facts are the
        // empty ones. Read through the real reader rather than hand-constructed,
        // so a fixture cannot drift from the shape the renderer consumes.
        hierarchy: crate::commands::parent::facts_over(
            std::slice::from_ref(&issue),
            "done",
            issue.number,
        ),
        issue,
        relationships,
        chain,
        blocked,
        scroll_offset: 0,
        viewport: std::cell::Cell::new(0),
        max_scroll: std::cell::Cell::new(0),
        rel_cursor: 0,
        related: Vec::new(),
        related_cursor: 0,
        read_only: false,
        epics: Vec::new(),
        capacity: Vec::new(),
    }
}

/// The three cases T027 step 4 names, in one test so the *order* and the
/// empty states are asserted against each other rather than in isolation.
#[test]
fn the_relationship_block_covers_a_blocks_edge_a_related_only_issue_and_the_empty_state() {
    // **A `blocks` edge.** The row carries the kind, the target, and the
    // display name — the three facts T027 step 1 names — and the blocked
    // state and chain are stated, not implied.
    let blocks = detail_with(
        vec![crate::relationships::Relationship::new(
            1,
            2,
            crate::relationships::RelationKind::Blocks,
            "Refactor store",
        )],
        no_chain(),
        Some("Blocked by #1 Ship the thing".to_string()),
    );
    let text = render_text(&blocks);
    assert!(text.contains("blocks #2 Refactor store"), "got:\n{text}");
    assert!(text.contains("blocked: Blocked by #1"), "got:\n{text}");
    assert!(text.contains("chain: none"), "got:\n{text}");

    // **Only `related` edges**, and an issue that is not blocked. A
    // relationship that merely *exists* must not be presented as blocking
    // anything — the whole point of the typed model.
    let related = detail_with(
        vec![crate::relationships::Relationship::new(
            1,
            3,
            crate::relationships::RelationKind::Related,
            "Notes",
        )],
        no_chain(),
        None,
    );
    let text = render_text(&related);
    assert!(text.contains("related #3 Notes"), "got:\n{text}");
    assert!(
        text.contains("blocked: not blocked"),
        "a `related` edge must not read as blocking: got:\n{text}"
    );
    assert!(
        !text.contains("blocked: related"),
        "and nothing may present a non-blocks edge as a blocker: got:\n{text}"
    );

    // **No relationships at all.** The empty state says so, rather than
    // leaving the reader to guess between "none" and "not computed".
    let empty = detail_with(vec![], no_chain(), None);
    let text = render_text(&empty);
    assert!(text.contains("blocked: not blocked"), "got:\n{text}");
    assert!(text.contains("chain: none"), "got:\n{text}");
    assert!(
        !text.contains("links: "),
        "an issue with no relationships has no links row: got:\n{text}"
    );
}

/// Field order is the same as `tix view --show relationships`:
/// relationships, then chain, then blocked.
///
/// Asserted by position rather than by presence, because presence alone would
/// pass with any order — and the order is the part T027 step 2 constrains.
#[test]
fn the_relationship_block_is_ordered_like_the_cli_detail() {
    let mut chain = no_chain();
    chain.paths.push(vec![crate::relationships::ChainNode {
        number: 1,
        title: "Ship it".into(),
    }]);
    let text = render_text(&detail_with(
        vec![crate::relationships::Relationship::new(
            1,
            2,
            crate::relationships::RelationKind::Blocks,
            "Refactor store",
        )],
        chain,
        Some("Blocked by #3 Something".to_string()),
    ));
    let links = text.find("links: ").expect("a links row");
    let chain_at = text.find("chain: ").expect("a chain row");
    let blocked = text.find("blocked: ").expect("a blocked row");
    assert!(
        links < chain_at && chain_at < blocked,
        "relationships, then chain, then blocked — got:\n{text}"
    );
}

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

    let backend = TestBackend::new(120, 40);
    let mut terminal = Terminal::new(backend).unwrap();
    // `sample_issue` owns its relationship, so a store-resolved set for it
    // is exactly its own stored field.
    let detail = DetailState {
        health: None,
        health_diagnostics: Vec::new(),
        wip: None,
        category: None,
        issue: sample_issue(),
        relationships: sample_issue().relationships,
        chain: no_chain(),
        blocked: None,
        // `sample_issue()` has no parent and no children, so the facts are the
        // empty ones. Built through the real reader rather than hand-constructed,
        // so a fixture cannot drift from the shape the renderer consumes.
        hierarchy: crate::commands::parent::facts_over(
            std::slice::from_ref(&sample_issue()),
            "done",
            sample_issue().number,
        ),
        scroll_offset: 0,
        viewport: std::cell::Cell::new(0),
        max_scroll: std::cell::Cell::new(0),
        rel_cursor: 0,
        related: Vec::new(),
        related_cursor: 0,
        read_only: false,
        epics: Vec::new(),
        capacity: Vec::new(),
    };
    terminal
        .draw(|f| render(&detail, f, f.area(), &crate::ui::color::Theme::default()))
        .unwrap();

    let buf = terminal.backend().buffer();
    let text: String = buf
        .content()
        .iter()
        .map(|c| c.symbol().to_string())
        .collect::<Vec<_>>()
        .join("");
    let link = hyperlink(
        &file_uri("openspec/changes/x/proposal.md"),
        "openspec/changes/x/proposal.md",
    );
    assert!(
        text.contains(&link),
        "files must render as an OSC 8 hyperlink to the resolved file"
    );
    assert!(text.contains("related #12 Twelve"), "got:\n{text}");
}

#[test]
fn hyperlink_wraps_label_and_keeps_file_uris() {
    assert_eq!(
        hyperlink("file:///a/b.md", "b.md"),
        "\u{1b}]8;;file:///a/b.md\u{1b}\\b.md\u{1b}]8;;\u{1b}\\"
    );
    assert_eq!(file_uri("file:///already/abs.md"), "file:///already/abs.md");
    assert!(file_uri("openspec/x.md").starts_with("file:///"));
}

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

    let backend = TestBackend::new(10, 5);
    let mut terminal = Terminal::new(backend).unwrap();
    // `sample_issue` owns its relationship, so a store-resolved set for it
    // is exactly its own stored field.
    let detail = DetailState {
        health: None,
        health_diagnostics: Vec::new(),
        wip: None,
        category: None,
        issue: sample_issue(),
        relationships: sample_issue().relationships,
        chain: no_chain(),
        blocked: None,
        // `sample_issue()` has no parent and no children, so the facts are the
        // empty ones. Built through the real reader rather than hand-constructed,
        // so a fixture cannot drift from the shape the renderer consumes.
        hierarchy: crate::commands::parent::facts_over(
            std::slice::from_ref(&sample_issue()),
            "done",
            sample_issue().number,
        ),
        scroll_offset: 0,
        viewport: std::cell::Cell::new(0),
        max_scroll: std::cell::Cell::new(0),
        rel_cursor: 0,
        related: Vec::new(),
        related_cursor: 0,
        read_only: false,
        epics: Vec::new(),
        capacity: Vec::new(),
    };
    terminal
        .draw(|f| render(&detail, f, f.area(), &crate::ui::color::Theme::default()))
        .unwrap();
}

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

    let backend = TestBackend::new(80, 40);
    let mut terminal = Terminal::new(backend).unwrap();
    // `sample_issue` owns its relationship, so a store-resolved set for it
    // is exactly its own stored field.
    let detail = DetailState {
        health: None,
        health_diagnostics: Vec::new(),
        wip: None,
        category: None,
        issue: sample_issue(),
        relationships: sample_issue().relationships,
        chain: no_chain(),
        blocked: None,
        // `sample_issue()` has no parent and no children, so the facts are the
        // empty ones. Built through the real reader rather than hand-constructed,
        // so a fixture cannot drift from the shape the renderer consumes.
        hierarchy: crate::commands::parent::facts_over(
            std::slice::from_ref(&sample_issue()),
            "done",
            sample_issue().number,
        ),
        scroll_offset: 0,
        viewport: std::cell::Cell::new(0),
        max_scroll: std::cell::Cell::new(0),
        rel_cursor: 0,
        related: Vec::new(),
        related_cursor: 0,
        read_only: false,
        epics: Vec::new(),
        capacity: Vec::new(),
    };
    terminal
        .draw(|f| render(&detail, f, f.area(), &crate::ui::color::Theme::default()))
        .unwrap();
}

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

    let backend = TestBackend::new(80, 10);
    let mut terminal = Terminal::new(backend).unwrap();
    // `sample_issue` owns its relationship, so a store-resolved set for it
    // is exactly its own stored field.
    let issue = sample_issue();
    let relationships = issue.relationships.clone();
    let detail = DetailState {
        health: None,
        health_diagnostics: Vec::new(),
        wip: None,
        category: None,
        hierarchy: crate::commands::parent::facts_over(
            std::slice::from_ref(&issue),
            "done",
            issue.number,
        ),
        issue,
        relationships,
        chain: no_chain(),
        blocked: None,
        scroll_offset: 5,
        viewport: std::cell::Cell::new(0),
        max_scroll: std::cell::Cell::new(0),
        rel_cursor: 0,
        related: Vec::new(),
        related_cursor: 0,
        read_only: false,
        epics: Vec::new(),
        capacity: Vec::new(),
    };
    terminal
        .draw(|f| render(&detail, f, f.area(), &crate::ui::color::Theme::default()))
        .unwrap();
}

/// tix #1513 T007: the `related:` block is drawn near the top (above the
/// relationship row), carries a count, styles each entry as a chip, and marks
/// the entry `o` will follow with a `>` — and is drawn at all only when the
/// issue has `related_issues`.
#[test]
fn the_related_block_renders_a_count_chips_and_the_selection_marker() {
    let mut detail = detail_with(
        vec![crate::relationships::Relationship::new(
            1,
            2,
            crate::relationships::RelationKind::Related,
            "Twelve",
        )],
        no_chain(),
        None,
    );
    detail.related = crate::related::classify_all(&[
        "12".to_string(),
        "../other-repo/issues/2026-01-01-x.md".to_string(),
        "https://gitlab.com/foo/bar#7".to_string(),
    ]);
    detail.related_cursor = 1;
    let text = render_text(&detail);

    assert!(
        text.contains("related: 3"),
        "a count is drawn: got:\n{text}"
    );
    // Rows carry the block border, so a cell's text is the row with the border
    // and padding stripped.
    let cell = |line: &str| {
        line.trim_matches(|c: char| c == '│' || c == ' ')
            .to_string()
    };
    // Chips: the local selector, the relative path, and the URL.
    assert!(
        text.lines().any(|line| cell(line) == "12"),
        "the local chip is drawn: got:\n{text}"
    );
    assert!(
        text.lines()
            .any(|line| cell(line).contains("../other-repo/issues/2026-01-01-x.md")),
        "the path chip is drawn: got:\n{text}"
    );
    assert!(
        text.lines()
            .any(|line| cell(line).contains("https://gitlab.com/foo/bar#7")),
        "the URL chip is drawn: got:\n{text}"
    );
    // The `>` marker sits on the **selected** entry, and only on it.
    let selected = text
        .lines()
        .find(|line| cell(line).contains("../other-repo"))
        .expect("the selected line");
    assert!(
        cell(selected).starts_with("> "),
        "the selected related entry needs a marker: {selected:?}"
    );
    let first = text
        .lines()
        .find(|line| cell(line) == "12")
        .expect("the first line");
    assert!(
        !cell(first).contains('>'),
        "unselected related entries carry no marker: {first:?}"
    );
    // "Near the top, before the relationship row" — asserted by position.
    let related_at = text.find("related: 3").expect("the related block");
    let links_at = text.find("links: ").expect("the relationship row");
    assert!(
        related_at < links_at,
        "the related block must precede the links row: got:\n{text}"
    );

    // Absent when there is nothing to show: no empty heading on every issue.
    let empty = detail_with(vec![], no_chain(), None);
    let empty_text = render_text(&empty);
    assert!(
        !empty_text.contains("related:"),
        "an issue with no related_issues must draw no block: got:\n{empty_text}"
    );
}

#[test]
fn assignee_render_identity_verbatim_bare_gets_at() {
    assert_eq!(render_assignee(None), None);
    assert_eq!(
        render_assignee(Some("Herbert Maschke <thyseus@pm.me>")),
        Some("Herbert Maschke <thyseus@pm.me>".to_string())
    );
    assert_eq!(render_assignee(Some("alice")), Some("@alice".to_string()));
    assert_eq!(render_assignee(Some("@alice")), Some("@alice".to_string()));
}

// ---- WP04 T019: the epic block and direct issue navigation --------------

/// The canonical rows the CLI prints, as `App::detail_state_for` fills them.
fn epic_entry(heading: &str, detail: &[&str]) -> crate::commands::view::EpicBlockEntry {
    crate::commands::view::EpicBlockEntry {
        heading: heading.to_string(),
        detail: detail.iter().map(|line| (*line).to_string()).collect(),
    }
}

#[test]
fn t019_the_pane_renders_the_canonical_epic_rows_and_the_navigation_affordance() {
    let mut detail = detail_with(vec![], no_chain(), None);
    detail.epics = vec![epic_entry(
        "Alpha (e-aaa111)",
        &[
            "progress: 1/2 done",
            "weighted progress: 2/2 (100%)",
            "children: 1",
            "blocked: 0",
        ],
    )];
    let text = render_text(&detail);
    assert!(text.contains("epics:"), "{text}");
    assert!(text.contains("Alpha (e-aaa111)"), "{text}");
    assert!(
        text.contains("progress: 1/2 done"),
        "the pane renders the same facts as `tix show`: {text}"
    );
    assert!(text.contains("weighted progress: 2/2 (100%)"), "{text}");
    assert!(
        text.contains("members open directly from the epic view"),
        "the direct issue navigation affordance is explicit (FR-004): {text}"
    );
}

#[test]
fn t019_an_issue_in_no_epic_draws_no_epic_heading() {
    let detail = detail_with(vec![], no_chain(), None);
    let text = render_text(&detail);
    assert!(
        !text.contains("epics:"),
        "an empty reference list is the empty state, not an empty heading: {text}"
    );
}

#[test]
fn t019_a_missing_epic_reference_is_rendered_with_its_id_and_reason() {
    let mut detail = detail_with(vec![], no_chain(), None);
    detail.epics = vec![epic_entry(
        "e-gone1 (missing reference)",
        &[
            "issue #5 records epic reference `e-gone1`, which is not in the registry \
           (the reference is kept so it can be repaired)",
        ],
    )];
    let text = render_text(&detail);
    assert!(
        text.contains("e-gone1 (missing reference)"),
        "a missing reference is named, not dropped (C-005): {text}"
    );
    assert!(text.contains("not in the registry"), "{text}");
}