Class: Ast::Merge::Git::LocalBenchmarkRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/ast/merge/git/local_benchmark.rb,
sig/ast/merge/git.rbs

Overview

Executes the same authored merge bytes through Git and the installed driver.

Constant Summary collapse

DEFAULT_TIMEOUT =

Returns:

  • (Integer)
30
MERGIRAF_EXTENSIONS =
{
  'bash' => 'sh',
  'html' => 'html',
  'json' => 'json',
  'markdown' => 'md',
  'ruby' => 'rb',
  'toml' => 'toml',
  'typescript' => 'ts',
  'yaml' => 'yaml'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(benchmark:, driver_path:, tmp_root:, timeout: DEFAULT_TIMEOUT, competitor_paths: {}) ⇒ LocalBenchmarkRunner

Returns a new instance of LocalBenchmarkRunner.



390
391
392
393
394
395
396
# File 'lib/ast/merge/git/local_benchmark.rb', line 390

def initialize(benchmark:, driver_path:, tmp_root:, timeout: DEFAULT_TIMEOUT, competitor_paths: {})
  @benchmark = benchmark
  @driver_path = Pathname(driver_path).expand_path
  @tmp_root = Pathname(tmp_root).expand_path
  @timeout = Integer(timeout)
  @competitor_paths = competitor_paths.transform_values { |path| Pathname(path).expand_path }
end

Instance Method Details

#run(profile:, changed_paths: []) ⇒ Hash[String, untyped]

Parameters:

  • profile: (String, Symbol)
  • changed_paths: (Array[String]) (defaults to: [])

Returns:

  • (Hash[String, untyped])


398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/ast/merge/git/local_benchmark.rb', line 398

def run(profile:, changed_paths: [])
  verify_environment!
  selection = @benchmark.select(profile: profile, changed_paths: changed_paths)
  original_cwd = Dir.pwd
  results = selection['selected_case_ids'].flat_map do |id|
    item = @benchmark.case_by_id(id)
    execute_case(item) + execute_competitors(item)
  end
  raise LocalBenchmark::Error, 'runner changed its working directory' unless Dir.pwd == original_cwd

  {
    'schema_version' => 'structuredmerge.benchmark.run/v1',
    'kind' => 'paired_local_run',
    'corpus_id' => @benchmark.document['id'],
    'corpus_digest' => @benchmark.corpus_digest,
    'selection' => selection,
    'cache_identity' => cache_identity(selection),
    'competitors' => competitor_provenance,
    'results' => results
  }
ensure
  Dir.chdir(original_cwd) if original_cwd && Dir.pwd != original_cwd
end