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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
//! End-to-end CLI contract tests for `tix initiative` and `tix roadmap`
//! (mission `roadmap-initiatives-01M3C8SX`, WP04; FR-001–FR-005, C-001–C-008).
//!
//! Driven through the compiled binary only — never through library calls — the
//! same discipline `tests/cli.rs` follows. Every no-partial-write assertion
//! snapshots `tix.toml` byte-for-byte: an exit code is not evidence that nothing
//! was written.

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

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

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

/// The registry file's exact bytes.
fn registry_bytes(dir: &Path) -> String {
    fs::read_to_string(dir.join("tix.toml")).expect("tix.toml")
}

/// The stable id from a `... (<id>)` announcement line.
fn parse_id(stdout: &[u8]) -> String {
    let stdout = String::from_utf8(stdout.to_vec()).unwrap();
    let open = stdout.rfind('(').expect("a parenthesised id");
    let close = stdout.rfind(')').expect("a closing parenthesis");
    stdout[open + 1..close].to_string()
}

/// `tix initiative create <name> [extra…]` and the allocated id it prints.
fn initiative_create(dir: &Path, name: &str, extra: &[&str]) -> String {
    let out = tix()
        .current_dir(dir)
        .args(["initiative", "create", name])
        .args(extra)
        .assert()
        .success()
        .get_output()
        .stdout
        .clone();
    parse_id(&out)
}

/// One `tix …` invocation's stdout.
fn stdout_of(dir: &Path, args: &[&str]) -> String {
    let out = tix()
        .current_dir(dir)
        .args(args)
        .assert()
        .success()
        .get_output()
        .stdout
        .clone();
    String::from_utf8(out).unwrap()
}

/// `tix roadmap list [args…]` rows as `(id, name, target date, summary state)`.
///
/// A header row has exactly four tab-separated columns; the optional `filter:`
/// context line and the indented contribution/diagnostic lines are skipped.
fn roadmap_rows(dir: &Path, args: &[&str]) -> Vec<(String, String, String, String)> {
    let mut full: Vec<&str> = vec!["roadmap", "list"];
    full.extend_from_slice(args);
    stdout_of(dir, &full)
        .lines()
        .filter(|line| line.split('\t').count() == 4)
        .map(|line| {
            let mut fields = line.split('\t');
            (
                fields.next().unwrap().to_string(),
                fields.next().unwrap().to_string(),
                fields.next().unwrap().to_string(),
                fields.next().unwrap().to_string(),
            )
        })
        .collect()
}

/// `tix initiative list` rows as `(id, name, target date, status)`.
fn initiative_rows(dir: &Path) -> Vec<(String, String, String, String)> {
    stdout_of(dir, &["initiative", "list"])
        .lines()
        .map(|line| {
            let mut fields = line.split('\t');
            (
                fields.next().unwrap().to_string(),
                fields.next().unwrap().to_string(),
                fields.next().unwrap().to_string(),
                fields.next().unwrap().to_string(),
            )
        })
        .collect()
}

/// `tix initiative create <name>` with no extra flags.
fn create_named(dir: &Path, name: &str) -> String {
    initiative_create(dir, name, &[])
}

// ---------------------------------------------------------------------------
// Initiative lifecycle
// ---------------------------------------------------------------------------

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

    let id = initiative_create(
        dir,
        "Platform",
        &[
            "--outcome",
            "Ship the platform",
            "--owner",
            "alice",
            "--status",
            "active",
            "--priority",
            "high",
            "--labels",
            "core,infra",
            "--target-date",
            "2026-03-01",
        ],
    );

    // The listing shows the id, the name and the scan metadata.
    let rows = initiative_rows(dir);
    assert_eq!(
        rows,
        vec![(
            id.clone(),
            "Platform".to_string(),
            "2026-03-01".to_string(),
            "active".to_string()
        )],
        "the id is a column of its own (C-002)"
    );

    // `show` round-trips every field just written.
    let shown = stdout_of(dir, &["initiative", "show", &id]);
    assert!(shown.contains(&format!("id: {id}")), "{shown}");
    assert!(shown.contains("name: Platform"), "{shown}");
    assert!(shown.contains("outcome: Ship the platform"), "{shown}");
    assert!(shown.contains("owner: alice"), "{shown}");
    assert!(shown.contains("status: active"), "{shown}");
    assert!(shown.contains("priority: high"), "{shown}");
    assert!(shown.contains("labels: core, infra"), "{shown}");
    assert!(shown.contains("target date: 2026-03-01"), "{shown}");

    // A second run of `list` reflects the on-disk record, not a cached value.
    let bytes = registry_bytes(dir);
    assert!(bytes.contains("[initiatives."), "{bytes}");
    assert!(bytes.contains(&format!("[initiatives.{id}]")), "{bytes}");
}

