Class: Henitai::SurvivorActivationCache

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

Overview

Stores and retrieves pre-computed define_method activation sources for survived mutants, enabling survivor reruns to skip the full mutant-generation pipeline.

The cache artifact (activation-recipes.json) is written alongside the session snapshot in reports/sessions/<session_id>/. When a survivor rerun finds this file next to the report it was given, it can build stub Mutant objects directly and execute them without re-parsing source files.

A recipe entry encodes everything needed to activate and re-report a mutant: the define_method source, subject coordinates, operator, description, location, and the coveredBy test list.

Constant Summary collapse

FILENAME =
"activation-recipes.json"

Class Method Summary collapse

Class Method Details

.compute(survived_mutants) ⇒ Hash<String, Hash>

Build a recipe hash for each survived mutant that has a computable activation source.

Parameters:

  • survived_mutants (Array<Mutant>)

Returns:

  • (Hash<String, Hash>)

    stableId → recipe



27
28
29
30
31
32
33
34
# File 'lib/henitai/survivor_activation_cache.rb', line 27

def self.compute(survived_mutants)
  survived_mutants.each_with_object({}) do |mutant, cache|
    source = Mutant::Activator.activation_source_for(mutant)
    next unless source

    cache[mutant.stable_id] = build_recipe(mutant, source)
  end
end

.load(path) ⇒ Hash?

Returns nil when the file is absent or unparseable.

Parameters:

  • path (String)

    path to activation-recipes.json

Returns:

  • (Hash, nil)

    nil when the file is absent or unparseable



38
39
40
41
42
43
44
# File 'lib/henitai/survivor_activation_cache.rb', line 38

def self.load(path)
  return nil unless File.exist?(path)

  JSON.parse(File.read(path))
rescue JSON::ParserError
  nil
end

.write(path, recipes) ⇒ Object

Parameters:

  • path (String)
  • recipes (Hash<String, Hash>)


48
49
50
51
# File 'lib/henitai/survivor_activation_cache.rb', line 48

def self.write(path, recipes)
  FileUtils.mkdir_p(File.dirname(path))
  File.write(path, JSON.pretty_generate(recipes))
end