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
//! `tix init` planning seeding contract tests
//! (`contracts/tix-toml-planning.md`, `contracts/milestone-file-format.md`),
//! driven through the compiled binary and the library config reader.

use std::fs;
use std::path::Path;

use assert_cmd::Command;
use predicates::prelude::*;
use tempfile::TempDir;

use tix::config::Config;

fn tix() -> Command {
    Command::cargo_bin("tix").unwrap()
}

/// Pin git's global/system config to a missing file so `git_identity()`
/// cannot inherit the developer's `~/.gitconfig` (deterministic tests).
fn without_git_identity() -> Command {
    let mut cmd = tix();
    cmd.env("GIT_CONFIG_GLOBAL", "/nonexistent-gitconfig")
        .env("GIT_CONFIG_SYSTEM", "/nonexistent-gitconfig")
        .env("GIT_CONFIG_NOSYSTEM", "1");
    cmd
}

/// `git init` + a local author identity inside `dir` (local config always
/// beats global, so the identity is deterministic).
fn git_author(dir: &Path, name: &str, email: &str) {
    for args in [
        &["init", "-q"][..],
        &["config", "user.name", name][..],
        &["config", "user.email", email][..],
    ] {
        let status = std::process::Command::new("git")
            .current_dir(dir)
            .args(args)
            .status()
            .expect("`git` must be available to run the CLI tests");
        assert!(status.success(), "git {args:?} failed");
    }
}

fn read_config(dir: &Path) -> tix::error::Result<Config> {
    Config::load_with_warning(&dir.join("tix.toml"), |_| {})
}

#[test]
fn init_seeds_planning_without_git_identity() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();

    without_git_identity()
        .current_dir(dir)
        .arg("init")
        .assert()
        .success()
        .stdout(predicate::str::contains("Created"));

    let cfg = read_config(dir).unwrap();
    assert_eq!(cfg.planning.cycle_number, 1);
    assert_eq!(cfg.planning.default_cycle.as_deref(), Some("Default"));
    assert_eq!(cfg.planning.default_milestone.as_deref(), Some("Backlog"));
    assert_eq!(
        cfg.planning.default_team, None,
        "no git identity → no default team"
    );
    assert!(cfg.teams.is_empty(), "no team without a git identity");
    assert_eq!(cfg.cycles.len(), 1);
    assert!(cfg.cycles.contains_key("Default"));
    assert_eq!(cfg.milestones_dir, Some("docs/milestones".into()));

    let raw = fs::read_to_string(dir.join("tix.toml")).unwrap();
    assert!(
        raw.contains("[planning]"),
        "seed must serialize `[planning]`:\n{raw}"
    );
    assert!(
        raw.contains("[cycles.Default]") || raw.contains(r#"[cycles."Default"]"#),
        "seed cycle key:\n{raw}"
    );
    // The board is a file store now: `tix.toml` must not carry a second copy.
    assert!(
        !raw.contains("[kanban"),
        "board records belong in docs/boards/:\n{raw}"
    );
    assert!(
        !raw.contains("card_order"),
        "card_order belongs in docs/boards/:\n{raw}"
    );
}

#[test]
fn init_seeds_default_team_from_git_author() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    git_author(dir, "Herb Mason", "herb@example.com");

    tix().current_dir(dir).arg("init").assert().success();
    let cfg = read_config(dir).unwrap();
    assert_eq!(cfg.planning.default_team.as_deref(), Some("default"));
    let team = cfg.teams.get("default").unwrap();
    assert_eq!(team.members, ["Herb Mason <herb@example.com>"]);
    assert!(cfg.cycles.contains_key("Default"));
}

#[test]
fn init_creates_backlog_milestone_file() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    without_git_identity()
        .current_dir(dir)
        .arg("init")
        .assert()
        .success();

    let milestones = dir.join("docs").join("milestones");
    let entries: Vec<String> = fs::read_dir(&milestones)
        .unwrap()
        .map(|e| e.unwrap().file_name().to_string_lossy().into_owned())
        .collect();
    assert_eq!(
        entries.len(),
        1,
        "exactly one milestone file in {milestones:?}"
    );
    let file_name = &entries[0];

    // Filename = `<today>-backlog.md`.
    assert!(file_name.ends_with("-backlog.md"), "got {file_name}");
    let prefix = file_name.trim_end_matches("-backlog.md");
    assert!(
        tix::model::validate_date(prefix),
        "date prefix {prefix} must be a calendar date"
    );

    let raw = fs::read_to_string(milestones.join(file_name)).unwrap();
    assert!(
        raw.starts_with("---\n"),
        "must start with a `---` delimiter"
    );
    assert!(raw.contains("name: Backlog"), "frontmatter name:\n{raw}");
    assert!(
        raw.contains(&format!("created: {prefix}")),
        "created must match the filename date prefix:\n{raw}"
    );
    assert!(raw.contains("updated:"), "frontmatter updated:\n{raw}");
    assert!(!raw.contains("target_date"), "seed has no due date:\n{raw}");
    assert!(
        raw.contains("Default milestone for unscheduled work"),
        "seed body:\n{raw}"
    );
}

