henitai 0.6.0 → 0.7.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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +111 -1
  3. data/README.md +23 -6
  4. data/assets/schema/henitai.schema.json +6 -0
  5. data/lib/henitai/bootstrap_error_message.rb +20 -2
  6. data/lib/henitai/checkpoint_reporter.rb +5 -0
  7. data/lib/henitai/cli/operator_command.rb +10 -3
  8. data/lib/henitai/cli.rb +2 -1
  9. data/lib/henitai/composite_progress_reporter.rb +15 -2
  10. data/lib/henitai/configuration.rb +6 -1
  11. data/lib/henitai/configuration_validator/rules.rb +1 -0
  12. data/lib/henitai/configuration_validator/scalars.rb +13 -0
  13. data/lib/henitai/configuration_validator.rb +2 -1
  14. data/lib/henitai/control_gate.rb +78 -0
  15. data/lib/henitai/control_run.rb +37 -43
  16. data/lib/henitai/coverage_bootstrapper.rb +12 -3
  17. data/lib/henitai/execution_engine/env_scope.rb +3 -3
  18. data/lib/henitai/execution_engine/fork_server_scope.rb +6 -6
  19. data/lib/henitai/execution_engine.rb +74 -99
  20. data/lib/henitai/execution_provenance.rb +67 -0
  21. data/lib/henitai/flaky_detection_baseline.rb +5 -3
  22. data/lib/henitai/fork_server/client.rb +0 -9
  23. data/lib/henitai/fork_server/mutant_runner.rb +14 -45
  24. data/lib/henitai/fork_server.rb +0 -1
  25. data/lib/henitai/history_checkpointer.rb +72 -0
  26. data/lib/henitai/integration/base.rb +6 -14
  27. data/lib/henitai/integration/child_report_store.rb +34 -5
  28. data/lib/henitai/integration/minitest.rb +1 -8
  29. data/lib/henitai/integration/minitest_fail_fast.rb +43 -0
  30. data/lib/henitai/integration/minitest_outcome_reporter.rb +17 -1
  31. data/lib/henitai/integration/minitest_test_runner.rb +16 -4
  32. data/lib/henitai/integration/mutant_run_support.rb +11 -8
  33. data/lib/henitai/integration/rspec_child_runner.rb +12 -7
  34. data/lib/henitai/integration/rspec_file_order.rb +37 -0
  35. data/lib/henitai/integration/rspec_process_runner.rb +0 -19
  36. data/lib/henitai/integration.rb +2 -3
  37. data/lib/henitai/kill_history/store.rb +67 -0
  38. data/lib/henitai/kill_history.rb +85 -0
  39. data/lib/henitai/mutant.rb +5 -0
  40. data/lib/henitai/mutant_history_store/database.rb +61 -0
  41. data/lib/henitai/mutant_history_store/sql.rb +9 -3
  42. data/lib/henitai/mutant_history_store/subject_scans.rb +101 -0
  43. data/lib/henitai/mutant_history_store/verdict_cache.rb +40 -11
  44. data/lib/henitai/mutant_history_store.rb +66 -50
  45. data/lib/henitai/operator.rb +6 -2
  46. data/lib/henitai/operators/equality_identity_operator.rb +2 -2
  47. data/lib/henitai/operators/hash_key_type.rb +11 -1
  48. data/lib/henitai/operators/hash_literal.rb +30 -5
  49. data/lib/henitai/operators/string_literal.rb +17 -4
  50. data/lib/henitai/process_worker_runner.rb +23 -3
  51. data/lib/henitai/reuse_context.rb +4 -2
  52. data/lib/henitai/rspec_outcomes.rb +3 -1
  53. data/lib/henitai/runner.rb +54 -2
  54. data/lib/henitai/runner_dependencies.rb +23 -3
  55. data/lib/henitai/scenario_execution_result.rb +27 -4
  56. data/lib/henitai/signal_deferral.rb +25 -0
  57. data/lib/henitai/slot_scheduler/control_slots.rb +58 -0
  58. data/lib/henitai/slot_scheduler/draining.rb +25 -6
  59. data/lib/henitai/slot_scheduler/retry_policy.rb +13 -1
  60. data/lib/henitai/slot_scheduler.rb +18 -14
  61. data/lib/henitai/test_file_outcomes.rb +15 -1
  62. data/lib/henitai/test_prioritizer.rb +10 -2
  63. data/lib/henitai/version.rb +1 -1
  64. data/lib/henitai.rb +5 -1
  65. data/sig/henitai.rbs +42 -24
  66. metadata +21 -6
  67. data/lib/henitai/flaky_mutant_retrier.rb +0 -43
  68. data/lib/henitai/fork_server/group_terminator.rb +0 -47
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "securerandom"
4
+
3
5
  module Henitai
