saboteur 0.7.0 → 0.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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +657 -0
  3. data/README.md +198 -1077
  4. data/lib/saboteur/cli/exit_status.rb +32 -1
  5. data/lib/saboteur/cli/help_options.rb +2 -1
  6. data/lib/saboteur/cli/history_command.rb +135 -0
  7. data/lib/saboteur/cli/presets.rb +6 -2
  8. data/lib/saboteur/cli/selection_options.rb +31 -0
  9. data/lib/saboteur/cli/shard_options.rb +17 -0
  10. data/lib/saboteur/cli/source_set.rb +53 -0
  11. data/lib/saboteur/cli/survivors_command.rb +157 -0
  12. data/lib/saboteur/cli.rb +71 -54
  13. data/lib/saboteur/config.rb +98 -5
  14. data/lib/saboteur/config_file.rb +8 -0
  15. data/lib/saboteur/constant_reads.rb +182 -0
  16. data/lib/saboteur/constant_subject.rb +70 -0
  17. data/lib/saboteur/constant_subject_finder.rb +281 -0
  18. data/lib/saboteur/coverage_reads.rb +29 -0
  19. data/lib/saboteur/dirty_tree_warning.rb +128 -0
  20. data/lib/saboteur/doctor.rb +9 -0
  21. data/lib/saboteur/engine/baseline_guard.rb +62 -14
  22. data/lib/saboteur/engine/boot.rb +4 -0
  23. data/lib/saboteur/engine/candidate_selection.rb +19 -0
  24. data/lib/saboteur/engine/candidates.rb +43 -3
  25. data/lib/saboteur/engine/coverage_store.rb +32 -10
  26. data/lib/saboteur/engine/defined_order_prefix.rb +43 -0
  27. data/lib/saboteur/engine/diagnostics.rb +18 -0
  28. data/lib/saboteur/engine/distribution.rb +10 -0
  29. data/lib/saboteur/engine/early_stop_recording.rb +3 -2
  30. data/lib/saboteur/engine/gated_run.rb +35 -0
  31. data/lib/saboteur/engine/load_coverage.rb +45 -0
  32. data/lib/saboteur/engine/out_of_scope_guard.rb +21 -0
  33. data/lib/saboteur/engine/pipelines.rb +107 -0
  34. data/lib/saboteur/engine/result_cache.rb +65 -8
  35. data/lib/saboteur/engine/run_budget.rb +27 -0
  36. data/lib/saboteur/engine/sandbox_policy.rb +38 -0
  37. data/lib/saboteur/engine/scheduler.rb +109 -3
  38. data/lib/saboteur/engine/selection_announcement.rb +54 -0
  39. data/lib/saboteur/engine/shard.rb +69 -0
  40. data/lib/saboteur/engine/subject_selection.rb +295 -20
  41. data/lib/saboteur/engine/test_guess.rb +315 -25
  42. data/lib/saboteur/engine/unchanged_syntax.rb +17 -2
  43. data/lib/saboteur/engine.rb +100 -127
  44. data/lib/saboteur/execution/external_runner.rb +471 -0
  45. data/lib/saboteur/execution/marker_sweep.rb +79 -0
  46. data/lib/saboteur/execution/peak_memory.rb +28 -0
  47. data/lib/saboteur/execution/process_table.rb +12 -0
  48. data/lib/saboteur/execution/process_tree.rb +65 -5
  49. data/lib/saboteur/execution/reevaluator.rb +68 -12
  50. data/lib/saboteur/execution/runner.rb +46 -7
  51. data/lib/saboteur/execution/sandbox.rb +15 -2
  52. data/lib/saboteur/execution/seatbelt.rb +226 -0
  53. data/lib/saboteur/execution/supervisor.rb +27 -10
  54. data/lib/saboteur/execution/worker_pool.rb +23 -1
  55. data/lib/saboteur/frameworks/sqlite_memory_database.rb +49 -0
  56. data/lib/saboteur/gates.rb +43 -2
  57. data/lib/saboteur/help.rb +60 -9
  58. data/lib/saboteur/ignore_list.rb +29 -6
  59. data/lib/saboteur/integration/rspec.rb +135 -5
  60. data/lib/saboteur/mutation_source/argument_removal.rb +1 -1
  61. data/lib/saboteur/mutation_source/builtin.rb +26 -5
  62. data/lib/saboteur/mutation_source/chain_removal.rb +1 -1
  63. data/lib/saboteur/mutation_source/condition_negation.rb +1 -1
  64. data/lib/saboteur/mutation_source/constant_literals.rb +66 -0
  65. data/lib/saboteur/mutation_source/element_removal.rb +73 -0
  66. data/lib/saboteur/mutation_source/endpoint_replacement.rb +1 -1
  67. data/lib/saboteur/mutation_source/entry_edits.rb +44 -0
  68. data/lib/saboteur/mutation_source/filter_replacement.rb +1 -1
  69. data/lib/saboteur/mutation_source/hazard_guard.rb +108 -0
  70. data/lib/saboteur/mutation_source/literal_replacement.rb +1 -1
  71. data/lib/saboteur/mutation_source/method_swap.rb +148 -0
  72. data/lib/saboteur/mutation_source/operator_assignment.rb +1 -1
  73. data/lib/saboteur/mutation_source/operator_examples.rb +3 -1
  74. data/lib/saboteur/mutation_source/operator_registry.rb +4 -2
  75. data/lib/saboteur/mutation_source/operator_visit.rb +1 -1
  76. data/lib/saboteur/mutation_source/pair_removal.rb +13 -31
  77. data/lib/saboteur/mutation_source/range_replacement.rb +1 -1
  78. data/lib/saboteur/mutation_source/regex_replacement.rb +93 -0
  79. data/lib/saboteur/preview.rb +120 -12
  80. data/lib/saboteur/refinement_activations.rb +60 -0
  81. data/lib/saboteur/reporter/agent.rb +9 -1
  82. data/lib/saboteur/reporter/agent_commands.rb +10 -3
  83. data/lib/saboteur/reporter/agent_incomplete.rb +11 -0
  84. data/lib/saboteur/reporter/agent_summary.rb +4 -3
  85. data/lib/saboteur/reporter/findings.rb +5 -2
  86. data/lib/saboteur/reporter/history_policy.rb +11 -0
  87. data/lib/saboteur/reporter/history_reader.rb +47 -0
  88. data/lib/saboteur/reporter/html.rb +26 -4
  89. data/lib/saboteur/reporter/mutation_text.rb +6 -0
  90. data/lib/saboteur/reporter/stryker.rb +27 -3
  91. data/lib/saboteur/reporter/survivor_classification.rb +101 -0
  92. data/lib/saboteur/reporter/survivor_list.rb +15 -9
  93. data/lib/saboteur/reporter/terminal.rb +40 -7
  94. data/lib/saboteur/result.rb +19 -3
  95. data/lib/saboteur/selection/coverage_map.rb +105 -10
  96. data/lib/saboteur/selection/dependency_shield.rb +80 -0
  97. data/lib/saboteur/selection/external_test_map.rb +27 -0
  98. data/lib/saboteur/selection/git_diff.rb +93 -11
  99. data/lib/saboteur/selection/layout_only_lines.rb +80 -0
  100. data/lib/saboteur/selection/recorder.rb +22 -4
  101. data/lib/saboteur/selection/source_scope.rb +22 -0
  102. data/lib/saboteur/subject.rb +42 -7
  103. data/lib/saboteur/subject_finder.rb +173 -29
  104. data/lib/saboteur/version.rb +1 -1
  105. data/lib/saboteur/working_tree.rb +38 -15
  106. data/lib/saboteur.rb +13 -0
  107. metadata +35 -2
