tasks-cli-rs 0.9.0

Markdown-based TODO task management CLI: each task is a Markdown file with YAML front matter
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
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
use std::path::Path;
use std::process::{Command, Output};

fn run(home: &Path, args: &[&str]) -> Output {
    Command::new(env!("CARGO_BIN_EXE_tasks"))
        .env("TASKS_CLI_HOME", home)
        .args(args)
        .output()
        .expect("failed to run tasks binary")
}

fn ok(home: &Path, args: &[&str]) -> String {
    let out = run(home, args);
    assert!(
        out.status.success(),
        "command {:?} failed: {}",
        args,
        String::from_utf8_lossy(&out.stderr)
    );
    String::from_utf8_lossy(&out.stdout).to_string()
}

#[test]
fn full_workflow() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    let lib_path = home.join("repos/personal");

    // library setup
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);
    let out = ok(&home, &["lib", "current"]);
    assert!(out.contains("personal"));

    // new
    let out = ok(&home, &[
        "new", "Fix login bug", "--priority", "high", "--tag", "backend", "--due", "2026-08-10",
    ]);
    assert!(out.contains("created task #1"));
    // `add` is an alias for `new`
    let out = ok(&home, &["add", "Write docs", "--dir", "work"]);
    assert!(out.contains("created task #2"), "{out}");

    // list
    let out = ok(&home, &["list"]);
    assert!(out.contains("Fix login bug"));
    assert!(out.contains("Write docs"));

    // start -> set -> done
    ok(&home, &["start", "1"]);
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("in_progress"));
    assert!(out.contains("started:"));

    ok(&home, &["set", "1", "--title", "Fix login timeout bug", "--tag-add", "urgent"]);
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("Fix login timeout bug"));
    assert!(out.contains("urgent"));

    ok(&home, &["done", "1"]);
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("done"));
    assert!(out.contains("completed:"));

    // filters and search
    let out = ok(&home, &["list", "--status", "done"]);
    assert!(out.contains("Fix login timeout bug"));
    assert!(!out.contains("Write docs"));

    let out = ok(&home, &["search", "docs"]);
    assert!(out.contains("Write docs"));

    // tag commands
    ok(&home, &["tag", "add", "2", "documentation"]);
    let out = ok(&home, &["tag", "list"]);
    assert!(out.contains("documentation"));

    // delete
    ok(&home, &["delete", "2", "--force"]);
    let out = ok(&home, &["list"]);
    assert!(!out.contains("Write docs"));

    // unknown id is a clean error
    let out = run(&home, &["show", "999"]);
    assert!(!out.status.success());
    assert!(String::from_utf8_lossy(&out.stderr).contains("not found"));

    std::fs::remove_dir_all(&home).unwrap();
}

#[test]
fn filename_format_and_rename_on_title_change() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-fmt-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    std::fs::write(home.join("config.toml"), "filename_format = \"{date}-{slug}-{short_id}\"\n")
        .unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);

    // new file carries the date prefix
    let out = ok(&home, &["new", "My Task"]);
    let file_line = out.lines().nth(1).unwrap().trim();
    let filename = Path::new(file_line).file_name().unwrap().to_string_lossy().to_string();
    assert!(filename.contains("-my-task-"), "{filename}");
    assert!(filename.chars().take(4).all(|c| c.is_ascii_digit()), "date prefix: {filename}");

    // title change renames the file, only the slug part differs
    let out = ok(&home, &["set", "1", "--title", "Renamed Task"]);
    assert!(out.contains("renamed:"), "{out}");
    let renamed = out
        .lines()
        .find(|l| l.starts_with("renamed:"))
        .unwrap()
        .trim_start_matches("renamed:")
        .trim();
    assert_eq!(renamed, filename.replace("my-task", "renamed-task"));
    assert!(lib_path.join(renamed).exists());
    assert!(!lib_path.join(&filename).exists());

    // task still resolvable and intact after rename
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("Renamed Task"));

    // bad template is rejected cleanly
    std::fs::write(home.join("config.toml"), "filename_format = \"{typo}\"\n").unwrap();
    let out = run(&home, &["new", "Another"]);
    assert!(!out.status.success());
    assert!(String::from_utf8_lossy(&out.stderr).contains("filename_format"));

    std::fs::remove_dir_all(&home).unwrap();
}