#[test]
fn init_refuses_to_overwrite() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    without_git_identity()
        .current_dir(dir)
        .arg("init")
        .assert()
        .success();

    let first = read_config(dir).unwrap();

    without_git_identity()
        .current_dir(dir)
        .arg("init")
        .assert()
        .failure()
        .code(1)
        .stderr(predicate::str::contains("refusing to overwrite"));

    // Nothing changed on the re-run.
    let second = read_config(dir).unwrap();
    assert_eq!(first, second);
}

#[test]
fn init_scaffold_places_the_keybinding_example_in_its_own_file() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    without_git_identity()
        .current_dir(dir)
        .arg("init")
        .assert()
        .success();
    let raw = fs::read_to_string(dir.join("tix.toml")).unwrap();
    assert!(!raw.contains("keybindings"));
    assert!(!raw.contains("[board]"));
    let keybindings = fs::read_to_string(dir.join(tix::keybindings::KEYBINDINGS_FILE)).unwrap();
    assert!(keybindings.contains("# [board]"));
    assert!(keybindings.contains("# new_issue = [\"ctrl+n\"]"));
    assert!(!keybindings.contains("\n[board]"));
    assert!(!keybindings.contains("move_left ="));
    // The template example is commented as well: enabling it is the user's act.
    assert!(raw.contains("# [templates.bug]"));
    assert!(raw.contains("# labels = [\"bug\"]"));
    assert!(!raw.contains("\n[templates."));
    // The child-repository example is commented too, and no live section is
    // written (tix #1529/#1531).
    assert!(raw.contains("# [repos]"));
    assert!(raw.contains("# parent_repo ="));
    assert!(!raw.contains("\n[repos]"));
    // #1530: `tags_dir` ships (uncommented) and the type colors are a commented
    // example; the default types are listed under `types`.
    assert!(raw.contains("tags_dir = \"docs/tags\""), "{raw}");
    assert!(raw.contains("# [type_colors]"), "{raw}");
    assert!(raw.contains("types = ["), "{raw}");
}

#[test]
fn uncommented_init_template_example_loads() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    without_git_identity()
        .current_dir(dir)
        .arg("init")
        .assert()
        .success();
    let path = dir.join("tix.toml");
    let raw = fs::read_to_string(&path).unwrap();
    let active = raw
        .replace("# [templates.bug]", "[templates.bug]")
        .replace("# labels = [\"bug\"]", "labels = [\"bug\"]")
        .replace(
            "# body = \"## Steps to reproduce\\n\\n## Expected\\n\"",
            "body = \"## Steps to reproduce\\n\\n## Expected\\n\"",
        );
    fs::write(&path, active).unwrap();

    let config = read_config(dir).unwrap();
    let bug = config
        .templates
        .get("bug")
        .expect("the documented example loads as a template");
    assert_eq!(bug.labels, ["bug"]);
    assert_eq!(
        bug.body.as_deref(),
        Some("## Steps to reproduce\n\n## Expected\n"),
        "the documented TOML escapes load as real newlines"
    );
}

#[test]
fn uncommented_init_keybinding_example_loads() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    without_git_identity()
        .current_dir(dir)
        .arg("init")
        .assert()
        .success();
    let path = dir.join(tix::keybindings::KEYBINDINGS_FILE);
    let raw = fs::read_to_string(&path).unwrap();
    let active = raw
        .replace("# [board]", "[board]")
        .replace("# new_issue = [\"ctrl+n\"]", "new_issue = [\"ctrl+n\"]");
    fs::write(&path, active).unwrap();
    let bindings = tix::keybindings::KeyBindings::load_effective(dir).unwrap();
    assert_eq!(
        bindings.label(
            tix::keybindings::InputContext::Board,
            tix::keybindings::TuiAction::NewIssue
        ),
        "Ctrl+n"
    );
    assert_eq!(
        bindings.label(
            tix::keybindings::InputContext::Board,
            tix::keybindings::TuiAction::Open
        ),
        "Enter"
    );
}

