Module: Henitai::CanonicalReportMerger

Defined in:
lib/henitai/canonical_report_merger.rb,
sig/henitai.rbs

Overview

Merges a scoped/partial run's Stryker schema into the previously-written canonical report on disk instead of letting it fully replace the file.

Pure and fail-safe: any anomaly (missing/corrupt prior file, mismatched shape, a merge that would end up thinner than the current run alone) falls back to the current run's schema by itself -- structurally never worse than the unconditional overwrite this replaces.

Merges at mutant granularity, keyed by stableId, not file granularity: a --survivors-from rerun's schema only contains the re-verified survivors for a file, so replacing that file's whole entry would drop every other mutant (e.g. Killed ones) in the same file.

Class Method Summary collapse

Class Method Details

.merge(current_schema, prior_path, prune_missing: false) ⇒ Hash[String, untyped]

Parameters:

  • prune_missing (Boolean) (defaults to: false)

    when true, prior file entries whose source file no longer exists on disk are dropped from the merged report (a deleted module, or one removed from includes). Off by default so the merge stays a pure schema operation; the reporter enables it because it runs from the project root where relative source paths resolve.

  • (Hash[Symbol, untyped])
  • (String)
  • prune_missing: (Boolean) (defaults to: false)

Returns:

  • (Hash[String, untyped])


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

def self.merge(current_schema, prior_path, prune_missing: false)
  current = stringify(current_schema)
  return current unless File.exist?(prior_path)

  prior = JSON.parse(File.read(prior_path))
  return current unless prior.is_a?(Hash) && prior["files"].is_a?(Hash)

  merged = merge_files(current, prior, prune_missing:)
  return current unless safe?(merged, current)

  merged
rescue StandardError
  stringify(current_schema)
end