#[test]
fn adopt_and_warning_suppression() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-adopt-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);

    // plain notes without front matter
    std::fs::write(lib_path.join("2026-06-17-langchain研究.md"), "# LangChain 研究\n\n内容\n").unwrap();
    std::fs::write(lib_path.join("scratch.md"), "just a note\n").unwrap();

    // one-line summary warning instead of per-file noise
    let out = run(&home, &["list"]);
    let stderr = String::from_utf8_lossy(&out.stderr).to_string();
    assert_eq!(stderr.matches("warning").count(), 1, "{stderr}");
    assert!(stderr.contains("2 non-task file(s)"), "{stderr}");

    // --quiet suppresses it
    let out = run(&home, &["list", "--quiet"]);
    assert!(!String::from_utf8_lossy(&out.stderr).contains("warning"));

    // ignore pattern silences and hides the file
    std::fs::write(
        lib_path.join(".tasks-meta.toml"),
        "next_seq = 1\nignore = [\"scratch.md\"]\n",
    )
    .unwrap();
    let out = run(&home, &["list"]);
    let stderr = String::from_utf8_lossy(&out.stderr).to_string();
    assert!(stderr.contains("1 non-task file(s)"), "{stderr}");

    // dry-run shows the plan without changing anything
    let out = ok(&home, &["adopt", "--dry-run"]);
    assert!(out.contains("would adopt"), "{out}");
    assert!(out.contains("LangChain 研究"), "{out}");
    let raw = std::fs::read_to_string(lib_path.join("2026-06-17-langchain研究.md")).unwrap();
    assert!(!raw.starts_with("---"));

    // adopt --all --rename converts and renames per template
    std::fs::write(home.join("config.toml"), "filename_format = \"{date}-{slug}-{short_id}\"\n")
        .unwrap();
    let out = ok(&home, &["adopt", "--all", "--rename"]);
    assert!(out.contains("adopted 1 file(s)"), "{out}");
    assert!(out.contains("renamed:"), "{out}");

    // adopted task is now listed, warning gone, metadata derived
    let out = run(&home, &["list"]);
    assert!(!String::from_utf8_lossy(&out.stderr).contains("warning"));
    let stdout = String::from_utf8_lossy(&out.stdout).to_string();
    assert!(stdout.contains("LangChain 研究"), "{stdout}");

    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("created:   2026-06-1"), "date from filename: {out}");
    assert!(out.contains("内容"), "body preserved: {out}");

    // renamed file carries the date prefix from created_at
    let renamed_exists = std::fs::read_dir(&lib_path)
        .unwrap()
        .filter_map(|e| e.ok())
        .any(|e| e.file_name().to_string_lossy().starts_with("2026-06-17-langchain-研究"));
    assert!(renamed_exists);

    // warn_invalid_files = false silences globally (scratch.md still skipped)
    std::fs::write(
        lib_path.join(".tasks-meta.toml"),
        "next_seq = 2\n",
    )
    .unwrap();
    std::fs::write(
        home.join("config.toml"),
        "warn_invalid_files = false\n",
    )
    .unwrap();
    let out = run(&home, &["list"]);
    assert!(!String::from_utf8_lossy(&out.stderr).contains("warning"));

    std::fs::remove_dir_all(&home).unwrap();
}

#[test]
fn v02_steps_board_remind_stats() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-v02-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    std::fs::write(home.join("config.toml"), "default_priority = \"high\"\n").unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);

    // default_priority from config is applied
    ok(&home, &["new", "Main work"]);
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("priority:  high"), "{out}");

    // steps: add, done, remove (body checkboxes)
    ok(&home, &["step", "add", "1", "Design schema"]);
    ok(&home, &["step", "add", "1", "Implement"]);

    let out = ok(&home, &["step", "done", "1", "s1"]);
    assert!(out.contains("progress: 1/2"), "{out}");
    let out = ok(&home, &["step", "done", "1", "s2"]);
    assert!(out.contains("progress: 2/2"), "{out}");
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("steps:     2/2"), "{out}");
    ok(&home, &["step", "remove", "1", "s1"]);
    let out = ok(&home, &["show", "1"]);
    assert!(!out.contains("Design schema"), "{out}");

    // board
    ok(&home, &["new", "Doing thing"]);
    ok(&home, &["start", "2"]);
    let out = ok(&home, &["board"]);
    assert!(out.contains("TODO (1)"), "{out}");
    assert!(out.contains("IN_PROGRESS (1)"), "{out}");
    assert!(out.contains("#2 Doing thing"), "{out}");

    // remind / overdue
    ok(&home, &["new", "Old due", "--due", "2020-01-01"]);
    ok(&home, &["new", "Far future", "--due", "2099-01-01"]);
    let out = ok(&home, &["remind"]);
    assert!(out.contains("OVERDUE"), "{out}");
    assert!(out.contains("Old due"), "{out}");
    assert!(!out.contains("Far future"), "{out}");
    let out = ok(&home, &["remind", "--summary"]);
    assert!(out.contains("1 overdue"), "{out}");
    let out = ok(&home, &["overdue"]);
    assert!(out.contains("Old due"), "{out}");
    assert!(!out.contains("Far future"), "{out}");

    // done tasks are not overdue
    ok(&home, &["done", "3"]);
    let out = ok(&home, &["overdue"]);
    assert!(!out.contains("Old due"), "{out}");

    // stats
    let out = ok(&home, &["stats"]);
    assert!(out.contains("Total tasks:      4"), "{out}");
    assert!(out.contains("done:"), "{out}");
    assert!(out.contains("Completion rate:"), "{out}");

    // completions
    let out = ok(&home, &["completions", "bash"]);
    assert!(out.contains("tasks"), "{out}");
    let out = run(&home, &["completions", "tcsh"]);
    assert!(!out.status.success());

    std::fs::remove_dir_all(&home).unwrap();
}

