@@ -320,7 +320,7 @@ async def test_edit_note_replace_section_missing_section(client, test_project):
320320 content = "new content" ,
321321 )
322322
323- assert "section parameter is required for replace_section operation " in str (exc_info .value )
323+ assert "section parameter is required for section-based operations " in str (exc_info .value )
324324
325325
326326@pytest .mark .asyncio
@@ -611,3 +611,96 @@ async def test_edit_note_preserves_permalink_when_frontmatter_missing(client, te
611611 assert f"permalink: { test_project .name } /test/test-note" in second_result
612612 assert f"[Session: Using project '{ test_project .name } ']" in second_result
613613 # The edit should succeed without validation errors
614+
615+
616+ @pytest .mark .asyncio
617+ async def test_edit_note_insert_before_section_operation (client , test_project ):
618+ """Test inserting content before a section heading."""
619+ # Create initial note with sections
620+ await write_note (
621+ project = test_project .name ,
622+ title = "Insert Before Doc" ,
623+ directory = "docs" ,
624+ content = "# Doc\n \n ## Overview\n Overview content.\n \n ## Details\n Detail content." ,
625+ )
626+
627+ result = await edit_note (
628+ project = test_project .name ,
629+ identifier = "docs/insert-before-doc" ,
630+ operation = "insert_before_section" ,
631+ content = "--- inserted divider ---" ,
632+ section = "## Details" ,
633+ )
634+
635+ assert isinstance (result , str )
636+ assert "Edited note (insert_before_section)" in result
637+ assert f"project: { test_project .name } " in result
638+ assert "Inserted content before section '## Details'" in result
639+ assert f"[Session: Using project '{ test_project .name } ']" in result
640+
641+
642+ @pytest .mark .asyncio
643+ async def test_edit_note_insert_after_section_operation (client , test_project ):
644+ """Test inserting content after a section heading."""
645+ # Create initial note with sections
646+ await write_note (
647+ project = test_project .name ,
648+ title = "Insert After Doc" ,
649+ directory = "docs" ,
650+ content = "# Doc\n \n ## Overview\n Overview content.\n \n ## Details\n Detail content." ,
651+ )
652+
653+ result = await edit_note (
654+ project = test_project .name ,
655+ identifier = "docs/insert-after-doc" ,
656+ operation = "insert_after_section" ,
657+ content = "Inserted after overview heading" ,
658+ section = "## Overview" ,
659+ )
660+
661+ assert isinstance (result , str )
662+ assert "Edited note (insert_after_section)" in result
663+ assert f"project: { test_project .name } " in result
664+ assert "Inserted content after section '## Overview'" in result
665+ assert f"[Session: Using project '{ test_project .name } ']" in result
666+
667+
668+ @pytest .mark .asyncio
669+ async def test_edit_note_insert_before_section_missing_section (client , test_project ):
670+ """Test insert_before_section without section parameter raises ValueError."""
671+ await write_note (
672+ project = test_project .name ,
673+ title = "Test Note" ,
674+ directory = "test" ,
675+ content = "# Test\n Content here." ,
676+ )
677+
678+ with pytest .raises (ValueError , match = "section parameter is required" ):
679+ await edit_note (
680+ project = test_project .name ,
681+ identifier = "test/test-note" ,
682+ operation = "insert_before_section" ,
683+ content = "new content" ,
684+ )
685+
686+
687+ @pytest .mark .asyncio
688+ async def test_edit_note_insert_before_section_not_found (client , test_project ):
689+ """Test insert_before_section when section doesn't exist returns error."""
690+ await write_note (
691+ project = test_project .name ,
692+ title = "Test Note" ,
693+ directory = "test" ,
694+ content = "# Test\n \n ## Existing\n Content here." ,
695+ )
696+
697+ result = await edit_note (
698+ project = test_project .name ,
699+ identifier = "test/test-note" ,
700+ operation = "insert_before_section" ,
701+ content = "new content" ,
702+ section = "## Nonexistent" ,
703+ )
704+
705+ assert isinstance (result , str )
706+ assert "# Edit Failed" in result
0 commit comments