4
6
  # Orchestrates the full mutation testing pipeline.
5
7
  #
@@ -82,12 +84,14 @@ module Henitai
82
84
  # static/skip/arid/stillborn filtering — everything short of execution.
83
85
  def pipeline_mutants
84
86
  if survivor_rerun? && (fast_mutants = survivor_strategy.try_recipe_run)
87
+ @recipe_run = true
85
88
  # Gate 0 still runs: test selection reads the per-test map, which must
86
89
  # include new or edited tests.
87
90
  bootstrap_coverage(fast_mutants.filter_map { |mutant| mutant.subject.source_file }.uniq)
88
91
  return fast_mutants
89
92
  end
90
93
 
94
+ capture_provenance unless @dry_run
91
95
  source_files = self.source_files
92
96
  subjects = resolve_subjects(source_files)
93
97
  mutants_for(subjects, source_files)
@@ -146,6 +150,13 @@ module Henitai
146
150
 
147
151
  def reuse_filter = deps.reuse_filter
148
152
 
153
+ # Before Gate 1 parses anything: what the run may parse, load or execute
154
+ # (ADR-19). Dry runs record nothing, and the recipe fast path's stubs are
155
+ # never cacheable, so neither captures.
156
+ def capture_provenance
157
+ deps.capture_provenance(source_files + Array(integration.test_files))
158
+ end
159
+
149
160
  def bootstrap_mutants(source_files) = Thread.new { bootstrap_coverage(source_files) }
150
161
 
151
162
  def execute_mutants(mutants)
@@ -155,6 +166,25 @@ module Henitai
155
166
  config,
156
167
  progress_reporter: progress_reporter
157
168
  )
169
+ rescue SignalException
170
+ save_interrupted_progress
171
+ raise
172
+ end
173
+
174
+ # The engine has torn its children down by now. Whatever the observers
175
+ # still buffer is written, so `--incremental` can resume (ADR-19); the
176
+ # aborted run itself gets no history record.
177
+ def save_interrupted_progress
178
+ flush_progress
179
+ saved = history_checkpointer&.committed || 0
180
+ warn "henitai: interrupted; #{saved} verdicts saved, resume with --incremental"
181
+ end
182
+
183
+ def flush_progress
184
+ reporter = progress_reporter
185
+ reporter.flush if reporter.respond_to?(:flush)
186
+ rescue StandardError => e
187
+ warn "henitai: could not flush progress (#{e.class}: #{e.message})"
158
188
  end
159
189
 
160
190
  def report(result)
@@ -167,12 +197,19 @@ module Henitai
167
197
  history_store.record(
168
198
  result,
169
199
  version: Henitai::VERSION,
170
- recorded_at:
200
+ recorded_at:,
201
+ operators: config.operators,
202
+ full_scan: full_mutant_set?,
203
+ run_id:
171
204
  )
172
205
  rescue StandardError => e
173
206
  warn "henitai: could not record mutation history (#{e.class}: #{e.message}); reports are still written"
174
207
  end
175
208
 
209
+ # A sampled run generates a fraction of each subject's mutants, so it
210
+ # cannot stand as evidence that the ones it omitted no longer exist.
211
+ def full_mutant_set? = config.respond_to?(:sampling) && config.sampling.to_h[:ratio].nil?
212
+
176
213
  def build_result(mutants, started_at, finished_at)
