mutineer 1.6.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +680 -0
  3. data/README.md +210 -499
  4. data/lib/mutineer/baseline.rb +1 -1
  5. data/lib/mutineer/changed_lines.rb +2 -1
  6. data/lib/mutineer/child_coverage.rb +53 -0
  7. data/lib/mutineer/cli.rb +293 -42
  8. data/lib/mutineer/concern_blocks.rb +243 -0
  9. data/lib/mutineer/config.rb +154 -8
  10. data/lib/mutineer/coverage_map.rb +265 -27
  11. data/lib/mutineer/daemon_backend.rb +244 -75
  12. data/lib/mutineer/daemon_client.rb +73 -10
  13. data/lib/mutineer/daemon_server.rb +226 -42
  14. data/lib/mutineer/external_backend.rb +159 -15
  15. data/lib/mutineer/init.rb +124 -0
  16. data/lib/mutineer/isolation.rb +78 -24
  17. data/lib/mutineer/job_plan.rb +234 -44
  18. data/lib/mutineer/kill_channel.rb +24 -14
  19. data/lib/mutineer/migrate.rb +707 -0
  20. data/lib/mutineer/minitest_integration/in_test_database_error.rb +184 -0
  21. data/lib/mutineer/minitest_integration/kill_recorder.rb +25 -17
  22. data/lib/mutineer/minitest_integration.rb +44 -14
  23. data/lib/mutineer/mutator_registry.rb +6 -2
  24. data/lib/mutineer/mutators/array_literal.rb +4 -2
  25. data/lib/mutineer/mutators/base.rb +36 -7
  26. data/lib/mutineer/mutators/call_to_receiver.rb +148 -0
  27. data/lib/mutineer/mutators/chain_link.rb +6 -6
  28. data/lib/mutineer/mutators/condition_forcing.rb +6 -3
  29. data/lib/mutineer/mutators/operand_removal.rb +4 -2
  30. data/lib/mutineer/mutators/range_literal.rb +105 -4
  31. data/lib/mutineer/mutators/return_nil.rb +1 -0
  32. data/lib/mutineer/orphan_guard.rb +84 -0
  33. data/lib/mutineer/pairing.rb +62 -1
  34. data/lib/mutineer/project.rb +302 -14
  35. data/lib/mutineer/rails_run_env.rb +73 -0
  36. data/lib/mutineer/rails_worker_db.rb +1596 -57
  37. data/lib/mutineer/redaction.rb +199 -0
  38. data/lib/mutineer/reporter.rb +173 -31
  39. data/lib/mutineer/result.rb +52 -15
  40. data/lib/mutineer/runner.rb +148 -28
  41. data/lib/mutineer/statement_lines.rb +24 -11
  42. data/lib/mutineer/subject.rb +30 -4
  43. data/lib/mutineer/test_runners/minitest.rb +2 -1
  44. data/lib/mutineer/test_runners/rspec.rb +15 -3
  45. data/lib/mutineer/test_runners.rb +5 -2
  46. data/lib/mutineer/triage.rb +111 -0
  47. data/lib/mutineer/version.rb +1 -1
  48. data/lib/mutineer/worker_pool.rb +2 -1
  49. data/lib/mutineer.rb +4 -0
  50. data/skills/mutineer/SKILL.md +84 -0
  51. metadata +13 -1
@@ -10,10 +10,14 @@ require_relative "minitest_integration"
10
10
  require_relative "test_runners"
11
11
  require_relative "child_stdout"
12
12
  require_relative "orphan_guard"
13
+ require_relative "redaction"
13
14
  require_relative "project_path"
14
15
  require_relative "pairing"
15
16
 
16
17
  module Mutineer
18
+ # A `--coverage-from` capture that cannot be read, or does not fit this run.
19
+ class CoverageFromError < StandardError; end
20
+
17
21
  # Maps `(source_file, line) -> [test_files]` so each mutant runs only against
