Class: Llm::Functions::FixOneRspecTest

Inherits:
Base
  • Object
show all
Defined in:
lib/llm/functions/fix_one_rspec_test.rb

Instance Method Summary collapse

Methods inherited from Base

#stop_llm_call?

Instance Method Details

#definitionObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/llm/functions/fix_one_rspec_test.rb', line 8

def definition
  return @definition unless @definition.nil?

  @definition = {
    name: self.function_name,
    description: I18n.t("ghostest.functions.#{self.function_name}.description"),
    parameters: {
      type: :object,
      properties: {
        file_path: {
          type: :string,
          description: I18n.t("ghostest.functions.#{self.function_name}.parameters.file_path"),
        },
        line_num: {
          type: :string,
          description: I18n.t("ghostest.functions.#{self.function_name}.parameters.line_num"),
        },
      },
      required: [:file_path, :line_num],
    },
  }
  @definition
end

#execute_and_generate_message(args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/llm/functions/fix_one_rspec_test.rb', line 32

def execute_and_generate_message(args)
  if args[:file_path].nil? || args[:file_path].empty? || !File.exist?(args[:file_path])
    raise Ghostest::Error.new("Please specify the file path.")
  end
  line_num = args[:line_num].to_i
  if line_num < 1
    raise Ghostest::Error.new("Please specify the line num. #{args[:line_num]}")
  end

  n = 0
  while n < 5
    n += 1
    script = "bundle exec rspec '#{args['file_path']}:#{args['line_num']}'"
    stdout, stderr, status = Open3.capture3(script)
    if status.exitstatus != 0

    end
  end

  { stdout:, stderr:, exit_status: status.exitstatus }
end

#function_nameObject



4
5
6
# File 'lib/llm/functions/fix_one_rspec_test.rb', line 4

def function_name
  :fix_one_rspec_test
end