mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
fix: [BUG] write_note Tool Fails to Update Existing Files in Some Situations. (#80)
This commit is contained in:
committed by
GitHub
parent
248214cb11
commit
9bff1f732e
@@ -92,7 +92,12 @@ class EntityParser:
|
||||
async def parse_file(self, path: Path | str) -> EntityMarkdown:
|
||||
"""Parse markdown file into EntityMarkdown."""
|
||||
|
||||
absolute_path = self.base_path / path
|
||||
# Check if the path is already absolute
|
||||
if isinstance(path, Path) and path.is_absolute() or (isinstance(path, str) and Path(path).is_absolute()):
|
||||
absolute_path = Path(path)
|
||||
else:
|
||||
absolute_path = self.base_path / path
|
||||
|
||||
# Parse frontmatter and content using python-frontmatter
|
||||
post = frontmatter.load(str(absolute_path))
|
||||
|
||||
|
||||
@@ -217,6 +217,37 @@ def test_parse_empty_content():
|
||||
assert len(result.relations) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_parse_file_with_absolute_path(test_config, entity_parser):
|
||||
"""Test parsing a file with an absolute path."""
|
||||
content = dedent("""
|
||||
---
|
||||
type: component
|
||||
permalink: absolute_path_test
|
||||
---
|
||||
|
||||
# Absolute Path Test
|
||||
|
||||
A file with an absolute path.
|
||||
""")
|
||||
|
||||
# Create a test file in the project directory
|
||||
test_file = test_config.home / "absolute_path_test.md"
|
||||
test_file.write_text(content)
|
||||
|
||||
# Get the absolute path to the test file
|
||||
absolute_path = test_file.resolve()
|
||||
|
||||
# Parse the file using the absolute path
|
||||
entity = await entity_parser.parse_file(absolute_path)
|
||||
|
||||
# Verify the file was parsed correctly
|
||||
assert entity.frontmatter.permalink == "absolute_path_test"
|
||||
assert "Absolute Path Test" in entity.content
|
||||
assert entity.created is not None
|
||||
assert entity.modified is not None
|
||||
|
||||
|
||||
# @pytest.mark.asyncio
|
||||
# async def test_parse_file_invalid_yaml(test_config, entity_parser):
|
||||
# """Test parsing file with invalid YAML frontmatter."""
|
||||
|
||||
Reference in New Issue
Block a user