Class: Ghostest::Manager

Inherits:
Object
  • Object
show all
Includes:
AttrReader
Defined in:
lib/ghostest/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Manager

Returns a new instance of Manager.



8
9
10
11
12
# File 'lib/ghostest/manager.rb', line 8

def initialize(config)
  @config = config
  @should_work_paths = []
  @test_condition = Ghostest::TestCondition.new(@config.language_klass)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/ghostest/manager.rb', line 6

def config
  @config
end

Instance Method Details

#start_work!Object

skip test for this method



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
# File 'lib/ghostest/manager.rb', line 15

def start_work!
  logger = Ghostest::Logger.instance

  loop do
    wait_for_update(@config.watch_files)
    next if @should_work_paths.empty?

    @should_work_paths.each do |source_path, test_path|
      agents = @config.agents.map do |name, agent_config|
        agent_config.role_klass.new(name, @config, logger)
      end

      assignee = agents.first
      switch_assignee_function = Llm::Functions::SwitchAssignee.new(assignee, agents)
      i = 0
      while i < 10
        i += 1
        assignee.work(source_path:, test_path:, switch_assignee_function:)
        break if assignee.respond_to?('lgtm?') && assignee.lgtm?
        assignee = switch_assignee_function.assignee
      end
      if assignee.respond_to?('lgtm?') && assignee.lgtm?
        @test_condition.save_as_updated!(source_path)
      else
        raise Ghostest::Error, "Workers couldn't finish the work. "
      end
    end
  end
end

#wait_for_update(watch_files) ⇒ Object

skip test for this method



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ghostest/manager.rb', line 46

def wait_for_update(watch_files)
  loop do
    sleep(3)
    should_work_paths = []
    watch_files.each do |watch_file|
      file_paths = Dir.glob(watch_file)

      file_paths.each do |source_path|
        if @test_condition.should_update_test?(source_path)
          test_path = @config.language_klass.convert_source_path_to_test_path(source_path)
          if File.exist?(test_path)
            should_work_paths << [source_path, test_path]
          else
            should_work_paths << [source_path, nil]
          end
        end
      end
    end

    unless should_work_paths.empty?
      @should_work_paths = should_work_paths
      break
    end
  end
end