18
22
  # the tests that actually exercise its line. Built once, then queried per
19
23
  # mutant via #tests_for. Persisted to .mutineer/coverage.json with a
@@ -33,6 +37,10 @@ module Mutineer
33
37
  # The result is already in the pipe then; the wait only lets the reader
34
38
  # thread run, even when the capture deadline has passed (#129).
35
39
  RESULT_GRACE = 1
40
+ # The redaction module, by absolute path, for the subprocess scripts: they
41
+ # write a failing test's report, or a load error, to the inherited stderr,
42
+ # and either can quote DATABASE_URL.
43
+ REDACTION_PATH = File.expand_path("redaction.rb", __dir__)
36
44
 
37
45
  attr_reader :project_root, :failed_test_files, :failed_clean_tests, :phase_a_ran, :map
38
46
 
@@ -90,11 +98,12 @@ module Mutineer
90
98
  def initialize(source_paths:, test_paths:, cache_dir: ".mutineer",
91
99
  load_paths: ["lib"], project_root: Dir.pwd,
92
100
  capture_timeout: DEFAULT_CAPTURE_TIMEOUT, boot_path: nil,
93
- framework: "minitest", verbose: false, require_paths: [])
101
+ framework: "minitest", verbose: false, require_paths: [], coverage_from: nil)
94
102
  @source_paths = Array(source_paths)
95
103
  @require_paths = Array(require_paths)
96
104
  @test_paths = Array(test_paths)
97
105
  @cache_dir = cache_dir
106
+ @coverage_from = coverage_from
98
107
  @load_paths = Array(load_paths)
99
108
  @project_root = project_root
100
109
  @capture_timeout = capture_timeout
@@ -367,13 +376,20 @@ module Mutineer
367
376
  # @return [Mutineer::CoverageMap] self.
368
377
  def cached_or(after_fork: nil)
369
378
  @digest = compute_digest
379
+ return reuse_capture(after_fork) if @coverage_from
380
+
370
381
  cached = read_cache
371
382
  # A cache from before load methods (#209) or test timings (#203) were
372
- # saved rebuilds once. Boot mode reads its load lines and methods from
373
- # the live boot instead (#build_via_fork), but its map from before #209
374
- # lacks the `def` lines of the methods each test called.
383
+ # saved rebuilds once. A cache that does not record this process's
384
+ # PARALLEL_WORKERS value rebuilds too. Rails reads that value inside
385
+ # parallelize, so a map from another worker count selects the wrong
386
+ # tests. The daemon writes this same file. Boot mode reads its load
387
+ # lines and methods from the live boot instead (#build_via_fork), but
388
+ # its map from before #209 lacks the `def` lines of the methods each
389
+ # test called.
375
390
  if cached && cached["digest"] == @digest && dependencies_match?(cached) &&
376
- cached.key?("load_methods") && cached.key?("timings")
391
+ cached.key?("load_methods") && cached.key?("timings") &&
392
+ parallel_workers_match?(cached)
377
393
  @map = cached["map"] || {}
378
394
  @timings = cached["timings"] || {}
379
395
  unless @boot_path
@@ -397,6 +413,137 @@ module Mutineer
397
413
  self
398
414
  end
399
415
 
