mycelium-manager 0.2.7

A robust, production-grade task/plan manager CLI (binary: myc)
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
826
827
828
829
830
831
832
833
834
835
836
use std::path::PathBuf;
use std::process::Command;
use tempfile::TempDir;

/// Concurrent `task create` invocations must not drop writes. Under WAL, SQLite
/// serializes writers with a single lock; without a busy_timeout the second
/// writer gets SQLITE_BUSY immediately and the insert is lost. This spawns
/// several creates in parallel and asserts every one landed.
#[test]
fn test_concurrent_task_create_no_lost_writes() {
    let temp = TempDir::new().unwrap();
    myc_cmd(&temp).arg("init").output().expect("init");
    myc_cmd(&temp)
        .args(["epic", "create", "--title", "E"])
        .output()
        .expect("epic");

    // Fire N creates concurrently (spawn without waiting).
    let n = 6;
    let mut children = Vec::new();
    for i in 0..n {
        let child = myc_cmd(&temp)
            .args(["task", "create", "--title", &format!("T{i}"), "--epic", "1"])
            .spawn()
            .expect("spawn create");
        children.push(child);
    }
    for mut child in children {
        let status = child.wait().expect("wait");
        assert!(status.success(), "a concurrent create failed with {status}");
    }

    let out = myc_cmd(&temp)
        .args(["task", "list", "--all", "--format", "json"])
        .output()
        .expect("list");
    let stdout = String::from_utf8_lossy(&out.stdout);
    let count = stdout.matches("\"id\"").count();
    assert_eq!(count, n, "expected {n} tasks, got {count}: {stdout}");
}

fn myc_path() -> PathBuf {
    // First try CARGO_BIN_EXE_myc
    if let Ok(path) = std::env::var("CARGO_BIN_EXE_myc") {
        return PathBuf::from(path);
    }

    let debug_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("target")
        .join("debug")
        .join("myc");
    if debug_path.exists() {
        return debug_path;
    }

    // Otherwise fall back to release
    PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("target")
        .join("release")
        .join("myc")
}

fn myc_cmd(temp_dir: &TempDir) -> Command {
    let mut cmd = Command::new(myc_path());
    cmd.current_dir(temp_dir);
    cmd
}

fn print_output(output: &std::process::Output) {
    eprintln!("stdout: {}", String::from_utf8_lossy(&output.stdout));
    eprintln!("stderr: {}", String::from_utf8_lossy(&output.stderr));
    eprintln!("status: {}", output.status);
}

#[test]
fn test_init() {
    let temp = TempDir::new().unwrap();
    let output = myc_cmd(&temp)
        .arg("init")
        .output()
        .expect("Failed to execute");
    print_output(&output);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("Mycelium project initialized"));
}

