From 165e2a76e017a878c0df1a7b6f746d1c6fc6b21a Mon Sep 17 00:00:00 2001 From: KoushikReddy Date: Tue, 23 Jun 2026 14:56:58 -0700 Subject: [PATCH] test(tools): add unit tests for ToolConfirmation Adds unit-test coverage for the previously untested ToolConfirmation model: default values, custom values, arbitrary JSON-serializable payloads, extra-field rejection (extra=forbid), and dict round-tripping. --- .../unittests/tools/test_tool_confirmation.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/unittests/tools/test_tool_confirmation.py diff --git a/tests/unittests/tools/test_tool_confirmation.py b/tests/unittests/tools/test_tool_confirmation.py new file mode 100644 index 0000000000..0db5d6b3ee --- /dev/null +++ b/tests/unittests/tools/test_tool_confirmation.py @@ -0,0 +1,57 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import annotations + +from google.adk.tools.tool_confirmation import ToolConfirmation +from pydantic import ValidationError +import pytest + +# ToolConfirmation is gated behind an experimental feature flag, which emits a +# UserWarning on use; that is expected and not under test here. +pytestmark = pytest.mark.filterwarnings("ignore::UserWarning") + + +class TestToolConfirmation: + + def test_defaults(self): + confirmation = ToolConfirmation() + + assert confirmation.hint == "" + assert confirmation.confirmed is False + assert confirmation.payload is None + + def test_stores_custom_values(self): + confirmation = ToolConfirmation( + hint="please confirm", confirmed=True, payload={"amount": 10} + ) + + assert confirmation.hint == "please confirm" + assert confirmation.confirmed is True + assert confirmation.payload == {"amount": 10} + + def test_payload_accepts_arbitrary_json_serializable_values(self): + assert ToolConfirmation(payload=[1, 2, 3]).payload == [1, 2, 3] + assert ToolConfirmation(payload="raw").payload == "raw" + + def test_forbids_extra_fields(self): + with pytest.raises(ValidationError): + ToolConfirmation(unexpected="value") + + def test_round_trips_through_dict(self): + original = ToolConfirmation( + hint="confirm transfer", confirmed=True, payload={"to": "bob"} + ) + + assert ToolConfirmation.model_validate(original.model_dump()) == original