@@ -7,16 +7,26 @@ require_relative "replay"
7
7
  require_relative "mutation_source/hazard_guard"
8
8
  require_relative "baseline/run_evidence"
9
9
  require_relative "engine/early_stop_recording"
10
+ require_relative "engine/gated_run"
11
+ require_relative "engine/load_coverage"
12
+ require_relative "engine/out_of_scope_guard"
10
13
  require_relative "engine/run_budget"
14
+ require_relative "engine/selection_announcement"
11
15
  require_relative "engine/thread_warnings"
12
16
 
17
+ require_relative "engine/pipelines"
18
+ require_relative "engine/shard"
19
+
13
20
  module Saboteur
14
21
  # A single-use instance runs one pipeline: boot the target, select subjects, fetch the
15
22
  # coverage map, then schedule each subject's mutants. The parts live in
16
23
  # engine/; this class only wires them together.
17
24
  class Engine
18
25
  include EarlyStopRecording
26
+ include OutOfScopeGuard
19
27
  include RunBudget
28
+ include GatedRun
29
+ include SelectionAnnouncement
20
30
 
21
31
  # Everything besides sources and tests that can change a verdict.
22
32
  VERDICT_INPUTS = %w[integration require rspec_args rails reeval sources operators exclude_operators arid
@@ -34,8 +44,9 @@ module Saboteur
34
44
  @root = File.realpath(config.root)
35
45
  @skipped_subjects = {}
36
46
  @replay = Replay.new(digest: digest) if digest
37
- if capture_evidence && (digest || config["since"] || config["incremental"])
38
- raise ConfigError, "baseline evidence requires fresh whole-scope execution: no since, replay or incremental"
47
+ if capture_evidence && (digest || config["since"] || config["incremental"] || config["shard"])
48
+ raise ConfigError,
49
+ "baseline evidence requires fresh whole-scope execution: no since, replay, shard or incremental"
39
50
  end
40
51
 
41
52
  @capture_evidence = capture_evidence
@@ -45,6 +56,7 @@ module Saboteur
45
56
 
46
57
  def call
47
58
  preflight!
59
+ ensure_artifacts_self_ignored
48
60
  started = monotonic
49
61
  start_budget_clock(started)
50
62
  # Capture evidence inputs before inference narrows the test list: the
@@ -52,31 +64,15 @@ module Saboteur
52
64
  # declared config, and the inferred specs are pinned by the hashed
53
65
  # source files anyway.
54
66
  @run_evidence = Baseline::RunEvidence.new(config: config, extra_files: @evidence_files) if @capture_evidence
55
- select_tests
67
+ select_tests unless external_command?
56
68
  announce_operators
57
69
  ignore_list = @replay ? IgnoreList.new([]) : IgnoreList.load(config.path("ignore_file"))
58
70
  warn_custom_map
59
- boot = Boot.new(config, hooks)
60
- begin
61
- integration, files, load_lines = boot_target(boot)
62
- @rails = boot.rails
63
- subjects, scope = select_subjects(files)
64
- results = subjects.empty? ? [] : mutate(subjects, files, integration, scope, ignore_list, load_lines:)
65
- @diagnostics.warnings.concat(ignore_list.apply(results, unscoped_digests: @unscoped_digests))
66
- build_report(results, subjects, scope, started)
67
- ensure
68
- # Cleanup runs however the call ends - a partway boot failure, no
69
- # subjects, no runnable work - so a host embedding Engine never
70
- # holds worker copies until process exit. Idempotent; the Rails
71
- # profile's at_exit handler stays the fallback for abrupt exit.
72
- begin
73
- @coverage_guard&.resume # an embedded host gets its coverage back (#254)
74
- ensure
75
- safely_cleanup_workers(boot.rails)
76
- end
77
- end
71
+ run_pipeline(ignore_list, started)
78
72
  end
79
73
 
74
+ include Pipelines
75
+
80
76
  def preflight!
81
77
  Boot.refuse_recursion!
82
78
  refuse_fail_fast_evidence
@@ -86,7 +82,11 @@ module Saboteur
86
82
 
87
83
  # Stale entries and duplicate literals never fail a run; they warn so the
88
84
  # map does not rot silently. doctor fails on stale keys.
89
- def load_custom_map = @replay ? CustomMap.new([]) : CustomMap.load(config.path("custom_map"), root: config.root)
85
+ def test_guess = TestGuess.new(config, diagnostics: @diagnostics, custom_map: load_custom_map)
86
+
87
+ def load_custom_map
88
+ @load_custom_map ||= @replay ? CustomMap.new([]) : CustomMap.load(config.path("custom_map"), root: config.root)
89
+ end
90
90
 
91
91
  def custom_map_warnings(map)
92
92
  path = config.path("custom_map")
@@ -109,75 +109,45 @@ module Saboteur
109
109
  # from the named subjects' files, so one unrelated spec-less file can
110
110
  # never block a one-method run.
111
111
  def select_tests
112
- return unless config["tests"].empty?
113
- return if @replay || config["all"] || config["test_selection"] == "all"
112
+ return if !config["tests"].empty? || @replay || config["all"] || config["test_selection"] == "all"
114
113
 
115
114
  subjects = config["subjects"]
116
115
  return select_subject_tests(subjects) if subjects.any?
117
116
 
118
- guess = TestGuess.new(config, diagnostics: @diagnostics).call
119
- @diagnostics.inform(guess.subjectless_message(since: config["since"])) if guess.subjectless.any?
120
- raise ConfigError, guess.unmatched_message if guess.unmatched.any?
117
+ guess = test_guess.call
118
+ @diagnostics.inform(guess.excluded_message) if guess.excluded.any? && guess.specs.any?
119
+ report_unmapped(guess)
120
+ refuse_out_of_scope_changes(guess)
121
121
 
122
- @diagnostics.announce(selection_message(guess))
122
+ announce_selection(guess)
123
123
  end
124
124
 
125
125
  # A --subject run infers only from the files holding the named subjects:
126
- # an unrelated spec-less file must not block a one-method run. A subject
127
- # file without a conventional spec stops the run before boot, like any
128
- # other unmatched file. With --since only named subjects inside the diff
129
- # scope count: an unchanged, comment-only or otherwise pruned subject
130
- # needs no spec and cannot stop the run either.
126
+ # an unrelated spec-less file must not block a one-method run, and a
127
+ # subject file without a conventional spec stops the run before boot.
128
+ # With --since only named subjects inside the diff scope count: an
129
+ # unchanged, comment-only or otherwise pruned subject needs no spec.
131
130
  def select_subject_tests(patterns)
132
- files = SubjectSelection.files_matching(@root, config.included_files, patterns)
133
- guess = TestGuess.new(config, diagnostics: @diagnostics).call_for(files, patterns)
131
+ files = SubjectSelection.files_matching(@root, config.included_files, patterns, config)
132
+ guess = test_guess.call_for(files, patterns)
134
133
  # No file in scope: the subjects are unknown (named later, in
135
134
  # selection) or --since left every named subject outside the diff, so
136
135
  # the run has nothing to mutate and needs no inferred spec.
137
136
  return if guess.changed.zero?
138
137
 
138
+ inform_skipped_specs(guess)
139
139
  raise ConfigError, guess.unmatched_message if guess.unmatched.any?
140
140
 
141
- @diagnostics.announce(scope_to_guesses(guess))
142
- end
141
+ @diagnostics.inform(guess.excluded_message) if guess.excluded.any?
142
+ # Every file in scope intentionally untested: mutate nothing. An
143
+ # empty guess must never read as "run the whole suite" (#369).
144
+ return if guess.specs.empty?
143
145
 
144
- def selection_message(guess)
145
- if guess.changed.zero?
146
- target = config["since"] ? "no changed source file" : "no source file"
147
- "inferred specs: #{target} to infer a spec for, so the whole suite runs"
148
- elsif guess.specs.empty?
149
- if config["since"]
150
- "inferred specs: no changed file has a mutation subject on its changed lines, " \
151
- "so there is nothing to mutate"
152
- else
153
- "inferred specs: no source file has a mutation subject, so there is nothing to mutate"
154
- end
155
- else
156
- scope_to_guesses(guess)
157
- end
158
- end
159
-
160
- # Stop before boot: name the spec-less files and the ways out. The
161
- # hinted spec paths are the conventional ones - they do not exist (that
162
- # is why the files are unmatched), so the message never prints them as
163
- # a runnable --test command, and it never reconstructs the source
164
- # scope: the user appends --test or --all to their own command. The
165
- # example is still shell-safe: the ref is user input, so it is quoted
166
- # and pinned to the flag with = (a ref like "-x" must not become a
167
- # switch).
168
- def scope_to_guesses(guess)
169
- # The guesses now stand as explicit tests, like --test. guess_tests is
170
- # dropped rather than set to false: an explicit false is the deprecated
171
- # opt-out and would warn.
172
- @config = config.with({ "tests" => guess.specs }, except: ["guess_tests"])
173
- @guessed_tests = guess.specs
174
- guess.scope_message(since: config["since"])
146
+ @diagnostics.announce(scope_to_guesses(guess))
175
147
  end
176
148
 
177
149
  # The run's immutable report, built once the last result is in.
178
- def announce_operators
179
- @diagnostics.inform("Operators: #{config.operator_policy['effective'].join(', ')}")
180
- end
150
+ def announce_operators = @diagnostics.inform("Operators: #{config.operator_policy['effective'].join(', ')}")
181
151
 
182
152
  def build_report(results, subjects, scope, started)
183
153
  Report.new(results: results, subjects: subjects, wall_time: monotonic - started, root: @root,
@@ -187,7 +157,8 @@ module Saboteur
187
157
  omissions: @diagnostics.omissions, run_evidence: complete_evidence(results, subjects),
188
158
  hazard_suppressions: @diagnostics.hazard_suppressions, early_stop: @early_stop,
189
159
  matrix: config["matrix"], inline_suppressions: @diagnostics.inline_suppressions,
190
- operator_policy: config.operator_policy, discovery_failures: @diagnostics.discovery_failures)
160
+ operator_policy: config.operator_policy, discovery_failures: @diagnostics.discovery_failures,
161
+ shard: @shard, memory: @memory_report)
191
162
  end