/// Schema contract guard. Since the `mycelium-core` extraction there is a
/// single schema (core migrations), consumed by both `myc` and MycUI. This
/// test pins the tables + columns MycUI's frontend relies on, so a future core
/// migration that renamed/dropped one of them would fail here loudly rather
/// than silently breaking the desktop app.
///
/// Invariant: every table + column below exists in a freshly-initialized DB
/// with the expected declared type. Core may have MORE (task_notes, epic_notes,
/// linear_sync, v5 columns) — MycUI simply ignores those.
#[test]
fn test_mycui_required_schema_present() {
    // Tables + columns the MycUI frontend reads (see mycui dto.rs / types.ts).
    // (table, [(column, declared_type)]).
    let expected: &[(&str, &[(&str, &str)])] = &[
        (
            "epics",
            &[
                ("id", "INTEGER"),
                ("title", "TEXT"),
                ("description", "TEXT"),
                ("status", "TEXT"),
                ("created_at", "TEXT"),
                ("updated_at", "TEXT"),
            ],
        ),
        (
            "assignees",
            &[
                ("id", "INTEGER"),
                ("name", "TEXT"),
                ("email", "TEXT"),
                ("github_username", "TEXT"),
                ("created_at", "TEXT"),
            ],
        ),
        (
            "tasks",
            &[
                ("id", "INTEGER"),
                ("title", "TEXT"),
                ("description", "TEXT"),
                ("status", "TEXT"),
                ("priority", "TEXT"),
                ("epic_id", "INTEGER"),
                ("assignee_id", "INTEGER"),
                ("due_date", "TEXT"),
                ("tags", "TEXT"),
                ("created_at", "TEXT"),
                ("updated_at", "TEXT"),
            ],
        ),
        (
            "dependencies",
            &[
                ("id", "INTEGER"),
                ("task_id", "INTEGER"),
                ("depends_on_task_id", "INTEGER"),
                ("created_at", "TEXT"),
            ],
        ),
        (
            "followups",
            &[
                ("id", "INTEGER"),
                ("body", "TEXT"),
                ("title", "TEXT"),
                ("status", "TEXT"),
                ("closure_reason", "TEXT"),
                ("created_at", "TEXT"),
                ("closed_at", "TEXT"),
            ],
        ),
    ];

    let temp = TempDir::new().unwrap();
    myc_cmd(&temp).arg("init").output().expect("Failed to init");
    let db_path = temp.path().join(".mycelium").join("mycelium.db");
    assert!(db_path.exists(), "myc init did not create the database");

    let conn = rusqlite::Connection::open(&db_path).expect("open cli db");

    for (table, columns) in expected {
        // (column_name -> declared_type) from the CLI schema.
        let mut stmt = conn
            .prepare(&format!("PRAGMA table_info({table})"))
            .expect("prepare pragma");
        let actual: std::collections::HashMap<String, String> = stmt
            .query_map([], |row| {
                Ok((row.get::<_, String>(1)?, row.get::<_, String>(2)?))
            })
            .expect("query pragma")
            .map(|r| r.expect("row"))
            .collect();

        assert!(
            !actual.is_empty(),
            "CLI schema is missing table `{table}` that mycui creates"
        );

        for (col, ty) in *columns {
            match actual.get(*col) {
                None => panic!(
                    "CLI schema table `{table}` is missing column `{col}` \
                     (mycui expects it). Schemas have drifted — sync both sides \
                     or land follow-up #1 (shared mycelium-core crate)."
                ),
                Some(actual_ty) => assert_eq!(
                    actual_ty.to_uppercase(),
                    ty.to_uppercase(),
                    "column `{table}.{col}` type drift: CLI has `{actual_ty}`, \
                     mycui expects `{ty}`"
                ),
            }
        }
    }
}

#[test]
fn test_epic_create() {
    let temp = TempDir::new().unwrap();
    myc_cmd(&temp).arg("init").output().expect("Failed to init");

    let output = myc_cmd(&temp)
        .arg("epic")
        .arg("create")
        .arg("--title")
        .arg("Test Epic")
        .output()
        .expect("Failed to create epic");

    print_output(&output);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("Created epic #1"));
}

#[test]
fn test_task_create() {
    let temp = TempDir::new().unwrap();
    myc_cmd(&temp).arg("init").output().expect("Failed to init");
    myc_cmd(&temp)
        .arg("epic")
        .arg("create")
        .arg("--title")
        .arg("Test Epic")
        .output()
        .expect("Failed to create epic");

    let output = myc_cmd(&temp)
        .arg("task")
        .arg("create")
        .arg("--title")
        .arg("Test Task")
        .arg("--epic")
        .arg("1")
        .output()
        .expect("Failed to create task");

    print_output(&output);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("Created task #1"));
}

