Class: Henitai::SurvivorTestFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/henitai/survivor_test_filter.rb

Overview

Splits a matched survivor set into stable and pending subsets by consulting a git diff against the covering tests from the prior report.

A survivor is stable (can skip re-execution) when:

- it has covering test data in the prior report, AND
- none of those test files appear in the diff between the prior run's
  git_sha and the current HEAD.

A survivor is pending (must execute) when:

- git_sha is nil (no anchor → conservative), OR
- its coveredBy data is absent or empty, OR
- at least one covering test file changed.

On any git error the filter conservatively treats all survivors as pending.

Instance Method Summary collapse

Constructor Details

#initialize(coverage_map:, git_sha:, dirty_source_files: false, worktree_changed_files: [], diff_analyzer: GitDiffAnalyzer.new) ⇒ SurvivorTestFilter

Returns a new instance of SurvivorTestFilter.

Parameters:

  • coverage_map (Hash<String, Array<String>>)

    stableId → [test_files]

  • git_sha (String, nil)

    git SHA from the prior report

  • dirty_source_files (Boolean) (defaults to: false)

    true when the current worktree has dirty source files and the survivor shortcut must be disabled

  • worktree_changed_files (Array<String>) (defaults to: [])

    dirty tracked/untracked files

  • diff_analyzer (GitDiffAnalyzer) (defaults to: GitDiffAnalyzer.new)


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/henitai/survivor_test_filter.rb', line 25

def initialize(
  coverage_map:,
  git_sha:,
  dirty_source_files: false,
  worktree_changed_files: [],
  diff_analyzer: GitDiffAnalyzer.new
)
  @coverage_map  = coverage_map
  @git_sha       = git_sha
  @dirty_source_files = dirty_source_files
  @worktree_changed_files = Array(worktree_changed_files)
  @diff_analyzer = diff_analyzer
end

Instance Method Details

#apply(mutants) ⇒ Hash<Symbol, Array<Mutant>>

Returns { stable: […], pending: […] }.

Parameters:

Returns:

  • (Hash<Symbol, Array<Mutant>>)

    { stable: […], pending: […] }



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/henitai/survivor_test_filter.rb', line 41

def apply(mutants)
  return { stable: [], pending: mutants } if @dirty_source_files
  return { stable: [], pending: mutants } if @git_sha.nil?

  changed = changed_test_files
  return { stable: [], pending: mutants } if changed.nil?

  mutants.each_with_object({ stable: [], pending: [] }) do |mutant, result|
    bucket = stable_survivor?(mutant, changed) ? :stable : :pending
    result[bucket] << mutant
  end
end