mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-08-29 04:26:20 +00:00
fix(context): retain path inspection diagnostics
This commit is contained in:
@@ -1867,10 +1867,19 @@ class AgentMemory:
|
||||
try:
|
||||
candidate_exists = candidate.exists()
|
||||
except OSError as exc:
|
||||
raise OSError(
|
||||
error_message = (
|
||||
"Failed to inspect possible Markdown import "
|
||||
f"path: {candidate}"
|
||||
) from exc
|
||||
f"path {candidate}: {exc.strerror or str(exc)}"
|
||||
)
|
||||
if exc.errno is None:
|
||||
error = OSError(error_message)
|
||||
else:
|
||||
error = OSError(
|
||||
exc.errno,
|
||||
error_message,
|
||||
exc.filename or str(candidate),
|
||||
)
|
||||
raise error from exc
|
||||
|
||||
if candidate_exists:
|
||||
documents = self._read_markdown_path(candidate)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import errno
|
||||
from copy import deepcopy
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from unittest.mock import MagicMock, patch
|
||||
@@ -676,18 +677,25 @@ def test_markdown_string_path_read_errors_are_not_treated_as_content(tmp_path):
|
||||
|
||||
def test_markdown_string_path_inspection_errors_are_actionable():
|
||||
memory = AgentMemory()
|
||||
original_error = PermissionError(
|
||||
errno.EACCES,
|
||||
"inspection denied",
|
||||
"blocked-memory.md",
|
||||
)
|
||||
|
||||
with patch(
|
||||
"semantica.context.agent_memory.Path.exists",
|
||||
side_effect=PermissionError("inspection denied"),
|
||||
side_effect=original_error,
|
||||
):
|
||||
with pytest.raises(
|
||||
OSError, match="Failed to inspect possible Markdown import path"
|
||||
) as exc_info:
|
||||
memory.import_data("memory.md", format="markdown")
|
||||
|
||||
assert isinstance(exc_info.value.__cause__, PermissionError)
|
||||
assert "inspection denied" in str(exc_info.value.__cause__)
|
||||
assert exc_info.value.errno == errno.EACCES
|
||||
assert exc_info.value.filename == "blocked-memory.md"
|
||||
assert "inspection denied" in str(exc_info.value)
|
||||
assert exc_info.value.__cause__ is original_error
|
||||
|
||||
|
||||
def test_legacy_dict_import_behavior_is_unchanged():
|
||||
|
||||
Reference in New Issue
Block a user