henitai 0.5.3 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +332 -1
- data/README.md +123 -19
- data/assets/schema/henitai.schema.json +26 -0
- data/lib/henitai/arid_node_filter.rb +4 -19
- data/lib/henitai/bootstrap_error_message.rb +38 -0
- data/lib/henitai/canonical_report_merger.rb +23 -2
- data/lib/henitai/checkpoint_reporter.rb +5 -0
- data/lib/henitai/cli/operator_command.rb +10 -3
- data/lib/henitai/cli/run_command.rb +25 -7
- data/lib/henitai/cli/run_options.rb +1 -1
- data/lib/henitai/cli.rb +6 -2
- data/lib/henitai/composite_progress_reporter.rb +15 -2
- data/lib/henitai/configuration.rb +9 -1
- data/lib/henitai/configuration_validator/rules.rb +9 -0
- data/lib/henitai/configuration_validator/scalars.rb +22 -0
- data/lib/henitai/configuration_validator.rb +4 -2
- data/lib/henitai/constant_path.rb +48 -0
- data/lib/henitai/control_gate.rb +78 -0
- data/lib/henitai/control_run.rb +67 -0
- data/lib/henitai/coverage_bootstrapper.rb +46 -11
- data/lib/henitai/coverage_formatter.rb +26 -3
- data/lib/henitai/coverage_report_reader.rb +21 -0
- data/lib/henitai/equivalence_detector/operand_predicates.rb +16 -0
- data/lib/henitai/equivalence_detector.rb +46 -38
- data/lib/henitai/example_summary.rb +24 -0
- data/lib/henitai/execution_engine/env_scope.rb +3 -3
- data/lib/henitai/execution_engine/fork_server_scope.rb +57 -0
- data/lib/henitai/execution_engine.rb +109 -119
- data/lib/henitai/execution_provenance.rb +67 -0
- data/lib/henitai/fidelity_check.rb +173 -0
- data/lib/henitai/flaky_detection_baseline.rb +63 -0
- data/lib/henitai/flaky_retry_decision.rb +23 -0
- data/lib/henitai/flaky_test_registry.rb +63 -0
- data/lib/henitai/fork_server/client.rb +222 -0
- data/lib/henitai/fork_server/group_killer.rb +48 -0
- data/lib/henitai/fork_server/launcher.rb +38 -0
- data/lib/henitai/fork_server/mutant_runner.rb +110 -0
- data/lib/henitai/fork_server/protocol.rb +73 -0
- data/lib/henitai/fork_server/reaper.rb +24 -0
- data/lib/henitai/fork_server/runtime.rb +109 -0
- data/lib/henitai/fork_server/server.rb +108 -0
- data/lib/henitai/fork_server/server_process.rb +73 -0
- data/lib/henitai/fork_server/status.rb +52 -0
- data/lib/henitai/fork_server.rb +42 -0
- data/lib/henitai/generated_artifacts.rb +3 -0
- data/lib/henitai/git_diff_analyzer.rb +28 -11
- data/lib/henitai/history_checkpointer.rb +72 -0
- data/lib/henitai/incremental_filter.rb +20 -10
- data/lib/henitai/integration/base.rb +78 -19
- data/lib/henitai/integration/capped_log_sink.rb +34 -0
- data/lib/henitai/integration/child_bootstrap.rb +7 -0
- data/lib/henitai/integration/child_report_store.rb +65 -0
- data/lib/henitai/integration/minitest.rb +8 -13
- data/lib/henitai/integration/minitest_autorun.rb +20 -0
- data/lib/henitai/integration/minitest_fail_fast.rb +43 -0
- data/lib/henitai/integration/minitest_outcome_reporter.rb +44 -0
- data/lib/henitai/integration/minitest_preload.rb +30 -0
- data/lib/henitai/integration/minitest_runnable_filter.rb +61 -0
- data/lib/henitai/integration/minitest_test_runner.rb +47 -18
- data/lib/henitai/integration/mutant_run_support.rb +80 -17
- data/lib/henitai/integration/rspec_child_runner.rb +49 -9
- data/lib/henitai/integration/rspec_file_order.rb +37 -0
- data/lib/henitai/integration/rspec_preload.rb +35 -0
- data/lib/henitai/integration/rspec_process_runner.rb +4 -20
- data/lib/henitai/integration/scenario_log_support.rb +31 -18
- data/lib/henitai/integration.rb +18 -6
- data/lib/henitai/kill_history/store.rb +67 -0
- data/lib/henitai/kill_history.rb +85 -0
- data/lib/henitai/minitest_coverage_reporter.rb +22 -6
- data/lib/henitai/minitest_result_file.rb +62 -0
- data/lib/henitai/mutant/activation.rb +32 -0
- data/lib/henitai/mutant/activator.rb +75 -55
- data/lib/henitai/mutant/def_injection.rb +136 -0
- data/lib/henitai/mutant/lexical_scope_check.rb +120 -0
- data/lib/henitai/mutant/lexical_target.rb +105 -0
- data/lib/henitai/mutant/replacement.rb +52 -0
- data/lib/henitai/mutant.rb +32 -8
- data/lib/henitai/mutant_generator.rb +62 -18
- data/lib/henitai/mutant_history_store/database.rb +61 -0
- data/lib/henitai/mutant_history_store/sql.rb +9 -3
- data/lib/henitai/mutant_history_store/subject_scans.rb +101 -0
- data/lib/henitai/mutant_history_store/verdict_cache.rb +48 -18
- data/lib/henitai/mutant_history_store.rb +77 -51
- data/lib/henitai/mutant_identity.rb +5 -1
- data/lib/henitai/mutant_verdict.rb +71 -0
- data/lib/henitai/operator.rb +6 -2
- data/lib/henitai/operators/array_declaration.rb +4 -0
- data/lib/henitai/operators/assignment_expression.rb +2 -0
- data/lib/henitai/operators/conditional_expression.rb +21 -1
- data/lib/henitai/operators/equality_identity_operator.rb +2 -2
- data/lib/henitai/operators/hash_key_type.rb +11 -1
- data/lib/henitai/operators/hash_literal.rb +37 -9
- data/lib/henitai/operators/method_expression.rb +14 -3
- data/lib/henitai/operators/regex_metacharacters.rb +89 -0
- data/lib/henitai/operators/regex_mutator.rb +23 -28
- data/lib/henitai/operators/return_value.rb +1 -1
- data/lib/henitai/operators/string_literal.rb +17 -4
- data/lib/henitai/operators.rb +1 -0
- data/lib/henitai/per_test_coverage.rb +11 -7
- data/lib/henitai/per_test_coverage_collector.rb +30 -31
- data/lib/henitai/per_test_coverage_delta.rb +60 -0
- data/lib/henitai/per_test_coverage_selector.rb +26 -13
- data/lib/henitai/process_wakeup.rb +8 -3
- data/lib/henitai/process_worker_runner.rb +41 -7
- data/lib/henitai/reporter.rb +15 -8
- data/lib/henitai/result.rb +32 -16
- data/lib/henitai/reuse_context.rb +52 -0
- data/lib/henitai/rspec_coverage_formatter.rb +4 -0
- data/lib/henitai/rspec_outcomes.rb +74 -0
- data/lib/henitai/runner.rb +112 -21
- data/lib/henitai/runner_dependencies.rb +44 -3
- data/lib/henitai/sampling_strategy.rb +36 -6
- data/lib/henitai/scenario_execution_result.rb +51 -5
- data/lib/henitai/signal_deferral.rb +25 -0
- data/lib/henitai/signature_line.rb +21 -0
- data/lib/henitai/slot_scheduler/control_slots.rb +58 -0
- data/lib/henitai/slot_scheduler/draining.rb +35 -6
- data/lib/henitai/slot_scheduler/process_control.rb +33 -0
- data/lib/henitai/slot_scheduler/retry_policy.rb +20 -6
- data/lib/henitai/slot_scheduler.rb +64 -21
- data/lib/henitai/source_file_selection.rb +1 -1
- data/lib/henitai/source_parser.rb +29 -9
- data/lib/henitai/static_filter.rb +45 -14
- data/lib/henitai/stillborn_filter.rb +70 -2
- data/lib/henitai/subject.rb +8 -3
- data/lib/henitai/subject_resolver.rb +65 -31
- data/lib/henitai/suite_boot_clock.rb +48 -0
- data/lib/henitai/survivor_activation_cache.rb +18 -11
- data/lib/henitai/survivor_rerun_strategy.rb +47 -43
- data/lib/henitai/test_file_outcomes.rb +93 -0
- data/lib/henitai/test_prioritizer.rb +10 -2
- data/lib/henitai/timeout_calibrator.rb +31 -9
- data/lib/henitai/timeout_ceiling.rb +37 -0
- data/lib/henitai/verdict_fingerprint.rb +29 -30
- data/lib/henitai/version.rb +1 -1
- data/lib/henitai.rb +21 -1
- data/sig/configuration_validator.rbs +1 -0
- data/sig/henitai.rbs +254 -56
- metadata +63 -5
- data/lib/henitai/survivor_test_filter.rb +0 -72
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "source_parser"
|
|
4
4
|
require_relative "subject"
|
|
5
|
+
require_relative "constant_path"
|
|
5
6
|
|
|
6
7
|
module Henitai
|
|
7
8
|
# Resolves AST subjects from Ruby source files.
|
|
@@ -26,6 +27,7 @@ module Henitai
|
|
|
26
27
|
private
|
|
27
28
|
|
|
28
29
|
def resolve_from_file(path)
|
|
30
|
+
@scope = []
|
|
29
31
|
subjects = []
|
|
30
32
|
walk(
|
|
31
33
|
SourceParser.parse_file(path),
|
|
@@ -38,6 +40,7 @@ module Henitai
|
|
|
38
40
|
|
|
39
41
|
def walk(node, namespace:, singleton_context:, subjects:)
|
|
40
42
|
return unless node.respond_to?(:type)
|
|
43
|
+
return walk_constructor_body(node, namespace, subjects) if constructor_assignment?(node)
|
|
41
44
|
return if anonymous_class_block?(node)
|
|
42
45
|
|
|
43
46
|
namespace, singleton_context = update_context(
|
|
@@ -46,8 +49,60 @@ module Henitai
|
|
|
46
49
|
singleton_context
|
|
47
50
|
)
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
within_scope(node) do
|
|
53
|
+
collect_subject(node, namespace, singleton_context, subjects)
|
|
54
|
+
traverse_children(node, namespace, singleton_context, subjects)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# +Point = Struct.new(:x) do ... end+: the block is evaluated with
|
|
59
|
+
# class_eval on the new class, so its methods belong to +Point+ while
|
|
60
|
+
# constant lookup stays in the enclosing scope. +Point.class_eval do+
|
|
61
|
+
# reproduces exactly that when the method is re-evaluated.
|
|
62
|
+
def walk_constructor_body(node, namespace, subjects)
|
|
63
|
+
@scope.push("#{assigned_constant_source(node)}.class_eval do")
|
|
64
|
+
walk(node.children[2].children[2], namespace: ConstantPath.qualify(namespace, ConstantPath.of(node)),
|
|
65
|
+
singleton_context: false, subjects:)
|
|
66
|
+
ensure
|
|
67
|
+
@scope.pop
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def constructor_assignment?(node)
|
|
71
|
+
node.type == :casgn && anonymous_class_block?(node.children[2])
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def assigned_constant_source(node)
|
|
75
|
+
node.location.expression.begin.join(node.location.name).source
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Tracks the openers of the modules and classes around the walk position,
|
|
79
|
+
# so a method can later be re-evaluated in its original lexical scope.
|
|
80
|
+
def within_scope(node)
|
|
81
|
+
opener = scope_opener(node)
|
|
82
|
+
@scope.push(opener) unless opener == :none
|
|
83
|
+
yield
|
|
84
|
+
ensure
|
|
85
|
+
@scope.pop unless opener == :none
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def scope_opener(node)
|
|
89
|
+
case node.type
|
|
90
|
+
when :class, :module then "#{node.type} #{node.children.first.location.expression.source}"
|
|
91
|
+
when :sclass then singleton_opener(node.children.first)
|
|
92
|
+
else :none
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def singleton_opener(receiver)
|
|
97
|
+
case receiver.type
|
|
98
|
+
when :self then "class << self"
|
|
99
|
+
when :const then "class << #{receiver.location.expression.source}"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# nil when some enclosing scope cannot be reopened by name (class << obj).
|
|
104
|
+
def lexical_scope
|
|
105
|
+
@scope.include?(nil) ? nil : @scope.dup
|
|
51
106
|
end
|
|
52
107
|
|
|
53
108
|
def collect_subject(node, namespace, singleton_context, subjects)
|
|
@@ -70,7 +125,7 @@ module Henitai
|
|
|
70
125
|
|
|
71
126
|
receiver = call_node.children.first
|
|
72
127
|
method_name = call_node.children[1]
|
|
73
|
-
receiver_name =
|
|
128
|
+
receiver_name = ConstantPath.of(receiver)&.delete_prefix("::")
|
|
74
129
|
|
|
75
130
|
anonymous_constructor_call?(receiver_name, method_name)
|
|
76
131
|
end
|
|
@@ -86,10 +141,10 @@ module Henitai
|
|
|
86
141
|
def update_context(node, namespace, singleton_context)
|
|
87
142
|
case node.type
|
|
88
143
|
when :class, :module
|
|
89
|
-
[
|
|
144
|
+
[ConstantPath.qualify(namespace, ConstantPath.of(node.children.first)),
|
|
90
145
|
singleton_context]
|
|
91
146
|
when :sclass
|
|
92
|
-
[namespace, true]
|
|
147
|
+
[ConstantPath.owner(node.children.first, namespace), true]
|
|
93
148
|
else
|
|
94
149
|
[namespace, singleton_context]
|
|
95
150
|
end
|
|
@@ -102,7 +157,7 @@ module Henitai
|
|
|
102
157
|
when :def
|
|
103
158
|
instance_subject(node, namespace, singleton_context)
|
|
104
159
|
when :defs
|
|
105
|
-
class_subject(node, namespace)
|
|
160
|
+
class_subject(node, ConstantPath.owner(node.children.first, namespace))
|
|
106
161
|
end
|
|
107
162
|
end
|
|
108
163
|
|
|
@@ -114,7 +169,8 @@ module Henitai
|
|
|
114
169
|
method_name: method_name(node.children.first),
|
|
115
170
|
method_type: singleton_context ? :class : :instance,
|
|
116
171
|
source_location: source_location_for(node),
|
|
117
|
-
ast_node: node
|
|
172
|
+
ast_node: node,
|
|
173
|
+
lexical_scope:
|
|
118
174
|
)
|
|
119
175
|
end
|
|
120
176
|
|
|
@@ -126,7 +182,8 @@ module Henitai
|
|
|
126
182
|
method_name: method_name(node.children[1]),
|
|
127
183
|
method_type: :class,
|
|
128
184
|
source_location: source_location_for(node),
|
|
129
|
-
ast_node: node
|
|
185
|
+
ast_node: node,
|
|
186
|
+
lexical_scope:
|
|
130
187
|
)
|
|
131
188
|
end
|
|
132
189
|
|
|
@@ -147,29 +204,6 @@ module Henitai
|
|
|
147
204
|
)
|
|
148
205
|
end
|
|
149
206
|
|
|
150
|
-
def qualify_namespace(namespace, name)
|
|
151
|
-
return name if namespace.nil? || namespace.empty?
|
|
152
|
-
return namespace if name.nil? || name.empty?
|
|
153
|
-
|
|
154
|
-
"#{namespace}::#{name}"
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def constant_name(node)
|
|
158
|
-
return unless node.respond_to?(:type)
|
|
159
|
-
|
|
160
|
-
case node.type
|
|
161
|
-
when :const
|
|
162
|
-
parent_name = constant_name(node.children.first)
|
|
163
|
-
current_name = symbol_name(node.children.last)
|
|
164
|
-
|
|
165
|
-
return current_name if parent_name.nil? || parent_name.empty?
|
|
166
|
-
|
|
167
|
-
"#{parent_name}::#{current_name}"
|
|
168
|
-
when :cbase
|
|
169
|
-
""
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
|
|
173
207
|
def method_name(value)
|
|
174
208
|
symbol_name(value)
|
|
175
209
|
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Henitai
|
|
4
|
+
# Measures how long a baseline suite process spent before its first test
|
|
5
|
+
# started. The parent passes its spawn wall-clock time through
|
|
6
|
+
# STARTED_AT_ENV; the boot time covers loading helpers and spec files and
|
|
7
|
+
# running before(:suite).
|
|
8
|
+
class SuiteBootClock
|
|
9
|
+
STARTED_AT_ENV = "HENITAI_SUITE_STARTED_AT"
|
|
10
|
+
|
|
11
|
+
# @param started_at [Float, nil] epoch seconds of the suite spawn
|
|
12
|
+
# @param clock [#call] returns the current epoch seconds
|
|
13
|
+
def initialize(started_at:, clock: -> { Time.now.to_f })
|
|
14
|
+
@started_at = started_at
|
|
15
|
+
@clock = clock
|
|
16
|
+
@boot_seconds = nil
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @param env [Hash] environment of the suite process
|
|
20
|
+
# @return [SuiteBootClock]
|
|
21
|
+
def self.from_env(env, clock: -> { Time.now.to_f })
|
|
22
|
+
new(started_at: parse_timestamp(env[STARTED_AT_ENV]), clock:)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.parse_timestamp(value)
|
|
26
|
+
Float(value)
|
|
27
|
+
rescue ArgumentError, TypeError
|
|
28
|
+
nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Records boot time at the first test start only; later calls are ignored.
|
|
32
|
+
def mark_first_test_started
|
|
33
|
+
return if @boot_seconds || @started_at.nil?
|
|
34
|
+
|
|
35
|
+
@boot_seconds = [@clock.call - @started_at, 0.0].max
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @return [Float] boot seconds, 0.0 when unknown
|
|
39
|
+
def boot_seconds
|
|
40
|
+
@boot_seconds || 0.0
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @return [Boolean] true once a boot time has been recorded
|
|
44
|
+
def measured?
|
|
45
|
+
!@boot_seconds.nil?
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -4,7 +4,7 @@ require "json"
|
|
|
4
4
|
require "fileutils"
|
|
5
5
|
|
|
6
6
|
module Henitai
|
|
7
|
-
# Stores and retrieves pre-computed
|
|
7
|
+
# Stores and retrieves pre-computed activations (see Mutant::Activation) for
|
|
8
8
|
# survived mutants, enabling survivor reruns to skip the full mutant-generation
|
|
9
9
|
# pipeline.
|
|
10
10
|
#
|
|
@@ -14,7 +14,7 @@ module Henitai
|
|
|
14
14
|
# objects directly and execute them without re-parsing source files.
|
|
15
15
|
#
|
|
16
16
|
# A recipe entry encodes everything needed to activate and re-report a mutant:
|
|
17
|
-
# the
|
|
17
|
+
# the activation (source, mode, file, line), subject coordinates, operator, description,
|
|
18
18
|
# location, and the coveredBy test list.
|
|
19
19
|
class SurvivorActivationCache
|
|
20
20
|
FILENAME = "activation-recipes.json"
|
|
@@ -26,10 +26,10 @@ module Henitai
|
|
|
26
26
|
# @return [Hash<String, Hash>] stableId → recipe
|
|
27
27
|
def self.compute(survived_mutants)
|
|
28
28
|
survived_mutants.each_with_object({}) do |mutant, cache|
|
|
29
|
-
|
|
30
|
-
next unless
|
|
29
|
+
activation = Mutant::Activator.activation_for(mutant)
|
|
30
|
+
next unless activation
|
|
31
31
|
|
|
32
|
-
cache[mutant.stable_id] = build_recipe(mutant,
|
|
32
|
+
cache[mutant.stable_id] = build_recipe(mutant, activation)
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
|
|
@@ -53,13 +53,11 @@ module Henitai
|
|
|
53
53
|
class << self
|
|
54
54
|
private
|
|
55
55
|
|
|
56
|
-
def build_recipe(mutant,
|
|
56
|
+
def build_recipe(mutant, activation)
|
|
57
57
|
{
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
"methodType" => mutant.subject.method_type.to_s,
|
|
62
|
-
"sourceFile" => mutant.subject.source_file,
|
|
58
|
+
"activation" => activation.to_h,
|
|
59
|
+
"replacement" => mutant.mutated_source,
|
|
60
|
+
**subject_fields(mutant.subject),
|
|
63
61
|
"operator" => mutant.operator,
|
|
64
62
|
"description" => mutant.description,
|
|
65
63
|
"location" => serialize_location(mutant.location),
|
|
@@ -67,6 +65,15 @@ module Henitai
|
|
|
67
65
|
}
|
|
68
66
|
end
|
|
69
67
|
|
|
68
|
+
def subject_fields(subject)
|
|
69
|
+
{
|
|
70
|
+
"namespace" => subject.namespace,
|
|
71
|
+
"methodName" => subject.method_name,
|
|
72
|
+
"methodType" => subject.method_type.to_s,
|
|
73
|
+
"sourceFile" => subject.source_file
|
|
74
|
+
}
|
|
75
|
+
end
|
|
76
|
+
|
|
70
77
|
def serialize_location(location)
|
|
71
78
|
{
|
|
72
79
|
"file" => location[:file],
|
|
@@ -12,8 +12,15 @@ module Henitai
|
|
|
12
12
|
# fast path, bypassing source parsing and mutant generation), or
|
|
13
13
|
# * filters a freshly generated mutant list down to the prior survivors.
|
|
14
14
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
15
|
+
# Survivors are never trusted on the strength of the prior report alone: a
|
|
16
|
+
# selected survivor is skipped only when the {IncrementalFilter} content
|
|
17
|
+
# fingerprint rules prove its stored verdict still valid (new or edited
|
|
18
|
+
# tests, helpers and configuration all force a re-run). Recipe stubs have no
|
|
19
|
+
# source range to fingerprint, so they always re-run.
|
|
20
|
+
#
|
|
21
|
+
# In both cases it records {#survivor_stats} (matched/unmatched counts, the
|
|
22
|
+
# reused-verdict count and the drift warning) for the Runner to attach to
|
|
23
|
+
# its Result.
|
|
17
24
|
class SurvivorRerunStrategy
|
|
18
25
|
attr_reader :survivor_stats
|
|
19
26
|
|
|
@@ -32,26 +39,19 @@ module Henitai
|
|
|
32
39
|
# bypassing source parsing and mutant generation entirely.
|
|
33
40
|
# Returns the mutant array on success, or nil if recipes are unavailable.
|
|
34
41
|
def try_recipe_run
|
|
35
|
-
dirty_worktree_files = dirty_worktree_changed_files
|
|
36
42
|
loaded = load_survivor_report
|
|
37
|
-
return nil unless recipe_fast_path_safe?(loaded
|
|
43
|
+
return nil unless recipe_fast_path_safe?(loaded)
|
|
38
44
|
|
|
39
|
-
run_from_recipes(loaded
|
|
45
|
+
run_from_recipes(loaded)
|
|
40
46
|
end
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
selector = SurvivorSelector.new(survivor_ids:
|
|
48
|
+
# @param reuse_filter [IncrementalFilter, nil] marks survivors whose
|
|
49
|
+
# stored verdict is provably still valid as cache hits.
|
|
50
|
+
def apply_selection(mutants, reuse_filter: nil)
|
|
51
|
+
selector = SurvivorSelector.new(survivor_ids: load_survivor_report.survivor_ids)
|
|
46
52
|
selected = selector.select(mutants)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
selected,
|
|
50
|
-
test_filter(
|
|
51
|
-
loaded,
|
|
52
|
-
dirty_source_files: dirty_source_files?(dirty_worktree_files, git_sha: loaded.git_sha)
|
|
53
|
-
).apply(selected)
|
|
54
|
-
)
|
|
53
|
+
reuse_filter&.apply(selected)
|
|
54
|
+
finalize_selection(selector, selected)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
private
|
|
@@ -60,20 +60,16 @@ module Henitai
|
|
|
60
60
|
SurvivorLoader.new(@survivors_from, include_paths: Array(@config.includes)).load
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
def run_from_recipes(loaded
|
|
63
|
+
def run_from_recipes(loaded)
|
|
64
64
|
recipes = load_activation_recipes(loaded.survivor_ids)
|
|
65
65
|
return nil if recipes.nil?
|
|
66
66
|
|
|
67
67
|
selector, stubs = recipe_selector_and_stubs(loaded.survivor_ids, recipes)
|
|
68
|
-
|
|
69
|
-
loaded,
|
|
70
|
-
dirty_source_files: dirty_source_files?(dirty_worktree_files, git_sha: loaded.git_sha)
|
|
71
|
-
).apply(stubs)
|
|
72
|
-
finalize_survivor_split(selector, stubs, split)
|
|
68
|
+
finalize_selection(selector, stubs)
|
|
73
69
|
end
|
|
74
70
|
|
|
75
|
-
def recipe_fast_path_safe?(loaded
|
|
76
|
-
!dirty_source_files?(
|
|
71
|
+
def recipe_fast_path_safe?(loaded)
|
|
72
|
+
!dirty_source_files?(dirty_worktree_changed_files, git_sha: loaded.git_sha)
|
|
77
73
|
end
|
|
78
74
|
|
|
79
75
|
# Builds stub Mutants from recipes and a SurvivorSelector primed with the
|
|
@@ -92,11 +88,29 @@ module Henitai
|
|
|
92
88
|
path = File.join(File.dirname(@survivors_from), SurvivorActivationCache::FILENAME)
|
|
93
89
|
recipes = SurvivorActivationCache.load(path)
|
|
94
90
|
return nil if recipes.nil?
|
|
95
|
-
return nil unless survivor_ids.all? { |id|
|
|
91
|
+
return nil unless survivor_ids.all? { |id| replayable_recipe?(recipes[id]) }
|
|
96
92
|
|
|
97
93
|
recipes
|
|
98
94
|
end
|
|
99
95
|
|
|
96
|
+
# Recipes without an "activation" entry predate ADR-13: their
|
|
97
|
+
# define_method sources lose lexical scope, so they are not replayed.
|
|
98
|
+
# A :toplevel activation needs the persisted scope and owner, because the
|
|
99
|
+
# stub subject has no AST to resolve them from.
|
|
100
|
+
def replayable_recipe?(recipe)
|
|
101
|
+
return false unless recipe.is_a?(Hash) && recipe["activation"].is_a?(Hash)
|
|
102
|
+
|
|
103
|
+
activation = recipe["activation"]
|
|
104
|
+
activation["mode"] != "toplevel" || toplevel_fields_valid?(activation)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def toplevel_fields_valid?(activation)
|
|
108
|
+
scope = activation["lexicalScope"]
|
|
109
|
+
scope.is_a?(Array) && scope.all?(String) &&
|
|
110
|
+
activation["owner"].is_a?(String) &&
|
|
111
|
+
[true, false].include?(activation["singleton"])
|
|
112
|
+
end
|
|
113
|
+
|
|
100
114
|
def build_stub_mutant(stable_id, recipe)
|
|
101
115
|
mutant = Mutant.new(
|
|
102
116
|
subject: stub_subject_from_recipe(recipe),
|
|
@@ -105,7 +119,8 @@ module Henitai
|
|
|
105
119
|
description: recipe.fetch("description"),
|
|
106
120
|
location: recipe_location(recipe["location"]),
|
|
107
121
|
precomputed_stable_id: stable_id,
|
|
108
|
-
|
|
122
|
+
precomputed_activation: Mutant::Activation.from_h(recipe.fetch("activation")),
|
|
123
|
+
precomputed_replacement: recipe["replacement"]
|
|
109
124
|
)
|
|
110
125
|
mutant.covered_by = recipe["coveredBy"]
|
|
111
126
|
mutant
|
|
@@ -132,21 +147,10 @@ module Henitai
|
|
|
132
147
|
}.compact
|
|
133
148
|
end
|
|
134
149
|
|
|
135
|
-
def
|
|
136
|
-
split[:stable].each { |m| m.status = :survived }
|
|
150
|
+
def finalize_selection(selector, selected)
|
|
137
151
|
warn_survivor_drift(selector) if selector.drift_warning?
|
|
138
|
-
@survivor_stats = build_survivor_stats(selector, selected
|
|
139
|
-
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def test_filter(loaded, dirty_source_files:)
|
|
143
|
-
SurvivorTestFilter.new(
|
|
144
|
-
coverage_map: loaded.coverage_map,
|
|
145
|
-
git_sha: loaded.git_sha,
|
|
146
|
-
dirty_source_files:,
|
|
147
|
-
worktree_changed_files: Array(dirty_worktree_changed_files),
|
|
148
|
-
diff_analyzer: @git_diff_analyzer
|
|
149
|
-
)
|
|
152
|
+
@survivor_stats = build_survivor_stats(selector, selected)
|
|
153
|
+
selected
|
|
150
154
|
end
|
|
151
155
|
|
|
152
156
|
def dirty_worktree_changed_files
|
|
@@ -170,12 +174,12 @@ module Henitai
|
|
|
170
174
|
"could not be matched; the source may have drifted - consider a full run"
|
|
171
175
|
end
|
|
172
176
|
|
|
173
|
-
def build_survivor_stats(selector, selected
|
|
177
|
+
def build_survivor_stats(selector, selected)
|
|
174
178
|
{
|
|
175
179
|
matched: selected.size,
|
|
176
180
|
unmatched_count: selector.unmatched_ids.size,
|
|
177
181
|
unmatched_ids: selector.unmatched_ids,
|
|
178
|
-
skipped_count:
|
|
182
|
+
skipped_count: selected.count(&:from_cache?),
|
|
179
183
|
drift_warning: selector.drift_warning?
|
|
180
184
|
}
|
|
181
185
|
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
require_relative "per_test_coverage_collector"
|
|
7
|
+
|
|
8
|
+
module Henitai
|
|
9
|
+
# Records per-test-file pass/fail outcomes from a test run.
|
|
10
|
+
#
|
|
11
|
+
# A failure that happens outside any example (a spec file that fails to
|
|
12
|
+
# load, a `before(:suite)` hook, a Minitest result without a usable file)
|
|
13
|
+
# cannot be pinned to a test file. It is recorded separately as an
|
|
14
|
+
# unattributed failure so consumers never mistake the run for a clean one.
|
|
15
|
+
class TestFileOutcomes
|
|
16
|
+
REPORT_FILE_NAME = "henitai_suite_outcomes.json"
|
|
17
|
+
|
|
18
|
+
def self.report_path(reports_dir)
|
|
19
|
+
File.join(reports_dir, REPORT_FILE_NAME)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.default_report_path
|
|
23
|
+
report_path(ENV.fetch(PerTestCoverageCollector::REPORT_DIR_ENV, "coverage"))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.load(path)
|
|
27
|
+
return new unless File.exist?(path)
|
|
28
|
+
|
|
29
|
+
data = JSON.parse(File.read(path))
|
|
30
|
+
new.tap do |outcomes|
|
|
31
|
+
outcomes.record_unattributed_failure if data["unattributed_failures"]
|
|
32
|
+
data.fetch("outcomes", {}).each do |file, outcome|
|
|
33
|
+
outcomes.record(file, failed: outcome == "failed")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
rescue JSON::ParserError
|
|
37
|
+
new
|
|
38
|
+
end
|
|
39
|
+
|
|
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)
|
|
43
|
+
@failed = {}
|
|
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)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def record(file, failed:)
|
|
60
|
+
path = File.expand_path(file)
|
|
61
|
+
@failed[path] = (@failed[path] || false) || failed
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def record_unattributed_failure
|
|
65
|
+
@unattributed_failures = true
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def unattributed_failures?
|
|
69
|
+
@unattributed_failures
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def failed_files
|
|
73
|
+
@failed.select { |_file, failed| failed }.keys.sort
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def outcomes
|
|
77
|
+
@failed.transform_values { |failed| failed ? "failed" : "passed" }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def write(path)
|
|
81
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
82
|
+
File.write(path, JSON.pretty_generate(payload))
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
private
|
|
86
|
+
|
|
87
|
+
def payload
|
|
88
|
+
data = { "outcomes" => outcomes }
|
|
89
|
+
data["unattributed_failures"] = true if @unattributed_failures
|
|
90
|
+
data
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -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,
|
|
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|
|
|
@@ -3,36 +3,58 @@
|
|
|
3
3
|
module Henitai
|
|
4
4
|
# Derives a per-mutant timeout from measured per-test-file durations.
|
|
5
5
|
#
|
|
6
|
-
# The
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
6
|
+
# The measured baseline is `sum(durations of the selected test files) +
|
|
7
|
+
# boot seconds`, where boot covers loading helpers and spec files and
|
|
8
|
+
# running before(:suite). The calibrated value is `multiplier × baseline`,
|
|
9
|
+
# clamped to a floor so a near-instant baseline doesn't flag normal jitter
|
|
10
|
+
# as a timeout. Returns nil — caller falls back to the static default —
|
|
11
|
+
# when any selected test lacks timing data, so a partially measured run is
|
|
12
|
+
# treated as uncalibratable rather than under-estimated.
|
|
11
13
|
class TimeoutCalibrator
|
|
12
14
|
FLOOR_SECONDS = 2.0
|
|
13
15
|
|
|
14
16
|
# @param timing_source [#call] returns a Hash of test file path to
|
|
15
17
|
# wall-clock seconds; resolved lazily on first use.
|
|
16
18
|
# @param multiplier [Numeric]
|
|
17
|
-
|
|
19
|
+
# @param boot_seconds [#call] returns the measured suite boot time.
|
|
20
|
+
# @param include_boot [Boolean] false when boot is paid once elsewhere
|
|
21
|
+
# (for example by a preloaded fork server) and must not be repeated.
|
|
22
|
+
def initialize(timing_source:, multiplier:, boot_seconds: -> { 0.0 }, include_boot: true)
|
|
18
23
|
@timing_source = timing_source
|
|
19
24
|
@multiplier = multiplier
|
|
25
|
+
@boot_seconds = boot_seconds
|
|
26
|
+
@include_boot = include_boot
|
|
20
27
|
end
|
|
21
28
|
|
|
22
29
|
# @param test_files [Array<String>]
|
|
23
30
|
# @return [Float, nil]
|
|
24
31
|
def timeout_for(test_files)
|
|
32
|
+
baseline = baseline_for(test_files)
|
|
33
|
+
return nil if baseline.nil?
|
|
34
|
+
|
|
35
|
+
[@multiplier * baseline, FLOOR_SECONDS].max
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @param test_files [Array<String>]
|
|
39
|
+
# @return [Float, nil] measured baseline seconds, nil without timing data
|
|
40
|
+
def baseline_for(test_files)
|
|
25
41
|
files = Array(test_files)
|
|
26
42
|
return nil if files.empty? || durations.empty?
|
|
27
43
|
|
|
28
|
-
|
|
29
|
-
return nil if
|
|
44
|
+
measured = files.map { |file| durations[normalize(file)] }
|
|
45
|
+
return nil if measured.any?(&:nil?)
|
|
30
46
|
|
|
31
|
-
|
|
47
|
+
measured.sum + boot_component
|
|
32
48
|
end
|
|
33
49
|
|
|
34
50
|
private
|
|
35
51
|
|
|
52
|
+
def boot_component
|
|
53
|
+
return 0.0 unless @include_boot
|
|
54
|
+
|
|
55
|
+
@boot_component ||= @boot_seconds.call.to_f
|
|
56
|
+
end
|
|
57
|
+
|
|
36
58
|
def durations
|
|
37
59
|
@durations ||= (@timing_source.call || {}).transform_keys { |key| normalize(key) }
|
|
38
60
|
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Henitai
|
|
4
|
+
# Applies the max_timeout ceiling to a calibrated timeout. The ceiling stops a
|
|
5
|
+
# runaway mutant from running for minutes, but it must never push the timeout
|
|
6
|
+
# below the measured test baseline, or every mutant would be reported as a
|
|
7
|
+
# timeout instead of being tested.
|
|
8
|
+
class TimeoutCeiling
|
|
9
|
+
def initialize(ceiling:, warner:)
|
|
10
|
+
@ceiling = ceiling
|
|
11
|
+
@warner = warner
|
|
12
|
+
@warned = false
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def cap(calibrated, baseline)
|
|
16
|
+
return calibrated if calibrated <= @ceiling
|
|
17
|
+
|
|
18
|
+
warn_baseline_exceeds_ceiling(baseline) if baseline > @ceiling
|
|
19
|
+
[@ceiling, baseline + TimeoutCalibrator::FLOOR_SECONDS].max
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def warn_baseline_exceeds_ceiling(baseline)
|
|
25
|
+
return if @warned
|
|
26
|
+
|
|
27
|
+
@warned = true
|
|
28
|
+
@warner.call(
|
|
29
|
+
format(
|
|
30
|
+
"henitai: measured test baseline of %<baseline>.1fs exceeds max_timeout (%<ceiling>.1fs); " \
|
|
31
|
+
"using %<timeout>.1fs instead",
|
|
32
|
+
baseline:, ceiling: @ceiling, timeout: baseline + TimeoutCalibrator::FLOOR_SECONDS
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|