192
163
 
193
164
  def complete_evidence(results, subjects)
@@ -201,32 +172,33 @@ module Saboteur
201
172
  end
202
173
 
203
174
  # The subjects to mutate and, in diff mode, the scope of changed lines.
204
- def select_subjects(files)
175
+ def select_subjects(files, test_files: nil)
205
176
  config.unmatched_patterns.each { |pattern| @diagnostics.warn("#{pattern} matches no file") }
206
- selection = SubjectSelection.new(config, @diagnostics)
177
+ selection = SubjectSelection.new(config, @diagnostics,
178
+ test_files: test_files, custom_map: load_custom_map)
207
179
  subjects = selection.select(files)
208
- scope = selection.changed_lines && DiffScope.new(selection.changed_lines)
180
+ scope = selection.behavior_lines && DiffScope.new(selection.behavior_lines)
209
181
  return replay_subject(subjects, scope) if @replay
210
182
 
211
183
  [subjects, scope]
212
184
  end
213
185
 
214
- def mutate(subjects, files, integration, scope, ignore_list, load_lines: {})
215
- store = coverage_store(integration, load_lines)
186
+ def mutate(subjects, files, integration, scope, ignore_list, load_lines: {}, load_methods: {})
187
+ store = coverage_store(integration, load_lines, load_methods)
216
188
  full_passes = config["baseline_passes"] + (store.reusable?(files) ? 0 : 1)
