Draft: fix: Duo Agent Platform setting followup
Relates to issue #583686
Changes
This MR addresses the remaining discussions from MR !216002 (merged):
1. Feature Flag Update (Discussion #2946330563)
-
File:
ee/lib/ai/duo_workflow.rb -
Change: Replaced
::Gitlab::Saas.feature_available?(:gitlab_com_subscriptions)with::Gitlab::Saas.feature_available?(:gitlab_duo_saas_only)in theduo_agent_platform_available?method -
Rationale: Using
gitlab_duo_saas_onlyis more specific to Duo features and aligns with the pattern already used inee/lib/gitlab/llm/stage_check.rb
2. Spec Coverage for Feature Flag (Discussion #2946330563)
-
File:
ee/spec/lib/ai/duo_workflow_spec.rb -
Change: Added a test to verify that the
duo_agent_platform_available?method uses thegitlab_duo_saas_onlyfeature flag - Rationale: Ensures the feature flag change is properly tested
3. Factory Usage in Specs (Discussion #2946330585)
-
File:
ee/spec/lib/ai/catalog_spec.rb -
Change: Replaced manual AI setting creation (
ai_setting = ::Ai::Setting.instance; ai_setting.update!(...)) with factory usage (create(:ai_settings, feature_settings: { ... })) in two locations - Rationale: Follows best practices by using factories instead of manual record creation, making tests more maintainable
4. Default Value in Spec (Discussion #2946330600)
-
File:
ee/spec/services/application_settings/update_service_spec.rb -
Change: Removed the
setting.update!(duo_agent_platform_enabled: true)setup line from the "when updating duo_agent_platform_enabled" context - Rationale: The test now relies on the default value (false) instead of explicitly setting it to true first, making the test cleaner
5. Documentation for Search Autocomplete (Discussion #2946330602)
-
File:
ee/app/helpers/ee/search_helper.rb -
Change: Added comprehensive documentation comment above the
default_autocomplete_ai_catalogmethod explaining:- The method respects
duo_agent_platform_enabledthrough theAi::Catalog.available?check - On SaaS in production, results are cached for 30 minutes
- Changes to the setting may take up to 30 minutes to reflect in autocomplete
- The method respects
- Rationale: Addresses the concern about AI Catalog still showing in search with the setting off by documenting the caching behavior
Verification
Through code analysis, the search autocomplete properly respects the duo_agent_platform_enabled setting:
-
default_autocomplete_ai_catalogchecksAbility.allowed?(current_user, :read_ai_catalog) - The
:read_ai_catalogability is defined inee/app/policies/ee/global_policy.rbbased onai_catalog_availablecondition - This condition calls
::Ai::Catalog.available?(@user) -
::Ai::Catalog.available?includesduo_agent_platform_available_for_user?which checks theduo_agent_platform_enabledsetting
The issue reported is likely due to the 30-minute cache in production (defined in ee/lib/ai/catalog.rb). The documentation added clarifies this behavior.
Edited by Duo Developer