Skip to content

Commit 165e2a7

Browse files
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.
1 parent 816a87f commit 165e2a7

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import annotations
16+
17+
from google.adk.tools.tool_confirmation import ToolConfirmation
18+
from pydantic import ValidationError
19+
import pytest
20+
21+
# ToolConfirmation is gated behind an experimental feature flag, which emits a
22+
# UserWarning on use; that is expected and not under test here.
23+
pytestmark = pytest.mark.filterwarnings("ignore::UserWarning")
24+
25+
26+
class TestToolConfirmation:
27+
28+
def test_defaults(self):
29+
confirmation = ToolConfirmation()
30+
31+
assert confirmation.hint == ""
32+
assert confirmation.confirmed is False
33+
assert confirmation.payload is None
34+
35+
def test_stores_custom_values(self):
36+
confirmation = ToolConfirmation(
37+
hint="please confirm", confirmed=True, payload={"amount": 10}
38+
)
39+
40+
assert confirmation.hint == "please confirm"
41+
assert confirmation.confirmed is True
42+
assert confirmation.payload == {"amount": 10}
43+
44+
def test_payload_accepts_arbitrary_json_serializable_values(self):
45+
assert ToolConfirmation(payload=[1, 2, 3]).payload == [1, 2, 3]
46+
assert ToolConfirmation(payload="raw").payload == "raw"
47+
48+
def test_forbids_extra_fields(self):
49+
with pytest.raises(ValidationError):
50+
ToolConfirmation(unexpected="value")
51+
52+
def test_round_trips_through_dict(self):
53+
original = ToolConfirmation(
54+
hint="confirm transfer", confirmed=True, payload={"to": "bob"}
55+
)
56+
57+
assert ToolConfirmation.model_validate(original.model_dump()) == original

0 commit comments

Comments
 (0)