217
189
  warn_unscoped(integration, full_passes)
218
190
  check_baseline(integration, full_passes)
191
+ refuse_unaffordable_coverage_build(store, files)
219
192
  return [] if abandon_for_budget?(subjects)
220
193
 
221
194
  map = store.fetch(files)
222
195
  inform_about_run(subjects, map)
223
- cache = result_cache
196
+ cache = result_cache(map, files)
224
197
  scheduler = scheduler_for(map, integration, cache)
225
198
  lists = candidate_lists(subjects, scope, map)
226
- work = subjects.zip(lists).reject { |_, list| list.empty? }
227
- return [] if work.empty?
199
+ runnable_subjects, runnable_lists = subjects.zip(lists).reject { |_, list| list.empty? }.transpose
200
+ return [] if runnable_subjects.nil?
228
201
 
229
- runnable_subjects, runnable_lists = work.transpose
230
202
  @rails&.prepare_workers(config["jobs"])
231
203
  # The execution phase forks next: the worker batch, or one child per
232
204
  # mutant when serial. Pack the heap now that the map and candidates
@@ -241,11 +213,15 @@ module Saboteur
241
213
 
242
214
  def run_candidates(subjects, lists, scheduler, cache, ignore_list)
243
215
  @diagnostics.start_progress(lists.sum(&:size))
