@@ -153,6 +153,64 @@ def test_constructor_copies_segments_list():
153153 assert path .segments == ["parent" , "child" ]
154154
155155
156+ def test_append_single_segment_returns_new_path ():
157+ """append adds a single segment to an existing path."""
158+ path = _BranchPath .from_string ("parent" )
159+ new_path = path .append ("child" )
160+
161+ assert new_path == _BranchPath .from_string ("parent.child" )
162+ assert path == _BranchPath .from_string ("parent" ) # Immutability check
163+
164+
165+ def test_append_with_run_id_formats_segment ():
166+ """append formats the segment as 'name@run_id' when run_id is provided."""
167+ path = _BranchPath .from_string ("parent" )
168+ new_path = path .append ("child" , run_id = "call_123" )
169+
170+ assert new_path == _BranchPath .from_string ("parent.child@call_123" )
171+
172+
173+ def test_append_another_branch_path ():
174+ """append combines segments from another _BranchPath instance."""
175+ path1 = _BranchPath .from_string ("parent" )
176+ path2 = _BranchPath .from_string ("child.grandchild" )
177+ new_path = path1 .append (path2 )
178+
179+ assert new_path == _BranchPath .from_string ("parent.child.grandchild" )
180+
181+
182+ def test_create_sub_branch_formats_string_correctly ():
183+ """create_sub_branch constructs sub-branch strings safely."""
184+ # With base branch and run ID
185+ res1 = _BranchPath .create_sub_branch (
186+ "parent.sub" , name = "child" , run_id = "run_1"
187+ )
188+ assert res1 == "parent.sub.child@run_1"
189+
190+ # Without base branch (None or empty)
191+ res2 = _BranchPath .create_sub_branch (None , name = "agent" , run_id = "fc_456" )
192+ assert res2 == "agent@fc_456"
193+
194+ # Dot-separated sub-path without run ID
195+ res3 = _BranchPath .create_sub_branch ("parent" , name = "agent.sub_agent" )
196+ assert res3 == "parent.agent.sub_agent"
197+
198+
199+ def test_append_with_run_id_and_branch_path_raises_value_error ():
200+ """append raises ValueError when run_id is provided with a _BranchPath."""
201+ path1 = _BranchPath .from_string ("parent" )
202+ path2 = _BranchPath .from_string ("child" )
203+ with pytest .raises (ValueError , match = "run_id cannot be provided" ):
204+ path1 .append (path2 , run_id = "123" )
205+
206+
207+ def test_append_with_run_id_and_dot_separated_path_raises_value_error ():
208+ """append raises ValueError when run_id is provided with a dot-separated path."""
209+ path = _BranchPath .from_string ("parent" )
210+ with pytest .raises (ValueError , match = "run_id cannot be provided" ):
211+ path .append ("child.sub" , run_id = "123" )
212+
213+
156214def test_run_ids_filters_out_empty_run_ids ():
157215 """run_ids filters out segments with empty run IDs (e.g. ending with '@')."""
158216 path = _BranchPath .from_string ("parent@.child@2.node@" )
0 commit comments