Fix model test connection returning 401 when code-suggestions unpinned
What does this MR do and why?
This MR is has 2 related fixes rolled into 1:
1)
When/admin/gitlab_duo/model_selection/models/new when no code completion model is pinned, Test connection button returns 401.
This change fixes it by passing down a mocked feature setting to the cloud connector token generator.
2)
When no code completion model is pinned for code completion. The direct_access call (getting tokens to directly access the AI Gateway without the monolith middle man) does not work neither without a clear error message.
The AIGW error raise JWTError(e)\njose.exceptions.JWTError: Not enough segments isn't much clearer.
How to set up and validate locally
Before
Test connection
- Make sure the code completion feature setting is unpinned in
/admin/gitlab_duo/model_selection.- You run this command in the console to unpin the feature setting in it original state
::Ai::FeatureSetting.find_by(feature: :code_completions).destroy && ::Ai::FeatureSetting.find_by(feature: :code_generations).destroy
- Create a new model or modify a model that you know works.
- Click the test connection button, It should return 401 coming from the AIGW.
Direct access API call
- Make sure the code completion feature setting is unpinned in
/admin/gitlab_duo/model_selection.- You run this command in the console to unpin the feature setting in it original state
::Ai::FeatureSetting.find_by(feature: :code_completions).destroy && ::Ai::FeatureSetting.find_by(feature: :code_generations).destroy
- Go to a project
- Open you the Web IDE in this project
- Open your developer console in the network tab and reload
- You should see this call

After
Test connection
Clicking the test connection button, Should work as intended. The test should pass through the AIGW.
Direct access API call
Should give a detailed error message.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #596662 (closed)


