@@ -1239,9 +1239,9 @@ def test_enrich_scenario_e2e_simulation(self):
12391239 api_response , eval_result
12401240 )
12411241 example = api_response .results [0 ].clusters [0 ].examples [0 ]
1242- assert (
1243- "scenario_preview" in example .evaluation_result
1244- ), f"scenario_preview not found. evaluation_result keys: { list ( example . evaluation_result . keys ()) } "
1242+ assert "scenario_preview" in example . evaluation_result , (
1243+ f "scenario_preview not found. evaluation_result keys: { list ( example .evaluation_result . keys ()) } "
1244+ )
12451245 assert (
12461246 "I need to book a flight" in example .evaluation_result ["scenario_preview" ]
12471247 )
@@ -1253,9 +1253,9 @@ def test_enrich_scenario_e2e_simulation(self):
12531253 json_str = json .dumps (result_dump )
12541254 parsed = json .loads (json_str )
12551255 ex_parsed = parsed ["results" ][0 ]["clusters" ][0 ]["examples" ][0 ]
1256- assert "scenario_preview" in ex_parsed .get (
1257- " evaluation_result" , {}
1258- ), f"scenario_preview missing after serialization. Keys: { list ( ex_parsed . get ( 'evaluation_result' , {}). keys ()) } "
1256+ assert "scenario_preview" in ex_parsed .get ("evaluation_result" , {}), (
1257+ f"scenario_preview missing after serialization. Keys: { list ( ex_parsed . get ( ' evaluation_result' , {}). keys ()) } "
1258+ )
12591259 assert (
12601260 "I need to book a flight"
12611261 in ex_parsed ["evaluation_result" ]["scenario_preview" ]
@@ -6355,6 +6355,37 @@ def test_metric_to_yaml_file_raises_importerror_if_yaml_is_none(self):
63556355 metric_obj .to_yaml_file ("/fake/path/error.yaml" )
63566356
63576357
6358+ class TestPrebuiltMetricLoaderGroundedness :
6359+ """Unit tests for legacy RubricMetric.GROUNDEDNESS alias to grounding_v1."""
6360+
6361+ def test_grounding_resolves_to_grounding_v1 (self ):
6362+ lazy_metric = agentplatform_genai_types .RubricMetric .GROUNDING
6363+ assert lazy_metric .name == "GROUNDING"
6364+ assert lazy_metric ._get_api_metric_spec_name () == "grounding_v1"
6365+
6366+ def test_groundedness_aliases_grounding_v1 (self ):
6367+ lazy_metric = agentplatform_genai_types .RubricMetric .GROUNDEDNESS
6368+ assert lazy_metric .name == "GROUNDING"
6369+ assert lazy_metric ._get_api_metric_spec_name () == "grounding_v1"
6370+
6371+ def test_groundedness_logs_field_difference_warning (self , caplog ):
6372+ loader_logger = (
6373+ "agentplatform._genai._evals_metric_loaders"
6374+ )
6375+ with caplog .at_level ("WARNING" , logger = loader_logger ):
6376+ _ = agentplatform_genai_types .RubricMetric .GROUNDEDNESS
6377+ messages = [r .getMessage () for r in caplog .records if r .name == loader_logger ]
6378+ assert any ("GROUNDEDNESS" in m for m in messages )
6379+ assert any ("grounding_v1" in m for m in messages )
6380+ assert any ("context" in m for m in messages )
6381+
6382+ def test_groundedness_resolve_returns_grounding_v1_metric (self ):
6383+ lazy_metric = agentplatform_genai_types .RubricMetric .GROUNDEDNESS
6384+ resolved = lazy_metric .resolve (api_client = mock .MagicMock ())
6385+ assert isinstance (resolved , agentplatform_genai_types .Metric )
6386+ assert resolved .name == "grounding_v1"
6387+
6388+
63586389class TestMergeResponseDatasets :
63596390 """Unit tests for the merge_response_datasets_into_canonical_format function."""
63606391
@@ -8310,13 +8341,11 @@ def test_execute_evaluation_deduplicates_candidate_names(
83108341 candidate_name = "gemini-pro" ,
83118342 )
83128343
8313- mock_eval_dependencies ["mock_evaluate_instances" ].return_value = (
8314- agentplatform_genai_types .EvaluateInstancesResponse (
8315- exact_match_results = agentplatform_genai_types .ExactMatchResults (
8316- exact_match_metric_values = [
8317- genai_types .ExactMatchMetricValue (score = 1.0 )
8318- ]
8319- )
8344+ mock_eval_dependencies [
8345+ "mock_evaluate_instances"
8346+ ].return_value = agentplatform_genai_types .EvaluateInstancesResponse (
8347+ exact_match_results = agentplatform_genai_types .ExactMatchResults (
8348+ exact_match_metric_values = [genai_types .ExactMatchMetricValue (score = 1.0 )]
83208349 )
83218350 )
83228351
0 commit comments