#[test]
fn cli_initiative_rename_keeps_the_id_and_every_association() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    tix().current_dir(dir).arg("init").assert().success();
    let id = create_named(dir, "Platform");
    let project = parse_id(
        tix()
            .current_dir(dir)
            .args(["project", "create", "Proj"])
            .assert()
            .success()
            .get_output()
            .stdout
            .as_slice(),
    );
    tix()
        .current_dir(dir)
        .args(["initiative", "associate", &id, "--project", &project])
        .assert()
        .success();

    tix()
        .current_dir(dir)
        .args(["initiative", "edit", &id, "--name", "Platform hardening"])
        .assert()
        .success();

    // The id is unchanged and still the key; only the label moved.
    let rows = initiative_rows(dir);
    assert_eq!(rows[0].0, id, "the id survives the rename (C-002)");
    assert_eq!(rows[0].1, "Platform hardening");
    let bytes = registry_bytes(dir);
    assert!(bytes.contains(&format!("[initiatives.{id}]")), "{bytes}");
    assert_eq!(
        bytes.matches("[initiatives.").count(),
        1,
        "the record was not re-keyed: {bytes}"
    );

    // The association survives the rename and is still visible on the roadmap row.
    let row = stdout_of(dir, &["roadmap", "show", &id]);
    assert!(row.contains(&format!("project:{project}")), "{row}");
}

#[test]
fn cli_initiative_associate_and_dereference_are_idempotent() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    tix().current_dir(dir).arg("init").assert().success();
    let id = create_named(dir, "Platform");

    // A well-formed reference that names nothing is stored, never refused (C-005).
    let first = tix()
        .current_dir(dir)
        .args([
            "initiative",
            "associate",
            &id,
            "--project",
            "p-0000000000000000",
        ])
        .assert()
        .success()
        .get_output()
        .stdout
        .clone();
    assert!(
        String::from_utf8_lossy(&first).contains("Associated"),
        "{first:?}"
    );
    let after_first = registry_bytes(dir);

    // A repeated association is an idempotent no-op that writes no bytes.
    let second = tix()
        .current_dir(dir)
        .args([
            "initiative",
            "associate",
            &id,
            "--project",
            "p-0000000000000000",
        ])
        .assert()
        .success()
        .get_output()
        .stdout
        .clone();
    assert!(
        String::from_utf8_lossy(&second).contains("Already associated"),
        "{second:?}"
    );
    assert_eq!(
        registry_bytes(dir),
        after_first,
        "the second associate writes nothing"
    );

    // Dereference removes it, and a repeated dereference is an idempotent no-op.
    let dropped = tix()
        .current_dir(dir)
        .args([
            "initiative",
            "dereference",
            &id,
            "--project",
            "p-0000000000000000",
        ])
        .assert()
        .success()
        .get_output()
        .stdout
        .clone();
    assert!(
        String::from_utf8_lossy(&dropped).contains("Dereferenced"),
        "{dropped:?}"
    );
    let after_drop = registry_bytes(dir);
    let again = tix()
        .current_dir(dir)
        .args([
            "initiative",
            "dereference",
            &id,
            "--project",
            "p-0000000000000000",
        ])
        .assert()
        .success()
        .get_output()
        .stdout
        .clone();
    assert!(
        String::from_utf8_lossy(&again).contains("Not associated"),
        "{again:?}"
    );
    assert_eq!(
        registry_bytes(dir),
        after_drop,
        "the second dereference writes nothing"
    );
}

#[test]
fn cli_initiative_association_requires_exactly_one_kind_flag() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    tix().current_dir(dir).arg("init").assert().success();
    let id = create_named(dir, "Platform");
    let before = registry_bytes(dir);

    let missing = tix()
        .current_dir(dir)
        .args(["initiative", "associate", &id])
        .assert()
        .failure()
        .get_output()
        .clone();
    assert!(
        String::from_utf8_lossy(&missing.stderr).contains("exactly one of `--project`"),
        "{:?}",
        missing.stderr
    );

    tix()
        .current_dir(dir)
        .args([
            "initiative",
            "associate",
            &id,
            "--project",
            "p-1",
            "--epic",
            "e-1",
        ])
        .assert()
        .failure()
        .stderr(predicate::str::contains("accepts only one of"));
    assert_eq!(
        registry_bytes(dir),
        before,
        "a refused associate writes nothing"
    );
}

