Class: Tng::Services::FixOrchestrator

Inherits:
Object
  • Object
show all
Defined in:
lib/tng/services/fix_orchestrator.rb

Constant Summary collapse

MAX_ITERATIONS =
3

Instance Method Summary collapse

Constructor Details

#initialize(pastel, http_client) ⇒ FixOrchestrator

Returns a new instance of FixOrchestrator.



10
11
12
13
# File 'lib/tng/services/fix_orchestrator.rb', line 10

def initialize(pastel, http_client)
  @pastel = pastel
  @repair_service = RepairService.new(http_client)
end

Instance Method Details

#run(file_path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/tng/services/fix_orchestrator.rb', line 15

def run(file_path)
  unless File.exist?(file_path)
    puts @pastel.red("❌ File not found: #{file_path}")
    return
  end

  puts @pastel.bright_white("🔧 Starting Auto-Fix loop for #{file_path}...")

  all_healthy = false
  MAX_ITERATIONS.times do |i|
    puts @pastel.dim("\n--- Iteration #{i + 1} ---")

    # 1. Syntax Check
    status = Tng::Utils.validate_ruby_syntax(file_path)
    unless status[:success]
      puts @pastel.yellow("⚠️  Syntax error detected!")
      apply_fix(file_path, :syntax, status[:output])
      next
    end
    puts @pastel.green("✓ Syntax OK")

    # 2. Rubocop Check
    status = Tng::Utils.validate_rubocop(file_path)
    unless status[:success]
      puts @pastel.yellow("⚠️  Rubocop violations detected!")
      apply_fix(file_path, :lint, status[:output])
      next
    end
    puts @pastel.green("✓ Rubocop OK")

    # 3. Test Check (Optional/Proactive)
    status = Tng::Utils.run_tests(file_path)
    unless status[:success]
      puts @pastel.yellow("⚠️  Test failures detected!")
      apply_fix(file_path, :runtime, status[:output])
      next
    end
    puts @pastel.green("✓ Tests Passed")

    all_healthy = true
    break
  end

  if all_healthy
    puts @pastel.bright_green("\n🎉 All checks passed! File is healthy.")
  else
    puts @pastel.red("\n❌ Max iterations reached. File still has issues.")
  end
end