177
214
  @result = build_result_object(mutants, started_at, finished_at)
178
215
  persist_history(@result, finished_at)
@@ -246,7 +283,22 @@ module Henitai
246
283
  def source_selection_coverage = deps.source_selection_coverage
247
284
  def source_provider = deps.source_provider
248
285
 
249
- def progress_reporter = deps.progress_reporter(full_run: full_run?)
286
+ # Built once per run, so an interrupt flushes the observers the engine
287
+ # was given.
288
+ def progress_reporter
289
+ return @progress_reporter if defined?(@progress_reporter)
290
+
291
+ @progress_reporter = deps.progress_reporter(full_run: full_run?, history_checkpointer:)
292
+ end
293
+
294
+ # Recipe stubs are never cacheable, so the fast path checkpoints nothing.
295
+ def history_checkpointer
296
+ return @history_checkpointer if defined?(@history_checkpointer)
297
+
298
+ @history_checkpointer = @recipe_run ? nil : deps.history_checkpointer(run_id:)
299
+ end
300
+
301
+ def run_id = @run_id ||= SecureRandom.uuid
250
302
 
251
303
  def source_files
252
304
  @source_files ||= source_file_selection.call
@@ -48,10 +48,21 @@ module Henitai
48
48
  @history_store ||= MutantHistoryStore.new(
49
49
  path: File.join(@config.reports_dir, Henitai::HISTORY_STORE_FILENAME),
50
50
  per_test_coverage: per_test_coverage,
51
- reuse_context: reuse_context
51
+ reuse_context: reuse_context,
52
+ provenance: execution_provenance
52
53
  )
53
54
  end
54
55
 
56
+ # Records the run's inputs; {Runner} calls it before Gate 1 parses
57
+ # anything (ADR-19). @return [ExecutionProvenance]
58
+ def capture_provenance(paths)
59
+ @execution_provenance = ExecutionProvenance.capture(paths)
60
+ end
61
+
62
+ # Until the capture, nothing counts as intact: a store built too early
63
+ # caches nothing rather than vouch for unrecorded inputs.
64
+ def execution_provenance = @execution_provenance || ExecutionProvenance::UNCAPTURED
65
+
55
66
  # Shared by the incremental filter and the history store: verdicts are
56
67
  # recorded under exactly the context they are later checked against.
57
68
  def reuse_context
@@ -71,8 +82,17 @@ module Henitai
71
82
  # Deliberately *not* memoized: `full_run?` is a property of the invocation,
72
83
  # not of the dependency set, and a cached reporter would silently keep the
73
84
  # first answer.
74
- def progress_reporter(full_run:)
75
- CompositeProgressReporter.for(config: @config, source_provider: source_provider, full_run: full_run)
85
+ def progress_reporter(full_run:, history_checkpointer: nil)
86
+ CompositeProgressReporter.for(config: @config, source_provider: source_provider, full_run: full_run,
87
+ history_checkpointer:)
88
+ end
89
+
90
+ # Checkpoints verdicts into the history store during the run (ADR-19);
91
+ # nil when `reports.checkpoint` is off.
92
+ def history_checkpointer(run_id:)
93
+ return unless @config.respond_to?(:checkpoint_enabled) && @config.checkpoint_enabled
94
+
95
+ HistoryCheckpointer.new(history_store:, config: @config, run_id:)
76
96
  end
77
97
 
78
98
  # Reads each source file once and caches it per path, so Result consumes
@@ -3,7 +3,7 @@
3
3
  module Henitai
4
4
  # Captures the result of one baseline or mutant test run.
5
5
  class ScenarioExecutionResult
6
- attr_reader :status, :status_reason, :stdout, :stderr, :exit_status, :log_path, :killing_tests
6
+ attr_reader :status, :status_reason, :stdout, :stderr, :exit_status, :log_path, :killing_tests, :hanging_test
7
7
 
8
8
  def self.build(wait_result:, stdout:, stderr:, log_path:)
