diff --git a/lib/ruby_llm/providers/vertexai.rb b/lib/ruby_llm/providers/vertexai.rb index 268774eec..8cf7bc057 100644 --- a/lib/ruby_llm/providers/vertexai.rb +++ b/lib/ruby_llm/providers/vertexai.rb @@ -41,7 +41,7 @@ def configuration_requirements def initialize_authorizer require 'googleauth' @authorizer = ::Google::Auth.get_application_default( - scope: [ + [ 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/generative-language.retriever' ] diff --git a/spec/ruby_llm/providers/vertexai/auth_spec.rb b/spec/ruby_llm/providers/vertexai/auth_spec.rb new file mode 100644 index 000000000..bcb5325f0 --- /dev/null +++ b/spec/ruby_llm/providers/vertexai/auth_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe RubyLLM::Providers::VertexAI do + include_context 'with configured RubyLLM' + + describe '#initialize_authorizer' do + let(:provider) do + described_class.new(RubyLLM.config) + end + + let(:mock_credentials) do + instance_double(Google::Auth::GCECredentials, apply: { 'Authorization' => 'Bearer test-token' }) + end + + before do + provider.instance_variable_set(:@authorizer, nil) + end + + it 'passes scope as a positional Array argument to get_application_default' do + # This test verifies the fix for the TypeError that occurs when running on GCE. + # Google::Auth.get_application_default expects scope as a positional argument, + # not a keyword argument. Passing `scope: [...]` causes Ruby to interpret it + # as a Hash, which triggers: TypeError: Expected Array or String, got Hash + expected_scopes = [ + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/generative-language.retriever' + ] + + expect(Google::Auth).to receive(:get_application_default) + .with(expected_scopes) + .and_return(mock_credentials) + + provider.headers + end + end +end