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 the duo_agent_platform_available? method
  • Rationale: Using gitlab_duo_saas_only is more specific to Duo features and aligns with the pattern already used in ee/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 the gitlab_duo_saas_only feature 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_catalog method explaining:
    • The method respects duo_agent_platform_enabled through the Ai::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
  • 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:

  1. default_autocomplete_ai_catalog checks Ability.allowed?(current_user, :read_ai_catalog)
  2. The :read_ai_catalog ability is defined in ee/app/policies/ee/global_policy.rb based on ai_catalog_available condition
  3. This condition calls ::Ai::Catalog.available?(@user)
  4. ::Ai::Catalog.available? includes duo_agent_platform_available_for_user? which checks the duo_agent_platform_enabled setting

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

Merge request reports

Loading