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
//! Integration tests for `tix init-agents`, driven through the compiled
//! binary only. Each test runs in a fresh temp dir standing in for the repo
//! root (AGENTS.md is written there, no tix.toml required).

use std::fs;
use std::path::Path;
use std::process::Output;

use assert_cmd::Command;
use tempfile::TempDir;

const MARKER_START: &str = "<!-- tix:start -->";
const MARKER_END: &str = "<!-- tix:end -->";

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

fn run_in(dir: &Path) -> Output {
    tix().current_dir(dir).arg("init-agents").output().unwrap()
}

fn read_agents(dir: &Path) -> String {
    fs::read_to_string(dir.join("AGENTS.md")).unwrap()
}

/// The block `tix init-agents` must write with no framework detected.
///
/// **Derived from the library, not copied from it.** This file used to carry a
/// second, hand-maintained copy of the pre-mission block, and the batch surface
/// proved the cost on its first landing: adding `tix bulk` to the generated section
/// left this copy stale and three integration tests red — with the copy, not the code,
/// wrong. A test whose expectation is a second copy of the thing under test fails on
/// every legitimate change and passes on every illegitimate one.
///
/// What is actually being asserted here is that the **binary** writes what the
/// library builds. That is a real end-to-end claim (argument parsing, the marker
/// splice, the write) and it is the only thing an integration test can check. The
/// guard against an *unintended* block change stays where it belongs: the inline
/// golden in `commands::agents::tests::build_section_none_matches_golden_pre_mission_block`,
/// which is compared against the builder and is updated deliberately.
fn golden_block() -> String {
    tix::commands::agents::build_section(tix::commands::agents::Detected::NONE)
}

const DOGFOODING_HEADING: &str = "### Tracking Spec Kitty tasks with tix";
const OPENSPEC_HEADING: &str = "### Tracking OpenSpec work with tix";
const SPEC_KIT_HEADING: &str = "### Tracking Spec Kit work with tix";

#[test]
fn missing_file_is_created_and_rerun_is_idempotent() {
    let tmp = TempDir::new().unwrap();
    assert!(!tmp.path().join("AGENTS.md").exists());

    let first = run_in(tmp.path());
    assert!(
        first.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&first.stderr)
    );
    let stdout = String::from_utf8_lossy(&first.stdout).to_string();
    assert!(stdout.contains("Created"), "stdout: {stdout}");

    let once = read_agents(tmp.path());
    assert!(once.contains(MARKER_START), "missing start marker: {once}");
    assert!(once.contains(MARKER_END), "missing end marker: {once}");
    assert!(once.contains("tix list"));
    assert!(once.contains("tix create"));
    assert!(once.contains("tix export"));
    // grouped-layout documentation (IC-06 / C-009): tix create defaults the
    // assignee from git, lands in an assignee segment, and plain files go to
    // unassigned/. `tix edit --assignee` moves the file between segments.
    assert!(
        once.contains("docs/issues/<assignee>/"),
        "missing grouped-layout path: {once}"
    );
    assert!(
        once.contains("unassigned/"),
        "missing unassigned fallback: {once}"
    );
    assert!(
        once.contains("--assignee"),
        "missing --assignee semantics: {once}"
    );
    assert!(
        once.contains("git"),
        "missing git-identity default note: {once}"
    );

    let second = run_in(tmp.path());
    assert!(second.status.success());
    let twice = read_agents(tmp.path());
    assert_eq!(once, twice, "re-run must not change AGENTS.md");
    assert_eq!(twice.matches(MARKER_START).count(), 1, "duplicated block");
}

