1717from tests .unit .types import SuggestionRequestFixture
1818
1919
20+ CLIENT_VARIANTS : list [str ] = ["engagement_guided_suggestions" ]
21+
22+
2023def test_thompson_attribute_is_none_by_default (adm : Provider ) -> None :
2124 """Provider created without a thompson argument should have thompson=None."""
2225 assert adm .thompson is None
@@ -69,10 +72,10 @@ async def test_query_with_thompson_dummy_suppresses_suggestion(
6972 await adm_with_thompson_dummy .initialize ()
7073 geolocation = Location (country = "US" )
7174 user_agent = UserAgent (form_factor = "desktop" , browser = "firefox" , os_family = "macos" )
72- client_variant = [ "engagement_guided_suggestions" ]
75+ client_variants = CLIENT_VARIANTS
7376
7477 res = await adm_with_thompson_dummy .query (
75- srequest ("firefox" , geolocation , user_agent , client_variant )
78+ srequest ("firefox" , geolocation , user_agent , client_variants )
7679 )
7780
7881 assert res == []
@@ -85,7 +88,7 @@ async def test_query_with_thompson_no_match_returns_empty(
8588) -> None :
8689 """Thompson-enabled provider should return empty list when the query matches nothing."""
8790 await adm_with_thompson .initialize ()
88- client_variants = [ "engagement_guided_suggestions" ]
91+ client_variants = CLIENT_VARIANTS
8992
9093 res = await adm_with_thompson .query (srequest ("zzznomatch" , None , None , client_variants ))
9194
@@ -100,8 +103,8 @@ async def test_query_with_thompson_uses_fallback_country_and_form_factor(
100103) -> None :
101104 """Thompson-enabled provider should apply country/form-factor fallbacks when absent."""
102105 await adm_with_thompson .initialize ()
103- client_variant = [ "engagement_guided_suggestions" ]
104- res = await adm_with_thompson .query (srequest ("firefox" , None , None , client_variant ))
106+ client_variants = CLIENT_VARIANTS
107+ res = await adm_with_thompson .query (srequest ("firefox" , None , None , client_variants ))
105108
106109 assert len (res ) == 1
107110 assert res [0 ].score == adm_parameters ["score" ]
@@ -119,7 +122,7 @@ async def test_query_with_thompson_min_attempted_count_returns_suggestion(
119122 await adm_with_thompson_dummy_min_attempted_count .initialize ()
120123 geolocation = Location (country = "US" )
121124 user_agent = UserAgent (form_factor = "desktop" , browser = "firefox" , os_family = "macos" )
122- client_variants = [ "engagement_guided_suggestions" ]
125+ client_variants = CLIENT_VARIANTS
123126
124127 res = await adm_with_thompson_dummy_min_attempted_count .query (
125128 srequest ("firefox" , geolocation , user_agent , client_variants )
@@ -141,3 +144,39 @@ async def test_query_with_thompson_min_attempted_count_returns_suggestion(
141144 score = adm_parameters ["score" ],
142145 )
143146 ]
147+
148+
149+ @pytest .mark .asyncio
150+ async def test_query_with_thompson_without_client_variants_check (
151+ srequest : SuggestionRequestFixture ,
152+ adm_with_thompson_skip_client_variants_check : Provider ,
153+ adm_parameters : dict [str , Any ],
154+ ) -> None :
155+ """Thompson-enabled provider without the client_variants check should return
156+ a suggestion when the sampler picks a winner even if client_variants does
157+ not match.
158+ """
159+ await adm_with_thompson_skip_client_variants_check .initialize ()
160+ geolocation = Location (country = "US" )
161+ user_agent = UserAgent (form_factor = "desktop" , browser = "firefox" , os_family = "macos" )
162+ client_variants : list [str ] = []
163+ res = await adm_with_thompson_skip_client_variants_check .query (
164+ srequest ("firefox" , geolocation , user_agent , client_variants )
165+ )
166+
167+ assert res == [
168+ NonsponsoredSuggestion (
169+ block_id = 2 ,
170+ full_keyword = "firefox accounts" ,
171+ title = "Mozilla Firefox Accounts" ,
172+ url = HttpUrl ("https://example.org/target/mozfirefoxaccounts" ),
173+ categories = [],
174+ impression_url = HttpUrl ("https://example.org/impression/mozilla" ),
175+ click_url = HttpUrl ("https://example.org/click/mozilla" ),
176+ provider = "adm" ,
177+ advertiser = "Example.org" ,
178+ is_sponsored = False ,
179+ icon = "attachment-host/main-workspace/quicksuggest/icon-01" ,
180+ score = adm_parameters ["score" ],
181+ )
182+ ]
0 commit comments