Class: Testgenai::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/testgenai/pipeline.rb

Constant Summary collapse

MAX_ATTEMPTS =
3

Instance Method Summary collapse

Constructor Details

#initialize(generator, validator) ⇒ Pipeline

Returns a new instance of Pipeline.



7
8
9
10
# File 'lib/testgenai/pipeline.rb', line 7

def initialize(generator, validator)
  @generator = generator
  @validator = validator
end

Instance Method Details

#run(method_info, context) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/testgenai/pipeline.rb', line 12

def run(method_info, context)
  output_path = @generator.output_path_for(method_info)
  original_content = File.exist?(output_path) ? File.read(output_path) : nil
  feedback = nil
  last_generated = nil

  MAX_ATTEMPTS.times do |i|
    last_generated = @generator.generate(method_info, context, feedback: feedback)
    combined = original_content ? "#{original_content}\n#{last_generated}" : last_generated
    result = @validator.validate(combined, output_path)

    if result[:runs] && result[:passes]
      return {success: true, output_path: output_path, attempts: i + 1, errors: []}
    end

    feedback = build_feedback(result)
  end

  fallback_path = cleanup_after_failure(output_path, original_content, last_generated, method_info)
  {success: false, output_path: output_path, fallback_path: fallback_path, attempts: MAX_ATTEMPTS, errors: [feedback]}
end