@@ -251,6 +251,37 @@ def _build_trimmed_dataset_id(evaluator_id: str) -> str:
251251 return f"{ base } { suffix } "
252252
253253
254+ def _resolve_selected_test (
255+ project_root : str ,
256+ evaluator_id : Optional [str ],
257+ selected_tests : Optional [list ] = None ,
258+ ) -> tuple [Optional [str ], Optional [str ]]:
259+ """
260+ Resolve a single test's source file path and function name to use downstream.
261+ Priority:
262+ 1) If selected_tests provided and length == 1, use it.
263+ 2) Else discover tests; if exactly one test, use it.
264+ 3) Else, if evaluator_id provided, match by normalized '<file-stem>-<func-name>'.
265+ Returns: (file_path, func_name) or (None, None) if unresolved.
266+ """
267+ try :
268+ tests = selected_tests if selected_tests is not None else _discover_tests (project_root )
269+ if not tests :
270+ return None , None
271+ if len (tests ) == 1 :
272+ return tests [0 ].file_path , tests [0 ].qualname .split ("." )[- 1 ]
273+ if evaluator_id :
274+ for t in tests :
275+ func_name = t .qualname .split ("." )[- 1 ]
276+ source_file_name = os .path .splitext (os .path .basename (t .file_path ))[0 ]
277+ candidate = _normalize_evaluator_id (f"{ source_file_name } -{ func_name } " )
278+ if candidate == evaluator_id :
279+ return t .file_path , func_name
280+ return None , None
281+ except Exception :
282+ return None , None
283+
284+
254285def _poll_evaluator_status (
255286 evaluator_resource_name : str , api_key : str , api_base : str , timeout_minutes : int = 10
256287) -> bool :
@@ -354,12 +385,15 @@ def create_rft_command(args) -> int:
354385 if len (selected_tests ) != 1 :
355386 print ("Error: Please select exactly one evaluation test for 'create rft'." )
356387 return 1
388+ # Derive evaluator_id from user's single selection
357389 chosen = selected_tests [0 ]
358390 func_name = chosen .qualname .split ("." )[- 1 ]
359391 source_file_name = os .path .splitext (os .path .basename (chosen .file_path ))[0 ]
360392 evaluator_id = _normalize_evaluator_id (f"{ source_file_name } -{ func_name } " )
361- selected_test_file_path = chosen .file_path
362- selected_test_func_name = func_name
393+ # Resolve selected test once for downstream
394+ selected_test_file_path , selected_test_func_name = _resolve_selected_test (
395+ project_root , evaluator_id , selected_tests = selected_tests
396+ )
363397 # Resolve evaluator resource name to fully-qualified format required by API
364398 evaluator_resource_name = f"accounts/{ account_id } /evaluators/{ evaluator_id } "
365399
@@ -392,6 +426,11 @@ def create_rft_command(args) -> int:
392426 print (" Wait for it to become ACTIVE, then run 'eval-protocol create rft' again." )
393427 return 1
394428 skip_upload = True
429+ # Populate selected test info for dataset inference later
430+ st_path , st_func = _resolve_selected_test (project_root , evaluator_id )
431+ if st_path and st_func :
432+ selected_test_file_path = st_path
433+ selected_test_func_name = st_func
395434 except requests .exceptions .RequestException :
396435 pass
397436
@@ -402,32 +441,16 @@ def create_rft_command(args) -> int:
402441
403442 tests = _discover_tests (project_root )
404443 selected_entry : Optional [str ] = None
405- if len ( tests ) == 1 :
406- func_name = tests [ 0 ]. qualname . split ( "." )[ - 1 ]
407- abs_path = os .path .abspath (tests [ 0 ]. file_path )
444+ st_path , st_func = _resolve_selected_test ( project_root , evaluator_id , selected_tests = tests )
445+ if st_path and st_func :
446+ abs_path = os .path .abspath (st_path )
408447 try :
409448 rel = os .path .relpath (abs_path , project_root )
410449 except Exception :
411450 rel = abs_path
412- selected_entry = f"{ rel } ::{ func_name } "
413- selected_test_file_path = tests [0 ].file_path
414- selected_test_func_name = func_name
415- else :
416- # Try to match evaluator_id to a discovered test's normalized ID
417- for t in tests :
418- func_name = t .qualname .split ("." )[- 1 ]
419- source_file_name = os .path .splitext (os .path .basename (t .file_path ))[0 ]
420- candidate = _normalize_evaluator_id (f"{ source_file_name } -{ func_name } " )
421- if candidate == evaluator_id :
422- abs_path = os .path .abspath (t .file_path )
423- try :
424- rel = os .path .relpath (abs_path , project_root )
425- except Exception :
426- rel = abs_path
427- selected_entry = f"{ rel } ::{ func_name } "
428- selected_test_file_path = t .file_path
429- selected_test_func_name = func_name
430- break
451+ selected_entry = f"{ rel } ::{ st_func } "
452+ selected_test_file_path = st_path
453+ selected_test_func_name = st_func
431454 # If still unresolved and multiple tests exist, fail fast to avoid uploading unintended evaluators
432455 if selected_entry is None and len (tests ) > 1 :
433456 print (
0 commit comments