diff --git a/.gitlab/ci/audit_event_types.gitlab-ci.yml b/.gitlab/ci/audit_event_types.gitlab-ci.yml deleted file mode 100644 index f079a3b55e19ae1e691dae37bcd7b8deafa8e44f..0000000000000000000000000000000000000000 --- a/.gitlab/ci/audit_event_types.gitlab-ci.yml +++ /dev/null @@ -1,12 +0,0 @@ -audit-event-types-verify: - variables: - SETUP_DB: "false" - extends: - - .default-retry - - .ruby-cache - - .default-before_script - - .audit-event-types:rules:audit-event-types-verify - stage: lint - needs: [] - script: - - bundle exec rake gitlab:audit_event_types:check_docs diff --git a/.gitlab/ci/rules.gitlab-ci.yml b/.gitlab/ci/rules.gitlab-ci.yml index f043c88bb5d69e890b282676f5faf2e5317fb379..b0332025338beafac0208b0387303544defbb7f3 100644 --- a/.gitlab/ci/rules.gitlab-ci.yml +++ b/.gitlab/ci/rules.gitlab-ci.yml @@ -444,7 +444,6 @@ - "{,ee/,jh/}{app,bin,config,db,elastic,generator_templates,gems,haml_lint,lib,locale,public,scripts,storybook,symbol,vendor}/**/*" # Auto-generated files - "doc/api/graphql/reference/*" - - "doc/administration/audit_event_types.md" # CI changes - ".gitlab-ci.yml" - ".gitlab/ci/**/*" @@ -470,7 +469,6 @@ - "{,ee/,jh/}{app,bin,config,db,elastic,generator_templates,gems,haml_lint,lib,locale,public,scripts,storybook,symbol,vendor}/**/*" # Auto-generated files - "doc/api/graphql/reference/*" - - "doc/administration/audit_event_types.md" # CI changes - ".gitlab-ci.yml" - ".gitlab/ci/**/*" @@ -503,7 +501,6 @@ - "{,ee/,jh/}{app,bin,config,db,elastic,generator_templates,gems,haml_lint,lib,locale,public,scripts,storybook,symbol,vendor}/**/*" # Auto-generated files - "doc/api/graphql/reference/*" - - "doc/administration/audit_event_types.md" # CI changes - ".gitlab-ci.yml" - ".gitlab/ci/**/*" @@ -533,7 +530,6 @@ - "{,ee/,jh/}{app,bin,config,db,elastic,generator_templates,gems,haml_lint,lib,locale,public,scripts,storybook,symbol,vendor}/**/*" # Auto-generated files - "doc/api/graphql/reference/*" - - "doc/administration/audit_event_types.md" # CI changes - ".gitlab-ci.yml" - ".gitlab/ci/**/*" @@ -572,7 +568,6 @@ - "{,ee/,jh/}{app,bin,config,db,elastic,generator_templates,gems,haml_lint,lib,locale,public,scripts,storybook,symbol,vendor}/**/*" # Auto-generated files - "doc/api/graphql/reference/*" - - "doc/administration/audit_event_types.md" # CI changes - ".gitlab-ci.yml" - ".gitlab/ci/**/*" @@ -651,6 +646,11 @@ - GITLAB_SHELL_VERSION - GITALY_SERVER_VERSION +.audit-events-patterns: &audit-events-patterns + - "{,ee/}config/audit_events/types/*.yml" + - "doc/administration/audit_event_types.md" + - "tooling/audit_events/docs/templates/audit_event_types.md.erb" + ################## # Conditions set # ################## @@ -1191,7 +1191,7 @@ - <<: *if-not-ee when: never - <<: *if-default-refs - changes: *code-backstage-qa-patterns + changes: *audit-events-patterns ################## # Frontend rules # diff --git a/.gitlab/ci/static-analysis.gitlab-ci.yml b/.gitlab/ci/static-analysis.gitlab-ci.yml index cce0beaa5cdebe67ea2b4a49e5496bef8410d372..b57fadee49eff9101e2e64ac8797194f5bde4090 100644 --- a/.gitlab/ci/static-analysis.gitlab-ci.yml +++ b/.gitlab/ci/static-analysis.gitlab-ci.yml @@ -187,6 +187,19 @@ semgrep-appsec-custom-rules: paths: - gl-sast-report.json +audit-event-types-verify: + variables: + SETUP_DB: "false" + extends: + - .default-retry + - .ruby-cache + - .default-before_script + - .audit-event-types:rules:audit-event-types-verify + stage: lint + needs: [] + script: + - bundle exec rake gitlab:audit_event_types:check_docs + ping-appsec-for-sast-findings: stage: lint image: alpine:latest diff --git a/ee/lib/gitlab/llm/anthropic/completions/categorize_question.rb b/ee/lib/gitlab/llm/anthropic/completions/categorize_question.rb index a38061d497155ecc324d2a49f2d9e2462c71c1c9..d5e0786b01d89a1a919fa6e8f9abfc80a4d3e130 100644 --- a/ee/lib/gitlab/llm/anthropic/completions/categorize_question.rb +++ b/ee/lib/gitlab/llm/anthropic/completions/categorize_question.rb @@ -6,6 +6,7 @@ module Anthropic module Completions class CategorizeQuestion < Gitlab::Llm::Completions::Base SCHEMA_URL = 'iglu:com.gitlab/ai_question_category/jsonschema/1-2-0' + OUTPUT_TOKEN_LIMIT = 200 private_class_method def self.load_xml(filename) File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', filename)).tr("\n", '') @@ -41,6 +42,7 @@ def execute def request(template) @ai_client.complete( + max_tokens_to_sample: OUTPUT_TOKEN_LIMIT, prompt: template.to_prompt )&.dig("completion").to_s.strip end diff --git a/ee/lib/gitlab/llm/templates/categorize_question.rb b/ee/lib/gitlab/llm/templates/categorize_question.rb index 2b6c7bc14fa5e298ba5a132dd0ed4f8991c090ec..98a3a50d5298b2efefac5029846a279c5e89c084 100644 --- a/ee/lib/gitlab/llm/templates/categorize_question.rb +++ b/ee/lib/gitlab/llm/templates/categorize_question.rb @@ -7,7 +7,7 @@ class CategorizeQuestion include Gitlab::Utils::StrongMemoize PROMPT = <<~PROMPT - \n\nHuman: You are helpful assistant, ready to give as accurate answer as possible in JSON format. + \n\nHuman: You are helpful assistant, ready to give as accurate answer as possible, in JSON format (i.e. starts with "{" and ends with "}"). Based on the information below (user input, categories, labels, language, %<previous_answer_prefix>s), classify user input's category, detailed_category, labels. There may be multiple labels. Don't provide clarification or explanation. Always return only a JSON hash, e.g.: <example>{"category": "Write, improve, or explain code", "detailed_category": "What are the potential security risks in this code?", "labels": ["contains_credentials", "contains_rejection_previous_answer_incorrect"], "language": "en"}</example> diff --git a/ee/spec/lib/gitlab/llm/anthropic/completions/categorize_question_spec.rb b/ee/spec/lib/gitlab/llm/anthropic/completions/categorize_question_spec.rb index 2e4190e8da6fe3008ed1bc9911d6d6424cd1c7a3..5f2602f5245c1c52aa3c3827c6771154aa4a5c95 100644 --- a/ee/spec/lib/gitlab/llm/anthropic/completions/categorize_question_spec.rb +++ b/ee/spec/lib/gitlab/llm/anthropic/completions/categorize_question_spec.rb @@ -38,7 +38,7 @@ allow(template).to receive(:to_prompt).and_return(prompt) end allow_next_instance_of(::Gitlab::Llm::Anthropic::Client) do |ai_client| - allow(ai_client).to receive(:complete).with(prompt: prompt).and_return(response) + allow(ai_client).to receive(:complete).with(prompt: prompt, max_tokens_to_sample: 200).and_return(response) end allow_next_instance_of(::Gitlab::Llm::ChatStorage, user) do |storage| allow(storage).to receive(:messages_up_to).with(chat_message.id).and_return(messages) diff --git a/lefthook.yml b/lefthook.yml index b248768f82fc93f5c8074dbbd3af452e87e224c4..f5f2597e5bbb733de846d7b90b07755544ac2935 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -51,7 +51,7 @@ pre-push: graphql_docs: tags: documentation files: git diff --name-only --diff-filter=d $(git merge-base origin/master HEAD)..HEAD - glob: '{app/graphql/**/*.rb,ee/app/graphql/**/*.rb}' + glob: '{,ee/}app/graphql/**/*.rb' run: bundle exec rake gitlab:graphql:check_docs vale: # Requires Vale: https://docs.gitlab.com/ee/development/documentation/testing.html#install-linters tags: documentation style @@ -103,7 +103,7 @@ pre-push: audit_event_types_docs: tags: documentation files: git diff --name-only --diff-filter=d $(git merge-base origin/master HEAD)..HEAD - glob: '{config/audit_events/types/*.yml,ee/config/audit_events/types/*yml,doc/administration/audit_event_streaming/audit_event_types.md}' + glob: '{config/audit_events/types/*.yml,ee/config/audit_events/types/*yml,doc/administration/audit_event_types.md,tooling/audit_events/docs/templates/audit_event_types.md.erb}' run: bundle exec rake gitlab:audit_event_types:check_docs rubocop: tags: backend style