9
9
  new(
@@ -23,16 +23,26 @@ module Henitai
23
23
  mutant.status_reason = result.status_reason
24
24
  end
25
25
 
26
+ # The verdict of a child that could not be spawned at all.
27
+ def self.spawn_failure(error)
28
+ new(status: :compile_error, stdout: "", stderr: "spawn failed: #{error.message}", log_path: "/dev/null")
29
+ end
30
+
26
31
  # Classifies a mutant run from the child's report (see MutantVerdict).
27
- def self.build_for_mutant(wait_result:, report:, stdout:, stderr:, log_path:)
32
+ # +running_test+ is the test file the child was executing when it was
33
+ # killed; it is kept only for a timeout (see #hanging_test).
34
+ # rubocop:disable Metrics/ParameterLists -- one keyword per captured field
35
+ def self.build_for_mutant(wait_result:, report:, stdout:, stderr:, log_path:, running_test: nil)
36
+ # rubocop:enable Metrics/ParameterLists
28
37
  verdict = MutantVerdict.new(wait_result:, report:, stdout:, stderr:)
29
38
  status, status_reason = verdict.to_a
30
39
  new(status:, status_reason:, stdout:, stderr:, log_path:, exit_status: exit_status_for(wait_result),
31
- killing_tests: verdict.killing_tests)
40
+ killing_tests: verdict.killing_tests, hanging_test: hanging_test_for(status, running_test))
32
41
  end
33
42
 
34
43
  # rubocop:disable Metrics/ParameterLists -- one keyword per captured field
35
- def initialize(status:, stdout:, stderr:, log_path:, exit_status: nil, status_reason: nil, killing_tests: [])
44
+ def initialize(status:, stdout:, stderr:, log_path:, exit_status: nil, status_reason: nil, killing_tests: [],
45
+ hanging_test: nil)
36
46
  # rubocop:enable Metrics/ParameterLists
37
47
  @status = status
38
48
  @status_reason = status_reason
@@ -41,6 +51,14 @@ module Henitai
41
51
  @log_path = log_path
42
52
  @exit_status = exit_status
43
53
  @killing_tests = killing_tests
54
+ @hanging_test = hanging_test
55
+ end
56
+
57
+ # The same run under a different verdict, e.g. a detection a failing
58
+ # control reclassified (ADR-14). Output and exit data are kept.
59
+ def reclassified(status:, status_reason:)
60
+ self.class.new(status:, status_reason:, stdout:, stderr:, log_path:, exit_status:, killing_tests:,
61
+ hanging_test:)
44
62
  end
45
63
 
46
64
  # Frees the captured child output once it has been consumed (e.g. by the
@@ -109,6 +127,11 @@ module Henitai
109
127
  class << self
110
128
  private
111
129
 
130
+ # The test file a timed-out child was running; nil for any other verdict.
131
+ def hanging_test_for(status, running_test)
132
+ status == :timeout ? running_test : nil
133
+ end
134
+
112
135
  def status_for(wait_result, stdout:, stderr:)
113
136
  return :timeout if wait_result == :timeout