244
- distribution = Distribution.new(jobs: config["jobs"], scheduler: scheduler, diagnostics: @diagnostics,
216
+ distribution = Distribution.new(jobs: external_command? ? 1 : config["jobs"], scheduler: scheduler,
217
+ diagnostics: @diagnostics,
245
218
  cache: cache, on_start: method(:start_worker),
246
219
  after_subject: after_subject_hook, stop_after: stop_checks(ignore_list),
247
220
  halt_check: config["max_duration"] ? method(:budget_exceeded?) : nil)
248
- distribution.run(subjects, lists).tap { record_early_stop(distribution) }
221
+ distribution.run(subjects, lists).tap do
222
+ record_early_stop(distribution, planned_mutants: lists.sum(&:size))
223
+ @memory_report = distribution.memory_report
224
+ end
249
225
  ensure
250
226
  @diagnostics.finish_progress
251
227
  end
@@ -282,8 +258,8 @@ module Saboteur
282
258
  ThreadWarnings.warn(@diagnostics)
283
259
  end
284
260
 
285
- def coverage_store(integration, load_lines)
286
- CoverageStore.new(config: config, integration: integration, hooks: hooks, load_lines:,
261
+ def coverage_store(integration, load_lines, load_methods = {})
262
+ CoverageStore.new(config: config, integration: integration, hooks: hooks, load_lines:, load_methods:,
287
263
  supervisor: supervisor(memory_factor: 4), diagnostics: @diagnostics,
288
264
  timeout_cap: method(:budget_capped_timeout))
289
265
  end
@@ -293,11 +269,13 @@ module Saboteur
293
269
  supervisor: supervisor(memory_factor: 4), diagnostics: @diagnostics,
294
270
  full_passes: full_passes, timeout_cap: method(:budget_capped_timeout),
295
271
  between_passes: config["max_duration"] ? method(:budget_exceeded?) : nil)
272
+ started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
296
273
  guard.call
274
+ @baseline_elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
297
275
  # Stability is the order comparison between completed checks: the cold
298
276
  # coverage build is not a baseline pass, and a budget break shortens
299
277
  # the loop, so certify only what actually ran.
300
- @stable_suite = guard.completed_passes >= 2
278
+ @stable_suite = (@completed_baseline_passes = guard.completed_passes) >= 2
301
279
  end
302
280
 
303
281
  # A --id replay targets one known mutant; the whole-suite cost summary
@@ -322,14 +300,21 @@ module Saboteur
322
300
  @sandbox_policy.hook
323
301
  end
324
302
 
325
- def result_cache
303
+ # The dependency universe a cached verdict watches when coverage
304
+ # cannot speak lives in Selection::CoverageMap (#344).
305
+ def source_files(files, prefixes: Selection::CoverageMap.root_prefixes(config.root))
306
+ Selection::CoverageMap.loaded_project_files(files, prefixes: prefixes)
307
+ end
308
+
309
+ def result_cache(map = nil, files = [])
326
310
  return nil if @replay
327
311
  return nil unless config["incremental"]
328
312
 
329
313
  inputs = JSON.generate(VERDICT_INPUTS.to_h { |key| [key, config[key]] }
330
314
  .merge("operator_policy" => config.operator_policy))
331
315
  ResultCache.new(path: File.join(config.path("cache_dir"), "results.json"), root: @root, inputs: inputs,
332
- suite_digest: SuiteFiles.new(config).digest)
316
+ suite_digest: SuiteFiles.new(config).digest,
317
+ coverage: map, fallback_files: source_files(files))
333
318
  end
