Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test(library): pin the sentinel unlink exclusion in delete_document (#7544)

Masyarakat AI362d65652156
diff --git a/tests/research_library/services/test_library_document_identity.py b/tests/research_library/services/test_library_document_identity.py
index c0b1383a8a..860a4c047a 100644
--- a/tests/research_library/services/test_library_document_identity.py
+++ b/tests/research_library/services/test_library_document_identity.py
@@ -621,3 +621,36 @@ def test_primary_deletion_resets_only_matching_version_tracker(
matched = identity != "conflicting_hash"
assert old_tracker.is_downloaded is (not matched)
assert old_tracker.file_path == (None if matched else "old.pdf")
+
+
[email protected]("sentinel", [*FILE_PATH_SENTINELS, "database"])
+def test_delete_document_never_unlinks_a_file_named_like_a_sentinel(
+ library, sentinel
+):
+ """A file literally named like a sentinel is the user's, not ours to unlink.
+
+ ``delete_document`` skips the unlink when the stored path is a sentinel (or
+ ``"database"``), so a user's file with one of those names in the library
+ root must survive the delete. Dropping that exclusion would unlink it.
+ """
+ doc, tracker = library.add(OLD_URL, sentinel, legacy=True)
+ doc_id = doc.id
+
+ # A real user file whose name collides with the stored sentinel path.
+ real_file = library.root / sentinel
+ real_file.write_bytes(
+ b"a real file that happens to be named like a sentinel"
+ )
+
+ assert library.service.delete_document(doc_id)
+ library.session.expire_all()
+
+ # The row and its tracker are reset...
+ assert library.session.get(Document, doc_id) is None
+ assert tracker.file_path is None
+ assert tracker.is_downloaded is False
+ # ...but the colliding file is still the user's.
+ assert real_file.exists()
+ assert real_file.read_bytes() == (
+ b"a real file that happens to be named like a sentinel"
+ )