114
137
  return :compile_error if no_examples_found?(stdout, stderr)
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Henitai
4
+ # Holds INT, TERM and HUP back while a block runs, then re-sends the first
5
+ # one that arrived (ADR-19). A history write therefore commits or rolls
6
+ # back as a whole before the signal takes effect.
7
+ #
8
+ # `Thread.handle_interrupt` cannot do this: it does not defer the
9
+ # `Interrupt` Ruby raises for a signal on the main thread.
10
+ module SignalDeferral
11
+ SIGNALS = %w[INT TERM HUP].freeze
12
+ RESEND = ->(signal) { Process.kill(signal, Process.pid) }
13
+
14
+ module_function
15
+
16
+ def call(resend: RESEND)
17
+ pending = nil
18
+ saved = SIGNALS.to_h { |signal| [signal, Signal.trap(signal) { pending ||= signal }] }
19
+ yield
20
+ ensure
21
+ saved&.each { |signal, handler| Signal.trap(signal, handler) }
22
+ resend.call(pending) if pending
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Henitai
4
+ class SlotScheduler
5
+ # Control jobs (ADR-19 §2): the unmutated method of a group whose first
6
+ # detection a {ControlGate} is holding. A control job is not a mutant job:
7
+ #
8
+ # - it is spawned ahead of pending mutants, with its group's test files
9
+ # (no reselection);
10
+ # - it runs as a local child (`spawn_local` when the integration is the
11
+ # fork-server runner, which registers the pid with the server runtime
12
+ # and applies a boot-inclusive timeout); the server never saw it;
13
+ # - it is never retried, and it is neither a result nor progress;
14
+ # - every terminal outcome -- exit, timeout, spawn failure -- reaches the
15
+ # listener once. A control interrupted by shutdown reports nothing: the
16
+ # gate's held detections are dropped with the run.
17
+ #
18
+ # Mixed into {SlotScheduler}; relies on its slot table and spawn helpers.
19
+ module ControlSlots
20
+ ControlJob = Struct.new(:key, :mutant, :test_files)
21
+
22
+ def enqueue_control(key, mutant, test_files)
23
+ control_jobs << ControlJob.new(key, mutant, test_files)
24
+ end
25
+
26
+ private
27
+
28
+ def control_jobs = @control_jobs ||= []
29
+
30
+ def spawn_control_into_slot(job)
31
+ worker_index = slot_table.next_free_worker_index(worker_count)
32
+ with_worker_slot(worker_index) do
33
+ handle = spawn_control_child(job)
34
+ timeout = handle.timeout || slot_timeout(job.mutant, job.test_files)
35
+ register_slot(handle, job.mutant, worker_index, timeout, control_key: job.key)
36
+ end
37
+ rescue StandardError => e
38
+ report_control(job.key, ScenarioExecutionResult.spawn_failure(e))
39
+ end
40
+
41
+ def spawn_control_child(job)
42
+ spawner = integration.respond_to?(:spawn_local) ? :spawn_local : :spawn_mutant
43
+ integration.public_send(spawner, mutant: job.mutant, test_files: job.test_files)
44
+ end
45
+
46
+ def complete_control(slot, wait_result)
47
+ slot_table.delete(slot.slot_id)
48
+ report_control(slot.control_key, integration.build_result(wait_result, slot.log_paths))
49
+ end
50
+
51
+ # The gate keeps only the control's verdict, never its output.
52
+ def report_control(key, result)
53
+ @control_listener&.control_finished(key, result)
54
+ result.release_output! if result.respond_to?(:release_output!)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -50,7 +50,7 @@ module Henitai
50
50
  return if draining.empty?
51
51
 
52
52
  broadcast_term(draining)
53
- wait_for_drain_window
53
+ wait_for_drain_window(draining)
54
54
  signal_draining_slots(draining)
55
55
  reap_and_remove_draining(draining)
56
56
  end
@@ -80,9 +80,12 @@ module Henitai
80
80
  end
81
81
  end
82
82
 
83
- # Unrelated events (CHLD of another slot, server traffic) wake the select
84
- # early; the SIGTERM grace window must still run its full length.
85
- def wait_for_drain_window
83
+ # The SIGTERM grace window ends at its deadline or as soon as every
84
+ # draining child has exited, whichever comes first. Unrelated events
85
+ # (CHLD of another slot, server traffic) wake the select early without
86
+ # ending it. Waiting out the full window for a child that already exited
87
+ # cost every timed-out mutant PROCESS_DRAIN_WINDOW of wall time.
88
+ def wait_for_drain_window(draining)
86
89
  return unless wakeup
87
90
 
88
91
  deadline = monotonic_time + PROCESS_DRAIN_WINDOW
@@ -90,9 +93,16 @@ module Henitai
90
93
  woken = wakeup.wait(remaining)
91
94
  wakeup.drain
92
95
  break unless woken
96
+ break if all_exited?(draining)
93
97
  end
94
98
  end
95
99
 