#[test]
fn templates_create_and_apply() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-tpl-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(home.join("templates")).unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);

    // empty state hint
    let out = ok(&home, &["template", "list"]);
    assert!(out.contains("no templates"), "{out}");

    // global template: TODO block above the content block
    std::fs::write(
        home.join("templates/bug.md"),
        "---\npriority: high\ntags: [bug]\n---\n\n- [ ] 复现\n\n## {{title}}\n\n报于 {{date}}\n",
    )
    .unwrap();
    let out = ok(&home, &["template", "list"]);
    assert!(out.contains("bug"), "{out}");
    assert!(out.contains("global"), "{out}");

    // create from template: defaults applied, variables substituted
    ok(&home, &["new", "登录页崩溃", "--template", "bug"]);
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("priority:  high"), "{out}");
    assert!(out.contains("bug"), "{out}");
    assert!(out.contains("steps:     0/1"), "{out}");
    assert!(out.contains("## 登录页崩溃"), "{out}");
    assert!(!out.contains("{{date}}"), "{out}");

    // CLI args override template
    ok(&home, &["new", "另一个", "--template", "bug", "--priority", "low", "--tag", "cli"]);
    let out = ok(&home, &["show", "2"]);
    assert!(out.contains("priority:  low"), "{out}");
    assert!(out.contains("cli"), "{out}");
    assert!(!out.contains("tags:      bug"), "{out}");

    // library template shadows global
    std::fs::create_dir_all(lib_path.join(".templates")).unwrap();
    std::fs::write(lib_path.join(".templates/bug.md"), "---\npriority: urgent\n---\nlib body\n").unwrap();
    ok(&home, &["new", "第三个", "--template", "bug"]);
    let out = ok(&home, &["show", "3"]);
    assert!(out.contains("priority:  urgent"), "{out}");

    // .templates dir does not pollute task list / warnings
    let out = run(&home, &["list"]);
    assert!(!String::from_utf8_lossy(&out.stderr).contains("warning"));

    // show / remove / unknown
    let out = ok(&home, &["template", "show", "bug"]);
    assert!(out.contains("lib body"), "{out}");
    ok(&home, &["template", "remove", "bug"]);
    let out = ok(&home, &["template", "show", "bug"]);
    assert!(out.contains("priority: high"), "global remains after lib removed: {out}");
    let out = run(&home, &["new", "x", "--template", "nope"]);
    assert!(!out.status.success());

    std::fs::remove_dir_all(&home).unwrap();
}

#[cfg(unix)]
#[test]
fn edit_rejects_immutable_changes_and_restores() {
    use std::os::unix::fs::PermissionsExt;

    let home = std::env::temp_dir().join(format!("tasks-e2e-edit-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);
    ok(&home, &["new", "Original task"]);

    let make_editor = |name: &str, script: &str| -> String {
        let path = home.join(name);
        std::fs::write(&path, script).unwrap();
        std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).unwrap();
        path.to_str().unwrap().to_string()
    };

    // editor that changes the immutable seq field -> rejected, file restored
    let editor = make_editor("edit-seq.sh", "#!/bin/sh\nsed -i 's/^seq: 1$/seq: 42/' \"$1\"\n");
    let out = run(&home, &["edit", "1", "--editor", &editor]);
    assert!(!out.status.success());
    assert!(String::from_utf8_lossy(&out.stderr).contains("'seq'"));
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("#1 "), "seq should be restored to 1");

    // editor that corrupts the front matter -> rejected, file restored
    let editor = make_editor("edit-break.sh", "#!/bin/sh\necho 'garbage' > \"$1\"\n");
    let out = run(&home, &["edit", "1", "--editor", &editor]);
    assert!(!out.status.success());
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("Original task"));

    // editor that makes a legal change -> accepted
    let editor = make_editor(
        "edit-title.sh",
        "#!/bin/sh\nsed -i 's/title: Original task/title: Renamed task/' \"$1\"\n",
    );
    let out = ok(&home, &["edit", "1", "--editor", &editor]);
    assert!(out.contains("saved #1 Renamed task"));

    std::fs::remove_dir_all(&home).unwrap();
}

