def test_hybrid_citation_strategy(self, mock_citation_results):
        """Test hybrid citation strategy with footnotes and bibliography."""
        # Function to process text with hybrid citation strategy
        def process_with_hybrid_citations(response_text, citation_metadata):
            import re

            # Step 1: Replace inline citations with footnote numbers
            footnotes = []
            footnote_index = 1

            def footnote_replacement(match):
                nonlocal footnote_index
                citation_id = match.group(1)

                if citation_id in citation_metadata:
                    # Add footnote
                    citation = citation_metadata[citation_id]
                    source = citation.get("source", "Unknown source")
                    title = citation.get("title", "Untitled")
                    authors = citation.get("authors", ["Unknown author"])
                    author_text = ", ".join(authors)

                    footnote = f"{footnote_index}. {author_text}. \"{title}\". {source}."
                    footnotes.append(footnote)

                    # Return footnote reference in text
                    result = f"[{footnote_index}]"
                    footnote_index += 1
                    return result

                return match.group(0)  # Keep original if not found

            # Replace [citeX] format with footnote numbers
            pattern = r'\[(cite\d+)\]'
            processed_text = re.sub(pattern, footnote_replacement, response_text)

            # Step 2: Add footnotes at the end
            if footnotes:
                processed_text += "\n\nFootnotes:\n" + "\n".join(footnotes)

            # Step 3: Add bibliography
            bibliography = []
            for citation_id, citation in citation_metadata.items():
                if any(f"[{citation_id}]" in response_text for citation_id in citation_metadata):
                    source = citation.get("source", "Unknown source")
                    title = citation.get("title", "Untitled")
                    authors = citation.get("authors", ["Unknown author"])
                    year = citation.get("year", "n.d.")

                    bib_entry = f"{', '.join(authors)}. ({year}). \"{title}\". {source}."
                    bibliography.append(bib_entry)

            if bibliography:
                processed_text += "\n\nBibliography:\n" + "\n".join(bibliography)

            return processed_text

        # Create mock citation metadata
        citation_metadata = {
            f"cite{i}": {
                "authors": [f"Author {chr(65+i)}"] + (["et al."] if i % 2 == 0 else []),
                "year": 2020 + i,
                "title": f"Document {i//2}",
                "source": f"Journal of Philosophy, Volume {i+1}"
            }
            for i in range(5)
        }

        # Response with citation placeholders
        response_with_placeholders = (
            "Aristotle's ethics [cite0] focuses on virtue ethics. "
            "This contrasts with utilitarianism [cite2] which focuses on outcomes. "
            "Later philosophers [cite4] expanded on these ideas."
        )

        # Apply hybrid citation processing
        final_response = process_with_hybrid_citations(response_with_placeholders, citation_metadata)

        # Check formatting
        assert "[1]" in final_response
        assert "[2]" in final_response
        assert "[3]" in final_response
        assert "Footnotes:" in final_response
        assert "Bibliography:" in final_response
        assert "Journal of Philosophy" in final_response
        assert "[cite0]" not in final_response
        assert "[cite2]" not in final_response
        assert "[cite4]" not in final_response
Test hybrid citation strategy with footnotes and bibliography.
py/tests/unit/retrieval/test_rag_processing.py