#[test]
fn test_dependency_blocking() {
    let temp = TempDir::new().unwrap();
    myc_cmd(&temp).arg("init").output().expect("Failed to init");
    myc_cmd(&temp)
        .arg("epic")
        .arg("create")
        .arg("--title")
        .arg("Test Epic")
        .output()
        .expect("Failed to create epic");
    myc_cmd(&temp)
        .arg("task")
        .arg("create")
        .arg("--title")
        .arg("Task 1")
        .output()
        .expect("Failed to create task 1");
    myc_cmd(&temp)
        .arg("task")
        .arg("create")
        .arg("--title")
        .arg("Task 2")
        .output()
        .expect("Failed to create task 2");

    // Make task 1 block task 2
    let output = myc_cmd(&temp)
        .arg("task")
        .arg("link")
        .arg("blocks")
        .arg("--task")
        .arg("1")
        .arg("2")
        .output()
        .expect("Failed to link");

    print_output(&output);
    assert!(output.status.success());

    // Try to close task 2 (should fail since it's blocked)
    let output = myc_cmd(&temp)
        .arg("task")
        .arg("close")
        .arg("2")
        .output()
        .expect("Failed to close");

    print_output(&output);
    // Note: blocked message goes to stdout since it's not a hard error
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("blocked by"));

    // Close task 1 first
    let output = myc_cmd(&temp)
        .arg("task")
        .arg("close")
        .arg("1")
        .output()
        .expect("Failed to close 1");
    print_output(&output);
    assert!(output.status.success());

    // Now task 2 should close
    let output = myc_cmd(&temp)
        .arg("task")
        .arg("close")
        .arg("2")
        .output()
        .expect("Failed to close 2");
    print_output(&output);
    assert!(output.status.success());
}

#[test]
fn test_assignee() {
    let temp = TempDir::new().unwrap();
    myc_cmd(&temp).arg("init").output().expect("Failed to init");

    // Create assignee
    let output = myc_cmd(&temp)
        .arg("assignee")
        .arg("create")
        .arg("--name")
        .arg("John Doe")
        .arg("--github")
        .arg("johndoe")
        .output()
        .expect("Failed to create assignee");

    print_output(&output);
    assert!(output.status.success());

    // Create task and assign
    myc_cmd(&temp)
        .arg("task")
        .arg("create")
        .arg("--title")
        .arg("Test")
        .output()
        .expect("Failed to create task");

    let output = myc_cmd(&temp)
        .arg("task")
        .arg("assign")
        .arg("1")
        .arg("1")
        .output()
        .expect("Failed to assign");

    print_output(&output);
    assert!(output.status.success());
}

#[test]
fn test_json_output() {
    let temp = TempDir::new().unwrap();
    myc_cmd(&temp).arg("init").output().expect("Failed to init");
    myc_cmd(&temp)
        .arg("epic")
        .arg("create")
        .arg("--title")
        .arg("Test Epic")
        .output()
        .expect("Failed to create epic");

    let output = myc_cmd(&temp)
        .arg("epic")
        .arg("list")
        .arg("--format")
        .arg("json")
        .output()
        .expect("Failed to list");

    print_output(&output);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("{")); // Should be JSON
}

#[test]
fn test_export() {
    let temp = TempDir::new().unwrap();
    myc_cmd(&temp).arg("init").output().expect("Failed to init");
    myc_cmd(&temp)
        .arg("epic")
        .arg("create")
        .arg("--title")
        .arg("Test Epic")
        .output()
        .expect("Failed to create epic");
    myc_cmd(&temp)
        .arg("task")
        .arg("create")
        .arg("--title")
        .arg("Test Task")
        .output()
        .expect("Failed to create task");

    let output = myc_cmd(&temp)
        .arg("export")
        .arg("json")
        .output()
        .expect("Failed to export");

    print_output(&output);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("epics"));
    assert!(stdout.contains("tasks"));
}