100
+ # Reaps what has exited; the status waits on the slot for the final reap.
101
+ def all_exited?(draining)
102
+ draining.each_value { |slot| slot.reaped_status ||= wnohang_reap(slot.pid)&.last }
103
+ draining.each_value.all?(&:reaped_status)
104
+ end
105
+
96
106
  def signal_draining_slots(draining)
97
107
  draining.each_value { |slot| signal_process_group(slot.pid, :SIGKILL) }
98
108
  end
@@ -121,8 +131,7 @@ module Henitai
121
131
  # One last WNOHANG before blocking: catches processes that exited
122
132
  # between SIGKILL and here.
123
133
  def reap_and_finalize_slot(slot)
124
- _, final_status = wnohang_reap(slot.pid)
125
- reap_pid(slot.pid) unless final_status
134
+ final_status = final_reap(slot)
126
135
  tear_down_process_group(slot.pid)
127
136
 
128
137
  slot_table.release_pid(slot.pid)
@@ -134,8 +143,18 @@ module Henitai
134
143
  record_drain_result(slot, final_status)
135
144
  end
136
145
 
146
+ # The status the drain window already reaped, else a last WNOHANG, else
147
+ # a blocking reap (which yields no status worth classifying).
148
+ def final_reap(slot)
149
+ status = slot.reaped_status || wnohang_reap(slot.pid)&.last
150
+ reap_pid(slot.pid) unless status
151
+ status
152
+ end
153
+
137
154
  def record_drain_result(slot, final_status)
138
155
  result = drain_verdict.build(slot, final_status)
156
+ return report_control(slot.control_key, result) if slot.control_key
157
+
139
158
  slot.mutant.status = result.status
140
159
  ScenarioExecutionResult.copy_reason(result, slot.mutant)
141
160
  results << result
@@ -14,7 +14,19 @@ module Henitai
14
14
  end
15
15
 
16
16
  def retry?(slot:, result:, shutdown:)
17
- return false if shutdown || result.status != :killed
17
+ !shutdown && retry_wanted?(slot, result)
18
+ end
19
+
20
+ # True when only the shutdown stopped a retry: the kill may be faked by
21
+ # a flaky test, so its verdict must not be cached (ADR-19).
22
+ def vetoed?(slot:, result:, shutdown:)
23
+ shutdown && retry_wanted?(slot, result)
24
+ end
25
+
26
+ private
27
+
28
+ def retry_wanted?(slot, result)
29
+ return false unless result.status == :killed
18
30
 
19
31
  @decision.retry?(status: :killed, killing_tests: result.killing_tests, attempts: slot.retry_count)
20
32
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "slot_scheduler/process_control"
4
+ require_relative "slot_scheduler/control_slots"
4
5
  require_relative "slot_scheduler/draining"
5
6
  require_relative "slot_scheduler/drain_verdict"
6
7
  require_relative "slot_scheduler/retry_policy"
@@ -25,6 +26,7 @@ module Henitai
25
26
  class SlotScheduler
26
27
  include ProcessControl
27
28
  include Draining
29
+ include ControlSlots
28
30
 
29
31
  PROCESS_DRAIN_WINDOW = 0.2
30
32
 
@@ -38,7 +40,7 @@ module Henitai
38
40
  Slot = Struct.new(
39
41
  :slot_id, :mutant, :pid, :started_at_monotonic, :timeout,
40
42
  :log_paths, :retry_count, :draining, :term_sent_at_monotonic,
41
- :forced_outcome, :worker_index
43
+ :forced_outcome, :worker_index, :control_key, :reaped_status
42
44
  )
43
45
 
44
46
  # @return [Integer] mutants that required at least one retry during the run.
@@ -52,7 +54,7 @@ module Henitai
52
54
  # collaborator supplied by ProcessWorkerRunner; bundling them into a context
53
55
  # object would only move the list.
54
56
  def initialize(integration:, config:, progress_reporter:, options:, host:, slot_table: SlotTable.new,
55
- flaky_tests: nil)
57
+ flaky_tests: nil, control_listener: nil)
56
58
  # rubocop:enable Metrics/ParameterLists
57
59
  @integration = integration
