Module: Polyrun::SpecQuality::PlanLoader

Defined in:
lib/polyrun/spec_quality/plan_loader.rb

Overview

Loads partition plan JSON for spec-quality ↔ shard correlation.

Class Method Summary collapse

Class Method Details

.load_shards(paths) ⇒ Hash{String=>Array<String>}

Returns shard index string => spec file paths.

Parameters:

  • paths (Array<String>)

    plan JSON files (+polyrun plan+ output per shard or a wrapper hash)

Returns:

  • (Hash{String=>Array<String>})

    shard index string => spec file paths



11
12
13
14
15
16
17
18
19
20
# File 'lib/polyrun/spec_quality/plan_loader.rb', line 11

def load_shards(paths)
  out = {}
  Array(paths).each do |path|
    next unless File.file?(path)

    data = JSON.parse(File.read(File.expand_path(path)))
    merge_plan_data!(out, data)
  end
  out
end

.merge_plan_data!(out, data) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/polyrun/spec_quality/plan_loader.rb', line 22

def merge_plan_data!(out, data)
  if data.is_a?(Hash) && data["shards"].is_a?(Hash)
    data["shards"].each { |k, v| out[k.to_s] = Array(v).map(&:to_s) }
    return
  end

  return unless data.is_a?(Hash)

  shard = data["shard_index"]
  paths = data["paths"]
  return if shard.nil? || !paths.is_a?(Array)

  out[shard.to_s] = paths.map(&:to_s)
end

.shard_for_example(example_loc, plan_shards) ⇒ String?

Returns shard index for an example locator given plan shards.

Returns:

  • (String, nil)

    shard index for an example locator given plan shards



38
39
40
41
42
43
44
# File 'lib/polyrun/spec_quality/plan_loader.rb', line 38

def shard_for_example(example_loc, plan_shards)
  file = example_loc.to_s.sub(/:\d+\z/, "")
  plan_shards.each do |shard, paths|
    return shard if paths.any? { |p| file == p || file.end_with?("/#{File.basename(p)}") || file.include?(p) }
  end
  nil
end