334
319
 
335
320
  # A cleanup failure must never mask the run's own outcome - not even
@@ -349,11 +334,7 @@ module Saboteur
349
334
  # Each subject's candidates, narrowed to changed lines in diff mode.
350
335
  # The hazard guard is off only when the user explicitly asks for the
351
336
  # dangerous mutants (issue #102); the canary then still watches the tree.
352
- def hazard_guard
353
- return nil if config["allow_hazardous"]
354
-
355
- MutationSource::HazardGuard.new(config["hazard"])
356
- end
337
+ def hazard_guard = (MutationSource::HazardGuard.new(config["hazard"]) unless config["allow_hazardous"])
357
338
 
358
339
  # Checks the tree after each subject's mutants; a vanished file means a
359
340
  # mutant deleted it, so abort with the most recent mutant's digest.
@@ -382,10 +363,13 @@ module Saboteur
382
363
  def candidate_lists(subjects, scope, map)
383
364
  return [@replay_candidate] if @replay
384
365
 
385
- candidates = Candidates.new(Candidates.build_sources(config), @diagnostics, hazard_guard: hazard_guard)
366
+ candidates = Candidates.build(config, @diagnostics, hazard_guard: hazard_guard)
386
367
  selection = CandidateSelection.new(candidates: candidates, map: map,
387
368
  limit: config["max_mutants_per_method"], diagnostics: @diagnostics)
388
- subjects.map { |subject| selection.for(subject, scope: scope) }.tap do
369
+ lists = subjects.map { |subject| selection.for(subject, scope: scope) }
370
+ @shard = Engine::Shard.parse(config["shard"]) if config["shard"]
371
+ lists = @shard.select(subjects, lists) if @shard
372
+ lists.tap do
389
373
  @skipped_subjects = selection.skipped_subjects
390
374
  @unscoped_digests = selection.unscoped_digests
391
375
  if @run_evidence