#[test]
fn test_export_csv_survives_commas_quotes_and_newlines() {
    // Regression: the old CSV export hand-rolled `"{}"` interpolation, which
    // only escaped embedded quotes. A title/description containing a literal
    // newline produced an extra, broken CSV row; commas inside unescaped
    // fields (assignee/epic ids are safe, but nothing quoted them either)
    // could also misalign columns for any consumer that (correctly) treats
    // an unescaped raw newline as a row terminator.
    let temp = TempDir::new().unwrap();
    myc_cmd(&temp).arg("init").output().expect("Failed to init");
    myc_cmd(&temp)
        .arg("epic")
        .arg("create")
        .arg("--title")
        .arg("Test Epic")
        .output()
        .expect("Failed to create epic");

    let tricky_title = "Title, with \"quotes\"\nand a newline";
    myc_cmd(&temp)
        .arg("task")
        .arg("create")
        .arg("--title")
        .arg(tricky_title)
        .arg("--epic")
        .arg("1")
        .output()
        .expect("Failed to create tricky task");
    myc_cmd(&temp)
        .arg("task")
        .arg("create")
        .arg("--title")
        .arg("Plain task")
        .output()
        .expect("Failed to create plain task");

    let output = myc_cmd(&temp)
        .arg("export")
        .arg("csv")
        .output()
        .expect("Failed to export csv");
    print_output(&output);
    assert!(output.status.success());

    let mut rdr = csv::Reader::from_reader(output.stdout.as_slice());
    let headers = rdr.headers().expect("headers").clone();
    assert_eq!(
        headers.iter().collect::<Vec<_>>(),
        vec![
            "id",
            "title",
            "description",
            "status",
            "priority",
            "epic_id",
            "assignee_id",
            "due_date",
            "tags",
            "notes",
            "user_info",
            "agent_questions",
            "created_at",
            "updated_at",
        ]
    );

    let records: Vec<csv::StringRecord> =
        rdr.records().map(|r| r.expect("valid csv row")).collect();
    // Exactly 2 data rows despite the embedded newline in row 1.
    assert_eq!(records.len(), 2, "expected 2 task rows, got {records:?}");

    let tricky_row = records
        .iter()
        .find(|r| r.get(0) == Some("1"))
        .expect("row for task #1");
    assert_eq!(tricky_row.get(1), Some(tricky_title));
    assert_eq!(tricky_row.get(5), Some("1")); // epic_id

    let plain_row = records
        .iter()
        .find(|r| r.get(0) == Some("2"))
        .expect("row for task #2");
    assert_eq!(plain_row.get(1), Some("Plain task"));
}

#[test]
fn test_task_create_help_does_not_panic() {
    let temp = TempDir::new().unwrap();
    let output = myc_cmd(&temp)
        .arg("task")
        .arg("create")
        .arg("--help")
        .output()
        .expect("Failed to show help");

    print_output(&output);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("Create a new task"));
}

#[test]
fn test_blocked_list_only_shows_tasks_with_open_blockers() {
    let temp = TempDir::new().unwrap();
    myc_cmd(&temp).arg("init").output().expect("Failed to init");
    myc_cmd(&temp)
        .arg("task")
        .arg("create")
        .arg("--title")
        .arg("Blocker")
        .output()
        .expect("Failed to create blocker");
    myc_cmd(&temp)
        .arg("task")
        .arg("create")
        .arg("--title")
        .arg("Blocked")
        .output()
        .expect("Failed to create blocked task");
    myc_cmd(&temp)
        .arg("task")
        .arg("link")
        .arg("blocks")
        .arg("--task")
        .arg("1")
        .arg("2")
        .output()
        .expect("Failed to link dependency");

    let output = myc_cmd(&temp)
        .arg("task")
        .arg("list")
        .arg("--blocked")
        .arg("--format")
        .arg("json")
        .output()
        .expect("Failed to list blocked tasks");
    print_output(&output);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("\"id\": 2"));

    myc_cmd(&temp)
        .arg("task")
        .arg("close")
        .arg("1")
        .output()
        .expect("Failed to close blocker");

    let output = myc_cmd(&temp)
        .arg("task")
        .arg("list")
        .arg("--blocked")
        .arg("--format")
        .arg("json")
        .output()
        .expect("Failed to list blocked tasks after closing blocker");
    print_output(&output);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert_eq!(stdout.trim(), "[]");
}

