Class: Flaky::Commands::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/flaky/commands/report.rb

Instance Method Summary collapse

Constructor Details

#initializeReport

Returns a new instance of Report.



8
9
10
# File 'lib/flaky/commands/report.rb', line 8

def initialize
  @repo = Repository.new
end

Instance Method Details

#executeObject



12
13
14
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
# File 'lib/flaky/commands/report.rb', line 12

def execute
  branch = Flaky.configuration.branch
  stats = @repo.run_stats(branch: branch)
  trend = @repo.failure_trend(branch: branch)

  puts "=== Flaky Test Report (#{branch}) ==="
  puts ""
  puts "CI Runs tracked:     #{stats[:total_runs]}"
  failure_pct = stats[:total_runs] > 0 ? (stats[:failed_runs].to_f / stats[:total_runs] * 100).round(1) : 0
  puts "Failed runs:         #{stats[:failed_runs]} (#{failure_pct}%)"
  puts "Total test failures: #{stats[:total_failures]}"
  puts "Unique flaky specs:  #{stats[:unique_specs]}"
  puts "Last fetch:          #{stats[:last_fetch] || 'never'}"

  puts ""
  puts "7-day trend:         #{trend[:recent]} failures (prior 7 days: #{trend[:prior]})"

  if trend[:recent] > trend[:prior]
    puts "                     \e[31m▲ Trending worse\e[0m"
  elsif trend[:recent] < trend[:prior]
    puts "                     \e[32m▼ Trending better\e[0m"
  else
    puts "                     → Stable"
  end

  top = @repo.top_flaky(branch: branch)
  if top.any?
    puts "\nTop 5 flaky tests:"
    puts "-" * 80
    top.each_with_index do |row, i|
      puts "  #{i + 1}. #{row['spec_file']}:#{row['line_number']} (#{row['failure_count']}x)"
      puts "     #{row['description']}"
    end
  end

  stress = @repo.recent_stress_runs
  if stress.any?
    puts "\nRecent stress runs:"
    puts "-" * 80
    stress.each do |run|
      total = run["passes"] + run["failures"]
      rate = total > 0 ? (run["failures"].to_f / total * 100).round(1) : 0
      ci_flag = run["ci_simulation"] == 1 ? " [CI sim]" : ""
      puts "  #{run['spec_location']}#{run['passes']}/#{total} passed (#{rate}% failure rate)#{ci_flag}"
    end
  end
ensure
  @repo.close
end