#[test]
fn unrelated_content_outside_markers_is_byte_preserved() {
    let tmp = TempDir::new().unwrap();
    let before = "line one\nline two\n";
    let after = "\nline three\n";
    let old_block = format!("{MARKER_START}\nstale block\n{MARKER_END}");
    fs::write(
        tmp.path().join("AGENTS.md"),
        format!("{before}{old_block}{after}"),
    )
    .unwrap();

    let out = run_in(tmp.path());
    assert!(out.status.success());
    let updated = read_agents(tmp.path());
    assert!(
        updated.starts_with(before),
        "before region changed: {updated}"
    );
    assert!(updated.ends_with(after), "after region changed: {updated}");
    assert!(!updated.contains("stale block"), "old block not replaced");
    assert_eq!(updated.matches(MARKER_START).count(), 1);

    let rerun = run_in(tmp.path());
    assert!(rerun.status.success());
    assert_eq!(read_agents(tmp.path()), updated, "re-run not idempotent");
}

#[test]
fn half_marker_file_is_appended_without_touching_original() {
    let tmp = TempDir::new().unwrap();
    let original = "some weird text <!-- tix:start --> that is incomplete\n";
    fs::write(tmp.path().join("AGENTS.md"), original).unwrap();

    let out = run_in(tmp.path());
    assert!(out.status.success());
    let updated = read_agents(tmp.path());
    assert!(
        updated.starts_with(original),
        "original content must be preserved: {updated}"
    );
    assert_eq!(
        updated.matches(MARKER_START).count(),
        2,
        "expected original + one appended block, got: {updated}"
    );
    assert_eq!(updated.matches(MARKER_END).count(), 1);
}

// T021 — spec-kitty detection + idempotency tests ------------------------------------

#[test]
fn kittify_present_includes_dogfooding_section() {
    let tmp = TempDir::new().unwrap();
    fs::create_dir_all(tmp.path().join(".kittify")).unwrap();

    let out = run_in(tmp.path());
    assert!(
        out.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&out.stderr)
    );

    let block = read_agents(tmp.path());
    assert!(
        block.contains(DOGFOODING_HEADING),
        "missing dogfooding heading"
    );
    assert!(block.contains("Filing a Spec Kitty task/work package"));
    assert!(block.contains("Opening an issue"));
    assert!(block.contains("Marking a task done"));
    assert!(block.contains("Commenting on a task issue"));
    assert_eq!(block.matches(MARKER_START).count(), 1);
    assert_eq!(block.matches(MARKER_END).count(), 1);
}

#[test]
fn no_kittify_omits_dogfooding_section() {
    let tmp = TempDir::new().unwrap();
    assert!(!tmp.path().join(".kittify").exists());
    assert!(!tmp.path().join("openspec").exists());

    let out = run_in(tmp.path());
    assert!(out.status.success());

    let block = read_agents(tmp.path());
    assert!(
        !block.contains(DOGFOODING_HEADING),
        "dogfooding section must not appear without .kittify/"
    );
    assert!(
        !block.contains(OPENSPEC_HEADING),
        "openspec section must not appear without openspec/"
    );
    assert!(
        !block.contains(SPEC_KIT_HEADING),
        "spec-kit section must not appear without .specify/"
    );
    assert_eq!(block.trim(), golden_block());
}

#[test]
fn openspec_present_includes_openspec_section() {
    let tmp = TempDir::new().unwrap();
    fs::create_dir_all(tmp.path().join("openspec")).unwrap();
    assert!(!tmp.path().join(".kittify").exists());

    let out = run_in(tmp.path());
    assert!(
        out.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&out.stderr)
    );

    let block = read_agents(tmp.path());
    assert!(block.contains(OPENSPEC_HEADING), "missing openspec heading");
    assert!(block.contains("`openspec/`"));
    assert!(block.contains("--labels openspec"));
    assert!(block.contains("Opening an issue"));
    assert!(
        !block.contains(DOGFOODING_HEADING),
        "spec-kitty section must not appear without .kittify/"
    );
    assert!(
        !block.contains(SPEC_KIT_HEADING),
        "spec-kit section must not appear without .specify/"
    );
    assert_eq!(block.matches(MARKER_START).count(), 1);
    assert_eq!(block.matches(MARKER_END).count(), 1);
}

