diff --git a/src/basic_memory/markdown/entity_parser.py b/src/basic_memory/markdown/entity_parser.py index 743af5b84..117baecb0 100644 --- a/src/basic_memory/markdown/entity_parser.py +++ b/src/basic_memory/markdown/entity_parser.py @@ -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)) diff --git a/tests/markdown/test_entity_parser.py b/tests/markdown/test_entity_parser.py index fc589efc7..0d286057e 100644 --- a/tests/markdown/test_entity_parser.py +++ b/tests/markdown/test_entity_parser.py @@ -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."""