416
+ # Takes the map from the `--coverage-from` capture instead of capturing,
417
+ # keeping only this run's sources, then runs the tests clean. A mutant runs
418
+ # only the tests that cover its line, often one file alone, so each test
419
+ # that covers one of this run's sources runs alone, as on a cache hit: a
420
+ # test that fails alone here would otherwise kill every mutant it runs. The
421
+ # other tests never run alone in this run, so only the combined check
422
+ # covers them.
423
+ #
424
+ # @api private
425
+ # @param after_fork [Proc, nil] boot-mode fork hook.
426
+ # @return [Mutineer::CoverageMap] self.
427
+ # @raise [Mutineer::CoverageFromError] when the capture does not fit.
428
+ def reuse_capture(after_fork)
429
+ cached = accepted_capture
430
+ sources = source_fingerprints.keys.to_set
431
+ @map = cached["map"].select { |key, _| sources.include?(key_source(key)) }
432
+ @timings = cached["timings"] || {}
433
+ @failed_test_files = []
434
+ @failed_clean_tests = []
435
+ @loaded_dependencies = cached["dependencies"]
436
+ covering = @map.values.flatten.to_set
437
+ verify_cached_clean(after_fork: after_fork,
438
+ test_paths: @test_paths.select { |t| covering.include?(relativize(t)) })
439
+ verify_combined_clean(after_fork: after_fork)
440
+ save
441
+ self
442
+ end
443
+
444
+ # The parsed `--coverage-from` capture, once it fits this run.
445
+ #
446
+ # @api private
447
+ # @return [Hash] the parsed coverage.json.
448
+ # @raise [Mutineer::CoverageFromError] when it cannot be read or does not fit.
449
+ def accepted_capture
450
+ if File.expand_path(@coverage_from) == File.expand_path(cache_path)
451
+ raise CoverageFromError, "--coverage-from #{@coverage_from} is this run's own cache; give the run another --cache-dir"
452
+ end
453
+
454
+ cached = JSON.parse(File.read(@coverage_from, encoding: "UTF-8"))
455
+ reason = capture_mismatch(cached)
456
+ raise CoverageFromError, "--coverage-from #{@coverage_from} cannot be reused: #{reason}" if reason
457
+
458
+ cached
459
+ rescue SystemCallError, JSON::ParserError => e
460
+ raise CoverageFromError, "--coverage-from #{@coverage_from} cannot be read: #{e.message}"
461
+ end
462
+
463
+ # Why a capture does not fit this run, or nil when it does.
464
+ #
465
+ # @api private
466
+ # @param cached [Object] the parsed coverage.json.
467
+ # @return [String, nil]
468
+ def capture_mismatch(cached)
469
+ return "it is not a coverage cache" unless cached.is_a?(Hash) && cached["map"].is_a?(Hash)
470
+ unless cached["sources"] && cached["owners"] && cached["inputs"]
471
+ return "it has no source fingerprints; capture it again with this version and --rails/--boot"
472
+ end
473
+ return "its entries are not the shape a coverage cache saves; capture it again" unless well_formed_capture?(cached)
474
+ return "its tests, --require files, boot file, load paths, framework or Minitest seed differ, or an older version made it; capture it again" unless cached["inputs"] == compute_digest(inputs_only: true)
475
+
476
+ fingerprints = source_fingerprints
477
+ missing = fingerprints.keys - cached["sources"].keys
478
+ return "it was not captured over #{missing.join(', ')}" if missing.any?
479
+
480
+ changed = fingerprints.reject { |rel, fingerprint| cached["sources"][rel] == fingerprint }.keys
481
+ return "#{changed.join(', ')} changed since the capture" if changed.any?
482
+
483
+ owners = ownership_paths - cached["owners"]
484
+ return "#{owners.join(', ')} appeared since the capture and can own a split test" if owners.any?
485
+
486
+ # The capture can list owners of sources outside this run, so compare
487
+ # with the disk, not with this run's owners.
488
+ gone = cached["owners"].reject { |rel| File.file?(absolute(rel)) }
489
+ return "#{gone.join(', ')} disappeared since the capture and could own a split test" if gone.any?
490
+
491
+ return "a file its tests loaded changed since the capture" unless dependencies_match?(cached)
492
+ unless parallel_workers_match?(cached)
493
+ return "it was captured with PARALLEL_WORKERS=#{cached['parallel_workers'].inspect}, " \
494
+ "this run has #{ENV.fetch('PARALLEL_WORKERS', nil).inspect}"
495
+ end
496
+
497
+ failed = Array(cached["failed_test_files"])
498
+ return "capture failed for #{failed.join(', ')}" if failed.any?
499
+
500
+ moved = load_mismatch(cached, fingerprints.keys.to_set)
501
+ return nil if moved.empty?
502
+
503
+ "lines of #{moved.join(', ')} ran at load in only one of the capture and this run: loading the capture's " \
504
+ "other sources ran them. Under --strategy redefine, eager-load in both (config.eager_load = true)"
505
+ end
506
+
507
+ # True when every entry the reuse reads has the type {#save} writes, so a
508
+ # hand-edited or foreign file is rejected with a reason, not a backtrace.
509
+ #
510
+ # @api private
511
+ # @param cached [Hash] the parsed coverage.json.
512
+ # @return [Boolean]
513
+ def well_formed_capture?(cached)
514
+ strings = ->(value) { value.is_a?(Array) && value.all?(String) }
515
+ cached["inputs"].is_a?(String) && strings.(cached["owners"]) &&
516
+ cached["sources"].is_a?(Hash) && cached["sources"].all? { |k, v| k.is_a?(String) && v.is_a?(String) } &&
517
+ cached["map"].all? { |k, v| k.is_a?(String) && strings.(v) } &&
518
+ %w[load_lines load_methods].all? { |key| cached[key].nil? || strings.(cached[key]) } &&
519
+ (cached["timings"].nil? || cached["timings"].is_a?(Hash))
520
+ end
521
+
522
+ # This run's sources whose load lines or load methods differ in the capture.
523
+ #
524
+ # @api private
525
+ # @param cached [Hash] the parsed coverage.json.
526
+ # @param sources [Set<String>] project-relative source paths.
527
+ # @return [Array<String>] the sources that differ, sorted.
528
+ def load_mismatch(cached, sources)
529
+ owned = ->(keys) { Array(keys).select { |key| sources.include?(key_source(key)) }.to_set }
530
+ moved = (owned.(cached["load_lines"]) ^ owned.(@load_lines)) + (owned.(cached["load_methods"]) ^ owned.(@load_methods))
531
+ moved.map { |key| key_source(key) }.uniq.sort
532
+ end
533
+
534
+ # Fingerprint of each source, by project-relative path.
535
+ #
536
+ # @return [Hash{String => String}]
537
+ def source_fingerprints
538
+ @source_paths.to_h { |p| [relativize(absolute(p)), file_fingerprint(absolute(p))] }
539
+ end
540
+
541
+ # The source path of a "file:line" or "file:line:column" key.
542
+ #
543
+ # @param key [String] a map, load line or load method key.
544
+ # @return [String]
545
+ def key_source(key) = key.sub(/(?::\d+)+\z/, "")
546
+
400
547
  # Runs standalone coverage capture.
