From 3a8cef1ebdb2baed6401a39faf104e463c033af8 Mon Sep 17 00:00:00 2001 From: Chenlu Ji Date: Fri, 26 Jun 2026 11:39:03 -0700 Subject: [PATCH] test(tinyfish): cover defensive branches in _default_missing_result_fields Codecov flagged 97.61% patch coverage (2 lines missing). The uncovered lines were the non-dict raw_json and non-dict per-result item early-exits in _default_missing_result_fields. Add two unit tests on the helper directly to bring patch coverage to 100%. --- .../llms/tinyfish/test_tinyfish_search.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_litellm/llms/tinyfish/test_tinyfish_search.py b/tests/test_litellm/llms/tinyfish/test_tinyfish_search.py index dc5f1a57905..58363e3baea 100644 --- a/tests/test_litellm/llms/tinyfish/test_tinyfish_search.py +++ b/tests/test_litellm/llms/tinyfish/test_tinyfish_search.py @@ -10,6 +10,7 @@ import pytest from litellm.llms.tinyfish.search.transformation import ( TinyfishSearchConfig, _append_domain_filters, + _default_missing_result_fields, ) MOCK_TINYFISH_RESPONSE = { @@ -681,3 +682,21 @@ class TestAppendDomainFilters: def test_multiple_domains(self): result = _append_domain_filters("query", ["a.com", "b.com", "c.com"]) assert result == "(query) (site:a.com OR site:b.com OR site:c.com)" + + +class TestDefaultMissingResultFields: + def test_non_dict_raw_json_is_noop(self): + # raw_json could be a string/list/None if TinyFish ever returns a + # non-envelope shape; the helper just returns without mutating. + for payload in ("not a dict", ["list"], None, 42): + _default_missing_result_fields(payload) # must not raise + + def test_non_dict_results_item_skipped(self): + # If `results` contains a non-dict entry (string, int, etc.), the helper + # skips it; SearchResponse.model_validate will reject it later. + raw_json = {"results": ["string item", 42, {"title": "ok"}]} + _default_missing_result_fields(raw_json) + # Only the dict item gets defaulted; the others are unchanged. + assert raw_json["results"][0] == "string item" + assert raw_json["results"][1] == 42 + assert raw_json["results"][2] == {"title": "ok", "url": "", "snippet": ""}