Class: Testprune::UI::Reviewer

Inherits:
Object
  • Object
show all
Defined in:
lib/testprune/ui/reviewer.rb

Overview

Interactive, cluster-at-a-time reviewer for ‘apply`. Walks the actionable removals in review order (identical first), grouping redundant tests under a shared keeper so one keystroke accepts a whole cluster. Returns the list of accepted candidates for the patch writer.

Input is read one keystroke at a time. The key reader is injectable so the flow is testable without a real TTY (see ReviewerTest).

Constant Summary collapse

KEYS =
"  [a] accept & remove   [s] skip   [d] diff vs keeper   [q] quit & write"

Instance Method Summary collapse

Constructor Details

#initialize(result, input: $stdin, output: $stdout, color: nil, read_key: nil) ⇒ Reviewer

Returns a new instance of Reviewer.



20
21
22
23
24
25
26
27
# File 'lib/testprune/ui/reviewer.rb', line 20

def initialize(result, input: $stdin, output: $stdout, color: nil, read_key: nil)
  @result   = result
  @in       = input
  @out      = output
  @color    = color.nil? ? UI.tty?(output) : color
  @read_key = read_key || method(:default_read_key)
  @fp_by_id = ReviewPlan.index_footprints(result)
end

Instance Method Details

#runObject

Returns an Array of accepted Candidate objects (subset of approved_removals).



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/testprune/ui/reviewer.rb', line 30

def run
  clusters = ReviewPlan.build(@result, actionable_only: true)
                       .flat_map { |tier| tier.clusters.map { |c| [tier, c] } }
  return finish([]) if clusters.empty?

  accepted = []
  clusters.each_with_index do |(tier, cluster), i|
    @diff_idx = 0
    loop do
      render_cluster(tier, cluster, i + 1, clusters.size, accepted.size)
      case @read_key.call
      when 'a', ' ', "\r", "\n"
        accepted.concat(cluster.members.select(&:safe).map(&:candidate))
        break
      when 's' then break
      when 'd' then show_diff(cluster)
      when 'q', "", nil then return finish(accepted)
      end
    end
  end
  finish(accepted)
end