#[test]
fn fix_names_renames_to_template() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-fixnames-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    std::fs::write(home.join("config.toml"), "filename_format = \"{date}-{slug}-{short_id}\"\n")
        .unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);
    ok(&home, &["new", "My Task"]);

    // Manually rename to a non-conforming name
    let entries: Vec<_> = std::fs::read_dir(&lib_path)
        .unwrap()
        .filter_map(|e| e.ok())
        .filter(|e| e.path().extension().is_some_and(|x| x == "md"))
        .collect();
    assert_eq!(entries.len(), 1);
    let original = entries[0].path();
    let renamed = lib_path.join("old-name.md");
    std::fs::rename(&original, &renamed).unwrap();

    // dry-run shows what would happen without changing
    let out = ok(&home, &["fix-names", "--dry-run"]);
    assert!(out.contains("would rename"), "{out}");
    assert!(renamed.exists());

    // actual fix
    let out = ok(&home, &["fix-names"]);
    assert!(out.contains("renamed 1 file(s)"), "{out}");
    assert!(!renamed.exists());

    // file now matches template (date-slug-shortid)
    let entries: Vec<_> = std::fs::read_dir(&lib_path)
        .unwrap()
        .filter_map(|e| e.ok())
        .filter(|e| e.path().extension().is_some_and(|x| x == "md"))
        .collect();
    let name = entries[0].file_name().to_string_lossy().to_string();
    assert!(name.contains("my-task"), "{name}");
    assert!(name.chars().take(4).all(|c| c.is_ascii_digit()), "date prefix: {name}");

    // idempotent: second run does nothing
    let out = ok(&home, &["fix-names"]);
    assert!(out.contains("already match"), "{out}");

    std::fs::remove_dir_all(&home).unwrap();
}

#[test]
fn batch_status_with_filters() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-batch-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);

    ok(&home, &["new", "Backend A", "--tag", "backend"]);
    ok(&home, &["new", "Backend B", "--tag", "backend"]);
    ok(&home, &["new", "Frontend C", "--tag", "frontend"]);
    ok(&home, &["new", "Project task", "--dir", "work", "--tag", "backend"]);

    // refuse batch without filters
    let out = run(&home, &["batch", "done", "--force"]);
    assert!(!out.status.success());
    assert!(String::from_utf8_lossy(&out.stderr).contains("without filters"));

    // dry-run shows matches without changing
    let out = ok(&home, &["batch", "done", "--tag", "backend", "--dry-run"]);
    assert!(out.contains("Backend A"), "{out}");
    assert!(out.contains("3 task(s) would be set to done"), "{out}");
    let out = ok(&home, &["list", "--status", "done"]);
    assert!(out.contains("no tasks"), "{out}");

    // batch by tag
    let out = ok(&home, &["batch", "done", "--tag", "backend", "--force"]);
    assert!(out.contains("3 task(s) -> done"), "{out}");
    let out = ok(&home, &["list", "--status", "done"]);
    assert!(out.contains("Backend A") && out.contains("Backend B"), "{out}");
    assert!(!out.contains("Frontend C"), "{out}");

    // batch by dir (project): reopen only work/ tasks
    let out = ok(&home, &["batch", "todo", "--dir", "work", "--force"]);
    assert!(out.contains("1 task(s) -> todo"), "{out}");

    // combined filters: status + tag
    let out = ok(&home, &["batch", "in_progress", "--status", "todo", "--tag", "frontend", "--force"]);
    assert!(out.contains("1 task(s) -> in_progress"), "{out}");

    // invalid status errors
    let out = run(&home, &["batch", "bogus", "--tag", "backend"]);
    assert!(!out.status.success());

    std::fs::remove_dir_all(&home).unwrap();
}

#[test]
fn archive_moves_tasks_to_month_folders() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-archive-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);

    ok(&home, &["new", "Finished A"]);
    ok(&home, &["new", "Finished B"]);
    ok(&home, &["new", "Still open"]);
    ok(&home, &["new", "Tagged old", "--tag", "legacy"]);
    ok(&home, &["done", "1"]);
    ok(&home, &["cancel", "2"]);

    // dry-run: default rule picks done + cancelled only
    let out = ok(&home, &["archive", "--dry-run"]);
    assert!(out.contains("would archive"), "{out}");
    assert!(out.contains("2 task(s) would be archived"), "{out}");
    assert!(!lib_path.join("archive").exists(), "dry-run must not create dirs");

    // real archive into archive/YYYY-MM/
    let out = ok(&home, &["archive", "--force"]);
    assert!(out.contains("archived 2 task(s)"), "{out}");
    let month = chrono::Local::now().format("%Y-%m").to_string();
    let month_dir = lib_path.join("archive").join(&month);
    assert!(month_dir.exists(), "expected {}", month_dir.display());
    let archived: Vec<_> = std::fs::read_dir(&month_dir)
        .unwrap()
        .filter_map(|e| e.ok())
        .filter(|e| e.path().extension().is_some_and(|x| x == "md"))
        .collect();
    assert_eq!(archived.len(), 2);

    // archived tasks disappear from normal scans, no stray warnings
    let out = run(&home, &["list"]);
    let stdout = String::from_utf8_lossy(&out.stdout).to_string();
    assert!(stdout.contains("Still open"), "{stdout}");
    assert!(!stdout.contains("Finished A"), "{stdout}");
    assert!(!String::from_utf8_lossy(&out.stderr).contains("warning"));

    // but are browsable via an explicit scope
    let scope = format!("archive/{month}");
    let out = ok(&home, &["list", "--dir", &scope]);
    assert!(out.contains("Finished A"), "{out}");

    // custom filter rule: archive by tag regardless of status
    let out = ok(&home, &["archive", "--tag", "legacy", "--force"]);
    assert!(out.contains("archived 1 task(s)"), "{out}");
    let out = ok(&home, &["list"]);
    assert!(!out.contains("Tagged old"), "{out}");

    // nested archive dirs are skipped at any depth
    std::fs::create_dir_all(lib_path.join("proj-a/archive/2026-01")).unwrap();
    std::fs::write(
        lib_path.join("proj-a/archive/2026-01/nested.md"),
        "---\nid: 00000000-0000-0000-0000-0000000000aa\nseq: 99\ntitle: Nested archived\ncreated_at: 2026-01-01T00:00:00Z\n---\n",
    )
    .unwrap();
    let out = run(&home, &["list"]);
    let stdout = String::from_utf8_lossy(&out.stdout).to_string();
    assert!(!stdout.contains("Nested archived"), "{stdout}");
    assert!(!String::from_utf8_lossy(&out.stderr).contains("warning"));
    // still browsable with an explicit scope
    let out = ok(&home, &["list", "--dir", "proj-a/archive/2026-01"]);
    assert!(out.contains("Nested archived"), "{out}");

    // nothing left matching the default rule
    let out = ok(&home, &["archive", "--force"]);
    assert!(out.contains("no tasks to archive"), "{out}");

    std::fs::remove_dir_all(&home).unwrap();
}

