Class: SkillBench::OutputFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/skill_bench/output_formatter.rb

Overview

Handles formatting output for different use cases (human, CI, etc.). Delegates all presentation logic to focused service objects under Services.

Class Method Summary collapse

Class Method Details

.batch_exit_code(aggregate) ⇒ Integer

Determine the exit code for an aggregate batch result.

Parameters:

  • aggregate (Hash)

    Aggregate envelope with a :summary.

Returns:

  • (Integer)

    0 when every eval passed, 1 when any failed.



62
63
64
# File 'lib/skill_bench/output_formatter.rb', line 62

def self.batch_exit_code(aggregate)
  aggregate.dig(:summary, :failed).to_i.positive? ? 1 : 0
end

.exit_code(result) ⇒ Integer

Determine exit code based on eval result.

Parameters:

  • result (Hash)

    Eval result with :pass or :success/:response keys.

Returns:

  • (Integer)

    0 if passed, 1 if failed



37
38
39
40
41
42
43
# File 'lib/skill_bench/output_formatter.rb', line 37

def self.exit_code(result)
  return 0 if result[:pass]
  return 1 unless result[:success]

  report = result.dig(:response, :report)
  report&.verdict ? 0 : 1
end

.format(result, format: :human) ⇒ String

Format the eval result for output.

Parameters:

  • result (Hash)

    Eval result with keys like :eval_name, :pass, :score, etc.

  • format (Symbol) (defaults to: :human)

    Output format (:human, :json, :junit, :html)

Returns:

  • (String)

    Formatted output string



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/skill_bench/output_formatter.rb', line 20

def self.format(result, format: :human)
  case format
  when :json
    Services::JsonFormatter.format(result)
  when :junit
    Services::JUnitFormatter.format(result)
  when :html
    Services::HtmlFormatter.format(result)
  else
    format_human(result)
  end
end

.format_batch(aggregate) ⇒ String

Format an aggregate batch result for human output.

Renders one PASS/FAIL line per eval plus a final summary line.

Parameters:

  • aggregate (Hash)

    Aggregate envelope with :results and :summary.

Returns:

  • (String)

    Human-readable batch summary.



51
52
53
54
55
56
# File 'lib/skill_bench/output_formatter.rb', line 51

def self.format_batch(aggregate)
  lines = aggregate[:results].map { |result| batch_result_line(result) }
  lines << ''
  lines << batch_summary_line(aggregate[:summary])
  lines.join("\n")
end