From 5be9353de85fb37b74103f07dd153f714186d6da Mon Sep 17 00:00:00 2001
From: David Dieulivol <ddieulivol@gitlab.com>
Date: Mon, 11 Mar 2024 10:19:50 +0000
Subject: [PATCH] Ensure detect-tests logic does not use the ActiveSupport gem

---
 .gitlab/ci/setup.gitlab-ci.yml                |  3 +--
 .../js_to_system_specs_mappings_spec.rb       |  3 ++-
 .../mappings/graphql_base_type_mappings.rb    |  9 ++++++---
 .../mappings/js_to_system_specs_mappings.rb   | 19 ++++++++++++++++---
 4 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/.gitlab/ci/setup.gitlab-ci.yml b/.gitlab/ci/setup.gitlab-ci.yml
index e2e9508200154..d37b804a40e65 100644
--- a/.gitlab/ci/setup.gitlab-ci.yml
+++ b/.gitlab/ci/setup.gitlab-ci.yml
@@ -120,13 +120,12 @@ detect-tests:
   variables:
     RSPEC_TESTS_MAPPING_ENABLED: "true"
   before_script:
-    - apt-get update && apt-get install -y curl make gcc # Not present in ruby-slim, so we add it manually
+    - apt update && apt install -y curl
   script:
     - source ./scripts/utils.sh
     - source ./scripts/rspec_helpers.sh
     - install_gitlab_gem
     - install_tff_gem
-    - install_activesupport_gem
     - retrieve_tests_mapping
     - retrieve_frontend_fixtures_mapping
     - |
diff --git a/spec/tooling/lib/tooling/mappings/js_to_system_specs_mappings_spec.rb b/spec/tooling/lib/tooling/mappings/js_to_system_specs_mappings_spec.rb
index e1f35bedebbe2..b04956b09cada 100644
--- a/spec/tooling/lib/tooling/mappings/js_to_system_specs_mappings_spec.rb
+++ b/spec/tooling/lib/tooling/mappings/js_to_system_specs_mappings_spec.rb
@@ -156,11 +156,12 @@
       %w[
         app/assets/javascripts/boards/issue_board_filters.js
         ee/app/assets/javascripts/queries/epic_due_date.query.graphql
+        app/assets/javascripts/protected_branches/constants.js
       ]
     end
 
     it 'returns a singularized keyword based on the first folder the file is in' do
-      expect(subject).to eq(%w[board query])
+      expect(subject).to eq(%w[board query protected_branch])
     end
 
     context 'when the files are under the pages folder' do
diff --git a/tooling/lib/tooling/mappings/graphql_base_type_mappings.rb b/tooling/lib/tooling/mappings/graphql_base_type_mappings.rb
index 80aa99efc9639..c18d90fe97c1b 100644
--- a/tooling/lib/tooling/mappings/graphql_base_type_mappings.rb
+++ b/tooling/lib/tooling/mappings/graphql_base_type_mappings.rb
@@ -1,7 +1,5 @@
 # frozen_string_literal: true
 
-require 'active_support/inflector'
-
 require_relative '../helpers/predictive_tests_helper'
 require_relative '../../../../lib/gitlab_edition'
 
@@ -104,7 +102,12 @@ def types_hierarchies
       end
 
       def filename_to_class_name(filename)
-        File.basename(filename, '.*').camelize
+        camelize(File.basename(filename, '.*'))
+      end
+
+      # We don't want to use active_support for this method, so we're making it ourselves
+      def camelize(str)
+        str.split('_').collect(&:capitalize).join
       end
 
       def filename_to_spec_filename(filename)
diff --git a/tooling/lib/tooling/mappings/js_to_system_specs_mappings.rb b/tooling/lib/tooling/mappings/js_to_system_specs_mappings.rb
index bc2cd259fdcca..01c0ae4dfa6fb 100644
--- a/tooling/lib/tooling/mappings/js_to_system_specs_mappings.rb
+++ b/tooling/lib/tooling/mappings/js_to_system_specs_mappings.rb
@@ -1,7 +1,5 @@
 # frozen_string_literal: true
 
-require 'active_support/inflector'
-
 require_relative '../helpers/predictive_tests_helper'
 require_relative '../../../../lib/gitlab_edition'
 
@@ -56,10 +54,25 @@ def filter_files
       def construct_js_keywords(js_files)
         js_files.map do |js_file|
           filename = js_file.scan(@first_js_folder_extract_regexp).flatten.first
-          filename.singularize
+          singularize(filename)
         end.uniq
       end
 
+      # We don't want to use active_support for this method, and our singularization cases
+      # are much simpler than what the active_support method would need.
+      def singularize(string)
+        if string.end_with?('ies')
+          string.sub(/ies$/, 'y')
+        # e.g. branches -> branch, protected branches -> protected branch
+        elsif string.end_with?('hes')
+          string.sub(/hes$/, 'h')
+        elsif string.end_with?('s')
+          string.sub(/s$/, '')
+        else
+          string
+        end
+      end
+
       def system_specs_for_edition(edition)
         all_files_in_folders_glob = File.join(@system_specs_base_folder, '**', '*')
         all_files_in_folders_glob = File.join(edition, all_files_in_folders_glob) if edition
-- 
GitLab