#[test]
fn cli_initiative_edit_requires_a_field_and_writes_nothing_without_one() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    tix().current_dir(dir).arg("init").assert().success();
    let id = create_named(dir, "Platform");
    let before = registry_bytes(dir);
    tix()
        .current_dir(dir)
        .args(["initiative", "edit", &id])
        .assert()
        .failure()
        .stderr(predicate::str::contains("requires at least one field flag"));
    assert_eq!(
        registry_bytes(dir),
        before,
        "a no-field edit writes nothing"
    );
}

#[test]
fn cli_initiative_delete_removes_only_the_entry_and_reports_references() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    tix().current_dir(dir).arg("init").assert().success();
    let id = initiative_create(dir, "Platform", &["--target-date", "2026-03-01"]);
    tix()
        .current_dir(dir)
        .args(["initiative", "associate", &id, "--milestone", "2026-Q4"])
        .assert()
        .success();

    let out = tix()
        .current_dir(dir)
        .args(["initiative", "delete", &id, "--yes"])
        .assert()
        .success()
        .get_output()
        .stdout
        .clone();
    let out = String::from_utf8(out).unwrap();
    assert!(out.contains("Deleted initiative Platform"), "{out}");
    assert!(
        out.contains("milestones: 2026-Q4"),
        "the record's own references are reported: {out}"
    );

    // Only the registry entry is gone; a later list is empty and the roadmap is empty.
    assert!(initiative_rows(dir).is_empty());
    assert_eq!(
        roadmap_rows(dir, &[]).len(),
        0,
        "the deleted initiative is gone from the roadmap"
    );
    let bytes = registry_bytes(dir);
    assert!(!bytes.contains("[initiatives."), "{bytes}");
}

// ---------------------------------------------------------------------------
// Roadmap ordering, filtering, projection
// ---------------------------------------------------------------------------

#[test]
fn cli_roadmap_orders_by_target_date_then_id_with_undated_last() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    tix().current_dir(dir).arg("init").assert().success();
    // Created out of order on purpose: ordering is by date, not declaration order.
    let late = initiative_create(dir, "Late", &["--target-date", "2026-05-01"]);
    let undated = create_named(dir, "Undated");
    let early = initiative_create(dir, "Early", &["--target-date", "2026-01-01"]);

    let rows = roadmap_rows(dir, &[]);
    assert_eq!(
        rows.iter().map(|row| row.0.clone()).collect::<Vec<_>>(),
        vec![early, late, undated],
        "date ascending, then the explicit undated state"
    );
    assert_eq!(
        rows[2].2, "undated",
        "an undated row is never blank (C-003)"
    );

    // A bounded period never invents a date for the undated initiative.
    let bounded = roadmap_rows(dir, &["--from", "2026-01-01", "--to", "2026-12-31"]);
    assert_eq!(bounded.len(), 2, "the undated initiative is excluded");
    assert!(bounded.iter().all(|row| row.2 != "undated"), "{bounded:?}");
}

#[test]
fn cli_roadmap_filters_every_dimension_and_a_combination() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    tix().current_dir(dir).arg("init").assert().success();
    let alpha = initiative_create(
        dir,
        "Alpha",
        &[
            "--owner",
            "alice",
            "--status",
            "active",
            "--labels",
            "core,infra",
            "--target-date",
            "2026-02-01",
            "--outcome",
            "the platform",
        ],
    );
    let beta = initiative_create(
        dir,
        "Beta",
        &[
            "--owner",
            "bob",
            "--status",
            "done",
            "--labels",
            "docs",
            "--target-date",
            "2026-07-01",
        ],
    );

    let ids = |args: &[&str]| {
        roadmap_rows(dir, args)
            .iter()
            .map(|row| row.0.clone())
            .collect::<Vec<_>>()
    };

    assert_eq!(
        ids(&["--owner", "ALICE"]),
        vec![alpha.clone()],
        "owner folds case"
    );
    assert_eq!(ids(&["--status", "done"]), vec![beta.clone()]);
    assert_eq!(ids(&["--label", "core"]), vec![alpha.clone()]);
    assert_eq!(ids(&["--from", "2026-06-01"]), vec![beta.clone()]);
    assert_eq!(ids(&["--to", "2026-03-01"]), vec![alpha.clone()]);
    assert_eq!(ids(&["--query", "platform"]), vec![alpha.clone()]);

    // A combination is an AND: only Alpha carries every criterion.
    assert_eq!(
        ids(&[
            "--owner",
            "alice",
            "--status",
            "active",
            "--label",
            "core",
            "--from",
            "2026-01-01",
            "--to",
            "2026-06-01",
        ]),
        vec![alpha]
    );
    // A label the initiative does not carry matches nothing.
    assert!(ids(&["--label", "core", "--status", "done"]).is_empty());
}

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

    // No initiatives at all.
    let out = stdout_of(dir, &["roadmap", "list"]);
    assert!(out.contains("no initiatives match"), "{out}");

    // A well-formed filter that names nothing is not an error: it matches nothing.
    initiative_create(dir, "Alpha", &["--status", "active"]);
    let out = stdout_of(dir, &["roadmap", "list", "--status", "nonexistent"]);
    assert!(out.contains("no initiatives match"), "{out}");
    assert!(
        roadmap_rows(dir, &["--status", "nonexistent"]).is_empty(),
        "the empty projection has no rows"
    );
}

