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.

feat: add argparse, static mode, and search sources to E2E test

LearningCircuitb9680e58c9a5
diff --git a/.github/workflows/e2e-research-test.yml b/.github/workflows/e2e-research-test.yml
index 62a45981a3..2eff07d087 100644
--- a/.github/workflows/e2e-research-test.yml
+++ b/.github/workflows/e2e-research-test.yml
@@ -7,14 +7,16 @@ on:
permissions: {} # Minimal top-level for OSSF Scorecard
jobs:
- research-diff:
- name: LDR Research on PR Diff
+ research:
+ name: LDR Research
runs-on: ubuntu-latest
- if: github.event.label.name == 'ldr_research'
+ if: github.event.label.name == 'ldr_research' || github.event.label.name == 'ldr_research_static'
permissions:
contents: read
pull-requests: write
issues: write
+ env:
+ LABEL_NAME: ${{ github.event.label.name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
@@ -25,6 +27,7 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y jq
- name: Get PR diff
+ if: github.event.label.name == 'ldr_research'
run: |
git fetch origin ${{ github.event.pull_request.base.ref }}
git diff origin/${{ github.event.pull_request.base.ref }}...HEAD --no-color > diff.txt
@@ -47,9 +50,19 @@ jobs:
LDR_MODEL: ${{ vars.LDR_MODEL || '' }}
LDR_ITERATIONS: ${{ vars.LDR_ITERATIONS || '1' }}
MAX_DIFF_SIZE: ${{ vars.MAX_DIFF_SIZE || '8000' }}
+ LDR_MODE: ${{ github.event.label.name == 'ldr_research_static' && 'static' || 'diff' }}
run: |
set +e
- RESPONSE=$(python scripts/ldr-diff-research.py < diff.txt 2>&1)
+
+ # Run in appropriate mode
+ if [ "$LDR_MODE" = "static" ]; then
+ echo "Running in STATIC mode (fixed query for regression testing)"
+ RESPONSE=$(python scripts/ldr-diff-research.py --mode static 2>&1)
+ else
+ echo "Running in DIFF mode (researching PR changes)"
+ RESPONSE=$(python scripts/ldr-diff-research.py --mode diff < diff.txt 2>&1)
+ fi
+
EXIT_CODE=$?
set -e
@@ -72,7 +85,10 @@ jobs:
exit 1
fi
- # Extract research
+ # Save full response for later steps
+ echo "$RESPONSE" > response.json
+
+ # Extract research summary
echo "$RESPONSE" | jq -r '.research' > result.md
echo "✅ Research completed"
@@ -80,11 +96,36 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
+ # Get mode from response
+ MODE=$(jq -r '.mode // "diff"' response.json)
+
+ # Build comment header based on mode
+ if [ "$MODE" = "static" ]; then
+ HEADER="## 🧪 LDR Static Query Test Results"
+ QUERY=$(jq -r '.query // empty' response.json)
+ SUBHEADER="**Query:** $QUERY"
+ else
+ HEADER="## 🔬 LDR Research Results"
+ SUBHEADER="_Analysis of PR code changes_"
+ fi
+
+ # Extract sources and format them
+ SOURCES=$(jq -r '.sources[:10][] | "- [\(.title)](\(.url))"' response.json 2>/dev/null || echo "")
+
+ # Build comment
{
- echo "## 🔬 LDR Research Results"
+ echo "$HEADER"
+ echo ""
+ echo "$SUBHEADER"
echo ""
cat result.md
echo ""
+ if [ -n "$SOURCES" ]; then
+ echo "### 🔍 Search Sources"
+ echo ""
+ echo "$SOURCES"
+ echo ""
+ fi
echo "---"
echo "_Generated by [Local Deep Research](https://github.com/LearningCircuit/local-deep-research) E2E test_"
} > comment.md
@@ -96,8 +137,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
- gh issue edit ${{ github.event.pull_request.number }} --remove-label "ldr_research" 2>/dev/null || true
+ gh issue edit ${{ github.event.pull_request.number }} --remove-label "$LABEL_NAME" 2>/dev/null || true
- name: Cleanup
if: always()
- run: rm -f diff.txt result.md comment.md
+ run: rm -f diff.txt result.md comment.md response.json
diff --git a/scripts/ldr-diff-research.py b/scripts/ldr-diff-research.py
index 3b53e3e9e7..e2b65ea807 100755
--- a/scripts/ldr-diff-research.py
+++ b/scripts/ldr-diff-research.py
@@ -6,16 +6,21 @@ Reads a code diff from stdin and uses Local Deep Research to find
relevant documentation, best practices, and known issues.
Usage:
+ # Diff mode (default) - research a code diff
cat diff.txt | python scripts/ldr-diff-research.py
git diff HEAD~1 | python scripts/ldr-diff-research.py
-Output: JSON with 'research' field containing the markdown research results.
+ # Static mode - run a fixed query for regression testing
+ python scripts/ldr-diff-research.py --mode static
-Environment variables (required):
- OPENROUTER_API_KEY - API key for OpenRouter (or other provider)
- SERPER_API_KEY - API key for Serper.dev search
+ # With CLI arguments (easier local testing)
+ python scripts/ldr-diff-research.py --provider openrouter --model gpt-4o < diff.txt
+
+Output: JSON with research results, sources, and findings.
-Environment variables (optional):
+Environment variables (can be overridden by CLI args):
+ OPENROUTER_API_KEY - API key for OpenRouter
+ SERPER_API_KEY - API key for Serper.dev search
LDR_PROVIDER - LLM provider (default: openrouter)
LDR_SEARCH_TOOL - Search tool (default: serper)
LDR_MODEL - Model name (default: google/gemini-2.0-flash-001 for openrouter)
@@ -25,45 +30,155 @@ Environment variables (optional):
Note: This uses the programmatic API and does NOT require a running LDR server.
"""
+import argparse
import json
import os
import sys
+# Default static query for regression testing
+DEFAULT_STATIC_QUERY = "What is Local Deep Research and how does it work?"
+
+
+def parse_args():
+ parser = argparse.ArgumentParser(
+ description="Run LDR research on code diffs or static queries"
+ )
+ parser.add_argument(
+ "--mode",
+ choices=["diff", "static"],
+ default=os.environ.get("LDR_MODE", "diff"),
+ help="Research mode: 'diff' for PR diffs, 'static' for fixed query",
+ )
+ parser.add_argument(
+ "--provider",
+ default=os.environ.get("LDR_PROVIDER", "openrouter"),
+ help="LLM provider (default: openrouter)",
+ )
+ parser.add_argument(
+ "--search-tool",
+ default=os.environ.get("LDR_SEARCH_TOOL", "serper"),
+ help="Search tool (default: serper)",
+ )
+ parser.add_argument(
+ "--model",
+ default=os.environ.get("LDR_MODEL"),
+ help="Model name (default: provider's default)",
+ )
+ parser.add_argument(
+ "--iterations",
+ type=int,
+ default=int(os.environ.get("LDR_ITERATIONS", "1")),
+ help="Number of research iterations (default: 1)",
+ )
+ parser.add_argument(
+ "--max-diff-size",
+ type=int,
+ default=int(os.environ.get("MAX_DIFF_SIZE", "8000")),
+ help="Max diff size in bytes (default: 8000)",
+ )
+ parser.add_argument(
+ "--static-query",
+ default=os.environ.get("LDR_STATIC_QUERY", DEFAULT_STATIC_QUERY),
+ help=f"Query for static mode (default: '{DEFAULT_STATIC_QUERY}')",
+ )
+ return parser.parse_args()
+
+
+def extract_sources(result):
+ """Extract source URLs from the result."""
+ sources = []
+
+ # Get sources directly from result
+ for source in result.get("sources", []):
+ if isinstance(source, dict):
+ sources.append(
+ {
+ "title": source.get("title", "Unknown"),
+ "url": source.get("url", source.get("link", "")),
+ }
+ )
+ elif isinstance(source, str):
+ sources.append({"title": source, "url": ""})
+
+ # Also check findings for search_results
+ for finding in result.get("findings", []):
+ if isinstance(finding, dict) and "search_results" in finding:
+ for sr in finding.get("search_results", []):
+ if isinstance(sr, dict):
+ sources.append(
+ {
+ "title": sr.get("title", "Unknown"),
+ "url": sr.get("url", sr.get("link", "")),
+ }
+ )
+
+ # Deduplicate by URL
+ seen_urls = set()
+ unique_sources = []
+ for s in sources:
+ url = s.get("url", "")
+ if url and url not in seen_urls:
+ seen_urls.add(url)
+ unique_sources.append(s)
+ elif not url and s.get("title") not in seen_urls:
+ seen_urls.add(s.get("title", ""))
+ unique_sources.append(s)
+
+ return unique_sources
+
def main():
- # Read diff from stdin
- diff = sys.stdin.read()
+ args = parse_args()
+
+ # Determine query based on mode
+ if args.mode == "static":
+ query = args.static_query
+ diff = None
+ else:
+ # Read diff from stdin
+ diff = sys.stdin.read()
+ if not diff.strip():
+ print(
+ json.dumps(
+ {
+ "error": "No diff provided (use --mode static for fixed query)"
+ }
+ )
+ )
+ sys.exit(1)
+
+ # Truncate if too large
+ if len(diff) > args.max_diff_size:
+ diff = diff[: args.max_diff_size] + "\n... (truncated)"
+
+ query = f"""Based on these code changes, research relevant documentation,
+best practices, and potential issues. Focus on any libraries, APIs, or patterns used.
- if not diff.strip():
- print(json.dumps({"error": "No diff provided", "research": ""}))
- sys.exit(1)
+Code changes:
+{diff}
- # Get settings from environment
- provider = os.environ.get("LDR_PROVIDER", "openrouter")
- search_tool = os.environ.get("LDR_SEARCH_TOOL", "serper")
- # Default to a known good OpenRouter model if not specified
- default_model = (
- "google/gemini-2.0-flash-001" if provider == "openrouter" else None
- )
- model_name = os.environ.get("LDR_MODEL") or default_model
- iterations = int(os.environ.get("LDR_ITERATIONS", "1"))
- max_size = int(os.environ.get("MAX_DIFF_SIZE", "8000"))
-
- # Check required API keys based on provider/search tool
- if provider == "openrouter" and not os.environ.get("OPENROUTER_API_KEY"):
- print(
- json.dumps({"error": "OPENROUTER_API_KEY not set", "research": ""})
- )
+Research topics to cover:
+1. Documentation for any libraries or APIs being used/modified
+2. Best practices for the patterns shown
+3. Known issues or gotchas related to these changes
+4. Security considerations if applicable"""
+
+ # Default model for OpenRouter if not specified
+ model_name = args.model
+ if not model_name and args.provider == "openrouter":
+ model_name = "google/gemini-2.0-flash-001"
+
+ # Check required API keys
+ if args.provider == "openrouter" and not os.environ.get(
+ "OPENROUTER_API_KEY"
+ ):
+ print(json.dumps({"error": "OPENROUTER_API_KEY not set"}))
sys.exit(1)
- if search_tool == "serper" and not os.environ.get("SERPER_API_KEY"):
- print(json.dumps({"error": "SERPER_API_KEY not set", "research": ""}))
+ if args.search_tool == "serper" and not os.environ.get("SERPER_API_KEY"):
+ print(json.dumps({"error": "SERPER_API_KEY not set"}))
sys.exit(1)
- # Truncate if too large
- if len(diff) > max_size:
- diff = diff[:max_size] + "\n... (truncated)"
-
try:
from local_deep_research.api import quick_summary
from local_deep_research.api.settings_utils import (
@@ -72,8 +187,8 @@ def main():
# Build settings overrides
overrides = {
- "search.tool": search_tool,
- "llm.provider": provider,
+ "search.tool": args.search_tool,
+ "llm.provider": args.provider,
}
if model_name:
overrides["llm.model"] = model_name
@@ -90,33 +205,33 @@ def main():
# Build kwargs
kwargs = {
- "query": f"""Based on these code changes, research relevant documentation,
-best practices, and potential issues. Focus on any libraries, APIs, or patterns used.
-
-Code changes:
-{diff}
-
-Research topics to cover:
-1. Documentation for any libraries or APIs being used/modified
-2. Best practices for the patterns shown
-3. Known issues or gotchas related to these changes
-4. Security considerations if applicable""",
- "provider": provider,
+ "query": query,
+ "provider": args.provider,
"settings_snapshot": settings,
"programmatic_mode": True,
- "iterations": iterations,
+ "iterations": args.iterations,
}
-
if model_name:
kwargs["model_name"] = model_name
result = quick_summary(**kwargs)
- research = result.get("summary", str(result))
- print(json.dumps({"research": research}))
+ # Build output with research and sources
+ output = {
+ "mode": args.mode,
+ "research": result.get("summary", str(result)),
+ "sources": extract_sources(result),
+ "iterations": result.get("iterations", args.iterations),
+ }
+
+ # Include query for static mode (for verification)
+ if args.mode == "static":
+ output["query"] = query
+
+ print(json.dumps(output))
except Exception as e:
- print(json.dumps({"error": str(e), "research": ""}))
+ print(json.dumps({"error": str(e)}))
sys.exit(1)