diff --git a/surfsense_backend/tests/unit/agents/new_chat/test_path_resolver.py b/surfsense_backend/tests/unit/agents/new_chat/test_path_resolver.py index ba9dc242b..ad3b17c9c 100644 --- a/surfsense_backend/tests/unit/agents/new_chat/test_path_resolver.py +++ b/surfsense_backend/tests/unit/agents/new_chat/test_path_resolver.py @@ -79,6 +79,33 @@ class TestDocToVirtualPath: assert path == f"{DOCUMENTS_ROOT}/notes/A.xml" +class TestConceptIdentityRoundTrip: + """A document's virtual path must parse back to the same (folder, title) - the + OKF path-identity guarantee at the grammar level, no DB required.""" + + def test_folder_nested_document_roundtrips(self): + index = PathIndex(folder_paths={5: f"{DOCUMENTS_ROOT}/Research/AI"}) + path = doc_to_virtual_path( + doc_id=2, title="My Note", folder_id=5, index=index + ) + assert path == f"{DOCUMENTS_ROOT}/Research/AI/My Note.xml" + folder_parts, title = parse_documents_path(path) + assert folder_parts == ["Research", "AI"] + assert title == "My Note" + + def test_colliding_title_roundtrips_to_base_title(self): + # Second doc with the same title gets a " ()" suffix; parsing the + # path must strip the disambiguator and recover the original title. + index = PathIndex(occupants={f"{DOCUMENTS_ROOT}/Hello.xml": 7}) + path = doc_to_virtual_path( + doc_id=8, title="Hello", folder_id=None, index=index + ) + assert path == f"{DOCUMENTS_ROOT}/Hello (8).xml" + folder_parts, title = parse_documents_path(path) + assert folder_parts == [] + assert title == "Hello" + + class TestParseDocumentsPath: def test_extracts_folder_parts_and_title(self): parts, title = parse_documents_path(f"{DOCUMENTS_ROOT}/foo/bar/baz.xml")