#[test]
fn three_block_document_layout() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-blocks-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);
    ok(&home, &["new", "Layout task"]);

    // build a content block first
    ok(&home, &["log", "1", "## 详细说明", "--quiet"]);
    ok(&home, &["log", "1", "一些正文内容", "--quiet"]);

    // step add creates the TODO block above the content block
    ok(&home, &["step", "add", "1", "第一步"]);
    ok(&home, &["step", "add", "1", "第二步"]);
    let file = std::fs::read_dir(&lib_path)
        .unwrap()
        .filter_map(|e| e.ok())
        .find(|e| e.path().extension().is_some_and(|x| x == "md"))
        .unwrap()
        .path();
    let content = std::fs::read_to_string(&file).unwrap();
    let body = content.split("---\n").nth(2).unwrap();
    let todo_pos = body.find("- [ ] 第一步").unwrap();
    let content_pos = body.find("## 详细说明").unwrap();
    assert!(todo_pos < content_pos, "TODO block must precede content:\n{body}");
    assert!(body.find("- [ ] 第二步").unwrap() < content_pos, "{body}");

    // checkboxes written into the content block are not steps
    ok(&home, &["log", "1", "--quiet", "--", "- [ ] 这只是正文里的文本"]);
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("steps:     0/2"), "{out}");

    // step done addresses TODO-block checkboxes only
    let out = ok(&home, &["step", "done", "1", "s2"]);
    assert!(out.contains("progress: 1/2"), "{out}");
    let out = run(&home, &["step", "done", "1", "s3"]);
    assert!(!out.status.success(), "content checkbox must not be s3");

    // step get lists the TODO block with step ids
    let out = ok(&home, &["step", "get", "1"]);
    assert!(out.contains("s1 [ ] 第一步"), "{out}");
    assert!(out.contains("s2 [x] 第二步"), "{out}");
    assert!(out.contains("progress: 1/2"), "{out}");
    // alias
    let out = ok(&home, &["step", "list", "1"]);
    assert!(out.contains("s1 [ ] 第一步"), "{out}");

    std::fs::remove_dir_all(&home).unwrap();
}

fn repl(home: &Path, script: &str) -> Output {
    use std::io::Write;
    let mut child = Command::new(env!("CARGO_BIN_EXE_tasks"))
        .env("TASKS_CLI_HOME", home)
        .arg("repl")
        .stdin(std::process::Stdio::piped())
        .stdout(std::process::Stdio::piped())
        .stderr(std::process::Stdio::piped())
        .spawn()
        .expect("failed to spawn repl");
    child.stdin.as_mut().unwrap().write_all(script.as_bytes()).unwrap();
    child.wait_with_output().unwrap()
}

