Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test(citations): cover exporter comma spacing regressions (#7712)

Chanhyo Jung493448d1b472
diff --git a/tests/text_optimization/test_citation_formatter.py b/tests/text_optimization/test_citation_formatter.py
index 6476f3c7af..7c0fe1be9e 100644
--- a/tests/text_optimization/test_citation_formatter.py
+++ b/tests/text_optimization/test_citation_formatter.py
@@ -14,6 +14,38 @@ from local_deep_research.text_optimization import (
class TestCitationFormatter:
"""Test cases for CitationFormatter class."""
+ @pytest.mark.parametrize(
+ "citation", ["[[2 ,3]]", "[[2,3]]"], ids=["spaced", "no-space"]
+ )
+ def test_group_citation_with_space_before_comma(self, citation):
+ """Keep both sources and surrounding prose when exporting a group."""
+ content = f"""# Report
+
+Wetland surveys {citation} support restoring the river floodplain.
+
+## Sources
+
+[2] Second Source
+ URL: https://example.com/2
+
+[3] Third Source
+ URL: https://example.com/3
+"""
+ result = CitationFormatter(
+ CitationMode.NUMBER_HYPERLINKS
+ ).format_document(content)
+ body = next(
+ line
+ for line in result.splitlines()
+ if line.startswith("Wetland surveys ")
+ )
+ assert (
+ "[[2]](https://example.com/2)[[3]](https://example.com/3)" in body
+ )
+ assert body.startswith("Wetland surveys ")
+ assert body.endswith(" support restoring the river floodplain.")
+ assert "[[2 ,3]]" not in result
+
@pytest.fixture
def sample_content(self):
"""Sample markdown content with citations."""
@@ -1333,6 +1365,34 @@ This research explores various topics [1][2][3].
class TestQuartoExporter:
"""Test cases for Quarto export functionality."""
+ @pytest.mark.parametrize(
+ "citation", ["[[2 ,3]]", "[[2,3]]"], ids=["spaced", "no-space"]
+ )
+ def test_group_citation_with_space_before_comma(self, citation):
+ """Keep both sources and surrounding prose when exporting a group."""
+ content = f"""# Report
+
+Wetland surveys {citation} support restoring the river floodplain.
+
+## Sources
+
+[2] Second Source
+ URL: https://example.com/2
+
+[3] Third Source
+ URL: https://example.com/3
+"""
+ result = QuartoExporter().export_to_quarto(content)
+ body = next(
+ line
+ for line in result.splitlines()
+ if line.startswith("Wetland surveys ")
+ )
+ assert "[@ref2, @ref3]" in body
+ assert body.startswith("Wetland surveys ")
+ assert body.endswith(" support restoring the river floodplain.")
+ assert "[[2 ,3]]" not in result
+
@pytest.fixture
def sample_markdown(self):
"""Sample markdown for Quarto conversion."""