401
548
  #
402
549
  # @api private
@@ -578,7 +725,8 @@ module Mutineer
578
725
  def fail_test(test_path, reason)
579
726
  rel = relativize(test_path)
580
727
  @failed_test_files << rel
581
- warn "[mutineer] coverage skipped for #{rel}: #{reason}"
728
+ # The reason can quote an app error, and so a credentialed DATABASE_URL.
729
+ warn "[mutineer] coverage skipped for #{rel}: #{Redaction.text(reason)}"
582
730
  nil
583
731
  end
584
732
 
@@ -623,9 +771,10 @@ module Mutineer
623
771
  #
624
772
  # @api private
625
773
  # @param after_fork [Proc, nil] boot-mode fork hook.
774
+ # @param test_paths [Array<String>] the tests to run, each alone.
626
775
  # @return [void]
627
- def verify_cached_clean(after_fork: nil)
628
- @test_paths.each do |test_path|
776
+ def verify_cached_clean(after_fork: nil, test_paths: @test_paths)
777
+ test_paths.each do |test_path|
629
778
  rel = relativize(test_path)
630
779
  next if @failed_test_files.include?(rel)
631
780
 
@@ -883,10 +1032,14 @@ module Mutineer
883
1032
  Minitest.define_singleton_method(:plugin_mutineer_report_init) { |options| reporter << Minitest::SummaryReporter.new(_report, options) }