#[test]
fn repl_workbench() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-repl-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);

    // create, select, and drive a task entirely from the workbench
    let out = repl(
        &home,
        "/add 重构存储层 -D 抽出接口层\n/use 1\n/start\n/step add 设计接口\n/step done s1\n/quit\n",
    );
    assert!(out.status.success());
    let stdout = String::from_utf8_lossy(&out.stdout).to_string();
    assert!(stdout.contains("=== 进行中 ==="), "{stdout}");
    assert!(stdout.contains("* #1 [medium] 重构存储层"), "selection marker: {stdout}");
    assert!(stdout.contains("抽出接口层"), "{stdout}");
    assert!(stdout.contains("s1 [x] 设计接口"), "{stdout}");
    assert!(stdout.contains("tasks[#1]>"), "prompt shows context: {stdout}");
    // /use prints the task details right away
    assert!(stdout.contains("uuid:"), "/use shows the task: {stdout}");
    assert!(stdout.contains("file:"), "/use shows the task: {stdout}");

    // state was persisted to disk by each command
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("status:    in_progress"), "{out}");
    assert!(out.contains("steps:     1/1"), "{out}");

    // help, bad prefix, unknown command, and /unuse
    let out = repl(&home, "/help\nnot-a-slash\n/nonsense\n/unuse\n/quit\n");
    let stdout = String::from_utf8_lossy(&out.stdout).to_string();
    let stderr = String::from_utf8_lossy(&out.stderr).to_string();
    assert!(stdout.contains("/use <id>"), "{stdout}");
    assert!(stderr.contains("must start with '/'"), "{stderr}");
    assert!(stderr.contains("unrecognized subcommand"), "{stderr}");
    assert!(
        !stderr.contains("invalid task file"),
        "clap errors must not be wrapped: {stderr}"
    );

    // the prompt is echoed exactly once per command when piped
    let out = repl(&home, "/list\n/quit\n");
    let stdout = String::from_utf8_lossy(&out.stdout).to_string();
    assert!(stdout.contains("tasks> /list"), "{stdout}");
    assert!(!stdout.contains("tasks> tasks>"), "duplicated prompt: {stdout}");

    // read-only commands print their result without redrawing the dashboard
    let dashboards = stdout.matches("=== 进行中 ===").count();
    assert_eq!(dashboards, 1, "only the startup dashboard: {stdout}");

    // Ctrl-D (EOF) exits cleanly, and nesting the repl is refused
    let out = repl(&home, "/repl\n");
    assert!(out.status.success());
    assert!(String::from_utf8_lossy(&out.stderr).contains("already in the workbench"));

    // dashboard summarises non-active tasks as counts
    ok(&home, &["new", "Pending one"]);
    let out = repl(&home, "/quit\n");
    let stdout = String::from_utf8_lossy(&out.stdout).to_string();
    assert!(stdout.contains("todo 1"), "{stdout}");
    // pending tasks now show up in the Top N column
    assert!(stdout.contains("=== 待办 Top"), "{stdout}");
    assert!(stdout.contains("Pending one"), "{stdout}");

    std::fs::remove_dir_all(&home).unwrap();
}

#[test]
fn description_field() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-desc-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);

    // set at creation
    ok(&home, &[
        "new",
        "重构存储层",
        "--description",
        "现有实现把文件 IO 和业务逻辑耦合在一起,需要抽出接口层以便未来替换后端。",
    ]);
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("desc:      现有实现把文件 IO"), "{out}");

    // title stays short (filename slug) while description carries the detail
    let file = std::fs::read_dir(&lib_path)
        .unwrap()
        .filter_map(|e| e.ok())
        .find(|e| e.path().extension().is_some_and(|x| x == "md"))
        .unwrap()
        .file_name()
        .to_string_lossy()
        .to_string();
    assert!(file.contains("重构存储层"), "{file}");
    assert!(!file.contains("耦合"), "description must not leak into filename: {file}");

    // searchable
    let out = ok(&home, &["search", "抽出接口层"]);
    assert!(out.contains("重构存储层"), "{out}");

    // update and clear
    ok(&home, &["set", "1", "--description", "新的简介"]);
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("desc:      新的简介"), "{out}");
    ok(&home, &["set", "1", "--description", "none"]);
    let out = ok(&home, &["show", "1"]);
    assert!(!out.contains("desc:"), "{out}");

    // omitted description keeps the field out of the YAML entirely
    ok(&home, &["new", "无简介任务"]);
    let content = std::fs::read_to_string(
        std::fs::read_dir(&lib_path)
            .unwrap()
            .filter_map(|e| e.ok())
            .map(|e| e.path())
            .find(|p| p.to_string_lossy().contains("无简介任务"))
            .unwrap(),
    )
    .unwrap();
    assert!(!content.contains("description:"), "{content}");

    std::fs::remove_dir_all(&home).unwrap();
}

#[test]
fn log_rewrite_strike() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-body-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);
    ok(&home, &["new", "Test task"]);

    // append to empty body
    let out = ok(&home, &["log", "1", "## Notes"]);
    assert!(out.contains("## Notes"), "{out}");

    // append after a specific line
    let out = ok(&home, &["log", "1", "first note", "--after", "Notes"]);
    assert!(out.contains("## Notes\nfirst note"), "{out}");

    // append --after with no match errors
    let out = run(&home, &["log", "1", "x", "--after", "nonexistent"]);
    assert!(!out.status.success());

    // replace a line (contains match)
    let out = ok(&home, &["rewrite", "1", "first note", "updated note"]);
    assert!(out.contains("updated note"), "{out}");
    assert!(!out.contains("first note"), "{out}");

    // replace with ambiguous match errors
    ok(&home, &["log", "1", "dup line A"]);
    // `note` is an alias for `log`
    ok(&home, &["note", "1", "dup line B"]);
    let out = run(&home, &["rewrite", "1", "dup line", "x"]);
    assert!(!out.status.success());
    assert!(String::from_utf8_lossy(&out.stderr).contains("2 lines"));

    // delete a line (starts_with match, unique)
    let out = ok(&home, &["strike", "1", "dup line A"]);
    assert!(!out.contains("dup line A"), "{out}");
    ok(&home, &["strike", "1", "dup line B"]);

    // delete with no match errors
    let out = run(&home, &["strike", "1", "nonexistent"]);
    assert!(!out.status.success());

    // --quiet suppresses output
    let out = ok(&home, &["log", "1", "silent line", "--quiet"]);
    assert!(out.is_empty(), "{out}");

    // --stdin reads from stdin
    let out = Command::new(env!("CARGO_BIN_EXE_tasks"))
        .env("TASKS_CLI_HOME", &home)
        .args(["log", "1", "--stdin", "--quiet"])
        .stdin(std::process::Stdio::piped())
        .stdout(std::process::Stdio::piped())
        .spawn()
        .and_then(|mut child| {
            use std::io::Write;
            child.stdin.as_mut().unwrap().write_all(b"from stdin\n").unwrap();
            child.wait_with_output()
        })
        .unwrap();
    assert!(out.status.success());
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("from stdin"), "{out}");

    std::fs::remove_dir_all(&home).unwrap();
}

