caelum0x 174222bcaa feat: Builder-Track named-user tools, bio + evidence-intelligence platform, Apache-2.0
Builds PaperTrail from the base skeleton into a full evidence-verification platform
for the "Built with Claude: Life Sciences" hackathon (Builder Track).

New named-user features (Build Beyond the Bench):
- Lab Notebook Companion — rough bench notes -> structured, searchable, grounded
  experiment records (lib/labNotebook, /console/lab-notebook, migration 0059)
- Clinical Trial Matcher — de-identified patient notes -> ranked eligible
  ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning
  (lib/trialMatcher, /console/trial-matcher, migrations 0060)

Platform:
- Deterministic verification moat (biostats recompute, exact-span grounding)
- 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar,
  PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier)
- Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise
  governance (RBAC, /api/v1 gateway, metering, audit chain, retention)
- 17 OSS projects assimilated into native TypeScript on our stack (backend/engines
  retained + credited in NOTICE)
- Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site
- Next.js 16 upgrade, benchmark harness (honest smoke-test caveat)

Licensing: Apache-2.0 (LICENSE + NOTICE).
2026-07-10 16:23:13 +03:00

119 lines
4.3 KiB
Python

import os
import sys
import zlib
from pathlib import Path
from unittest.mock import patch
import pytest
from tenacity import Retrying, retry_if_exception_type, stop_after_attempt
from paperqa import Docs
from paperqa.agents import ask, build_index, main, search_query
from paperqa.agents.models import AnswerResponse
from paperqa.settings import Settings
from paperqa.utils import pqa_directory
def test_can_modify_settings(capsys, stub_data_dir: Path) -> None:
rel_path_home_to_stub_data = Path("~") / stub_data_dir.relative_to(Path.home())
# This test depends on the unit_test config not previously existing
with pytest.raises(FileNotFoundError, match="unit_test"):
Settings.from_name("unit_test")
old_argv = sys.argv
try:
sys.argv = (
"paperqa -s debug --llm=my-model-foo"
f" --agent.index.paper_directory={rel_path_home_to_stub_data!s} save"
" unit_test"
).split()
main()
captured = capsys.readouterr()
assert not captured.err
assert "Settings saved" in captured.out
settings = Settings.from_name("unit_test")
assert settings.llm == "my-model-foo"
assert settings.agent.index.paper_directory == str(rel_path_home_to_stub_data)
sys.argv = ["paperqa", "-s", "unit_test", "view"]
main()
captured = capsys.readouterr()
assert not captured.err
assert "my-model-foo" in captured.out
finally:
sys.argv = old_argv
os.unlink(pqa_directory("settings") / "unit_test.json")
def test_cli_ask(agent_index_dir: Path, stub_data_dir: Path) -> None:
settings = Settings.from_name("debug")
settings.agent.index.index_directory = agent_index_dir
settings.agent.index.paper_directory = stub_data_dir
response = ask(
"How can you use XAI for chemical property prediction?", settings=settings
)
assert isinstance(response, AnswerResponse)
assert response.session.formatted_answer
search_result = search_query(
" ".join(response.session.formatted_answer.split()),
"answers",
settings,
)
assert isinstance(search_result, list)
found_answer = search_result[0][0]
assert isinstance(found_answer, AnswerResponse)
assert found_answer.model_dump() == response.model_dump()
def test_cli_can_build_and_search_index(
agent_index_dir: Path, stub_data_dir: Path
) -> None:
rel_path_home_to_stub_data = Path("~") / stub_data_dir.relative_to(Path.home())
settings = Settings.from_name("debug")
settings.agent.index.paper_directory = rel_path_home_to_stub_data
settings.agent.index.index_directory = agent_index_dir
index_name = "test"
for attempt in Retrying(
stop=stop_after_attempt(3),
# zlib.error: Error -5 while decompressing data: incomplete or truncated stream
retry=retry_if_exception_type(zlib.error),
):
with attempt:
build_index(index_name, stub_data_dir, settings)
result = search_query("XAI", index_name, settings)
assert isinstance(result, list)
assert len(result) == 1
assert isinstance(result[0][0], Docs)
assert all(d.startswith("Wellawatte") for d in result[0][0].docnames)
assert result[0][1] == "paper.pdf"
def test_settings_index_name_used_when_index_arg_is_default(
stub_data_dir: Path,
) -> None:
settings = Settings(
agent={"index": {"paper_directory": stub_data_dir, "name": "my_named_index"}}
)
with patch("paperqa.agents.get_directory_index") as mock_get_directory_index:
# When --index isn't provided, the default name of "default" will still
# respect a custom-specified index name
build_index("default", stub_data_dir, settings)
assert settings.agent.index.name == "my_named_index"
mock_get_directory_index.assert_awaited_once_with(settings=settings)
passed_settings = mock_get_directory_index.call_args.kwargs["settings"]
assert passed_settings.agent.index.name == "my_named_index"
with patch("paperqa.agents.index_search", return_value=[]) as mock_index_search:
# When --index isn't provided, the default name of "default" will still
# respect a custom-specified index name
search_query("XAI", "default", settings)
mock_index_search.assert_awaited_once()
assert mock_index_search.call_args.kwargs["index_name"] == "my_named_index"