@@ -273,7 +273,6 @@ def load_golden_samples(
273273 if not isinstance (data , list ):
274274 raise ValueError (f"golden samples file must contain a JSON list, got { type (data ).__name__ } " )
275275
276- known = set (known_tool_names ) if known_tool_names is not None else None
277276 golden_fields = {f .name for f in fields (GoldenSample )}
278277 samples : List [GoldenSample ] = []
279278 seen_ids : set = set ()
@@ -287,7 +286,7 @@ def load_golden_samples(
287286 if sample .id in seen_ids :
288287 raise ValueError (f"duplicate sample id: { sample .id } " )
289288 seen_ids .add (sample .id )
290- issues = validate_golden_sample (sample , known )
289+ issues = validate_golden_sample (sample , known_tool_names )
291290 if issues :
292291 raise ValueError (f"sample '{ sample .id } ': " + "; " .join (issues ))
293292 samples .append (sample )
@@ -302,7 +301,9 @@ def validate_golden_sample(
302301
303302 When ``known_tool_names`` is provided, ``expected_tools`` must be a subset
304303 of it; the caller supplies the authoritative registry names (this module
305- deliberately does not import ``src/``).
304+ deliberately does not import ``src/``). Any ``Iterable[str]`` is accepted
305+ — including one-shot generators — and materialized once internally, so
306+ membership checks never consume the caller's iterable.
306307
307308 Field *types* are part of the structural contract — hand-edited golden
308309 JSON must fail with a clear message instead of crashing or silently
@@ -311,6 +312,7 @@ def validate_golden_sample(
311312 boolean.
312313 """
313314 issues : List [str ] = []
315+ known = set (known_tool_names ) if known_tool_names is not None else None
314316 if not isinstance (sample .id , str ) or not sample .id .strip ():
315317 issues .append ("id must be a non-empty string" )
316318 if not isinstance (sample .task_description , str ) or not sample .task_description .strip ():
@@ -323,8 +325,10 @@ def validate_golden_sample(
323325 issues .append ("expected_tools must be a non-empty list" )
324326 elif any (not isinstance (t , str ) or not t .strip () for t in sample .expected_tools ):
325327 issues .append ("expected_tools must contain only non-empty strings" )
326- if known_tool_names is not None :
327- unknown = [t for t in sample .expected_tools if isinstance (t , str ) and t .strip () and t not in known_tool_names ]
328+ elif known is not None :
329+ # Only reachable when expected_tools is a non-empty list of non-empty
330+ # strings, so malformed values can never crash the membership check.
331+ unknown = [t for t in sample .expected_tools if t not in known ]
328332 if unknown :
329333 issues .append (f"unknown expected_tools: { ', ' .join (unknown )} " )
330334 if not isinstance (sample .skills , list ):
0 commit comments