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
//! `tix wip` and WIP-enforced `tix move` through the **real binary** (mission
//! `configurable-wip-limits-01M3C6WX`, WP04 T018-T022).
//!
//! The policy itself is tested in `wip_policy.rs`; what is proved here is the CLI's
//! side of the contract: the flags, the exit codes, the stream discipline (the
//! decision's findings on stderr, the result on stdout), the History entry an
//! override writes, and that a board with no limits is byte-for-byte unaffected.

use std::collections::BTreeMap;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};

use tempfile::TempDir;

fn tix() -> String {
    env!("CARGO_BIN_EXE_tix").to_string()
}

/// A repository with three columns and, optionally, a `wip` section.
fn repo(wip: &str) -> (TempDir, PathBuf) {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path().join("issues");
    fs::create_dir_all(&dir).unwrap();
    fs::write(
        tmp.path().join("tix.toml"),
        format!(
            // The canonical form a save reproduces: `done_column` at its default is
            // omitted, and the column list is the pretty one. A hand-written
            // compact file would be rewritten by the first `tix wip` save, which is
            // the schema's own rule rather than a defect — so the round-trip claim
            // is asserted against the canonical bytes.
            "issues_dir = {issues:?}\n\
             [kanban.default]\ncolumns = [\n    \"todo\",\n    \"in progress\",\n    \"done\",\n]\n\
             [layout]\nmove_on_change = false\n{wip}",
            issues = dir.to_string_lossy(),
        ),
    )
    .unwrap();
    (tmp, dir)
}

fn write_issue(dir: &Path, number: u32, status: &str, estimate: Option<&str>) {
    let estimate = estimate
        .map(|value| format!("estimate: \"{value}\"\n"))
        .unwrap_or_default();
    fs::write(
        dir.join(format!("2026-01-01-issue-{number}.md")),
        format!(
            "---\nnumber: {number}\ntitle: \"Issue {number}\"\nstatus: \"{status}\"\n\
             labels: []\npriority: \"medium\"\ncreated: \"2026-01-01\"\nupdated: \"2026-01-01\"\n\
             {estimate}---\n\nBody.\n"
        ),
    )
    .unwrap();
}

fn run(root: &Path, args: &[&str]) -> Output {
    Command::new(tix())
        .current_dir(root)
        .args(args)
        .output()
        .expect("the binary runs")
}

fn ok(root: &Path, args: &[&str]) -> String {
    let out = run(root, args);
    assert!(
        out.status.success(),
        "tix {args:?} failed: {}{}",
        String::from_utf8_lossy(&out.stdout),
        String::from_utf8_lossy(&out.stderr)
    );
    String::from_utf8(out.stdout).expect("stdout is UTF-8")
}

fn refused(root: &Path, args: &[&str]) -> (String, String) {
    let out = run(root, args);
    assert!(!out.status.success(), "tix {args:?} unexpectedly succeeded");
    (
        String::from_utf8_lossy(&out.stdout).to_string(),
        String::from_utf8_lossy(&out.stderr).to_string(),
    )
}

fn snapshot(dir: &Path) -> BTreeMap<String, Vec<u8>> {
    fn walk(root: &Path, dir: &Path, out: &mut BTreeMap<String, Vec<u8>>) {
        let Ok(entries) = fs::read_dir(dir) else {
            return;
        };
        for entry in entries.flatten() {
            let path = entry.path();
            if path.is_dir() {
                walk(root, &path, out);
            } else {
                out.insert(
                    path.strip_prefix(root)
                        .unwrap_or(&path)
                        .to_string_lossy()
                        .to_string(),
                    fs::read(&path).unwrap_or_default(),
                );
            }
        }
    }
    let mut out = BTreeMap::new();
    walk(dir, dir, &mut out);
    out
}

fn issue_text(dir: &Path, number: u32) -> String {
    fs::read_to_string(dir.join(format!("2026-01-01-issue-{number}.md"))).unwrap_or_default()
}