#[test]
fn init_scaffold_documents_custom_attributes() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    without_git_identity()
        .current_dir(dir)
        .arg("init")
        .assert()
        .success();
    let raw = fs::read_to_string(dir.join("tix.toml")).unwrap();

    // The example is present, and commented: an empty `[custom_attributes]`
    // section is not serialized, so an *active* one would be a section with no
    // keys plus a duplicate the moment it is uncommented.
    assert!(
        raw.contains("# [custom_attributes]"),
        "the scaffold documents the section:\n{raw}"
    );
    assert!(
        raw.contains("# keys = [\"build_id\", \"reviewed_by\"]"),
        "the scaffold shows a keys example:\n{raw}"
    );
    assert!(
        !raw.contains("\n[custom_attributes]"),
        "the example must stay commented out:\n{raw}"
    );
    assert_eq!(
        read_config(dir).unwrap().custom_attributes(),
        Vec::<String>::new(),
        "a fresh project declares nothing"
    );
}

#[test]
fn uncommented_custom_attribute_example_loads() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    without_git_identity()
        .current_dir(dir)
        .arg("init")
        .assert()
        .success();
    let path = dir.join("tix.toml");
    let raw = fs::read_to_string(&path).unwrap();
    let active = raw
        .replace("# [custom_attributes]", "[custom_attributes]")
        .replace(
            "# keys = [\"build_id\", \"reviewed_by\"]",
            "keys = [\"build_id\", \"reviewed_by\"]",
        );
    fs::write(&path, active).unwrap();

    assert_eq!(
        read_config(dir).unwrap().custom_attributes(),
        vec!["build_id".to_string(), "reviewed_by".to_string()],
        "uncommenting the example declares both keys"
    );
}

#[test]
fn seeded_config_roundtrips_planning_and_cycles() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    without_git_identity()
        .current_dir(dir)
        .arg("init")
        .assert()
        .success();

    let cfg = read_config(dir).unwrap();
    cfg.save(&dir.join("tix.toml")).unwrap();
    let reloaded = read_config(dir).unwrap();
    assert_eq!(cfg, reloaded, "save/load must be a stable round trip");
    assert!(reloaded.cycles.contains_key("Default"));
}

#[test]
fn init_writes_default_board_and_leaves_cycles_implicit() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    without_git_identity()
        .current_dir(dir)
        .arg("init")
        .assert()
        .success();

    let board_path = dir.join("docs").join("boards").join("default.md");
    assert!(board_path.is_file(), "init writes docs/boards/default.md");
    let raw = fs::read_to_string(&board_path).unwrap();
    for column in [
        "triage",
        "todo",
        "in progress",
        "in review",
        "done",
        "wontfix",
    ] {
        assert!(raw.contains(column), "missing column {column}:\n{raw}");
    }
    assert!(raw.contains("done_column: done"), "{raw}");
    assert!(raw.contains("completed"), "category map:\n{raw}");
    assert!(raw.contains("canceled"), "category map:\n{raw}");

    assert!(
        !dir.join("docs").join("cycles").exists(),
        "init leaves docs/cycles/ absent; the Default cycle is implicit"
    );
    let cycles = tix::cycle_store::CycleStore::new(dir).list().unwrap();
    assert_eq!(cycles.len(), 1);
    assert_eq!(cycles[0].name, "Default");
    assert_eq!(cycles[0].due_date, None, "Default has no end date");

    // The board is read back from its file, not from tix.toml.
    let cfg = read_config(dir).unwrap();
    assert_eq!(
        cfg.default_config().columns,
        [
            "triage",
            "todo",
            "in progress",
            "in review",
            "done",
            "wontfix"
        ]
    );

    // A second run is refused and changes nothing.
    without_git_identity()
        .current_dir(dir)
        .arg("init")
        .assert()
        .failure()
        .code(1)
        .stderr(predicate::str::contains("refusing to overwrite"));
    assert_eq!(
        fs::read_to_string(&board_path).unwrap(),
        raw,
        "the existing board file is not overwritten"
    );
}

#[test]
fn legacy_tables_load_unchanged_and_files_win_when_present() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    fs::write(
        dir.join("tix.toml"),
        "issues_dir = \"docs/issues\"\n\n\
         [kanban.default]\ncolumns = [\"todo\", \"done\"]\ndone_column = \"done\"\n\n\
         [cycles.\"Cycle 1\"]\nstart_date = \"2026-01-01\"\n",
    )
    .unwrap();

    // No store directories: the legacy tables load unchanged.
    let legacy = read_config(dir).unwrap();
    assert_eq!(legacy.default_config().columns, ["todo", "done"]);
    assert!(legacy.cycles.contains_key("Cycle 1"));
    assert!(!dir.join("docs/boards").exists());
    assert!(!dir.join("docs/cycles").exists());

    // With files present, the files win and the tables are ignored.
    fs::create_dir_all(dir.join("docs/boards")).unwrap();
    fs::write(
        dir.join("docs/boards/default.md"),
        "---\nname: default\ncolumns:\n- a\n- b\ndone_column: b\n---\n\n",
    )
    .unwrap();
    fs::create_dir_all(dir.join("docs/cycles")).unwrap();
    fs::write(
        dir.join("docs/cycles/q1.md"),
        "---\nname: q1\nstart_date: 2026-03-01\ndue_date: 2026-03-14\n---\n\n",
    )
    .unwrap();

    let files = read_config(dir).unwrap();
    assert_eq!(files.default_config().columns, ["a", "b"]);
    assert!(files.cycles.contains_key("q1"));
    assert!(files.cycles.contains_key("Default"), "implicit Default");
    assert!(
        !files.cycles.contains_key("Cycle 1"),
        "legacy cycles are ignored when the file store exists"
    );
}

