Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/basic_memory/markdown/entity_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ def parse_date(self, value: Any) -> Optional[datetime]:
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))

Expand Down
31 changes: 31 additions & 0 deletions tests/markdown/test_entity_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Loading