Class: RailsAiBridge::Tools::GetContext::RelatedTests

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/tools/get_context/related_tests.rb

Overview

Cheap related-test discovery: File.exist? on conventional spec/test paths. Does not read file bodies or run ripgrep. Tokens must be +word+/path segments so feature cannot traverse out of the application root.

Constant Summary collapse

SAFE_TOKEN =

Model/controller tokens interpolated into conventional test paths.

%r{\A\w+(?:/\w+)*\z}

Instance Method Summary collapse

Constructor Details

#initialize(root:, resolution:) ⇒ RelatedTests

Returns a new instance of RelatedTests.

Parameters:



15
16
17
18
# File 'lib/rails_ai_bridge/tools/get_context/related_tests.rb', line 15

def initialize(root:, resolution:)
  @root = root
  @resolution = resolution
end

Instance Method Details

#pathsArray<String>

Returns relative paths that exist on disk under root.

Returns:

  • (Array<String>)

    relative paths that exist on disk under root



21
22
23
24
25
# File 'lib/rails_ai_bridge/tools/get_context/related_tests.rb', line 21

def paths
  return [] if @root.nil?

  conventional_paths.select { |relative| safe_exist?(relative) }
end