58
60
  @config = config
@@ -61,6 +63,7 @@ module Henitai
61
63
  @host = host
62
64
  @slot_table = slot_table
63
65
  @injected_flaky_tests = flaky_tests
66
+ @control_listener = control_listener
64
67
  @pending = []
65
68
  @results = []
66
69
  @flaky_retry_count = 0
@@ -72,13 +75,13 @@ module Henitai
72
75
  end
73
76
 
74
77
  def done?
75
- pending.empty? && slot_table.empty?
78
+ pending.empty? && control_jobs.empty? && slot_table.empty?
76
79
  end
77
80
 
81
+ # Queued control jobs go first: detections wait on them (ADR-19).
78
82
  def fill_idle_slots
79
- while slot_table.size < worker_count && !pending.empty?
80
- mutant = pending.shift
81
- spawn_into_slot(mutant)
83
+ while slot_table.size < worker_count && (control_jobs.any? || pending.any?)
84
+ control_jobs.any? ? spawn_control_into_slot(control_jobs.shift) : spawn_into_slot(pending.shift)
82
85
  end
83
86
  end
84
87
 
@@ -135,8 +138,9 @@ module Henitai
135
138
  mutant.tests_completed = test_files.size if mutant.respond_to?(:tests_completed=)
136
139
  end
137
140
 
138
- def register_slot(handle, mutant, worker_index, timeout)
141
+ def register_slot(handle, mutant, worker_index, timeout, control_key: nil)
139
142
  slot = build_slot(slot_table.next_slot_id!, mutant, handle, worker_index, timeout)
143
+ slot.control_key = control_key
140
144
  slot_table.add(slot)
141
145
  slot_table.register_pid(handle.pid, slot.slot_id)
142
146
  Integration::SchedulerDiagnostics.child_started(handle.pid)
@@ -169,6 +173,7 @@ module Henitai
169
173
  return unless slot
170
174
 
171
175
  Integration::SchedulerDiagnostics.child_ended(pid)
176
+ return complete_control(slot, wait_result) if slot.control_key
172
177
  return rerun_lost_slot(slot) if lost?(wait_result)
173
178
 
174
179
  result = integration.build_result(wait_result, slot.log_paths)
@@ -178,9 +183,14 @@ module Henitai
178
183
  def dispatch_slot_result(slot, result)
179
184
  return retry_slot(slot) if retry_policy.retry?(slot: slot, result: result, shutdown: shutdown?)
180
185
 
186
+ mark_retry_cut_short(slot) if retry_policy.vetoed?(slot: slot, result: result, shutdown: shutdown?)
181
187
  finalize_slot(slot, result)
182
188
  end
183
189
 
190
+ def mark_retry_cut_short(slot)
191
+ slot.mutant.retry_cut_short = true if slot.mutant.respond_to?(:retry_cut_short=)
192
+ end
193
+
184
194
  def finalize_slot(slot, result)
185
195
  slot_table.delete(slot.slot_id)
186
196
  slot.mutant.status = result.status
@@ -267,13 +277,7 @@ module Henitai
267
277
  end
268
278
 
269
279
  def record_spawn_failure(mutant, error)
270
- result = ScenarioExecutionResult.new(
271
- status: :compile_error,
272
- stdout: "",
273
- stderr: "spawn failed: #{error.message}",
274
- log_path: "/dev/null",
275
- exit_status: nil
276
- )
280
+ result = ScenarioExecutionResult.spawn_failure(error)
277
281
  mutant.status = result.status
278
282
  results << result
279
283
  progress_reporter&.progress(mutant, scenario_result: result)
@@ -37,9 +37,23 @@ module Henitai
37
37
  new
38
38
  end
39
39
 
40
- def initialize
40
+ # @param on_started [#call, nil] called with the expanded path each time
41
+ # a different test file starts (see {#started})
42
+ def initialize(on_started: nil)
41
43
  @failed = {}
42
44
  @unattributed_failures = false
