Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cli/decompose/decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,18 @@ def reorder_subtasks(
come before dependents, with numbering prefixes updated.

Raises:
ValueError: If duplicate subtask tags are detected (case-insensitive).
ValueError: If a circular dependency is detected.
"""
seen: set[str] = set()
for subtask in subtasks:
tag = subtask["tag"].lower()
if tag in seen:
raise ValueError(
f'Duplicate subtask tag "{tag}". Tags must be unique (case-insensitive).'
)
seen.add(tag)

subtask_map = {subtask["tag"].lower(): subtask for subtask in subtasks}

graph = {}
Expand Down
12 changes: 12 additions & 0 deletions test/cli/test_decompose_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ def test_reorder_circular_raises():
reorder_subtasks(subtasks)


def test_reorder_duplicate_tag_raises():
subtasks = [_subtask("a", "1. Task A"), _subtask("a", "2. Also A")]
with pytest.raises(ValueError, match="Duplicate subtask tag"):
reorder_subtasks(subtasks)


def test_reorder_duplicate_tag_case_insensitive_raises():
subtasks = [_subtask("Step_A", "1. Task A"), _subtask("step_a", "2. Also A")]
with pytest.raises(ValueError, match="Duplicate subtask tag"):
reorder_subtasks(subtasks)


def test_reorder_renumbers_subtasks():
subtasks = [
_subtask("b", "2. Task B", depends_on=["a"]),
Expand Down
Loading