Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to another question in the review, is this necessary? If the project wasn't specified, would the client fill in from ADC?

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
Original file line number Diff line number Diff line change
@@ -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
63 changes: 63 additions & 0 deletions google-cloud-ai_platform/acceptance/helper.rb
Original file line number Diff line number Diff line change
@@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this is included at the service level?

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
3 changes: 3 additions & 0 deletions librarian.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

- acceptance/google/cloud/ai_platform/v1/smoke_test.rb
- acceptance/helper.rb
- test/README.md
ruby:
wrapper_of:
Expand Down
Loading