From 72a8d8d85be17bae318d553eb6ac3438a4e984eb Mon Sep 17 00:00:00 2001 From: Ankur Sharma Date: Wed, 29 Oct 2025 15:53:08 -0700 Subject: [PATCH] fix: Session input file are required for creating an eval case Session input file contains fields that are needed to run evals and later be able retrieve the session generated by them. Co-authored-by: Ankur Sharma PiperOrigin-RevId: 825742522 --- src/google/adk/cli/cli_tools_click.py | 12 ++--- .../cli/utils/test_cli_tools_click.py | 52 +++---------------- 2 files changed, 12 insertions(+), 52 deletions(-) diff --git a/src/google/adk/cli/cli_tools_click.py b/src/google/adk/cli/cli_tools_click.py index 1bee5355..b841e017 100644 --- a/src/google/adk/cli/cli_tools_click.py +++ b/src/google/adk/cli/cli_tools_click.py @@ -754,10 +754,8 @@ def cli_create_eval_set( type=click.Path( exists=True, dir_okay=False, file_okay=True, resolve_path=True ), - help=( - "Optional. Path to session file containing SessionInput in JSON format." - ), - default=None, + help="Path to session file containing SessionInput in JSON format.", + required=True, ) @eval_options() def cli_add_eval_case( @@ -787,10 +785,8 @@ def cli_add_eval_case( eval_sets_manager = get_eval_sets_manager(eval_storage_uri, agents_dir) try: - session_input = None - if session_input_file: - with open(session_input_file, "r") as f: - session_input = SessionInput.model_validate_json(f.read()) + with open(session_input_file, "r") as f: + session_input = SessionInput.model_validate_json(f.read()) with open(scenarios_file, "r") as f: conversation_scenarios = ConversationScenarios.model_validate_json( diff --git a/tests/unittests/cli/utils/test_cli_tools_click.py b/tests/unittests/cli/utils/test_cli_tools_click.py index 3bd02b39..be9015ca 100644 --- a/tests/unittests/cli/utils/test_cli_tools_click.py +++ b/tests/unittests/cli/utils/test_cli_tools_click.py @@ -643,50 +643,6 @@ def test_cli_create_eval_set(tmp_path: Path): assert eval_set_data["eval_cases"] == [] -def test_cli_add_eval_case_no_session(tmp_path: Path): - app_name = "test_app_add_1" - eval_set_id = "test_eval_set_add_1" - agent_path = tmp_path / app_name - agent_path.mkdir() - (agent_path / "__init__.py").touch() - - scenarios_file = tmp_path / "scenarios1.json" - scenarios_file.write_text( - '{"scenarios": [{"starting_prompt": "hello", "conversation_plan":' - ' "world"}]}' - ) - - runner = CliRunner() - runner.invoke( - cli_tools_click.main, - ["eval_set", "create", str(agent_path), eval_set_id], - catch_exceptions=False, - ) - result = runner.invoke( - cli_tools_click.main, - [ - "eval_set", - "add_eval_case", - str(agent_path), - eval_set_id, - "--scenarios_file", - str(scenarios_file), - ], - catch_exceptions=False, - ) - - assert result.exit_code == 0 - eval_set_file = agent_path / f"{eval_set_id}.evalset.json" - assert eval_set_file.exists() - with open(eval_set_file, "r") as f: - eval_set_data = json.load(f) - assert len(eval_set_data["eval_cases"]) == 1 - eval_case = eval_set_data["eval_cases"][0] - assert eval_case["eval_id"] == "0a1a5048" - assert eval_case["conversation_scenario"]["starting_prompt"] == "hello" - assert "session_input" not in eval_case - - def test_cli_add_eval_case_with_session(tmp_path: Path): app_name = "test_app_add_2" eval_set_id = "test_eval_set_add_2" @@ -748,6 +704,10 @@ def test_cli_add_eval_case_skip_existing(tmp_path: Path): '{"scenarios": [{"starting_prompt": "hello", "conversation_plan":' ' "world"}]}' ) + session_file = tmp_path / "session3.json" + session_file.write_text( + '{"app_name": "test_app_add_3", "user_id": "test_user", "state": {}}' + ) runner = CliRunner() runner.invoke( @@ -764,6 +724,8 @@ def test_cli_add_eval_case_skip_existing(tmp_path: Path): eval_set_id, "--scenarios_file", str(scenarios_file), + "--session_input_file", + str(session_file), ], catch_exceptions=False, ) @@ -780,6 +742,8 @@ def test_cli_add_eval_case_skip_existing(tmp_path: Path): eval_set_id, "--scenarios_file", str(scenarios_file), + "--session_input_file", + str(session_file), ], catch_exceptions=False, )