saboteur 0.7.0 → 0.8.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +772 -0
- data/README.md +221 -1072
- data/lib/saboteur/attribute_finder.rb +113 -0
- data/lib/saboteur/cli/exit_status.rb +32 -1
- data/lib/saboteur/cli/help_options.rb +2 -1
- data/lib/saboteur/cli/history_command.rb +135 -0
- data/lib/saboteur/cli/presets.rb +47 -3
- data/lib/saboteur/cli/run_budget_options.rb +3 -1
- data/lib/saboteur/cli/selection_options.rb +31 -0
- data/lib/saboteur/cli/shard_options.rb +17 -0
- data/lib/saboteur/cli/source_set.rb +35 -0
- data/lib/saboteur/cli/survivors_command.rb +157 -0
- data/lib/saboteur/cli.rb +74 -55
- data/lib/saboteur/config.rb +102 -6
- data/lib/saboteur/config_file.rb +19 -7
- data/lib/saboteur/constant_reads.rb +182 -0
- data/lib/saboteur/constant_subject.rb +70 -0
- data/lib/saboteur/constant_subject_finder.rb +281 -0
- data/lib/saboteur/coverage_reads.rb +29 -0
- data/lib/saboteur/custom_map.rb +12 -1
- data/lib/saboteur/dirty_tree_warning.rb +130 -0
- data/lib/saboteur/doctor.rb +13 -0
- data/lib/saboteur/engine/baseline_guard.rb +135 -21
- data/lib/saboteur/engine/boot.rb +11 -3
- data/lib/saboteur/engine/bytecode_equivalence.rb +17 -1
- data/lib/saboteur/engine/candidate_selection.rb +20 -0
- data/lib/saboteur/engine/candidates.rb +43 -3
- data/lib/saboteur/engine/coverage_store.rb +58 -14
- data/lib/saboteur/engine/defined_order_prefix.rb +43 -0
- data/lib/saboteur/engine/diagnostics.rb +19 -1
- data/lib/saboteur/engine/distribution.rb +10 -0
- data/lib/saboteur/engine/early_stop_recording.rb +3 -2
- data/lib/saboteur/engine/gated_run.rb +37 -0
- data/lib/saboteur/engine/load_coverage.rb +63 -0
- data/lib/saboteur/engine/out_of_scope_guard.rb +21 -0
- data/lib/saboteur/engine/pipelines.rb +115 -0
- data/lib/saboteur/engine/result_cache.rb +65 -8
- data/lib/saboteur/engine/run_budget.rb +32 -2
- data/lib/saboteur/engine/sandbox_policy.rb +59 -3
- data/lib/saboteur/engine/scheduler.rb +131 -17
- data/lib/saboteur/engine/selection_announcement.rb +59 -0
- data/lib/saboteur/engine/shard.rb +69 -0
- data/lib/saboteur/engine/subject_selection.rb +380 -21
- data/lib/saboteur/engine/test_guess.rb +407 -27
- data/lib/saboteur/engine/unchanged_syntax.rb +17 -2
- data/lib/saboteur/engine.rb +103 -129
- data/lib/saboteur/execution/external_runner.rb +489 -0
- data/lib/saboteur/execution/fiddle_loader.rb +34 -0
- data/lib/saboteur/execution/marker_sweep.rb +80 -0
- data/lib/saboteur/execution/peak_memory.rb +28 -0
- data/lib/saboteur/execution/process_table.rb +19 -3
- data/lib/saboteur/execution/process_tree.rb +65 -5
- data/lib/saboteur/execution/reevaluator.rb +75 -12
- data/lib/saboteur/execution/runner.rb +46 -7
- data/lib/saboteur/execution/sandbox.rb +25 -6
- data/lib/saboteur/execution/seatbelt.rb +233 -0
- data/lib/saboteur/execution/supervisor.rb +29 -11
- data/lib/saboteur/execution/test_command_shape.rb +149 -0
- data/lib/saboteur/execution/worker_pool.rb +23 -1
- data/lib/saboteur/frameworks/sqlite_memory_database.rb +79 -0
- data/lib/saboteur/gates.rb +43 -2
- data/lib/saboteur/help.rb +60 -9
- data/lib/saboteur/ignore_list.rb +29 -6
- data/lib/saboteur/integration/rspec.rb +223 -5
- data/lib/saboteur/mutation_source/argument_removal.rb +1 -1
- data/lib/saboteur/mutation_source/argument_swap.rb +54 -0
- data/lib/saboteur/mutation_source/builtin.rb +28 -5
- data/lib/saboteur/mutation_source/chain_removal.rb +1 -1
- data/lib/saboteur/mutation_source/condition_negation.rb +1 -1
- data/lib/saboteur/mutation_source/constant_literals.rb +66 -0
- data/lib/saboteur/mutation_source/element_removal.rb +73 -0
- data/lib/saboteur/mutation_source/endpoint_replacement.rb +1 -1
- data/lib/saboteur/mutation_source/entry_edits.rb +44 -0
- data/lib/saboteur/mutation_source/filter_replacement.rb +1 -1
- data/lib/saboteur/mutation_source/hazard_guard.rb +189 -0
- data/lib/saboteur/mutation_source/literal_replacement.rb +1 -1
- data/lib/saboteur/mutation_source/method_swap.rb +148 -0
- data/lib/saboteur/mutation_source/operator_assignment.rb +1 -1
- data/lib/saboteur/mutation_source/operator_examples.rb +4 -1
- data/lib/saboteur/mutation_source/operator_registry.rb +5 -2
- data/lib/saboteur/mutation_source/operator_visit.rb +1 -1
- data/lib/saboteur/mutation_source/pair_removal.rb +13 -31
- data/lib/saboteur/mutation_source/range_replacement.rb +1 -1
- data/lib/saboteur/mutation_source/regex_replacement.rb +93 -0
- data/lib/saboteur/preview.rb +125 -12
- data/lib/saboteur/refinement_activations.rb +60 -0
- data/lib/saboteur/reporter/agent.rb +9 -1
- data/lib/saboteur/reporter/agent_commands.rb +10 -3
- data/lib/saboteur/reporter/agent_incomplete.rb +31 -5
- data/lib/saboteur/reporter/agent_summary.rb +4 -3
- data/lib/saboteur/reporter/findings.rb +5 -2
- data/lib/saboteur/reporter/history_policy.rb +11 -0
- data/lib/saboteur/reporter/history_reader.rb +47 -0
- data/lib/saboteur/reporter/html.rb +26 -4
- data/lib/saboteur/reporter/mutation_text.rb +6 -0
- data/lib/saboteur/reporter/stryker.rb +27 -3
- data/lib/saboteur/reporter/survivor_classification.rb +101 -0
- data/lib/saboteur/reporter/survivor_list.rb +15 -9
- data/lib/saboteur/reporter/terminal.rb +56 -8
- data/lib/saboteur/result.rb +19 -3
- data/lib/saboteur/selection/coverage_map.rb +120 -10
- data/lib/saboteur/selection/dependency_shield.rb +80 -0
- data/lib/saboteur/selection/external_test_map.rb +27 -0
- data/lib/saboteur/selection/git_diff.rb +93 -11
- data/lib/saboteur/selection/layout_only_lines.rb +80 -0
- data/lib/saboteur/selection/recorder.rb +22 -4
- data/lib/saboteur/selection/source_scope.rb +22 -0
- data/lib/saboteur/subject.rb +42 -7
- data/lib/saboteur/subject_finder.rb +173 -29
- data/lib/saboteur/version.rb +1 -1
- data/lib/saboteur/working_tree.rb +38 -15
- data/lib/saboteur.rb +14 -0
- metadata +39 -16
data/lib/saboteur/engine.rb
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
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
|
|
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
|
|
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 =
|
|
119
|
-
@diagnostics.inform(guess.
|
|
120
|
-
|
|
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
|
-
|
|
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
|
|
127
|
-
# file without a conventional spec stops the run before boot
|
|
128
|
-
#
|
|
129
|
-
#
|
|
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 =
|
|
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
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
@diagnostics.announce(scope_to_guesses(guess))
|
|
142
|
-
end
|
|
138
|
+
inform_skipped_specs(guess)
|
|
139
|
+
raise ConfigError, guess.unmatched_message(verbose: @diagnostics.verbose) if guess.unmatched.any?
|
|
143
140
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
|
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?
|
|
159
145
|
|
|
160
|
-
|
|
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.
|
|
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
|
-
|
|
227
|
-
return [] if
|
|
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,
|
|
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
|
|
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
|
|
@@ -292,12 +268,15 @@ module Saboteur
|
|
|
292
268
|
guard = BaselineGuard.new(config: config, integration: integration, hooks: hooks,
|
|
293
269
|
supervisor: supervisor(memory_factor: 4), diagnostics: @diagnostics,
|
|
294
270
|
full_passes: full_passes, timeout_cap: method(:budget_capped_timeout),
|
|
295
|
-
between_passes: config["max_duration"] ? method(:budget_exceeded?) : nil
|
|
271
|
+
between_passes: config["max_duration"] ? method(:budget_exceeded?) : nil,
|
|
272
|
+
run_started: @run_started)
|
|
273
|
+
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
296
274
|
guard.call
|
|
275
|
+
@baseline_elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started
|
|
297
276
|
# Stability is the order comparison between completed checks: the cold
|
|
298
277
|
# coverage build is not a baseline pass, and a budget break shortens
|
|
299
278
|
# the loop, so certify only what actually ran.
|
|
300
|
-
@stable_suite = guard.completed_passes >= 2
|
|
279
|
+
@stable_suite = (@completed_baseline_passes = guard.completed_passes) >= 2
|
|
301
280
|
end
|
|
302
281
|
|
|
303
282
|
# A --id replay targets one known mutant; the whole-suite cost summary
|
|
@@ -322,14 +301,21 @@ module Saboteur
|
|
|
322
301
|
@sandbox_policy.hook
|
|
323
302
|
end
|
|
324
303
|
|
|
325
|
-
|
|
304
|
+
# The dependency universe a cached verdict watches when coverage
|
|
305
|
+
# cannot speak lives in Selection::CoverageMap (#344).
|
|
306
|
+
def source_files(files, prefixes: Selection::CoverageMap.root_prefixes(config.root))
|
|
307
|
+
Selection::CoverageMap.loaded_project_files(files, prefixes: prefixes)
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
def result_cache(map = nil, files = [])
|
|
326
311
|
return nil if @replay
|
|
327
312
|
return nil unless config["incremental"]
|
|
328
313
|
|
|
329
314
|
inputs = JSON.generate(VERDICT_INPUTS.to_h { |key| [key, config[key]] }
|
|
330
315
|
.merge("operator_policy" => config.operator_policy))
|
|
331
316
|
ResultCache.new(path: File.join(config.path("cache_dir"), "results.json"), root: @root, inputs: inputs,
|
|
332
|
-
suite_digest: SuiteFiles.new(config).digest
|
|
317
|
+
suite_digest: SuiteFiles.new(config).digest,
|
|
318
|
+
coverage: map, fallback_files: source_files(files))
|
|
333
319
|
end
|
|
334
320
|
|
|
335
321
|
# A cleanup failure must never mask the run's own outcome - not even
|
|
@@ -349,11 +335,7 @@ module Saboteur
|
|
|
349
335
|
# Each subject's candidates, narrowed to changed lines in diff mode.
|
|
350
336
|
# The hazard guard is off only when the user explicitly asks for the
|
|
351
337
|
# 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
|
|
338
|
+
def hazard_guard = (MutationSource::HazardGuard.new(config["hazard"]) unless config["allow_hazardous"])
|
|
357
339
|
|
|
358
340
|
# Checks the tree after each subject's mutants; a vanished file means a
|
|
359
341
|
# mutant deleted it, so abort with the most recent mutant's digest.
|
|
@@ -382,10 +364,13 @@ module Saboteur
|
|
|
382
364
|
def candidate_lists(subjects, scope, map)
|
|
383
365
|
return [@replay_candidate] if @replay
|
|
384
366
|
|
|
385
|
-
candidates = Candidates.
|
|
367
|
+
candidates = Candidates.build(config, @diagnostics, hazard_guard: hazard_guard)
|
|
386
368
|
selection = CandidateSelection.new(candidates: candidates, map: map,
|
|
387
369
|
limit: config["max_mutants_per_method"], diagnostics: @diagnostics)
|
|
388
|
-
subjects.map { |subject| selection.for(subject, scope: scope) }
|
|
370
|
+
lists = subjects.map { |subject| selection.for(subject, scope: scope) }
|
|
371
|
+
@shard = Engine::Shard.parse(config["shard"]) if config["shard"]
|
|
372
|
+
lists = @shard.select(subjects, lists) if @shard
|
|
373
|
+
lists.tap do
|
|
389
374
|
@skipped_subjects = selection.skipped_subjects
|
|
390
375
|
@unscoped_digests = selection.unscoped_digests
|
|
391
376
|
if @run_evidence
|
|
@@ -396,7 +381,7 @@ module Saboteur
|
|
|
396
381
|
end
|
|
397
382
|
|
|
398
383
|
def replay_subject(subjects, scope)
|
|
399
|
-
candidates = Candidates.
|
|
384
|
+
candidates = Candidates.build(config, @diagnostics, hazard_guard: hazard_guard)
|
|
400
385
|
subject, candidate = @replay.select(subjects, candidates, scope: scope)
|
|
401
386
|
@replay_candidate = [candidate]
|
|
402
387
|
[[subject], nil]
|
|
@@ -408,6 +393,21 @@ module Saboteur
|
|
|
408
393
|
Execution::Supervisor.new(limits: limits)
|
|
409
394
|
end
|
|
410
395
|
|
|
396
|
+
# Artifact dirs ignore themselves, the pattern git, vagrant and bundler
|
|
397
|
+
# use: a run writes logs, coverage maps and reports under cache_dir, and
|
|
398
|
+
# without the marker a `git add -A` commits them all (#426). An existing
|
|
399
|
+
# .gitignore is the user's and stays. Best effort: a cache dir that
|
|
400
|
+
# cannot be created or written belongs to the stages that need it, and
|
|
401
|
+
# they refuse with their established wording (#512 CI fault injection).
|
|
402
|
+
def ensure_artifacts_self_ignored
|
|
403
|
+
dir = config.path("cache_dir")
|
|
404
|
+
FileUtils.mkdir_p(dir)
|
|
405
|
+
marker = File.join(dir, ".gitignore")
|
|
406
|
+
File.write(marker, "*\n") unless File.exist?(marker)
|
|
407
|
+
rescue SystemCallError
|
|
408
|
+
nil
|
|
409
|
+
end
|
|
410
|
+
|
|
411
411
|
# The last run's child logs (only those of errors are kept).
|
|
412
412
|
def fresh_log_dir
|
|
413
413
|
File.join(config.path("cache_dir"), "logs").tap do |dir|
|
|
@@ -416,46 +416,19 @@ module Saboteur
|
|
|
416
416
|
end
|
|
417
417
|
end
|
|
418
418
|
|
|
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
419
|
# Loads the target and stops coverage, returning what the rest of the
|
|
448
420
|
# run needs from that boot.
|
|
449
421
|
def boot_target(boot)
|
|
450
422
|
@diagnostics.inform("loading the application")
|
|
451
423
|
integration = boot.load_target
|
|
452
424
|
files = config.included_files
|
|
453
|
-
|
|
425
|
+
load_lines, load_methods = suspend_coverage(files)
|
|
426
|
+
[integration, files, load_lines, load_methods]
|
|
454
427
|
end
|
|
455
428
|
|
|
456
429
|
def suspend_coverage(files)
|
|
457
430
|
(@coverage_guard = CoverageGuard.new(@diagnostics)).suspend
|
|
458
|
-
|
|
431
|
+
LoadCoverage.capture(files)
|
|
459
432
|
end
|
|
460
433
|
|
|
461
434
|
def monotonic = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
@@ -478,6 +451,7 @@ require_relative "engine/candidates"
|
|
|
478
451
|
require_relative "engine/candidate_selection"
|
|
479
452
|
require_relative "engine/diff_scope"
|
|
480
453
|
require_relative "engine/result_cache"
|
|
454
|
+
require_relative "engine/defined_order_prefix"
|
|
481
455
|
require_relative "engine/verdict_check"
|
|
482
456
|
require_relative "engine/scheduler"
|
|
483
457
|
require_relative "engine/canary"
|