async def test_document_citation_processing(mock_document_handler, sample_document):
    """Test citation extraction and processing in documents."""
    from core.main.services.documents import DocumentProcessingService

    # Add citation markers to document text
    document_with_citations = Document(
        document_id="doc-456",
        raw_text="According to Smith [abc123], Aristotle developed formal logic. Jones [def456] argues that his ethics were revolutionary.",
        metadata={"source": "Academic Journal"}
    )

    # Setup document processing service
    service = DocumentProcessingService(document_handler=mock_document_handler)

    # Mock citation extraction method
    original_extract_citations = service.extract_citations
    service.extract_citations = MagicMock(return_value=[
        {"id": "abc123", "span": "According to Smith [abc123]", "start": 0, "end": 25},
        {"id": "def456", "span": "Jones [def456]", "start": 54, "end": 68}
    ])

    # Process document with citation extraction
    processed_doc = await service.process_document(
        document_with_citations,
        extract_citations=True
    )

    # Verify citation extraction was called
    service.extract_citations.assert_called_once_with(document_with_citations.raw_text)

    # Check that citations were stored with the document
    assert "citations" in processed_doc.metadata
    assert len(processed_doc.metadata["citations"]) == 2
    assert processed_doc.metadata["citations"][0]["id"] == "abc123"
    assert processed_doc.metadata["citations"][1]["id"] == "def456"

    # Restore original method
    service.extract_citations = original_extract_citations
Test citation extraction and processing in documents.
py/tests/unit/document/test_document_processing.py