Skip to content

Commit c5e3ab5

Browse files
committed
Python: refuse the store root in delete_directory on both backends
The filesystem backend resolved the empty path to the configured store root and rmdir'd it, returning True, while the in-memory backend raised on the same call from re-normalizing the already normalized path as a file path. Both now return False for the empty or whitespace-only path before touching storage, the in-memory store normalizes once, and the parity test covers the empty path and whitespace spelling on both backends. Signed-off-by: Manohar Paturi <[email protected]>
1 parent 4c6ce3b commit c5e3ab5

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎python/packages/core/agent_framework/_harness/_file_access.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,12 @@ async def delete_directory(self, path: str) -> bool:
11811181
file-only ``delete`` contract while giving session-scoped directories a
11821182
lifecycle instead of staying in the shared map forever.
11831183
"""
1184-
key = self._key(_normalize_relative_path(path, is_directory=True))
1184+
normalized = _normalize_relative_path(path, is_directory=True)
1185+
if not normalized:
1186+
# The empty path is the store root, which is not an explicitly
1187+
# created directory this method releases.
1188+
return False
1189+
key = normalized.lower()
11851190
async with self._lock:
11861191
if key not in self._explicit_dirs:
11871192
return False
@@ -1578,7 +1583,12 @@ async def delete_directory(self, path: str) -> bool:
15781583
that is missing, is a file, or still holds entries returns ``False``
15791584
instead of raising, matching :class:`InMemoryAgentFileStore`.
15801585
"""
1581-
full_path = self._resolve_safe_directory_path(path)
1586+
normalized = _normalize_relative_path(path, is_directory=True)
1587+
if not normalized:
1588+
# The empty path resolves to the configured store root, which is
1589+
# not an explicitly created directory this method releases.
1590+
return False
1591+
full_path = self._resolve_safe_directory_path(normalized)
15821592
return await asyncio.to_thread(self._delete_directory_sync, full_path)
15831593

15841594
@staticmethod

‎python/packages/core/tests/core/test_harness_file_access.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,6 +2758,15 @@ async def in_memory_mirror() -> tuple[InMemoryAgentFileStore, FileSystemAgentFil
27582758
assert await fs_store.delete_directory("sessions/s1") is False
27592759
assert await memory_store.delete_directory("sessions/s1") is False
27602760

2761+
# The empty path is the store root, not an explicitly created directory:
2762+
# both backends must refuse it identically (previously the filesystem
2763+
# backend rmdir'd its configured root and returned True while the
2764+
# in-memory store raised on the same call).
2765+
for empty in ("", " "):
2766+
assert await fs_store.delete_directory(empty) is False
2767+
assert await memory_store.delete_directory(empty) is False
2768+
assert fs_store._root_path.is_dir()
2769+
27612770

27622771
async def test_in_memory_store_delete_is_file_only() -> None:
27632772
"""delete() must stay file-only: a directory path is never removed, matching

0 commit comments

Comments
 (0)