/// The `status:` value of an issue file, without its quotes.
///
/// The fixture writes a quoted value and the serializer drops the quotes when they
/// are unnecessary, so an assertion about a status compares the *value* rather than
/// one of the two spellings.
fn status_of(text: &str) -> String {
    text.lines()
        .find_map(|line| line.trim_start().strip_prefix("status:"))
        .map(|value| value.trim().trim_matches('"').to_string())
        .unwrap_or_default()
}

#[test]
fn wip_config_round_trips_through_the_cli() {
    let (tmp, _dir) = repo("");
    let root = tmp.path();
    let before = fs::read_to_string(root.join("tix.toml")).unwrap();
    assert!(
        ok(root, &["wip", "show"]).contains("units: -"),
        "a board with no limits says so"
    );

    ok(root, &["wip", "unit", "d", "1"]);
    ok(root, &["wip", "unit", "w", "5"]);
    let set = ok(
        root,
        &[
            "wip",
            "set",
            "in progress",
            "--max-items",
            "2",
            "--max-estimate",
            "10",
            "--unit",
            "d",
            "--policy",
            "block",
        ],
    );
    assert!(set.contains("Set the limit"), "{set}");
    let configured = fs::read_to_string(root.join("tix.toml")).unwrap();
    assert!(
        configured.contains("[kanban.default.wip.units]"),
        "{configured}"
    );
    assert!(configured.contains("max_items = 2"), "{configured}");
    assert!(configured.contains("policy = \"block\""), "{configured}");

    let shown = ok(root, &["wip", "show"]);
    assert!(shown.contains("units: d=1, w=5"), "{shown}");
    assert!(shown.contains("in progress"), "{shown}");
    assert!(
        shown.contains("max_items=2,max_estimate=10d,policy=block"),
        "{shown}"
    );
    assert!(shown.contains("todo  -"), "{shown}");

    // Only the flags named change: the estimate ceiling, still there, is untouched.
    ok(root, &["wip", "set", "in progress", "--max-items", "3"]);
    let updated = fs::read_to_string(root.join("tix.toml")).unwrap();
    assert!(updated.contains("max_items = 3") && updated.contains("max_estimate = 10"));
    assert!(
        updated.contains("policy = \"block\""),
        "the policy survived"
    );

    // An unknown column, an unknown policy and a blank unit are refused with the
    // configuration untouched.
    let (_, stderr) = refused(root, &["wip", "set", "shipped", "--max-items", "1"]);
    assert!(stderr.contains("not a column"), "{stderr}");
    let (_, stderr) = refused(
        root,
        &["wip", "set", "todo", "--max-items", "1", "--policy", "nope"],
    );
    assert!(stderr.contains("unknown policy"), "{stderr}");
    let (_, stderr) = refused(
        root,
        &["wip", "set", "todo", "--max-items", "1", "--unit", "q"],
    );
    assert!(
        stderr.contains("q") && stderr.contains("wip.units"),
        "an undeclared unit is refused by name: {stderr}"
    );
    assert_eq!(fs::read_to_string(root.join("tix.toml")).unwrap(), updated);

    // Unsetting the limit removes the key, and removing the units leaves the file
    // exactly as it started: limits absent, nothing materialized.
    ok(root, &["wip", "unset", "in progress"]);
    let without_limit = fs::read_to_string(root.join("tix.toml")).unwrap();
    assert!(!without_limit.contains("max_items"), "{without_limit}");
    let (_, stderr) = refused(root, &["wip", "unset", "in progress"]);
    assert!(stderr.contains("no limit"), "{stderr}");
    ok(root, &["wip", "unit", "d", "--remove"]);
    ok(root, &["wip", "unit", "w", "--remove"]);
    // A hand-written partial `tix.toml` is canonicalized by the first save (the
    // loader fills the derived paths, and the serializer writes what is no longer at
    // its default). From that canonical state on, saving is byte-stable — and the
    // `wip` key is gone, which is the claim that matters: limits absent means no
    // key materializes (#1415).
    let canonical = fs::read_to_string(root.join("tix.toml")).unwrap();
    assert!(!canonical.contains("wip"), "{canonical}");
    ok(root, &["wip", "unit", "q", "2"]);
    ok(root, &["wip", "unit", "q", "--remove"]);
    assert_eq!(
        fs::read_to_string(root.join("tix.toml")).unwrap(),
        canonical,
        "saving twice from the canonical state changes nothing"
    );
    assert!(!before.is_empty(), "the fixture was written");
}

