mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-06-15 20:05:14 +02:00
fix(filesystem): detect ambiguous virtual paths
Resolve root virtual file paths correctly and raise a clear error for ambiguous file targets.
This commit is contained in:
parent
e9453725b6
commit
8e0f295464
2 changed files with 98 additions and 14 deletions
44
tests/test_pifs_path_resolution.py
Normal file
44
tests/test_pifs_path_resolution.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import pytest
|
||||
|
||||
|
||||
def test_root_virtual_file_path_resolves_without_double_slash(tmp_path):
|
||||
from pageindex.filesystem import PageIndexFileSystem
|
||||
|
||||
filesystem = PageIndexFileSystem(workspace=tmp_path / "workspace")
|
||||
file_ref = filesystem.register_file(
|
||||
storage_uri="file:///tmp/root-source.txt",
|
||||
source_path="sources/root-source.txt",
|
||||
folder_path="/",
|
||||
external_id="doc_root_title",
|
||||
title="Root Title",
|
||||
content="root content",
|
||||
)
|
||||
|
||||
assert filesystem.store.resolve_file_ref("/Root Title") == file_ref
|
||||
|
||||
|
||||
def test_ambiguous_virtual_file_path_raises_clear_error(tmp_path):
|
||||
from pageindex.filesystem import PageIndexFileSystem
|
||||
|
||||
filesystem = PageIndexFileSystem(workspace=tmp_path / "workspace")
|
||||
first_ref = filesystem.register_file(
|
||||
storage_uri="file:///tmp/first.txt",
|
||||
source_path="b/file.txt",
|
||||
folder_path="/a",
|
||||
external_id="doc_first",
|
||||
title="First",
|
||||
content="first content",
|
||||
)
|
||||
second_ref = filesystem.register_file(
|
||||
storage_uri="file:///tmp/second.txt",
|
||||
source_path="second-source.txt",
|
||||
folder_path="/a/b",
|
||||
external_id="doc_second",
|
||||
title="file.txt",
|
||||
content="second content",
|
||||
)
|
||||
|
||||
with pytest.raises(KeyError, match="Ambiguous file target"):
|
||||
filesystem.store.resolve_file_ref("/a/b/file.txt")
|
||||
|
||||
assert first_ref != second_ref
|
||||
Loading…
Add table
Add a link
Reference in a new issue