~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(metadata_extractor): pin field-preference and empty-@type branches (#4092)
LearningCircuitb8005346cbe4
diff --git a/tests/research_library/downloaders/test_metadata_extractor_expanded.py b/tests/research_library/downloaders/test_metadata_extractor_expanded.pyindex ca668bddc3..9fe8b9ab1d 100644--- a/tests/research_library/downloaders/test_metadata_extractor_expanded.py+++ b/tests/research_library/downloaders/test_metadata_extractor_expanded.py@@ -519,3 +519,105 @@ class TestExtractMetadataEdgeCases:result = extract_metadata("<html><body>test</body></html>")assert result["json_ld"] == []+++class TestFieldPreferenceFallbacks:+ """Several formatter functions check a preferred field first, then+ fall back to an alternative. The existing tests covered the+ fallback paths; this class pins the *preferred* paths so reversing+ the priority would surface a regression.+ """++ def test_format_product_rating_prefers_review_count(self):+ """``aggregateRating`` lookup tries ``reviewCount`` before+ ``ratingCount``. If both are present, the review count must win+ — pinning the order documented at ``_format_product`` where+ ``rating.get("reviewCount", rating.get("ratingCount", ""))`` is+ used.+ """+ from local_deep_research.research_library.downloaders.extraction.metadata_extractor import (+ _format_product,+ )++ item = {+ "name": "Widget",+ "aggregateRating": {+ "ratingValue": "4.2",+ "reviewCount": "987",+ "ratingCount": "1",+ },+ }+ parts = _format_product(item)+ text = "\n".join(parts)+ # reviewCount wins; ratingCount must NOT be the visible number.+ assert "987" in text+ assert "(1 reviews)" not in text++ def test_format_opengraph_price_prefers_product_namespace(self):+ """``_format_opengraph`` checks ``product:price:amount`` before+ ``og:price:amount`` (similarly for currency). If both are+ present, the product-namespace value wins — pinning the lookup+ order.+ """+ from local_deep_research.research_library.downloaders.extraction.metadata_extractor import (+ _format_opengraph,+ )++ item = {+ "og:title": "Widget Page",+ "product:price:amount": "29.99",+ "product:price:currency": "EUR",+ "og:price:amount": "999.00",+ "og:price:currency": "JPY",+ }+ parts = _format_opengraph(item)+ text = "\n".join(parts)+ # product:price wins; og:price values must NOT appear.+ assert "29.99" in text+ assert "EUR" in text+ assert "999.00" not in text+ assert "JPY" not in text+++class TestMetadataToTextEmptyTypeList:+ """``metadata_to_text`` extracts the dispatch type from each JSON-LD+ or microdata item via ``item_type[0] if item_type else ""`` for list+ forms. An empty-list ``@type`` must collapse to ``""`` and fall+ through every branch cleanly — no IndexError, no formatting.+ """++ def test_empty_type_list_in_json_ld_is_ignored(self):+ from local_deep_research.research_library.downloaders.extraction.metadata_extractor import (+ metadata_to_text,+ )++ metadata = {+ "json_ld": [+ {+ "@type": [], # empty list — collapses to ""+ "name": "Should-not-appear",+ "headline": "Should-also-not-appear",+ }+ ],+ "opengraph": [],+ "microdata": [],+ }+ # No matching branch → returns None (no useful metadata).+ assert metadata_to_text(metadata) is None++ def test_empty_type_list_in_microdata_is_ignored(self):+ from local_deep_research.research_library.downloaders.extraction.metadata_extractor import (+ metadata_to_text,+ )++ metadata = {+ "json_ld": [],+ "opengraph": [],+ "microdata": [+ {+ "@type": [],+ "name": "Should-not-appear",+ }+ ],+ }+ assert metadata_to_text(metadata) is None