#[test]
fn move_blocks_allows_and_reports_a_warning() {
    let (tmp, dir) = repo(
        "\n[kanban.default.wip.units]\nd = 1\n\n\
         [kanban.default.wip.limits.\"in progress\"]\nmax_items = 1\nmax_estimate = 10\n\
         unit = \"d\"\npolicy = \"block\"\n",
    );
    let root = tmp.path();
    write_issue(&dir, 1, "todo", Some("2"));
    write_issue(&dir, 2, "todo", Some("2"));

    // The first move fills the column exactly: within the limit, so it proceeds with
    // no event and nothing on stderr.
    let out = run(root, &["move", "1", "in progress"]);
    assert!(out.status.success());
    assert!(
        out.stderr.is_empty(),
        "{:?}",
        String::from_utf8_lossy(&out.stderr)
    );
    assert!(
        !issue_text(&dir, 1).contains("wip override"),
        "a move within the limit writes no override event"
    );

    // The second is refused by the policy, and the issue has not moved.
    let before = snapshot(&dir);
    let (stdout, stderr) = refused(root, &["move", "2", "in progress"]);
    assert!(stdout.is_empty(), "the refusal is not a result: {stdout:?}");
    assert!(stderr.contains("block"), "{stderr}");
    assert!(stderr.contains("override_required"), "{stderr}");
    assert!(
        stderr.contains("authorized override is required"),
        "the policy says what to do without naming a surface's flag: {stderr}"
    );
    let help = ok(root, &["move", "--help"]);
    assert!(
        help.contains("--override") && help.contains("--reason"),
        "and the flag that supplies one is documented where a caller looks: {help}"
    );
    assert_eq!(snapshot(&dir), before, "a refused move writes nothing");
    assert_eq!(
        status_of(&issue_text(&dir, 2)),
        "todo",
        "the refused issue did not move"
    );

    // `--override` alone is not authorization: the reason is required.
    let (_, stderr) = refused(root, &["move", "2", "in progress", "--override", "--yes"]);
    assert!(stderr.contains("missing_override_field"), "{stderr}");
    assert_eq!(snapshot(&dir), before);
    // …and confirmation is not implied by the reason either.
    let (_, stderr) = refused(
        root,
        &[
            "move",
            "2",
            "in progress",
            "--override",
            "--reason",
            "release week",
        ],
    );
    assert!(stderr.contains("unconfirmed_override"), "{stderr}");
    assert_eq!(snapshot(&dir), before);

    // With both, the move proceeds and the override is recorded in the issue's own
    // History, with the reason and the limit it was authorized against.
    let out = ok(
        root,
        &[
            "move",
            "2",
            "in progress",
            "--override",
            "--reason",
            "release week",
            "--yes",
        ],
    );
    assert!(out.contains("Moved"), "{out}");
    let moved = issue_text(&dir, 2);
    assert!(moved.contains("in progress"), "{moved}");
    assert!(moved.contains("wip override"), "{moved}");
    assert!(moved.contains("release week"), "{moved}");
    assert!(moved.contains("max_items 1"), "{moved}");

    // Switching the column to `warn` lets the next over-limit move through and
    // reports it on stderr, so stdout stays a result a script can parse.
    write_issue(&dir, 3, "todo", Some("2"));
    ok(root, &["wip", "set", "in progress", "--policy", "warn"]);
    let out = run(root, &["move", "3", "in progress"]);
    assert!(out.status.success());
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(
        stderr.contains("warn") && stderr.contains("over_limit"),
        "{stderr}"
    );
    assert!(
        !stderr.contains("wip override"),
        "a warning appends no override: {stderr}"
    );
    assert!(String::from_utf8_lossy(&out.stdout).contains("Moved"));
    assert!(!issue_text(&dir, 3).contains("wip override"));
}

