@@ -359,3 +359,42 @@ async def test_edit_note_find_replace_empty_find_text(client):
359359 assert isinstance (result , str )
360360 assert "# Edit Failed" in result
361361 # Should contain helpful guidance about the error
362+
363+
364+ @pytest .mark .asyncio
365+ async def test_edit_note_preserves_permalink_when_frontmatter_missing (client ):
366+ """Test that editing a note preserves the permalink when frontmatter doesn't contain one.
367+
368+ This is a regression test for issue #170 where edit_note would fail with a validation error
369+ because the permalink was being set to None when the markdown file didn't have a permalink
370+ in its frontmatter.
371+ """
372+ # Create initial note
373+ await write_note .fn (
374+ title = "Test Note" ,
375+ folder = "test" ,
376+ content = "# Test Note\n Original content here." ,
377+ )
378+
379+ # Verify the note was created with a permalink
380+ first_result = await edit_note .fn (
381+ identifier = "test/test-note" ,
382+ operation = "append" ,
383+ content = "\n First edit." ,
384+ )
385+
386+ assert isinstance (first_result , str )
387+ assert "permalink: test/test-note" in first_result
388+
389+ # Perform another edit - this should preserve the permalink even if the
390+ # file doesn't have a permalink in its frontmatter
391+ second_result = await edit_note .fn (
392+ identifier = "test/test-note" ,
393+ operation = "append" ,
394+ content = "\n Second edit." ,
395+ )
396+
397+ assert isinstance (second_result , str )
398+ assert "Edited note (append)" in second_result
399+ assert "permalink: test/test-note" in second_result
400+ # The edit should succeed without validation errors
0 commit comments