From 5b274a0f82aeb2f61e959e240ddbc8bcf1e675dd Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Sun, 15 Sep 2024 04:09:58 -0500 Subject: [PATCH 01/42] Update Caseflow-Commons for Zeitwerk --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 20b39d724..fc470f20a 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,7 @@ gem "aws-sdk-s3" gem "aws-sdk-sqs" gem "bgs", git: "https://github.com/department-of-veterans-affairs/ruby-bgs.git", ref: "a2e055b5a52bd1e2bb8c2b3b8d5820b1a404cd3d" gem "bootsnap", require: false -gem "caseflow", git: "https://github.com/department-of-veterans-affairs/caseflow-commons", ref: "9bd3635fbd8094d25160669f38d8699e2f1d7a98" +gem "caseflow", git: "https://github.com/department-of-veterans-affairs/caseflow-commons", branch: "AlecK/Zeitwerk" # ref: "9bd3635fbd8094d25160669f38d8699e2f1d7a98" gem "coffee-rails", "> 4.1.0" gem "connect_vbms", git: "https://github.com/department-of-veterans-affairs/connect_vbms.git", branch: "master" gem "connect_vva", git: "https://github.com/department-of-veterans-affairs/connect_vva.git", ref: "dfd1aeb2605c1f237f520bcdc41b059202e8944d" diff --git a/Gemfile.lock b/Gemfile.lock index 923449742..104d1ad26 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,8 +20,8 @@ GIT GIT remote: https://github.com/department-of-veterans-affairs/caseflow-commons - revision: 9bd3635fbd8094d25160669f38d8699e2f1d7a98 - ref: 9bd3635fbd8094d25160669f38d8699e2f1d7a98 + revision: 298c0a10c67920ad98251c0a9f3bd37abf408c35 + branch: AlecK/Zeitwerk specs: caseflow (0.4.8) aws-sdk-s3 From 4a66c1dd019795a9799ddeae6d210468d821346a Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Sun, 15 Sep 2024 04:26:17 -0500 Subject: [PATCH 02/42] Remove classic loading, added Zeitwerk loading options --- config/application.rb | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/config/application.rb b/config/application.rb index 25f1bd0f3..bc52e39f1 100644 --- a/config/application.rb +++ b/config/application.rb @@ -10,7 +10,6 @@ module CaseflowEfolder class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 6.1 - config.autoloader = :classic # Configuration for the application, engines, and railties goes here. # @@ -122,9 +121,30 @@ class Application < Rails::Application # eFolder Specific configs #--------------------------------------------------------------------------------------- config.download_filepath = Rails.root + "tmp/files" - config.autoload_paths += Dir[Rails.root + 'app/jobs'] - config.autoload_paths << Rails.root.join('lib') - config.autoload_paths << Rails.root.join('lib/scripts') + + config.autoload_paths += [ + "#{root}/lib", + ] + + config.eager_load_paths += [ + "#{root}/lib", + ] + + # A collapse statement will remove the need for a namespace based on the direcotry given. + # Tasks::Support::ModuleOrClassName becomes ModuleOrClassName with the below statements. + Rails.autoloaders.main.collapse( + "app/jobs/middleware", + "#{root}/lib/tasks", + "#{root}/lib/tasks/support" + ) + + Rails.autoloaders.main.ignore( + "#{root}/lib/assets", + "#{root}/lib/pdfs", + "#{root}/lib/scripts" + ) + + # Currently the Caseflow client makes calls to get document content directly # from eFolder Express to reduce load on Caseflow. Since Caseflow and eFolder From 6918c9c6b25cab94af6772e226feca31b2355a88 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Sun, 15 Sep 2024 04:46:14 -0500 Subject: [PATCH 03/42] Added to_prepare's - Solves DW on autoloading initialized constants --- config/initializers/bgs.rb | 4 +- .../initializers/ruby_claim_evidence_api.rb | 6 ++- config/initializers/s3.rb | 4 +- config/initializers/shoryuken.rb | 43 ++++++++++--------- config/initializers/vbms.rb | 4 +- config/initializers/vva.rb | 4 +- 6 files changed, 39 insertions(+), 26 deletions(-) diff --git a/config/initializers/bgs.rb b/config/initializers/bgs.rb index da7707d1d..1c12184ef 100644 --- a/config/initializers/bgs.rb +++ b/config/initializers/bgs.rb @@ -1 +1,3 @@ -BGSService = (!BaseController.dependencies_faked? ? ExternalApi::BGSService : Fakes::BGSService) +Rails.application.reloader.to_prepare do + BGSService = (!BaseController.dependencies_faked? ? ExternalApi::BGSService : Fakes::BGSService) +end diff --git a/config/initializers/ruby_claim_evidence_api.rb b/config/initializers/ruby_claim_evidence_api.rb index b888776da..b7bedf7bf 100644 --- a/config/initializers/ruby_claim_evidence_api.rb +++ b/config/initializers/ruby_claim_evidence_api.rb @@ -1,4 +1,6 @@ # frozen_string_literal: true -VeteranFileFetcher = ExternalApi::VeteranFileFetcher - .new(use_canned_api_responses: BaseController.dependencies_faked_for_CEAPI?, logger: Rails.logger) +Rails.application.reloader.to_prepare do + VeteranFileFetcher = ExternalApi::VeteranFileFetcher + .new(use_canned_api_responses: BaseController.dependencies_faked_for_CEAPI?, logger: Rails.logger) +end diff --git a/config/initializers/s3.rb b/config/initializers/s3.rb index 89160ef81..7ad21e6c1 100644 --- a/config/initializers/s3.rb +++ b/config/initializers/s3.rb @@ -1 +1,3 @@ -S3Service = (Rails.application.config.s3_enabled ? Caseflow::S3Service : Caseflow::Fakes::S3Service) +Rails.application.reloader.to_prepare do + S3Service = (Rails.application.config.s3_enabled ? Caseflow::S3Service : Caseflow::Fakes::S3Service) +end diff --git a/config/initializers/shoryuken.rb b/config/initializers/shoryuken.rb index b508b0c3c..78f1c83e3 100644 --- a/config/initializers/shoryuken.rb +++ b/config/initializers/shoryuken.rb @@ -1,28 +1,31 @@ require "#{Rails.root}/app/jobs/middleware/job_metrics_service_metric_middleware" -# set up default exponential backoff parameters -ActiveJob::QueueAdapters::ShoryukenAdapter::JobWrapper - .shoryuken_options(auto_visibility_timeout: true, - retry_intervals: [5.seconds, 5.minutes, rand(4..8).hours]) -if Rails.application.config.sqs_endpoint - # override the sqs_endpoint - Shoryuken::Client.sqs.config[:endpoint] = URI(Rails.application.config.sqs_endpoint) -end +Rails.application.reloader.to_prepare do + # set up default exponential backoff parameters + ActiveJob::QueueAdapters::ShoryukenAdapter::JobWrapper + .shoryuken_options(auto_visibility_timeout: true, + retry_intervals: [5.seconds, 5.minutes, rand(4..8).hours]) -if Rails.application.config.sqs_create_queues - # create the development queues - Shoryuken::Client.sqs.create_queue(queue_name: ActiveJob::Base.queue_name_prefix + "_low_priority") - Shoryuken::Client.sqs.create_queue(queue_name: ActiveJob::Base.queue_name_prefix + "_med_priority") - Shoryuken::Client.sqs.create_queue(queue_name: ActiveJob::Base.queue_name_prefix + "_high_priority") -end + if Rails.application.config.sqs_endpoint + # override the sqs_endpoint + Shoryuken::Client.sqs.config[:endpoint] = URI(Rails.application.config.sqs_endpoint) + end + + if Rails.application.config.sqs_create_queues + # create the development queues + Shoryuken::Client.sqs.create_queue(queue_name: ActiveJob::Base.queue_name_prefix + "_low_priority") + Shoryuken::Client.sqs.create_queue(queue_name: ActiveJob::Base.queue_name_prefix + "_med_priority") + Shoryuken::Client.sqs.create_queue(queue_name: ActiveJob::Base.queue_name_prefix + "_high_priority") + end -Shoryuken.configure_server do |config| - Rails.logger = Shoryuken::Logging.logger - Rails.logger.level = Logger::INFO + Shoryuken.configure_server do |config| + Rails.logger = Shoryuken::Logging.logger + Rails.logger.level = Logger::INFO - # register all shoryuken middleware - config.server_middleware do |chain| - chain.add JobMetricsServiceMetricMiddleware + # register all shoryuken middleware + config.server_middleware do |chain| + chain.add JobMetricsServiceMetricMiddleware + end end end diff --git a/config/initializers/vbms.rb b/config/initializers/vbms.rb index fe2496de9..7b3e323e1 100644 --- a/config/initializers/vbms.rb +++ b/config/initializers/vbms.rb @@ -1 +1,3 @@ -VBMSService = (!BaseController.dependencies_faked? ? ExternalApi::VBMSService : Fakes::VBMSService) +Rails.application.reloader.to_prepare do + VBMSService = (!BaseController.dependencies_faked? ? ExternalApi::VBMSService : Fakes::VBMSService) +end diff --git a/config/initializers/vva.rb b/config/initializers/vva.rb index bfe115237..82102da02 100644 --- a/config/initializers/vva.rb +++ b/config/initializers/vva.rb @@ -1 +1,3 @@ -VVAService = (!BaseController.dependencies_faked? ? ExternalApi::VVAService : Fakes::VVAService) +Rails.application.reloader.to_prepare do + VVAService = (!BaseController.dependencies_faked? ? ExternalApi::VVAService : Fakes::VVAService) +end From 6d481bf482d37412fd43f4df9afa51c08633f584 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Sun, 15 Sep 2024 11:44:53 -0500 Subject: [PATCH 04/42] Added Zeitwerk initializer file --- config/initializers/zeitwerk.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 config/initializers/zeitwerk.rb diff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rb new file mode 100644 index 000000000..7479fc38c --- /dev/null +++ b/config/initializers/zeitwerk.rb @@ -0,0 +1,33 @@ + +# Zeitwerk has specific requirements for auto/eager loading. See below links for more details +# https://guides.rubyonrails.org/classic_to_zeitwerk_howto.html +# https://github.com/fxn/zeitwerk + +# To sumarize Zeitwerk requires several conditions be met when attempting to auto/eager load +# - The top level namespace must reflect the auto/eager-loadpath / filename. The auto/eager-load +# path will be different from the relative path. See https://github.com/fxn/zeitwerk#file-structure +# - Zeitwerk expects 1 constant per file, anything not under that constant won't be loaded +# - Acronyms aren't implicit. You can use them but you'll need to tell zeitwerk. (More details below) +# - The constant name and file name MUST match, or zeitwerk needs to be told otherwise. +# So file_name.rb should be `module or class FileName` not `FileNames``. +# - Namespaces need to be unique. Depending on the auto/eager-load path, files with the same +# name but located in different directories can cause issues. This also applies to any Gems you have have installed. +# +# +# Use the command and test below to ensure zeitwerk compliance. +# A rspec test has been added for this, you can also check your CI output for details +# bin/rails zeitwerk:check + +# For more info add Rails.autoloaders.log! to your application.rb file +# before running the zeitwerk:check for a breakdown of what zeitwerk is doing. + +Rails.autoloaders.each do |autoloader| + # "file_name" => Expected Module or Class name. + autoloader.inflector.inflect( + "bgs" => "BGS", + "bgs_service" => "BGSService", + "poa_mapper" => "POAMapper", + "vbms_service" => "VBMSService", + "vva_service" => "VVAService" + ) +end \ No newline at end of file From 9ffdb8ba3f0f7d190f5b8f6bc3e5ce599df30263 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Sun, 15 Sep 2024 11:51:36 -0500 Subject: [PATCH 05/42] Refactored bgs_errors.rb and bgs.rb --- app/exceptions/bgs_errors.rb | 8 -------- config/initializers/bgs.rb | 9 +++++++-- config/initializers/bgs_service.rb | 3 +++ 3 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 app/exceptions/bgs_errors.rb create mode 100644 config/initializers/bgs_service.rb diff --git a/app/exceptions/bgs_errors.rb b/app/exceptions/bgs_errors.rb deleted file mode 100644 index a61d1a594..000000000 --- a/app/exceptions/bgs_errors.rb +++ /dev/null @@ -1,8 +0,0 @@ -module BGS - class InvalidUsername < StandardError; end - class InvalidStation < StandardError; end - class InvalidApplication < StandardError; end - class NoActiveStations < StandardError; end - class NoCaseflowAccess < StandardError; end - class StationAssertionRequired < StandardError; end -end diff --git a/config/initializers/bgs.rb b/config/initializers/bgs.rb index 1c12184ef..a61d1a594 100644 --- a/config/initializers/bgs.rb +++ b/config/initializers/bgs.rb @@ -1,3 +1,8 @@ -Rails.application.reloader.to_prepare do - BGSService = (!BaseController.dependencies_faked? ? ExternalApi::BGSService : Fakes::BGSService) +module BGS + class InvalidUsername < StandardError; end + class InvalidStation < StandardError; end + class InvalidApplication < StandardError; end + class NoActiveStations < StandardError; end + class NoCaseflowAccess < StandardError; end + class StationAssertionRequired < StandardError; end end diff --git a/config/initializers/bgs_service.rb b/config/initializers/bgs_service.rb new file mode 100644 index 000000000..1c12184ef --- /dev/null +++ b/config/initializers/bgs_service.rb @@ -0,0 +1,3 @@ +Rails.application.reloader.to_prepare do + BGSService = (!BaseController.dependencies_faked? ? ExternalApi::BGSService : Fakes::BGSService) +end From dbcc1ad12f3b0b94f84ce49aa3f44e164ffcef62 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Sun, 15 Sep 2024 12:00:54 -0500 Subject: [PATCH 06/42] Remove require statements --- app/services/external_api/bgs_service.rb | 2 +- app/services/external_api/vbms_service.rb | 2 +- app/services/external_api/vva_service.rb | 2 +- config/initializers/shoryuken.rb | 2 +- lib/fakes/bgs_service.rb | 2 +- lib/fakes/document_service.rb | 3 +-- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/services/external_api/bgs_service.rb b/app/services/external_api/bgs_service.rb index 42658082a..e8dee9867 100644 --- a/app/services/external_api/bgs_service.rb +++ b/app/services/external_api/bgs_service.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "bgs" -require "bgs_errors" + # Thin interface to all things BGS class ExternalApi::BGSService diff --git a/app/services/external_api/vbms_service.rb b/app/services/external_api/vbms_service.rb index 08fe2d8c2..435609a70 100644 --- a/app/services/external_api/vbms_service.rb +++ b/app/services/external_api/vbms_service.rb @@ -1,4 +1,4 @@ -require "vbms" + class RailsVBMSLogger def log(event, data) diff --git a/app/services/external_api/vva_service.rb b/app/services/external_api/vva_service.rb index 7bfd6b658..145171e5a 100644 --- a/app/services/external_api/vva_service.rb +++ b/app/services/external_api/vva_service.rb @@ -1,4 +1,4 @@ -require "vva" + # Thin interface to talk to Virtual VA class ExternalApi::VVAService diff --git a/config/initializers/shoryuken.rb b/config/initializers/shoryuken.rb index 78f1c83e3..3ba1d991e 100644 --- a/config/initializers/shoryuken.rb +++ b/config/initializers/shoryuken.rb @@ -1,4 +1,4 @@ -require "#{Rails.root}/app/jobs/middleware/job_metrics_service_metric_middleware" + Rails.application.reloader.to_prepare do diff --git a/lib/fakes/bgs_service.rb b/lib/fakes/bgs_service.rb index 641415651..65de30350 100644 --- a/lib/fakes/bgs_service.rb +++ b/lib/fakes/bgs_service.rb @@ -1,4 +1,4 @@ -require 'bgs_errors' + class Fakes::BGSService include ActiveModel::Model diff --git a/lib/fakes/document_service.rb b/lib/fakes/document_service.rb index 0f8626e5d..a664e4775 100644 --- a/lib/fakes/document_service.rb +++ b/lib/fakes/document_service.rb @@ -1,5 +1,4 @@ -require "vbms" -require "vva" + class Fakes::DocumentService cattr_accessor :errors, :max_time From 87b603f2186f550417735d68b10469a854532cf2 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Sun, 15 Sep 2024 12:05:42 -0500 Subject: [PATCH 07/42] Added Fakes and TestAuthStrategy modules --- lib/fakes/test_auth_strategy.rb | 75 ++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/lib/fakes/test_auth_strategy.rb b/lib/fakes/test_auth_strategy.rb index a724db4a4..38f0ba5d0 100644 --- a/lib/fakes/test_auth_strategy.rb +++ b/lib/fakes/test_auth_strategy.rb @@ -1,43 +1,48 @@ require "omniauth/strategies/developer" require "omniauth/form" -class EfolderAuthForm < OmniAuth::Form - def hidden_field(name, value) - @html << "\n" - self - end - def header(title, header_info) - @html << <<-HTML - - - - - #{title} - #{css} - #{header_info} - - -

