From d589585545d7606116c67326596bd46e3082912b Mon Sep 17 00:00:00 2001 From: sjoerdvink99 Date: Thu, 16 Apr 2026 11:03:39 -0400 Subject: [PATCH] fix: raise ValueError on duplicate subtask tags in reorder_subtasks --- cli/decompose/decompose.py | 10 ++++++++++ test/cli/test_decompose_unit.py | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/cli/decompose/decompose.py b/cli/decompose/decompose.py index c5631068c..d9b46f4ce 100644 --- a/cli/decompose/decompose.py +++ b/cli/decompose/decompose.py @@ -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 = {} diff --git a/test/cli/test_decompose_unit.py b/test/cli/test_decompose_unit.py index 571e117e6..2b68c7d82 100644 --- a/test/cli/test_decompose_unit.py +++ b/test/cli/test_decompose_unit.py @@ -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"]),