~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: remove 2 shadow files in tests/core/ (#4122)
LearningCircuitafa9859f0fe5
diff --git a/tests/core/test_citation_handler_extended.py b/tests/core/test_citation_handler_extended.pydeleted file mode 100644index f683664846..0000000000--- a/tests/core/test_citation_handler_extended.py+++ /dev/null@@ -1,479 +0,0 @@-"""-Extended tests for CitationHandler - Configurable citation handler.--Tests cover:-- Citation handler initialization-- Handler type selection-- Handler creation-- Method delegation-- Settings snapshot handling-- analyze_initial delegation-- analyze_followup delegation-"""---class TestCitationHandlerInitialization:- """Tests for CitationHandler initialization."""-- def test_llm_assignment(self):- """Should assign LLM on initialization."""- llm = "mock_llm"- assigned_llm = llm- assert assigned_llm == "mock_llm"-- def test_settings_snapshot_default_empty(self):- """Settings snapshot should default to empty dict."""- settings_snapshot = None- actual = settings_snapshot or {}- assert actual == {}-- def test_settings_snapshot_provided(self):- """Should use provided settings snapshot."""- settings_snapshot = {"key": "value"}- actual = settings_snapshot or {}- assert actual == {"key": "value"}---class TestHandlerTypeSelection:- """Tests for handler type selection."""-- def test_default_handler_type_standard(self):- """Default handler type should be standard."""- handler_type = None- settings_snapshot = {}-- if handler_type is None:- if "citation.handler_type" in settings_snapshot:- handler_type = settings_snapshot["citation.handler_type"]- else:- handler_type = "standard"-- assert handler_type == "standard"-- def test_handler_type_from_settings_simple(self):- """Should get handler type from simple settings value."""- settings_snapshot = {"citation.handler_type": "forced_answer"}-- value = settings_snapshot["citation.handler_type"]- handler_type = (- value["value"]- if isinstance(value, dict) and "value" in value- else value- )-- assert handler_type == "forced_answer"-- def test_handler_type_from_settings_dict(self):- """Should extract handler type from dict value."""- settings_snapshot = {- "citation.handler_type": {"value": "precision", "other": "data"}- }-- value = settings_snapshot["citation.handler_type"]- handler_type = (- value["value"]- if isinstance(value, dict) and "value" in value- else value- )-- assert handler_type == "precision"-- def test_explicit_handler_type_overrides(self):- """Explicit handler type should override settings."""- explicit_type = "browsecomp"- settings_type = "standard"-- # Explicit type should take precedence over settings type- handler_type = explicit_type- assert handler_type == "browsecomp"- assert handler_type != settings_type---class TestHandlerCreation:- """Tests for handler creation via _create_handler."""-- def test_standard_handler_type(self):- """Should create standard handler for 'standard' type."""- handler_type = "standard"- handler_type_lower = handler_type.lower()-- assert handler_type_lower == "standard"-- def test_forced_answer_handler_type(self):- """Should create forced answer handler for 'forced' type."""- handler_type = "forced"- handler_type_lower = handler_type.lower()-- expected_types = ["forced", "forced_answer", "browsecomp"]- assert handler_type_lower in expected_types-- def test_forced_answer_alias(self):- """Should accept 'forced_answer' alias."""- handler_type = "forced_answer"- expected_types = ["forced", "forced_answer", "browsecomp"]-- assert handler_type in expected_types-- def test_browsecomp_alias(self):- """Should accept 'browsecomp' alias."""- handler_type = "browsecomp"- expected_types = ["forced", "forced_answer", "browsecomp"]-- assert handler_type in expected_types-- def test_precision_handler_type(self):- """Should create precision handler for 'precision' type."""- handler_type = "precision"- expected_types = ["precision", "precision_extraction", "simpleqa"]-- assert handler_type in expected_types-- def test_precision_extraction_alias(self):- """Should accept 'precision_extraction' alias."""- handler_type = "precision_extraction"- expected_types = ["precision", "precision_extraction", "simpleqa"]-- assert handler_type in expected_types-- def test_simpleqa_alias(self):- """Should accept 'simpleqa' alias."""- handler_type = "simpleqa"- expected_types = ["precision", "precision_extraction", "simpleqa"]-- assert handler_type in expected_types-- def test_unknown_handler_fallback_to_standard(self):- """Unknown handler type should fallback to standard."""- handler_type = "unknown_type"-- known_types = [- "standard",- "forced",- "forced_answer",- "browsecomp",- "precision",- "precision_extraction",- "simpleqa",- ]- if handler_type not in known_types:- fallback = "standard"- else:- fallback = handler_type-- assert fallback == "standard"-- def test_case_insensitive_handler_type(self):- """Handler type should be case insensitive."""- handler_type = "STANDARD"- handler_type_lower = handler_type.lower()-- assert handler_type_lower == "standard"-- def test_mixed_case_handler_type(self):- """Should handle mixed case handler type."""- handler_type = "Forced_Answer"- handler_type_lower = handler_type.lower()-- assert handler_type_lower == "forced_answer"---class TestMethodDelegation:- """Tests for method delegation to internal handler."""-- def test_analyze_initial_delegation(self):- """analyze_initial should delegate to handler."""- query = "What is AI?"- search_results = [{"title": "Result 1"}]-- # Simulating delegation- delegated_query = query- delegated_results = search_results-- assert delegated_query == query- assert delegated_results == search_results-- def test_analyze_followup_delegation(self):- """analyze_followup should delegate to handler."""- question = "Follow-up question?"- search_results = [{"title": "Result 1"}]- previous_knowledge = "Previous knowledge"- nr_of_links = 5-- # Simulating delegation- delegated_params = {- "question": question,- "search_results": search_results,- "previous_knowledge": previous_knowledge,- "nr_of_links": nr_of_links,- }-- assert delegated_params["question"] == question- assert delegated_params["nr_of_links"] == 5---class TestBackwardCompatibility:- """Tests for backward compatibility."""-- def test_create_documents_exposed(self):- """_create_documents method should be exposed."""- # Simulating method exposure- handler_methods = ["_create_documents", "_format_sources"]- assert "_create_documents" in handler_methods-- def test_format_sources_exposed(self):- """_format_sources method should be exposed."""- handler_methods = ["_create_documents", "_format_sources"]- assert "_format_sources" in handler_methods---class TestAnalyzeInitial:- """Tests for analyze_initial method."""-- def test_accepts_string_search_results(self):- """Should accept string search results."""- query = "Test query"- search_results = "Raw search results string"-- # Type check simulation- is_string = isinstance(search_results, str)- assert is_string is True- assert len(query) > 0-- def test_accepts_list_search_results(self):- """Should accept list of dict search results."""- query = "Test query"- search_results = [- {"title": "Result 1", "snippet": "Snippet 1"},- {"title": "Result 2", "snippet": "Snippet 2"},- ]-- is_list = isinstance(search_results, list)- assert is_list is True- assert len(search_results) == 2- assert len(query) > 0-- def test_returns_dict(self):- """analyze_initial should return a dict."""- result = {"analysis": "content", "documents": []}- assert isinstance(result, dict)---class TestAnalyzeFollowup:- """Tests for analyze_followup method."""-- def test_accepts_all_parameters(self):- """Should accept all required parameters."""- question = "Follow-up question?"- search_results = [{"title": "Result"}]- previous_knowledge = "Previous knowledge text"- nr_of_links = 10-- params = {- "question": question,- "search_results": search_results,- "previous_knowledge": previous_knowledge,- "nr_of_links": nr_of_links,- }-- assert params["question"] is not None- assert params["nr_of_links"] == 10-- def test_nr_of_links_integer(self):- """nr_of_links should be an integer."""- nr_of_links = 5- assert isinstance(nr_of_links, int)-- def test_previous_knowledge_string(self):- """previous_knowledge should be a string."""- previous_knowledge = "Knowledge from previous iterations"- assert isinstance(previous_knowledge, str)-- def test_returns_dict(self):- """analyze_followup should return a dict."""- result = {"analysis": "followup content", "documents": []}- assert isinstance(result, dict)---class TestSettingsSnapshotHandling:- """Tests for settings snapshot handling."""-- def test_empty_settings_snapshot(self):- """Should handle empty settings snapshot."""- settings_snapshot = {}- handler_type = settings_snapshot.get(- "citation.handler_type", "standard"- )- assert handler_type == "standard"-- def test_none_settings_snapshot(self):- """Should handle None settings snapshot."""- settings_snapshot = None- actual = settings_snapshot or {}- assert actual == {}-- def test_nested_settings_value(self):- """Should handle nested settings value."""- settings_snapshot = {- "citation.handler_type": {- "value": "forced_answer",- "type": "string",- "category": "citation",- }- }-- value = settings_snapshot["citation.handler_type"]- handler_type = (- value["value"]- if isinstance(value, dict) and "value" in value- else value- )-- assert handler_type == "forced_answer"-- def test_settings_passed_to_handler(self):- """Settings snapshot should be passed to handler."""- settings_snapshot = {"key": "value"}-- # Simulating passing to handler- handler_settings = settings_snapshot- assert handler_settings == {"key": "value"}---class TestHandlerTypeValidation:- """Tests for handler type validation."""-- def test_valid_standard_type(self):- """'standard' should be a valid type."""- handler_type = "standard"- valid_types = [- "standard",- "forced",- "forced_answer",- "browsecomp",- "precision",- "precision_extraction",- "simpleqa",- ]-- is_valid = (- handler_type in valid_types or handler_type not in valid_types- )- assert is_valid is True # All types are handled-- def test_valid_forced_types(self):- """Forced types should all be valid."""- forced_types = ["forced", "forced_answer", "browsecomp"]-- for handler_type in forced_types:- handler_type_lower = handler_type.lower()- assert handler_type_lower in forced_types-- def test_valid_precision_types(self):- """Precision types should all be valid."""- precision_types = ["precision", "precision_extraction", "simpleqa"]-- for handler_type in precision_types:- handler_type_lower = handler_type.lower()- assert handler_type_lower in precision_types---class TestLogging:- """Tests for logging behavior."""-- def test_standard_handler_log_message(self):- """Should log standard handler creation."""- handler_type = "standard"- log_message = f"Using StandardCitationHandler for {handler_type}"-- assert "StandardCitationHandler" in log_message- assert handler_type in log_message-- def test_forced_answer_handler_log_message(self):- """Should log forced answer handler creation."""- log_message = (- "Using ForcedAnswerCitationHandler for better benchmark performance"- )-- assert "ForcedAnswerCitationHandler" in log_message- assert "benchmark" in log_message-- def test_precision_handler_log_message(self):- """Should log precision handler creation."""- log_message = (- "Using PrecisionExtractionHandler for precise answer extraction"- )-- assert "PrecisionExtractionHandler" in log_message- assert "precise" in log_message-- def test_unknown_handler_warning(self):- """Should log warning for unknown handler type."""- handler_type = "unknown"- warning_message = f"Unknown citation handler type: {handler_type}, falling back to standard"-- assert "unknown" in warning_message- assert "falling back" in warning_message---class TestEdgeCases:- """Tests for edge cases."""-- def test_empty_handler_type_string(self):- """Should handle empty handler type string."""- handler_type = ""-- valid_types = [- "standard",- "forced",- "forced_answer",- "browsecomp",- "precision",- "precision_extraction",- "simpleqa",- ]- if handler_type not in valid_types:- fallback = "standard"- else:- fallback = handler_type-- assert fallback == "standard"-- def test_whitespace_handler_type(self):- """Should handle whitespace handler type."""- handler_type = " standard "- handler_type_clean = handler_type.strip().lower()-- assert handler_type_clean == "standard"-- def test_search_results_empty_list(self):- """Should handle empty search results list."""- search_results = []- is_empty = len(search_results) == 0- assert is_empty is True-- def test_search_results_empty_string(self):- """Should handle empty search results string."""- search_results = ""- is_empty = len(search_results) == 0- assert is_empty is True-- def test_large_nr_of_links(self):- """Should handle large nr_of_links value."""- nr_of_links = 10000- assert nr_of_links == 10000-- def test_zero_nr_of_links(self):- """Should handle zero nr_of_links."""- nr_of_links = 0- assert nr_of_links == 0-- def test_query_with_special_characters(self):- """Should handle query with special characters."""- query = "What is AI? How does it work & why?"- assert "?" in query- assert "&" in query-- def test_unicode_in_query(self):- """Should handle unicode in query."""- query = "What is 人工智能?"- assert "人工智能" in querydiff --git a/tests/core/test_integrated_report_generator.py b/tests/core/test_integrated_report_generator.pydeleted file mode 100644index fa7aeea2c7..0000000000--- a/tests/core/test_integrated_report_generator.py+++ /dev/null@@ -1,577 +0,0 @@-"""-Extended tests for IntegratedReportGenerator - Research report generation.--Tests cover:-- Report generator initialization-- Report structure determination-- Section research and generation-- Final report formatting-- Error report generation-- Table of contents generation-- Metadata handling-"""--from datetime import datetime, UTC---class TestReportGeneratorInitialization:- """Tests for IntegratedReportGenerator initialization."""-- def test_default_searches_per_section(self):- """Default searches per section should be 2."""- searches_per_section = 2- assert searches_per_section == 2-- def test_custom_searches_per_section(self):- """Should accept custom searches per section."""- searches_per_section = 5- assert searches_per_section == 5-- def test_search_system_assignment(self):- """Should assign search system when provided."""- search_system = "mock_search_system"- assigned = search_system- assert assigned == "mock_search_system"-- def test_llm_from_search_system(self):- """Should use LLM from search system if provided."""- search_system_llm = "search_system_llm"- provided_llm = None-- model = provided_llm or search_system_llm- assert model == "search_system_llm"-- def test_llm_override(self):- """Should use provided LLM over search system LLM."""- search_system_llm = "search_system_llm"- provided_llm = "custom_llm"-- model = provided_llm or search_system_llm- assert model == "custom_llm"---class TestGenerateReport:- """Tests for generate_report method."""-- def test_returns_dict(self):- """generate_report should return a dict."""- report = {"content": "Report content", "metadata": {}}- assert isinstance(report, dict)-- def test_report_has_content_key(self):- """Report should have content key."""- report = {"content": "# Report\n\nContent here", "metadata": {}}- assert "content" in report-- def test_report_has_metadata_key(self):- """Report should have metadata key."""- report = {"content": "Content", "metadata": {"query": "test"}}- assert "metadata" in report-- def test_report_generation_steps(self):- """Report generation should follow steps."""- # Step 1: Determine structure- structure = [{"name": "Section 1", "subsections": []}]-- # Step 2: Research and generate sections- sections = {"Section 1": "Content"}-- # Step 3: Format final report- report = {"content": "Formatted", "metadata": {}}-- assert len(structure) == 1- assert len(sections) == 1- assert "content" in report---class TestDetermineReportStructure:- """Tests for _determine_report_structure method."""-- def test_returns_list(self):- """_determine_report_structure should return a list."""- structure = []- assert isinstance(structure, list)-- def test_structure_item_has_name(self):- """Structure item should have name key."""- section = {"name": "Introduction", "subsections": []}- assert "name" in section-- def test_structure_item_has_subsections(self):- """Structure item should have subsections key."""- section = {"name": "Introduction", "subsections": []}- assert "subsections" in section-- def test_subsection_has_name(self):- """Subsection should have name key."""- subsection = {"name": "Overview", "purpose": "Provide overview"}- assert "name" in subsection-- def test_subsection_has_purpose(self):- """Subsection should have purpose key."""- subsection = {"name": "Overview", "purpose": "Provide overview"}- assert "purpose" in subsection-- def test_parse_section_from_line(self):- """Should parse section from numbered line."""- line = "1. Introduction"-- if line.strip().startswith(tuple("123456789")):- section_name = line.split(".")[1].strip()- current_section = {"name": section_name, "subsections": []}-- assert current_section["name"] == "Introduction"-- def test_parse_subsection_from_line(self):- """Should parse subsection from bullet line."""- line = "- Overview | Provide an overview"- parts = line.strip("- ").split("|")-- if len(parts) == 2:- subsection = {"name": parts[0].strip(), "purpose": parts[1].strip()}-- assert subsection["name"] == "Overview"- assert subsection["purpose"] == "Provide an overview"-- def test_parse_subsection_without_purpose(self):- """Should handle subsection without purpose."""- line = "- Background"- parts = line.strip("- ").split("|")-- if len(parts) == 1 and parts[0].strip():- subsection = {- "name": parts[0].strip(),- "purpose": f"Provide detailed information about {parts[0].strip()}",- }-- assert subsection["name"] == "Background"- assert "Background" in subsection["purpose"]-- def test_filter_source_sections(self):- """Should filter out source-related sections."""- structure = [- {"name": "Introduction", "subsections": []},- {"name": "Sources and References", "subsections": []},- ]-- source_keywords = ["source", "citation", "reference", "bibliography"]- last_section = structure[-1]- section_name_lower = last_section["name"].lower()-- if any(keyword in section_name_lower for keyword in source_keywords):- structure = structure[:-1]-- assert len(structure) == 1- assert structure[0]["name"] == "Introduction"---class TestResearchAndGenerateSections:- """Tests for _research_and_generate_sections method."""-- def test_returns_dict(self):- """_research_and_generate_sections should return a dict."""- sections = {}- assert isinstance(sections, dict)-- def test_section_key_is_name(self):- """Section key should be section name."""- sections = {"Introduction": "Content"}- assert "Introduction" in sections-- def test_section_content_includes_header(self):- """Section content should include header."""- section_name = "Introduction"- content = f"# {section_name}\n"-- assert f"# {section_name}" in content-- def test_section_without_subsections_creates_default(self):- """Section without subsections should create default subsection."""- section = {"name": "Introduction", "subsections": []}-- if not section["subsections"]:- section["subsections"] = [- {- "name": section["name"],- "purpose": f"Provide comprehensive content for {section['name']}",- }- ]-- assert len(section["subsections"]) == 1- assert section["subsections"][0]["name"] == "Introduction"-- def test_multiple_subsections_get_headers(self):- """Multiple subsections should get individual headers."""- section = {- "name": "Overview",- "subsections": [- {"name": "Part A", "purpose": "Purpose A"},- {"name": "Part B", "purpose": "Purpose B"},- ],- }-- content = []- for subsection in section["subsections"]:- if len(section["subsections"]) > 1:- content.append(f"## {subsection['name']}\n")- content.append(f"_{subsection['purpose']}_\n\n")-- result = "".join(content)- assert "## Part A" in result- assert "## Part B" in result-- def test_single_subsection_no_header(self):- """Single subsection should not add subsection header."""- section = {- "name": "Introduction",- "subsections": [{"name": "Introduction", "purpose": "Purpose"}],- }-- is_section_level = len(section["subsections"]) == 1- assert is_section_level is True-- def test_other_subsections_context(self):- """Should generate other subsections context."""- subsections = [- {"name": "Part A", "purpose": "Purpose A"},- {"name": "Part B", "purpose": "Purpose B"},- {"name": "Part C", "purpose": "Purpose C"},- ]- current = "Part B"-- other_subsections = [- f"- {s['name']}: {s['purpose']}"- for s in subsections- if s["name"] != current- ]-- other_text = (- "\n".join(other_subsections) if other_subsections else "None"- )-- assert "Part A" in other_text- assert "Part C" in other_text- assert "Part B" not in other_text-- def test_other_sections_context(self):- """Should generate other sections context."""- structure = [- {"name": "Introduction"},- {"name": "Analysis"},- {"name": "Conclusion"},- ]- current = "Analysis"-- other_sections = [- f"- {s['name']}" for s in structure if s["name"] != current- ]- other_text = "\n".join(other_sections) if other_sections else "None"-- assert "Introduction" in other_text- assert "Conclusion" in other_text- assert "Analysis" not in other_text-- def test_limited_information_fallback(self):- """Should show fallback when limited information."""- results = {"current_knowledge": None}-- if results.get("current_knowledge"):- content = results["current_knowledge"]- else:- content = "*Limited information was found for this subsection.*\n"-- assert "Limited information" in content---class TestFormatFinalReport:- """Tests for _format_final_report method."""-- def test_returns_dict(self):- """_format_final_report should return a dict."""- report = {"content": "Content", "metadata": {}}- assert isinstance(report, dict)-- def test_generates_table_of_contents(self):- """Should generate table of contents."""- structure = [- {"name": "Introduction", "subsections": []},- {"name": "Analysis", "subsections": []},- ]-- toc = ["# Table of Contents\n"]- for i, section in enumerate(structure, 1):- toc.append(f"{i}. **{section['name']}**")-- result = "\n".join(toc)- assert "# Table of Contents" in result- assert "1. **Introduction**" in result- assert "2. **Analysis**" in result-- def test_toc_includes_subsections(self):- """TOC should include subsections."""- section = {- "name": "Overview",- "subsections": [- {"name": "Part A", "purpose": "Purpose A"},- {"name": "Part B", "purpose": "Purpose B"},- ],- }-- toc = [f"1. **{section['name']}**"]- for j, subsection in enumerate(section["subsections"], 1):- toc.append(- f" 1.{j} {subsection['name']} | _{subsection['purpose']}_"- )-- result = "\n".join(toc)- assert "1.1 Part A" in result- assert "1.2 Part B" in result-- def test_includes_research_summary(self):- """Should include research summary."""- report_parts = ["# Research Summary"]- report_parts.append(- "This report was researched using an advanced search system."- )-- result = "\n".join(report_parts)- assert "# Research Summary" in result-- def test_includes_sources_section(self):- """Should include sources section."""- formatted_links = "[1] http://example.com"- final_content = "Report content\n\n## Sources\n\n" + formatted_links-- assert "## Sources" in final_content- assert "http://example.com" in final_content---class TestMetadataGeneration:- """Tests for metadata generation."""-- def test_metadata_has_generated_at(self):- """Metadata should have generated_at timestamp."""- metadata = {"generated_at": datetime.now(UTC).isoformat()}- assert "generated_at" in metadata- assert "T" in metadata["generated_at"] # ISO format has T separator-- def test_metadata_has_initial_sources(self):- """Metadata should have initial_sources count."""- all_links = ["link1", "link2", "link3"]- metadata = {"initial_sources": len(all_links)}- assert metadata["initial_sources"] == 3-- def test_metadata_has_sections_researched(self):- """Metadata should have sections_researched count."""- structure = [{"name": "Section 1"}, {"name": "Section 2"}]- metadata = {"sections_researched": len(structure)}- assert metadata["sections_researched"] == 2-- def test_metadata_has_searches_per_section(self):- """Metadata should have searches_per_section."""- metadata = {"searches_per_section": 2}- assert metadata["searches_per_section"] == 2-- def test_metadata_has_query(self):- """Metadata should have query."""- metadata = {"query": "What is machine learning?"}- assert metadata["query"] == "What is machine learning?"-- def test_complete_metadata_structure(self):- """Metadata should have complete structure."""- metadata = {- "generated_at": datetime.now(UTC).isoformat(),- "initial_sources": 10,- "sections_researched": 5,- "searches_per_section": 2,- "query": "Test query",- }-- expected_keys = [- "generated_at",- "initial_sources",- "sections_researched",- "searches_per_section",- "query",- ]-- for key in expected_keys:- assert key in metadata---class TestGenerateErrorReport:- """Tests for _generate_error_report method."""-- def test_returns_string(self):- """_generate_error_report should return a string."""- query = "Test query"- error_msg = "Test error"- error_report = (- f"=== ERROR REPORT ===\nQuery: {query}\nError: {error_msg}"- )-- assert isinstance(error_report, str)-- def test_includes_error_header(self):- """Error report should include header."""- error_report = "=== ERROR REPORT ==="- assert "ERROR REPORT" in error_report-- def test_includes_query(self):- """Error report should include query."""- query = "What is AI?"- error_report = f"Query: {query}"- assert "What is AI?" in error_report-- def test_includes_error_message(self):- """Error report should include error message."""- error_msg = "Connection timeout"- error_report = f"Error: {error_msg}"- assert "Connection timeout" in error_report---class TestQuestionPreservation:- """Tests for question preservation from initial research."""-- def test_preserve_existing_questions(self):- """Should preserve questions from initial research."""- initial_findings = {- "questions_by_iteration": {0: ["Q1?", "Q2?"], 1: ["Q3?"]}- }-- existing_questions = initial_findings.get("questions_by_iteration", {})- assert len(existing_questions) == 2- assert 0 in existing_questions-- def test_copy_questions_to_search_system(self):- """Should copy questions to search system."""- existing_questions = {0: ["Q1?"], 1: ["Q2?"]}-- # Simulating copy to search system- search_system_questions = existing_questions.copy()-- assert search_system_questions[0] == ["Q1?"]- assert search_system_questions[1] == ["Q2?"]-- def test_empty_questions_handled(self):- """Should handle empty questions gracefully."""- initial_findings = {}-- existing_questions = initial_findings.get("questions_by_iteration", {})- if existing_questions:- has_questions = True- else:- has_questions = False-- assert has_questions is False---class TestMaxIterationsControl:- """Tests for max iterations control during section research."""-- def test_save_original_max_iterations(self):- """Should save original max iterations."""- original = 3- modified = 1-- assert original != modified- assert modified == 1-- def test_restore_max_iterations(self):- """Should restore original max iterations after research."""- original = 3- current = 1-- # After research, restore- current = original- assert current == 3---class TestSectionLevelDetection:- """Tests for section-level content detection."""-- def test_section_level_with_single_subsection(self):- """Single subsection indicates section-level content."""- section = {"subsections": [{"name": "Content"}]}- is_section_level = len(section["subsections"]) == 1-- assert is_section_level is True-- def test_not_section_level_with_multiple_subsections(self):- """Multiple subsections indicates not section-level."""- section = {"subsections": [{"name": "A"}, {"name": "B"}]}- is_section_level = len(section["subsections"]) == 1-- assert is_section_level is False---class TestPromptGeneration:- """Tests for prompt generation."""-- def test_section_level_prompt_includes_query(self):- """Section-level prompt should include query."""- query = "machine learning"- section_name = "Introduction"-- prompt = f"Create comprehensive content for the '{section_name}' section in a report about '{query}'."-- assert "machine learning" in prompt- assert "Introduction" in prompt-- def test_subsection_level_prompt_includes_section(self):- """Subsection-level prompt should include parent section."""- section_name = "Analysis"- subsection_name = "Data Analysis"- query = "test"-- prompt = f"Create content for subsection '{subsection_name}' in a report about '{query}'. Part of section: '{section_name}'"-- assert "Data Analysis" in prompt- assert "Analysis" in prompt-- def test_prompt_includes_purpose(self):- """Prompt should include subsection purpose."""- purpose = "Provide detailed analysis"- prompt = f"This subsection's purpose: {purpose}"-- assert "Provide detailed analysis" in prompt---class TestEdgeCases:- """Tests for edge cases."""-- def test_empty_structure(self):- """Should handle empty structure."""- structure = []- sections = {}-- for section in structure:- sections[section["name"]] = "Content"-- assert len(sections) == 0-- def test_empty_findings(self):- """Should handle empty findings."""- findings = {"current_knowledge": ""}-- combined_content = findings.get("current_knowledge", "")- assert combined_content == ""-- def test_truncated_content_for_structure(self):- """Should truncate content for structure determination."""- content = "x" * 2000- truncated = content[:1000]-- assert len(truncated) == 1000-- def test_section_with_pipe_in_name(self):- """Should handle section name with pipe."""- section_name = "Introduction | Overview"-- if "|" in section_name:- parts = section_name.split("|", 1)- name = parts[0].strip()- purpose = parts[1].strip()-- assert name == "Introduction"- assert purpose == "Overview"