Class: ActiveMutator::Baseline

Inherits:
Object
  • Object
show all
Defined in:
lib/active_mutator/baseline.rb

Overview

Runs the host suite once, instrumented, in a subprocess. Produces and caches the CoverageMap. Invalidation is coarse: any digest change in app,lib/**/*.rb or the configured spec paths triggers a full re-run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:, spec_paths: ["spec"], cache_dir: File.join(root, ".active_mutator")) ⇒ Baseline

Returns a new instance of Baseline.



10
11
12
13
14
15
# File 'lib/active_mutator/baseline.rb', line 10

def initialize(root:, spec_paths: ["spec"], cache_dir: File.join(root, ".active_mutator"))
  @root = root
  @spec_paths = spec_paths
  @cache_dir = cache_dir
  @out_path = File.join(cache_dir, "coverage.json")
end

Instance Attribute Details

#last_refreshObject (readonly)

Returns the value of attribute last_refresh.



17
18
19
# File 'lib/active_mutator/baseline.rb', line 17

def last_refresh
  @last_refresh
end

Instance Method Details

#coverage_map(force: false) ⇒ Object



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
# File 'lib/active_mutator/baseline.rb', line 19

def coverage_map(force: false)
  digests = current_digests
  if !force && File.exist?(@out_path)
    map = CoverageMap.load(@out_path)
    # A spec_paths change silently degrades the delta classifier: files
    # under a removed spec path just vanish from the digest scan, so
    # BaselineDelta treats their stale example records as untouched
    # source coverage instead of dropping them. Force a full rebuild
    # whenever the configured spec_paths differ from what the cache was
    # stamped with.
    if stored_spec_paths(map) == @spec_paths && map.fresh?(digests)
      @last_refresh = :cached
      return map
    end
    if stored_spec_paths(map) == @spec_paths && map.version == 2
      delta = BaselineDelta.compute(old_digests: stored_digests(map), new_digests: digests,
                                    coverage_map: map, root: @root, spec_paths: @spec_paths)
      unless delta.full?
        run_partial!(delta)
        stamp_digests(digests)
        @last_refresh = :partial
        return CoverageMap.load(@out_path)
      end
    end
  end
  run_baseline!
  stamp_digests(digests)
  @last_refresh = :full
  CoverageMap.load(@out_path)
end