~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
test: add 76 tests for news strategy, news questions, and xbench dataset pure logic (#2486)
LearningCircuit30be28e457e3
diff --git a/tests/advanced_search_system/questions/test_news_question_generator.py b/tests/advanced_search_system/questions/test_news_question_generator.pynew file mode 100644index 0000000000..e6b38a49c4--- /dev/null+++ b/tests/advanced_search_system/questions/test_news_question_generator.py@@ -0,0 +1,283 @@+"""+Tests for NewsQuestionGenerator.generate_questions() pure logic.++Existing tests: none — this file is the first test coverage.++Covers:+- Default query generation (base_queries list slicing)+- Focused query generation when user provides specific query+- Date formatting in queries+- questions_per_iteration limiting+- Edge cases: empty query, "latest important news today" passthrough+"""++from unittest.mock import Mock++from freezegun import freeze_time+++def _make_generator():+ """Create a NewsQuestionGenerator with a mocked LLM."""+ from local_deep_research.advanced_search_system.questions.news_question import (+ NewsQuestionGenerator,+ )++ return NewsQuestionGenerator(model=Mock())+++class TestDefaultQueryGeneration:+ """Tests for base query generation without specific focus."""++ @freeze_time("2025-03-15")+ def test_returns_list_of_strings(self):+ """Returns a list of string queries."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="latest important news today",+ )+ assert isinstance(result, list)+ assert all(isinstance(q, str) for q in result)++ @freeze_time("2025-03-15")+ def test_default_returns_8_queries(self):+ """Default questions_per_iteration=8 returns 8 queries."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="latest important news today",+ )+ assert len(result) == 8++ @freeze_time("2025-03-15")+ def test_respects_questions_per_iteration(self):+ """Returns only the requested number of queries."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="latest important news today",+ questions_per_iteration=3,+ )+ assert len(result) == 3++ @freeze_time("2025-03-15")+ def test_contains_date_string(self):+ """Base queries contain today's formatted date."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="latest important news today",+ )+ date_queries = [q for q in result if "March 15, 2025" in q]+ assert len(date_queries) > 0++ @freeze_time("2025-03-15")+ def test_breaking_news_in_queries(self):+ """At least one query contains 'breaking news'."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="latest important news today",+ )+ assert any("breaking news" in q for q in result)++ @freeze_time("2025-03-15")+ def test_covers_diverse_categories(self):+ """Queries cover diverse news categories."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="latest important news today",+ )+ all_text = " ".join(result)+ assert "economic" in all_text.lower()+ assert "political" in all_text.lower()+ assert "technology" in all_text.lower()++ @freeze_time("2025-12-25")+ def test_date_format_december(self):+ """Date formatting works for different months."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="latest important news today",+ )+ date_queries = [q for q in result if "December 25, 2025" in q]+ assert len(date_queries) > 0+++class TestFocusedQueryGeneration:+ """Tests when user provides a specific query focus."""++ @freeze_time("2025-06-01")+ def test_focused_returns_8_queries(self):+ """Focused query returns 3 focus + 5 base = 8 queries."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="climate change",+ )+ assert len(result) == 8++ @freeze_time("2025-06-01")+ def test_focus_queries_come_first(self):+ """Focus-specific queries appear before base queries."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="AI regulation",+ )+ # First 3 should contain the user's query+ assert "AI regulation" in result[0]+ assert "AI regulation" in result[1]+ assert "AI regulation" in result[2]++ @freeze_time("2025-06-01")+ def test_focus_query_includes_date(self):+ """First focus query includes the date."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="elections",+ )+ assert "June 01, 2025" in result[0]++ @freeze_time("2025-06-01")+ def test_focus_query_includes_breaking_news(self):+ """Second focus query includes 'breaking news'."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="elections",+ )+ assert "breaking news" in result[1]++ @freeze_time("2025-06-01")+ def test_focus_query_includes_latest_developments(self):+ """Third focus query includes 'latest developments'."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="elections",+ )+ assert "latest developments" in result[2]++ @freeze_time("2025-06-01")+ def test_base_queries_follow_focus(self):+ """Base queries follow the 3 focus queries."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="space exploration",+ )+ # Items 3-7 should be from the base queries (first 5)+ assert len(result) == 8+ # These should NOT contain the user query+ base_part = result[3:]+ assert all("space exploration" not in q for q in base_part)+++class TestEmptyAndEdgeCaseQueries:+ """Tests for edge case query values."""++ @freeze_time("2025-06-01")+ def test_empty_string_query_uses_base(self):+ """Empty string query returns base queries."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="",+ )+ # Empty query is falsy, so base queries are used+ assert len(result) == 8++ @freeze_time("2025-06-01")+ def test_exact_default_query_uses_base(self):+ """The exact string 'latest important news today' uses base queries."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="latest important news today",+ )+ # This specific string triggers the default path+ assert len(result) == 8+ # None should contain "latest important news today" as a prefix+ # (they're base queries, not focus queries)+ assert "latest important news today" not in result[0]++ @freeze_time("2025-06-01")+ def test_questions_per_iteration_larger_than_base(self):+ """Requesting more questions than base queries returns all available."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="latest important news today",+ questions_per_iteration=20,+ )+ # Only 8 base queries exist+ assert len(result) == 8++ @freeze_time("2025-06-01")+ def test_questions_per_iteration_zero(self):+ """Zero questions_per_iteration returns empty list."""+ gen = _make_generator()+ result = gen.generate_questions(+ current_knowledge="",+ query="latest important news today",+ questions_per_iteration=0,+ )+ assert result == []++ @freeze_time("2025-06-01")+ def test_none_questions_by_iteration(self):+ """None questions_by_iteration is accepted."""+ gen = _make_generator()+ # Should not raise+ result = gen.generate_questions(+ current_knowledge="some knowledge",+ query="latest important news today",+ questions_by_iteration=None,+ )+ assert isinstance(result, list)++ @freeze_time("2025-06-01")+ def test_current_knowledge_ignored(self):+ """current_knowledge doesn't affect output (news uses template queries)."""+ gen = _make_generator()+ result_empty = gen.generate_questions(+ current_knowledge="",+ query="latest important news today",+ )+ result_full = gen.generate_questions(+ current_knowledge="Lots of existing knowledge about many topics.",+ query="latest important news today",+ )+ assert result_empty == result_full+++class TestBaseQuestionGeneratorFormatting:+ """Tests for _format_previous_questions from BaseQuestionGenerator."""++ def test_format_previous_questions_empty(self):+ """Empty dict returns empty string."""+ gen = _make_generator()+ result = gen._format_previous_questions({})+ assert result == ""++ def test_format_previous_questions_single_iteration(self):+ """Single iteration formatted correctly."""+ gen = _make_generator()+ result = gen._format_previous_questions({1: ["Q1", "Q2"]})+ assert "Iteration 1:" in result+ assert "- Q1" in result+ assert "- Q2" in result++ def test_format_previous_questions_multiple_iterations(self):+ """Multiple iterations formatted correctly."""+ gen = _make_generator()+ result = gen._format_previous_questions({1: ["Q1"], 2: ["Q2", "Q3"]})+ assert "Iteration 1:" in result+ assert "Iteration 2:" in result+ assert "- Q1" in result+ assert "- Q2" in result+ assert "- Q3" in resultdiff --git a/tests/advanced_search_system/strategies/test_news_strategy_pure_logic.py b/tests/advanced_search_system/strategies/test_news_strategy_pure_logic.pynew file mode 100644index 0000000000..7593f567a1--- /dev/null+++ b/tests/advanced_search_system/strategies/test_news_strategy_pure_logic.py@@ -0,0 +1,424 @@+"""+Tests for NewsAggregationStrategy pure logic methods.++Existing tests: none — this file is the first test coverage.++Covers:+- _format_news_summary: category grouping, top story selection, empty input,+ missing fields, impact scoring, top-3 per category limit+- _fallback_news_extraction: title filtering, headline truncation, snippet+ fallback, max 10 limit, empty/short title filtering+- _create_news_analysis_prompt: snippet joining, field mapping, date inclusion+"""++from unittest.mock import Mock++from freezegun import freeze_time+++def _make_strategy():+ """Create a NewsAggregationStrategy with mocked dependencies."""+ from local_deep_research.advanced_search_system.strategies.news_strategy import (+ NewsAggregationStrategy,+ )++ mock_model = Mock()+ mock_search = Mock()+ return NewsAggregationStrategy(model=mock_model, search=mock_search)+++class TestFormatNewsSummaryEmpty:+ """Tests for _format_news_summary with empty/missing input."""++ def test_empty_list_returns_no_stories_message(self):+ """Empty news_items returns a 'no stories' message."""+ strategy = _make_strategy()+ result = strategy._format_news_summary([])+ assert result == "No significant news stories found."++ def test_none_like_empty(self):+ """Falsy input returns 'no stories' message."""+ strategy = _make_strategy()+ result = strategy._format_news_summary([])+ assert "No significant news stories" in result+++class TestFormatNewsSummaryCategoryGrouping:+ """Tests for category grouping in _format_news_summary."""++ def test_single_category_single_item(self):+ """Single item in single category."""+ strategy = _make_strategy()+ items = [+ {+ "headline": "Earthquake hits region",+ "category": "Environment",+ "impact_score": 8,+ }+ ]+ result = strategy._format_news_summary(items)+ assert "**Environment** (1 stories):" in result+ assert "Earthquake hits region" in result+ assert "(Impact: 8/10)" in result++ def test_multiple_categories(self):+ """Items are grouped by category."""+ strategy = _make_strategy()+ items = [+ {+ "headline": "Market crash",+ "category": "Economy",+ "impact_score": 9,+ },+ {+ "headline": "New vaccine",+ "category": "Health",+ "impact_score": 7,+ },+ {+ "headline": "Trade deal",+ "category": "Economy",+ "impact_score": 6,+ },+ ]+ result = strategy._format_news_summary(items)+ assert "**Economy** (2 stories):" in result+ assert "**Health** (1 stories):" in result++ def test_missing_category_defaults_to_other(self):+ """Items without category key default to 'Other'."""+ strategy = _make_strategy()+ items = [{"headline": "Unknown event", "impact_score": 5}]+ result = strategy._format_news_summary(items)+ assert "**Other** (1 stories):" in result++ def test_top_3_per_category_limit(self):+ """Only top 3 items per category are shown."""+ strategy = _make_strategy()+ items = [+ {"headline": f"Story {i}", "category": "Tech", "impact_score": i}+ for i in range(5)+ ]+ result = strategy._format_news_summary(items)+ # Should show first 3 items (Story 0, 1, 2), not 4 and 5+ assert "Story 0" in result+ assert "Story 1" in result+ assert "Story 2" in result+ # Story 3 and 4 should not appear as bullet points+ lines = [+ line for line in result.split("\n") if line.startswith("- Story")+ ]+ assert len(lines) == 3+++class TestFormatNewsSummaryTopStory:+ """Tests for top story selection in _format_news_summary."""++ def test_top_story_highest_impact(self):+ """Top story is the one with highest impact_score."""+ strategy = _make_strategy()+ items = [+ {"headline": "Minor event", "category": "Other", "impact_score": 3},+ {+ "headline": "Major crisis",+ "category": "Security",+ "impact_score": 10,+ },+ {+ "headline": "Medium event",+ "category": "Other",+ "impact_score": 6,+ },+ ]+ result = strategy._format_news_summary(items)+ assert "**Top Story**: Major crisis" in result++ def test_top_story_missing_impact_defaults_to_zero(self):+ """Items without impact_score are treated as 0."""+ strategy = _make_strategy()+ items = [+ {"headline": "No score", "category": "Other"},+ {"headline": "Has score", "category": "Other", "impact_score": 1},+ ]+ result = strategy._format_news_summary(items)+ assert "**Top Story**: Has score" in result++ def test_top_story_summary_included(self):+ """Top story summary is included."""+ strategy = _make_strategy()+ items = [+ {+ "headline": "Big news",+ "category": "Economy",+ "impact_score": 9,+ "summary": "Markets fell sharply today.",+ }+ ]+ result = strategy._format_news_summary(items)+ assert "Markets fell sharply today." in result++ def test_top_story_missing_summary(self):+ """Missing summary falls back to default."""+ strategy = _make_strategy()+ items = [+ {+ "headline": "No summary story",+ "category": "Other",+ "impact_score": 5,+ }+ ]+ result = strategy._format_news_summary(items)+ assert "No summary available" in result++ def test_found_count_in_header(self):+ """Header shows correct count of news items."""+ strategy = _make_strategy()+ items = [+ {"headline": f"Story {i}", "category": "Tech", "impact_score": i}+ for i in range(4)+ ]+ result = strategy._format_news_summary(items)+ assert "Found 4 significant news stories:" in result++ def test_impact_score_na_when_missing(self):+ """Impact shows N/A when score is missing."""+ strategy = _make_strategy()+ items = [{"headline": "No impact", "category": "Other"}]+ result = strategy._format_news_summary(items)+ assert "(Impact: N/A/10)" in result+++class TestFallbackNewsExtraction:+ """Tests for _fallback_news_extraction."""++ def test_basic_extraction(self):+ """Extracts items from snippets with valid titles."""+ strategy = _make_strategy()+ snippets = [+ {+ "title": "A significant headline here",+ "url": "https://ex.com",+ "snippet": "Details here",+ },+ ]+ result = strategy._fallback_news_extraction(snippets)+ assert result["status"] == "Fallback extraction"+ assert len(result["news_items"]) == 1+ assert (+ result["news_items"][0]["headline"] == "A significant headline here"+ )+ assert result["news_items"][0]["source_url"] == "https://ex.com"++ def test_short_title_filtered_out(self):+ """Titles <= 10 chars are filtered out."""+ strategy = _make_strategy()+ snippets = [+ {"title": "Short", "url": "https://a.com", "snippet": "Content"},+ {+ "title": "0123456789",+ "url": "https://b.com",+ "snippet": "Content",+ }, # exactly 10+ {+ "title": "Long enough title here",+ "url": "https://c.com",+ "snippet": "Content",+ },+ ]+ result = strategy._fallback_news_extraction(snippets)+ assert len(result["news_items"]) == 1+ assert result["news_items"][0]["headline"] == "Long enough title here"++ def test_empty_title_filtered_out(self):+ """Empty string title is filtered out."""+ strategy = _make_strategy()+ snippets = [+ {"title": "", "url": "https://a.com", "snippet": "Content"},+ ]+ result = strategy._fallback_news_extraction(snippets)+ assert len(result["news_items"]) == 0++ def test_headline_truncated_to_60_chars(self):+ """Headlines are truncated to 60 characters."""+ strategy = _make_strategy()+ long_title = "A" * 100+ snippets = [+ {+ "title": long_title,+ "url": "https://ex.com",+ "snippet": "Content",+ },+ ]+ result = strategy._fallback_news_extraction(snippets)+ assert len(result["news_items"][0]["headline"]) == 60++ def test_max_10_snippets(self):+ """Only first 10 snippets are processed."""+ strategy = _make_strategy()+ snippets = [+ {+ "title": f"Valid title number {i:02d}",+ "url": f"https://ex{i}.com",+ "snippet": f"Snippet {i}",+ }+ for i in range(15)+ ]+ result = strategy._fallback_news_extraction(snippets)+ assert len(result["news_items"]) == 10++ def test_snippet_fallback_to_default(self):+ """Empty snippet falls back to 'No summary available'."""+ strategy = _make_strategy()+ snippets = [+ {+ "title": "A valid title here",+ "url": "https://ex.com",+ "snippet": "",+ },+ ]+ result = strategy._fallback_news_extraction(snippets)+ assert result["news_items"][0]["summary"] == "No summary available"++ def test_all_items_have_default_category_and_score(self):+ """All fallback items get category 'Other' and impact_score 5."""+ strategy = _make_strategy()+ snippets = [+ {+ "title": "A valid title here",+ "url": "https://ex.com",+ "snippet": "Content",+ },+ ]+ result = strategy._fallback_news_extraction(snippets)+ assert result["news_items"][0]["category"] == "Other"+ assert result["news_items"][0]["impact_score"] == 5++ def test_answer_shows_correct_count(self):+ """Answer message shows correct count of extracted items."""+ strategy = _make_strategy()+ snippets = [+ {+ "title": f"Valid title number {i:02d}",+ "url": f"https://ex{i}.com",+ "snippet": f"S {i}",+ }+ for i in range(3)+ ]+ result = strategy._fallback_news_extraction(snippets)+ assert (+ "Found 3 news stories (simplified extraction)" == result["answer"]+ )++ def test_empty_snippets(self):+ """Empty snippets list returns zero items."""+ strategy = _make_strategy()+ result = strategy._fallback_news_extraction([])+ assert result["news_items"] == []+ assert "Found 0 news stories" in result["answer"]+++class TestCreateNewsAnalysisPrompt:+ """Tests for _create_news_analysis_prompt."""++ @freeze_time("2025-06-15")+ def test_contains_date(self):+ """Prompt contains today's date."""+ strategy = _make_strategy()+ snippets = [+ {+ "id": 1,+ "url": "https://ex.com",+ "title": "Title",+ "snippet": "Snip",+ "content": "",+ }+ ]+ result = strategy._create_news_analysis_prompt(snippets)+ assert "June 15, 2025" in result++ def test_contains_snippet_fields(self):+ """Prompt includes all snippet fields."""+ strategy = _make_strategy()+ snippets = [+ {+ "id": 42,+ "url": "https://example.com/news",+ "title": "Breaking News",+ "snippet": "Details here",+ "content": "",+ }+ ]+ result = strategy._create_news_analysis_prompt(snippets)+ assert "[42] Source: https://example.com/news" in result+ assert "Title: Breaking News" in result+ assert "Content: Details here" in result++ def test_snippet_preferred_over_content(self):+ """Snippet is preferred over content when both are present."""+ strategy = _make_strategy()+ snippets = [+ {+ "id": 1,+ "url": "https://ex.com",+ "title": "T",+ "snippet": "snippet_text",+ "content": "content_text",+ }+ ]+ result = strategy._create_news_analysis_prompt(snippets)+ assert "Content: snippet_text" in result++ def test_content_fallback_when_no_snippet(self):+ """Content is used when snippet is empty."""+ strategy = _make_strategy()+ snippets = [+ {+ "id": 1,+ "url": "https://ex.com",+ "title": "T",+ "snippet": "",+ "content": "content_text",+ }+ ]+ result = strategy._create_news_analysis_prompt(snippets)+ assert "Content: content_text" in result++ def test_multiple_snippets_joined(self):+ """Multiple snippets are joined with double newlines."""+ strategy = _make_strategy()+ snippets = [+ {+ "id": 1,+ "url": "https://a.com",+ "title": "A",+ "snippet": "snip_a",+ "content": "",+ },+ {+ "id": 2,+ "url": "https://b.com",+ "title": "B",+ "snippet": "snip_b",+ "content": "",+ },+ ]+ result = strategy._create_news_analysis_prompt(snippets)+ assert "[1] Source: https://a.com" in result+ assert "[2] Source: https://b.com" in result++ def test_prompt_requests_json_response(self):+ """Prompt asks for structured JSON response."""+ strategy = _make_strategy()+ snippets = [+ {"id": 1, "url": "", "title": "T", "snippet": "S", "content": ""}+ ]+ result = strategy._create_news_analysis_prompt(snippets)+ assert "JSON response" in result+ assert "news_items" in result++ def test_empty_snippets(self):+ """Empty snippets list produces prompt with no snippet section."""+ strategy = _make_strategy()+ result = strategy._create_news_analysis_prompt([])+ # Should still have the prompt structure+ assert "news_items" in resultdiff --git a/tests/benchmarks/test_xbench_deepsearch_pure_logic.py b/tests/benchmarks/test_xbench_deepsearch_pure_logic.pynew file mode 100644index 0000000000..d4a4c443a3--- /dev/null+++ b/tests/benchmarks/test_xbench_deepsearch_pure_logic.py@@ -0,0 +1,263 @@+"""+Tests for XBenchDeepSearchDataset pure logic methods.++Existing tests: none — this file is the first test coverage.++Covers:+- xor_decrypt: symmetric encryption, empty data, key cycling, single byte+- get_dataset_info: expected keys and values+- get_default_dataset_path: exact string+- process_example: dict enrichment, shallow copy, evaluation criteria weights+"""++import base64+++def _cls():+ """Import and return the XBenchDeepSearchDataset class."""+ from local_deep_research.benchmarks.datasets.xbench_deepsearch import (+ XBenchDeepSearchDataset,+ )++ return XBenchDeepSearchDataset+++class TestXorDecrypt:+ """Tests for xor_decrypt static method."""++ def test_symmetry(self):+ """XOR decrypt is symmetric: decrypt(encrypt(x)) == x."""+ cls = _cls()+ plaintext = b"Hello, World!"+ key = "secret"+ encrypted = cls.xor_decrypt(plaintext, key)+ decrypted = cls.xor_decrypt(encrypted, key)+ assert decrypted == plaintext++ def test_known_values(self):+ """Known plaintext/key produces expected ciphertext."""+ cls = _cls()+ # XOR of b'A' (0x41) with b'k' (0x6B) = 0x2A = b'*'+ result = cls.xor_decrypt(b"A", "k")+ assert result == bytes([0x41 ^ 0x6B])++ def test_empty_data(self):+ """Empty data returns empty bytes."""+ cls = _cls()+ result = cls.xor_decrypt(b"", "anykey")+ assert result == b""++ def test_key_cycling(self):+ """Key cycles through for data longer than key."""+ cls = _cls()+ data = b"ABCD"+ key = "ab"+ # A^a, B^b, C^a, D^b+ expected = bytes(+ [+ ord("A") ^ ord("a"),+ ord("B") ^ ord("b"),+ ord("C") ^ ord("a"),+ ord("D") ^ ord("b"),+ ]+ )+ result = cls.xor_decrypt(data, key)+ assert result == expected++ def test_single_byte_key(self):+ """Single byte key applied to every byte."""+ cls = _cls()+ data = b"HELLO"+ key = "X"+ expected = bytes([b ^ ord("X") for b in data])+ result = cls.xor_decrypt(data, key)+ assert result == expected++ def test_all_zeros(self):+ """XOR with all-zero data returns key bytes repeated."""+ cls = _cls()+ data = bytes(5) # 5 zero bytes+ key = "AB"+ # 0^A, 0^B, 0^A, 0^B, 0^A+ expected = bytes([ord("A"), ord("B"), ord("A"), ord("B"), ord("A")])+ result = cls.xor_decrypt(data, key)+ assert result == expected++ def test_unicode_key(self):+ """Unicode key is encoded as UTF-8."""+ cls = _cls()+ data = b"\x00\x00\x00"+ key = "\u00e9" # é = 0xC3 0xA9 in UTF-8 (2 bytes)+ key_bytes = key.encode("utf-8")+ expected = bytes(+ [+ 0x00 ^ key_bytes[0],+ 0x00 ^ key_bytes[1],+ 0x00 ^ key_bytes[0],+ ]+ )+ result = cls.xor_decrypt(data, key)+ assert result == expected++ def test_roundtrip_with_base64(self):+ """Full roundtrip: plaintext -> encrypt -> base64 -> decode -> decrypt."""+ cls = _cls()+ plaintext = b"This is a test question for benchmarking"+ key = "canary_key_123"+ encrypted = cls.xor_decrypt(plaintext, key)+ encoded = base64.b64encode(encrypted)+ decoded = base64.b64decode(encoded)+ decrypted = cls.xor_decrypt(decoded, key)+ assert decrypted == plaintext+++class TestGetDatasetInfo:+ """Tests for get_dataset_info class method."""++ def test_returns_dict(self):+ """Returns a dictionary."""+ cls = _cls()+ info = cls.get_dataset_info()+ assert isinstance(info, dict)++ def test_has_required_keys(self):+ """Contains id, name, description, and url."""+ cls = _cls()+ info = cls.get_dataset_info()+ assert "id" in info+ assert "name" in info+ assert "description" in info+ assert "url" in info++ def test_id_value(self):+ """Dataset ID is 'xbench_deepsearch'."""+ cls = _cls()+ info = cls.get_dataset_info()+ assert info["id"] == "xbench_deepsearch"++ def test_name_value(self):+ """Dataset name is 'xbench-DeepSearch'."""+ cls = _cls()+ info = cls.get_dataset_info()+ assert info["name"] == "xbench-DeepSearch"++ def test_url_is_huggingface(self):+ """URL points to Hugging Face."""+ cls = _cls()+ info = cls.get_dataset_info()+ assert "huggingface.co" in info["url"]++ def test_callable_on_class_and_instance(self):+ """Can be called on both class and instance."""+ cls = _cls()+ class_result = cls.get_dataset_info()+ instance_result = cls().get_dataset_info()+ assert class_result == instance_result+++class TestGetDefaultDatasetPath:+ """Tests for get_default_dataset_path class method."""++ def test_returns_string(self):+ """Returns a string."""+ cls = _cls()+ path = cls.get_default_dataset_path()+ assert isinstance(path, str)++ def test_exact_value(self):+ """Returns the expected HuggingFace path."""+ cls = _cls()+ path = cls.get_default_dataset_path()+ assert path == "xbench/DeepSearch"+++class TestProcessExample:+ """Tests for process_example instance method."""++ def test_adds_requires_deep_search(self):+ """Adds requires_deep_search=True."""+ cls = _cls()+ instance = cls()+ result = instance.process_example({"id": "q1", "problem": "test"})+ assert result["requires_deep_search"] is True++ def test_adds_expected_iterations(self):+ """Adds expected_iterations=4."""+ cls = _cls()+ instance = cls()+ result = instance.process_example({"id": "q1"})+ assert result["expected_iterations"] == 4++ def test_adds_evaluation_criteria(self):+ """Adds evaluation_criteria dict."""+ cls = _cls()+ instance = cls()+ result = instance.process_example({"id": "q1"})+ criteria = result["evaluation_criteria"]+ assert "accuracy" in criteria+ assert "completeness" in criteria+ assert "reasoning" in criteria+ assert "sources" in criteria++ def test_evaluation_criteria_weights_sum_to_one(self):+ """Evaluation criteria weights sum to 1.0."""+ cls = _cls()+ instance = cls()+ result = instance.process_example({"id": "q1"})+ total = sum(result["evaluation_criteria"].values())+ assert abs(total - 1.0) < 1e-9++ def test_preserves_original_fields(self):+ """Original example fields are preserved."""+ cls = _cls()+ instance = cls()+ original = {"id": "q42", "problem": "What is X?", "answer": "Y"}+ result = instance.process_example(original)+ assert result["id"] == "q42"+ assert result["problem"] == "What is X?"+ assert result["answer"] == "Y"++ def test_does_not_modify_original(self):+ """Original dict is not modified (shallow copy)."""+ cls = _cls()+ instance = cls()+ original = {"id": "q1", "problem": "test"}+ instance.process_example(original)+ assert "requires_deep_search" not in original+ assert "evaluation_criteria" not in original++ def test_empty_input(self):+ """Empty dict gets all enrichment fields."""+ cls = _cls()+ instance = cls()+ result = instance.process_example({})+ assert result["requires_deep_search"] is True+ assert result["expected_iterations"] == 4+ assert "evaluation_criteria" in result++ def test_existing_field_overwritten(self):+ """If input has 'requires_deep_search', it gets overwritten."""+ cls = _cls()+ instance = cls()+ result = instance.process_example({"requires_deep_search": False})+ assert result["requires_deep_search"] is True+++class TestXBenchInheritance:+ """Tests for XBenchDeepSearchDataset class structure."""++ def test_inherits_from_benchmark_dataset(self):+ """Inherits from BenchmarkDataset base class."""+ cls = _cls()+ from local_deep_research.benchmarks.datasets.base import (+ BenchmarkDataset,+ )++ assert issubclass(cls, BenchmarkDataset)++ def test_instantiation(self):+ """Can be instantiated without arguments."""+ cls = _cls()+ instance = cls()+ assert instance is not None+ assert instance.dataset_path == "xbench/DeepSearch"