Fix Zotero table models for Zotero 9:
- Remove stale Annotations/Highlights/Transaction* models
- Add ItemAnnotations, RetractedItems, DeletedCollections,
DeletedSearches, DbDebug1
- Fix ItemAttachments, Libraries, Users column mismatches
New test files covering all major modules:
- cli/{bib,prisma,rec,zot,mail,run} deep exercising tests
- mail/{droplet,postmark,resend,cloudflare} lifecycle tests
- bib/{iom,oig,pincite,sync,regulations_gov,email_ingest,format,store}
- prisma/{vpn,fetch,export,llm,screen,eligibility,extract,project,ingest,flow}
- aco/lake/{unity,quality,deploy} + api/aco coverage gaps
- zot/{ops,db,extract,duck} + rec/{report,engine,base,pricers}
- pfs/{pipe,rules,eq,files}
Add pytest-xdist for parallel test execution.
Tracks #353
134 lines
4.2 KiB
Python
134 lines
4.2 KiB
Python
"""Exercise prisma.screen — covers run() with mocked provider + real DB."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from prisma.screen import _build_call, _queue, run
|
|
from zot.db import Db
|
|
from zot.schema import create_db
|
|
|
|
|
|
def _setup(tmp_path):
|
|
path = str(tmp_path / "z.sqlite")
|
|
con = create_db(path)
|
|
con.close()
|
|
return path
|
|
|
|
|
|
class TestBuildCall:
|
|
def test_returns_call(self):
|
|
project = MagicMock()
|
|
project.criteria = "Include studies on X"
|
|
project.reasons = "R1: not relevant"
|
|
call = _build_call(project, "# Test Item\nabstract: ...")
|
|
assert len(call.messages) == 3
|
|
assert call.force_tool is not None
|
|
|
|
|
|
class TestQueue:
|
|
def test_empty(self, tmp_path):
|
|
path = _setup(tmp_path)
|
|
with Db(path) as db:
|
|
ids = _queue(db, "test-proj", None)
|
|
assert ids == []
|
|
|
|
|
|
class TestRun:
|
|
def test_empty_queue(self, tmp_path):
|
|
path = _setup(tmp_path)
|
|
provider = MagicMock()
|
|
project = MagicMock()
|
|
project.name = "test-proj"
|
|
project.criteria = "criteria"
|
|
project.reasons = "reasons"
|
|
with Db(path) as db:
|
|
stats = run(
|
|
db,
|
|
provider,
|
|
project,
|
|
storage_dir=Path(tmp_path / "storage"),
|
|
)
|
|
assert stats["screened"] == 0
|
|
|
|
@patch("prisma.screen.load_item")
|
|
@patch("prisma.screen.to_markdown", return_value="# Item")
|
|
@patch("prisma.screen.apply_screen_decision")
|
|
def test_screens_items(self, mc_apply, mc_md, mc_load, tmp_path):
|
|
path = _setup(tmp_path)
|
|
with Db(path) as db:
|
|
db.con.execute(
|
|
"INSERT INTO items (itemTypeID, libraryID, key, dateAdded, dateModified, clientDateModified) "
|
|
"VALUES (2, 1, 'K1', '', '', '')"
|
|
)
|
|
iid = db.con.execute("SELECT last_insert_rowid()").fetchone()[0]
|
|
tag_id = db.con.execute(
|
|
"INSERT INTO tags (name) VALUES (?)", ("project:test-proj",)
|
|
).lastrowid
|
|
db.con.execute(
|
|
"INSERT INTO itemTags (itemID, tagID, type) VALUES (?, ?, 0)",
|
|
(iid, tag_id),
|
|
)
|
|
db.commit()
|
|
|
|
provider = MagicMock()
|
|
result = MagicMock()
|
|
result.tool_calls = [
|
|
{
|
|
"input": {
|
|
"decision": "include",
|
|
"reasons": [],
|
|
"themes": [],
|
|
"rationale": "ok",
|
|
}
|
|
}
|
|
]
|
|
provider.complete.return_value = result
|
|
|
|
project = MagicMock()
|
|
project.name = "test-proj"
|
|
project.criteria = "c"
|
|
project.reasons = "r"
|
|
|
|
mc_load.return_value = MagicMock()
|
|
|
|
stats = run(
|
|
db,
|
|
provider,
|
|
project,
|
|
storage_dir=Path(tmp_path / "storage"),
|
|
)
|
|
assert stats["screened"] == 1
|
|
assert stats["include"] == 1
|
|
|
|
@patch("prisma.screen.load_item", side_effect=Exception("boom"))
|
|
def test_handles_error(self, mc_load, tmp_path):
|
|
path = _setup(tmp_path)
|
|
with Db(path) as db:
|
|
db.con.execute(
|
|
"INSERT INTO items (itemTypeID, libraryID, key, dateAdded, dateModified, clientDateModified) "
|
|
"VALUES (2, 1, 'K1', '', '', '')"
|
|
)
|
|
iid = db.con.execute("SELECT last_insert_rowid()").fetchone()[0]
|
|
tag_id = db.con.execute(
|
|
"INSERT INTO tags (name) VALUES (?)", ("project:test-proj",)
|
|
).lastrowid
|
|
db.con.execute(
|
|
"INSERT INTO itemTags (itemID, tagID, type) VALUES (?, ?, 0)",
|
|
(iid, tag_id),
|
|
)
|
|
db.commit()
|
|
|
|
provider = MagicMock()
|
|
project = MagicMock()
|
|
project.name = "test-proj"
|
|
|
|
stats = run(
|
|
db,
|
|
provider,
|
|
project,
|
|
storage_dir=Path(tmp_path / "storage"),
|
|
)
|
|
assert stats["errors"] == 1
|