Skip to content

Commit 2006528

Browse files
committed
fix: fix read_content to work with file path
Signed-off-by: phernandez <paul@basicmachines.co>
1 parent d4025ba commit 2006528

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/basic_memory/services/link_resolver.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ async def resolve_link(self, link_text: str, use_search: bool = True) -> Optiona
4646
logger.debug(f"Found title match: {entity.title}")
4747
return entity
4848

49+
# 3. Try file path
50+
found_path = await self.entity_repository.get_by_file_path(clean_text)
51+
if found_path :
52+
logger.debug(f"Found entity with path: {found_path.file_path}")
53+
return found_path
54+
55+
# search if indicated
4956
if use_search and "*" not in clean_text:
5057
# 3. Fall back to search for fuzzy matching on title
5158
results = await self.search_service.search(

tests/mcp/test_tool_resource.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,32 @@ async def test_read_file_text_file(app, synced_files):
4141
assert response["content_type"].startswith("text/")
4242
assert response["encoding"] == "utf-8"
4343

44+
@pytest.mark.asyncio
45+
async def test_read_content_file_path(app, synced_files):
46+
"""Test reading a text file.
47+
48+
Should:
49+
- Correctly identify text content
50+
- Return the content as text
51+
- Include correct metadata
52+
"""
53+
# First create a text file via notes
54+
result = await write_note(
55+
title="Text Resource",
56+
folder="test",
57+
content="This is a test text resource",
58+
tags=["test", "resource"],
59+
)
60+
assert result is not None
61+
62+
# Now read it as a resource
63+
response = await read_content("test/Text Resource.md")
64+
65+
assert response["type"] == "text"
66+
assert "This is a test text resource" in response["text"]
67+
assert response["content_type"].startswith("text/")
68+
assert response["encoding"] == "utf-8"
69+
4470

4571
@pytest.mark.asyncio
4672
async def test_read_file_image_file(app, synced_files):

0 commit comments

Comments
 (0)