tedi 0.16.3

Personal productivity CLI for task tracking, time management, and GitHub issue integration
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
//! Integration tests for blocker commands in integrated mode (issue files).
//!
//! These tests verify that `blocker add` and `blocker pop` work correctly
//! when operating on issue files (integrated mode) rather than standalone blocker files.

use crate::common::{
	TestContext,
	are_you_sure::{UnsafePathExt, read_issue_file},
	parse_virtual,
};

/// Build a MilestoneBlockerCache JSON from embedded issue title lines.
/// `titles` is a list of `(title, user, url)` tuples.
fn milestone_cache_json(titles: &[(&str, &str, &str)], current_index: usize) -> String {
	milestone_cache_json_with_refs(titles, current_index, &[])
}

/// Build a MilestoneBlockerCache JSON with ref_targets annotations.
/// `ref_targets` is a list of `(source_url, target_url)` tuples.
fn milestone_cache_json_with_refs(titles: &[(&str, &str, &str)], current_index: usize, ref_targets: &[(&str, &str)]) -> String {
	let description: String = titles
		.iter()
		.enumerate()
		.map(|(i, (title, user, url))| {
			let sep = if i + 1 < titles.len() { "\n\n" } else { "" };
			format!("- [ ] {title} <!-- @{user} {url} -->{sep}")
		})
		.collect();
	let refs: serde_json::Map<String, serde_json::Value> = ref_targets.iter().map(|(src, tgt)| (src.to_string(), serde_json::Value::String(tgt.to_string()))).collect();
	serde_json::json!({
		"current_index": current_index,
		"milestone_description": description,
		"ref_targets": refs
	})
	.to_string()
}