#[test]
fn migration_from_yaml_steps() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-migrate-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);

    // Write a v0.2-format file with YAML steps
    std::fs::write(
        lib_path.join("old-task-abc12345.md"),
        "---\nid: abc12345-0000-0000-0000-000000000000\nseq: 1\ntitle: Legacy task\ncreated_at: 2026-01-01T00:00:00Z\nsteps:\n  - id: s1\n    title: Design\n    status: done\n  - id: s2\n    title: Implement\n    status: todo\n---\n\nOriginal body.\n",
    )
    .unwrap();

    // show works and displays migrated steps
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains("steps:     1/2"), "{out}");
    assert!(out.contains("- [x] Design"), "{out}");
    assert!(out.contains("- [ ] Implement"), "{out}");

    // step commands work on migrated steps
    let out = ok(&home, &["step", "done", "1", "s2"]);
    assert!(out.contains("progress: 2/2"), "{out}");

    // file is now migrated: no steps in YAML, checkboxes in body
    let content = std::fs::read_to_string(lib_path.join("old-task-abc12345.md")).unwrap();
    assert!(!content.contains("steps:"), "YAML steps removed: {content}");
    assert!(content.contains("- [x] Design"));
    assert!(content.contains("- [x] Implement"));

    std::fs::remove_dir_all(&home).unwrap();
}

#[test]
fn validation_friendly_errors() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-valid-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);

    // bad status value — file is skipped, not crash
    std::fs::write(
        lib_path.join("bad-status.md"),
        "---\nid: 00000000-0000-0000-0000-000000000001\nseq: 1\ntitle: T\nstatus: bogus\ncreated_at: 2026-01-01T00:00:00Z\n---\n",
    )
    .unwrap();
    // empty title — also skipped
    std::fs::write(
        lib_path.join("empty-title.md"),
        "---\nid: 00000000-0000-0000-0000-000000000002\nseq: 2\ntitle: \"  \"\ncreated_at: 2026-01-01T00:00:00Z\n---\n",
    )
    .unwrap();

    // list reports skipped files as a one-line summary
    let out = run(&home, &["list"]);
    let stderr = String::from_utf8_lossy(&out.stderr).to_string();
    assert!(stderr.contains("2 non-task file(s)"), "{stderr}");
    assert!(stderr.contains("tasks adopt"), "{stderr}");

    // adopt refuses them (they have front matter, just invalid)
    // but they show up as candidates
    let out = ok(&home, &["adopt", "--dry-run"]);
    assert!(out.contains("would adopt"), "{out}");

    std::fs::remove_dir_all(&home).unwrap();
}

fn rule_file(lib: &Path) -> std::path::PathBuf {
    std::fs::read_dir(lib.join(".recurring"))
        .expect("missing .recurring dir")
        .map(|e| e.unwrap().path())
        .find(|p| p.extension().is_some_and(|x| x == "md"))
        .expect("no rule file")
}

/// Rewrites next_run so the test can pretend the CLI has not run for a while.
fn rewind_next_run(path: &Path, to: chrono::NaiveDate) {
    let content = std::fs::read_to_string(path).unwrap();
    let rewritten: String = content
        .lines()
        .map(|line| {
            if line.starts_with("next_run:") {
                format!("next_run: {to}")
            } else {
                line.to_string()
            }
        })
        .collect::<Vec<_>>()
        .join("\n");
    std::fs::write(path, format!("{rewritten}\n")).unwrap();
}

