diff --git a/ee/app/graphql/mutations/projects/project_settings_update.rb b/ee/app/graphql/mutations/projects/project_settings_update.rb index 275667bd09442e69175ce13aa71182116f79637b..9f5e78e1146d779dbe6272696ccc0809360891d2 100644 --- a/ee/app/graphql/mutations/projects/project_settings_update.rb +++ b/ee/app/graphql/mutations/projects/project_settings_update.rb @@ -44,12 +44,7 @@ def allowed? return true if ::Gitlab::Saas.feature_available?(:duo_chat_on_saas) return false unless ::License.feature_available?(:code_suggestions) - if ::CodeSuggestions::SelfManaged::SERVICE_START_DATE.past? - ::GitlabSubscriptions::AddOnPurchase.for_gitlab_duo_pro.any? - else # Before service start date - # TODO: Remove this else branch after the service start date - ::Gitlab::CurrentSettings.instance_level_code_suggestions_enabled - end + ::GitlabSubscriptions::AddOnPurchase.for_gitlab_duo_pro.any? end end end diff --git a/ee/app/helpers/admin/application_settings_helper.rb b/ee/app/helpers/admin/application_settings_helper.rb index 5eb1bbc8106c93e042244da4fa57e3058a024cad..5ca0b337b7f409a630875c08159d817c923e91e9 100644 --- a/ee/app/helpers/admin/application_settings_helper.rb +++ b/ee/app/helpers/admin/application_settings_helper.rb @@ -14,11 +14,6 @@ def ai_powered_description tag_pair_for_link(ai_powered_docs_url)) end - def admin_display_code_suggestions_toggle? - start_date = CodeSuggestions::SelfManaged::SERVICE_START_DATE - License.feature_available?(:code_suggestions) && start_date.future? - end - def admin_display_ai_powered_toggle? License.feature_available?(:ai_chat) && CloudConnector::AccessService.new.free_access_for?(:duo_chat) end diff --git a/ee/app/views/admin/application_settings/_ai_powered.html.haml b/ee/app/views/admin/application_settings/_ai_powered.html.haml index 9df16426807ca48bacd043dc604bc2f6f37457d0..75151511ae2cef801831dc17d2c3b7d036417fb2 100644 --- a/ee/app/views/admin/application_settings/_ai_powered.html.haml +++ b/ee/app/views/admin/application_settings/_ai_powered.html.haml @@ -1,11 +1,8 @@ - return if Gitlab.org_or_com? --# TODO: clean-up after the Code Suggestions service start date (16.9+) --# Details (internal): https://gitlab.com/gitlab-org/gitlab/-/issues/425047#note_1673643291 -- visible_code_suggestions = admin_display_code_suggestions_toggle? - visible_duo_chat = admin_display_ai_powered_toggle? -- return if !visible_code_suggestions && !visible_duo_chat +- return if !visible_duo_chat - expanded = false @@ -24,19 +21,8 @@ %fieldset .form-group - - if visible_code_suggestions - %h5.settings-header-controls - = s_('CodeSuggestionsSM|Code Suggestions').html_safe - = f.gitlab_ui_checkbox_component :instance_level_code_suggestions_enabled, - s_('CodeSuggestionsSM|Enable Code Suggestions for this instance'), - help_text: ai_powered_testing_agreement - - - if visible_duo_chat - - if visible_code_suggestions - %h5.settings-header-controls - = s_('AIPoweredSM|AI-powered features') - = f.gitlab_ui_checkbox_component :instance_level_ai_beta_features_enabled, - s_('AIPoweredSM|Enable Experiment and Beta AI-powered features'), - help_text: ai_powered_testing_agreement + = f.gitlab_ui_checkbox_component :instance_level_ai_beta_features_enabled, + s_('AIPoweredSM|Enable Experiment and Beta AI-powered features'), + help_text: ai_powered_testing_agreement = f.submit _('Save changes'), pajamas_button: true diff --git a/ee/lib/api/internal/ai/x_ray/scan.rb b/ee/lib/api/internal/ai/x_ray/scan.rb index c7664ab1036ab2c6bfc8be848d8be5b6d8648863..2a3df4d22d48d4a6a2cfb42e3177e0ca993a6b44 100644 --- a/ee/lib/api/internal/ai/x_ray/scan.rb +++ b/ee/lib/api/internal/ai/x_ray/scan.rb @@ -25,14 +25,7 @@ def x_ray_enabled_on_instance? return true if ::Gitlab.org_or_com? return false unless ::License.feature_available?(:code_suggestions) - if ::CodeSuggestions::SelfManaged::SERVICE_START_DATE.past? - ::GitlabSubscriptions::AddOnPurchase - .for_gitlab_duo_pro - .any? - else # Before service start date - # TODO: Remove this else branch after the service start date - ::Gitlab::CurrentSettings.instance_level_code_suggestions_enabled - end + ::GitlabSubscriptions::AddOnPurchase.for_gitlab_duo_pro.any? end def x_ray_available? diff --git a/ee/lib/code_suggestions/self_managed.rb b/ee/lib/code_suggestions/self_managed.rb deleted file mode 100644 index 10e5ea1bac487cfbd420da366ed9a870b5feb740..0000000000000000000000000000000000000000 --- a/ee/lib/code_suggestions/self_managed.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -module CodeSuggestions - class SelfManaged - SERVICE_START_DATE = Time.zone.parse('2024-02-15T00:00:00Z') - end -end diff --git a/ee/spec/graphql/mutations/projects/project_settings_update_spec.rb b/ee/spec/graphql/mutations/projects/project_settings_update_spec.rb index 7cd09fc271cf0850b9eefcfdcde497861cedf81d..a16deb5d4c9d56386310d8e69e8c076ae0c13fde 100644 --- a/ee/spec/graphql/mutations/projects/project_settings_update_spec.rb +++ b/ee/spec/graphql/mutations/projects/project_settings_update_spec.rb @@ -44,7 +44,6 @@ context 'when duo addon is not available' do before do stub_licensed_features(code_suggestions: true) - stub_const("::CodeSuggestions::SelfManaged::SERVICE_START_DATE", Time.zone.parse('2000-02-15T00:00:00Z')) end it 'raises an error' do @@ -55,18 +54,6 @@ end end - context 'when instance has it disabled' do - before do - stub_licensed_features(code_suggestions: true) - stub_const("::CodeSuggestions::SelfManaged::SERVICE_START_DATE", Time.zone.parse('3000-02-15T00:00:00Z')) - stub_application_setting(instance_level_code_suggestions_enabled: false) - end - - it 'raises an error' do - expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) - end - end - context 'when duo chat is enabled on saas' do before do stub_licensed_features(code_suggestions: false) diff --git a/ee/spec/helpers/admin/application_settings_helper_spec.rb b/ee/spec/helpers/admin/application_settings_helper_spec.rb index 148b3b503eb04d7864628284ed375b0ab197965a..777df9e2a1bf6460d1ba8643a525d1e41cdbc087 100644 --- a/ee/spec/helpers/admin/application_settings_helper_spec.rb +++ b/ee/spec/helpers/admin/application_settings_helper_spec.rb @@ -19,33 +19,6 @@ end end - describe '#admin_display_code_suggestions_toggle?', :freeze_time, feature_category: :code_suggestions do - let(:feature_enabled) { true } - - let(:today) { Date.current } - let(:tomorrow) { today + 1.day } - - before do - stub_licensed_features(ai_chat: feature_enabled) - stub_const('CodeSuggestions::SelfManaged::SERVICE_START_DATE', service_start_date) - end - - where(:service_start_date, :feature_available, :expectation) do - ref(:today) | true | false - ref(:today) | false | false - ref(:tomorrow) | true | true - ref(:tomorrow) | false | false - end - - with_them do - it 'returns expectation' do - stub_licensed_features(code_suggestions: feature_available) - - expect(helper.admin_display_code_suggestions_toggle?).to eq(expectation) - end - end - end - describe '#admin_display_ai_powered_toggle?', :freeze_time, feature_category: :duo_chat do let(:feature_enabled) { true } let(:past) { Time.current - 1.second } diff --git a/ee/spec/requests/api/internal/ai/x_ray/scan_spec.rb b/ee/spec/requests/api/internal/ai/x_ray/scan_spec.rb index 772740560b6ac7b5a3d95ae7e24fc2c6ac0124b6..302ff0910055b0e9f392d694eb793d0d10cceeea 100644 --- a/ee/spec/requests/api/internal/ai/x_ray/scan_spec.rb +++ b/ee/spec/requests/api/internal/ai/x_ray/scan_spec.rb @@ -92,163 +92,72 @@ stub_licensed_features(code_suggestions: true) end - # TODO: clean up date-related tests after the Code Suggestions service start date (15.02.2024) - context 'when before the service start date' do - around do |example| - travel_to(CodeSuggestions::SelfManaged::SERVICE_START_DATE - 1.day) do - example.run - end - end - - context 'with code suggestions disabled on instance level' do - before do - stub_ee_application_setting(instance_level_code_suggestions_enabled: false) - end - - it 'returns NOT_FOUND status' do - post_api + context 'without add on' do + it 'returns NOT_FOUND status' do + post_api - expect(response).to have_gitlab_http_status(:not_found) - end + expect(response).to have_gitlab_http_status(:not_found) end + end - context 'with code suggestions enabled on instance level' do - before do - stub_ee_application_setting(instance_level_code_suggestions_enabled: true) - end - - it 'calls ::CloudConnector::AccessService to obtain access token', :aggregate_failures do - expect_next_instance_of(::CloudConnector::AccessService) do |instance| - expect(instance).to receive(:access_token).with([:code_suggestions]).and_return(ai_gateway_token) - end - - post_api - - expect(response).to have_gitlab_http_status(:ok) - end - - context 'when cloud connector access token is missing' do - before do - allow_next_instance_of(::CloudConnector::AccessService) do |instance| - allow(instance).to receive(:access_token).and_return(nil) - end - end - - it 'returns UNAUTHORIZED status' do - post_api + context 'with add on' do + before_all { create(:gitlab_subscription_add_on_purchase, namespace: namespace) } - expect(response).to have_gitlab_http_status(:unauthorized) - end + it 'calls ::CloudConnector::AccessService to obtain access token', :aggregate_failures do + expect_next_instance_of(::CloudConnector::AccessService) do |instance| + expect(instance).to receive(:access_token).with([:code_suggestions]) + .and_return(ai_gateway_token) end - context 'when cloud connector access token is valid' do - before do - allow_next_instance_of(::CloudConnector::AccessService) do |instance| - allow(instance).to receive(:access_token).and_return(ai_gateway_token) - end - end - - context 'when instance has uuid available' do - let(:instance_uuid) { 'some uuid' } - - before do - allow(Gitlab::CurrentSettings).to receive(:uuid).and_return(instance_uuid) - end - - it_behaves_like 'successful send request via workhorse' - end - - context 'when instance has custom hostname' do - let(:hostname) { 'gitlab.local' } - - before do - stub_config(gitlab: { - protocol: 'http', - host: hostname, - url: "http://#{hostname}", - relative_url_root: "http://#{hostname}" - }) - end + post_api - it_behaves_like 'successful send request via workhorse' - end - end + expect(response).to have_gitlab_http_status(:ok) end - end - context 'when it is past the code suggestions service start date' do - around do |example| - travel_to(::CodeSuggestions::SelfManaged::SERVICE_START_DATE + 1.second) do - example.run + context 'when cloud connector access token is missing' do + before do + allow_next_instance_of(::CloudConnector::AccessService) do |instance| + allow(instance).to receive(:access_token).and_return(nil) + end end - end - context 'with out add on' do - it 'returns NOT_FOUND status' do + it 'returns UNAUTHORIZED status' do post_api - expect(response).to have_gitlab_http_status(:not_found) + expect(response).to have_gitlab_http_status(:unauthorized) end end - context 'with add on' do - before_all { create(:gitlab_subscription_add_on_purchase, namespace: namespace) } - - it 'calls ::CloudConnector::AccessService to obtain access token', :aggregate_failures do - expect_next_instance_of(::CloudConnector::AccessService) do |instance| - expect(instance).to receive(:access_token).with([:code_suggestions]).and_return(ai_gateway_token) + context 'when cloud connector access token is valid' do + before do + allow_next_instance_of(::CloudConnector::AccessService) do |instance| + allow(instance).to receive(:access_token).and_return(ai_gateway_token) end - - post_api - - expect(response).to have_gitlab_http_status(:ok) end - context 'when cloud connector access token is missing' do - before do - allow_next_instance_of(::CloudConnector::AccessService) do |instance| - allow(instance).to receive(:access_token).and_return(nil) - end - end - - it 'returns UNAUTHORIZED status' do - post_api - - expect(response).to have_gitlab_http_status(:unauthorized) - end - end + context 'when instance has uuid available' do + let(:instance_uuid) { 'some uuid' } - context 'when cloud connector access token is valid' do before do - allow_next_instance_of(::CloudConnector::AccessService) do |instance| - allow(instance).to receive(:access_token).and_return(ai_gateway_token) - end + allow(Gitlab::CurrentSettings).to receive(:uuid).and_return(instance_uuid) end - context 'when instance has uuid available' do - let(:instance_uuid) { 'some uuid' } + it_behaves_like 'successful send request via workhorse' + end - before do - allow(Gitlab::CurrentSettings).to receive(:uuid).and_return(instance_uuid) - end + context 'when instance has custom hostname' do + let(:hostname) { 'gitlab.local' } - it_behaves_like 'successful send request via workhorse' + before do + stub_config(gitlab: { + protocol: 'http', + host: hostname, + url: "http://#{hostname}", + relative_url_root: "http://#{hostname}" + }) end - context 'when instance has custom hostname' do - let(:hostname) { 'gitlab.local' } - - before do - stub_config(gitlab: { - protocol: 'http', - host: hostname, - url: "http://#{hostname}", - relative_url_root: "http://#{hostname}" - }) - end - - it_behaves_like 'successful send request via workhorse' - end + it_behaves_like 'successful send request via workhorse' end end end diff --git a/ee/spec/views/admin/application_settings/general.html.haml_spec.rb b/ee/spec/views/admin/application_settings/general.html.haml_spec.rb index d5e6d9a268665360f1664e4c97a15fc563368918..f6ff64a5eca88f72acdaa57f5997fc4afe2c228a 100644 --- a/ee/spec/views/admin/application_settings/general.html.haml_spec.rb +++ b/ee/spec/views/admin/application_settings/general.html.haml_spec.rb @@ -8,14 +8,7 @@ let_it_be(:user) { create(:admin) } let_it_be(:app_settings) { build(:application_setting) } - let(:code_suggestions_start_date) { CodeSuggestions::SelfManaged::SERVICE_START_DATE } - let(:before_code_suggestions_start_date) { code_suggestions_start_date - 1.second } - let(:after_code_suggestions_start_date) { code_suggestions_start_date + 1.second } - - let(:duo_chat_cut_off_date) { code_suggestions_start_date + 1.month } - let(:before_duo_chat_cut_off_date) { duo_chat_cut_off_date - 1.second } - let(:after_duo_chat_cut_off_date) { duo_chat_cut_off_date + 1.second } - + let(:duo_chat_cut_off_date) { Time.zone.parse('2024-03-15T00:00:00Z') } let(:duo_chat) { CloudConnector::ConnectedService.new(name: :duo_chat, cut_off_date: duo_chat_cut_off_date) } subject { rendered } @@ -168,74 +161,6 @@ end end - describe 'instance-level Code Suggestions settings', feature_category: :code_suggestions do - before do - allow(::Gitlab).to receive(:org_or_com?).and_return(gitlab_org_or_com?) - stub_licensed_features(code_suggestions: false) - end - - shared_examples 'does not render Code Suggestions toggle' do - it 'does not render Code Suggestions toggle' do - render - expect(rendered).not_to have_field('application_setting_instance_level_code_suggestions_enabled') - end - end - - context 'when on .com or .org' do - let(:gitlab_org_or_com?) { true } - - it_behaves_like 'does not render Code Suggestions toggle' - end - - context 'when not on .com and not on .org' do - let(:gitlab_org_or_com?) { false } - - context 'with license', :with_license do - context 'with :code_suggestions feature available' do - before do - stub_licensed_features(code_suggestions: true) - end - - # TODO: clean up date-related tests after the Code Suggestions service start date (16.9+) - context 'when before the service start date' do - around do |example| - travel_to(CodeSuggestions::SelfManaged::SERVICE_START_DATE - 1.day) do - example.run - end - end - - it 'renders Code Suggestions toggle' do - render - expect(rendered).to have_field('application_setting_instance_level_code_suggestions_enabled') - end - end - - context 'when at the service start date' do - around do |example| - travel_to(CodeSuggestions::SelfManaged::SERVICE_START_DATE) do - example.run - end - end - - it_behaves_like 'does not render Code Suggestions toggle' - end - end - - context 'with :code_suggestions feature not available' do - before do - stub_licensed_features(code_suggestions: false) - end - - it_behaves_like 'does not render Code Suggestions toggle' - end - end - - context 'with no license', :without_license do - it_behaves_like 'does not render Code Suggestions toggle' - end - end - end - describe 'instance-level ai-powered beta features settings', feature_category: :duo_chat do before do allow(::Gitlab).to receive(:org_or_com?).and_return(gitlab_org_or_com?) @@ -293,12 +218,6 @@ context 'when cut off date is nil' do let(:duo_chat_cut_off_date) { nil } - around do |example| - travel_to(before_code_suggestions_start_date) do - example.run - end - end - it 'renders AI Beta features toggle' do render expect(rendered).to have_field('application_setting_instance_level_ai_beta_features_enabled') @@ -321,29 +240,21 @@ end end - # Tests specific license-related UI change that happens on the Code Suggestions service start date: - # (internal) https://gitlab.com/gitlab-org/gitlab/-/issues/425047#note_1673643291 - # TODO: clean-up after the Code Suggestions service start date (16.9+) describe 'entire instance-level ai-powered menu section visibility', feature_category: :duo_chat do - where(:current_date, :ai_chat_available, :code_suggestions_available, :expect_section_is_visible) do - ref(:before_code_suggestions_start_date) | false | false | false - ref(:before_code_suggestions_start_date) | false | true | true - ref(:before_code_suggestions_start_date) | true | false | true - ref(:before_code_suggestions_start_date) | true | true | true - ref(:after_code_suggestions_start_date) | false | false | false - ref(:after_code_suggestions_start_date) | false | true | false - ref(:after_code_suggestions_start_date) | true | false | true - ref(:after_code_suggestions_start_date) | true | true | true - ref(:after_duo_chat_cut_off_date) | false | false | false - ref(:after_duo_chat_cut_off_date) | false | true | false - ref(:after_duo_chat_cut_off_date) | true | false | false - ref(:after_duo_chat_cut_off_date) | true | true | false + let(:before_duo_chat_cut_off_date) { duo_chat_cut_off_date - 1.second } + let(:after_duo_chat_cut_off_date) { duo_chat_cut_off_date + 1.second } + + where(:current_date, :ai_chat_available, :expect_section_is_visible) do + ref(:before_duo_chat_cut_off_date) | false | false + ref(:before_duo_chat_cut_off_date) | true | true + ref(:after_duo_chat_cut_off_date) | false | false + ref(:after_duo_chat_cut_off_date) | true | false end with_them do it 'sets entire ai-powered menu section visibility correctly' do allow(::Gitlab).to receive(:org_or_com?).and_return(false) - stub_licensed_features(ai_chat: ai_chat_available, code_suggestions: code_suggestions_available) + stub_licensed_features(ai_chat: ai_chat_available) travel_to(current_date) do render diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 543016289b9d5a8d6d3875975c8495105badba7a..f83498d8c4b036d2742b831cb8a59a9eeb39de84 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -12138,12 +12138,6 @@ msgstr "" msgid "CodeSuggestionsGAAlert|Dismiss Code Suggestions banner" msgstr "" -msgid "CodeSuggestionsSM|Code Suggestions" -msgstr "" - -msgid "CodeSuggestionsSM|Enable Code Suggestions for this instance" -msgstr "" - msgid "CodeSuggestions|%{linkStart}Code Suggestions%{linkEnd} uses generative AI to suggest code while you're developing." msgstr ""