#[tokio::test]
async fn test_blocker_pop_in_integrated_mode() {
	let ctx = TestContext::build_with_preexisting_state_unsafe("");

	// Create issue with multiple blockers
	let vi = parse_virtual(
		r#"- [ ] Test Issue <!-- @mock_user https://github.com/o/r/issues/1 -->

  Body text.

  # Blockers
  - First task
  - Second task
  - Third task
"#,
	);

	// Set up: local issue file exists
	let issue = ctx.local(&vi, None).await;
	let issue_path = ctx.resolve_issue_path(&issue);

	// Set this issue as the current blocker issue via milestone cache
	ctx.xdg.write_cache(
		"milestone_blockers.json",
		&milestone_cache_json(&[("Test Issue", "mock_user", "https://github.com/o/r/issues/1")], 0),
	);

	// Run blocker pop in integrated mode (no --individual-files flag)
	let out = ctx.run(&["--offline", "blocker", "pop"]);

	eprintln!("stdout: {}", out.stdout);
	eprintln!("stderr: {}", out.stderr);

	assert!(out.status.success(), "blocker pop should succeed in integrated mode. stderr: {}", out.stderr);

	// Third task popped, First and Second remain
	insta::assert_snapshot!(read_issue_file(&issue_path), @"
	- [ ] Test Issue <!-- @mock_user https://github.com/o/r/issues/1 -->
	    Body text.

	  # Blockers
	  - First task
	  - Second task
	");
}

#[tokio::test]
async fn test_blocker_add_creates_blockers_section_if_missing() {
	let ctx = TestContext::build_with_preexisting_state_unsafe("");

	// Create issue WITHOUT blockers section
	let vi = parse_virtual(
		r#"- [ ] Test Issue <!-- @mock_user https://github.com/o/r/issues/1 -->
	Body text without blockers section.
"#,
	);

	// Set up: local issue file exists
	let issue = ctx.local(&vi, None).await;
	let issue_path = ctx.resolve_issue_path(&issue);

	// Set this issue as the current blocker issue via milestone cache
	ctx.xdg.write_cache(
		"milestone_blockers.json",
		&milestone_cache_json(&[("Test Issue", "mock_user", "https://github.com/o/r/issues/1")], 0),
	);

	// Run blocker add in integrated mode
	let out = ctx.run(&["--offline", "blocker", "add", "New task"]);

	eprintln!("stdout: {}", out.stdout);
	eprintln!("stderr: {}", out.stderr);

	assert!(out.status.success(), "blocker add should succeed even without existing blockers section. stderr: {}", out.stderr);

	// blockers section created with new task
	insta::assert_snapshot!(read_issue_file(&issue_path), @"
	- [ ] Test Issue <!-- @mock_user https://github.com/o/r/issues/1 -->
	    Body text without blockers section.

	  # Blockers
	  - New task
	");
}

#[tokio::test]
async fn test_blocker_add_urgent_without_blocker_file_set() {
	// Regression test: `blocker add --urgent` should work even without a blocker file set.
	// The urgent file is owner-independent and doesn't need blocker file context.
	// Previously this errored with "No blocker file set. Use `todo blocker set <pattern>` first."
	let ctx = TestContext::build_with_preexisting_state_unsafe("");

	// NO blocker file set - this is the key part of the test

	// Run blocker add --urgent
	let out = ctx.run(&["--offline", "blocker", "add", "--urgent", "manage through 'urgent' until tool is working"]);

	eprintln!("stdout: {}", out.stdout);
	eprintln!("stderr: {}", out.stderr);

	assert!(
		out.status.success() && out.stdout.contains("urgent"),
		"Should succeed and confirm urgent add. stdout: {}, stderr: {}",
		out.stdout,
		out.stderr
	);
}

#[tokio::test]
async fn test_blocker_add_with_nested_context() {
	let ctx = TestContext::build_with_preexisting_state_unsafe("");

	// Create issue with blockers section containing nested items
	let vi = parse_virtual(
		r#"- [ ] Test Issue <!-- @mock_user https://github.com/o/r/issues/1 -->
description

  # Blockers
  - Phase 1
    - Setup task
  - Phase 2
    - Implementation task
"#,
	);

	// Set up: local issue file exists
	let issue = ctx.local(&vi, None).await;
	let issue_path = ctx.resolve_issue_path(&issue);

	// Set this issue as the current blocker issue via milestone cache
	ctx.xdg.write_cache(
		"milestone_blockers.json",
		&milestone_cache_json(&[("Test Issue", "mock_user", "https://github.com/o/r/issues/1")], 0),
	);

	// Run blocker add in integrated mode
	let out = ctx.run(&["--offline", "blocker", "add", "New sub-task"]);

	eprintln!("stdout: {}", out.stdout);
	eprintln!("stderr: {}", out.stderr);

	assert!(out.status.success(), "blocker add should succeed. stderr: {}", out.stderr);

	// new sub-task added under Phase 2
	insta::assert_snapshot!(read_issue_file(&issue_path), @"
	- [ ] Test Issue <!-- @mock_user https://github.com/o/r/issues/1 -->
	    description

	  # Blockers
	  - Phase 1
	    - Setup task
	  - Phase 2
	    - Implementation task
	    - New sub-task
	");
}

#[tokio::test]
async fn test_blocker_move_up_cycles_between_entries() {
	let ctx = TestContext::build_with_preexisting_state_unsafe("");

	// Create two issues
	let vi1 = parse_virtual(
		r#"- [ ] Issue A <!-- @mock_user https://github.com/o/r/issues/1 -->

  # Blockers
  - task A
"#,
	);
	let vi2 = parse_virtual(
		r#"- [ ] Issue B <!-- @mock_user https://github.com/o/r/issues/2 -->

  # Blockers
  - task B
"#,
	);

	let issue1 = ctx.local(&vi1, None).await;
	let issue2 = ctx.local(&vi2, None).await;
	let _path1 = ctx.resolve_issue_path(&issue1);
	let _path2 = ctx.resolve_issue_path(&issue2);

	// Set up milestone cache with two embedded issues, pointing at first
	ctx.xdg.write_cache(
		"milestone_blockers.json",
		&milestone_cache_json(
			&[
				("Issue A", "mock_user", "https://github.com/o/r/issues/1"),
				("Issue B", "mock_user", "https://github.com/o/r/issues/2"),
			],
			0,
		),
	);

	// Current should show task A
	let out = ctx.run(&["--offline", "blocker", "current"]);
	assert!(out.stdout.contains("task A"), "Before move, current should be task A. stdout: {}", out.stdout);

	// Move up should switch to issue B
	let out = ctx.run(&["--offline", "blocker", "move", "up"]);
	assert!(out.status.success(), "move up should succeed. stderr: {}", out.stderr);
	assert!(
		out.stdout.contains("Issue B") || out.stdout.contains("task B"),
		"move up should switch to B. stdout: {}",
		out.stdout
	);

	// Current should now show task B
	let out = ctx.run(&["--offline", "blocker", "current"]);
	assert!(out.stdout.contains("task B"), "After move up, current should be task B. stdout: {}", out.stdout);

	// Move up again should wrap back to issue A
	let out = ctx.run(&["--offline", "blocker", "move", "up"]);
	assert!(out.status.success(), "second move up should succeed. stderr: {}", out.stderr);

	let out = ctx.run(&["--offline", "blocker", "current"]);
	assert!(out.stdout.contains("task A"), "After second move up, should be back to task A. stdout: {}", out.stdout);
}

#[tokio::test]
async fn test_blocker_move_up_with_three_entries_cycles() {
	let ctx = TestContext::build_with_preexisting_state_unsafe("");

	let vi1 = parse_virtual(
		r#"- [ ] Issue A <!-- @mock_user https://github.com/o/r/issues/1 -->

  # Blockers
  - task A
"#,
	);
	let vi2 = parse_virtual(
		r#"- [ ] Issue B <!-- @mock_user https://github.com/o/r/issues/2 -->

  # Blockers
  - task B
"#,
	);
	let vi3 = parse_virtual(
		r#"- [ ] Issue C <!-- @mock_user https://github.com/o/r/issues/3 -->

  # Blockers
  - task C
"#,
	);

	ctx.local(&vi1, None).await;
	ctx.local(&vi2, None).await;
	ctx.local(&vi3, None).await;

	// Set up milestone cache with three embedded issues, pointing at first
	ctx.xdg.write_cache(
		"milestone_blockers.json",
		&milestone_cache_json(
			&[
				("Issue A", "mock_user", "https://github.com/o/r/issues/1"),
				("Issue B", "mock_user", "https://github.com/o/r/issues/2"),
				("Issue C", "mock_user", "https://github.com/o/r/issues/3"),
			],
			0,
		),
	);

	// Move up A→B
	let out = ctx.run(&["--offline", "blocker", "move", "up"]);
	assert!(out.status.success(), "move up should succeed. stderr: {}", out.stderr);
	let out = ctx.run(&["--offline", "blocker", "current"]);
	assert!(out.stdout.contains("task B"), "After first move up, should be B. stdout: {}", out.stdout);

	// Move up B→C
	let out = ctx.run(&["--offline", "blocker", "move", "up"]);
	assert!(out.status.success());
	let out = ctx.run(&["--offline", "blocker", "current"]);
	assert!(out.stdout.contains("task C"), "After second move up, should be C. stdout: {}", out.stdout);

	// Move up C→A (wrap)
	let out = ctx.run(&["--offline", "blocker", "move", "up"]);
	assert!(out.status.success());
	let out = ctx.run(&["--offline", "blocker", "current"]);
	assert!(out.stdout.contains("task A"), "After third move up, should wrap to A. stdout: {}", out.stdout);
}

#[tokio::test]
async fn test_blocker_move_single_entry_errors() {
	let ctx = TestContext::build_with_preexisting_state_unsafe("");

	let vi = parse_virtual(
		r#"- [ ] Issue A <!-- @mock_user https://github.com/o/r/issues/1 -->

  # Blockers
  - task A
"#,
	);

	ctx.local(&vi, None).await;

	// Single entry in milestone cache
	ctx.xdg.write_cache(
		"milestone_blockers.json",
		&milestone_cache_json(&[("Issue A", "mock_user", "https://github.com/o/r/issues/1")], 0),
	);

	// Move up should fail with single entry
	let out = ctx.run(&["--offline", "blocker", "move", "up"]);
	assert!(!out.status.success(), "move with single entry should fail. stdout: {}", out.stdout);
	assert!(out.stderr.contains("Only one issue"), "error should mention single issue. stderr: {}", out.stderr);
}

#[tokio::test]
async fn test_blocker_add_works_after_move() {
	let ctx = TestContext::build_with_preexisting_state_unsafe("");

	let vi1 = parse_virtual(
		r#"- [ ] Issue A <!-- @mock_user https://github.com/o/r/issues/1 -->

  # Blockers
  - task A
"#,
	);
	let vi2 = parse_virtual(
		r#"- [ ] Issue B <!-- @mock_user https://github.com/o/r/issues/2 -->

  # Blockers
  - task B
"#,
	);

	let issue1 = ctx.local(&vi1, None).await;
	let issue2 = ctx.local(&vi2, None).await;
	let path1 = ctx.resolve_issue_path(&issue1);
	let path2 = ctx.resolve_issue_path(&issue2);

	// Start on A, move up to B
	ctx.xdg.write_cache(
		"milestone_blockers.json",
		&milestone_cache_json(
			&[
				("Issue A", "mock_user", "https://github.com/o/r/issues/1"),
				("Issue B", "mock_user", "https://github.com/o/r/issues/2"),
			],
			0,
		),
	);
	ctx.run(&["--offline", "blocker", "move", "up"]);

	// Add a blocker - should go into Issue B (the now-current one)
	let out = ctx.run(&["--offline", "blocker", "add", "new task on B"]);
	assert!(out.status.success(), "add should succeed after move. stderr: {}", out.stderr);

	// Verify it went into issue B
	insta::assert_snapshot!(read_issue_file(&path2), @"
	- [ ] Issue B <!-- @mock_user https://github.com/o/r/issues/2 -->
	  # Blockers
	  - task B
	  - new task on B
	");

	// Issue A should be untouched
	insta::assert_snapshot!(read_issue_file(&path1), @"
	- [ ] Issue A <!-- @mock_user https://github.com/o/r/issues/1 -->
	  # Blockers
	  - task A
	");
}

#[tokio::test]
async fn test_blocker_move_skips_ref_annotated_issues() {
	let ctx = TestContext::build_with_preexisting_state_unsafe("");

	// Create three issues: A (real task), B (delegates to C via ref), C (real task)
	let vi1 = parse_virtual(
		r#"- [ ] Issue A <!-- @mock_user https://github.com/o/r/issues/1 -->

  # Blockers
  - task A
"#,
	);
	let vi2 = parse_virtual(
		r#"- [ ] Issue B <!-- @mock_user https://github.com/o/r/issues/2 -->

  # Blockers
  - o/r#3
"#,
	);
	let vi3 = parse_virtual(
		r#"- [ ] Issue C <!-- @mock_user https://github.com/o/r/issues/3 -->

  # Blockers
  - task C
"#,
	);

	ctx.local(&vi1, None).await;
	ctx.local(&vi2, None).await;
	ctx.local(&vi3, None).await;

	// Set up milestone cache with ref_targets: B points at C
	ctx.xdg.write_cache(
		"milestone_blockers.json",
		&milestone_cache_json_with_refs(
			&[
				("Issue A", "mock_user", "https://github.com/o/r/issues/1"),
				("Issue B", "mock_user", "https://github.com/o/r/issues/2"),
				("Issue C", "mock_user", "https://github.com/o/r/issues/3"),
			],
			0,
			&[("https://github.com/o/r/issues/2", "https://github.com/o/r/issues/3")],
		),
	);

	// Starting at A (index 0), move up should skip B (ref-annotated) and land on C
	let out = ctx.run(&["--offline", "blocker", "move", "up"]);
	assert!(out.status.success(), "move up should succeed. stderr: {}", out.stderr);

	let out = ctx.run(&["--offline", "blocker", "current"]);
	assert!(out.stdout.contains("task C"), "Should skip B and land on C. stdout: {}", out.stdout);
}

#[tokio::test]
async fn test_blocker_move_all_refs_errors() {
	let ctx = TestContext::build_with_preexisting_state_unsafe("");

	// Create two issues, both with ref blockers
	let vi1 = parse_virtual(
		r#"- [ ] Issue A <!-- @mock_user https://github.com/o/r/issues/1 -->

  # Blockers
  - o/r#2
"#,
	);
	let vi2 = parse_virtual(
		r#"- [ ] Issue B <!-- @mock_user https://github.com/o/r/issues/2 -->

  # Blockers
  - o/r#1
"#,
	);

	ctx.local(&vi1, None).await;
	ctx.local(&vi2, None).await;

	// Both issues are ref-annotated
	ctx.xdg.write_cache(
		"milestone_blockers.json",
		&milestone_cache_json_with_refs(
			&[
				("Issue A", "mock_user", "https://github.com/o/r/issues/1"),
				("Issue B", "mock_user", "https://github.com/o/r/issues/2"),
			],
			0,
			&[
				("https://github.com/o/r/issues/1", "https://github.com/o/r/issues/2"),
				("https://github.com/o/r/issues/2", "https://github.com/o/r/issues/1"),
			],
		),
	);

	// Move should error: all issues have refs
	let out = ctx.run(&["--offline", "blocker", "move", "up"]);
	assert!(!out.status.success(), "move should fail when all issues have refs. stdout: {}", out.stdout);
	assert!(
		out.stderr.contains("All issues") || out.stderr.contains("Nothing to stop at"),
		"error should mention all refs. stderr: {}",
		out.stderr
	);
}

#[tokio::test]
async fn test_blocker_move_to_unique_pattern_selects_directly() {
	let ctx = TestContext::build_with_preexisting_state_unsafe("");

	let vi1 = parse_virtual(
		r#"- [ ] Issue Alpha <!-- @mock_user https://github.com/o/r/issues/1 -->

  # Blockers
  - task alpha
"#,
	);
	let vi2 = parse_virtual(
		r#"- [ ] Issue Beta <!-- @mock_user https://github.com/o/r/issues/2 -->

  # Blockers
  - task beta
"#,
	);

	ctx.local(&vi1, None).await;
	ctx.local(&vi2, None).await;

	ctx.xdg.write_cache(
		"milestone_blockers.json",
		&milestone_cache_json(
			&[
				("Issue Alpha", "mock_user", "https://github.com/o/r/issues/1"),
				("Issue Beta", "mock_user", "https://github.com/o/r/issues/2"),
			],
			0,
		),
	);

	// "beta" uniquely matches Issue Beta — should succeed without fzf
	let out = ctx.run(&["--offline", "blocker", "move", "to", "beta"]);
	assert!(out.status.success(), "unique match should succeed. stderr: {}", out.stderr);
	assert!(
		out.stdout.contains("Beta") || out.stdout.contains("beta"),
		"output should mention the selected issue. stdout: {}",
		out.stdout
	);

	// Current should now be task beta
	let out = ctx.run(&["--offline", "blocker", "current"]);
	assert!(out.stdout.contains("task beta"), "after move to beta, current should be task beta. stdout: {}", out.stdout);
}

#[tokio::test]
async fn test_blocker_move_to_no_match_errors() {
	let ctx = TestContext::build_with_preexisting_state_unsafe("");

	let vi1 = parse_virtual(
		r#"- [ ] Issue Alpha <!-- @mock_user https://github.com/o/r/issues/1 -->

  # Blockers
  - task alpha
"#,
	);

	ctx.local(&vi1, None).await;

	ctx.xdg.write_cache(
		"milestone_blockers.json",
		&milestone_cache_json(&[("Issue Alpha", "mock_user", "https://github.com/o/r/issues/1")], 0),
	);

	let out = ctx.run(&["--offline", "blocker", "move", "to", "zzznomatch"]);
	assert!(!out.status.success(), "no-match should fail. stdout: {}", out.stdout);
	assert!(out.stderr.contains("zzznomatch"), "error should mention the pattern. stderr: {}", out.stderr);
}

#[tokio::test]
async fn test_blocker_move_to_ambiguous_pattern_does_not_silently_pick_first() {
	// Regression test: before the fix, `move to issue` on a milestone with two issues
	// whose display paths both contain "issue" would silently select the first match.
	// After the fix, multiple matches trigger fzf; since there's no TTY in tests,
	// fzf exits with an error rather than silently returning the wrong issue.
	let ctx = TestContext::build_with_preexisting_state_unsafe("");

	let vi1 = parse_virtual(
		r#"- [ ] Issue One <!-- @mock_user https://github.com/o/r/issues/1 -->

  # Blockers
  - task one
"#,
	);
	let vi2 = parse_virtual(
		r#"- [ ] Issue Two <!-- @mock_user https://github.com/o/r/issues/2 -->

  # Blockers
  - task two
"#,
	);

	ctx.local(&vi1, None).await;
	ctx.local(&vi2, None).await;

	ctx.xdg.write_cache(
		"milestone_blockers.json",
		&milestone_cache_json(
			&[
				("Issue One", "mock_user", "https://github.com/o/r/issues/1"),
				("Issue Two", "mock_user", "https://github.com/o/r/issues/2"),
			],
			0,
		),
	);

	// "issue" matches both entries — must NOT silently select the first one
	let out = ctx.run(&["--offline", "blocker", "move", "to", "issue"]);
	// In a non-interactive context fzf fails (no TTY), so the command should fail
	// rather than silently return the first matching issue (the pre-fix behavior).
	assert!(
		!out.status.success(),
		"ambiguous pattern without a TTY should not silently pick the first match. stdout: {}",
		out.stdout
	);
}