Skip to content
代码片段 群组 项目
未验证 提交 f6b152a2 编辑于 作者: Alexandru Croitor's avatar Alexandru Croitor 提交者: GitLab
浏览文件

Merge branch 'fix-tests-for-cutoff' into 'master'

Fix chat tests that will fail after the cutoff free use of Duo

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/168230



Merged-by: default avatarAlexandru Croitor <acroitor@gitlab.com>
Approved-by: default avatarLesley Razzaghian <lrazzaghian@gitlab.com>
Approved-by: default avatarAlexandru Croitor <acroitor@gitlab.com>
Reviewed-by: default avatarTetiana Chupryna <tchupryna@gitlab.com>
Reviewed-by: default avatarAlexandru Croitor <acroitor@gitlab.com>
Co-authored-by: default avatarTetiana Chupryna <tchupryna@gitlab.com>
No related branches found
No related tags found
无相关合并请求
显示
125 个添加8 个删除
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
RSpec.describe 'Root cause analysis job page', :saas, :js, feature_category: :continuous_integration do RSpec.describe 'Root cause analysis job page', :saas, :js, feature_category: :continuous_integration do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:namespace) { create(:group_with_plan, plan: :ultimate_plan, owners: user) } let(:group) { create(:group_with_plan, plan: :ultimate_plan, owners: user) }
let(:project) { create(:project, :repository, namespace: namespace) } let(:project) { create(:project, :repository, namespace: group) }
let(:passed_job) { create(:ci_build, :success, :trace_live, project: project) } let(:passed_job) { create(:ci_build, :success, :trace_live, project: project) }
let(:failed_job) { create(:ci_build, :failed, :trace_live, project: project) } let(:failed_job) { create(:ci_build, :failed, :trace_live, project: project) }
...@@ -17,9 +17,7 @@ ...@@ -17,9 +17,7 @@
end end
context 'with duo enterprise license' do context 'with duo enterprise license' do
before do include_context 'with duo enterprise addon'
create(:gitlab_subscription_add_on_purchase, :duo_enterprise, namespace: namespace)
end
context 'with failed jobs' do context 'with failed jobs' do
before do before do
......
...@@ -72,6 +72,8 @@ ...@@ -72,6 +72,8 @@
end end
context "when user can use AI to explain vulnerability" do context "when user can use AI to explain vulnerability" do
include_context "with duo enterprise addon"
before do before do
allow(Gitlab).to receive(:org_or_com?).and_return(true) allow(Gitlab).to receive(:org_or_com?).and_return(true)
stub_licensed_features( stub_licensed_features(
...@@ -114,6 +116,8 @@ ...@@ -114,6 +116,8 @@
end end
context "when the vulnerability type does not support AI actions" do context "when the vulnerability type does not support AI actions" do
include_context "with duo enterprise addon"
before do before do
finding.update!(report_type: 'dast') finding.update!(report_type: 'dast')
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
agent_version: instance_double(Ai::AgentVersion), additional_context: additional_context) agent_version: instance_double(Ai::AgentVersion), additional_context: additional_context)
end end
include_context 'with duo pro addon'
before_all do before_all do
group.add_reporter(user) group.add_reporter(user)
end end
......
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
let_it_be_with_reload(:group) { create(:group_with_plan, plan: :ultimate_plan) } let_it_be_with_reload(:group) { create(:group_with_plan, plan: :ultimate_plan) }
let_it_be_with_reload(:project) { create(:project, :public, :repository, group: group) } let_it_be_with_reload(:project) { create(:project, :public, :repository, group: group) }
include_context 'with duo pro addon'
before_all do before_all do
group.add_developer(user) group.add_developer(user)
end end
......
...@@ -56,6 +56,8 @@ ...@@ -56,6 +56,8 @@
# we need project for Gitlab::ReferenceExtractor # we need project for Gitlab::ReferenceExtractor
let_it_be(:project) { create(:project, group: group) } let_it_be(:project) { create(:project, group: group) }
include_context "with duo pro addon"
before do before do
stub_const("::Gitlab::Llm::Chain::Tools::IssueReader::Prompts::Anthropic::MAX_CHARACTERS", stub_const("::Gitlab::Llm::Chain::Tools::IssueReader::Prompts::Anthropic::MAX_CHARACTERS",
999999) 999999)
......
...@@ -84,6 +84,8 @@ ...@@ -84,6 +84,8 @@
end end
context 'when user has permission to read resource' do context 'when user has permission to read resource' do
include_context 'with duo pro addon'
before do before do
stub_application_setting(check_namespace_plan: true) stub_application_setting(check_namespace_plan: true)
stub_licensed_features(ai_chat: true) stub_licensed_features(ai_chat: true)
......
...@@ -52,6 +52,8 @@ ...@@ -52,6 +52,8 @@
let_it_be_with_reload(:group) { create(:group_with_plan, plan: :ultimate_plan) } let_it_be_with_reload(:group) { create(:group_with_plan, plan: :ultimate_plan) }
let_it_be_with_reload(:project) { create(:project, group: group) } let_it_be_with_reload(:project) { create(:project, group: group) }
include_context "with duo pro addon"
before_all do before_all do
project.add_developer(user) project.add_developer(user)
end end
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
end end
end end
include_context 'with duo pro addon'
context 'for saas', :saas do context 'for saas', :saas do
let_it_be(:group) { create(:group_with_plan, :public, plan: :ultimate_plan) } let_it_be(:group) { create(:group_with_plan, :public, plan: :ultimate_plan) }
let_it_be_with_reload(:project) { create(:project, group: group) } let_it_be_with_reload(:project) { create(:project, group: group) }
...@@ -277,10 +279,13 @@ ...@@ -277,10 +279,13 @@
context 'when resource is current user' do context 'when resource is current user' do
context 'when user is not in any group with ai' do context 'when user is not in any group with ai' do
let(:current_user) { create(:user) } # we use 'with duo pro addon' that will assign a seat in addon for
# `current_user` or `user` if this variable is defined
# that's why we need to use here a variable with a different name
let(:new_user) { create(:user) }
it 'returns false' do it 'returns false' do
expect(authorizer.resource(resource: current_user, user: current_user).allowed?) expect(authorizer.resource(resource: new_user, user: new_user).allowed?)
.to be(false) .to be(false)
end end
end end
......
...@@ -93,7 +93,19 @@ ...@@ -93,7 +93,19 @@
group_without_experiment_features_enabled.add_guest(user) group_without_experiment_features_enabled.add_guest(user)
end end
include_context 'with ai features enabled for group' # TODO: Change to use context 'with ai features enabled for group'
# Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/497781
before do
allow(Gitlab).to receive(:org_or_com?).and_return(true)
stub_ee_application_setting(should_check_namespace_plan: true)
allow(group.namespace_settings).to receive(:experiment_settings_allowed?).and_return(true)
stub_licensed_features(
ai_features: true,
glab_ask_git_command: true,
generate_description: true
)
group.namespace_settings.reload.update!(experiment_features_enabled: true)
end
shared_examples 'checking available groups' do shared_examples 'checking available groups' do
it { is_expected.to be true } it { is_expected.to be true }
......
...@@ -126,6 +126,12 @@ ...@@ -126,6 +126,12 @@
context 'when user is not logged in' do context 'when user is not logged in' do
let(:current_user) { nil } let(:current_user) { nil }
# we are trying to authenticate with a token of `authorized_user`
# we need to define variable `user` so included context
# 'with ai features enabled for group' will
# enroll `authorized_user` to Duo Pro addon
# and that is a requirement for successful authorization
let(:user) { authorized_user }
include_examples 'an unauthorized response' include_examples 'an unauthorized response'
......
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_context 'with ai features enabled for group' do RSpec.shared_context 'with ai features enabled for group' do
include_context 'with duo pro addon'
before do before do
allow(Gitlab).to receive(:org_or_com?).and_return(true) allow(Gitlab).to receive(:org_or_com?).and_return(true)
stub_ee_application_setting(should_check_namespace_plan: true) stub_ee_application_setting(should_check_namespace_plan: true)
...@@ -15,6 +17,8 @@ ...@@ -15,6 +17,8 @@
end end
RSpec.shared_context 'with experiment features disabled for group' do RSpec.shared_context 'with experiment features disabled for group' do
include_context 'with duo pro addon'
before do before do
allow(Gitlab).to receive(:org_or_com?).and_return(true) allow(Gitlab).to receive(:org_or_com?).and_return(true)
stub_ee_application_setting(should_check_namespace_plan: true) stub_ee_application_setting(should_check_namespace_plan: true)
...@@ -29,6 +33,8 @@ ...@@ -29,6 +33,8 @@
end end
RSpec.shared_context 'with duo features enabled and ai chat available for self-managed' do RSpec.shared_context 'with duo features enabled and ai chat available for self-managed' do
include_context 'with duo pro addon'
before do before do
allow(Gitlab).to receive(:org_or_com?).and_return(false) allow(Gitlab).to receive(:org_or_com?).and_return(false)
stub_application_setting(duo_features_enabled: true) stub_application_setting(duo_features_enabled: true)
...@@ -37,6 +43,8 @@ ...@@ -37,6 +43,8 @@
end end
RSpec.shared_context 'with duo features enabled and ai chat not available for self-managed' do RSpec.shared_context 'with duo features enabled and ai chat not available for self-managed' do
include_context 'with duo pro addon'
before do before do
allow(Gitlab).to receive(:org_or_com?).and_return(false) allow(Gitlab).to receive(:org_or_com?).and_return(false)
stub_application_setting(duo_features_enabled: true) stub_application_setting(duo_features_enabled: true)
...@@ -45,6 +53,8 @@ ...@@ -45,6 +53,8 @@
end end
RSpec.shared_context 'with duo features disabled and ai chat available for self-managed' do RSpec.shared_context 'with duo features disabled and ai chat available for self-managed' do
include_context 'with duo pro addon'
before do before do
allow(Gitlab).to receive(:org_or_com?).and_return(false) allow(Gitlab).to receive(:org_or_com?).and_return(false)
stub_application_setting(duo_features_enabled: false) stub_application_setting(duo_features_enabled: false)
...@@ -53,6 +63,8 @@ ...@@ -53,6 +63,8 @@
end end
RSpec.shared_context 'with duo features enabled and ai chat available for group on SaaS' do RSpec.shared_context 'with duo features enabled and ai chat available for group on SaaS' do
include_context 'with duo pro addon'
before do before do
allow(Gitlab).to receive(:org_or_com?).and_return(true) allow(Gitlab).to receive(:org_or_com?).and_return(true)
stub_ee_application_setting(should_check_namespace_plan: true) stub_ee_application_setting(should_check_namespace_plan: true)
...@@ -62,6 +74,8 @@ ...@@ -62,6 +74,8 @@
end end
RSpec.shared_context 'with duo features enabled and ai chat not available for group on SaaS' do RSpec.shared_context 'with duo features enabled and ai chat not available for group on SaaS' do
include_context 'with duo pro addon'
before do before do
allow(Gitlab).to receive(:org_or_com?).and_return(true) allow(Gitlab).to receive(:org_or_com?).and_return(true)
stub_ee_application_setting(should_check_namespace_plan: true) stub_ee_application_setting(should_check_namespace_plan: true)
...@@ -71,6 +85,8 @@ ...@@ -71,6 +85,8 @@
end end
RSpec.shared_context 'with duo features disabled and ai chat available for group on SaaS' do RSpec.shared_context 'with duo features disabled and ai chat available for group on SaaS' do
include_context 'with duo pro addon'
before do before do
allow(Gitlab).to receive(:org_or_com?).and_return(true) allow(Gitlab).to receive(:org_or_com?).and_return(true)
stub_ee_application_setting(should_check_namespace_plan: true) stub_ee_application_setting(should_check_namespace_plan: true)
...@@ -78,3 +94,69 @@ ...@@ -78,3 +94,69 @@
group.namespace_settings.reload.update!(duo_features_enabled: false) group.namespace_settings.reload.update!(duo_features_enabled: false)
end end
end end
RSpec.shared_context 'with duo pro addon' do
# To accommodate existing specs that use this config
# this helper assign seat in an addon for both
# current_user or user depends on which one is defined
before do
the_user = if defined?(current_user) && current_user.present?
current_user
elsif defined?(user) && user.present?
user
else
false
end
if the_user
# As this context could be included in tests multiple times,
# we first search by active purchases and are trying to not create
# entities twice because it will cause an ActiveRecord error in tests
active_purchase = GitlabSubscriptions::AddOnPurchase.find_by(namespace: group)
active_purchase ||= create(:gitlab_subscription_add_on_purchase, :gitlab_duo_pro, namespace: group)
active_assignment = GitlabSubscriptions::UserAddOnAssignment.find_by(
user: the_user, add_on_purchase: active_purchase)
unless active_assignment
create(
:gitlab_subscription_user_add_on_assignment,
user: the_user,
add_on_purchase: active_purchase
)
end
end
end
end
# This context is the same as the one for Duo Pro
# only difference is the purchased addon
RSpec.shared_context 'with duo enterprise addon' do
before do
the_user = if defined?(current_user) && current_user.present?
current_user
elsif defined?(user) && user.present?
user
else
false
end
if the_user
active_purchase = GitlabSubscriptions::AddOnPurchase.find_by(namespace: group)
active_purchase ||= create(:gitlab_subscription_add_on_purchase, :duo_enterprise, namespace: group)
active_assignment = GitlabSubscriptions::UserAddOnAssignment.find_by(
user: the_user, add_on_purchase: active_purchase)
unless active_assignment
create(
:gitlab_subscription_user_add_on_assignment,
user: the_user,
add_on_purchase: active_purchase
)
end
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册