45
+ @on_started = on_started
46
+ @started_file = nil
47
+ end
48
+
49
+ # Reports that +file+ is now running. Repeated starts of the same file
50
+ # are not reported again.
51
+ def started(file)
52
+ path = File.expand_path(file)
53
+ return if path == @started_file
54
+
55
+ @started_file = path
56
+ @on_started&.call(path)
43
57
  end
44
58
 
45
59
  def record(file, failed:)
@@ -8,6 +8,10 @@ module Henitai
8
8
  # ascending, so the first kill costs as little wall-clock as possible.
9
9
  # Untimed tests sort after timed ones by original inventory order; with no
10
10
  # timing source at all the ordering is exactly the historical behavior.
11
+ #
12
+ # A test file that hung (timed out) for a mutant of the same subject goes
13
+ # last, ahead of every other key, so the hang is reached only after the
14
+ # mutant's other candidates have had their chance to kill it.
11
15
  class TestPrioritizer
12
16
  # @param timing_source [#call, nil] returns a Hash of test file path to
13
17
  # wall-clock seconds; resolved lazily on first sort.
@@ -15,14 +19,18 @@ module Henitai
15
19
  @timing_source = timing_source
16
20
  end
17
21
 
18
- def sort(tests, _mutant, history)
22
+ def sort(tests, mutant, history)
19
23
  Array(tests).each_with_index.sort_by do |test, index|
20
- [-history_count(history, test), runtime(test), index]
24
+ [hung_rank(history, mutant, test), -history_count(history, test), runtime(test), index]
21
25
  end.map(&:first)
22
26
  end
23
27
 
24
28
  private
25
29
 
30
+ def hung_rank(history, mutant, test)
31
+ history.respond_to?(:hung?) && history.hung?(mutant, test) ? 1 : 0
32
+ end
33
+
26
34
  def runtime(test)
27
35
  durations = timing_durations
28
36
  history_key_candidates(test).each do |key|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Henitai
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.0"
5
5
  end
data/lib/henitai.rb CHANGED
@@ -53,6 +53,10 @@ module Henitai
53
53
  autoload :StillbornFilter, "henitai/stillborn_filter"
54
54
  autoload :FidelityCheck, "henitai/fidelity_check"
55
55
  autoload :ControlRun, "henitai/control_run"
56
+ autoload :ControlGate, "henitai/control_gate"
57
+ autoload :ExecutionProvenance, "henitai/execution_provenance"
58
+ autoload :SignalDeferral, "henitai/signal_deferral"
59
+ autoload :HistoryCheckpointer, "henitai/history_checkpointer"
56
60
  autoload :CanonicalReportMerger, "henitai/canonical_report_merger"
57
61
  autoload :CanonicalReportWriter, "henitai/canonical_report_writer"
58
62
  autoload :CheckpointReporter, "henitai/checkpoint_reporter"
@@ -69,7 +73,6 @@ module Henitai
69
73
  autoload :ScenarioExecutionResult, "henitai/scenario_execution_result"
70
74
  autoload :FlakyTestRegistry, "henitai/flaky_test_registry"
71
75
  autoload :FlakyDetectionBaseline, "henitai/flaky_detection_baseline"
72
- autoload :FlakyMutantRetrier, "henitai/flaky_mutant_retrier"
73
76
  autoload :TestFileOutcomes, "henitai/test_file_outcomes"
74
77
  autoload :FlakyRetryDecision, "henitai/flaky_retry_decision"
75
78
  autoload :ExampleSummary, "henitai/example_summary"
@@ -81,6 +84,7 @@ module Henitai
81
84
  autoload :SyntaxValidator, "henitai/syntax_validator"
82
85
  autoload :SamplingStrategy, "henitai/sampling_strategy"
83
86
  autoload :TestPrioritizer, "henitai/test_prioritizer"
87
+ autoload :KillHistory, "henitai/kill_history"
84
88
  autoload :ExcludedTestFilter, "henitai/excluded_test_filter"
85
89
  autoload :SuiteBootClock, "henitai/suite_boot_clock"
86
90
  autoload :TimeoutCalibrator, "henitai/timeout_calibrator"