Skip to content

Commit d9cc21c

Browse files
github-actions[bot]phernandez
authored andcommitted
fix: [BUG] write_note Tool Fails to Update Existing Files in Some Situations. (#80)
Signed-off-by: phernandez <paul@basicmachines.co>
1 parent 086aa44 commit d9cc21c

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/basic_memory/markdown/entity_parser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ def parse_date(self, value: Any) -> Optional[datetime]:
9292
async def parse_file(self, path: Path | str) -> EntityMarkdown:
9393
"""Parse markdown file into EntityMarkdown."""
9494

95-
absolute_path = self.base_path / path
95+
# Check if the path is already absolute
96+
if isinstance(path, Path) and path.is_absolute() or (isinstance(path, str) and Path(path).is_absolute()):
97+
absolute_path = Path(path)
98+
else:
99+
absolute_path = self.base_path / path
100+
96101
# Parse frontmatter and content using python-frontmatter
97102
post = frontmatter.load(str(absolute_path))
98103

tests/markdown/test_entity_parser.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,37 @@ def test_parse_empty_content():
217217
assert len(result.relations) == 0
218218

219219

220+
@pytest.mark.asyncio
221+
async def test_parse_file_with_absolute_path(test_config, entity_parser):
222+
"""Test parsing a file with an absolute path."""
223+
content = dedent("""
224+
---
225+
type: component
226+
permalink: absolute_path_test
227+
---
228+
229+
# Absolute Path Test
230+
231+
A file with an absolute path.
232+
""")
233+
234+
# Create a test file in the project directory
235+
test_file = test_config.home / "absolute_path_test.md"
236+
test_file.write_text(content)
237+
238+
# Get the absolute path to the test file
239+
absolute_path = test_file.resolve()
240+
241+
# Parse the file using the absolute path
242+
entity = await entity_parser.parse_file(absolute_path)
243+
244+
# Verify the file was parsed correctly
245+
assert entity.frontmatter.permalink == "absolute_path_test"
246+
assert "Absolute Path Test" in entity.content
247+
assert entity.created is not None
248+
assert entity.modified is not None
249+
250+
220251
# @pytest.mark.asyncio
221252
# async def test_parse_file_invalid_yaml(test_config, entity_parser):
222253
# """Test parsing file with invalid YAML frontmatter."""

0 commit comments

Comments
 (0)