@@ -768,3 +768,30 @@ async def test_append_mode(editor, tmp_path):
768
768
769
769
assert result ["result" ] == "ok"
770
770
assert test_file .read_text () == original_content + append_content
771
+
772
+
773
+ @pytest .mark .asyncio
774
+ async def test_dict_patch_with_defaults (editor : TextEditor , tmp_path ):
775
+ """Test dictionary patch with default values."""
776
+ test_file = tmp_path / "test.txt"
777
+ original_content = "line1\n line2\n line3\n "
778
+ test_file .write_text (original_content )
779
+
780
+ # Get first line content and calculate hashes
781
+ first_line_content , _ , _ , _ , _ , _ = await editor .read_file_contents (
782
+ str (test_file ), line_start = 1 , line_end = 1
783
+ )
784
+ file_hash = editor .calculate_hash (original_content )
785
+
786
+ # Edit using dict patch with missing optional fields
787
+ patch = {
788
+ "contents" : "new line\n " , # Add newline to maintain file structure
789
+ "line_start" : 1 ,
790
+ "line_end" : 1 , # Explicitly specify line_end
791
+ "range_hash" : editor .calculate_hash (first_line_content ),
792
+ }
793
+ result = await editor .edit_file_contents (str (test_file ), file_hash , [patch ])
794
+
795
+ assert result ["result" ] == "ok"
796
+ # Should replace line 1 when range_hash is provided
797
+ assert test_file .read_text () == "new line\n line2\n line3\n "
0 commit comments