Files
chatwoot/spec/lib/llm/models_spec.rb
T
Sony MathewandGitHub 8b977b35a8 feat: Add LLM feature router (1/6) (#14839)
## Description

Adds the foundation for feature-specific LLM model routing so Captain AI
features can resolve their effective provider/model from code defaults
and account-level overrides. This fixes the provider metadata key in
`config/llm.yml`, adds `Llm::FeatureRouter`, and routes existing
`CaptainFeaturable` model defaults through the shared resolver.

Fixes https://linear.app/chatwoot/issue/CW-7425/test-new-models

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality not to work as expected)
- [ ] This change requires a documentation update

## How Has This Been Tested?

- `bundle exec rspec spec/lib/llm/models_spec.rb
spec/lib/llm/feature_router_spec.rb
spec/models/concerns/captain_featurable_spec.rb` - 23 examples, 0
failures
- `bundle exec rubocop lib/llm/models.rb lib/llm/feature_router.rb
app/models/concerns/captain_featurable.rb spec/lib/llm/models_spec.rb
spec/lib/llm/feature_router_spec.rb
spec/models/concerns/captain_featurable_spec.rb` - no offenses
- `bundle exec ruby -e "require 'yaml'; config =
YAML.load_file('config/llm.yml'); abort('missing providers') unless
config['providers']; abort('missing models') unless config['models'];
abort('missing features') unless config['features']; puts 'llm.yml ok'"`
- `git diff --check`

## Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [ ] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
2026-06-25 17:00:07 +05:30

57 lines
1.7 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 '.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