#{title}

-
- HTML - self - end -end +module Fakes + module TestAuthStrategy + class EfolderAuthForm < OmniAuth::Form + def hidden_field(name, value) + @html << "\n" + self + end -class OmniAuth::Strategies::TestAuthStrategy < OmniAuth::Strategies::Developer - # custom form rendering - def request_phase - form = EfolderAuthForm.new(title: "Test VA Saml", url: callback_path) - form.hidden_field :username, session["login"]["username"] - form.hidden_field :station_id, session["login"]["station_id"] - form.button "Fake PIV Login" - form.to_response - end + def header(title, header_info) + @html << <<-HTML + + + + + #{title} + #{css} + #{header_info} + + +

#{title}

+ + HTML + self + end + end + + class OmniAuth::Strategies::TestAuthStrategy < OmniAuth::Strategies::Developer + # custom form rendering + def request_phase + form = EfolderAuthForm.new(title: "Test VA Saml", url: callback_path) + form.hidden_field :username, session["login"]["username"] + form.hidden_field :station_id, session["login"]["station_id"] + form.button "Fake PIV Login" + form.to_response + end - def auth_hash - hash = super - hash.uid = hash["info"]["css_id"] - hash + def auth_hash + hash = super + hash.uid = hash["info"]["css_id"] + hash + end + end end end From 9308c957a401aa51ea45d54acf7f8b16f297ba6f Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Sun, 15 Sep 2024 12:16:18 -0500 Subject: [PATCH 08/42] Readded accidental require deletion --- lib/fakes/document_service.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/fakes/document_service.rb b/lib/fakes/document_service.rb index a664e4775..0f8626e5d 100644 --- a/lib/fakes/document_service.rb +++ b/lib/fakes/document_service.rb @@ -1,4 +1,5 @@ - +require "vbms" +require "vva" class Fakes::DocumentService cattr_accessor :errors, :max_time From 9a6dac6afdfebfe93b7a95de713bd5cb960044ac Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Sun, 15 Sep 2024 12:17:46 -0500 Subject: [PATCH 09/42] Removed plural from CurrentUserLoadTests --- lib/scripts/current_user_load_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/scripts/current_user_load_test.rb b/lib/scripts/current_user_load_test.rb index 8968600f6..1e69682be 100644 --- a/lib/scripts/current_user_load_test.rb +++ b/lib/scripts/current_user_load_test.rb @@ -1,4 +1,4 @@ -class CurrentUserLoadTests +class CurrentUserLoadTest def initialize(iterations = 100) @iterations = iterations end From 2167642215ab097fe2e7459bfe7f005c276838f2 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Sun, 15 Sep 2024 12:21:02 -0500 Subject: [PATCH 10/42] Refactored for One File One Constant --- app/services/external_api/vbms_service.rb | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/services/external_api/vbms_service.rb b/app/services/external_api/vbms_service.rb index 435609a70..296577960 100644 --- a/app/services/external_api/vbms_service.rb +++ b/app/services/external_api/vbms_service.rb @@ -1,22 +1,22 @@ -class RailsVBMSLogger - def log(event, data) - case event - when :request - if data[:response_code] != 200 - name = data[:request].class.name.split("::").last - - Rails.logger.error( - "VBMS HTTP Error #{data[:response_code]}\n" \ - "VBMS #{name} Response #{data[:response_body]}" - ) +class ExternalApi::VBMSService + class RailsVBMSLogger + def log(event, data) + case event + when :request + if data[:response_code] != 200 + name = data[:request].class.name.split("::").last + + Rails.logger.error( + "VBMS HTTP Error #{data[:response_code]}\n" \ + "VBMS #{name} Response #{data[:response_body]}" + ) + end end end end -end -class ExternalApi::VBMSService def self.fetch_documents_for(download) request = VBMS::Requests::ListDocuments.new(download.file_number) From ed055b08056efb94f37c43fec652e4c5899cfa2a Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Sun, 15 Sep 2024 12:35:35 -0500 Subject: [PATCH 11/42] Added Zeitwerk Rspec test --- spec/initializers/zeitwerk_check_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 spec/initializers/zeitwerk_check_spec.rb diff --git a/spec/initializers/zeitwerk_check_spec.rb b/spec/initializers/zeitwerk_check_spec.rb new file mode 100644 index 000000000..44af6df8d --- /dev/null +++ b/spec/initializers/zeitwerk_check_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true +require "rails_helper" + +# See config/initializers/zeitwerk.rb if this fails +RSpec.describe "Zeitwerk Compliance Check" do + it "Eager loads all files without errors" do + expect { Rails.application.eager_load! }.not_to raise_error + end +end \ No newline at end of file From b0d4858c242be2a582964b7b4baaba02fd69eab1 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Mon, 16 Sep 2024 18:18:03 -0500 Subject: [PATCH 12/42] Fix Rubocop setup - removed incorrect include setup --- .rubocop.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 82e04ba6f..24842b923 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,10 +1,6 @@ AllCops: - TargetRubyVersion: 2.5 - TargetRailsVersion: 5.1 - Include: - - '**/config.ru' - - '**/Rakefile' - - '**/*.rake' + TargetRubyVersion: 2.3 + TargetRailsVersion: 4.2 Exclude: - 'bin/**/*' - 'db/**/*' From 9d67b0df14e3a5a3d26263d20d255343bc32c09a Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Mon, 16 Sep 2024 18:24:53 -0500 Subject: [PATCH 13/42] Added custom Rubocop - Top Level Constatns Per File --- .rubocop.yml | 11 ++++ .../top_level_constants_per_file.rb | 28 ++++++++++ .../top_level_constants_per_file_spec.rb | 55 +++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 .rubocop/custom_cop/top_level_constants_per_file.rb create mode 100644 spec/rubocop/custom_cop/- .rubocop/custom_cop/top_level_constants_per_file_spec.rb diff --git a/.rubocop.yml b/.rubocop.yml index 24842b923..d5fbbbf42 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,6 @@ +require: + - .rubocop/custom_cop/top_level_constants_per_file.rb + AllCops: TargetRubyVersion: 2.3 TargetRailsVersion: 4.2 @@ -58,3 +61,11 @@ Style/TrailingCommaInArrayLiteral: Style/TrailingCommaInHashLiteral: Enabled: false + +CustomCop/TopLevelConstantsPerFile: + Enabled: true + Include: + - 'app/**/*' + - 'lib/**/*' + Exclude: + - '**/*[^.rb]' # exclude non-.rb files (ex: .rake files) diff --git a/.rubocop/custom_cop/top_level_constants_per_file.rb b/.rubocop/custom_cop/top_level_constants_per_file.rb new file mode 100644 index 000000000..90832839f --- /dev/null +++ b/.rubocop/custom_cop/top_level_constants_per_file.rb @@ -0,0 +1,28 @@ +module RuboCop + module CustomCop + class TopLevelConstantsPerFile < RuboCop::Cop::Cop + MSG = "Multiple top-level constants detected in one file. The autoloader expects one top-level constant per file." + + def investigate(processed_source) + return unless processed_source + + # If more than one top-level constant in the file, add offense on the second one + if top_level_constant_nodes.size > 1 + add_offense(top_level_constant_nodes[1], message: MSG) + end + end + + private + + def top_level_constant_nodes + @top_level_constant_nodes ||= + processed_source.ast.each_node(:class, :module).select { |node| top_level_constant?(node) } + end + + def top_level_constant?(node) + # node is not nested within a class or module node? + node.ancestors.none? { |ancestor| ancestor.class_type? || ancestor.module_type? } + end + end + end +end diff --git a/spec/rubocop/custom_cop/- .rubocop/custom_cop/top_level_constants_per_file_spec.rb b/spec/rubocop/custom_cop/- .rubocop/custom_cop/top_level_constants_per_file_spec.rb new file mode 100644 index 000000000..98d7543ef --- /dev/null +++ b/spec/rubocop/custom_cop/- .rubocop/custom_cop/top_level_constants_per_file_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require "spec_helper" +require "rubocop" +require "rubocop/rspec/support" +require_relative "../../../.rubocop/custom_cop/top_level_constants_per_file" + +describe RuboCop::CustomCop::TopLevelConstantsPerFile do + include RuboCop::RSpec::ExpectOffense + + subject(:cop) { described_class.new(config) } + let(:config) { RuboCop::Config.new } + + let(:message) do + "Multiple top-level constants detected in one file. The autoloader expects one top-level constant per file." + end + + context "when there is only one top-level class in file" do + it "does not register an offense" do + expect_no_offenses(<<~RUBY) + class SomeClass; end + RUBY + end + end + + context "when there is only one top-level module in file" do + it "does not register an offense" do + expect_no_offenses(<<~RUBY) + module SomeModule; end + RUBY + end + end + + context "when there is only one top-level class/module in file, having one or more nested classes/modules" do + it "does not register an offense" do + expect_no_offenses(<<~RUBY) + module SomeModule + class FirstNestedClass; end + class SecondNestedClass; end + end + RUBY + end + end + + context "when there are multiple top-level classes/modules in file" do + it "registers an offense on the second one" do + expect_offense(<<~RUBY) + class FirstClass; end + module SomeModule; end + ^^^^^^^^^^^^^^^^^^^^^^ #{message} + class SecondClass; end + RUBY + end + end +end From ca196eba1e6d6db864bda77ee966c49ab156ac7e Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Mon, 16 Sep 2024 18:27:17 -0500 Subject: [PATCH 14/42] Rename and moved Zeitwerk spec for Caseflow parity --- .../zeitwerk_check_spec.rb => config/zeitwerk_spec.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/{initializers/zeitwerk_check_spec.rb => config/zeitwerk_spec.rb} (100%) diff --git a/spec/initializers/zeitwerk_check_spec.rb b/spec/config/zeitwerk_spec.rb similarity index 100% rename from spec/initializers/zeitwerk_check_spec.rb rename to spec/config/zeitwerk_spec.rb From 75e874eeeb43c2c25abd819e2d7ec8c793757c61 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Mon, 16 Sep 2024 20:28:42 -0500 Subject: [PATCH 15/42] Fixed custom cop spec file structure --- .../custom_cop => }/top_level_constants_per_file_spec.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/rubocop/custom_cop/{- .rubocop/custom_cop => }/top_level_constants_per_file_spec.rb (100%) diff --git a/spec/rubocop/custom_cop/- .rubocop/custom_cop/top_level_constants_per_file_spec.rb b/spec/rubocop/custom_cop/top_level_constants_per_file_spec.rb similarity index 100% rename from spec/rubocop/custom_cop/- .rubocop/custom_cop/top_level_constants_per_file_spec.rb rename to spec/rubocop/custom_cop/top_level_constants_per_file_spec.rb From e11055a535376f8371648fdd57faf5439eb9f752 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Tue, 17 Sep 2024 14:37:32 -0500 Subject: [PATCH 16/42] Zeitwerk spec comments addressed --- spec/config/zeitwerk_spec.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spec/config/zeitwerk_spec.rb b/spec/config/zeitwerk_spec.rb index 44af6df8d..99a4cbc8c 100644 --- a/spec/config/zeitwerk_spec.rb +++ b/spec/config/zeitwerk_spec.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true -require "rails_helper" -# See config/initializers/zeitwerk.rb if this fails RSpec.describe "Zeitwerk Compliance Check" do it "Eager loads all files without errors" do expect { Rails.application.eager_load! }.not_to raise_error end -end \ No newline at end of file +end From 121b98e8ab7ff6dcea62cb898b91871c0ad1a1d8 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Tue, 17 Sep 2024 14:51:45 -0500 Subject: [PATCH 17/42] Refactored for Caseflow parity --- config/application.rb | 18 +++++++++++++++++- config/initializers/zeitwerk.rb | 33 --------------------------------- 2 files changed, 17 insertions(+), 34 deletions(-) delete mode 100644 config/initializers/zeitwerk.rb diff --git a/config/application.rb b/config/application.rb index bc52e39f1..25bbdf1bc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -122,6 +122,10 @@ class Application < Rails::Application #--------------------------------------------------------------------------------------- config.download_filepath = Rails.root + "tmp/files" + # Zeitwerk has specific requirements for auto/eager loading. See below links for more details + # https://guides.rubyonrails.org/classic_to_zeitwerk_howto.html + # https://github.com/fxn/zeitwerk + config.autoload_paths += [ "#{root}/lib", ] @@ -130,14 +134,26 @@ class Application < Rails::Application "#{root}/lib", ] + Rails.autoloaders.each do | autoloader | + # "file_name" => Expected Module or Class name. + autoloader.inflector.inflect( + "bgs" => "BGS", + "bgs_service" => "BGSService", + "poa_mapper" => "POAMapper", + "vbms_service" => "VBMSService", + "vva_service" => "VVAService" + ) + end + # A collapse statement will remove the need for a namespace based on the direcotry given. - # Tasks::Support::ModuleOrClassName becomes ModuleOrClassName with the below statements. + # Tasks::Support::ModuleOrClassName becomes ModuleOrClassName with the last two statements. Rails.autoloaders.main.collapse( "app/jobs/middleware", "#{root}/lib/tasks", "#{root}/lib/tasks/support" ) + # Will not autoload any files within directories added here Rails.autoloaders.main.ignore( "#{root}/lib/assets", "#{root}/lib/pdfs", diff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rb deleted file mode 100644 index 7479fc38c..000000000 --- a/config/initializers/zeitwerk.rb +++ /dev/null @@ -1,33 +0,0 @@ - -# Zeitwerk has specific requirements for auto/eager loading. See below links for more details -# https://guides.rubyonrails.org/classic_to_zeitwerk_howto.html -# https://github.com/fxn/zeitwerk - -# To sumarize Zeitwerk requires several conditions be met when attempting to auto/eager load -# - The top level namespace must reflect the auto/eager-loadpath / filename. The auto/eager-load -# path will be different from the relative path. See https://github.com/fxn/zeitwerk#file-structure -# - Zeitwerk expects 1 constant per file, anything not under that constant won't be loaded -# - Acronyms aren't implicit. You can use them but you'll need to tell zeitwerk. (More details below) -# - The constant name and file name MUST match, or zeitwerk needs to be told otherwise. -# So file_name.rb should be `module or class FileName` not `FileNames``. -# - Namespaces need to be unique. Depending on the auto/eager-load path, files with the same -# name but located in different directories can cause issues. This also applies to any Gems you have have installed. -# -# -# Use the command and test below to ensure zeitwerk compliance. -# A rspec test has been added for this, you can also check your CI output for details -# bin/rails zeitwerk:check - -# For more info add Rails.autoloaders.log! to your application.rb file -# before running the zeitwerk:check for a breakdown of what zeitwerk is doing. - -Rails.autoloaders.each do |autoloader| - # "file_name" => Expected Module or Class name. - autoloader.inflector.inflect( - "bgs" => "BGS", - "bgs_service" => "BGSService", - "poa_mapper" => "POAMapper", - "vbms_service" => "VBMSService", - "vva_service" => "VVAService" - ) -end \ No newline at end of file From 2004005a789190a62a582285f1f26744fd1f343e Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Tue, 17 Sep 2024 14:57:54 -0500 Subject: [PATCH 18/42] Renamed for consistency --- config/initializers/{s3.rb => s3_service.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename config/initializers/{s3.rb => s3_service.rb} (100%) diff --git a/config/initializers/s3.rb b/config/initializers/s3_service.rb similarity index 100% rename from config/initializers/s3.rb rename to config/initializers/s3_service.rb From 6f7007d235046b64c22cb3ca292c2055a35d86b1 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Tue, 17 Sep 2024 15:01:40 -0500 Subject: [PATCH 19/42] Safety require --- app/services/external_api/vva_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/external_api/vva_service.rb b/app/services/external_api/vva_service.rb index 145171e5a..7bfd6b658 100644 --- a/app/services/external_api/vva_service.rb +++ b/app/services/external_api/vva_service.rb @@ -1,4 +1,4 @@ - +require "vva" # Thin interface to talk to Virtual VA class ExternalApi::VVAService From 59c882bae474d3d760dc645776b69f806fd7c878 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Tue, 17 Sep 2024 15:03:49 -0500 Subject: [PATCH 20/42] Safety require and to_prepare for BGS --- config/initializers/bgs.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/config/initializers/bgs.rb b/config/initializers/bgs.rb index a61d1a594..ddb1ef447 100644 --- a/config/initializers/bgs.rb +++ b/config/initializers/bgs.rb @@ -1,8 +1,13 @@ -module BGS - class InvalidUsername < StandardError; end - class InvalidStation < StandardError; end - class InvalidApplication < StandardError; end - class NoActiveStations < StandardError; end - class NoCaseflowAccess < StandardError; end - class StationAssertionRequired < StandardError; end +Rails.application.config.to_prepare do + require "bgs" + + module BGS + class InvalidUsername < StandardError; end + class InvalidStation < StandardError; end + class InvalidApplication < StandardError; end + class NoActiveStations < StandardError; end + class NoCaseflowAccess < StandardError; end + class StationAssertionRequired < StandardError; end + end end + From 7b43bc128592128d78e78aa9c97a60e14fb87d13 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Tue, 17 Sep 2024 15:11:03 -0500 Subject: [PATCH 21/42] Added autoload/eagerload section --- config/application.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/config/application.rb b/config/application.rb index 25bbdf1bc..59c5cc8f6 100644 --- a/config/application.rb +++ b/config/application.rb @@ -122,9 +122,13 @@ class Application < Rails::Application #--------------------------------------------------------------------------------------- config.download_filepath = Rails.root + "tmp/files" - # Zeitwerk has specific requirements for auto/eager loading. See below links for more details - # https://guides.rubyonrails.org/classic_to_zeitwerk_howto.html - # https://github.com/fxn/zeitwerk + + # -------------------------------------------------------------------------------------- + # Autoloading & Eager loading + + # Zeitwerk has specific requirements for auto/eager loading. See below links for more details + # https://guides.rubyonrails.org/classic_to_zeitwerk_howto.html + # https://github.com/fxn/zeitwerk config.autoload_paths += [ "#{root}/lib", @@ -159,7 +163,7 @@ class Application < Rails::Application "#{root}/lib/pdfs", "#{root}/lib/scripts" ) - + # -------------------------------------------------------------------------------------- # Currently the Caseflow client makes calls to get document content directly From 9436ce1ed478e7811a1f6e8a7f4aa40e212d44bd Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Tue, 17 Sep 2024 19:17:04 -0500 Subject: [PATCH 22/42] Renamed for consistency --- config/initializers/{vbms.rb => vbms_service.rb} | 0 config/initializers/{vva.rb => vva_service.rb} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename config/initializers/{vbms.rb => vbms_service.rb} (100%) rename config/initializers/{vva.rb => vva_service.rb} (100%) diff --git a/config/initializers/vbms.rb b/config/initializers/vbms_service.rb similarity index 100% rename from config/initializers/vbms.rb rename to config/initializers/vbms_service.rb diff --git a/config/initializers/vva.rb b/config/initializers/vva_service.rb similarity index 100% rename from config/initializers/vva.rb rename to config/initializers/vva_service.rb From 40caf033dfadc91e2c525164679f430fa7e46cff Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Tue, 17 Sep 2024 19:36:47 -0500 Subject: [PATCH 23/42] Readded require so to_prepare could be removed --- config/application.rb | 4 +-- config/initializers/shoryuken.rb | 43 ++++++++++++++++---------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/config/application.rb b/config/application.rb index 59c5cc8f6..f1b4638a3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -150,15 +150,15 @@ class Application < Rails::Application end # A collapse statement will remove the need for a namespace based on the direcotry given. - # Tasks::Support::ModuleOrClassName becomes ModuleOrClassName with the last two statements. + # Tasks::Support::ModuleOrClassName becomes ModuleOrClassName with the two statements below. Rails.autoloaders.main.collapse( - "app/jobs/middleware", "#{root}/lib/tasks", "#{root}/lib/tasks/support" ) # Will not autoload any files within directories added here Rails.autoloaders.main.ignore( + "app/jobs/middleware", "#{root}/lib/assets", "#{root}/lib/pdfs", "#{root}/lib/scripts" diff --git a/config/initializers/shoryuken.rb b/config/initializers/shoryuken.rb index 3ba1d991e..5ad98a326 100644 --- a/config/initializers/shoryuken.rb +++ b/config/initializers/shoryuken.rb @@ -1,31 +1,30 @@ +require "#{Rails.root}/app/jobs/middleware/job_metrics_service_metric_middleware" -Rails.application.reloader.to_prepare do - # set up default exponential backoff parameters - ActiveJob::QueueAdapters::ShoryukenAdapter::JobWrapper - .shoryuken_options(auto_visibility_timeout: true, - retry_intervals: [5.seconds, 5.minutes, rand(4..8).hours]) +# set up default exponential backoff parameters +ActiveJob::QueueAdapters::ShoryukenAdapter::JobWrapper + .shoryuken_options(auto_visibility_timeout: true, + retry_intervals: [5.seconds, 5.minutes, rand(4..8).hours]) - if Rails.application.config.sqs_endpoint - # override the sqs_endpoint - Shoryuken::Client.sqs.config[:endpoint] = URI(Rails.application.config.sqs_endpoint) - end +if Rails.application.config.sqs_endpoint + # override the sqs_endpoint + Shoryuken::Client.sqs.config[:endpoint] = URI(Rails.application.config.sqs_endpoint) +end - if Rails.application.config.sqs_create_queues - # create the development queues - Shoryuken::Client.sqs.create_queue(queue_name: ActiveJob::Base.queue_name_prefix + "_low_priority") - Shoryuken::Client.sqs.create_queue(queue_name: ActiveJob::Base.queue_name_prefix + "_med_priority") - Shoryuken::Client.sqs.create_queue(queue_name: ActiveJob::Base.queue_name_prefix + "_high_priority") - end +if Rails.application.config.sqs_create_queues + # create the development queues + Shoryuken::Client.sqs.create_queue(queue_name: ActiveJob::Base.queue_name_prefix + "_low_priority") + Shoryuken::Client.sqs.create_queue(queue_name: ActiveJob::Base.queue_name_prefix + "_med_priority") + Shoryuken::Client.sqs.create_queue(queue_name: ActiveJob::Base.queue_name_prefix + "_high_priority") +end - Shoryuken.configure_server do |config| - Rails.logger = Shoryuken::Logging.logger - Rails.logger.level = Logger::INFO +Shoryuken.configure_server do |config| + Rails.logger = Shoryuken::Logging.logger + Rails.logger.level = Logger::INFO - # register all shoryuken middleware - config.server_middleware do |chain| - chain.add JobMetricsServiceMetricMiddleware - end + # register all shoryuken middleware + config.server_middleware do |chain| + chain.add JobMetricsServiceMetricMiddleware end end From 0a00c22ce2466752f697798e037cf2852020925a Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Fri, 4 Oct 2024 13:31:23 -0500 Subject: [PATCH 24/42] Added rubocop_todo for temp ignore linter errors --- .rubocop.yml | 2 ++ .rubocop_todo.yml | 0 2 files changed, 2 insertions(+) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index d5fbbbf42..20d586a9f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +inherit_from: .rubocop_todo.yml + require: - .rubocop/custom_cop/top_level_constants_per_file.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 000000000..e69de29bb From a9fbcb9bfd6187e9f840a3f5199f377fade841ae Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Fri, 4 Oct 2024 13:48:17 -0500 Subject: [PATCH 25/42] Required changes for .rubocop.yml to work --- .rubocop.yml | 6 +- .rubocop_todo.yml | 576 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 580 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 20d586a9f..9693b677e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,11 +1,13 @@ inherit_from: .rubocop_todo.yml require: + - rubocop-performance + - rubocop-rails - .rubocop/custom_cop/top_level_constants_per_file.rb AllCops: - TargetRubyVersion: 2.3 - TargetRailsVersion: 4.2 + TargetRubyVersion: 2.5 + TargetRailsVersion: 5.1 Exclude: - 'bin/**/*' - 'db/**/*' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e69de29bb..c046b807c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -0,0 +1,576 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2024-10-04 13:43:11 -0500 using RuboCop version 0.83.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_argument, with_fixed_indentation +Layout/ArgumentAlignment: + Exclude: + - 'app/services/manifest_fetcher.rb' + - 'app/services/record_fetcher.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/ClosingHeredocIndentation: + Exclude: + - 'spec/services/pdf_service_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/ClosingParenthesisIndentation: + Exclude: + - 'spec/initializers/deprecation_warning_subscriber_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/CommentIndentation: + Exclude: + - 'spec/features/help_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/ElseAlignment: + Exclude: + - 'spec/features/user_error_flows_spec.rb' + +# Offense count: 16 +# Cop supports --auto-correct. +Layout/EmptyLineAfterGuardClause: + Exclude: + - 'app/controllers/api/v2/manifests_controller.rb' + - 'app/controllers/api/v2/records_controller.rb' + - 'app/controllers/sessions_controller.rb' + - 'app/helpers/application_helper.rb' + - 'app/models/manifest.rb' + - 'app/models/manifest_source.rb' + - 'app/services/external_api/bgs_service.rb' + - 'app/services/manifest_fetcher.rb' + - 'lib/fakes/bgs_service.rb' + - 'lib/fakes/document_service.rb' + - 'spec/support/download_helper.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines. +Layout/EmptyLineBetweenDefs: + Exclude: + - 'app/services/manifest_fetcher.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Layout/EmptyLines: + Exclude: + - 'app/services/external_api/bgs_service.rb' + - 'app/services/manifest_fetcher.rb' + - 'lib/fakes/test_auth_strategy.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: around, only_before +Layout/EmptyLinesAroundAccessModifier: + Exclude: + - 'app/controllers/health_checks_controller.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only +Layout/EmptyLinesAroundClassBody: + Exclude: + - 'app/controllers/health_checks_controller.rb' + - 'app/services/record_api_fetcher.rb' + - 'app/services/record_fetcher.rb' + - 'app/services/record_fetcher_base.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity. +# SupportedStylesAlignWith: keyword, variable, start_of_line +Layout/EndAlignment: + Exclude: + - 'spec/features/user_error_flows_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses +Layout/FirstArgumentIndentation: + Exclude: + - 'spec/initializers/deprecation_warning_subscriber_spec.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_brackets +Layout/FirstArrayElementIndentation: + EnforcedStyle: consistent + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_braces +Layout/FirstHashElementIndentation: + EnforcedStyle: consistent + +# Offense count: 27 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/HashAlignment: + Exclude: + - 'spec/requests/api/v2/manifests_spec.rb' + - 'spec/services/bgs_service_spec.rb' + - 'spec/services/user_authorizer_spec.rb' + - 'spec/services/veteran_finder_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: Width, IgnoredPatterns. +Layout/IndentationWidth: + Exclude: + - 'spec/features/user_error_flows_spec.rb' + +# Offense count: 14 +# Cop supports --auto-correct. +# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. +Layout/LeadingCommentSpace: + Exclude: + - 'Gemfile' + - 'ci-bin/concatenate-log.rb' + - 'spec/rails_helper.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Layout/LeadingEmptyLines: + Exclude: + - 'app/services/external_api/vbms_service.rb' + - 'lib/fakes/bgs_service.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented, indented_relative_to_receiver +Layout/MultilineMethodCallIndentation: + Exclude: + - 'spec/controllers/api_v2_application_controller_spec.rb' + - 'spec/helpers/application_helper_spec.rb' + - 'spec/services/external_api/vbms_service_spec.rb' + +# Offense count: 38 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. +# SupportedStylesForExponentOperator: space, no_space +Layout/SpaceAroundOperators: + Exclude: + - 'spec/services/bgs_service_spec.rb' + - 'spec/services/user_authorizer_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceBeforeBlockBraces: + Exclude: + - 'spec/services/manifest_fetcher_spec.rb' + +# Offense count: 14 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBrackets: space, no_space +Layout/SpaceInsideArrayLiteralBrackets: + Exclude: + - 'spec/features/backend_error_flows_spec.rb' + - 'spec/features/react_download_spec.rb' + - 'spec/jobs/v2/download_manifest_job_spec.rb' + - 'spec/requests/api/v2/document_counts_spec.rb' + - 'spec/requests/api/v2/manifests_spec.rb' + - 'spec/services/document_counter_spec.rb' + - 'spec/services/manifest_fetcher_spec.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideBlockBraces: + Exclude: + - 'spec/services/document_creator_spec.rb' + - 'spec/services/manifest_fetcher_spec.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideHashLiteralBraces: + Exclude: + - 'spec/services/bgs_service_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: final_newline, final_blank_line +Layout/TrailingEmptyLines: + Exclude: + - '.simplecov' + - 'app/services/metrics_service.rb' + - 'spec/services/manifest_fetcher_spec.rb' + +# Offense count: 31 +# Cop supports --auto-correct. +# Configuration parameters: AllowInHeredoc. +Layout/TrailingWhitespace: + Exclude: + - 'app/services/external_api/vbms_service.rb' + - 'app/services/manifest_fetcher.rb' + - 'app/services/record_fetcher.rb' + - 'spec/controllers/sessions_controller_spec.rb' + - 'spec/jobs/v2/download_manifest_job_spec.rb' + - 'spec/services/document_creator_spec.rb' + - 'spec/services/manifest_fetcher_spec.rb' + - 'spec/services/user_authorizer_spec.rb' + - 'spec/support/capybara.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/AmbiguousRegexpLiteral: + Exclude: + - 'spec/requests/sso_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/DeprecatedClassMethods: + Exclude: + - 'spec/services/zipfile_creator_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/EnsureReturn: + Exclude: + - 'app/services/manifest_fetcher.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Lint/NonDeterministicRequireOrder: + Exclude: + - 'Rakefile' + - 'spec/rails_helper.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Lint/RedundantCopDisableDirective: + Exclude: + - 'app/helpers/application_helper.rb' + - 'app/services/metrics_service.rb' + - 'spec/features/help_spec.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. +Lint/UnusedMethodArgument: + Exclude: + - 'app/services/metrics_service.rb' + - 'lib/fakes/bgs_service.rb' + - 'lib/fakes/document_service.rb' + - 'spec/requests/sso_spec.rb' + +# Offense count: 1 +Lint/UselessAssignment: + Exclude: + - 'app/services/manifest_fetcher.rb' + +# Offense count: 2 +# Configuration parameters: IgnoredMethods. +Metrics/AbcSize: + Max: 65 + +# Offense count: 4 +# Configuration parameters: IgnoredMethods. +Metrics/CyclomaticComplexity: + Max: 15 + +# Offense count: 3 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/MethodLength: + Max: 32 + +# Offense count: 4 +# Configuration parameters: IgnoredMethods. +Metrics/PerceivedComplexity: + Max: 15 + +# Offense count: 1 +# Configuration parameters: IgnoredPatterns. +# SupportedStyles: snake_case, camelCase +Naming/MethodName: + EnforcedStyle: snake_case + +# Offense count: 4 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp +Naming/MethodParameterName: + Exclude: + - 'app/services/zipfile_creator.rb' + - 'lib/fakes/bgs_service.rb' + - 'lib/fakes/document_service.rb' + +# Offense count: 12 +# Cop supports --auto-correct. +# Configuration parameters: PreferredName. +Naming/RescuedExceptionsVariableName: + Exclude: + - 'app/controllers/sessions_controller.rb' + - 'app/jobs/middleware/job_metrics_service_metric_middleware.rb' + - 'app/jobs/v2/download_manifest_job.rb' + - 'app/jobs/v2/package_files_job.rb' + - 'app/services/external_api/bgs_service.rb' + - 'app/services/manifest_fetcher.rb' + - 'app/services/metrics_service.rb' + - 'app/services/record_api_fetcher.rb' + - 'app/services/record_fetcher.rb' + - 'app/services/user_authorizer.rb' + - 'lib/efolder/migration.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Performance/Count: + Exclude: + - 'app/models/manifest.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Performance/RegexpMatch: + Exclude: + - 'app/services/external_api/bgs_service.rb' + - 'lib/tasks/symlink_assets.rake' + +# Offense count: 1 +# Cop supports --auto-correct. +Rails/ApplicationController: + Exclude: + - 'app/controllers/base_controller.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Rails/ApplicationJob: + Exclude: + - 'app/jobs/fakes/download_files_job.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent. +Rails/Blank: + Exclude: + - 'app/controllers/sessions_controller.rb' + - 'lib/fakes/bgs_service.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: numeric, symbolic +Rails/HttpStatus: + Exclude: + - 'app/controllers/api/v1/application_controller.rb' + - 'app/controllers/api/v2/application_controller.rb' + - 'app/controllers/api/v2/records_controller.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Rails/Presence: + Exclude: + - 'app/services/external_api/bgs_service.rb' + - 'app/services/user_authorizer.rb' + - 'app/services/veteran_finder.rb' + - 'lib/fakes/bgs_service.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: NotNilAndNotEmpty, NotBlank, UnlessBlank. +Rails/Present: + Exclude: + - 'app/services/pdf_service.rb' + +# Offense count: 3 +# Configuration parameters: Include. +# Include: **/Rakefile, **/*.rake +Rails/RakeEnvironment: + Exclude: + - 'lib/capistrano/tasks/**/*.rake' + - 'lib/tasks/bundle_javascript.rake' + - 'lib/tasks/lint.rake' + - 'lib/tasks/symlink_assets.rake' + +# Offense count: 1 +# Configuration parameters: Include. +# Include: app/models/**/*.rb +Rails/UniqueValidationWithoutIndex: + Exclude: + - 'app/models/manifest_source.rb' + +# Offense count: 1 +Security/Open: + Exclude: + - 'app/jobs/touch_file_job.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. +# SupportedStyles: assign_to_condition, assign_inside_condition +Style/ConditionalAssignment: + Exclude: + - 'app/services/manifest_fetcher.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: compact, expanded +Style/EmptyMethod: + Exclude: + - 'app/controllers/sessions_controller.rb' + - 'app/controllers/test_controller.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/ExpandPathArguments: + Exclude: + - 'spec/rails_helper.rb' + +# Offense count: 1 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: annotated, template, unannotated +Style/FormatStringToken: + Exclude: + - 'app/services/zipfile_creator.rb' + +# Offense count: 38 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +Style/HashSyntax: + Exclude: + - 'spec/services/bgs_service_spec.rb' + - 'spec/services/user_authorizer_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Style/IfUnlessModifier: + Exclude: + - '.simplecov' + - 'app/controllers/application_controller.rb' + - 'app/models/user.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: line_count_dependent, lambda, literal +Style/Lambda: + Exclude: + - 'spec/jobs/application_job_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedOctalStyle. +# SupportedOctalStyles: zero_with_o, zero_only +Style/NumericLiteralPrefix: + Exclude: + - 'spec/services/user_authorizer_spec.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: compact, exploded +Style/RaiseArgs: + Exclude: + - 'spec/controllers/api_v2_application_controller_spec.rb' + - 'spec/features/backend_error_flows_spec.rb' + - 'spec/features/user_error_flows_spec.rb' + - 'spec/requests/api/v2/manifests_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantBegin: + Exclude: + - 'app/services/manifest_fetcher.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantCondition: + Exclude: + - 'app/services/external_api/bgs_service.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantInterpolation: + Exclude: + - 'spec/support/fake_saml_idp.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Exclude: + - 'app/controllers/api/v2/document_counts_controller.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowInnerSlashes. +# SupportedStyles: slashes, percent_r, mixed +Style/RegexpLiteral: + Exclude: + - 'spec/requests/sso_spec.rb' + +# Offense count: 16 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: only_raise, only_fail, semantic +Style/SignalException: + Exclude: + - 'app/controllers/sessions_controller.rb' + - 'app/models/css_authentication_session.rb' + - 'app/services/external_api/bgs_service.rb' + - 'app/services/manifest_fetcher.rb' + - 'lib/fakes/bgs_service.rb' + +# Offense count: 37 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - 'app/controllers/api/v2/files_downloads_controller.rb' + - 'app/controllers/application_controller.rb' + - 'app/controllers/test_controller.rb' + - 'app/jobs/touch_file_job.rb' + - 'app/services/external_api/bgs_service.rb' + - 'app/services/record_fetcher.rb' + - 'app/services/record_fetcher_base.rb' + - 'spec/controllers/api_v2_application_controller_spec.rb' + - 'spec/features/active_job_spec.rb' + - 'spec/requests/sso_spec.rb' + - 'spec/support/capybara.rb' + - 'spec/support/fake_saml_idp.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInArguments: + Exclude: + - 'app/models/css_authentication_session.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/WhileUntilDo: + Exclude: + - 'spec/support/download_helper.rb' From 5feee96601d2a91da1aecdc44267254a26e36b86 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Fri, 4 Oct 2024 20:13:37 -0500 Subject: [PATCH 26/42] Updated Rubocop todo with proper generation --- .rubocop.yml | 4 +-- .rubocop_todo.yml | 90 ++++++----------------------------------------- 2 files changed, 13 insertions(+), 81 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 9693b677e..b9b273919 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,8 +1,8 @@ inherit_from: .rubocop_todo.yml + + require: - - rubocop-performance - - rubocop-rails - .rubocop/custom_cop/top_level_constants_per_file.rb AllCops: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c046b807c..61b253d9e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-10-04 13:43:11 -0500 using RuboCop version 0.83.0. +# on 2024-10-04 20:06:20 -0500 using RuboCop version 0.83.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -260,11 +260,10 @@ Lint/EnsureReturn: Exclude: - 'app/services/manifest_fetcher.rb' -# Offense count: 2 +# Offense count: 1 # Cop supports --auto-correct. Lint/NonDeterministicRequireOrder: Exclude: - - 'Rakefile' - 'spec/rails_helper.rb' # Offense count: 3 @@ -294,6 +293,9 @@ Lint/UselessAssignment: # Configuration parameters: IgnoredMethods. Metrics/AbcSize: Max: 65 + Exclude: + - 'app/services/document_creator.rb' + - 'app/services/external_api/bgs_service.rb' # Offense count: 4 # Configuration parameters: IgnoredMethods. @@ -304,6 +306,10 @@ Metrics/CyclomaticComplexity: # Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: Max: 32 + Exclude: + - 'app/services/external_api/bgs_service.rb' + - 'lib/fakes/bgs_service.rb' + - 'spec/support/fake_saml_idp.rb' # Offense count: 4 # Configuration parameters: IgnoredMethods. @@ -315,6 +321,8 @@ Metrics/PerceivedComplexity: # SupportedStyles: snake_case, camelCase Naming/MethodName: EnforcedStyle: snake_case + Exclude: + - 'app/controllers/base_controller.rb' # Offense count: 4 # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. @@ -342,82 +350,6 @@ Naming/RescuedExceptionsVariableName: - 'app/services/user_authorizer.rb' - 'lib/efolder/migration.rb' -# Offense count: 3 -# Cop supports --auto-correct. -Performance/Count: - Exclude: - - 'app/models/manifest.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -Performance/RegexpMatch: - Exclude: - - 'app/services/external_api/bgs_service.rb' - - 'lib/tasks/symlink_assets.rake' - -# Offense count: 1 -# Cop supports --auto-correct. -Rails/ApplicationController: - Exclude: - - 'app/controllers/base_controller.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Rails/ApplicationJob: - Exclude: - - 'app/jobs/fakes/download_files_job.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent. -Rails/Blank: - Exclude: - - 'app/controllers/sessions_controller.rb' - - 'lib/fakes/bgs_service.rb' - -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: numeric, symbolic -Rails/HttpStatus: - Exclude: - - 'app/controllers/api/v1/application_controller.rb' - - 'app/controllers/api/v2/application_controller.rb' - - 'app/controllers/api/v2/records_controller.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -Rails/Presence: - Exclude: - - 'app/services/external_api/bgs_service.rb' - - 'app/services/user_authorizer.rb' - - 'app/services/veteran_finder.rb' - - 'lib/fakes/bgs_service.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: NotNilAndNotEmpty, NotBlank, UnlessBlank. -Rails/Present: - Exclude: - - 'app/services/pdf_service.rb' - -# Offense count: 3 -# Configuration parameters: Include. -# Include: **/Rakefile, **/*.rake -Rails/RakeEnvironment: - Exclude: - - 'lib/capistrano/tasks/**/*.rake' - - 'lib/tasks/bundle_javascript.rake' - - 'lib/tasks/lint.rake' - - 'lib/tasks/symlink_assets.rake' - -# Offense count: 1 -# Configuration parameters: Include. -# Include: app/models/**/*.rb -Rails/UniqueValidationWithoutIndex: - Exclude: - - 'app/models/manifest_source.rb' - # Offense count: 1 Security/Open: Exclude: From f14a7176e0c50bf811a290066ce06ab477480841 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Fri, 4 Oct 2024 20:45:21 -0500 Subject: [PATCH 27/42] Unecessary ShellCommand removed --- lib/tasks/support/shell_command.rb | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 lib/tasks/support/shell_command.rb diff --git a/lib/tasks/support/shell_command.rb b/lib/tasks/support/shell_command.rb deleted file mode 100644 index cf11bc63e..000000000 --- a/lib/tasks/support/shell_command.rb +++ /dev/null @@ -1,17 +0,0 @@ -class ShellCommand - # runs shell command and prints output - # returns boolean depending on the success of the command - def self.run(command) - success = false - - Open3.popen2e(command) do |_stdin, stdout_and_stderr, thread| - while (line = stdout_and_stderr.gets) - puts(line) - end - - success = thread.value.zero? - end - - success - end -end From 21b4bfa97543b405168748b41f0fa353658ae237 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Fri, 4 Oct 2024 20:48:21 -0500 Subject: [PATCH 28/42] Ignored TestAuthStrategy in autoloading - unneeded --- config/application.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/application.rb b/config/application.rb index f1b4638a3..8bee11ec1 100644 --- a/config/application.rb +++ b/config/application.rb @@ -125,7 +125,7 @@ class Application < Rails::Application # -------------------------------------------------------------------------------------- # Autoloading & Eager loading - + # Zeitwerk has specific requirements for auto/eager loading. See below links for more details # https://guides.rubyonrails.org/classic_to_zeitwerk_howto.html # https://github.com/fxn/zeitwerk @@ -161,7 +161,8 @@ class Application < Rails::Application "app/jobs/middleware", "#{root}/lib/assets", "#{root}/lib/pdfs", - "#{root}/lib/scripts" + "#{root}/lib/scripts", + "#{root}/lib/fakes/test_auth_strategy.rb" ) # -------------------------------------------------------------------------------------- From 40fbaec407b73d1d244ff70aa3d0ad7f90d34583 Mon Sep 17 00:00:00 2001 From: AKeyframe <89286339+AKeyframe@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:38:26 -0500 Subject: [PATCH 29/42] Update .rubocop.yml Co-authored-by: Jeremy Croteau --- .rubocop.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b9b273919..2d1193107 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,5 @@ inherit_from: .rubocop_todo.yml - - require: - .rubocop/custom_cop/top_level_constants_per_file.rb From 96471528383e3b0dc560c49727f23bf8f236d50b Mon Sep 17 00:00:00 2001 From: AKeyframe <89286339+AKeyframe@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:39:17 -0500 Subject: [PATCH 30/42] Update app/services/external_api/vbms_service.rb Co-authored-by: Jeremy Croteau --- app/services/external_api/vbms_service.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/services/external_api/vbms_service.rb b/app/services/external_api/vbms_service.rb index 296577960..9a2038b0c 100644 --- a/app/services/external_api/vbms_service.rb +++ b/app/services/external_api/vbms_service.rb @@ -1,5 +1,3 @@ - - class ExternalApi::VBMSService class RailsVBMSLogger def log(event, data) From fb224883c24e6b0ae06396bbbb71fb0cf22d9ca5 Mon Sep 17 00:00:00 2001 From: AKeyframe <89286339+AKeyframe@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:40:20 -0500 Subject: [PATCH 31/42] Add #{root} to config/application.rb Co-authored-by: Jeremy Croteau --- config/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index 8bee11ec1..e33ceaeec 100644 --- a/config/application.rb +++ b/config/application.rb @@ -158,7 +158,7 @@ class Application < Rails::Application # Will not autoload any files within directories added here Rails.autoloaders.main.ignore( - "app/jobs/middleware", + "#{root}/app/jobs/middleware", "#{root}/lib/assets", "#{root}/lib/pdfs", "#{root}/lib/scripts", From b6bdf9eb1044e7a1dac9475d3158b2496ca651fd Mon Sep 17 00:00:00 2001 From: AKeyframe <89286339+AKeyframe@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:40:46 -0500 Subject: [PATCH 32/42] Cosmetic Update config/initializers/shoryuken.rb Co-authored-by: Jeremy Croteau --- config/initializers/shoryuken.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/config/initializers/shoryuken.rb b/config/initializers/shoryuken.rb index 5ad98a326..f06cdaa44 100644 --- a/config/initializers/shoryuken.rb +++ b/config/initializers/shoryuken.rb @@ -1,4 +1,3 @@ - require "#{Rails.root}/app/jobs/middleware/job_metrics_service_metric_middleware" From fb974e23e79ca6a39b0a31294405179874cd72b2 Mon Sep 17 00:00:00 2001 From: AKeyframe <89286339+AKeyframe@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:41:19 -0500 Subject: [PATCH 33/42] Cosmetic Update config/initializers/shoryuken.rb Co-authored-by: Jeremy Croteau --- config/initializers/shoryuken.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/config/initializers/shoryuken.rb b/config/initializers/shoryuken.rb index f06cdaa44..9026312da 100644 --- a/config/initializers/shoryuken.rb +++ b/config/initializers/shoryuken.rb @@ -1,6 +1,5 @@ require "#{Rails.root}/app/jobs/middleware/job_metrics_service_metric_middleware" - # set up default exponential backoff parameters ActiveJob::QueueAdapters::ShoryukenAdapter::JobWrapper .shoryuken_options(auto_visibility_timeout: true, From db93fa2d2c76e374f734803bf96685c20dda5a34 Mon Sep 17 00:00:00 2001 From: AKeyframe <89286339+AKeyframe@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:41:52 -0500 Subject: [PATCH 34/42] Cosmetic Update config/initializers/shoryuken.rb Co-authored-by: Jeremy Croteau --- config/initializers/shoryuken.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/shoryuken.rb b/config/initializers/shoryuken.rb index 9026312da..b508b0c3c 100644 --- a/config/initializers/shoryuken.rb +++ b/config/initializers/shoryuken.rb @@ -3,7 +3,7 @@ # set up default exponential backoff parameters ActiveJob::QueueAdapters::ShoryukenAdapter::JobWrapper .shoryuken_options(auto_visibility_timeout: true, - retry_intervals: [5.seconds, 5.minutes, rand(4..8).hours]) + retry_intervals: [5.seconds, 5.minutes, rand(4..8).hours]) if Rails.application.config.sqs_endpoint # override the sqs_endpoint From 1d9bd66a1efbd98ffb24ae9239f30900e30cf9a2 Mon Sep 17 00:00:00 2001 From: AKeyframe <89286339+AKeyframe@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:42:17 -0500 Subject: [PATCH 35/42] Cosmetic Update lib/fakes/test_auth_strategy.rb Co-authored-by: Jeremy Croteau --- lib/fakes/test_auth_strategy.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/fakes/test_auth_strategy.rb b/lib/fakes/test_auth_strategy.rb index 38f0ba5d0..9193f972b 100644 --- a/lib/fakes/test_auth_strategy.rb +++ b/lib/fakes/test_auth_strategy.rb @@ -1,7 +1,6 @@ require "omniauth/strategies/developer" require "omniauth/form" - module Fakes module TestAuthStrategy class EfolderAuthForm < OmniAuth::Form From f2f2d371e289d7df5a270f43450be878cb7e9bb1 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Wed, 9 Oct 2024 08:52:30 -0500 Subject: [PATCH 36/42] Added after_initialize to prevent multiple subscribers on relead --- .../deprecation_warning_subscriber.rb | 94 ++++++++++--------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/config/initializers/deprecation_warning_subscriber.rb b/config/initializers/deprecation_warning_subscriber.rb index 26fe96972..c8abd92ff 100644 --- a/config/initializers/deprecation_warning_subscriber.rb +++ b/config/initializers/deprecation_warning_subscriber.rb @@ -3,51 +3,53 @@ # @note For use in conjuction with setting `Rails.application.config.active_support.deprecation = :notify`. # Whenever a “deprecation.rails” notification is published, it will dispatch the event # (ActiveSupport::Notifications::Event) to method #deprecation. -class DeprecationWarningSubscriber < ActiveSupport::Subscriber - APP_NAME = "efolder" - SLACK_ALERT_CHANNEL = "#appeals-deprecation-alerts" - - attach_to :rails - - def deprecation(event) - emit_warning_to_application_logs(event) - emit_warning_to_sentry(event) - ## Skip until we have ENV["SSL_CERT_FILE"] set in eFolder environments, as needed by SlackService - # emit_warning_to_slack_alerts_channel(event) - rescue StandardError => error - Raven.capture_exception(error) - end - - private - - def emit_warning_to_application_logs(event) - Rails.logger.warn(event.payload[:message]) - end - - def emit_warning_to_sentry(event) - # Need to convert callstack elements from `Thread::Backtrace::Location` objects to `Strings` - # to avoid a `TypeError` on `options.deep_dup` in `Raven.capture_message`: - # https://github.com/getsentry/sentry-ruby/blob/2e07e0295ba83df4c76c7bf3315d199c7050a7f9/lib/raven/instance.rb#L114 - callstack_strings = event.payload[:callstack].map(&:to_s) - - Raven.capture_message( - event.payload[:message], - level: "warning", - extra: { - message: event.payload[:message], - gem_name: event.payload[:gem_name], - deprecation_horizon: event.payload[:deprecation_horizon], - callstack: callstack_strings, - environment: Rails.env - } - ) - end - - def emit_warning_to_slack_alerts_channel(event) - slack_alert_title = "Deprecation Warning - #{APP_NAME} (#{ENV['DEPLOY_ENV']})" - - SlackService - .new(url: ENV["SLACK_DISPATCH_ALERT_URL"]) - .send_notification(event.payload[:message], slack_alert_title, SLACK_ALERT_CHANNEL) +Rails.application.config.after_initialize do + class DeprecationWarningSubscriber < ActiveSupport::Subscriber + APP_NAME = "efolder" + SLACK_ALERT_CHANNEL = "#appeals-deprecation-alerts" + + attach_to :rails + + def deprecation(event) + emit_warning_to_application_logs(event) + emit_warning_to_sentry(event) + ## Skip until we have ENV["SSL_CERT_FILE"] set in eFolder environments, as needed by SlackService + # emit_warning_to_slack_alerts_channel(event) + rescue StandardError => error + Raven.capture_exception(error) + end + + private + + def emit_warning_to_application_logs(event) + Rails.logger.warn(event.payload[:message]) + end + + def emit_warning_to_sentry(event) + # Need to convert callstack elements from `Thread::Backtrace::Location` objects to `Strings` + # to avoid a `TypeError` on `options.deep_dup` in `Raven.capture_message`: + # https://github.com/getsentry/sentry-ruby/blob/2e07e0295ba83df4c76c7bf3315d199c7050a7f9/lib/raven/instance.rb#L114 + callstack_strings = event.payload[:callstack].map(&:to_s) + + Raven.capture_message( + event.payload[:message], + level: "warning", + extra: { + message: event.payload[:message], + gem_name: event.payload[:gem_name], + deprecation_horizon: event.payload[:deprecation_horizon], + callstack: callstack_strings, + environment: Rails.env + } + ) + end + + def emit_warning_to_slack_alerts_channel(event) + slack_alert_title = "Deprecation Warning - #{APP_NAME} (#{ENV['DEPLOY_ENV']})" + + SlackService + .new(url: ENV["SLACK_DISPATCH_ALERT_URL"]) + .send_notification(event.payload[:message], slack_alert_title, SLACK_ALERT_CHANNEL) + end end end From 8847fb91947701bfc9a973215bdb8dca90052fcb Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Wed, 9 Oct 2024 08:54:05 -0500 Subject: [PATCH 37/42] Added before_initialize so Error class is loaded before anything else --- config/initializers/{errors.rb => standard_errors.rb} | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename config/initializers/{errors.rb => standard_errors.rb} (51%) diff --git a/config/initializers/errors.rb b/config/initializers/standard_errors.rb similarity index 51% rename from config/initializers/errors.rb rename to config/initializers/standard_errors.rb index f71765294..39bc6a6b8 100644 --- a/config/initializers/errors.rb +++ b/config/initializers/standard_errors.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true # monkeypatch some error classes to conform with BGS/VBMS error classes. - -class StandardError - def ignorable? - false +Rails.application.config.before_initialize do + class StandardError + def ignorable? + false + end end end From 6f3d9c8fc3e51fda163443e3e3dd1fb9d2e4471f Mon Sep 17 00:00:00 2001 From: Jeremy Croteau Date: Wed, 9 Oct 2024 18:28:22 -0400 Subject: [PATCH 38/42] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Fix=20typo=20in=20fi?= =?UTF-8?q?lename?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/initializers/{standard_errors.rb => standard_error.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename config/initializers/{standard_errors.rb => standard_error.rb} (100%) diff --git a/config/initializers/standard_errors.rb b/config/initializers/standard_error.rb similarity index 100% rename from config/initializers/standard_errors.rb rename to config/initializers/standard_error.rb From 2593d26986f5a716edd01a908de2a7b791454cf2 Mon Sep 17 00:00:00 2001 From: Jeremy Croteau Date: Wed, 9 Oct 2024 19:01:29 -0400 Subject: [PATCH 39/42] =?UTF-8?q?=F0=9F=9A=9A=20Move=20spec=20file=20to=20?= =?UTF-8?q?proper=20location?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .rubocop_todo.yml | 16 +++++++--------- .../{ => external_api}/bgs_service_spec.rb | 0 2 files changed, 7 insertions(+), 9 deletions(-) rename spec/services/{ => external_api}/bgs_service_spec.rb (100%) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 61b253d9e..dce59c222 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-10-04 20:06:20 -0500 using RuboCop version 0.83.0. +# on 2024-10-09 19:23:15 -0400 using RuboCop version 0.83.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -62,13 +62,12 @@ Layout/EmptyLineBetweenDefs: Exclude: - 'app/services/manifest_fetcher.rb' -# Offense count: 3 +# Offense count: 2 # Cop supports --auto-correct. Layout/EmptyLines: Exclude: - 'app/services/external_api/bgs_service.rb' - 'app/services/manifest_fetcher.rb' - - 'lib/fakes/test_auth_strategy.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -128,7 +127,7 @@ Layout/FirstHashElementIndentation: Layout/HashAlignment: Exclude: - 'spec/requests/api/v2/manifests_spec.rb' - - 'spec/services/bgs_service_spec.rb' + - 'spec/services/external_api/bgs_service_spec.rb' - 'spec/services/user_authorizer_spec.rb' - 'spec/services/veteran_finder_spec.rb' @@ -148,11 +147,10 @@ Layout/LeadingCommentSpace: - 'ci-bin/concatenate-log.rb' - 'spec/rails_helper.rb' -# Offense count: 2 +# Offense count: 1 # Cop supports --auto-correct. Layout/LeadingEmptyLines: Exclude: - - 'app/services/external_api/vbms_service.rb' - 'lib/fakes/bgs_service.rb' # Offense count: 9 @@ -171,7 +169,7 @@ Layout/MultilineMethodCallIndentation: # SupportedStylesForExponentOperator: space, no_space Layout/SpaceAroundOperators: Exclude: - - 'spec/services/bgs_service_spec.rb' + - 'spec/services/external_api/bgs_service_spec.rb' - 'spec/services/user_authorizer_spec.rb' # Offense count: 1 @@ -215,7 +213,7 @@ Layout/SpaceInsideBlockBraces: # SupportedStylesForEmptyBraces: space, no_space Layout/SpaceInsideHashLiteralBraces: Exclude: - - 'spec/services/bgs_service_spec.rb' + - 'spec/services/external_api/bgs_service_spec.rb' # Offense count: 3 # Cop supports --auto-correct. @@ -391,7 +389,7 @@ Style/FormatStringToken: # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys Style/HashSyntax: Exclude: - - 'spec/services/bgs_service_spec.rb' + - 'spec/services/external_api/bgs_service_spec.rb' - 'spec/services/user_authorizer_spec.rb' # Offense count: 3 diff --git a/spec/services/bgs_service_spec.rb b/spec/services/external_api/bgs_service_spec.rb similarity index 100% rename from spec/services/bgs_service_spec.rb rename to spec/services/external_api/bgs_service_spec.rb From a7fe2f772a2e6c14db57a0352518a64d089fab69 Mon Sep 17 00:00:00 2001 From: Jeremy Croteau Date: Tue, 15 Oct 2024 14:02:18 -0400 Subject: [PATCH 40/42] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Lexically=20order=20?= =?UTF-8?q?filters=20in=20.simplecov?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .simplecov | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.simplecov b/.simplecov index 7ee2d5008..aed9a0214 100644 --- a/.simplecov +++ b/.simplecov @@ -1,17 +1,17 @@ if ENV["RAILS_ENV"] == "test" SimpleCov.start do + add_filter "app/controllers/errors_controller.rb" add_filter "app/services/test_data_service.rb" + add_filter "config/environments/test.rb" + add_filter "config/initializers" add_filter "lib/fakes" add_filter "lib/generators" - add_filter "spec/support" - add_filter "spec/rails_helper.rb" - add_filter "spec/spec_helper.rb" - add_filter "config/initializers" - add_filter "config/environments/test.rb" add_filter "lib/tasks" - add_filter "app/controllers/errors_controller.rb" - add_filter "spec/factories" add_filter "spec/" + add_filter "spec/factories" + add_filter "spec/rails_helper.rb" + add_filter "spec/spec_helper.rb" + add_filter "spec/support" end SimpleCov.coverage_dir ENV["COVERAGE_DIR"] || nil SimpleCov.command_name ENV["TEST_SUBCATEGORY"] || "all" From 816a735519a64c954d825183feed14b81a83f841 Mon Sep 17 00:00:00 2001 From: Jeremy Croteau Date: Tue, 15 Oct 2024 14:07:50 -0400 Subject: [PATCH 41/42] =?UTF-8?q?=F0=9F=94=A7=20Filter=20`lib/efolder/migr?= =?UTF-8?q?ation.rb`=20from=20simplecov=20coverage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .simplecov | 1 + 1 file changed, 1 insertion(+) diff --git a/.simplecov b/.simplecov index aed9a0214..2195e2327 100644 --- a/.simplecov +++ b/.simplecov @@ -4,6 +4,7 @@ if ENV["RAILS_ENV"] == "test" add_filter "app/services/test_data_service.rb" add_filter "config/environments/test.rb" add_filter "config/initializers" + add_filter "lib/efolder/migration.rb" add_filter "lib/fakes" add_filter "lib/generators" add_filter "lib/tasks" From 9f06bce4af9e918f27151672eff1540aa27496fa Mon Sep 17 00:00:00 2001 From: Jeremy Croteau Date: Thu, 31 Oct 2024 10:16:34 -0400 Subject: [PATCH 42/42] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Update=20`caseflow-c?= =?UTF-8?q?ommons`=20dependecy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index fc470f20a..8b456abf3 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,7 @@ gem "aws-sdk-s3" gem "aws-sdk-sqs" gem "bgs", git: "https://github.com/department-of-veterans-affairs/ruby-bgs.git", ref: "a2e055b5a52bd1e2bb8c2b3b8d5820b1a404cd3d" gem "bootsnap", require: false -gem "caseflow", git: "https://github.com/department-of-veterans-affairs/caseflow-commons", branch: "AlecK/Zeitwerk" # ref: "9bd3635fbd8094d25160669f38d8699e2f1d7a98" +gem "caseflow", git: "https://github.com/department-of-veterans-affairs/caseflow-commons", ref: "dbd86859856d161d84b0bba4d67a8b62e4684996" gem "coffee-rails", "> 4.1.0" gem "connect_vbms", git: "https://github.com/department-of-veterans-affairs/connect_vbms.git", branch: "master" gem "connect_vva", git: "https://github.com/department-of-veterans-affairs/connect_vva.git", ref: "dfd1aeb2605c1f237f520bcdc41b059202e8944d" diff --git a/Gemfile.lock b/Gemfile.lock index 104d1ad26..01b1faf22 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -20,8 +20,8 @@ GIT GIT remote: https://github.com/department-of-veterans-affairs/caseflow-commons - revision: 298c0a10c67920ad98251c0a9f3bd37abf408c35 - branch: AlecK/Zeitwerk + revision: dbd86859856d161d84b0bba4d67a8b62e4684996 + ref: dbd86859856d161d84b0bba4d67a8b62e4684996 specs: caseflow (0.4.8) aws-sdk-s3