Class: Henitai::MutantHistoryStore

Inherits:
Object
  • Object
show all
Includes:
VerdictCache
Defined in:
lib/henitai/mutant_history_store.rb,
lib/henitai/mutant_history_store/sql.rb,
lib/henitai/mutant_history_store/verdict_cache.rb,
sig/henitai.rbs

Overview

Persists mutant outcomes across runs in a lightweight SQLite database.

Defined Under Namespace

Modules: Sql, VerdictCache

Constant Summary

Constants included from VerdictCache

VerdictCache::CACHEABLE_STATUSES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, per_test_coverage: nil) ⇒ MutantHistoryStore

Returns a new instance of MutantHistoryStore.

Parameters:

  • per_test_coverage (PerTestCoverage, nil) (defaults to: nil)

    live per-test coverage view used to record the full-map intersection set for survived verdicts; without it survived rows stay NULL (never reusable).

  • path: (String)
  • per_test_coverage: (PerTestCoverage, nil) (defaults to: nil)


20
21
22
23
# File 'lib/henitai/mutant_history_store.rb', line 20

def initialize(path:, per_test_coverage: nil)
  @path = path
  @per_test_coverage = per_test_coverage
end

Instance Attribute Details

#pathString (readonly)

Returns the value of attribute path.

Returns:

  • (String)


25
26
27
# File 'lib/henitai/mutant_history_store.rb', line 25

def path
  @path
end

Instance Method Details

#killed_verdict_for(stable_id) ⇒ Hash[Symbol, untyped]?

Killed-only view of #verdict_for, kept for the original killed reuse path.

Parameters:

  • (String)

Returns:

  • (Hash[Symbol, untyped], nil)


57
58
59
60
# File 'lib/henitai/mutant_history_store.rb', line 57

def killed_verdict_for(stable_id)
  verdict = verdict_for(stable_id)
  verdict if verdict && verdict[:status] == :killed
end

#record(result, version:, recorded_at: Time.now.utc) ⇒ void

This method returns an undefined value.

Parameters:

  • (Object)
  • version: (String)
  • recorded_at: (Time) (defaults to: Time.now.utc)


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/henitai/mutant_history_store.rb', line 27

def record(result, version:, recorded_at: Time.now.utc)
  FileUtils.mkdir_p(File.dirname(path))

  with_database do |db|
    ensure_schema(db)
    db.transaction do
      insert_run(db, result, version, recorded_at) unless partial_rerun?(result)
      Array(result.mutants).each do |mutant|
        upsert_mutant(db, mutant, version, recorded_at)
      end
    end
  end
end

#trend_reportHash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


62
63
64
65
66
67
68
69
70
71
# File 'lib/henitai/mutant_history_store.rb', line 62

def trend_report
  with_database do |db|
    ensure_schema(db)
    {
      generatedAt: Time.now.utc.iso8601,
      runs: load_runs(db),
      mutants: load_mutants(db)
    }
  end
end

#verdict_for(stable_id) ⇒ Hash[Symbol, untyped]?

Verdict-cache lookup for --incremental: returns the stored hashes for the mutant's LATEST verdict when it is Killed or Survived — the upsert keeps exactly one row per stable id, so current_status is always the most recent outcome. nil for every other status, unknown ids and legacy rows without hashes (recorded before the cache columns existed).

Parameters:

  • (String)

Returns:

  • (Hash[Symbol, untyped], nil)


46
47
48
49
50
51
52
53
# File 'lib/henitai/mutant_history_store.rb', line 46

def verdict_for(stable_id)
  return nil unless File.exist?(path)

  with_database do |db|
    ensure_schema(db)
    verdict_from_row(db.get_first_row(Sql::VERDICT_LOOKUP, stable_id))
  end
end