Skip to content

Commit 50b106c

Browse files
authored
fix: raise ValueError on duplicate subtask tags in reorder_subtasks (#874)
1 parent c208bba commit 50b106c

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

cli/decompose/decompose.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,18 @@ def reorder_subtasks(
6262
come before dependents, with numbering prefixes updated.
6363
6464
Raises:
65+
ValueError: If duplicate subtask tags are detected (case-insensitive).
6566
ValueError: If a circular dependency is detected.
6667
"""
68+
seen: set[str] = set()
69+
for subtask in subtasks:
70+
tag = subtask["tag"].lower()
71+
if tag in seen:
72+
raise ValueError(
73+
f'Duplicate subtask tag "{tag}". Tags must be unique (case-insensitive).'
74+
)
75+
seen.add(tag)
76+
6777
subtask_map = {subtask["tag"].lower(): subtask for subtask in subtasks}
6878

6979
graph = {}

test/cli/test_decompose_unit.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ def test_reorder_circular_raises():
6262
reorder_subtasks(subtasks)
6363

6464

65+
def test_reorder_duplicate_tag_raises():
66+
subtasks = [_subtask("a", "1. Task A"), _subtask("a", "2. Also A")]
67+
with pytest.raises(ValueError, match="Duplicate subtask tag"):
68+
reorder_subtasks(subtasks)
69+
70+
71+
def test_reorder_duplicate_tag_case_insensitive_raises():
72+
subtasks = [_subtask("Step_A", "1. Task A"), _subtask("step_a", "2. Also A")]
73+
with pytest.raises(ValueError, match="Duplicate subtask tag"):
74+
reorder_subtasks(subtasks)
75+
76+
6577
def test_reorder_renumbers_subtasks():
6678
subtasks = [
6779
_subtask("b", "2. Task B", depends_on=["a"]),

0 commit comments

Comments
 (0)