@@ -72,6 +72,8 @@ def _write_ticket(
7272 tracker_dir : Path ,
7373 ticket_id : str ,
7474 status : str = "open" ,
75+ parent_id : str | None = None ,
76+ ticket_type : str = "task" ,
7577) -> Path :
7678 """Write a minimal ticket directory with a CREATE event and optional STATUS event.
7779
@@ -87,9 +89,9 @@ def _write_ticket(
8789 "author" : "Test User" ,
8890 "env_id" : "00000000-0000-4000-8000-000000000001" ,
8991 "data" : {
90- "ticket_type" : "task" ,
92+ "ticket_type" : ticket_type ,
9193 "title" : f"Ticket { ticket_id } " ,
92- "parent_id" : None ,
94+ "parent_id" : parent_id ,
9395 },
9496 }
9597 with open (ticket_dir / f"1000-create-{ ticket_id } -CREATE.json" , "w" ) as f :
@@ -659,3 +661,58 @@ def test_is_active_link_same_second_unlink_sorts_after_link(
659661 "This indicates same-second UNLINK is sorting before LINK — the timestamp "
660662 "tie-breaker (event_type_order: LINK=0, UNLINK=1) is missing or incorrect."
661663 )
664+
665+
666+ # ---------------------------------------------------------------------------
667+ # Parent-child (children) tests — bug 8cbf-e13b
668+ # ---------------------------------------------------------------------------
669+
670+
671+ def test_build_dep_graph_includes_children (graph : ModuleType , tmp_path : Path ) -> None :
672+ """build_dep_graph must return a 'children' field listing tickets whose
673+ parent_id matches the queried ticket.
674+
675+ Bug 8cbf-e13b: ticket deps returns empty deps for epics with parent-linked
676+ children because it only traverses dependency links, not parent_id.
677+ """
678+ tracker_dir = tmp_path / "tracker"
679+ tracker_dir .mkdir ()
680+
681+ # Create an epic
682+ _write_ticket (tracker_dir , "epic-001" , ticket_type = "epic" )
683+ # Create 3 child stories with parent_id pointing to the epic
684+ _write_ticket (tracker_dir , "story-a" , parent_id = "epic-001" , ticket_type = "story" )
685+ _write_ticket (tracker_dir , "story-b" , parent_id = "epic-001" , ticket_type = "story" )
686+ _write_ticket (tracker_dir , "story-c" , parent_id = "epic-001" , ticket_type = "story" )
687+ # Create an unrelated ticket (no parent)
688+ _write_ticket (tracker_dir , "unrelated" )
689+
690+ result = graph .build_dep_graph ("epic-001" , str (tracker_dir ))
691+
692+ assert "children" in result , (
693+ "build_dep_graph result is missing 'children' field — "
694+ "parent-child relationships are not included in the graph output"
695+ )
696+ children = sorted (result ["children" ])
697+ assert children == ["story-a" , "story-b" , "story-c" ], (
698+ f"Expected 3 children [story-a, story-b, story-c], got { children } "
699+ )
700+
701+
702+ def test_build_dep_graph_children_empty_when_no_children (
703+ graph : ModuleType , tmp_path : Path
704+ ) -> None :
705+ """build_dep_graph must return an empty 'children' list when no tickets
706+ have parent_id matching the queried ticket."""
707+ tracker_dir = tmp_path / "tracker"
708+ tracker_dir .mkdir ()
709+
710+ _write_ticket (tracker_dir , "lonely-ticket" )
711+ _write_ticket (tracker_dir , "other-ticket" )
712+
713+ result = graph .build_dep_graph ("lonely-ticket" , str (tracker_dir ))
714+
715+ assert "children" in result , "build_dep_graph result missing 'children' field"
716+ assert result ["children" ] == [], (
717+ f"Expected empty children, got { result ['children' ]} "
718+ )
0 commit comments