#[test]
fn recurring_rules_generate_tasks_lazily() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-recur-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);
    let today = chrono::Local::now().date_naive();

    // a daily rule created today is due today
    let out = ok(&home, &["recur", "add", "每日站会", "--rule", "daily", "--tag", "daily"]);
    assert!(out.contains("created rule"), "{out}");
    assert!(out.contains(&format!("next: {today}")), "{out}");

    let out = ok(&home, &["recur", "list"]);
    assert!(out.contains("daily") && out.contains("每日站会"), "{out}");

    // any command materialises what is due, and says so on stderr
    let out = run(&home, &["list"]);
    assert!(out.status.success());
    let stderr = String::from_utf8_lossy(&out.stderr).to_string();
    assert!(stderr.contains("generated 1 recurring task(s)"), "{stderr}");
    assert!(String::from_utf8_lossy(&out.stdout).contains("每日站会"));

    // the instance carries the cycle it stands for and the rule's tags
    let out = ok(&home, &["show", "1"]);
    assert!(out.contains(&format!("occurs:    {today}")), "{out}");
    assert!(out.contains("daily"), "{out}");

    // running again is a no-op: next_run already moved past today
    let out = run(&home, &["list"]);
    assert!(!String::from_utf8_lossy(&out.stderr).contains("generated"));
    let out = ok(&home, &["recur", "tick"]);
    assert!(out.contains("no rules are due"), "{out}");

    // ten missed days collapse into a single task for the latest cycle
    let path = rule_file(&lib_path);
    rewind_next_run(&path, today - chrono::Duration::days(10));
    let out = ok(&home, &["recur", "tick"]);
    assert!(out.contains("created task #2"), "{out}");
    assert!(out.contains(&format!("for {today}")), "{out}");
    assert!(out.contains("generated 1 task(s)"), "{out}");

    // the previous instance is still open, and that does not block the next one
    rewind_next_run(&path, today);
    let out = ok(&home, &["recur", "tick"]);
    assert!(out.contains("created task #3"), "{out}");

    // paused rules stay put until resumed
    ok(&home, &["recur", "pause", "每日"]);
    rewind_next_run(&path, today);
    let out = ok(&home, &["recur", "tick"]);
    assert!(out.contains("no rules are due"), "{out}");
    let out = ok(&home, &["recur", "list"]);
    assert!(out.contains("paused"), "{out}");
    ok(&home, &["recur", "resume", "每日"]);
    let out = ok(&home, &["recur", "tick"]);
    assert!(out.contains("created task #4"), "{out}");

    let out = ok(&home, &["recur", "show", "每日"]);
    assert!(out.contains("generated: 4"), "{out}");
    assert!(out.contains("rule:      daily"), "{out}");

    // removing a rule keeps the tasks it produced
    ok(&home, &["recur", "remove", "每日", "--force"]);
    let out = ok(&home, &["recur", "list"]);
    assert!(out.contains("no rules"), "{out}");
    let out = ok(&home, &["list"]);
    assert!(out.contains("每日站会"), "{out}");

    std::fs::remove_dir_all(&home).unwrap();
}

#[test]
fn recurring_rule_bounds_and_bad_syntax() {
    let home = std::env::temp_dir().join(format!("tasks-e2e-recur-bounds-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&home);
    std::fs::create_dir_all(&home).unwrap();
    let lib_path = home.join("repos/personal");
    ok(&home, &["lib", "add", "personal", lib_path.to_str().unwrap()]);
    let today = chrono::Local::now().date_naive();

    // unsupported syntax is rejected with the accepted forms listed
    let out = run(&home, &["recur", "add", "x", "--rule", "0 9 * * 1"]);
    assert!(!out.status.success());
    let stderr = String::from_utf8_lossy(&out.stderr).to_string();
    assert!(stderr.contains("invalid recurrence rule"), "{stderr}");
    assert!(stderr.contains("weekly:mon,thu"), "{stderr}");

    // until before start is refused
    let out = run(&home, &[
        "recur", "add", "y", "--rule", "daily", "--start", "2026-08-01", "--until", "2026-07-01",
    ]);
    assert!(!out.status.success());

    // max_count stops the rule for good
    ok(&home, &["recur", "add", "打卡", "--rule", "daily", "--max-count", "1"]);
    let out = ok(&home, &["recur", "tick"]);
    assert!(out.contains("created task #1"), "{out}");
    let path = rule_file(&lib_path);
    rewind_next_run(&path, today);
    let out = ok(&home, &["recur", "tick"]);
    assert!(out.contains("no rules are due"), "{out}");
    let out = ok(&home, &["recur", "list"]);
    assert!(out.contains("finished") && out.contains("1/1"), "{out}");

    // a weekly rule lands on the next matching local weekday
    ok(&home, &["recur", "add", "周报", "--rule", "weekly:mon", "--start", "2026-08-01"]);
    let out = ok(&home, &["recur", "show", "周报"]);
    assert!(out.contains("next:      2026-08-03"), "{out}");
    assert!(out.contains("start:     2026-08-01"), "{out}");

    // rule files never show up as tasks or as skipped non-task files
    let out = run(&home, &["list"]);
    let stderr = String::from_utf8_lossy(&out.stderr).to_string();
    assert!(!stderr.contains("non-task file"), "{stderr}");
    assert!(!String::from_utf8_lossy(&out.stdout).contains("周报"), "rules are not tasks");

    std::fs::remove_dir_all(&home).unwrap();
}