#[test]
fn cli_roadmap_malformed_filter_is_refused_with_a_named_diagnostic_and_no_write() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    tix().current_dir(dir).arg("init").assert().success();
    initiative_create(dir, "Alpha", &["--target-date", "2026-03-01"]);
    let before = registry_bytes(dir);

    tix()
        .current_dir(dir)
        .args(["roadmap", "list", "--from", "2026-13-01"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("roadmap filter `period_from`"))
        .stderr(predicate::str::contains("YYYY-MM-DD"));

    tix()
        .current_dir(dir)
        .args([
            "roadmap",
            "list",
            "--from",
            "2026-06-01",
            "--to",
            "2026-01-01",
        ])
        .assert()
        .failure()
        .stderr(predicate::str::contains("must be <="));

    assert_eq!(
        registry_bytes(dir),
        before,
        "a malformed filter is read-only and writes nothing"
    );
}

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

    // A real project, a real epic and one member issue, so the join has values.
    let project = parse_id(
        tix()
            .current_dir(dir)
            .args(["project", "create", "Proj"])
            .assert()
            .success()
            .get_output()
            .stdout
            .as_slice(),
    );
    let epic = parse_id(
        tix()
            .current_dir(dir)
            .args(["epic", "create", "Eppy"])
            .assert()
            .success()
            .get_output()
            .stdout
            .as_slice(),
    );
    tix()
        .current_dir(dir)
        .args([
            "create",
            "--title",
            "Member",
            "--projects",
            &project,
            "--epics",
            &epic,
        ])
        .assert()
        .success();

    let id = initiative_create(dir, "Alpha", &["--target-date", "2026-03-01"]);
    for args in [
        vec!["initiative", "associate", &id, "--project", &project],
        vec!["initiative", "associate", &id, "--epic", &epic],
        vec!["initiative", "associate", &id, "--milestone", "2026-Q4"],
    ] {
        tix().current_dir(dir).args(args).assert().success();
    }

    let out = stdout_of(dir, &["roadmap", "show", &id]);
    let header = out.lines().next().unwrap();
    assert!(
        header.contains(&format!("{id}\tAlpha\t2026-03-01\t")),
        "{out}"
    );

    // One line per referenced source, each with its own provenance and policy.
    let contributions: Vec<&str> = out
        .lines()
        .filter(|line| line.starts_with("  ") && line.contains("policy="))
        .collect();
    assert_eq!(contributions.len(), 3, "one contribution per source: {out}");
    assert!(
        contributions
            .iter()
            .any(|line| line.contains(&format!("project:{project}")) && line.contains("[resolved]")),
        "{out}"
    );
    assert!(
        contributions
            .iter()
            .any(|line| line.contains(&format!("epic:{epic}")) && line.contains("[resolved]")),
        "{out}"
    );
    // The missing milestone stays visible on the row (C-005).
    assert!(
        contributions
            .iter()
            .any(|line| line.contains("milestone:2026-Q4") && line.contains("[missing]")),
        "{out}"
    );
    assert!(
        out.contains("missing_reference"),
        "the missing reference is diagnosed: {out}"
    );

    // Every resolved contribution carries the shared health policy version; a
    // missing one carries none rather than a fabricated figure.
    assert!(out.contains("policy=health-v1"), "{out}");
    assert!(out.contains("policy=-"), "{out}");

    // A join, not a blend: no single line carries two sources, and no output line
    // reports a percentage or an aggregate score (C-004).
    for line in contributions {
        assert!(
            !(line.contains("project:") && line.contains("epic:")),
            "a contribution is one source: {line}"
        );
    }
    assert!(
        !out.contains('%'),
        "no blended percentage is invented: {out}"
    );
}

