From aa1b6ed3ea0fab26e14351d56935a229ca498473 Mon Sep 17 00:00:00 2001 From: Torrey Payne <11740989+torreypayne@users.noreply.github.com> Date: Mon, 16 Nov 2026 19:42:24 +0000 Subject: [PATCH] chore(ai_platform): add PredictionService and V1 acceptance smoke tests --- .../v1/prediction_service_smoke_test.rb | 106 ++++++++++++++++++ .../google/cloud/ai_platform/v1/smoke_test.rb | 45 ++++++++ google-cloud-ai_platform/acceptance/helper.rb | 63 +++++++++++ librarian.yaml | 3 + 4 files changed, 217 insertions(+) create mode 100644 google-cloud-ai_platform/acceptance/google/cloud/ai_platform/v1/prediction_service_smoke_test.rb create mode 100644 google-cloud-ai_platform/acceptance/google/cloud/ai_platform/v1/smoke_test.rb create mode 100644 google-cloud-ai_platform/acceptance/helper.rb diff --git a/google-cloud-ai_platform/acceptance/google/cloud/ai_platform/v1/prediction_service_smoke_test.rb b/google-cloud-ai_platform/acceptance/google/cloud/ai_platform/v1/prediction_service_smoke_test.rb new file mode 100644 index 000000000000..20214a7a67f0 --- /dev/null +++ b/google-cloud-ai_platform/acceptance/google/cloud/ai_platform/v1/prediction_service_smoke_test.rb @@ -0,0 +1,106 @@ +# frozen_string_literal: true + +# 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 +# +# https://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. + +require_relative "../../../../helper" + +class PredictionServiceSmokeTest < Minitest::Test + GENERATE_MODEL = "gemini-3.1-flash-lite" + GENERATE_LOCATION = "global" + EMBED_MODEL = "gemini-embedding-001" + EMBED_LOCATION = "us-central1" + + [:grpc, :rest].each do |transport| + define_method "test_generate_content_#{transport}" do + verify_generate_content transport + end + + define_method "test_stream_generate_content_#{transport}" do + verify_stream_generate_content transport + end + + define_method "test_embed_content_#{transport}" do + verify_embed_content transport + end + end + + private + + def verify_generate_content transport + client = AcceptanceHelper.client :prediction_service, location: GENERATE_LOCATION, transport: transport + model = client.endpoint_path( + project: AcceptanceHelper.project_id, + location: GENERATE_LOCATION, + publisher: "google", + model: GENERATE_MODEL + ) + + response = client.generate_content( + model: model, + contents: [{ role: "user", parts: [{ text: "Reply with the single word: pong" }] }], + generation_config: { max_output_tokens: 256 } + ) + + refute_empty response.candidates + text = extract_text [response] + refute_empty text.strip + end + + def verify_stream_generate_content transport + client = AcceptanceHelper.client :prediction_service, location: GENERATE_LOCATION, transport: transport + model = client.endpoint_path( + project: AcceptanceHelper.project_id, + location: GENERATE_LOCATION, + publisher: "google", + model: GENERATE_MODEL + ) + + chunks = client.stream_generate_content( + model: model, + contents: [{ role: "user", parts: [{ text: "Reply with the single word: ok" }] }], + generation_config: { max_output_tokens: 256 } + ).to_a + + refute_empty chunks + text = extract_text chunks + refute_empty text.strip + end + + def verify_embed_content transport + client = AcceptanceHelper.client :prediction_service, location: EMBED_LOCATION, transport: transport + model = client.endpoint_path( + project: AcceptanceHelper.project_id, + location: EMBED_LOCATION, + publisher: "google", + model: EMBED_MODEL + ) + + response = client.embed_content( + model: model, + content: { parts: [{ text: "Hello, world!" }] } + ) + + refute_nil response.embedding + refute_empty response.embedding.values + end + + def extract_text responses + responses.flat_map do |response| + response.candidates.flat_map do |candidate| + candidate.content&.parts&.filter_map(&:text) || [] + end + end.join + end +end diff --git a/google-cloud-ai_platform/acceptance/google/cloud/ai_platform/v1/smoke_test.rb b/google-cloud-ai_platform/acceptance/google/cloud/ai_platform/v1/smoke_test.rb new file mode 100644 index 000000000000..6d2849fde2b7 --- /dev/null +++ b/google-cloud-ai_platform/acceptance/google/cloud/ai_platform/v1/smoke_test.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +# 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 +# +# https://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. + +require_relative "../../../../helper" + +class SmokeTest < Minitest::Test + SMOKE_LOCATION = "us-east1" + + SMOKE_CASES = [ + [:dataset_service, :list_datasets], + [:endpoint_service, :list_endpoints], + [:job_service, :list_batch_prediction_jobs], + [:job_service, :list_custom_jobs], + [:job_service, :list_hyperparameter_tuning_jobs], + [:migration_service, :search_migratable_resources], + [:model_service, :list_models], + [:pipeline_service, :list_training_pipelines] + ].freeze + + SMOKE_CASES.each do |service, rpc| + [:grpc, :rest].each do |transport| + define_method "test_#{service}_#{rpc}_#{transport}" do + client = AcceptanceHelper.client service, location: SMOKE_LOCATION, transport: transport + parent = "projects/#{AcceptanceHelper.project_id}/locations/#{SMOKE_LOCATION}" + response = client.public_send rpc, parent: parent, page_size: 1 + expected_class = transport == :rest ? Gapic::Rest::PagedEnumerable : Gapic::PagedEnumerable + assert_kind_of expected_class, response + refute_nil response.response + end + end + end +end diff --git a/google-cloud-ai_platform/acceptance/helper.rb b/google-cloud-ai_platform/acceptance/helper.rb new file mode 100644 index 000000000000..80ebcbe8f0b5 --- /dev/null +++ b/google-cloud-ai_platform/acceptance/helper.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +# 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 +# +# https://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. + +if ENV["CI"] || ENV["KOKORO_JOB_NAME"] + # Load JUnit XML formatter from googleapis/ruby-common-tools for Kokoro/Sponge. + begin + require "gapic/minitest_junit_preloader" + rescue LoadError + # Ignored for local runs without ruby-common-tools on $LOAD_PATH. + end +end + +require "minitest/autorun" +require "minitest/focus" +require "minitest/rg" + +require "google/cloud/ai_platform" + +## +# Shared helpers for google-cloud-ai_platform acceptance smoke tests. +# +module AcceptanceHelper + ## + # Returns the GCP project ID configured for acceptance tests. + # + # @return [String] + # + def self.project_id + ENV["GOOGLE_CLOUD_PROJECT"] || + ENV["GOOGLE_CLOUD_TEST_PROJECT"] || + ENV["GCLOUD_TEST_PROJECT"] || + raise("missing GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_TEST_PROJECT, or GCLOUD_TEST_PROJECT") + end + + ## + # Instantiates a versioned AIPlatform service client for the given location and transport. + # + # @param service [Symbol] Factory method name on {Google::Cloud::AIPlatform}. + # @param location [String] Vertex AI location (e.g. "global", "us-central1", "us-east1"). + # @param transport [Symbol] RPC transport (`:grpc` or `:rest`). + # + # @return [Object] + # + def self.client service, location:, transport: :grpc + endpoint = location == "global" ? "aiplatform.googleapis.com" : "#{location}-aiplatform.googleapis.com" + Google::Cloud::AIPlatform.public_send service, version: :v1, transport: transport do |config| + config.endpoint = endpoint + end + end +end diff --git a/librarian.yaml b/librarian.yaml index 2e083a077e32..3be5970e81f6 100644 --- a/librarian.yaml +++ b/librarian.yaml @@ -190,6 +190,9 @@ libraries: ruby-cloud-gem-namespace: Google::Cloud::AIPlatform ruby-cloud-service-override: AiPlatform=AIPlatform keep: + - acceptance/google/cloud/ai_platform/v1/prediction_service_smoke_test.rb + - acceptance/google/cloud/ai_platform/v1/smoke_test.rb + - acceptance/helper.rb - test/README.md ruby: wrapper_of: