Skip to content

Commit 7f538d2

Browse files
authored
Merge branch 'main' into fix/eval-user-content-validation-error
2 parents 9352f62 + 0cb4c81 commit 7f538d2

4 files changed

Lines changed: 66 additions & 6 deletions

File tree

src/google/adk/integrations/api_registry/api_registry.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ def __init__(
6161
page_token = None
6262
with httpx.Client() as client:
6363
while True:
64-
params = {}
64+
params = {
65+
# Include all the apis including disabled ones. API registry no longer supports enabling APIs.
66+
"filter": "enabled=false"
67+
}
6568
if page_token:
6669
params["pageToken"] = page_token
6770

src/google/adk/tools/skill_toolset.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,10 @@ def _build_wrapper_code(
669669
" full_path = os.path.join(os.path.abspath(td), norm_rel)",
670670
" os.makedirs(os.path.dirname(full_path), exist_ok=True)",
671671
" mode = 'wb' if isinstance(content, bytes) else 'w'",
672-
" with open(full_path, mode) as f:",
672+
(
673+
" with open(full_path, mode, encoding='utf-8' if mode == 'w'"
674+
" else None) as f:"
675+
),
673676
" f.write(content)",
674677
" os.chdir(td)",
675678
" try:",

tests/unittests/integrations/api_registry/test_api_registry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_init_success(self, MockHttpClient):
9191
"Authorization": "Bearer mock_token",
9292
"Content-Type": "application/json",
9393
},
94-
params={},
94+
params={"filter": "enabled=false"},
9595
)
9696

9797
@patch("httpx.Client", autospec=True)
@@ -120,7 +120,7 @@ def test_init_with_quota_project_id_success(self, MockHttpClient):
120120
"Content-Type": "application/json",
121121
"x-goog-user-project": "quota-project",
122122
},
123-
params={},
123+
params={"filter": "enabled=false"},
124124
)
125125

126126
@patch("httpx.Client", autospec=True)
@@ -176,15 +176,15 @@ def test_init_with_pagination_success(self, MockHttpClient):
176176
"Authorization": "Bearer mock_token",
177177
"Content-Type": "application/json",
178178
},
179-
params={},
179+
params={"filter": "enabled=false"},
180180
)
181181
mock_client_instance.get.assert_called_with(
182182
f"https://cloudapiregistry.googleapis.com/v1beta/projects/{self.project_id}/locations/{self.location}/mcpServers",
183183
headers={
184184
"Authorization": "Bearer mock_token",
185185
"Content-Type": "application/json",
186186
},
187-
params={"pageToken": "next_page_token"},
187+
params={"filter": "enabled=false", "pageToken": "next_page_token"},
188188
)
189189

190190
@patch("httpx.Client", autospec=True)

tests/unittests/tools/test_skill_toolset.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,31 @@ async def test_execute_script_shell_success(mock_skill1):
817817
assert "__shell_result__" in code_input.code
818818

819819

820+
@pytest.mark.asyncio
821+
async def test_build_wrapper_code_with_unicode(mock_skill1):
822+
"""Verify that generated code uses utf-8 encoding for materializing files."""
823+
# Add unicode content to mock_skill1 resources
824+
unicode_content = "你好"
825+
mock_skill1.resources.list_references.return_value = ["unicode.txt"]
826+
mock_skill1.resources.get_reference.side_effect = lambda name: (
827+
unicode_content if name == "unicode.txt" else None
828+
)
829+
830+
executor = _make_mock_executor()
831+
toolset = skill_toolset.SkillToolset([mock_skill1], code_executor=executor)
832+
tool = skill_toolset.RunSkillScriptTool(toolset)
833+
ctx = _make_tool_context_with_agent()
834+
await tool.run_async(
835+
args={"skill_name": "skill1", "file_path": "run.py"},
836+
tool_context=ctx,
837+
)
838+
839+
call_args = executor.execute_code.call_args
840+
code_input = call_args[0][1]
841+
assert "encoding='utf-8' if mode == 'w' else None" in code_input.code
842+
assert unicode_content in code_input.code
843+
844+
820845
@pytest.mark.asyncio
821846
async def test_execute_script_with_input_args_python(mock_skill1):
822847
executor = _make_mock_executor(stdout="done\n")
@@ -1251,6 +1276,35 @@ async def test_integration_python_stdout():
12511276
assert result["stderr"] == ""
12521277

12531278

1279+
@pytest.mark.asyncio
1280+
async def test_integration_python_unicode_materialization():
1281+
"""Real executor: Python script with unicode resources."""
1282+
script = models.Script(
1283+
src=(
1284+
"with open('references/unicode.txt', 'r', encoding='utf-8') as f:"
1285+
" print(f.read())"
1286+
)
1287+
)
1288+
skill = _make_skill_with_script("test_skill", "unicode.py", script)
1289+
skill.resources.get_reference.side_effect = lambda n: (
1290+
"你好,世界" if n == "unicode.txt" else None
1291+
)
1292+
skill.resources.list_references.return_value = ["unicode.txt"]
1293+
toolset = _make_real_executor_toolset([skill])
1294+
tool = skill_toolset.RunSkillScriptTool(toolset)
1295+
ctx = _make_tool_context_with_agent()
1296+
result = await tool.run_async(
1297+
args={
1298+
"skill_name": "test_skill",
1299+
"file_path": "unicode.py",
1300+
},
1301+
tool_context=ctx,
1302+
)
1303+
assert "status" in result, f"Result missing status: {result}"
1304+
assert result["status"] == "success"
1305+
assert "你好,世界" in result["stdout"]
1306+
1307+
12541308
@pytest.mark.asyncio
12551309
async def test_integration_python_imports_sibling_script_module():
12561310
"""Real executor: Python scripts can import helpers from scripts/."""

0 commit comments

Comments
 (0)