#[test]
fn test_delete_epic_detaches_tasks_instead_of_deleting_them() {
    let temp = TempDir::new().unwrap();
    myc_cmd(&temp).arg("init").output().expect("Failed to init");
    myc_cmd(&temp)
        .arg("epic")
        .arg("create")
        .arg("--title")
        .arg("Epic")
        .output()
        .expect("Failed to create epic");
    myc_cmd(&temp)
        .arg("task")
        .arg("create")
        .arg("--title")
        .arg("Task")
        .arg("--epic")
        .arg("1")
        .output()
        .expect("Failed to create task");

    let output = myc_cmd(&temp)
        .arg("epic")
        .arg("delete")
        .arg("1")
        .arg("--force")
        .output()
        .expect("Failed to delete epic");
    print_output(&output);
    assert!(output.status.success());

    let output = myc_cmd(&temp)
        .arg("task")
        .arg("show")
        .arg("1")
        .arg("--format")
        .arg("json")
        .output()
        .expect("Failed to show task");
    print_output(&output);
    assert!(output.status.success());
    let stdout = String::from_utf8_lossy(&output.stdout);
    assert!(stdout.contains("\"id\": 1"));
    assert!(stdout.contains("\"epic_id\": null"));
}

#[test]
fn test_followup_full_lifecycle() {
    let temp = TempDir::new().unwrap();
    let _ = myc_cmd(&temp).arg("init").output().expect("init");

    // add (with title)
    let out = myc_cmd(&temp)
        .args(["followup", "add", "first body text", "--title", "first"])
        .output()
        .expect("add");
    print_output(&out);
    assert!(out.status.success());

    // add (no title, alias `fu`)
    let out = myc_cmd(&temp)
        .args(["fu", "add", "second body, no title"])
        .output()
        .expect("add 2");
    assert!(out.status.success());

    // list — default -a shows all (both visible)
    let out = myc_cmd(&temp)
        .args(["followup", "list", "--format", "json"])
        .output()
        .expect("list");
    let json = String::from_utf8_lossy(&out.stdout);
    assert!(json.contains("\"id\": 1"));
    assert!(json.contains("\"id\": 2"));

    // -o shows only active items (both open at this point)
    let out = myc_cmd(&temp)
        .args(["followup", "list", "-o", "--format", "json"])
        .output()
        .expect("list -o");
    let json = String::from_utf8_lossy(&out.stdout);
    assert!(json.contains("\"id\": 1"));
    assert!(json.contains("\"id\": 2"));

    // -c shows only closed items (none yet)
    let out = myc_cmd(&temp)
        .args(["followup", "list", "-c", "--format", "json"])
        .output()
        .expect("list -c");
    let json = String::from_utf8_lossy(&out.stdout);
    assert!(!json.contains("\"id\": 1"));
    assert!(!json.contains("\"id\": 2"));

    // count
    let out = myc_cmd(&temp)
        .args(["followup", "count", "--format", "json"])
        .output()
        .expect("count");
    let body = String::from_utf8_lossy(&out.stdout);
    assert!(body.contains("\"open\": 2"));

    // append
    let out = myc_cmd(&temp)
        .args(["followup", "append", "1", "extra context"])
        .output()
        .expect("append");
    assert!(out.status.success());
    let out = myc_cmd(&temp)
        .args(["followup", "show", "1", "--format", "json"])
        .output()
        .expect("show");
    let body = String::from_utf8_lossy(&out.stdout);
    assert!(body.contains("extra context"));

    // edit replace
    let out = myc_cmd(&temp)
        .args(["followup", "edit", "1", "--body", "fully replaced"])
        .output()
        .expect("edit");
    assert!(out.status.success());

    // start + done
    let out = myc_cmd(&temp)
        .args(["followup", "start", "1"])
        .output()
        .expect("start");
    assert!(out.status.success());
    let out = myc_cmd(&temp)
        .args(["followup", "done", "1", "--reason", "tested"])
        .output()
        .expect("done");
    assert!(out.status.success());

    // next should now return #2 (only remaining open)
    let out = myc_cmd(&temp)
        .args(["followup", "next", "--format", "json"])
        .output()
        .expect("next");
    let body = String::from_utf8_lossy(&out.stdout);
    assert!(body.contains("\"id\": 2"));

    // -c now shows #1 (done), -o shows #2 (open)
    let out = myc_cmd(&temp)
        .args(["followup", "list", "-c", "--format", "json"])
        .output()
        .expect("list -c");
    let body = String::from_utf8_lossy(&out.stdout);
    assert!(body.contains("\"id\": 1"));
    assert!(!body.contains("\"id\": 2"));
    let out = myc_cmd(&temp)
        .args(["followup", "list", "-o", "--format", "json"])
        .output()
        .expect("list -o");
    let body = String::from_utf8_lossy(&out.stdout);
    assert!(!body.contains("\"id\": 1"));
    assert!(body.contains("\"id\": 2"));

    // wontfix #2
    let out = myc_cmd(&temp)
        .args(["followup", "wontfix", "2", "--reason", "scope creep"])
        .output()
        .expect("wontfix");
    assert!(out.status.success());

    // next should be null now
    let out = myc_cmd(&temp)
        .args(["followup", "next", "--format", "json"])
        .output()
        .expect("next empty");
    let body = String::from_utf8_lossy(&out.stdout);
    assert!(body.trim().starts_with("null"));

    // reopen #2
    let out = myc_cmd(&temp)
        .args(["followup", "reopen", "2"])
        .output()
        .expect("reopen");
    assert!(out.status.success());

    // rm with --force
    let out = myc_cmd(&temp)
        .args(["followup", "rm", "2", "--force"])
        .output()
        .expect("rm");
    assert!(out.status.success());
}

