beads_rust 0.2.13

Agent-first issue tracker (SQLite + JSONL)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
//! Comprehensive tests for the blocked_issues_cache correctness.
//!
//! Covers: cache rebuild triggers, ready/blocked consistency, reopen semantics,
//! chain dependencies, mixed dependency types, delete/tombstone cleanup,
//! remove-all-deps, parent-child transitive blocking, and cross-check of
//! `get_ready_issues` vs `get_blocked_ids`.
//!
//! Related bead: beads_rust-1kaf

#![allow(clippy::similar_names)]

mod common;

use beads_rust::model::{DependencyType, Status};
use beads_rust::storage::{IssueUpdate, ReadyFilters, ReadySortPolicy, SqliteStorage};
use common::{fixtures, test_db};

// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------

fn blocked_ids(storage: &SqliteStorage) -> Vec<String> {
    storage
        .get_blocked_issues()
        .unwrap()
        .into_iter()
        .map(|(issue, _)| issue.id)
        .collect()
}

fn ready_ids(storage: &SqliteStorage) -> Vec<String> {
    storage
        .get_ready_issues(&ReadyFilters::default(), ReadySortPolicy::Priority)
        .unwrap()
        .into_iter()
        .map(|i| i.id)
        .collect()
}

fn status_update(status: Status) -> IssueUpdate {
    IssueUpdate {
        status: Some(status),
        ..Default::default()
    }
}

// ===========================================================================
// 1. Reopen blocker → re-blocks dependent
// ===========================================================================