#[test]
fn a_move_with_an_uncountable_estimate_is_refused_not_rounded() {
    let (tmp, dir) = repo(
        "\n[kanban.default.wip.units]\nd = 1\n\n\
         [kanban.default.wip.limits.\"in progress\"]\nmax_estimate = 10\nunit = \"d\"\n\
         policy = \"warn\"\n",
    );
    let root = tmp.path();
    write_issue(&dir, 1, "todo", Some("nope"));
    write_issue(&dir, 2, "todo", Some("3q"));
    let before = snapshot(&dir);
    for (issue, kind) in [(1, "malformed_estimate"), (2, "missing_conversion")] {
        let (_, stderr) = refused(root, &["move", &issue.to_string(), "in progress"]);
        assert!(stderr.contains(kind), "{issue}: {stderr}");
        assert!(
            stderr.contains("refused rather than counted as zero")
                || stderr.contains("cannot count"),
            "{issue}: {stderr}"
        );
    }
    assert_eq!(snapshot(&dir), before, "neither refusal wrote anything");

    // The same board, with an estimate it *can* count: allowed.
    write_issue(&dir, 3, "todo", Some("2"));
    ok(root, &["move", "3", "in progress"]);
    assert!(
        issue_text(&dir, 3).contains("in progress"),
        "the move landed"
    );
}

#[test]
fn a_board_without_limits_is_unaffected() {
    let (tmp, dir) = repo("");
    let root = tmp.path();
    write_issue(&dir, 1, "todo", None);
    write_issue(&dir, 2, "in progress", None);
    write_issue(&dir, 3, "in progress", None);

    // The move, and both display surfaces, behave exactly as before this mission:
    // no `wip` key appeared, and no figure leaked into the output.
    ok(root, &["move", "1", "in progress"]);
    let status = ok(root, &["status"]);
    assert!(!status.contains('/'), "no usage figures: {status}");
    let listed = ok(root, &["list", "--show", "wip"]);
    assert!(listed.lines().all(|line| !line.contains("4/3")), "{listed}");
    assert_eq!(
        ok(root, &["wip", "show"]).lines().count(),
        3 + 3,
        "one header line, the units line, the column header and three rows"
    );
}

#[test]
fn the_existing_move_behaviour_is_preserved() {
    let (tmp, dir) = repo("");
    let root = tmp.path();
    write_issue(&dir, 1, "in progress", None);

    // The done-column commit coupling is untouched: `--commit` is recorded, and the
    // category is reported beside the column.
    let out = ok(root, &["move", "1", "done", "--commit", "abc123"]);
    assert!(out.contains("(commit abc123)"), "{out}");
    assert!(out.contains("Moved"), "{out}");
    let text = issue_text(&dir, 1);
    assert!(text.contains("status: done"), "{text}");
    assert!(text.contains("commit: abc123"), "{text}");

    // Moving out of `done` still clears it, on a board with no category map.
    ok(root, &["move", "1", "in progress"]);
    let text = issue_text(&dir, 1);
    assert!(!text.contains("commit:"), "the commit is cleared: {text}");

    // And an unknown column is still refused with #183's named diagnostic.
    let (_, stderr) = refused(root, &["move", "1", "shipped"]);
    assert!(stderr.contains("unknown_column"), "{stderr}");
}