#[test]
fn spec_kit_present_includes_spec_kit_section() {
    let tmp = TempDir::new().unwrap();
    fs::create_dir_all(tmp.path().join(".specify")).unwrap();
    assert!(!tmp.path().join(".kittify").exists());
    assert!(!tmp.path().join("openspec").exists());

    let out = run_in(tmp.path());
    assert!(
        out.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&out.stderr)
    );

    let block = read_agents(tmp.path());
    assert!(block.contains(SPEC_KIT_HEADING), "missing spec-kit heading");
    assert!(block.contains("`.specify/`"));
    assert!(block.contains("--labels speckit"));
    assert!(block.contains("Opening an issue"));
    assert!(
        !block.contains(DOGFOODING_HEADING),
        "spec-kitty section must not appear without .kittify/"
    );
    assert!(
        !block.contains(OPENSPEC_HEADING),
        "openspec section must not appear without openspec/"
    );
    assert_eq!(block.matches(MARKER_START).count(), 1);
    assert_eq!(block.matches(MARKER_END).count(), 1);
}

#[test]
fn all_three_frameworks_include_all_sections_in_order() {
    let tmp = TempDir::new().unwrap();
    fs::create_dir_all(tmp.path().join(".kittify")).unwrap();
    fs::create_dir_all(tmp.path().join("openspec")).unwrap();
    fs::create_dir_all(tmp.path().join(".specify")).unwrap();

    let out = run_in(tmp.path());
    assert!(
        out.status.success(),
        "stderr: {}",
        String::from_utf8_lossy(&out.stderr)
    );

    let block = read_agents(tmp.path());
    let kitty = block.find(DOGFOODING_HEADING).unwrap();
    let openspec = block.find(OPENSPEC_HEADING).unwrap();
    let spec_kit = block.find(SPEC_KIT_HEADING).unwrap();
    assert!(
        kitty < openspec && openspec < spec_kit,
        "sections must appear Spec Kitty, OpenSpec, Spec Kit"
    );
    assert_eq!(block.matches(DOGFOODING_HEADING).count(), 1);
    assert_eq!(block.matches(OPENSPEC_HEADING).count(), 1);
    assert_eq!(block.matches(SPEC_KIT_HEADING).count(), 1);
    // The detection report names each marker dir, once, in the same order.
    let stdout = String::from_utf8_lossy(&out.stdout);
    let kitty_line = stdout.find("Detected Spec Kitty (via .kittify/)").unwrap();
    let openspec_line = stdout.find("Detected OpenSpec (via openspec/)").unwrap();
    let spec_kit_line = stdout.find("Detected Spec Kit (via .specify/)").unwrap();
    assert!(kitty_line < openspec_line && openspec_line < spec_kit_line);
}