/// OpenSpec change `issue-mentions`, task 3.1: a `tix.toml` with no
/// `[mentions]` section loads as **enabled with the default directory**, and
/// saving it writes nothing new — so no existing repository gains a key, and
/// the feature is on by default.
#[test]
fn mentions_default_to_enabled_and_save_byte_identically_without_the_section() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    let legacy = "issues_dir = \"docs/issues\"\n\n\
        [kanban.legacy]\n\
        columns = [\n    \"backlog\",\n    \"doing\",\n    \"review\",\n    \"shipped\",\n]\n\
        done_column = \"shipped\"\n";
    let path = dir.join("tix.toml");
    fs::write(&path, legacy).unwrap();

    let cfg = read_config(dir).unwrap();
    assert!(
        cfg.mentions.enabled,
        "mentions are on when the section is absent"
    );
    assert_eq!(cfg.mentions.dir, std::path::PathBuf::from("docs/mentions"));
    assert!(cfg.mentions.is_default());

    cfg.save(&path).unwrap();
    assert_eq!(
        fs::read_to_string(&path).unwrap(),
        legacy,
        "an absent [mentions] section must not be written back"
    );
}

/// An explicit `[mentions]` section is honoured and round-trips.
#[test]
fn an_explicit_mentions_section_is_read() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    // The canonical form `tix` writes, so the save below is a fixed point.
    let text = "issues_dir = \"docs/issues\"\n\n\
        [kanban.default]\n\
        columns = [\n    \"todo\",\n    \"in progress\",\n    \"in review\",\n    \"done\",\n]\n\n\
        [mentions]\n\
        enabled = false\n\
        dir = \"meta/mentions\"\n";
    fs::write(dir.join("tix.toml"), text).unwrap();
    let cfg = read_config(dir).unwrap();
    assert!(!cfg.mentions.enabled);
    assert_eq!(cfg.mentions.dir, std::path::PathBuf::from("meta/mentions"));
    cfg.save(&dir.join("tix.toml")).unwrap();
    assert_eq!(fs::read_to_string(dir.join("tix.toml")).unwrap(), text);
}

/// `#1415`: a legacy `tix.toml` whose board omits the display/ordering keys must
/// save **byte-identically**, so an ordinary command that writes the config
/// never rewrites the user's file with six keys they did not write (plus an
/// empty `[export]`).
///
/// The fixture is in `toml`'s pretty form — `tix` may reformat a hand-written
/// file on its first save, but from the canonical form on it must be a fixed
/// point. `done_column` is set explicitly because a board whose columns omit
/// `done` must name one; it is not the default (`done`), so it stays.
#[test]
fn legacy_config_round_trips_byte_identically_on_save() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    let legacy = "issues_dir = \"docs/issues\"\n\n\
        [kanban.legacy]\n\
        columns = [\n    \"backlog\",\n    \"doing\",\n    \"review\",\n    \"shipped\",\n]\n\
        done_column = \"shipped\"\n";
    let path = dir.join("tix.toml");
    fs::write(&path, legacy).unwrap();

    let cfg = read_config(dir).unwrap();
    // Behavior comes from the values those omitted keys stand for.
    assert_eq!(
        cfg.default_config().columns,
        ["backlog", "doing", "review", "shipped"]
    );
    assert_eq!(
        cfg.default_config().effective_done_column(),
        Some("shipped")
    );
    assert_eq!(
        cfg.default_config().order_by,
        tix::config::OrderBy::CreatedAtDesc
    );

    cfg.save(&path).unwrap();
    let on_disk = fs::read_to_string(&path).unwrap();
    assert_eq!(
        on_disk, legacy,
        "a legacy tix.toml must save byte-identically"
    );

    // And the saved bytes reload to the same behavior.
    let reloaded = read_config(dir).unwrap();
    assert_eq!(
        reloaded.default_config().columns,
        cfg.default_config().columns
    );
    assert_eq!(
        reloaded.default_config().effective_done_column(),
        Some("shipped")
    );
    assert_eq!(
        reloaded.default_config().order_by,
        cfg.default_config().order_by
    );
}