mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-15 11:00:47 +02:00
Set up document management for Stirling Engine (#6476)
# Description of Changes Change Stirling Engine to support deleting documents automatically. This happens both on user logout and after an amount of time specified by the Java when ingesting a document (allowing for personal documents to have short lifetimes but org documents to be left in the db with no expiry date). Also sets up an [ACL policy](https://en.wikipedia.org/wiki/Access-control_list) for the documents so the database knows which users have access to which documents. This is not fully implemented in the Java, so currently all docs are treated as having a single owner, the uploader, but theoretically when we need to support org storage, we shouldn't need to change the db schema.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
from dataclasses import replace
|
||||
|
||||
import pytest
|
||||
@@ -19,9 +20,25 @@ from stirling.contracts import (
|
||||
SupportedCapability,
|
||||
)
|
||||
from stirling.documents import Document, DocumentService, SqliteVecStore
|
||||
from stirling.models import FileId
|
||||
from stirling.models import FileId, OwnerId, PrincipalId, UserId
|
||||
from stirling.services import current_user_id
|
||||
from stirling.services.runtime import AppRuntime
|
||||
|
||||
USER = UserId("test-user")
|
||||
OWNER = OwnerId("test-user")
|
||||
OWNER_PRINCIPALS = [PrincipalId("test-user")]
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _set_user_context() -> Iterator[None]:
|
||||
"""Set current_user_id to a fixed test user for every test in this module so
|
||||
agent code calling require_current_user_id() doesn't fail closed."""
|
||||
token = current_user_id.set(USER)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
current_user_id.reset(token)
|
||||
|
||||
|
||||
class StubEmbedder:
|
||||
"""Deterministic embeddings so RAG lookups work in tests without network."""
|
||||
@@ -94,6 +111,9 @@ async def test_reports_only_missing_files(runtime_with_stub_rag: AppRuntime) ->
|
||||
FileId("present-id"),
|
||||
[PageText(page_number=1, text="Invoice total: 120.00.")],
|
||||
source="present.pdf",
|
||||
owner_id=OWNER,
|
||||
read_principals=OWNER_PRINCIPALS,
|
||||
expires_at=None,
|
||||
)
|
||||
agent = PdfQuestionAgent(runtime_with_stub_rag)
|
||||
|
||||
@@ -111,6 +131,9 @@ async def test_returns_grounded_answer_when_all_files_ingested(runtime_with_stub
|
||||
FileId("invoice-id"),
|
||||
[PageText(page_number=1, text="Invoice total: 120.00.")],
|
||||
source="invoice.pdf",
|
||||
owner_id=OWNER,
|
||||
read_principals=OWNER_PRINCIPALS,
|
||||
expires_at=None,
|
||||
)
|
||||
agent = StubPdfQuestionAgent(
|
||||
runtime_with_stub_rag,
|
||||
@@ -142,6 +165,9 @@ async def test_returns_not_found_when_answer_not_in_doc(runtime_with_stub_rag: A
|
||||
FileId("shipping-id"),
|
||||
[PageText(page_number=1, text="This page contains only a shipping address.")],
|
||||
source="shipping.pdf",
|
||||
owner_id=OWNER,
|
||||
read_principals=OWNER_PRINCIPALS,
|
||||
expires_at=None,
|
||||
)
|
||||
agent = StubPdfQuestionAgent(
|
||||
runtime_with_stub_rag,
|
||||
|
||||
Reference in New Issue
Block a user