@@ -396,7 +380,7 @@ module Saboteur
396
380
  end
397
381
 
398
382
  def replay_subject(subjects, scope)
399
- candidates = Candidates.new(Candidates.build_sources(config), @diagnostics, hazard_guard: hazard_guard)
383
+ candidates = Candidates.build(config, @diagnostics, hazard_guard: hazard_guard)
400
384
  subject, candidate = @replay.select(subjects, candidates, scope: scope)
401
385
  @replay_candidate = [candidate]
402
386
  [[subject], nil]
@@ -408,6 +392,21 @@ module Saboteur
408
392
  Execution::Supervisor.new(limits: limits)
409
393
  end
410
394
 
395
+ # Artifact dirs ignore themselves, the pattern git, vagrant and bundler
396
+ # use: a run writes logs, coverage maps and reports under cache_dir, and
397
+ # without the marker a `git add -A` commits them all (#426). An existing
398
+ # .gitignore is the user's and stays. Best effort: a cache dir that
399
+ # cannot be created or written belongs to the stages that need it, and
400
+ # they refuse with their established wording (#512 CI fault injection).
401
+ def ensure_artifacts_self_ignored
402
+ dir = config.path("cache_dir")
403
+ FileUtils.mkdir_p(dir)
404
+ marker = File.join(dir, ".gitignore")
405
+ File.write(marker, "*\n") unless File.exist?(marker)
406
+ rescue SystemCallError
407
+ nil
408
+ end
409
+
411
410
  # The last run's child logs (only those of errors are kept).
412
411
  def fresh_log_dir
413
412
  File.join(config.path("cache_dir"), "logs").tap do |dir|
@@ -416,46 +415,19 @@ module Saboteur
416
415
  end
417
416
  end
418
417
 
419
- # The lines that ran while the app and spec files loaded: the executable
420
- # counts from its first line, so this snapshot holds the whole boot.
421
- # Read here, in the parent: a forked child does not inherit Coverage
422
- # counters. They become the map's load lines, which tell ran-at-load
423
- # mutants apart from uncovered ones.
424
- def capture_load_lines(files)
425
- return {} unless Coverage.state == :suspended
426
-
427
- wanted = files.to_set { |file| Selection::CoverageMap.canonical(file) }
428
- Coverage.result(stop: false, clear: false).each_with_object({}) do |(path, data), hits|
429
- file = Selection::CoverageMap.canonical(path)
430
- next unless wanted.include?(file)
431
-
432
- lines = data[:lines].each_with_index.filter_map { |count, index| index + 1 if count&.positive? }
433
- lines -= uncalled_shared_lines(data)
434
- hits[file] = lines unless lines.empty?
435
- end
436
- end
437
-
438
- # A one-line or endless definition executes its def line even when its
439
- # body is never called. If any sibling on that physical line is uncalled,
440
- # discard its ambiguous line evidence rather than crediting every body.
441
- def uncalled_shared_lines(data)
442
- shared = data.fetch(:methods, {}).select { |(_owner, _name, first, _column, last, *), _| first == last }
443
- calls = shared.group_by { |(_owner, _name, first, *), _count| first }
444
- calls.filter_map { |line, entries| line if entries.any? { |_key, count| count.zero? } }
445
- end
446
-
447
418
  # Loads the target and stops coverage, returning what the rest of the
448
419
  # run needs from that boot.
449
420
  def boot_target(boot)
450
421
  @diagnostics.inform("loading the application")
451
422
  integration = boot.load_target
452
423
  files = config.included_files
453
- [integration, files, suspend_coverage(files)]
424
+ load_lines, load_methods = suspend_coverage(files)
425
+ [integration, files, load_lines, load_methods]
454
426
  end
455
427
 
456
428
  def suspend_coverage(files)
457
429
  (@coverage_guard = CoverageGuard.new(@diagnostics)).suspend
458
- capture_load_lines(files)
430
+ LoadCoverage.capture(files)
459
431
  end
460
432
 
461
433
  def monotonic = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@@ -478,6 +450,7 @@ require_relative "engine/candidates"
478
450
  require_relative "engine/candidate_selection"
479
451
  require_relative "engine/diff_scope"
480
452
  require_relative "engine/result_cache"
453
+ require_relative "engine/defined_order_prefix"
481
454
  require_relative "engine/verdict_check"
482
455
  require_relative "engine/scheduler"
483
456
  require_relative "engine/canary"