#[test]
fn reopen_blocker_re_blocks_dependent() {
    let mut storage = test_db();

    let blocker = fixtures::issue("reopen-blocker");
    let dependent = fixtures::issue("reopen-dependent");

    storage.create_issue(&blocker, "tester").unwrap();
    storage.create_issue(&dependent, "tester").unwrap();

    storage
        .add_dependency(
            &dependent.id,
            &blocker.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    // Dependent should be blocked
    assert!(
        blocked_ids(&storage).contains(&dependent.id),
        "dependent should be blocked initially"
    );

    // Close blocker → dependent unblocked
    storage
        .update_issue(&blocker.id, &status_update(Status::Closed), "tester")
        .unwrap();
    assert!(
        !blocked_ids(&storage).contains(&dependent.id),
        "dependent should be unblocked after closing blocker"
    );

    // Reopen blocker → dependent blocked again
    storage
        .update_issue(&blocker.id, &status_update(Status::Open), "tester")
        .unwrap();
    assert!(
        blocked_ids(&storage).contains(&dependent.id),
        "dependent should be re-blocked after reopening blocker"
    );
}

// ===========================================================================
// 2. Chain dependencies (A blocks B, B blocks C)
// ===========================================================================

#[test]
fn chain_dependency_blocks_downstream() {
    let mut storage = test_db();

    let a = fixtures::issue("chain-A");
    let b = fixtures::issue("chain-B");
    let c = fixtures::issue("chain-C");

    storage.create_issue(&a, "tester").unwrap();
    storage.create_issue(&b, "tester").unwrap();
    storage.create_issue(&c, "tester").unwrap();

    // A blocks B
    storage
        .add_dependency(&b.id, &a.id, DependencyType::Blocks.as_str(), "tester")
        .unwrap();

    // B blocks C
    storage
        .add_dependency(&c.id, &b.id, DependencyType::Blocks.as_str(), "tester")
        .unwrap();

    let ids = blocked_ids(&storage);
    assert!(ids.contains(&b.id), "B should be blocked by A");
    assert!(ids.contains(&c.id), "C should be blocked by B");

    // Close A → B unblocked, but C still blocked by B (B is open, not closed)
    storage
        .update_issue(&a.id, &status_update(Status::Closed), "tester")
        .unwrap();

    let ids = blocked_ids(&storage);
    assert!(!ids.contains(&b.id), "B should be unblocked after A closed");
    assert!(ids.contains(&c.id), "C should still be blocked by open B");

    // Close B → C finally unblocked
    storage
        .update_issue(&b.id, &status_update(Status::Closed), "tester")
        .unwrap();

    let ids = blocked_ids(&storage);
    assert!(!ids.contains(&c.id), "C should be unblocked after B closed");
}

// ===========================================================================
// 3. Multiple blockers — partial close leaves blocked
// ===========================================================================

#[test]
fn multiple_blockers_partial_close() {
    let mut storage = test_db();

    let blocker1 = fixtures::issue("multi-blocker-1");
    let blocker2 = fixtures::issue("multi-blocker-2");
    let dependent = fixtures::issue("multi-dependent");

    storage.create_issue(&blocker1, "tester").unwrap();
    storage.create_issue(&blocker2, "tester").unwrap();
    storage.create_issue(&dependent, "tester").unwrap();

    storage
        .add_dependency(
            &dependent.id,
            &blocker1.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();
    storage
        .add_dependency(
            &dependent.id,
            &blocker2.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    assert!(blocked_ids(&storage).contains(&dependent.id));

    // Close only blocker1 → still blocked by blocker2
    storage
        .update_issue(&blocker1.id, &status_update(Status::Closed), "tester")
        .unwrap();
    assert!(
        blocked_ids(&storage).contains(&dependent.id),
        "still blocked by blocker2"
    );

    // Close blocker2 → fully unblocked
    storage
        .update_issue(&blocker2.id, &status_update(Status::Closed), "tester")
        .unwrap();
    assert!(
        !blocked_ids(&storage).contains(&dependent.id),
        "unblocked after all blockers closed"
    );
}

// ===========================================================================
// 4. Mixed dependency types (blocks, conditional-blocks, waits-for)
// ===========================================================================

#[test]
fn mixed_dependency_types_all_block() {
    let mut storage = test_db();

    let b1 = fixtures::issue("mix-blocks-src");
    let b2 = fixtures::issue("mix-cond-src");
    let b3 = fixtures::issue("mix-waits-src");
    let target = fixtures::issue("mix-target");

    storage.create_issue(&b1, "tester").unwrap();
    storage.create_issue(&b2, "tester").unwrap();
    storage.create_issue(&b3, "tester").unwrap();
    storage.create_issue(&target, "tester").unwrap();

    storage
        .add_dependency(&target.id, &b1.id, "blocks", "tester")
        .unwrap();
    storage
        .add_dependency(&target.id, &b2.id, "conditional-blocks", "tester")
        .unwrap();
    storage
        .add_dependency(&target.id, &b3.id, "waits-for", "tester")
        .unwrap();

    let ids = blocked_ids(&storage);
    assert!(
        ids.contains(&target.id),
        "target should be blocked by all three dependency types"
    );

    // Close all blockers
    for blocker_id in [&b1.id, &b2.id, &b3.id] {
        storage
            .update_issue(blocker_id, &status_update(Status::Closed), "tester")
            .unwrap();
    }

    assert!(
        !blocked_ids(&storage).contains(&target.id),
        "target unblocked after all mixed deps closed"
    );
}

// ===========================================================================
// 5. Closing the blocked issue itself → removed from cache
// ===========================================================================

#[test]
fn closing_blocked_issue_removes_from_cache() {
    let mut storage = test_db();

    let blocker = fixtures::issue("close-self-blocker");
    let blocked_issue = fixtures::issue("close-self-blocked");

    storage.create_issue(&blocker, "tester").unwrap();
    storage.create_issue(&blocked_issue, "tester").unwrap();

    storage
        .add_dependency(
            &blocked_issue.id,
            &blocker.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    assert!(blocked_ids(&storage).contains(&blocked_issue.id));

    // Close the blocked issue itself (not the blocker)
    storage
        .update_issue(&blocked_issue.id, &status_update(Status::Closed), "tester")
        .unwrap();

    // Closed issues should not appear in blocked cache
    // (blocked cache only tracks open/in_progress issues)
    let ids = blocked_ids(&storage);
    assert!(
        !ids.contains(&blocked_issue.id),
        "closed issue should not appear in blocked cache"
    );
}

// ===========================================================================
// 6. Delete issue → cache cleaned
// ===========================================================================

#[test]
fn delete_issue_cleans_cache() {
    let mut storage = test_db();

    let blocker = fixtures::issue("del-blocker");
    let blocked_issue = fixtures::issue("del-blocked");

    storage.create_issue(&blocker, "tester").unwrap();
    storage.create_issue(&blocked_issue, "tester").unwrap();

    storage
        .add_dependency(
            &blocked_issue.id,
            &blocker.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    assert!(blocked_ids(&storage).contains(&blocked_issue.id));

    // Delete the blocker → blocked_issue should become unblocked
    // (tombstoned issues are terminal, so dependency no longer active)
    storage
        .delete_issue(&blocker.id, "tester", "test cleanup", None)
        .unwrap();

    let ids = blocked_ids(&storage);
    assert!(
        !ids.contains(&blocked_issue.id),
        "deleting blocker should unblock dependent"
    );
}

// ===========================================================================
// 7. Remove all dependencies → cache cleared
// ===========================================================================

#[test]
fn remove_all_dependencies_clears_cache() {
    let mut storage = test_db();

    let b1 = fixtures::issue("rm-all-b1");
    let b2 = fixtures::issue("rm-all-b2");
    let target = fixtures::issue("rm-all-target");

    storage.create_issue(&b1, "tester").unwrap();
    storage.create_issue(&b2, "tester").unwrap();
    storage.create_issue(&target, "tester").unwrap();

    storage
        .add_dependency(
            &target.id,
            &b1.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();
    storage
        .add_dependency(
            &target.id,
            &b2.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    assert!(blocked_ids(&storage).contains(&target.id));

    storage
        .remove_all_dependencies(&target.id, "tester")
        .unwrap();

    assert!(
        !blocked_ids(&storage).contains(&target.id),
        "removing all deps should unblock issue"
    );
}

// ===========================================================================
// 8. Transitive parent-child blocking
// ===========================================================================

#[test]
fn parent_child_transitive_blocking() {
    let mut storage = test_db();

    let blocker = fixtures::issue("pc-blocker");
    let parent = fixtures::issue("pc-parent");
    let child = fixtures::issue("pc-child");

    storage.create_issue(&blocker, "tester").unwrap();
    storage.create_issue(&parent, "tester").unwrap();
    storage.create_issue(&child, "tester").unwrap();

    // blocker blocks parent
    storage
        .add_dependency(
            &parent.id,
            &blocker.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    // child is child of parent
    storage
        .add_dependency(&child.id, &parent.id, "parent-child", "tester")
        .unwrap();

    let ids = blocked_ids(&storage);
    assert!(ids.contains(&parent.id), "parent blocked by blocker");
    assert!(
        ids.contains(&child.id),
        "child transitively blocked via parent"
    );

    // Close blocker → parent unblocked → child also unblocked
    storage
        .update_issue(&blocker.id, &status_update(Status::Closed), "tester")
        .unwrap();

    let ids = blocked_ids(&storage);
    assert!(!ids.contains(&parent.id), "parent unblocked");
    assert!(!ids.contains(&child.id), "child transitively unblocked");
}

// ===========================================================================
// 9. Remove parent → child unblocked if parent was sole reason
// ===========================================================================

#[test]
fn remove_parent_unblocks_child() {
    let mut storage = test_db();

    let blocker = fixtures::issue("rp-blocker");
    let parent = fixtures::issue("rp-parent");
    let child = fixtures::issue("rp-child");

    storage.create_issue(&blocker, "tester").unwrap();
    storage.create_issue(&parent, "tester").unwrap();
    storage.create_issue(&child, "tester").unwrap();

    storage
        .add_dependency(
            &parent.id,
            &blocker.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();
    storage
        .add_dependency(&child.id, &parent.id, "parent-child", "tester")
        .unwrap();

    assert!(
        blocked_ids(&storage).contains(&child.id),
        "child blocked via parent"
    );

    // Remove parent-child link
    storage
        .remove_dependency(&child.id, &parent.id, "tester")
        .unwrap();

    assert!(
        !blocked_ids(&storage).contains(&child.id),
        "child should be unblocked after parent link removed"
    );
}

// ===========================================================================
// 10. Ready/blocked cross-consistency
// ===========================================================================

#[test]
fn ready_and_blocked_are_disjoint() {
    let mut storage = test_db();

    let blocker = fixtures::issue("disjoint-blocker");
    let blocked_issue = fixtures::issue("disjoint-blocked");
    let free_issue = fixtures::issue("disjoint-free");

    storage.create_issue(&blocker, "tester").unwrap();
    storage.create_issue(&blocked_issue, "tester").unwrap();
    storage.create_issue(&free_issue, "tester").unwrap();

    storage
        .add_dependency(
            &blocked_issue.id,
            &blocker.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    let ready = ready_ids(&storage);
    let blocked = blocked_ids(&storage);

    // Blocked issues must not appear in ready list
    for id in &blocked {
        assert!(
            !ready.contains(id),
            "blocked issue {id} should not appear in ready list"
        );
    }

    // Free issue should be in ready list
    assert!(ready.contains(&free_issue.id), "free issue should be ready");

    // Blocked issue must be in blocked list, not ready
    assert!(blocked.contains(&blocked_issue.id));
    assert!(!ready.contains(&blocked_issue.id));
}

// ===========================================================================
// 11. is_blocked matches get_blocked_ids
// ===========================================================================

#[test]
fn is_blocked_matches_get_blocked_ids() {
    let mut storage = test_db();

    let blocker = fixtures::issue("ib-blocker");
    let blocked_issue = fixtures::issue("ib-blocked");
    let free_issue = fixtures::issue("ib-free");

    storage.create_issue(&blocker, "tester").unwrap();
    storage.create_issue(&blocked_issue, "tester").unwrap();
    storage.create_issue(&free_issue, "tester").unwrap();

    storage
        .add_dependency(
            &blocked_issue.id,
            &blocker.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    let blocked_set = storage.get_blocked_ids().unwrap();

    // is_blocked should agree with get_blocked_ids for every issue
    assert_eq!(
        storage.is_blocked(&blocked_issue.id).unwrap(),
        blocked_set.contains(&blocked_issue.id),
        "is_blocked should match for blocked issue"
    );
    assert_eq!(
        storage.is_blocked(&free_issue.id).unwrap(),
        blocked_set.contains(&free_issue.id),
        "is_blocked should match for free issue"
    );
    assert_eq!(
        storage.is_blocked(&blocker.id).unwrap(),
        blocked_set.contains(&blocker.id),
        "is_blocked should match for blocker (not blocked itself)"
    );
}

// ===========================================================================
// 12. Blocker metadata format
// ===========================================================================

#[test]
fn blocked_cache_stores_blocker_metadata() {
    let mut storage = test_db();

    let blocker = fixtures::issue("meta-blocker");
    let blocked_issue = fixtures::issue("meta-blocked");

    storage.create_issue(&blocker, "tester").unwrap();
    storage.create_issue(&blocked_issue, "tester").unwrap();

    storage
        .add_dependency(
            &blocked_issue.id,
            &blocker.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    let blocked_issues = storage.get_blocked_issues().unwrap();
    let entry = blocked_issues
        .iter()
        .find(|(issue, _)| issue.id == blocked_issue.id)
        .expect("blocked entry should exist");

    // Blocker references should contain the blocker's ID
    assert!(
        entry.1.iter().any(|r| r.contains(&blocker.id)),
        "blocker references should contain blocker ID, got: {:?}",
        entry.1
    );
}

// ===========================================================================
// 13. In-progress blocker still blocks
// ===========================================================================

#[test]
fn in_progress_blocker_still_blocks() {
    let mut storage = test_db();

    let blocker = fixtures::issue("ip-blocker");
    let dependent = fixtures::issue("ip-dependent");

    storage.create_issue(&blocker, "tester").unwrap();
    storage.create_issue(&dependent, "tester").unwrap();

    storage
        .add_dependency(
            &dependent.id,
            &blocker.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    // Move blocker to in_progress → should still block
    storage
        .update_issue(&blocker.id, &status_update(Status::InProgress), "tester")
        .unwrap();

    assert!(
        blocked_ids(&storage).contains(&dependent.id),
        "in_progress blocker should still block dependent"
    );
}

// ===========================================================================
// 14. Force rebuild produces same result as auto-rebuild
// ===========================================================================

#[test]
fn force_rebuild_matches_auto_rebuild() {
    let mut storage = test_db();

    let blocker = fixtures::issue("force-blocker");
    let blocked_issue = fixtures::issue("force-blocked");
    let free_issue = fixtures::issue("force-free");

    storage.create_issue(&blocker, "tester").unwrap();
    storage.create_issue(&blocked_issue, "tester").unwrap();
    storage.create_issue(&free_issue, "tester").unwrap();

    storage
        .add_dependency(
            &blocked_issue.id,
            &blocker.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    // Capture auto-rebuild state
    let auto_blocked = storage.get_blocked_ids().unwrap();

    // Force rebuild and compare
    storage.rebuild_blocked_cache(true).unwrap();
    let force_blocked = storage.get_blocked_ids().unwrap();

    assert_eq!(
        auto_blocked, force_blocked,
        "force rebuild should produce identical result to auto-rebuild"
    );
}

#[test]
fn force_rebuild_with_direct_blocker_dependency_succeeds() {
    let mut storage = test_db();

    let blocker = fixtures::issue("ok70-force-blocker");
    let blocked_issue = fixtures::issue("ok70-force-blocked");

    storage.create_issue(&blocker, "tester").unwrap();
    storage.create_issue(&blocked_issue, "tester").unwrap();

    storage
        .add_dependency(
            &blocked_issue.id,
            &blocker.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    let rebuilt = storage.rebuild_blocked_cache(true).unwrap();
    assert_eq!(rebuilt, 1, "force rebuild should persist one blocked issue");
    assert!(
        blocked_ids(&storage).contains(&blocked_issue.id),
        "force rebuild should keep the direct blocker in cache"
    );
}

// ===========================================================================
// 15. Deep transitive parent-child chain
// ===========================================================================

#[test]
fn deep_parent_child_chain_blocking() {
    let mut storage = test_db();

    let blocker = fixtures::issue("deep-blocker");
    let p1 = fixtures::issue("deep-parent-1");
    let p2 = fixtures::issue("deep-parent-2");
    let p3 = fixtures::issue("deep-parent-3");
    let leaf = fixtures::issue("deep-leaf");

    storage.create_issue(&blocker, "tester").unwrap();
    storage.create_issue(&p1, "tester").unwrap();
    storage.create_issue(&p2, "tester").unwrap();
    storage.create_issue(&p3, "tester").unwrap();
    storage.create_issue(&leaf, "tester").unwrap();

    // blocker blocks p1
    storage
        .add_dependency(
            &p1.id,
            &blocker.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    // p2 is child of p1, p3 is child of p2, leaf is child of p3
    storage
        .add_dependency(&p2.id, &p1.id, "parent-child", "tester")
        .unwrap();
    storage
        .add_dependency(&p3.id, &p2.id, "parent-child", "tester")
        .unwrap();
    storage
        .add_dependency(&leaf.id, &p3.id, "parent-child", "tester")
        .unwrap();

    let ids = blocked_ids(&storage);
    assert!(ids.contains(&p1.id), "p1 directly blocked");
    assert!(ids.contains(&p2.id), "p2 transitively blocked");
    assert!(ids.contains(&p3.id), "p3 transitively blocked");
    assert!(ids.contains(&leaf.id), "leaf transitively blocked");

    // Close blocker → entire chain unblocked
    storage
        .update_issue(&blocker.id, &status_update(Status::Closed), "tester")
        .unwrap();

    let ids = blocked_ids(&storage);
    assert!(!ids.contains(&p1.id), "p1 unblocked");
    assert!(!ids.contains(&p2.id), "p2 unblocked");
    assert!(!ids.contains(&p3.id), "p3 unblocked");
    assert!(!ids.contains(&leaf.id), "leaf unblocked");
}

// ===========================================================================
// 16. Regression: >50 parent-child levels must propagate correctly (#154)
// ===========================================================================

/// Before the fix for issue #154, transitive blocked-cache propagation was
/// capped at `MAX_DEPTH = 50`, causing descendants beyond that depth to
/// silently appear as "ready" even though an ancestor was blocked.
///
/// This test builds a chain of 75 parent-child levels to verify that
/// propagation reaches every descendant.
#[test]
fn deep_chain_beyond_50_levels_blocks_all_descendants() {
    const CHAIN_LEN: usize = 75;
    let mut storage = test_db();

    // Create the blocker issue that will block the root of the chain
    let blocker = fixtures::issue("deep75-blocker");
    storage.create_issue(&blocker, "tester").unwrap();

    // Build a chain of CHAIN_LEN issues: node-0 -> node-1 -> ... -> node-(CHAIN_LEN-1)
    let mut chain_issues: Vec<beads_rust::model::Issue> = Vec::with_capacity(CHAIN_LEN);
    for i in 0..CHAIN_LEN {
        let issue = fixtures::issue(&format!("deep75-node-{i}"));
        storage.create_issue(&issue, "tester").unwrap();
        chain_issues.push(issue);
    }

    // blocker blocks node-0
    storage
        .add_dependency(
            &chain_issues[0].id,
            &blocker.id,
            DependencyType::Blocks.as_str(),
            "tester",
        )
        .unwrap();

    // node-1 is child of node-0, node-2 is child of node-1, etc.
    for i in 1..CHAIN_LEN {
        storage
            .add_dependency(
                &chain_issues[i].id,
                &chain_issues[i - 1].id,
                "parent-child",
                "tester",
            )
            .unwrap();
    }

    // Every issue in the chain should be blocked
    let ids = blocked_ids(&storage);
    for (i, issue) in chain_issues.iter().enumerate() {
        assert!(
            ids.contains(&issue.id),
            "node-{i} (depth {depth}) should be blocked but was not found in blocked list \
             (old MAX_DEPTH=50 bug if depth > 50)",
            depth = i + 1,
        );
    }

    // Close the blocker → entire chain should unblock
    storage
        .update_issue(&blocker.id, &status_update(Status::Closed), "tester")
        .unwrap();

    let ids = blocked_ids(&storage);
    for (i, issue) in chain_issues.iter().enumerate() {
        assert!(
            !ids.contains(&issue.id),
            "node-{i} should be unblocked after closing blocker",
        );
    }
}