#[test]
fn test_followup_promote_to_task() {
    let temp = TempDir::new().unwrap();
    let _ = myc_cmd(&temp).arg("init").output().expect("init");

    let _ = myc_cmd(&temp)
        .args([
            "followup",
            "add",
            "should become a real task",
            "--title",
            "Real work",
        ])
        .output()
        .expect("add");

    let out = myc_cmd(&temp)
        .args(["followup", "promote", "1", "--priority", "high"])
        .output()
        .expect("promote");
    print_output(&out);
    assert!(out.status.success());

    // Followup should now be done
    let out = myc_cmd(&temp)
        .args(["followup", "show", "1", "--format", "json"])
        .output()
        .expect("show fu");
    let body = String::from_utf8_lossy(&out.stdout);
    assert!(body.contains("\"status\": \"done\""));
    assert!(body.contains("Promoted to task #1"));

    // Task should exist with the title
    let out = myc_cmd(&temp)
        .args(["task", "show", "1", "--format", "json"])
        .output()
        .expect("show task");
    let body = String::from_utf8_lossy(&out.stdout);
    assert!(body.contains("\"title\": \"Real work\""));
    assert!(body.contains("\"priority\": \"high\""));
}

#[test]
fn test_followup_close_hint_fires() {
    let temp = TempDir::new().unwrap();
    let _ = myc_cmd(&temp).arg("init").output().expect("init");
    let _ = myc_cmd(&temp)
        .args(["task", "create", "--title", "Some task"])
        .output()
        .expect("task create");
    let _ = myc_cmd(&temp)
        .args(["followup", "add", "something to look at later"])
        .output()
        .expect("fu add");

    let out = myc_cmd(&temp)
        .args(["task", "close", "1"])
        .output()
        .expect("task close");
    print_output(&out);
    let stdout = String::from_utf8_lossy(&out.stdout);
    assert!(stdout.contains("open follow-up"));
}