def test_structured_citation_formatting(self, mock_citation_results):
        """Test formatting structured citations with academic format."""
        # Function to format structured citations
        def format_structured_citations(search_results):
            citations = {}

            # Extract citation information
            for result in search_results["chunk_search_results"]:
                citation_id = result.get("metadata", {}).get("citation_id")
                if not citation_id:
                    continue

                # Skip if we've already processed this citation
                if citation_id in citations:
                    continue

                # Extract metadata
                metadata = result.get("metadata", {})
                authors = metadata.get("authors", [])
                title = metadata.get("title", "Untitled")
                source = metadata.get("source", "Unknown source")
                page = metadata.get("page", None)

                # Format citation in academic style
                author_text = ", ".join(authors) if authors else "Unknown author"
                citation_text = f"{author_text}. \"{title}\". {source}"
                if page:
                    citation_text += f", p. {page}"

                # Store the formatted citation
                citations[citation_id] = {
                    "text": citation_text,
                    "document_id": result.get("document_id"),
                    "chunk_id": result.get("chunk_id")
                }

            return citations

        # Format citations
        citations = format_structured_citations(mock_citation_results)

        # Check formatting
        assert len(citations) == 5, "Should have 5 unique citations"
        assert "Author A, Author B" in citations["cite0"]["text"], "Should include authors"
        assert "Document 0" in citations["cite0"]["text"], "Should include title"
        assert "source-0" in citations["cite0"]["text"], "Should include source"
        assert "p. 1" in citations["cite0"]["text"], "Should include page number"
Test formatting structured citations with academic format.
py/tests/unit/retrieval/test_rag_processing.py