// ---------------------------------------------------------------------------
// Mutation boundary and legacy regression
// ---------------------------------------------------------------------------

#[test]
fn cli_initiative_rejected_mutations_leave_toml_byte_identical() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    tix().current_dir(dir).arg("init").assert().success();
    initiative_create(dir, "Platform", &["--target-date", "2026-03-01"]);
    let second = create_named(dir, "Infra");
    let before = registry_bytes(dir);

    // A duplicate display name is refused by the service, and nothing is written.
    tix()
        .current_dir(dir)
        .args(["initiative", "create", "Platform"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("must be unique"));
    assert_eq!(
        registry_bytes(dir),
        before,
        "a refused create writes nothing"
    );

    // A malformed reference id is refused before the write.
    tix()
        .current_dir(dir)
        .args(["initiative", "edit", &second, "--projects", "not an id!"])
        .assert()
        .failure();
    assert_eq!(registry_bytes(dir), before, "a refused edit writes nothing");

    // A malformed target date is refused before the write.
    tix()
        .current_dir(dir)
        .args(["initiative", "edit", &second, "--target-date", "2026-13-01"])
        .assert()
        .failure();
    assert_eq!(registry_bytes(dir), before, "a refused date writes nothing");
}

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

    // Create: a padded known spelling is normalized, not stored verbatim.
    let padded = initiative_create(dir, "Padded", &["--priority", " high "]);
    let shown = stdout_of(dir, &["initiative", "show", &padded]);
    assert!(
        shown.contains("priority: high"),
        "the known spelling is normalized on create: {shown}"
    );

    // Create: a blank priority means "absent", exactly as it clears on edit.
    let blank = initiative_create(dir, "Blank", &["--priority", ""]);
    let shown = stdout_of(dir, &["initiative", "show", &blank]);
    assert!(
        shown.contains("priority: -"),
        "a blank --priority is absent on create: {shown}"
    );
    let bytes = registry_bytes(dir);
    let blank_section = format!("[initiatives.{blank}]");
    let blank_body = bytes
        .split(&blank_section)
        .nth(1)
        .unwrap_or_default()
        .split("[initiatives.")
        .next()
        .unwrap_or_default();
    assert!(
        !blank_body.contains("priority ="),
        "a blank --priority stores no key: {bytes}"
    );

    // Edit: the same padded spelling normalizes, and a blank clears.
    let target = create_named(dir, "EditTarget");
    tix()
        .current_dir(dir)
        .args(["initiative", "edit", &target, "--priority", " low "])
        .assert()
        .success();
    let shown = stdout_of(dir, &["initiative", "show", &target]);
    assert!(
        shown.contains("priority: low"),
        "the known spelling is normalized on edit: {shown}"
    );
    tix()
        .current_dir(dir)
        .args(["initiative", "edit", &target, "--priority", ""])
        .assert()
        .success();
    let shown = stdout_of(dir, &["initiative", "show", &target]);
    assert!(
        shown.contains("priority: -"),
        "a blank --priority clears on edit: {shown}"
    );
}

#[test]
fn cli_initiative_refused_delete_and_dereference_write_nothing() {
    let tmp = TempDir::new().unwrap();
    let dir = tmp.path();
    tix().current_dir(dir).arg("init").assert().success();
    let id = create_named(dir, "Platform");
    let before = registry_bytes(dir);

    // An unknown id refuses the delete before any write.
    tix()
        .current_dir(dir)
        .args(["initiative", "delete", "nosuch", "--yes"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("unknown initiative"));
    assert_eq!(
        registry_bytes(dir),
        before,
        "a refused delete writes nothing"
    );

    // A malformed reference shape refuses the dereference before any write.
    tix()
        .current_dir(dir)
        .args(["initiative", "dereference", &id, "--project", "not an id!"])
        .assert()
        .failure();
    assert_eq!(
        registry_bytes(dir),
        before,
        "a refused dereference writes nothing"
    );
}

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

    // Both surfaces work with no initiative defined, and neither writes a section.
    assert!(initiative_rows(dir).is_empty());
    let out = stdout_of(dir, &["roadmap", "list"]);
    assert!(out.contains("no initiatives match"), "{out}");
    assert_eq!(
        registry_bytes(dir),
        before,
        "a read-only surface never writes tix.toml"
    );
}