|
| 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 | +"""Tests the skills.update() method against the Vertex AI endpoint using replays.""" |
| 16 | + |
| 17 | +import io |
| 18 | +import os |
| 19 | +import zipfile |
| 20 | + |
| 21 | +from tests.unit.vertexai.genai.replays import pytest_helper |
| 22 | +from vertexai._genai import types |
| 23 | + |
| 24 | +# MANDATORY: Initialize the replay test framework for this module |
| 25 | +pytestmark = pytest_helper.setup( |
| 26 | + file=__file__, |
| 27 | + globals_for_file=globals(), |
| 28 | +) |
| 29 | + |
| 30 | +PROJECT_ID = os.environ.get("GOOGLE_CLOUD_PROJECT", "srbai-testing") |
| 31 | +REGION = "us-central1" |
| 32 | + |
| 33 | + |
| 34 | +def test_update_skill(client, tmp_path): |
| 35 | + # Target the autopush sandbox endpoint for the Skill Registry API |
| 36 | + client._api_client._http_options.base_url = ( |
| 37 | + "https://us-central1-autopush-aiplatform.sandbox.googleapis.com" |
| 38 | + ) |
| 39 | + |
| 40 | + # 1. Create a fresh unique skill first |
| 41 | + with open(tmp_path / "SKILL.md", "w") as f: |
| 42 | + f.write("# Test Skill\nInitial content.") |
| 43 | + |
| 44 | + created_skill = client.skills.create( |
| 45 | + display_name="Original Skill", |
| 46 | + description="Original Description", |
| 47 | + config=types.CreateSkillConfig( |
| 48 | + local_path=str(tmp_path), wait_for_completion=True |
| 49 | + ), |
| 50 | + ) |
| 51 | + |
| 52 | + # 2. Perform the metadata-only update on the new skill |
| 53 | + updated_skill = client.skills.update( |
| 54 | + name=created_skill.name, |
| 55 | + config=types.UpdateSkillConfig( |
| 56 | + display_name="My Updated Replay Skill", |
| 57 | + description="My Updated Replay Skill Description", |
| 58 | + wait_for_completion=True, |
| 59 | + ), |
| 60 | + ) |
| 61 | + |
| 62 | + assert updated_skill.name == created_skill.name |
| 63 | + assert updated_skill.display_name == "My Updated Replay Skill" |
| 64 | + assert updated_skill.description == "My Updated Replay Skill Description" |
| 65 | + |
| 66 | + |
| 67 | +def test_update_skill_with_zipped_bytes(client, tmp_path): |
| 68 | + # Target the autopush sandbox endpoint for the Skill Registry API |
| 69 | + client._api_client._http_options.base_url = ( |
| 70 | + "https://us-central1-autopush-aiplatform.sandbox.googleapis.com" |
| 71 | + ) |
| 72 | + |
| 73 | + # 1. Create a fresh unique skill first |
| 74 | + with open(tmp_path / "SKILL.md", "w") as f: |
| 75 | + f.write("# Test Skill\nInitial content.") |
| 76 | + |
| 77 | + created_skill = client.skills.create( |
| 78 | + display_name="Original Skill", |
| 79 | + description="Original Description", |
| 80 | + config=types.CreateSkillConfig( |
| 81 | + local_path=str(tmp_path), wait_for_completion=True |
| 82 | + ), |
| 83 | + ) |
| 84 | + |
| 85 | + # 2. Prepare zipped bytes for update |
| 86 | + zip_buffer = io.BytesIO() |
| 87 | + zinfo = zipfile.ZipInfo("SKILL.md", date_time=(1980, 1, 1, 0, 0, 0)) |
| 88 | + with zipfile.ZipFile(zip_buffer, "w") as zip_file: |
| 89 | + zip_file.writestr(zinfo, "# My Updated Zipped Replay Skill\nThis is updated.") |
| 90 | + zipped_bytes = zip_buffer.getvalue() |
| 91 | + |
| 92 | + # 3. Update the skill with new zipped bytes |
| 93 | + updated_skill = client.skills.update( |
| 94 | + name=created_skill.name, |
| 95 | + config=types.UpdateSkillConfig( |
| 96 | + zipped_filesystem=zipped_bytes, wait_for_completion=True |
| 97 | + ), |
| 98 | + ) |
| 99 | + |
| 100 | + assert updated_skill.name == created_skill.name |
| 101 | + assert ( |
| 102 | + updated_skill.display_name == "Original Skill" |
| 103 | + ) # Display name remains unchanged |
0 commit comments