from __future__ import annotations import time from backend.core.document_library import ( document_created_at_iso, is_reingest_running, recover_stale_processing_documents, schedule_reingest_all_documents, ) from backend.core.report_session import UploadedDocument, list_documents, save_document def test_document_created_at_iso_from_epoch(): ts = time.time() doc = UploadedDocument( document_id="abc", filename="test.pdf", created_at=ts, ) iso = document_created_at_iso(doc) assert "T" in iso assert iso.endswith("+00:00") or iso.endswith("Z") or "+" in iso def test_recover_stale_processing_when_no_worker(tmp_path, monkeypatch): monkeypatch.setenv("DATA_DIR", str(tmp_path)) tenant = "t-recover" doc = UploadedDocument( document_id="d1", filename="a.pdf", status="processing", storage_path=str(tmp_path / "a.pdf"), ) (tmp_path / "a.pdf").write_bytes(b"x") save_document(tenant, doc) assert is_reingest_running(tenant) is False n = recover_stale_processing_documents(tenant) assert n == 1 assert list_documents(tenant)["d1"].status == "complete"