diff --git a/.rubocop.yml b/.rubocop.yml index bd23d84..4aa0b2c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,16 @@ +inherit_from: .rubocop_todo.yml + +inherit_mode: + merge: + - Exclude + - Include + +inherit_gem: + rubocop-gusto: + - config/default.yml + plugins: - - rubocop-sorbet - - rubocop-performance + - rubocop-gusto AllCops: TargetRubyVersion: 3.3 @@ -10,7 +20,7 @@ AllCops: - bin/**/* - vendor/**/* -Sorbet/StrictSigil: +Gemspec/RequireMFA: Enabled: false Layout/ExtraSpacing: @@ -18,70 +28,77 @@ Layout/ExtraSpacing: Exclude: - danger-packwerk.gemspec +Layout/LineLength: + Enabled: false + Layout/SpaceAroundOperators: Enabled: true Exclude: - danger-packwerk.gemspec -Sorbet/ValidSigil: - Enabled: true - -Gemspec/RequireMFA: +Lint/UnusedMethodArgument: Enabled: false -Layout/LineLength: +Metrics/AbcSize: Enabled: false Metrics/BlockLength: Enabled: false -Style/Documentation: +Metrics/ClassLength: Enabled: false -Style/SignalException: +Metrics/CyclomaticComplexity: Enabled: false -Style/MultilineBlockChain: +Metrics/MethodLength: Enabled: false -Metrics/MethodLength: +Metrics/ModuleLength: Enabled: false -Metrics/CyclomaticComplexity: +Metrics/ParameterLists: Enabled: false -Metrics/ModuleLength: +Metrics/PerceivedComplexity: Enabled: false -Metrics/ClassLength: +Naming/BlockForwarding: Enabled: false +RSpec/NotToNot: + Enabled: true + Sorbet/FalseSigil: Enabled: false -Lint/UnusedMethodArgument: +Sorbet/StrictSigil: Enabled: false -Metrics/AbcSize: - Enabled: false +Sorbet/ValidSigil: + Enabled: true -Style/GuardClause: +Style/ArgumentsForwarding: Enabled: false -Style/NumericPredicate: +Style/Documentation: Enabled: false -Metrics/PerceivedComplexity: +Style/GuardClause: Enabled: false -Metrics/ParameterLists: +Style/MultilineBlockChain: Enabled: false -Style/SuperArguments: +Style/NumericPredicate: Enabled: false -Style/ArgumentsForwarding: +Style/SignalException: Enabled: false -Naming/BlockForwarding: +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes + +Style/SuperArguments: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..d67a453 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,37 @@ +# This configuration was generated by +# `rubocop --auto-gen-config --exclude-limit 10000` +# on 2026-11-30 21:02:31 UTC using RuboCop version 1.92.1. +# 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: 1 +Gusto/NoMetaprogramming: + Exclude: + - 'lib/chatwerk/views/base_view.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Gusto/RegexpBypass: + Exclude: + - 'lib/chatwerk/helpers.rb' + +# Offense count: 22 +# This cop supports unsafe autocorrection (--autocorrect-all). +RSpec/VerifiedDoubleReference: + Exclude: + - 'spec/chatwerk/api_spec.rb' + - 'spec/chatwerk/error_spec.rb' + - 'spec/chatwerk/helpers_spec.rb' + - 'spec/chatwerk/views/no_violations_view_spec.rb' + - 'spec/chatwerk/views/package_view_spec.rb' + - 'spec/chatwerk/views/packages_view_spec.rb' + - 'spec/chatwerk/views/violations_details_view_spec.rb' + - 'spec/chatwerk/views/violations_list_view_spec.rb' + +# Offense count: 1 +# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. +RSpec/VerifiedDoubles: + Exclude: + - 'spec/chatwerk/mcp_tools_spec.rb' diff --git a/Gemfile b/Gemfile index f38507a..816aa4b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,16 +1,17 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in chatwerk.gemspec gemspec -gem 'irb' -gem 'rake', '~> 13.4' +gem "irb" +gem "rake", "~> 13.4" -gem 'rspec', '~> 3.13' +gem "rspec", "~> 3.13" -gem 'rubocop', '~> 1.92' -gem 'rubocop-performance' -gem 'rubocop-sorbet' -gem 'sorbet', '~> 0.6' +gem "rubocop", "~> 1.92" +gem "rubocop-gusto", require: false +gem "rubocop-performance" +gem "rubocop-sorbet" +gem "sorbet", "~> 0.6" diff --git a/Gemfile.lock b/Gemfile.lock index 88caab7..40de8b4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,6 +42,8 @@ GEM smart_properties bigdecimal (4.1.3) builder (3.3.0) + code_teams (1.3.1) + sorbet-runtime coderay (1.1.3) concurrent-ruby (1.3.8) connection_pool (3.0.2) @@ -181,10 +183,26 @@ GEM rubocop-ast (1.50.0) parser (>= 3.3.7.2) prism (~> 1.7) + rubocop-gusto (11.12.0) + code_teams + lint_roller + rubocop (>= 1.76) + rubocop-performance + rubocop-rake + rubocop-rspec + rubocop-sorbet (>= 0.13.0) + smart_todo + thor rubocop-performance (1.27.0) lint_roller (~> 1.1) rubocop (>= 1.89.0, < 2.0) rubocop-ast (>= 1.47.1, < 2.0) + rubocop-rake (0.7.1) + lint_roller (~> 1.1) + rubocop (>= 1.72.1) + rubocop-rspec (3.11.0) + lint_roller (~> 1.1) + rubocop (~> 1.92) rubocop-sorbet (0.17.2) rbi (~> 0.4, >= 0.4.3) rbs (>= 4.1.1) @@ -193,6 +211,8 @@ GEM securerandom (0.4.1) simpleidn (0.3.0) smart_properties (1.17.0) + smart_todo (1.11.0) + prism (~> 1.0) sorbet (0.6.13593) sorbet-static (= 0.6.13593) sorbet-runtime (0.6.13593) @@ -238,6 +258,7 @@ DEPENDENCIES rake (~> 13.4) rspec (~> 3.13) rubocop (~> 1.92) + rubocop-gusto rubocop-performance rubocop-sorbet sorbet (~> 0.6) diff --git a/Rakefile b/Rakefile index 4964751..9a7fd8d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,12 @@ # frozen_string_literal: true -require 'bundler/gem_tasks' -require 'rspec/core/rake_task' +require "bundler/gem_tasks" +require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) -require 'rubocop/rake_task' +require "rubocop/rake_task" RuboCop::RakeTask.new -task default: %i[spec rubocop] +task default: %i(spec rubocop) diff --git a/chatwerk.gemspec b/chatwerk.gemspec index 63688e3..181fce7 100644 --- a/chatwerk.gemspec +++ b/chatwerk.gemspec @@ -1,41 +1,41 @@ # frozen_string_literal: true -require_relative 'lib/chatwerk/version' +require_relative "lib/chatwerk/version" Gem::Specification.new do |spec| - spec.name = 'chatwerk' + spec.name = "chatwerk" spec.version = Chatwerk::VERSION - spec.authors = ['Gusto Engineering'] - spec.email = ['dev@gusto.com'] + spec.authors = ["Gusto Engineering"] + spec.email = ["dev@gusto.com"] - spec.summary = 'Chatwerk: AI integration for Packwerk' - spec.description = 'MCP server and API for integrating Packwerk with AI tools like Cursor.' - spec.homepage = 'https://github.com/rubyatscale/chatwerk' - spec.license = 'MIT' - spec.required_ruby_version = '>= 3.3' + spec.summary = "Chatwerk: AI integration for Packwerk" + spec.description = "MCP server and API for integrating Packwerk with AI tools like Cursor." + spec.homepage = "https://github.com/rubyatscale/chatwerk" + spec.license = "MIT" + spec.required_ruby_version = ">= 3.3" - spec.metadata['allowed_push_host'] = 'https://rubygems.org' + spec.metadata["allowed_push_host"] = "https://rubygems.org" - spec.metadata['homepage_uri'] = spec.homepage - spec.metadata['source_code_uri'] = 'https://github.com/rubyatscale/chatwerk' - spec.metadata['changelog_uri'] = 'https://github.com/rubyatscale/chatwerk/blob/main/CHANGELOG.md' + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/rubyatscale/chatwerk" + spec.metadata["changelog_uri"] = "https://github.com/rubyatscale/chatwerk/blob/main/CHANGELOG.md" # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. gemspec = File.basename(__FILE__) - spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls| + spec.files = IO.popen(%w(git ls-files -z), chdir: __dir__, err: IO::NULL) do |ls| ls.readlines("\x0", chomp: true).reject do |f| (f == gemspec) || - f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile]) + f.start_with?(*%w(bin/ test/ spec/ features/ .git .github appveyor Gemfile)) end end - spec.bindir = 'exe' - spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } - spec.require_paths = ['lib'] + spec.bindir = "exe" + spec.executables = spec.files.grep(%r(\Aexe/)) { |f| File.basename(f) } + spec.require_paths = ["lib"] - spec.add_dependency 'mcp' - spec.add_dependency 'query_packwerk', '~> 0.1' - spec.add_dependency 'sorbet-runtime' - spec.add_dependency 'thor' - spec.add_dependency 'zeitwerk' + spec.add_dependency "mcp" + spec.add_dependency "query_packwerk", "~> 0.1" + spec.add_dependency "sorbet-runtime" + spec.add_dependency "thor" + spec.add_dependency "zeitwerk" end diff --git a/config.ru b/config.ru index e4273be..22a342a 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,5 @@ +# typed: false # frozen_string_literal: true -require 'chatwerk' +require "chatwerk" run Chatwerk::MCPServer.new diff --git a/exe/chatwerk b/exe/chatwerk index fdb440f..10612cd 100755 --- a/exe/chatwerk +++ b/exe/chatwerk @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require 'chatwerk' +require "chatwerk" Chatwerk::Cli.start(ARGV) diff --git a/lib/chatwerk.rb b/lib/chatwerk.rb index 2cce3ae..1f39eb0 100644 --- a/lib/chatwerk.rb +++ b/lib/chatwerk.rb @@ -1,10 +1,10 @@ # typed: strict # frozen_string_literal: true -require 'zeitwerk' -require 'query_packwerk' -require 'sorbet-runtime' -require 'chatwerk/version' +require "zeitwerk" +require "query_packwerk" +require "sorbet-runtime" +require "chatwerk/version" loader = Zeitwerk::Loader.for_gem loader.setup diff --git a/lib/chatwerk/api.rb b/lib/chatwerk/api.rb index bdce990..78dcbf6 100644 --- a/lib/chatwerk/api.rb +++ b/lib/chatwerk/api.rb @@ -1,7 +1,7 @@ # typed: strict # frozen_string_literal: true -require 'yaml' +require "yaml" module Chatwerk module Api @@ -18,16 +18,16 @@ def print_env msg end - def packages(package_path: '') + def packages(package_path: "") packages = Helpers.all_packages(package_path) if packages.empty? - has_packwerk_yml = File.exist?('packwerk.yml') + has_packwerk_yml = File.exist?("packwerk.yml") Views::NoPackagesView.render(has_packwerk_yml:) else Views::PackagesView.render(packages:) end - rescue StandardError => e + rescue => e raise Chatwerk::Error.new(e, package_path:) end @@ -35,11 +35,11 @@ def package(package_path:) package = Helpers.find_package(package_path) Views::PackageView.render(package:) - rescue StandardError => e + rescue => e raise Chatwerk::Error.new(e, package_path:) end - def package_todos(package_path:, constant_name: '') + def package_todos(package_path:, constant_name: "") package = Helpers.find_package(package_path) constant_name = Helpers.normalize_constant_name(constant_name) violations = package.todos @@ -49,11 +49,11 @@ def package_todos(package_path:, constant_name: '') else Views::ViolationsDetailsView.render(package:, violations:, constant_name:) end - rescue StandardError => e + rescue => e raise Chatwerk::Error.new(e, package_path:, constant_name:) end - def package_violations(package_path:, constant_name: '') + def package_violations(package_path:, constant_name: "") package = Helpers.find_package(package_path) constant_name = Helpers.normalize_constant_name(constant_name) violations = package.violations @@ -63,7 +63,7 @@ def package_violations(package_path:, constant_name: '') else Views::ViolationsDetailsView.render(package:, violations:, constant_name:) end - rescue StandardError => e + rescue => e raise Chatwerk::Error.new(e, package_path:, constant_name:) end end diff --git a/lib/chatwerk/cli.rb b/lib/chatwerk/cli.rb index 28e19ae..60465e3 100644 --- a/lib/chatwerk/cli.rb +++ b/lib/chatwerk/cli.rb @@ -1,55 +1,56 @@ +# typed: false # frozen_string_literal: true -require 'thor' +require "thor" module Chatwerk # CLI interface for Chatwerk using Thor class Cli < Thor - desc 'mcp', 'Start the Model Context Protocol server in stdio mode' + desc "mcp", "Start the Model Context Protocol server in stdio mode" def mcp - require_relative 'mcp' - require 'mcp/transports/stdio' + require_relative "mcp" + require "mcp/transports/stdio" server = Chatwerk::Mcp.server transport = MCP::Transports::StdioTransport.new(server) transport.open end - desc 'inspect [WORKING_DIRECTORY]', 'Run the MCP inspector with an optional working directory path (defaults to current directory)' + desc "inspect [WORKING_DIRECTORY]", "Run the MCP inspector with an optional working directory path (defaults to current directory)" def inspect(working_directory = nil) pwd = working_directory || Dir.pwd - system('npx', '@modelcontextprotocol/inspector', '-e', "PWD=#{pwd}", 'bundle', 'exec', 'exe/chatwerk', 'mcp') + system("npx", "@modelcontextprotocol/inspector", "-e", "PWD=#{pwd}", "bundle", "exec", "exe/chatwerk", "mcp") end - desc 'print_env', 'Show current environment details' + desc "print_env", "Show current environment details" def print_env puts Api.print_env end - desc 'packages [PACKAGE_PATH]', 'List all valid packwerk packages, optionally filtered by package path' + desc "packages [PACKAGE_PATH]", "List all valid packwerk packages, optionally filtered by package path" def packages(package_path = nil) puts Api.packages(package_path:) end - desc 'package PACKAGE_PATH', 'Show details for a specific package' + desc "package PACKAGE_PATH", "Show details for a specific package" def package(package_path) puts Api.package(package_path:) end - desc 'package_todos PACKAGE_PATH [CONSTANT_NAME]', 'Show dependency violations FROM this package TO others' + desc "package_todos PACKAGE_PATH [CONSTANT_NAME]", "Show dependency violations FROM this package TO others" def package_todos(package_path, constant_name = nil) puts Api.package_todos(package_path:, constant_name:) end - desc 'package_violations PACKAGE_PATH [CONSTANT_NAME]', 'Show dependency violations TO this package FROM others' + desc "package_violations PACKAGE_PATH [CONSTANT_NAME]", "Show dependency violations TO this package FROM others" def package_violations(package_path, constant_name = nil) puts Api.package_violations(package_path:, constant_name:) end - desc 'version', 'Display Chatwerk version' + desc "version", "Display Chatwerk version" def version puts "Chatwerk #{Chatwerk::VERSION}" end - map %w[--version -v] => :version + map %w(--version -v) => :version def self.exit_on_failure? true diff --git a/lib/chatwerk/error.rb b/lib/chatwerk/error.rb index 9493f46..c124af7 100644 --- a/lib/chatwerk/error.rb +++ b/lib/chatwerk/error.rb @@ -1,14 +1,14 @@ +# typed: false # frozen_string_literal: true module Chatwerk class Error < RuntimeError def initialize(error, package_path: nil, **args) - message = - if package_path && !package_path.empty? - "There was a problem finding or accessing #{package_path.inspect}" - else - 'There was a problem accessing package information' - end + if package_path && !package_path.empty? + message = "There was a problem finding or accessing #{package_path.inspect}" + else + message = "There was a problem accessing package information" + end super(<<~ERROR) #{message} diff --git a/lib/chatwerk/helpers.rb b/lib/chatwerk/helpers.rb index face5bb..d358882 100644 --- a/lib/chatwerk/helpers.rb +++ b/lib/chatwerk/helpers.rb @@ -1,3 +1,4 @@ +# typed: false # frozen_string_literal: true module Chatwerk @@ -8,7 +9,7 @@ def chdir(&) module_function :chdir def env_pwd - path = ENV.fetch('PWD', pwd) + path = ENV.fetch("PWD", pwd) # Use realpath if the path exists, otherwise fall back to expand_path File.directory?(path) ? File.realpath(path) : File.expand_path(path) end @@ -21,22 +22,22 @@ def pwd def normalize_package_path(package_path) package_path = package_path.to_s.strip - package_path = package_path.delete_prefix('/') - package_path = package_path.delete_suffix('/package.yml') - package_path = package_path.delete_suffix('/package_todo.yml') - package_path.delete_suffix('/') + package_path = package_path.delete_prefix("/") + package_path = package_path.delete_suffix("/package.yml") + package_path = package_path.delete_suffix("/package_todo.yml") + package_path.delete_suffix("/") end module_function :normalize_package_path def normalize_constant_name(constant_name) constant_name = constant_name.to_s.strip - return '' if constant_name.empty? + return "" if constant_name.empty? - constant_name.sub(/^(::)?/, '::') + constant_name.sub(/^(::)?/, "::") end module_function :normalize_constant_name - def all_packages(path_pattern = '') + def all_packages(path_pattern = "") path_pattern = normalize_package_path(path_pattern) if path_pattern.empty? QueryPackwerk::Packages.all.to_a diff --git a/lib/chatwerk/mcp.rb b/lib/chatwerk/mcp.rb index 6c29972..54c4a34 100644 --- a/lib/chatwerk/mcp.rb +++ b/lib/chatwerk/mcp.rb @@ -1,6 +1,7 @@ +# typed: false # frozen_string_literal: true -require 'mcp' +require "mcp" module Chatwerk # MCP Server setup @@ -8,20 +9,20 @@ class Mcp def self.server # Set up the server with all tools MCP::Server.new( - name: name, + name:, version: Chatwerk::VERSION, tools: [ Tools::PrintEnvTool, Tools::PackagesTool, Tools::PackageTool, Tools::PackageTodosTool, - Tools::PackageViolationsTool + Tools::PackageViolationsTool, ] ) end def self.name - 'chatwerk' + "chatwerk" end end end diff --git a/lib/chatwerk/tools/package_todos_tool.rb b/lib/chatwerk/tools/package_todos_tool.rb index fc3d2e7..22f7149 100644 --- a/lib/chatwerk/tools/package_todos_tool.rb +++ b/lib/chatwerk/tools/package_todos_tool.rb @@ -1,6 +1,7 @@ +# typed: false # frozen_string_literal: true -require 'mcp' +require "mcp" module Chatwerk module Tools @@ -23,26 +24,30 @@ class PackageTodosTool < MCP::Tool input_schema( properties: { package_path: { - type: 'string', - description: "The relative path of a directory containing a package.yml file (e.g. 'packs/product_services/payments/origination_banks')." + type: "string", + description: "The relative path of a directory containing a package.yml file (e.g. 'packs/product_services/payments/origination_banks').", }, constant_name: { - type: 'string', - description: "The name of a constant to filter the results by. If provided, a more detailed list of code usage examples will be returned. (e.g. '::OtherPackage::SomeClass')" - } + type: "string", + description: "The name of a constant to filter the results by. If provided, a more detailed list of code usage examples will be returned. (e.g. '::OtherPackage::SomeClass')", + }, }, - required: ['package_path'] + required: ["package_path"] ) class << self def call(package_path:, server_context:, constant_name: nil) Helpers.chdir - result = Api.package_todos(package_path: package_path, constant_name: constant_name) + result = Api.package_todos(package_path:, constant_name:) - MCP::Tool::Response.new([{ - type: 'text', - text: result - }]) + MCP::Tool::Response.new( + [ + { + type: "text", + text: result, + }, + ] + ) end end end diff --git a/lib/chatwerk/tools/package_tool.rb b/lib/chatwerk/tools/package_tool.rb index a28fb14..78face1 100644 --- a/lib/chatwerk/tools/package_tool.rb +++ b/lib/chatwerk/tools/package_tool.rb @@ -1,6 +1,7 @@ +# typed: false # frozen_string_literal: true -require 'mcp' +require "mcp" module Chatwerk module Tools @@ -16,22 +17,26 @@ class PackageTool < MCP::Tool input_schema( properties: { package_path: { - type: 'string', - description: "A full relative package path (e.g. 'packs/product_services/payments/banks')." - } + type: "string", + description: "A full relative package path (e.g. 'packs/product_services/payments/banks').", + }, }, - required: ['package_path'] + required: ["package_path"] ) class << self def call(package_path:, server_context:) Helpers.chdir - result = Api.package(package_path: package_path) + result = Api.package(package_path:) - MCP::Tool::Response.new([{ - type: 'text', - text: result - }]) + MCP::Tool::Response.new( + [ + { + type: "text", + text: result, + }, + ] + ) end end end diff --git a/lib/chatwerk/tools/package_violations_tool.rb b/lib/chatwerk/tools/package_violations_tool.rb index ed0f532..1bb6440 100644 --- a/lib/chatwerk/tools/package_violations_tool.rb +++ b/lib/chatwerk/tools/package_violations_tool.rb @@ -1,6 +1,7 @@ +# typed: false # frozen_string_literal: true -require 'mcp' +require "mcp" module Chatwerk module Tools @@ -24,26 +25,30 @@ class PackageViolationsTool < MCP::Tool input_schema( properties: { package_path: { - type: 'string', - description: "The relative path of a directory containing a package.yml file (e.g. 'packs/product_services/payments/origination_banks'). AKA a 'pack' or 'package'." + type: "string", + description: "The relative path of a directory containing a package.yml file (e.g. 'packs/product_services/payments/origination_banks'). AKA a 'pack' or 'package'.", }, constant_name: { - type: 'string', - description: 'The name of a constant to filter the results by. If provided, a more detailed list of code usage examples will be returned.' - } + type: "string", + description: "The name of a constant to filter the results by. If provided, a more detailed list of code usage examples will be returned.", + }, }, - required: ['package_path'] + required: ["package_path"] ) class << self def call(package_path:, server_context:, constant_name: nil) Helpers.chdir - result = Api.package_violations(package_path: package_path, constant_name: constant_name) + result = Api.package_violations(package_path:, constant_name:) - MCP::Tool::Response.new([{ - type: 'text', - text: result - }]) + MCP::Tool::Response.new( + [ + { + type: "text", + text: result, + }, + ] + ) end end end diff --git a/lib/chatwerk/tools/packages_tool.rb b/lib/chatwerk/tools/packages_tool.rb index df45dba..62899b4 100644 --- a/lib/chatwerk/tools/packages_tool.rb +++ b/lib/chatwerk/tools/packages_tool.rb @@ -1,6 +1,7 @@ +# typed: false # frozen_string_literal: true -require 'mcp' +require "mcp" module Chatwerk module Tools @@ -14,21 +15,25 @@ class PackagesTool < MCP::Tool input_schema( properties: { package_path: { - type: 'string', - description: "A partial package path name to constrain the results (e.g. 'packs/product_services/payments/banks' or 'payments/banks')." - } + type: "string", + description: "A partial package path name to constrain the results (e.g. 'packs/product_services/payments/banks' or 'payments/banks').", + }, } ) class << self def call(server_context:, package_path: nil) Helpers.chdir - result = Api.packages(package_path: package_path) + result = Api.packages(package_path:) - MCP::Tool::Response.new([{ - type: 'text', - text: result - }]) + MCP::Tool::Response.new( + [ + { + type: "text", + text: result, + }, + ] + ) end end end diff --git a/lib/chatwerk/tools/print_env_tool.rb b/lib/chatwerk/tools/print_env_tool.rb index b797552..0e66424 100644 --- a/lib/chatwerk/tools/print_env_tool.rb +++ b/lib/chatwerk/tools/print_env_tool.rb @@ -1,13 +1,14 @@ +# typed: false # frozen_string_literal: true -require 'mcp' -require_relative '../helpers' +require "mcp" +require_relative "../helpers" module Chatwerk module Tools # Print environment information tool class PrintEnvTool < MCP::Tool - description 'Get the current working directory and environment path of the MCP server, ensuring correct directory context' + description "Get the current working directory and environment path of the MCP server, ensuring correct directory context" input_schema( properties: {} @@ -25,10 +26,14 @@ def call(server_context:) end msg << ENV.to_h.map { |key, value| "#{key}=#{value}" }.join("\n") - MCP::Tool::Response.new([{ - type: 'text', - text: msg - }]) + MCP::Tool::Response.new( + [ + { + type: "text", + text: msg, + }, + ] + ) end end end diff --git a/lib/chatwerk/version.rb b/lib/chatwerk/version.rb index d28d118..406f5bd 100644 --- a/lib/chatwerk/version.rb +++ b/lib/chatwerk/version.rb @@ -1,5 +1,6 @@ +# typed: false # frozen_string_literal: true module Chatwerk - VERSION = '0.1.0' + VERSION = "0.1.0" end diff --git a/lib/chatwerk/views.rb b/lib/chatwerk/views.rb index d162987..32303ae 100644 --- a/lib/chatwerk/views.rb +++ b/lib/chatwerk/views.rb @@ -1,12 +1,13 @@ +# typed: false # frozen_string_literal: true module Chatwerk module Views - autoload :NoPackagesView, 'chatwerk/views/no_packages_view' - autoload :NoViolationsView, 'chatwerk/views/no_violations_view' - autoload :PackageView, 'chatwerk/views/package_view' - autoload :PackagesView, 'chatwerk/views/packages_view' - autoload :ViolationsDetailsView, 'chatwerk/views/violations_details_view' - autoload :ViolationsListView, 'chatwerk/views/violations_list_view' + autoload :NoPackagesView, "chatwerk/views/no_packages_view" + autoload :NoViolationsView, "chatwerk/views/no_violations_view" + autoload :PackageView, "chatwerk/views/package_view" + autoload :PackagesView, "chatwerk/views/packages_view" + autoload :ViolationsDetailsView, "chatwerk/views/violations_details_view" + autoload :ViolationsListView, "chatwerk/views/violations_list_view" end end diff --git a/lib/chatwerk/views/base_view.rb b/lib/chatwerk/views/base_view.rb index 23f98f6..955fdc2 100644 --- a/lib/chatwerk/views/base_view.rb +++ b/lib/chatwerk/views/base_view.rb @@ -1,3 +1,4 @@ +# typed: false # frozen_string_literal: true module Chatwerk @@ -25,11 +26,11 @@ def render private def template(**data) - raise NotImplementedError, 'Subclasses must implement the #template method' + raise NotImplementedError, "Subclasses must implement the #template method" end - def say(message = '') - @output ||= +'' + def say(message = "") + @output ||= +"" @output << message << "\n" end diff --git a/lib/chatwerk/views/no_packages_view.rb b/lib/chatwerk/views/no_packages_view.rb index a935245..504e6fa 100644 --- a/lib/chatwerk/views/no_packages_view.rb +++ b/lib/chatwerk/views/no_packages_view.rb @@ -1,3 +1,4 @@ +# typed: false # frozen_string_literal: true module Chatwerk diff --git a/lib/chatwerk/views/no_violations_view.rb b/lib/chatwerk/views/no_violations_view.rb index ced8503..88ef859 100644 --- a/lib/chatwerk/views/no_violations_view.rb +++ b/lib/chatwerk/views/no_violations_view.rb @@ -1,3 +1,4 @@ +# typed: false # frozen_string_literal: true module Chatwerk diff --git a/lib/chatwerk/views/package_view.rb b/lib/chatwerk/views/package_view.rb index 18d38e2..527102d 100644 --- a/lib/chatwerk/views/package_view.rb +++ b/lib/chatwerk/views/package_view.rb @@ -1,3 +1,4 @@ +# typed: false # frozen_string_literal: true module Chatwerk @@ -8,17 +9,19 @@ def template(package:, package_path: nil) consumers += package.consumer_names consumers.uniq.sort! - say YAML.dump({ - name: package.name, - enforce_dependencies: package.enforce_dependencies, - enforce_privacy: package.enforce_privacy, - owner: package.owner, - metadata: package.metadata, - dependencies: package.dependency_names, - consumers:, - todos_count: package.todos.count, - violations_count: package.violations.count - }.transform_keys(&:to_s)) + say YAML.dump( + { + name: package.name, + enforce_dependencies: package.enforce_dependencies, + enforce_privacy: package.enforce_privacy, + owner: package.owner, + metadata: package.metadata, + dependencies: package.dependency_names, + consumers:, + todos_count: package.todos.count, + violations_count: package.violations.count, + }.transform_keys(&:to_s) + ) end end end diff --git a/lib/chatwerk/views/packages_view.rb b/lib/chatwerk/views/packages_view.rb index 1818480..6bdea7f 100644 --- a/lib/chatwerk/views/packages_view.rb +++ b/lib/chatwerk/views/packages_view.rb @@ -1,3 +1,4 @@ +# typed: false # frozen_string_literal: true module Chatwerk diff --git a/lib/chatwerk/views/violations_details_view.rb b/lib/chatwerk/views/violations_details_view.rb index 6911793..8aa2d51 100644 --- a/lib/chatwerk/views/violations_details_view.rb +++ b/lib/chatwerk/views/violations_details_view.rb @@ -1,3 +1,4 @@ +# typed: false # frozen_string_literal: true module Chatwerk @@ -25,9 +26,9 @@ def grep_formatted_violations(relevant_violations) say "No files found for #{constant} with code: #{code}" if files.empty? files.each do |file_with_line| - file, line = file_with_line.split(':') + file, line = file_with_line.split(":") files_to_violations[file] ||= [] - files_to_violations[file] << { constant:, code:, line: line } + files_to_violations[file] << { constant:, code:, line: } end end end diff --git a/lib/chatwerk/views/violations_list_view.rb b/lib/chatwerk/views/violations_list_view.rb index 3782fd2..9ece944 100644 --- a/lib/chatwerk/views/violations_list_view.rb +++ b/lib/chatwerk/views/violations_list_view.rb @@ -1,3 +1,4 @@ +# typed: false # frozen_string_literal: true module Chatwerk diff --git a/spec/chatwerk/api_spec.rb b/spec/chatwerk/api_spec.rb index 9eb79ba..6b499be 100644 --- a/spec/chatwerk/api_spec.rb +++ b/spec/chatwerk/api_spec.rb @@ -1,43 +1,44 @@ +# typed: false # frozen_string_literal: true RSpec.describe Chatwerk::Api do - let(:pwd) { '/test/workspace' } - let(:package_path) { 'packs/test_package' } - let(:constant_name) { '::TestPackage::TestClass' } - let(:package) { instance_double('Packwerk::Package', name: 'packs/test_package') } - let(:violations) { instance_double('QueryPackwerk::Violations') } - let(:anonymous_source_counts) { { '::TestPackage::TestClass' => { 'example usage' => 1, 'another example' => 2 } } } - let(:anonymous_sources_with_locations) { { '::TestPackage::TestClass' => { 'example usage' => ['app/models/test.rb:1'] } } } + let(:pwd) { "/test/workspace" } + let(:package_path) { "packs/test_package" } + let(:constant_name) { "::TestPackage::TestClass" } + let(:package) { instance_double("Packwerk::Package", name: "packs/test_package") } + let(:violations) { instance_double("QueryPackwerk::Violations") } + let(:anonymous_source_counts) { { "::TestPackage::TestClass" => { "example usage" => 1, "another example" => 2 } } } + let(:anonymous_sources_with_locations) { { "::TestPackage::TestClass" => { "example usage" => ["app/models/test.rb:1"] } } } before do allow(Chatwerk::Helpers).to receive(:chdir) end - describe '.packages' do - context 'when packages exist' do + describe ".packages" do + context "when packages exist" do before do - allow(File).to receive(:exist?).with('packwerk.yml').and_return(true) + allow(File).to receive(:exist?).with("packwerk.yml").and_return(true) allow(Chatwerk::Helpers).to receive(:all_packages).and_return([package]) end - it 'returns the packages view' do + it "returns the packages view" do expect(described_class.packages).to eq("packs/test_package\n") end - it 'accepts an optional package path filter' do + it "accepts an optional package path filter" do expect(Chatwerk::Helpers).to receive(:all_packages).with(package_path).and_return([package]) - described_class.packages(package_path: package_path) + described_class.packages(package_path:) end end - context 'when no packages exist' do + context "when no packages exist" do before do - allow(File).to receive(:exist?).with('packwerk.yml').and_return(true) + allow(File).to receive(:exist?).with("packwerk.yml").and_return(true) allow(Chatwerk::Helpers).to receive(:all_packages).and_return([]) - allow(Chatwerk::Helpers).to receive(:pwd).and_return('/test/workspace') + allow(Chatwerk::Helpers).to receive(:pwd).and_return("/test/workspace") end - it 'returns the no packages view' do + it "returns the no packages view" do expect(described_class.packages).to eq(<<~STRING) 0 packages found. `packwerk.yml` file exists in project root: /test/workspace @@ -49,41 +50,41 @@ end end - context 'when an error occurs' do + context "when an error occurs" do before do - allow(Chatwerk::Helpers).to receive(:all_packages).and_raise(StandardError.new('test error')) + allow(Chatwerk::Helpers).to receive(:all_packages).and_raise(StandardError.new("test error")) end - it 'returns the error view' do + it "returns the error view" do expect { described_class.packages }.to raise_error(Chatwerk::Error) end end end - describe '.package' do + describe ".package" do before do allow(Chatwerk::Helpers).to receive(:all_packages).and_return([package]) # this view is tested well in the views/package_view_spec.rb and it's complicated to render - allow(Chatwerk::Views::PackageView).to receive(:render).with(package:).and_return('package view') + allow(Chatwerk::Views::PackageView).to receive(:render).with(package:).and_return("package view") end - it 'returns the package view' do - expect(described_class.package(package_path: package_path)).to eq('package view') + it "returns the package view" do + expect(described_class.package(package_path:)).to eq("package view") end - context 'when an error occurs' do + context "when an error occurs" do before do - allow(Chatwerk::Helpers).to receive(:all_packages).and_raise(StandardError.new('test error')) + allow(Chatwerk::Helpers).to receive(:all_packages).and_raise(StandardError.new("test error")) end - it 'returns the error view' do - expect { described_class.package(package_path: package_path) }.to raise_error(Chatwerk::Error) + it "returns the error view" do + expect { described_class.package(package_path:) }.to raise_error(Chatwerk::Error) end end end - describe '.package_todos' do - let(:expected_output) { 'test output' } + describe ".package_todos" do + let(:expected_output) { "test output" } before do allow(Chatwerk::Helpers).to receive(:all_packages).and_return([package]) @@ -91,89 +92,89 @@ allow(violations).to receive(:anonymous_sources_with_locations).and_return(anonymous_sources_with_locations) end - it 'returns the violations details view' do - expect(described_class.package_todos(package_path: package_path, constant_name: constant_name)).to eq(<<~STRING) + it "returns the violations details view" do + expect(described_class.package_todos(package_path:, constant_name:)).to eq(<<~STRING) app/models/test.rb 1: example usage STRING end - context 'when no violations found' do - it 'returns the no violations view' do + context "when no violations found" do + it "returns the no violations view" do allow(violations).to receive(:anonymous_sources_with_locations).and_return({}) - expect(described_class.package_todos(package_path: package_path, constant_name: constant_name).strip).to eq(<<~STRING.strip) + expect(described_class.package_todos(package_path:, constant_name:).strip).to eq(<<~STRING.strip) No violations found in "packs/test_package" for "::TestPackage::TestClass". Ensure that constant_name is given in the format of "::ConstantName" or "::ConstantName::NestedConstant". STRING end end - context 'without constant name' do - let(:constant_name) { '' } + context "without constant name" do + let(:constant_name) { "" } - it 'returns the violations list view' do + it "returns the violations list view" do allow(violations).to receive(:anonymous_source_counts).and_return(anonymous_source_counts) - expect(described_class.package_todos(package_path: package_path)).to eq(<<~STRING) + expect(described_class.package_todos(package_path:)).to eq(<<~STRING) ::TestPackage::TestClass (3 violations) STRING end end - context 'when an error occurs' do + context "when an error occurs" do before do - allow(Chatwerk::Helpers).to receive(:all_packages).and_raise(StandardError.new('test error')) + allow(Chatwerk::Helpers).to receive(:all_packages).and_raise(StandardError.new("test error")) end - it 'returns the error view' do - expect { described_class.package_todos(package_path: package_path) }.to raise_error(Chatwerk::Error) + it "returns the error view" do + expect { described_class.package_todos(package_path:) }.to raise_error(Chatwerk::Error) end end end - describe '.package_violations' do - let(:expected_output) { 'test output' } + describe ".package_violations" do + let(:expected_output) { "test output" } before do allow(Chatwerk::Helpers).to receive(:all_packages).and_return([package]) allow(package).to receive(:violations).and_return(violations) end - it 'returns the violations details view' do + it "returns the violations details view" do allow(violations).to receive(:anonymous_sources_with_locations).and_return(anonymous_sources_with_locations) - expect(described_class.package_violations(package_path: package_path, constant_name: constant_name)).to eq(<<~STRING) + expect(described_class.package_violations(package_path:, constant_name:)).to eq(<<~STRING) app/models/test.rb 1: example usage STRING end - context 'when no violations found' do - it 'returns the no violations view' do + context "when no violations found" do + it "returns the no violations view" do allow(violations).to receive(:anonymous_sources_with_locations).and_return({}) - expect(described_class.package_violations(package_path: package_path, constant_name: constant_name)).to eq(<<~STRING) + expect(described_class.package_violations(package_path:, constant_name:)).to eq(<<~STRING) No violations found in "packs/test_package" for "::TestPackage::TestClass". Ensure that constant_name is given in the format of "::ConstantName" or "::ConstantName::NestedConstant". STRING end end - context 'without constant name' do - let(:constant_name) { '' } + context "without constant name" do + let(:constant_name) { "" } - it 'returns the violations list view' do + it "returns the violations list view" do allow(violations).to receive(:anonymous_source_counts).and_return(anonymous_source_counts) - expect(described_class.package_violations(package_path: package_path)).to eq(<<~STRING) + expect(described_class.package_violations(package_path:)).to eq(<<~STRING) ::TestPackage::TestClass (3 violations) STRING end end - context 'when an error occurs' do + context "when an error occurs" do before do - allow(Chatwerk::Helpers).to receive(:all_packages).and_raise(StandardError.new('test error')) + allow(Chatwerk::Helpers).to receive(:all_packages).and_raise(StandardError.new("test error")) end - it 'returns the error view' do - expect { described_class.package_violations(package_path: package_path) }.to raise_error(Chatwerk::Error) + it "returns the error view" do + expect { described_class.package_violations(package_path:) }.to raise_error(Chatwerk::Error) end end end diff --git a/spec/chatwerk/error_spec.rb b/spec/chatwerk/error_spec.rb index 30897f2..aeef9da 100644 --- a/spec/chatwerk/error_spec.rb +++ b/spec/chatwerk/error_spec.rb @@ -1,11 +1,14 @@ +# typed: false # frozen_string_literal: true RSpec.describe Chatwerk::Error do - context 'with a Chatwerk::Error' do - it 'renders the error message' do - error = instance_double('Error', - to_s: 'Custom error message', - backtrace: %w[line1 line2]) + context "with a Chatwerk::Error" do + it "renders the error message" do + error = instance_double( + "Error", + to_s: "Custom error message", + backtrace: %w(line1 line2) + ) expect(described_class.new(error).message).to eq(<<~OUTPUT) There was a problem accessing package information @@ -19,13 +22,15 @@ end end - context 'with a standard error and package_path' do - it 'renders an error about package path access' do - error = instance_double('StandardError', - to_s: 'Standard error message', - backtrace: %w[line1 line2]) + context "with a standard error and package_path" do + it "renders an error about package path access" do + error = instance_double( + "StandardError", + to_s: "Standard error message", + backtrace: %w(line1 line2) + ) - expect(described_class.new(error, package_path: 'app/packages/some_package').message).to eq(<<~OUTPUT) + expect(described_class.new(error, package_path: "app/packages/some_package").message).to eq(<<~OUTPUT) There was a problem finding or accessing "app/packages/some_package" Error: Standard error message @@ -37,11 +42,13 @@ end end - context 'with a standard error and no package_path' do - it 'renders a generic error message' do - error = instance_double('StandardError', - to_s: 'Standard error message', - backtrace: %w[line1 line2]) + context "with a standard error and no package_path" do + it "renders a generic error message" do + error = instance_double( + "StandardError", + to_s: "Standard error message", + backtrace: %w(line1 line2) + ) expect(described_class.new(error).message).to eq(<<~OUTPUT) There was a problem accessing package information diff --git a/spec/chatwerk/helpers_spec.rb b/spec/chatwerk/helpers_spec.rb index 3e32196..179b86c 100644 --- a/spec/chatwerk/helpers_spec.rb +++ b/spec/chatwerk/helpers_spec.rb @@ -1,10 +1,11 @@ +# typed: false # frozen_string_literal: true RSpec.describe Chatwerk::Helpers do - describe '.chdir' do - it 'changes directory temporarily and executes the block' do + describe ".chdir" do + it "changes directory temporarily and executes the block" do original_dir = Dir.pwd - File.expand_path('..', original_dir) + File.expand_path("..", original_dir) described_class.chdir do expect(Dir.pwd).to eq(described_class.env_pwd) @@ -14,26 +15,26 @@ end end - describe '.env_pwd' do + describe ".env_pwd" do it 'returns ENV["PWD"] when set' do - allow(ENV).to receive(:fetch).with('PWD', anything).and_return('/custom/path') - expect(described_class.env_pwd).to eq('/custom/path') + allow(ENV).to receive(:fetch).with("PWD", anything).and_return("/custom/path") + expect(described_class.env_pwd).to eq("/custom/path") end it 'falls back to pwd when ENV["PWD"] is not set' do - allow(ENV).to receive(:fetch).with('PWD', anything).and_call_original + allow(ENV).to receive(:fetch).with("PWD", anything).and_call_original expect(described_class.env_pwd).to eq(described_class.pwd) end end - describe '.normalize_package_path' do - it 'normalizes package paths correctly' do + describe ".normalize_package_path" do + it "normalizes package paths correctly" do examples = { - '/path/to/package/' => 'path/to/package', - 'path/to/package/package.yml' => 'path/to/package', - 'path/to/package/package_todo.yml' => 'path/to/package', - ' path/to/package ' => 'path/to/package', - nil => '' + "/path/to/package/" => "path/to/package", + "path/to/package/package.yml" => "path/to/package", + "path/to/package/package_todo.yml" => "path/to/package", + " path/to/package " => "path/to/package", + nil => "", } examples.each do |input, expected| @@ -42,13 +43,13 @@ end end - describe '.normalize_constant_name' do - it 'normalizes constant names correctly' do + describe ".normalize_constant_name" do + it "normalizes constant names correctly" do examples = { - 'MyConstant' => '::MyConstant', - '::MyConstant' => '::MyConstant', - ' MyConstant ' => '::MyConstant', - nil => '' + "MyConstant" => "::MyConstant", + "::MyConstant" => "::MyConstant", + " MyConstant " => "::MyConstant", + nil => "", } examples.each do |input, expected| @@ -57,9 +58,9 @@ end end - describe '.all_packages' do - let(:package1) { instance_double('QueryPackwerk::Package', name: 'package1') } - let(:package2) { instance_double('QueryPackwerk::Package', name: 'package2') } + describe ".all_packages" do + let(:package1) { instance_double("QueryPackwerk::Package", name: "package1") } + let(:package2) { instance_double("QueryPackwerk::Package", name: "package2") } let(:all_packages) { [package1, package2] } before do @@ -67,50 +68,50 @@ allow(QueryPackwerk::Packages).to receive(:where).and_return([package1]) end - it 'returns all packages when no pattern is given' do + it "returns all packages when no pattern is given" do expect(described_class.all_packages).to eq(all_packages) end - it 'returns filtered packages when pattern is given' do - expect(described_class.all_packages('package1')).to eq([package1]) + it "returns filtered packages when pattern is given" do + expect(described_class.all_packages("package1")).to eq([package1]) end end - describe '.find_package' do - let(:package) { instance_double('QueryPackwerk::Package', name: 'test_package') } + describe ".find_package" do + let(:package) { instance_double("QueryPackwerk::Package", name: "test_package") } - context 'when one package is found' do + context "when one package is found" do before do - allow(described_class).to receive(:all_packages).with('test_package').and_return([package]) + allow(described_class).to receive(:all_packages).with("test_package").and_return([package]) end - it 'returns the package' do - expect(described_class.find_package('test_package')).to eq(package) + it "returns the package" do + expect(described_class.find_package("test_package")).to eq(package) end end - context 'when no packages are found' do + context "when no packages are found" do before do - allow(described_class).to receive(:all_packages).with('nonexistent').and_return([]) + allow(described_class).to receive(:all_packages).with("nonexistent").and_return([]) end - it 'raises an error' do + it "raises an error" do expect do - described_class.find_package('nonexistent') + described_class.find_package("nonexistent") end.to raise_error(/Unable to find a package/) end end - context 'when multiple packages are found' do - let(:package2) { instance_double('QueryPackwerk::Package', name: 'test_package2') } + context "when multiple packages are found" do + let(:package2) { instance_double("QueryPackwerk::Package", name: "test_package2") } before do - allow(described_class).to receive(:all_packages).with('test').and_return([package, package2]) + allow(described_class).to receive(:all_packages).with("test").and_return([package, package2]) end - it 'raises an error' do + it "raises an error" do expect do - described_class.find_package('test') + described_class.find_package("test") end.to raise_error(Chatwerk::Error, /Found multiple packages/) end end diff --git a/spec/chatwerk/mcp_tools_spec.rb b/spec/chatwerk/mcp_tools_spec.rb index 5c7029f..8c36828 100644 --- a/spec/chatwerk/mcp_tools_spec.rb +++ b/spec/chatwerk/mcp_tools_spec.rb @@ -1,14 +1,15 @@ +# typed: false # frozen_string_literal: true -RSpec.describe 'MCP Tools' do - let(:server_context) { double('server_context') } +RSpec.describe "MCP Tools" do + let(:server_context) { double("server_context") } describe Chatwerk::Mcp do - it 'creates server with all tool classes available' do + it "creates server with all tool classes available" do server = described_class.server expect(server).to be_a(MCP::Server) - expect(server.name).to eq('chatwerk') + expect(server.name).to eq("chatwerk") expect(server.version).to eq(Chatwerk::VERSION) # Verify all tool classes are available @@ -21,151 +22,151 @@ end describe Chatwerk::Tools::PrintEnvTool do - it 'responds with environment information' do - response = described_class.call(server_context: server_context) + it "responds with environment information" do + response = described_class.call(server_context:) expect(response).to be_a(MCP::Tool::Response) expect(response.content).to be_an(Array) - expect(response.content.first[:type]).to eq('text') - expect(response.content.first[:text]).to include('Current Directory:') - expect(response.content.first[:text]).to include('Environment:') + expect(response.content.first[:type]).to eq("text") + expect(response.content.first[:text]).to include("Current Directory:") + expect(response.content.first[:text]).to include("Environment:") end - it 'has correct description' do - expect(described_class.description).to include('current working directory') + it "has correct description" do + expect(described_class.description).to include("current working directory") end - it 'has no required arguments' do + it "has no required arguments" do schema = described_class.input_schema expect(schema.to_h.fetch(:required, [])).to be_empty end end describe Chatwerk::Tools::PackagesTool do - it 'responds with package list when no package_path provided' do - allow(Chatwerk::Api).to receive(:packages).with(package_path: nil).and_return('package list') + it "responds with package list when no package_path provided" do + allow(Chatwerk::Api).to receive(:packages).with(package_path: nil).and_return("package list") - response = described_class.call(server_context: server_context) + response = described_class.call(server_context:) expect(response).to be_a(MCP::Tool::Response) - expect(response.content.first[:text]).to eq('package list') + expect(response.content.first[:text]).to eq("package list") end - it 'responds with filtered packages when package_path provided' do - allow(Chatwerk::Api).to receive(:packages).with(package_path: 'packs/payments').and_return('filtered packages') + it "responds with filtered packages when package_path provided" do + allow(Chatwerk::Api).to receive(:packages).with(package_path: "packs/payments").and_return("filtered packages") - response = described_class.call(package_path: 'packs/payments', server_context: server_context) + response = described_class.call(package_path: "packs/payments", server_context:) - expect(response.content.first[:text]).to eq('filtered packages') + expect(response.content.first[:text]).to eq("filtered packages") end - it 'has correct description' do - expect(described_class.description).to include('List all valid packwerk packages') + it "has correct description" do + expect(described_class.description).to include("List all valid packwerk packages") end - it 'has package_path as optional argument' do + it "has package_path as optional argument" do schema = described_class.input_schema expect(schema.to_h[:properties]).to have_key(:package_path) - expect(schema.to_h.fetch(:required, [])).not_to include('package_path') + expect(schema.to_h.fetch(:required, [])).not_to include("package_path") end end describe Chatwerk::Tools::PackageTool do - it 'responds with package details' do - allow(Chatwerk::Api).to receive(:package).with(package_path: 'packs/payments').and_return('package details') + it "responds with package details" do + allow(Chatwerk::Api).to receive(:package).with(package_path: "packs/payments").and_return("package details") - response = described_class.call(package_path: 'packs/payments', server_context: server_context) + response = described_class.call(package_path: "packs/payments", server_context:) expect(response).to be_a(MCP::Tool::Response) - expect(response.content.first[:text]).to eq('package details') + expect(response.content.first[:text]).to eq("package details") end - it 'has correct description' do - expect(described_class.description).to include('Show the details for a specific package') + it "has correct description" do + expect(described_class.description).to include("Show the details for a specific package") end - it 'has package_path as required argument' do + it "has package_path as required argument" do schema = described_class.input_schema expect(schema.to_h[:properties]).to have_key(:package_path) - expect(schema.to_h.fetch(:required, [])).to include('package_path') + expect(schema.to_h.fetch(:required, [])).to include("package_path") end end describe Chatwerk::Tools::PackageTodosTool do - it 'responds with todos list when no constant_name provided' do + it "responds with todos list when no constant_name provided" do allow(Chatwerk::Api).to receive(:package_todos) - .with(package_path: 'packs/payments', constant_name: nil) - .and_return('todos list') + .with(package_path: "packs/payments", constant_name: nil) + .and_return("todos list") - response = described_class.call(package_path: 'packs/payments', server_context: server_context) + response = described_class.call(package_path: "packs/payments", server_context:) expect(response).to be_a(MCP::Tool::Response) - expect(response.content.first[:text]).to eq('todos list') + expect(response.content.first[:text]).to eq("todos list") end - it 'responds with detailed todos when constant_name provided' do + it "responds with detailed todos when constant_name provided" do allow(Chatwerk::Api).to receive(:package_todos) - .with(package_path: 'packs/payments', constant_name: '::OtherPackage::SomeClass') - .and_return('detailed todos') + .with(package_path: "packs/payments", constant_name: "::OtherPackage::SomeClass") + .and_return("detailed todos") response = described_class.call( - package_path: 'packs/payments', - constant_name: '::OtherPackage::SomeClass', - server_context: server_context + package_path: "packs/payments", + constant_name: "::OtherPackage::SomeClass", + server_context: ) - expect(response.content.first[:text]).to eq('detailed todos') + expect(response.content.first[:text]).to eq("detailed todos") end - it 'has correct description' do - expect(described_class.description).to include('Find code that violates dependency boundaries FROM this package') + it "has correct description" do + expect(described_class.description).to include("Find code that violates dependency boundaries FROM this package") end - it 'has correct argument requirements' do + it "has correct argument requirements" do schema = described_class.input_schema expect(schema.to_h[:properties]).to have_key(:package_path) expect(schema.to_h[:properties]).to have_key(:constant_name) - expect(schema.to_h.fetch(:required, [])).to include('package_path') - expect(schema.to_h.fetch(:required, [])).not_to include('constant_name') + expect(schema.to_h.fetch(:required, [])).to include("package_path") + expect(schema.to_h.fetch(:required, [])).not_to include("constant_name") end end describe Chatwerk::Tools::PackageViolationsTool do - it 'responds with violations list when no constant_name provided' do + it "responds with violations list when no constant_name provided" do allow(Chatwerk::Api).to receive(:package_violations) - .with(package_path: 'packs/payments', constant_name: nil) - .and_return('violations list') + .with(package_path: "packs/payments", constant_name: nil) + .and_return("violations list") - response = described_class.call(package_path: 'packs/payments', server_context: server_context) + response = described_class.call(package_path: "packs/payments", server_context:) expect(response).to be_a(MCP::Tool::Response) - expect(response.content.first[:text]).to eq('violations list') + expect(response.content.first[:text]).to eq("violations list") end - it 'responds with detailed violations when constant_name provided' do + it "responds with detailed violations when constant_name provided" do allow(Chatwerk::Api).to receive(:package_violations) - .with(package_path: 'packs/payments', constant_name: '::ThisPackage::SomeClass') - .and_return('detailed violations') + .with(package_path: "packs/payments", constant_name: "::ThisPackage::SomeClass") + .and_return("detailed violations") response = described_class.call( - package_path: 'packs/payments', - constant_name: '::ThisPackage::SomeClass', - server_context: server_context + package_path: "packs/payments", + constant_name: "::ThisPackage::SomeClass", + server_context: ) - expect(response.content.first[:text]).to eq('detailed violations') + expect(response.content.first[:text]).to eq("detailed violations") end - it 'has correct description' do - expect(described_class.description).to include('Find code that violates dependency boundaries TO this package') + it "has correct description" do + expect(described_class.description).to include("Find code that violates dependency boundaries TO this package") end - it 'has correct argument requirements' do + it "has correct argument requirements" do schema = described_class.input_schema expect(schema.to_h[:properties]).to have_key(:package_path) expect(schema.to_h[:properties]).to have_key(:constant_name) - expect(schema.to_h.fetch(:required, [])).to include('package_path') - expect(schema.to_h.fetch(:required, [])).not_to include('constant_name') + expect(schema.to_h.fetch(:required, [])).to include("package_path") + expect(schema.to_h.fetch(:required, [])).not_to include("constant_name") end end end diff --git a/spec/chatwerk/views/no_packages_view_spec.rb b/spec/chatwerk/views/no_packages_view_spec.rb index a1d81c5..3f33b91 100644 --- a/spec/chatwerk/views/no_packages_view_spec.rb +++ b/spec/chatwerk/views/no_packages_view_spec.rb @@ -1,8 +1,9 @@ +# typed: false # frozen_string_literal: true RSpec.describe Chatwerk::Views::NoPackagesView do - context 'when packwerk.yml exists' do - it 'renders a message indicating 0 packages found' do + context "when packwerk.yml exists" do + it "renders a message indicating 0 packages found" do expect(described_class.render(has_packwerk_yml: true)).to eq(<<~MESSAGE) 0 packages found. `packwerk.yml` file exists in project root: #{Chatwerk::Helpers.pwd} @@ -14,8 +15,8 @@ end end - context 'when packwerk.yml does not exist' do - it 'renders a message indicating packwerk is not being used' do + context "when packwerk.yml does not exist" do + it "renders a message indicating packwerk is not being used" do expect(described_class.render(has_packwerk_yml: false)).to eq(<<~MESSAGE) This project does not appear to be using packwerk. `packwerk.yml` file does not exist in project root: #{Chatwerk::Helpers.pwd} diff --git a/spec/chatwerk/views/no_violations_view_spec.rb b/spec/chatwerk/views/no_violations_view_spec.rb index 0937fe6..6bf5f5c 100644 --- a/spec/chatwerk/views/no_violations_view_spec.rb +++ b/spec/chatwerk/views/no_violations_view_spec.rb @@ -1,9 +1,10 @@ +# typed: false # frozen_string_literal: true RSpec.describe Chatwerk::Views::NoViolationsView do - it 'renders a message indicating no violations found' do - package = instance_double('Chatwerk::Package', name: 'orders') - constant_name = '::Orders::Order' + it "renders a message indicating no violations found" do + package = instance_double("Chatwerk::Package", name: "orders") + constant_name = "::Orders::Order" expect(described_class.render(package:, constant_name:)).to eq(<<~MESSAGE) No violations found in "orders" for "::Orders::Order". diff --git a/spec/chatwerk/views/package_view_spec.rb b/spec/chatwerk/views/package_view_spec.rb index 8a8f1a0..7a09c45 100644 --- a/spec/chatwerk/views/package_view_spec.rb +++ b/spec/chatwerk/views/package_view_spec.rb @@ -1,20 +1,23 @@ +# typed: false # frozen_string_literal: true RSpec.describe Chatwerk::Views::PackageView do - context 'with a valid package' do - it 'renders package details' do - config = { 'dependencies' => ['core'], 'enforce_dependencies' => true } - package = instance_double('QueryPackwerk::Package', - name: 'orders', - config: config, - enforce_dependencies: true, - enforce_privacy: true, - owner: 'Test Team', - metadata: {}, - dependency_names: ['dependency1'], - consumer_names: ['consumer1'], - todos: [], - violations: []) + context "with a valid package" do + it "renders package details" do + config = { "dependencies" => ["core"], "enforce_dependencies" => true } + package = instance_double( + "QueryPackwerk::Package", + name: "orders", + config:, + enforce_dependencies: true, + enforce_privacy: true, + owner: "Test Team", + metadata: {}, + dependency_names: ["dependency1"], + consumer_names: ["consumer1"], + todos: [], + violations: [] + ) expect(described_class.render(package:)).to eq(<<~OUTPUT) --- diff --git a/spec/chatwerk/views/packages_view_spec.rb b/spec/chatwerk/views/packages_view_spec.rb index dbe37c6..207a2bb 100644 --- a/spec/chatwerk/views/packages_view_spec.rb +++ b/spec/chatwerk/views/packages_view_spec.rb @@ -1,14 +1,15 @@ +# typed: false # frozen_string_literal: true RSpec.describe Chatwerk::Views::PackagesView do - context 'when packages are found' do - it 'renders a list of packages' do + context "when packages are found" do + it "renders a list of packages" do packages = [ - instance_double('Chatwerk::Package', name: 'orders'), - instance_double('Chatwerk::Package', name: 'users'), - instance_double('Chatwerk::Package', name: 'payments') + instance_double("Chatwerk::Package", name: "orders"), + instance_double("Chatwerk::Package", name: "users"), + instance_double("Chatwerk::Package", name: "payments"), ] - package_path = 'app/packages' + package_path = "app/packages" expect(described_class.render(packages:, package_path:)).to eq(<<~OUTPUT) orders @@ -18,10 +19,10 @@ end end - context 'when no packages are found' do - it 'renders a message indicating no packages found' do + context "when no packages are found" do + it "renders a message indicating no packages found" do packages = [] - package_path = 'app/invalid_path' + package_path = "app/invalid_path" expect(described_class.render(packages:, package_path:)).to eq(<<~OUTPUT) No packages found matching "app/invalid_path" diff --git a/spec/chatwerk/views/violations_details_view_spec.rb b/spec/chatwerk/views/violations_details_view_spec.rb index 9d423cd..08102d8 100644 --- a/spec/chatwerk/views/violations_details_view_spec.rb +++ b/spec/chatwerk/views/violations_details_view_spec.rb @@ -1,17 +1,18 @@ +# typed: false # frozen_string_literal: true RSpec.describe Chatwerk::Views::ViolationsDetailsView do - context 'with violations having source locations' do - it 'renders violation details with source locations' do - package = instance_double('QueryPackwerk::Package', name: 'orders') - constant_name = '::Core::User' + context "with violations having source locations" do + it "renders violation details with source locations" do + package = instance_double("QueryPackwerk::Package", name: "orders") + constant_name = "::Core::User" sources = { - '::Core::User' => { - 'User.find(_)' => ['app/packages/orders/app/models/order.rb:45', 'app/packages/orders/app/services/order_service.rb:12'], - 'User.create(_)' => ['app/packages/orders/app/controllers/orders_controller.rb:28', 'app/packages/orders/app/models/order.rb:48'] - } + "::Core::User" => { + "User.find(_)" => ["app/packages/orders/app/models/order.rb:45", "app/packages/orders/app/services/order_service.rb:12"], + "User.create(_)" => ["app/packages/orders/app/controllers/orders_controller.rb:28", "app/packages/orders/app/models/order.rb:48"], + }, } - violations = instance_double('QueryPackwerk::Violations', anonymous_sources_with_locations: sources) + violations = instance_double("QueryPackwerk::Violations", anonymous_sources_with_locations: sources) expect(described_class.render(package:, violations:, constant_name:)).to eq(<<~OUTPUT) app/packages/orders/app/controllers/orders_controller.rb @@ -27,14 +28,14 @@ end end - context 'with violations having no source locations' do - it 'renders message about no sources being found' do - package = instance_double('QueryPackwerk::Package', name: 'orders') - constant_name = '::Core::Product' + context "with violations having no source locations" do + it "renders message about no sources being found" do + package = instance_double("QueryPackwerk::Package", name: "orders") + constant_name = "::Core::Product" sources = { - '::Core::Product' => {} + "::Core::Product" => {}, } - violations = instance_double('QueryPackwerk::Violations', anonymous_sources_with_locations: sources) + violations = instance_double("QueryPackwerk::Violations", anonymous_sources_with_locations: sources) expect(described_class.render(package:, violations:, constant_name:)).to eq(<<~OUTPUT) No sources found for ::Core::Product diff --git a/spec/chatwerk/views/violations_list_view_spec.rb b/spec/chatwerk/views/violations_list_view_spec.rb index 726025c..01145ae 100644 --- a/spec/chatwerk/views/violations_list_view_spec.rb +++ b/spec/chatwerk/views/violations_list_view_spec.rb @@ -1,14 +1,17 @@ +# typed: false # frozen_string_literal: true RSpec.describe Chatwerk::Views::ViolationsListView do - context 'with multiple violations' do - it 'renders a list of violations with counts' do - package = instance_double('Chatwerk::Package', name: 'packs/core') - violations = instance_double('Chatwerk::Violations') - allow(violations).to receive(:anonymous_source_counts).and_return({ - '::Core::User' => { 'source1' => 2, 'source2' => 1 }, - '::Core::Product' => { 'source3' => 1 } - }) + context "with multiple violations" do + it "renders a list of violations with counts" do + package = instance_double("Chatwerk::Package", name: "packs/core") + violations = instance_double("Chatwerk::Violations") + allow(violations).to receive(:anonymous_source_counts).and_return( + { + "::Core::User" => { "source1" => 2, "source2" => 1 }, + "::Core::Product" => { "source3" => 1 }, + } + ) expect(described_class.render(package:, violations:)).to eq(<<~OUTPUT) ::Core::User (3 violations) @@ -17,10 +20,10 @@ end end - context 'with no violations' do - it 'renders a message indicating no violations' do - package = instance_double('Chatwerk::Package', name: 'packs/core') - violations = instance_double('Chatwerk::Violations') + context "with no violations" do + it "renders a message indicating no violations" do + package = instance_double("Chatwerk::Package", name: "packs/core") + violations = instance_double("Chatwerk::Violations") allow(violations).to receive(:anonymous_source_counts).and_return({}) expect(described_class.render(package:, violations:)).to eq(<<~OUTPUT) diff --git a/spec/chatwerk_spec.rb b/spec/chatwerk_spec.rb index 2bf5ed2..a89b7c6 100644 --- a/spec/chatwerk_spec.rb +++ b/spec/chatwerk_spec.rb @@ -1,13 +1,14 @@ +# typed: false # frozen_string_literal: true RSpec.describe Chatwerk do - it 'has a version number' do - expect(Chatwerk::VERSION).not_to be nil + it "has a version number" do + expect(Chatwerk::VERSION).not_to be_nil end describe Chatwerk::Mcp do - it 'is defined' do - expect(Chatwerk::Mcp.name).to eq('chatwerk') + it "is defined" do + expect(Chatwerk::Mcp.name).to eq("chatwerk") end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b5a2311..dc2338c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,11 @@ +# typed: false # frozen_string_literal: true -require 'chatwerk' +require "chatwerk" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = '.rspec_status' + config.example_status_persistence_file_path = ".rspec_status" # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching!