Skip to content

Commit 6dcf59c

Browse files
Fix empty components bug
1 parent f02f207 commit 6dcf59c

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/usethis/_pipeweld/func.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@ def _get_instructions_for_insertion(
506506

507507
endpoints.append(endpoint)
508508
instructions_per_sub.append(new_instructions)
509+
if min_endpoint is None:
510+
# If the existing components are empty...
511+
min_endpoint = after
509512

510513
for idx in range(len(component.root)):
511514
if idx != min_idx and instructions_per_sub[idx]:

tests/usethis/_integrations/ci/bitbucket/test_pipeweld.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,22 @@ def test_empty_series_with_smaller_after(self):
774774
assert instructions == [InsertSuccessor(step="C", after="A")]
775775
assert endpoint == "C"
776776

777+
def test_all_empty_branches_preserves_after(self):
778+
"""When all branches are empty, no instructions are produced but the
779+
endpoint should still be the original ``after`` value."""
780+
# Arrange
781+
component = parallel(series(), series())
782+
after = "X"
783+
784+
# Act
785+
instructions, endpoint = _get_instructions_for_insertion(
786+
component, after=after
787+
)
788+
789+
# Assert
790+
assert instructions == []
791+
assert endpoint == "X"
792+
777793
class TestDepGroup:
778794
def test_basic(self):
779795
# Arrange

0 commit comments

Comments
 (0)