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).
127 lines
4.3 KiB
Python
127 lines
4.3 KiB
Python
import uuid
|
|
|
|
import pytest
|
|
|
|
from core.base import Message, R2RException
|
|
from shared.api.models.management.responses import (
|
|
ConversationResponse,
|
|
MessageResponse,
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_conversation(conversations_handler):
|
|
resp = await conversations_handler.create_conversation()
|
|
assert isinstance(resp, ConversationResponse)
|
|
assert resp.id is not None
|
|
assert resp.created_at is not None
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_conversation_with_user_and_name(conversations_handler):
|
|
user_id = uuid.uuid4()
|
|
resp = await conversations_handler.create_conversation(user_id=user_id,
|
|
name="Test Conv")
|
|
assert resp.id is not None
|
|
assert resp.created_at is not None
|
|
# There's no direct field for user_id in ConversationResponse,
|
|
# but we can verify by fetch:
|
|
# Just trust it for now since the handler doesn't return user_id directly.
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_add_message(conversations_handler):
|
|
conv = await conversations_handler.create_conversation()
|
|
conv_id = conv.id
|
|
|
|
msg = Message(role="user", content="Hello!")
|
|
resp = await conversations_handler.add_message(conv_id, msg)
|
|
assert isinstance(resp, MessageResponse)
|
|
assert resp.id is not None
|
|
assert resp.message.content == "Hello!"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_add_message_with_parent(conversations_handler):
|
|
conv = await conversations_handler.create_conversation()
|
|
conv_id = conv.id
|
|
|
|
parent_msg = Message(role="user", content="Parent message")
|
|
parent_resp = await conversations_handler.add_message(conv_id, parent_msg)
|
|
parent_id = parent_resp.id
|
|
|
|
child_msg = Message(role="assistant", content="Child reply")
|
|
child_resp = await conversations_handler.add_message(conv_id,
|
|
child_msg,
|
|
parent_id=parent_id)
|
|
assert child_resp.id is not None
|
|
assert child_resp.message.content == "Child reply"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_edit_message(conversations_handler):
|
|
conv = await conversations_handler.create_conversation()
|
|
conv_id = conv.id
|
|
|
|
original_msg = Message(role="user", content="Original")
|
|
resp = await conversations_handler.add_message(conv_id, original_msg)
|
|
msg_id = resp.id
|
|
|
|
updated = await conversations_handler.edit_message(msg_id,
|
|
"Edited content")
|
|
assert updated["message"].content == "Edited content"
|
|
assert updated["metadata"]["edited"] is True
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_message_metadata(conversations_handler):
|
|
conv = await conversations_handler.create_conversation()
|
|
conv_id = conv.id
|
|
|
|
msg = Message(role="user", content="Meta-test")
|
|
resp = await conversations_handler.add_message(conv_id, msg)
|
|
msg_id = resp.id
|
|
|
|
await conversations_handler.update_message_metadata(
|
|
msg_id, {"test_key": "test_value"})
|
|
|
|
# Verify metadata updated
|
|
full_conversation = await conversations_handler.get_conversation(conv_id)
|
|
for m in full_conversation:
|
|
if m.id == str(msg_id):
|
|
assert m.metadata["test_key"] == "test_value"
|
|
break
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_conversation(conversations_handler):
|
|
conv = await conversations_handler.create_conversation()
|
|
conv_id = conv.id
|
|
|
|
msg1 = Message(role="user", content="Msg1")
|
|
msg2 = Message(role="assistant", content="Msg2")
|
|
|
|
await conversations_handler.add_message(conv_id, msg1)
|
|
await conversations_handler.add_message(conv_id, msg2)
|
|
|
|
messages = await conversations_handler.get_conversation(conv_id)
|
|
assert len(messages) == 2
|
|
assert messages[0].message.content == "Msg1"
|
|
assert messages[1].message.content == "Msg2"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delete_conversation(conversations_handler):
|
|
conv = await conversations_handler.create_conversation()
|
|
conv_id = conv.id
|
|
|
|
msg = Message(role="user", content="To be deleted")
|
|
await conversations_handler.add_message(conv_id, msg)
|
|
|
|
await conversations_handler.delete_conversation(conv_id)
|
|
|
|
with pytest.raises(R2RException) as exc:
|
|
await conversations_handler.get_conversation(conv_id)
|
|
assert exc.value.status_code == 404, (
|
|
"Conversation should be deleted and not found")
|