#[test]
fn committed_agents_block_matches_the_current_binary() {
    let root = Path::new(env!("CARGO_MANIFEST_DIR"));
    let agents = fs::read_to_string(root.join("AGENTS.md")).expect("repo AGENTS.md");
    let start = agents.find(MARKER_START).expect("tix start marker");
    let end = agents.find(MARKER_END).expect("tix end marker") + MARKER_END.len();
    let committed = &agents[start..end];
    let expected = tix::commands::agents::build_section(tix::commands::agents::detect(root));

    assert_eq!(
        committed, expected,
        "the committed tix block is stale; run `tix init-agents`"
    );
}

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

    // Create with .specify/ present.
    fs::create_dir_all(tmp.path().join(".specify")).unwrap();
    let _ = run_in(tmp.path());
    let with_section = read_agents(tmp.path());
    assert!(with_section.contains(SPEC_KIT_HEADING));

    // Remove .specify/ and re-run: section must disappear.
    fs::remove_dir_all(tmp.path().join(".specify")).unwrap();
    let _ = run_in(tmp.path());
    let without = read_agents(tmp.path());
    assert!(
        !without.contains(SPEC_KIT_HEADING),
        "stale spec-kit section after .specify/ removal"
    );
    assert_eq!(without.trim(), golden_block());

    // Re-create .specify/ and re-run: section must return, no duplication.
    fs::create_dir_all(tmp.path().join(".specify")).unwrap();
    let _ = run_in(tmp.path());
    let back_again = read_agents(tmp.path());
    assert!(back_again.contains(SPEC_KIT_HEADING));
    assert_eq!(
        back_again.matches(SPEC_KIT_HEADING).count(),
        1,
        "duplicated spec-kit section after flip"
    );
    assert_eq!(back_again.matches(MARKER_START).count(), 1);
    assert_eq!(back_again.matches(MARKER_END).count(), 1);
}

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

    // Create with openspec/ present.
    fs::create_dir_all(tmp.path().join("openspec")).unwrap();
    let _ = run_in(tmp.path());
    let with_section = read_agents(tmp.path());
    assert!(with_section.contains(OPENSPEC_HEADING));

    // Remove openspec/ and re-run: section must disappear.
    fs::remove_dir_all(tmp.path().join("openspec")).unwrap();
    let _ = run_in(tmp.path());
    let without = read_agents(tmp.path());
    assert!(
        !without.contains(OPENSPEC_HEADING),
        "stale openspec section after openspec/ removal"
    );
    assert_eq!(without.trim(), golden_block());

    // Re-create openspec/ and re-run: section must return, no duplication.
    fs::create_dir_all(tmp.path().join("openspec")).unwrap();
    let _ = run_in(tmp.path());
    let back_again = read_agents(tmp.path());
    assert!(back_again.contains(OPENSPEC_HEADING));
    assert_eq!(
        back_again.matches(OPENSPEC_HEADING).count(),
        1,
        "duplicated openspec section after flip"
    );
    assert_eq!(back_again.matches(MARKER_START).count(), 1);
    assert_eq!(back_again.matches(MARKER_END).count(), 1);
}

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

    // Create with .kittify/ present.
    fs::create_dir_all(tmp.path().join(".kittify")).unwrap();
    let _ = run_in(tmp.path());
    let with_section = read_agents(tmp.path());
    assert!(with_section.contains(DOGFOODING_HEADING));

    // Remove .kittify/ and re-run: section must disappear.
    fs::remove_dir_all(tmp.path().join(".kittify")).unwrap();
    let _ = run_in(tmp.path());
    let without = read_agents(tmp.path());
    assert!(
        !without.contains(DOGFOODING_HEADING),
        "stale dogfooding section after .kittify/ removal"
    );
    assert_eq!(without.trim(), golden_block());

    // Re-create .kittify/ and re-run: section must return, no duplication.
    fs::create_dir_all(tmp.path().join(".kittify")).unwrap();
    let _ = run_in(tmp.path());
    let back_again = read_agents(tmp.path());
    assert!(back_again.contains(DOGFOODING_HEADING));
    assert_eq!(
        back_again.matches(DOGFOODING_HEADING).count(),
        1,
        "duplicated dogfooding section after flip"
    );
    assert_eq!(back_again.matches(MARKER_START).count(), 1);
    assert_eq!(back_again.matches(MARKER_END).count(), 1);
}

#[test]
fn double_run_prints_already_up_to_date() {
    let tmp = TempDir::new().unwrap();
    fs::create_dir_all(tmp.path().join(".kittify")).unwrap();

    let first = run_in(tmp.path());
    assert!(first.status.success());
    let stdout = String::from_utf8_lossy(&first.stdout);
    assert!(stdout.contains("Created"));

    let second = run_in(tmp.path());
    assert!(second.status.success());
    let stdout = String::from_utf8_lossy(&second.stdout);
    assert!(
        stdout.contains("already up to date"),
        "expected already-up-to-date message, got: {stdout}"
    );
}