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.

fix: resolve import error in text optimization tests and split CI workflow

LearningCircuit5d48973e6188
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index e1f8466435..1cdcf5dd13 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -109,10 +109,63 @@ jobs:
ldr-test \
sh -c "cd tests && python run_all_tests.py ci --no-server-start"
- # Full tests for PRs to main/dev branches and main branch pushes
- full-tests:
+ # Health check tests
+ health-check:
runs-on: ubuntu-latest
- name: Full Test Suite
+ name: Health Check
+ needs: [unit-tests, infrastructure-tests]
+ if: |
+ github.event_name == 'pull_request' ||
+ github.ref == 'refs/heads/main' ||
+ github.ref == 'refs/heads/dev'
+
+ steps:
+ - uses: actions/checkout@v5
+
+ - name: Build Docker image
+ run: docker build --target ldr-test -t ldr-test .
+
+ - name: Run health check
+ run: |
+ docker run --rm \
+ -v $PWD:/app \
+ -e LDR_USE_FALLBACK_LLM=true \
+ -e LDR_TESTING_WITH_MOCKS=true \
+ -w /app \
+ ldr-test \
+ sh -c "cd tests && python run_all_tests.py ci --tests health"
+
+ # Pytest tests
+ pytest-tests:
+ runs-on: ubuntu-latest
+ name: Pytest Suite
+ needs: [unit-tests, infrastructure-tests]
+ if: |
+ github.event_name == 'pull_request' ||
+ github.ref == 'refs/heads/main' ||
+ github.ref == 'refs/heads/dev'
+
+ steps:
+ - uses: actions/checkout@v5
+
+ - name: Build Docker image
+ run: docker build --target ldr-test -t ldr-test .
+
+ - name: Run pytest tests
+ run: |
+ docker run --rm \
+ -v $PWD:/app \
+ -e LDR_USE_FALLBACK_LLM=true \
+ -e LDR_TESTING_WITH_MOCKS=true \
+ -e CI=true \
+ -w /app \
+ ldr-test \
+ sh -c "cd tests && python run_all_tests.py ci --tests pytest"
+
+ # UI tests
+ ui-tests-full:
+ runs-on: ubuntu-latest
+ name: UI Tests (Puppeteer)
needs: [unit-tests, infrastructure-tests]
if: |
github.event_name == 'pull_request' ||
@@ -135,10 +188,6 @@ jobs:
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
cd tests && npm install
- - name: Install infrastructure test dependencies
- run: |
- cd tests/infrastructure_tests && npm install
-
- name: Start application server in Docker
run: |
docker run -d \
@@ -171,7 +220,7 @@ jobs:
exit 1
fi
- - name: Run optimized full test suite (including UI tests)
+ - name: Run UI tests
run: |
docker run --rm \
-v $PWD:/app \
@@ -181,11 +230,7 @@ jobs:
--network host \
-w /app \
ldr-test \
- sh -c "cd tests && python run_all_tests.py full"
-
- - name: Run JavaScript infrastructure tests
- run: |
- cd tests/infrastructure_tests && npm test
+ sh -c "cd tests && python run_all_tests.py ci --tests ui"
- name: Stop server
if: always()
@@ -193,13 +238,12 @@ jobs:
docker stop ldr-server || true
docker rm ldr-server || true
- - name: Upload test results and screenshots
+ - name: Upload UI test screenshots
if: always()
uses: actions/upload-artifact@v4
with:
- name: full-test-results
+ name: ui-test-screenshots
path: |
- tests/test_results.json
tests/screenshots/
tests/ui_tests/screenshots/
# Force CI rebuild
diff --git a/src/local_deep_research/text_optimization/README.md b/src/local_deep_research/text_optimization/README.md
index ec8d3aa41f..8c654f662b 100644
--- a/src/local_deep_research/text_optimization/README.md
+++ b/src/local_deep_research/text_optimization/README.md
@@ -65,16 +65,16 @@ Export formats can be configured to automatically export reports in multiple for
### Export Examples
```python
-from local_deep_research.web.services.research_service import export_report_to_format, export_report_to_latex
+from local_deep_research.web.services.research_service import export_report_to_memory
-# Export to LaTeX
-latex_path = export_report_to_latex(report_path)
+# Export to LaTeX (returns bytes, filename, mimetype)
+latex_bytes, filename, mimetype = export_report_to_memory(markdown_content, "latex")
-# Export to Quarto
-quarto_path = export_report_to_format(report_path, "quarto")
+# Export to Quarto (returns zip file with .qmd and .bib files)
+zip_bytes, filename, mimetype = export_report_to_memory(markdown_content, "quarto")
# Export to Quarto with custom title
-quarto_path = export_report_to_format(report_path, "quarto", "My Research Title")
+zip_bytes, filename, mimetype = export_report_to_memory(markdown_content, "quarto", "My Research Title")
```
## Testing
diff --git a/tests/text_optimization/test_integration.py b/tests/text_optimization/test_integration.py
index 1547786c49..f3bd4d64ab 100644
--- a/tests/text_optimization/test_integration.py
+++ b/tests/text_optimization/test_integration.py
@@ -1,13 +1,11 @@
"""Integration tests for text optimization with the research service."""
import pytest
-from pathlib import Path
-import tempfile
from unittest.mock import patch
from local_deep_research.web.services.research_service import (
get_citation_formatter,
- export_report_to_format,
+ export_report_to_memory,
)
from local_deep_research.text_optimization import (
CitationFormatter,
@@ -56,11 +54,7 @@ class TestResearchServiceIntegration:
def test_export_report_to_latex(self):
"""Test LaTeX export functionality."""
- # Create a temporary markdown file
- with tempfile.NamedTemporaryFile(
- mode="w", suffix=".md", delete=False
- ) as f:
- f.write("""# Test Report
+ markdown_content = """# Test Report
This is a test with citation [1].
@@ -68,30 +62,23 @@ This is a test with citation [1].
[1] Test Source
URL: https://example.com
-""")
- markdown_path = Path(f.name)
-
- try:
- # Export to LaTeX
- latex_path = export_report_to_format(markdown_path, "latex")
-
- # Check LaTeX file was created
- assert latex_path.exists()
- assert latex_path.suffix == ".tex"
+"""
+ # Export to LaTeX
+ latex_bytes, filename, mimetype = export_report_to_memory(
+ markdown_content, "latex"
+ )
- # Check LaTeX content
- with open(latex_path, "r") as f:
- latex_content = f.read()
+ # Check export results
+ assert filename.endswith(".tex")
+ assert mimetype == "text/plain"
- assert r"\documentclass[12pt]{article}" in latex_content
- assert r"\section{Test Report}" in latex_content
- assert r"\cite{1}" in latex_content
- assert r"\bibitem{1}" in latex_content
+ # Check LaTeX content
+ latex_content = latex_bytes.decode("utf-8")
- # Clean up
- latex_path.unlink()
- finally:
- markdown_path.unlink()
+ assert r"\documentclass[12pt]{article}" in latex_content
+ assert r"\section{Test Report}" in latex_content
+ assert r"\cite{1}" in latex_content
+ assert r"\bibitem{1}" in latex_content
@patch("local_deep_research.config.search_config.get_setting_from_snapshot")
def test_real_world_citation_formatting(self, mock_get_setting):
@@ -177,11 +164,7 @@ Recent architectural innovations include:
def test_export_report_to_quarto(self):
"""Test Quarto export functionality."""
- # Create a temporary markdown file
- with tempfile.NamedTemporaryFile(
- mode="w", suffix=".md", delete=False
- ) as f:
- f.write("""# AI Research Report
+ markdown_content = """# AI Research Report
This report discusses recent advances [1] and challenges [2].
@@ -191,22 +174,32 @@ This report discusses recent advances [1] and challenges [2].
URL: https://arxiv.org/abs/2024.1234
[2] AI Challenges
URL: https://example.com/challenges
-""")
- markdown_path = Path(f.name)
+"""
+ # Export to Quarto
+ zip_bytes, filename, mimetype = export_report_to_memory(
+ markdown_content, "quarto", "AI Research"
+ )
- try:
- # Export to Quarto
- quarto_path = export_report_to_format(
- markdown_path, "quarto", "AI Research"
- )
+ # Check export results
+ assert filename.endswith(".zip")
+ assert mimetype == "application/zip"
- # Check Quarto file was created
- assert quarto_path.exists()
- assert quarto_path.suffix == ".qmd"
+ # Extract and check content from zip
+ import zipfile
+ import io
+
+ zip_buffer = io.BytesIO(zip_bytes)
+ with zipfile.ZipFile(zip_buffer, "r") as zipf:
+ # Check files in zip
+ file_list = zipf.namelist()
+ qmd_files = [f for f in file_list if f.endswith(".qmd")]
+ bib_files = [f for f in file_list if f.endswith(".bib")]
+
+ assert len(qmd_files) == 1, "Should have one .qmd file"
+ assert len(bib_files) == 1, "Should have one .bib file"
# Check Quarto content
- with open(quarto_path, "r") as f:
- quarto_content = f.read()
+ quarto_content = zipf.read(qmd_files[0]).decode("utf-8")
# Verify YAML header
assert 'title: "AI Research"' in quarto_content
@@ -216,35 +209,18 @@ This report discusses recent advances [1] and challenges [2].
assert "[@ref1]" in quarto_content
assert "[@ref2]" in quarto_content
- # Check bibliography file was created
- bib_path = markdown_path.parent / "references.bib"
- assert bib_path.exists()
-
- with open(bib_path, "r") as f:
- bib_content = f.read()
+ # Check bibliography content
+ bib_content = zipf.read(bib_files[0]).decode("utf-8")
assert "@misc{ref1," in bib_content
assert 'title = "{Advances in AI}"' in bib_content
- # Clean up
- quarto_path.unlink()
- bib_path.unlink()
- finally:
- markdown_path.unlink()
-
def test_export_with_invalid_format(self):
"""Test export with invalid format raises error."""
- with tempfile.NamedTemporaryFile(
- mode="w", suffix=".md", delete=False
- ) as f:
- f.write("# Test")
- markdown_path = Path(f.name)
-
- try:
- with pytest.raises(ValueError, match="Unsupported export format"):
- export_report_to_format(markdown_path, "invalid_format")
- finally:
- markdown_path.unlink()
+ markdown_content = "# Test"
+
+ with pytest.raises(ValueError, match="Unsupported export format"):
+ export_report_to_memory(markdown_content, "invalid_format")
@patch("local_deep_research.config.search_config.get_setting_from_snapshot")
def test_automatic_export_formats(self, mock_get_setting):