Skip to content
Snippets Groups Projects

Change the unit primitive for troubleshoot job

Merged Allison Browne requested to merge ab-rca-unit-primitive into master
All threads resolved!
1 file
+ 0
110
Compare changes
  • Side-by-side
  • Inline
@@ -513,114 +513,4 @@
it { expect_disallowed(:create_build_terminal) }
end
end
describe 'troubleshoot_job_with_ai' do
subject { described_class.new(user, build) }
let(:project) { create(:project, :private) }
let(:authorized) { true }
let(:cloud_connector_free_access) { true }
let(:cloud_connector_user_access) { true }
before do
project.add_maintainer(user)
stub_licensed_features(ai_features: true, troubleshoot_job: true)
allow(::Gitlab::Llm::Chain::Utils::ChatAuthorizer).to receive_message_chain(
:resource, :allowed?).and_return(authorized)
allow(user).to receive(:can?).with(:admin_all_resources).and_call_original
allow(::Gitlab::Llm::StageCheck).to receive(:available?).and_return(true)
allow(user).to receive(:can?).with(:access_duo_chat).and_return(true)
allow(user).to receive(:can?).with(:access_duo_features, build.project).and_return(true)
allow(::CloudConnector::AvailableServices).to receive(:find_by_name).with(:troubleshoot_job).and_return(
instance_double(
CloudConnector::BaseAvailableServiceData,
free_access?: cloud_connector_free_access,
allowed_for?: cloud_connector_user_access
)
)
end
context 'when feature is chat authorized' do
subject { described_class.new(user, build) }
let(:authorized) { true }
it { is_expected.to be_allowed(:troubleshoot_job_with_ai) }
context 'when user cannot read_build' do
include_context 'public pipelines disabled'
before do
project.add_guest(user)
end
it { is_expected.to be_disallowed(:troubleshoot_job_with_ai) }
end
context 'when the feature is not ai licensed' do
before do
stub_licensed_features(ai_features: false)
end
it { is_expected.to be_disallowed(:troubleshoot_job_with_ai) }
end
context 'when feature is not licensed' do
before do
stub_licensed_features(troubleshoot_job: false)
end
it { is_expected.to be_disallowed(:troubleshoot_job_with_ai) }
end
end
context 'when feature is not authorized' do
let(:authorized) { false }
it { is_expected.to be_disallowed(:troubleshoot_job_with_ai) }
end
# TODO: remove these tests when implementing https://gitlab.com/gitlab-org/gitlab/-/issues/473087
describe 'cloud connector' do
using RSpec::Parameterized::TableSyntax
where(:free_access, :user_access, :allowed) do
true | true | true
true | false | true
false | true | true
false | false | false
end
with_them do
let(:cloud_connector_free_access) { free_access }
let(:cloud_connector_user_access) { user_access }
let(:policy) { :troubleshoot_job_with_ai }
it { is_expected.to(allowed ? be_allowed(policy) : be_disallowed(policy)) }
end
end
context 'when on .org or .com', :saas do
using RSpec::Parameterized::TableSyntax
where(:group_with_ai_membership, :free_access, :user_access, :allowed) do
true | true | true | true
true | false | true | true
false | false | true | true
false | false | false | false
true | true | false | true
false | true | false | false
end
with_them do
before do
allow(user).to receive(:any_group_with_ai_available?).and_return(group_with_ai_membership)
end
let(:cloud_connector_free_access) { free_access }
let(:cloud_connector_user_access) { user_access }
let(:policy) { :troubleshoot_job_with_ai }
it { is_expected.to(allowed ? be_allowed(policy) : be_disallowed(policy)) }
end
end
end
end
Loading