102 lines
3.5 KiB
Ruby
102 lines
3.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe Llm::Models do
|
|
describe '.providers' do
|
|
it 'loads provider metadata from the config' do
|
|
expect(described_class.providers).to include(
|
|
'openai' => include('display_name' => 'OpenAI')
|
|
)
|
|
end
|
|
end
|
|
|
|
describe '.features' do
|
|
it 'keeps every feature default in the allowed model list' do
|
|
described_class.features.each do |feature_key, config|
|
|
expect(config['models']).to include(config['default']), "#{feature_key} default model must be allowed"
|
|
end
|
|
end
|
|
|
|
it 'references existing models from every feature' do
|
|
described_class.features.each do |feature_key, config|
|
|
missing_models = config['models'].reject { |model_name| described_class.models.key?(model_name) }
|
|
|
|
expect(missing_models).to be_empty, "#{feature_key} references missing models: #{missing_models.join(', ')}"
|
|
end
|
|
end
|
|
end
|
|
|
|
describe '.models' do
|
|
it 'references existing providers from every model' do
|
|
missing_providers = described_class.models.filter_map do |model_name, config|
|
|
provider = config['provider']
|
|
next if described_class.providers.key?(provider)
|
|
|
|
"#{model_name}: #{provider}"
|
|
end
|
|
|
|
expect(missing_providers).to be_empty
|
|
end
|
|
end
|
|
|
|
describe '.models_for' do
|
|
it 'filters out models whose provider is not supported by RubyLLM' do
|
|
allow(Llm::Config).to receive(:ruby_llm_provider_supported?) do |provider|
|
|
provider.to_s != 'anthropic'
|
|
end
|
|
|
|
expect(described_class.models_for('assistant')).not_to include('claude-haiku-4.5')
|
|
end
|
|
|
|
it 'adds selected RubyLLM provider chat models for chat features' do
|
|
create(:installation_config, name: 'CAPTAIN_LLM_PROVIDER', value: 'openrouter')
|
|
|
|
expect(described_class.models_for('assistant')).to include('ai21/jamba-large-1.7')
|
|
expect(described_class.models_for('assistant')).not_to include('gpt-4.1')
|
|
end
|
|
|
|
it 'does not add selected chat-provider models to OpenAI-only features' do
|
|
create(:installation_config, name: 'CAPTAIN_LLM_PROVIDER', value: 'openrouter')
|
|
|
|
expect(described_class.models_for('help_center_search')).not_to include('ai21/jamba-large-1.7')
|
|
expect(described_class.models_for('help_center_search')).to include('text-embedding-3-small')
|
|
end
|
|
end
|
|
|
|
describe '.default_model_for' do
|
|
it 'uses the installation model when it is valid for the feature and active provider' do
|
|
create(:installation_config, name: 'CAPTAIN_LLM_MODEL', value: 'gpt-5-mini')
|
|
|
|
expect(described_class.default_model_for('assistant')).to eq('gpt-5-mini')
|
|
end
|
|
|
|
it 'ignores installation models from another provider' do
|
|
create(:installation_config, name: 'CAPTAIN_LLM_PROVIDER', value: 'openrouter')
|
|
create(:installation_config, name: 'CAPTAIN_LLM_MODEL', value: 'gpt-5-mini')
|
|
|
|
expect(described_class.default_model_for('assistant')).to eq('ai21/jamba-large-1.7')
|
|
end
|
|
end
|
|
|
|
describe '.provider_for' do
|
|
it 'uses RubyLLM model metadata for provider models outside llm.yml' do
|
|
expect(described_class.provider_for('ai21/jamba-large-1.7')).to eq('openrouter')
|
|
end
|
|
end
|
|
|
|
describe '.feature_config' do
|
|
it 'returns model metadata for a feature' do
|
|
config = described_class.feature_config('editor')
|
|
|
|
expect(config[:default]).to eq('gpt-4.1-mini')
|
|
expect(config[:models].first).to include(
|
|
id: 'gpt-4.1-mini',
|
|
display_name: 'GPT-4.1 Mini',
|
|
provider: 'openai',
|
|
credit_multiplier: 1
|
|
)
|
|
end
|
|
end
|
|
end
|