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
2 changes: 1 addition & 1 deletion lib/ruby_llm/providers/vertexai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
Expand Down
38 changes: 38 additions & 0 deletions spec/ruby_llm/providers/vertexai/auth_spec.rb
Original file line number Diff line number Diff line change
@@ -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