884
1033
  Minitest.extensions << "mutineer_report"
885
1034
  $LOAD_PATH.unshift(*#{abs_load_paths.inspect})
886
- #{abs_preload_paths.inspect}.each { |f| require f }
887
- #{loads}
888
- _passed = Minitest.run([])
889
- $stderr.write(_report.string) unless _passed
1035
+ begin
1036
+ #{abs_preload_paths.inspect}.each { |f| require f }
1037
+ Minitest::Runnable.reset
1038
+ #{loads}
1039
+ #{load_failure_rescue}
1040
+ end
1041
+ _passed = Minitest.run(#{minitest_seed_args_expression})
1042
+ $stderr.write(#{redacted_expression("_report.string")}) unless _passed
890
1043
  exit(_passed ? 0 : 1)
891
1044
  RUBY
892
1045
  end
@@ -908,14 +1061,58 @@ module Mutineer
908
1061
  end
909
1062
  RSpec::Core::Runner.disable_autorun!
910
1063
  $LOAD_PATH.unshift(*#{abs_load_paths.inspect})
911
- #{abs_preload_paths.inspect}.each { |f| require f }
1064
+ begin
1065
+ #{abs_preload_paths.inspect}.each { |f| require f }
1066
+ #{load_failure_rescue}
1067
+ end
912
1068
  _sink = StringIO.new
913
1069
  status = RSpec::Core::Runner.run(["--no-color", #{specs}], _sink, _sink)
914
- $stderr.write(_sink.string) unless status.zero?
1070
+ $stderr.write(#{redacted_expression("_sink.string")}) unless status.zero?
915
1071
  exit(status.zero? ? 0 : 1)
916
1072
  RUBY
917
1073
  end
918
1074
 
1075
+ # Ruby source, for a subprocess script, that loads the redaction module
1076
+ # and returns the redacted value of `expression`.
1077
+ #
1078
+ # @api private
1079
+ # @param expression [String] Ruby source for the text to redact.
1080
+ # @return [String] Ruby script text.
1081
+ def redacted_expression(expression)
1082
+ "(require #{REDACTION_PATH.inspect}; Mutineer::Redaction.text(#{expression}))"
1083
+ end
1084
+
1085
+ # Ruby source, for a subprocess script, that closes a `begin` around the
1086
+ # project and test file loads. A load error then prints one redacted line
1087
+ # (Ruby's own printer would show DATABASE_URL raw), and the child still
1088
+ # exits 1, as it did when the error went uncaught. Under --verbose the
1089
+ # redacted backtrace follows; otherwise a hint says how to get it.
1090
+ #
1091
+ # @api private
1092
+ # @return [String] Ruby script text.
1093
+ def load_failure_rescue
1094
+ detail =
1095
+ if @verbose
1096
+ <<~RUBY.chomp
1097
+ (_e.backtrace || []).each { |_f| $stderr.puts("\t" + Mutineer::Redaction.text(_f)) }
1098
+ _cause = _e.cause
1099
+ while _cause
1100
+ $stderr.puts("[mutineer] caused by: " + Mutineer::Redaction.describe(_cause))
1101
+ _cause = _cause.cause
1102
+ end
1103
+ RUBY
1104
+ else
1105
+ '$stderr.puts("[mutineer] re-run with --verbose for the backtrace")'
1106
+ end
1107
+ <<~RUBY.chomp
1108
+ rescue ScriptError, StandardError => _e
1109
+ require #{REDACTION_PATH.inspect}
1110
+ $stderr.puts("[mutineer] load failed: " + Mutineer::Redaction.describe(_e))
1111
+ #{detail}
1112
+ exit 1
1113
+ RUBY
1114
+ end
1115
+
919
1116
  # Builds the framework-specific subprocess script.
920
1117
  #
921
1118
  # @api private
@@ -943,11 +1140,15 @@ module Mutineer
943
1140
  Minitest.extensions << "mutineer_report"
944
1141
  Coverage.start(lines: true, methods: true)
945
1142
  $LOAD_PATH.unshift(*#{abs_load_paths.inspect})
946
- #{abs_preload_paths.inspect}.each { |f| require f }
947
- _load = #{load_coverage_expression}
948
- load #{absolute(test_path).inspect}
949
- _passed = Minitest.run([])
950
- $stderr.write(_report.string) unless _passed
1143
+ begin
1144
+ #{abs_preload_paths.inspect}.each { |f| require f }
1145
+ _load = #{load_coverage_expression}
1146
+ Minitest::Runnable.reset
1147
+ load #{absolute(test_path).inspect}
1148
+ #{load_failure_rescue}
1149
+ end
1150
+ _passed = Minitest.run(#{minitest_seed_args_expression})
1151
+ $stderr.write(#{redacted_expression("_report.string")}) unless _passed
951
1152
  _coverage = Coverage.result.transform_values { |v| v.is_a?(Hash) ? v[:lines] : v }
952
1153
  _result.puts JSON.generate("passed" => _passed == true, "coverage" => _coverage,
953
1154
  "load_coverage" => _load,
@@ -956,6 +1157,18 @@ module Mutineer
956
1157
  RUBY
957
1158
  end
958
1159
 
1160
+ # Selects the seed inside the generated child, after its tests and helpers
1161
+ # load. Choosing in the parent can ignore a helper's SEED assignment and
1162
+ # let a clean check pass in an order the mutant run never uses (#282).
1163
+ # The default comes from the same constant as the in-process runner; the
1164
+ # child needs no Mutineer require and the parent's environment is unchanged.
1165
+ #
1166
+ # @api private
1167
+ # @return [String] Ruby expression for the Minitest argument array.
1168
+ def minitest_seed_args_expression
1169
+ "ENV[\"SEED\"] ? [] : [\"--seed\", #{MinitestIntegration::PINNED_SEED.to_s.inspect}]"
1170
+ end
1171
+
959
1172
  # Same coverage-JSON contract as the minitest path, but driven by RSpec:
960
1173
  # require rspec/core lazily, require the sources under Coverage, then run the
961
1174
  # one spec via RSpec::Core::Runner. The JSON goes to the result channel (see
@@ -977,11 +1190,14 @@ module Mutineer
977
1190
  RSpec::Core::Runner.disable_autorun!
978
1191
  Coverage.start(lines: true, methods: true)
979
1192
  $LOAD_PATH.unshift(*#{abs_load_paths.inspect})
980
- #{abs_preload_paths.inspect}.each { |f| require f }
981
- _load = #{load_coverage_expression}
1193
+ begin
1194
+ #{abs_preload_paths.inspect}.each { |f| require f }
1195
+ _load = #{load_coverage_expression}
1196
+ #{load_failure_rescue}
1197
+ end
982
1198
  _sink = StringIO.new
983
1199
  _status = RSpec::Core::Runner.run(["--no-color", #{absolute(test_path).inspect}], _sink, _sink)
984
- $stderr.write(_sink.string) unless _status.zero?
1200
+ $stderr.write(#{redacted_expression("_sink.string")}) unless _status.zero?
985
1201
  _coverage = Coverage.result.transform_values { |v| v.is_a?(Hash) ? v[:lines] : v }
986
1202
  _result.puts JSON.generate("passed" => _status.zero?, "coverage" => _coverage,
987
1203
  "load_coverage" => _load,
@@ -1178,24 +1394,42 @@ module Mutineer
1178
1394
  end
1179
1395
  end
1180
1396
 
1397
+ # True when `cached` records the same +PARALLEL_WORKERS+ value this process
1398
+ # has now. Rails reads that variable inside +parallelize+ and can run one
1399
+ # test file in several workers. A missing key is a map saved before this
1400
+ # value was stored. In-process runs and the daemon write this same file.
1401
+ #
1402
+ # @api private
1403
+ # @param cached [Hash] parsed coverage.json.
1404
+ # @return [Boolean]
1405
+ def parallel_workers_match?(cached)
1406
+ cached.key?("parallel_workers") && cached["parallel_workers"] == ENV.fetch("PARALLEL_WORKERS", nil)
1407
+ end
1408
+
1181
1409
  # Digest each file's ROLE + relative path + content length + content, plus
1182
1410
  # the load_paths. Without role/path/length delimiters the digest collides
1183
1411
  # (("ab","c") == ("a","bc")) and is blind to source/test role swaps, silently
1184
1412
  # accepting a stale cached map.
1185
- def compute_digest
1413
+ #
1414
+ # @param inputs_only [Boolean] leave out the sources and their owners.
1415
+ def compute_digest(inputs_only: false)
1186
1416
  d = Digest::SHA256.new
1187
- digest_group(d, "source", @source_paths)
1417
+ digest_group(d, "source", @source_paths) unless inputs_only
1188
1418
  digest_group(d, "test", @test_paths)
1189
1419
  # One group per file: digest_group sorts, and the load order matters.
1190
1420
  @require_paths.each { |p| digest_group(d, "require", [digest_path(p)]) }
1191
1421
  digest_group(d, "boot", [digest_path(@boot_path)]) if @boot_path
1192
- ownership_paths.each do |rel|
1422
+ (inputs_only ? [] : ownership_paths).each do |rel|
1193
1423
  d.update("owner\0")
1194
1424
  d.update(rel)
1195
1425
  d.update("\0")
1196
1426
  end
1197
1427
  @load_paths.sort.each { |lp| d.update("loadpath\0#{lp}\0") }
1198
1428
  d.update("framework\0#{@framework}\0")
1429
+ # The seed sets the test order, and the order can change which lines run (#282).
1430
+ # This is the configured seed. A test helper that changes SEED is not
1431
+ # digested, like any other helper edit.
1432
+ d.update("seed\0#{MinitestIntegration.seed}\0") unless @framework == "rspec"
1199
1433
  d.hexdigest
1200
1434
  end
1201
1435
 
@@ -1289,7 +1523,7 @@ module Mutineer
1289
1523
  def read_cache
1290
1524
  return nil unless File.exist?(cache_path)
1291
1525
 
1292
- JSON.parse(File.read(cache_path))
1526
+ JSON.parse(File.read(cache_path, encoding: "UTF-8"))
1293
1527
  rescue JSON::ParserError
1294
1528
  nil # corrupt cache: rebuild from scratch
1295
1529
  end
@@ -1305,7 +1539,11 @@ module Mutineer
1305
1539
  data = { "digest" => @digest, "failed_test_files" => @failed_test_files,
1306
1540
  "dependencies" => @loaded_dependencies, "map" => @map,
1307
1541
  "load_lines" => @load_lines.to_a.sort, "load_methods" => @load_methods.to_a.sort,
1308
- "timings" => @timings }
1542
+ "timings" => @timings, "parallel_workers" => ENV.fetch("PARALLEL_WORKERS", nil) }
1543
+ if @boot_path
1544
+ data.merge!("inputs" => compute_digest(inputs_only: true), "sources" => source_fingerprints,
1545
+ "owners" => ownership_paths)
1546
+ end
1309
1547
  tmp = "#{cache_path}.tmp"
1310
1548
  File.write(tmp, JSON.generate(data))
1311
1549
  File.rename(tmp, cache_path) # atomic swap