evilution 1.5.1 → 1.6.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 (227) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +30 -0
  3. data/CHANGELOG.md +49 -0
  4. data/README.md +285 -45
  5. data/docs/architecture.md +110 -12
  6. data/docs/ast_pattern_syntax.md +35 -7
  7. data/docs/combined_runs_spike.md +407 -0
  8. data/docs/integrations.md +1 -1
  9. data/docs/isolation.md +63 -2
  10. data/docs/migration-from-mutant.md +16 -11
  11. data/docs/mutant_schemata_spike.md +387 -0
  12. data/docs/operator_yield_study.md +576 -0
  13. data/docs/probe_first_spike.md +264 -0
  14. data/lib/evilution/ast/ancestor_lookup.rb +36 -0
  15. data/lib/evilution/ast/callback_declaration.rb +36 -3
  16. data/lib/evilution/ast/class_body.rb +62 -16
  17. data/lib/evilution/ast/def_region.rb +130 -0
  18. data/lib/evilution/ast/local_declaration.rb +37 -0
  19. data/lib/evilution/ast/parent_index.rb +50 -0
  20. data/lib/evilution/ast/parse_cache.rb +27 -0
  21. data/lib/evilution/ast/parser.rb +8 -3
  22. data/lib/evilution/ast/pattern/filter.rb +53 -12
  23. data/lib/evilution/ast/skip_filter.rb +83 -0
  24. data/lib/evilution/ast/skip_sites/debug_output.rb +67 -0
  25. data/lib/evilution/ast/skip_sites/error_messages.rb +74 -0
  26. data/lib/evilution/ast/skip_sites/logging.rb +93 -0
  27. data/lib/evilution/ast/skip_sites/message.rb +44 -0
  28. data/lib/evilution/ast/skip_sites/nodes.rb +105 -0
  29. data/lib/evilution/ast/skip_sites/presets.rb +31 -0
  30. data/lib/evilution/ast/skip_sites/purity.rb +69 -0
  31. data/lib/evilution/ast/skip_sites/requires.rb +40 -0
  32. data/lib/evilution/ast/skip_sites.rb +9 -0
  33. data/lib/evilution/ast/source_surgeon.rb +20 -2
  34. data/lib/evilution/ast/syntax_check.rb +10 -8
  35. data/lib/evilution/baseline/report.rb +11 -2
  36. data/lib/evilution/baseline.rb +31 -6
  37. data/lib/evilution/cache/keys.rb +140 -0
  38. data/lib/evilution/cache/run_fingerprint.rb +51 -0
  39. data/lib/evilution/cache/skeleton.rb +57 -0
  40. data/lib/evilution/cache/spec_digest.rb +39 -0
  41. data/lib/evilution/cache.rb +143 -50
  42. data/lib/evilution/class_tree.rb +38 -0
  43. data/lib/evilution/cli/command.rb +12 -4
  44. data/lib/evilution/cli/commands/run.rb +12 -3
  45. data/lib/evilution/cli/commands/subjects.rb +5 -2
  46. data/lib/evilution/cli/parser/options_builder.rb +67 -3
  47. data/lib/evilution/cli/printers/environment.rb +34 -4
  48. data/lib/evilution/cli/printers/session_detail.rb +20 -3
  49. data/lib/evilution/compare/categorizer.rb +2 -1
  50. data/lib/evilution/compare/normalizer.rb +3 -2
  51. data/lib/evilution/config/sources.rb +3 -0
  52. data/lib/evilution/config/validators/base.rb +9 -0
  53. data/lib/evilution/config/validators/since.rb +22 -0
  54. data/lib/evilution/config/validators/skip_sites.rb +24 -0
  55. data/lib/evilution/config/validators/timeout_ceiling.rb +10 -0
  56. data/lib/evilution/config/validators/timeout_factor.rb +10 -0
  57. data/lib/evilution/config/validators/timeout_floor.rb +10 -0
  58. data/lib/evilution/config.rb +122 -6
  59. data/lib/evilution/coverage/load_tracker.rb +50 -0
  60. data/lib/evilution/coverage/map.rb +42 -5
  61. data/lib/evilution/coverage/map_builder.rb +123 -22
  62. data/lib/evilution/coverage/map_store.rb +15 -5
  63. data/lib/evilution/coverage/recorder.rb +42 -3
  64. data/lib/evilution/coverage_example_filter.rb +35 -0
  65. data/lib/evilution/equivalent/heuristic/comment_marking.rb +14 -1
  66. data/lib/evilution/example_filter.rb +20 -0
  67. data/lib/evilution/git/changed_lines.rb +103 -0
  68. data/lib/evilution/git/since_scope.rb +77 -0
  69. data/lib/evilution/git/unified_diff.rb +68 -0
  70. data/lib/evilution/infra_crash.rb +26 -0
  71. data/lib/evilution/integration/base.rb +97 -6
  72. data/lib/evilution/integration/crash_detector.rb +46 -6
  73. data/lib/evilution/integration/known_failures.rb +4 -0
  74. data/lib/evilution/integration/loading/body_call_neutralizer.rb +49 -11
  75. data/lib/evilution/integration/loading/callback_equivalence.rb +62 -0
  76. data/lib/evilution/integration/loading/callback_redeclaration.rb +151 -36
  77. data/lib/evilution/integration/loading/concern_redeclaration.rb +16 -12
  78. data/lib/evilution/integration/loading/concern_registry.rb +87 -0
  79. data/lib/evilution/integration/loading/concern_state_cleaner.rb +19 -8
  80. data/lib/evilution/integration/loading/created_modules.rb +56 -0
  81. data/lib/evilution/integration/loading/frozen_namespaces.rb +80 -0
  82. data/lib/evilution/integration/loading/mutation_applier.rb +42 -11
  83. data/lib/evilution/integration/loading/neutralization.rb +41 -0
  84. data/lib/evilution/integration/loading/redefinition_recovery.rb +5 -3
  85. data/lib/evilution/integration/loading/superseded_modules.rb +22 -19
  86. data/lib/evilution/integration/minitest/stop_hook.rb +57 -0
  87. data/lib/evilution/integration/minitest.rb +22 -2
  88. data/lib/evilution/integration/minitest_crash_detector.rb +19 -0
  89. data/lib/evilution/integration/rspec/baseline_runner.rb +3 -2
  90. data/lib/evilution/integration/rspec/crash_detector_lifecycle.rb +6 -1
  91. data/lib/evilution/integration/rspec/example_filter_applier.rb +16 -0
  92. data/lib/evilution/integration/rspec/example_ids.rb +23 -0
  93. data/lib/evilution/integration/rspec/example_order.rb +86 -0
  94. data/lib/evilution/integration/rspec/killer_first.rb +72 -0
  95. data/lib/evilution/integration/rspec/result_builder.rb +7 -0
  96. data/lib/evilution/integration/rspec/state_guard/example_group_descendants.rb +44 -0
  97. data/lib/evilution/integration/rspec/state_guard.rb +2 -2
  98. data/lib/evilution/integration/rspec/target_resolver.rb +42 -0
  99. data/lib/evilution/integration/rspec/test_file_resolver.rb +4 -2
  100. data/lib/evilution/integration/rspec.rb +98 -47
  101. data/lib/evilution/integration/stop_policy.rb +49 -0
  102. data/lib/evilution/integration/test_unit/dispatcher.rb +20 -1
  103. data/lib/evilution/integration/test_unit/subject_class_registry.rb +6 -1
  104. data/lib/evilution/integration/test_unit.rb +28 -2
  105. data/lib/evilution/isolation/fork.rb +58 -13
  106. data/lib/evilution/isolation/in_process.rb +12 -1
  107. data/lib/evilution/line_set.rb +72 -0
  108. data/lib/evilution/mcp/info_tool/actions/environment.rb +12 -16
  109. data/lib/evilution/mcp/info_tool/actions/subjects.rb +3 -5
  110. data/lib/evilution/mcp/info_tool/status_glossary.rb +15 -2
  111. data/lib/evilution/mcp/info_tool.rb +24 -17
  112. data/lib/evilution/mcp/mutate_tool/config_builder.rb +13 -1
  113. data/lib/evilution/mcp/mutate_tool/option_parser.rb +2 -2
  114. data/lib/evilution/mcp/mutate_tool/progress_streamer.rb +1 -1
  115. data/lib/evilution/mcp/mutate_tool/report_trimmer.rb +28 -5
  116. data/lib/evilution/mcp/mutate_tool/survived_enricher.rb +12 -7
  117. data/lib/evilution/mcp/mutate_tool.rb +32 -7
  118. data/lib/evilution/mcp/session_tool.rb +1 -2
  119. data/lib/evilution/mcp.rb +4 -0
  120. data/lib/evilution/mutation/line_diff.rb +111 -0
  121. data/lib/evilution/mutation.rb +17 -13
  122. data/lib/evilution/mutator/base.rb +121 -98
  123. data/lib/evilution/mutator/constant_value_subjects.rb +29 -1
  124. data/lib/evilution/mutator/line_range_filter.rb +27 -0
  125. data/lib/evilution/mutator/load_sources.rb +88 -0
  126. data/lib/evilution/mutator/operator/alias_removal.rb +2 -5
  127. data/lib/evilution/mutator/operator/argument_method_call_replacement.rb +3 -0
  128. data/lib/evilution/mutator/operator/attr_accessor_swap.rb +2 -5
  129. data/lib/evilution/mutator/operator/constant_namespace_strip.rb +3 -3
  130. data/lib/evilution/mutator/operator/freeze_removal.rb +29 -11
  131. data/lib/evilution/mutator/operator/method_call_removal.rb +3 -1
  132. data/lib/evilution/mutator/operator/mixin_removal.rb +2 -5
  133. data/lib/evilution/mutator/operator/superclass_removal.rb +2 -5
  134. data/lib/evilution/mutator/operator/symbol_literal.rb +1 -1
  135. data/lib/evilution/mutator/operator/visibility_removal.rb +2 -5
  136. data/lib/evilution/mutator/registry.rb +11 -5
  137. data/lib/evilution/mutator/restore_source_cache.rb +41 -0
  138. data/lib/evilution/parallel/pool.rb +11 -4
  139. data/lib/evilution/parallel/work_queue/dispatcher/result_stream.rb +40 -0
  140. data/lib/evilution/parallel/work_queue/dispatcher.rb +20 -7
  141. data/lib/evilution/parallel/work_queue/worker/loop.rb +7 -2
  142. data/lib/evilution/parallel/work_queue/worker.rb +10 -3
  143. data/lib/evilution/parallel/work_queue/worker_stat.rb +7 -0
  144. data/lib/evilution/parallel/work_queue.rb +69 -12
  145. data/lib/evilution/parallel_db_warning.rb +39 -12
  146. data/lib/evilution/process_supervisor.rb +22 -2
  147. data/lib/evilution/reporter/cli/item_formatters/coverage_gap.rb +13 -2
  148. data/lib/evilution/reporter/cli/item_formatters/subject_score.rb +5 -1
  149. data/lib/evilution/reporter/cli/line_formatters/mutations.rb +9 -2
  150. data/lib/evilution/reporter/cli/line_formatters/result_line.rb +9 -1
  151. data/lib/evilution/reporter/cli/line_formatters/skipped_sites.rb +14 -0
  152. data/lib/evilution/reporter/cli/line_formatters/uncovered_code.rb +17 -0
  153. data/lib/evilution/reporter/cli/metrics_block.rb +4 -0
  154. data/lib/evilution/reporter/cli/trailer.rb +4 -4
  155. data/lib/evilution/reporter/cli.rb +9 -2
  156. data/lib/evilution/reporter/html/assets/style.css +8 -0
  157. data/lib/evilution/reporter/html/sections/file_section.rb +9 -0
  158. data/lib/evilution/reporter/html/sections/uncovered_details.rb +27 -0
  159. data/lib/evilution/reporter/html/templates/file_section.html.erb +2 -1
  160. data/lib/evilution/reporter/html/templates/summary_cards.html.erb +3 -0
  161. data/lib/evilution/reporter/html/templates/uncovered_details.html.erb +11 -0
  162. data/lib/evilution/reporter/json/mutation_detail.rb +77 -0
  163. data/lib/evilution/reporter/json/subjects.rb +1 -0
  164. data/lib/evilution/reporter/json/timings.rb +42 -0
  165. data/lib/evilution/reporter/json.rb +13 -50
  166. data/lib/evilution/result/coverage_gap.rb +5 -0
  167. data/lib/evilution/result/mutation_result.rb +55 -3
  168. data/lib/evilution/result/mutation_timings.rb +54 -0
  169. data/lib/evilution/result/run_timings.rb +20 -0
  170. data/lib/evilution/result/subject_score.rb +8 -1
  171. data/lib/evilution/result/subject_scorer.rb +5 -3
  172. data/lib/evilution/result/summary.rb +49 -12
  173. data/lib/evilution/runner/baseline_runner.rb +47 -5
  174. data/lib/evilution/runner/diagnostics.rb +0 -13
  175. data/lib/evilution/runner/isolation_resolver.rb +16 -4
  176. data/lib/evilution/runner/mutation_executor/isolated_run.rb +34 -0
  177. data/lib/evilution/runner/mutation_executor/kill_history.rb +66 -0
  178. data/lib/evilution/runner/mutation_executor/mutation_runner.rb +31 -12
  179. data/lib/evilution/runner/mutation_executor/neutralizer/baseline_failed.rb +1 -0
  180. data/lib/evilution/runner/mutation_executor/neutralizer/infra_error.rb +6 -20
  181. data/lib/evilution/runner/mutation_executor/probe_first.rb +99 -0
  182. data/lib/evilution/runner/mutation_executor/probe_first_run.rb +59 -0
  183. data/lib/evilution/runner/mutation_executor/result_cache.rb +45 -14
  184. data/lib/evilution/runner/mutation_executor/result_notifier.rb +1 -1
  185. data/lib/evilution/runner/mutation_executor/result_packer.rb +54 -24
  186. data/lib/evilution/runner/mutation_executor/runless_verdict.rb +39 -0
  187. data/lib/evilution/runner/mutation_executor/strategy/parallel/hinted_items.rb +27 -0
  188. data/lib/evilution/runner/mutation_executor/strategy/parallel/ordered_delivery.rb +97 -0
  189. data/lib/evilution/runner/mutation_executor/strategy/parallel.rb +102 -83
  190. data/lib/evilution/runner/mutation_executor/timed_run.rb +33 -0
  191. data/lib/evilution/runner/mutation_executor/timeout_policy/adaptive.rb +67 -0
  192. data/lib/evilution/runner/mutation_executor/timeout_policy/base.rb +35 -0
  193. data/lib/evilution/runner/mutation_executor/timeout_policy/fixed.rb +17 -0
  194. data/lib/evilution/runner/mutation_executor/timeout_policy.rb +56 -0
  195. data/lib/evilution/runner/mutation_executor.rb +75 -10
  196. data/lib/evilution/runner/mutation_planner.rb +29 -21
  197. data/lib/evilution/runner/phase_clock.rb +22 -0
  198. data/lib/evilution/runner/report_publisher.rb +1 -1
  199. data/lib/evilution/runner/subject_pipeline.rb +18 -8
  200. data/lib/evilution/runner.rb +87 -26
  201. data/lib/evilution/session/diff.rb +9 -2
  202. data/lib/evilution/session/store.rb +17 -2
  203. data/lib/evilution/source_ast_cache.rb +10 -0
  204. data/lib/evilution/spec_ast_cache.rb +15 -0
  205. data/lib/evilution/spec_resolver/constant_references.rb +66 -0
  206. data/lib/evilution/spec_resolver/project_files.rb +50 -0
  207. data/lib/evilution/spec_resolver/sibling_spec_ranker.rb +111 -0
  208. data/lib/evilution/spec_resolver/spec_pattern.rb +19 -0
  209. data/lib/evilution/spec_resolver.rb +76 -65
  210. data/lib/evilution/spec_selector.rb +17 -13
  211. data/lib/evilution/subject.rb +7 -2
  212. data/lib/evilution/version.rb +1 -1
  213. data/lib/evilution/worker_database/copies.rb +73 -0
  214. data/lib/evilution/worker_database/schema.rb +39 -0
  215. data/lib/evilution/worker_database/sqlite_copy.rb +65 -0
  216. data/lib/evilution/worker_database.rb +214 -0
  217. data/schema/evilution.config.schema.json +74 -2
  218. metadata +84 -13
  219. data/lib/evilution/integration/rspec/state_guard/object_space_example_groups.rb +0 -42
  220. data/scripts/benchmark_density +0 -262
  221. data/scripts/benchmark_density.yml +0 -19
  222. data/scripts/canary_manifest.yml +0 -47
  223. data/scripts/compare_mutations +0 -421
  224. data/scripts/compare_mutations.yml +0 -24
  225. data/scripts/compare_targeting +0 -279
  226. data/scripts/compare_targeting.example.yml +0 -24
  227. data/scripts/mutant_json_adapter +0 -227
@@ -8,15 +8,20 @@ require_relative "../../feedback/messages"
8
8
  require_relative "../../feedback/setup_warning"
9
9
 
10
10
  module Evilution::MCP::MutateTool::ReportTrimmer
11
- MINIMAL_KEYS = %w[summary survived].freeze
11
+ # An uncovered mutation is a survivor no test executes, as actionable as one
12
+ # that ran: it is kept wherever survivors are, with its diff.
13
+ MINIMAL_KEYS = %w[summary survived uncovered].freeze
12
14
  FULL_DIFF_STRIP_KEYS = %w[killed neutral equivalent unresolved unparseable].freeze
13
- SUMMARY_DROP_KEYS = %w[killed neutral equivalent unparseable].freeze
15
+ SUMMARY_DROP_KEYS = %w[killed neutral equivalent unparseable timings].freeze
14
16
  # EV-187j / GH #1169: at summary verbosity, non-survived entries that remain
15
17
  # (timed_out, errors, unresolved) shed `diff` and `error_backtrace` payload —
16
18
  # those two fields dominate response size at scale and aren't actionable for
17
- # a scanning agent. Survived stays full-detail.
19
+ # a scanning agent. Survived and uncovered stay full-detail.
18
20
  SUMMARY_HEAVY_FIELDS = %w[diff error_backtrace].freeze
19
21
  SUMMARY_TRIM_KEYS = %w[timed_out errors unresolved].freeze
22
+ # Per-mutation timings are for profiling a run, not for acting on a result,
23
+ # so summary verbosity drops them from every entry it keeps, survived included.
24
+ SUMMARY_TIMED_KEYS = %w[survived uncovered timed_out errors unresolved].freeze
20
25
 
21
26
  # EV-t7kh / GH #1170: at minimal verbosity we surface a small sample of any
22
27
  # errored mutations so agents are not stuck in a diagnose-vs-token-cap
@@ -25,7 +30,7 @@ module Evilution::MCP::MutateTool::ReportTrimmer
25
30
  ERROR_BACKTRACE_HEAD_LINES = 5
26
31
  ERROR_SAMPLE_KEYS = %w[operator file line error_message error_class].freeze
27
32
 
28
- def self.call(json_string, verbosity:, survived_results:, config:, enricher:, summary: nil)
33
+ def self.call(json_string, verbosity:, survived_results:, config:, enricher:, summary: nil, uncovered_results: [])
29
34
  data = ::JSON.parse(json_string)
30
35
  case verbosity
31
36
  when "full"
@@ -33,10 +38,11 @@ module Evilution::MCP::MutateTool::ReportTrimmer
33
38
  when "summary"
34
39
  SUMMARY_DROP_KEYS.each { |key| data.delete(key) }
35
40
  SUMMARY_TRIM_KEYS.each { |key| strip_heavy_fields(data, key) }
41
+ strip_entry_timings(data)
36
42
  when "minimal"
37
43
  apply_minimal(data)
38
44
  end
39
- enricher.call(data, survived_results, config)
45
+ enricher.call(data, survived_results, config, uncovered_results: uncovered_results)
40
46
  embed_feedback(data, summary) unless verbosity == "minimal"
41
47
  embed_setup_warning(data, summary)
42
48
  ::JSON.generate(data)
@@ -80,6 +86,23 @@ module Evilution::MCP::MutateTool::ReportTrimmer
80
86
  end
81
87
  private_class_method :strip_heavy_fields
82
88
 
89
+ def self.strip_entry_timings(data)
90
+ entries = SUMMARY_TIMED_KEYS.flat_map { |key| array_at(data, key) }
91
+ entries += array_at(data, "coverage_gaps").flat_map { |gap| array_at(gap, "mutations") }
92
+ entries.each { |entry| entry.delete("timings") if entry.is_a?(Hash) }
93
+ end
94
+ private_class_method :strip_entry_timings
95
+
96
+ # The Array under key, or none when the container or the value is not what
97
+ # a report holds there.
98
+ def self.array_at(container, key)
99
+ return [] unless container.is_a?(Hash)
100
+
101
+ value = container[key]
102
+ value.is_a?(Array) ? value : []
103
+ end
104
+ private_class_method :array_at
105
+
83
106
  def self.embed_feedback(data, summary)
84
107
  return unless Evilution::Feedback::Detector.friction?(summary)
85
108
 
@@ -4,19 +4,24 @@ require_relative "../mutate_tool"
4
4
  require_relative "../../runner"
5
5
  require_relative "../../spec_resolver"
6
6
 
7
+ # Survived and uncovered entries alike: an uncovered mutation is a survivor no
8
+ # test executes, and wants the same test written.
7
9
  module Evilution::MCP::MutateTool::SurvivedEnricher
8
- def self.call(data, survived_results, config)
9
- entries = data["survived"]
10
- return unless entries.is_a?(Array)
10
+ def self.call(data, survived_results, config, uncovered_results: [])
11
+ buckets = { "survived" => survived_results, "uncovered" => uncovered_results }
12
+ .select { |key, _| data[key].is_a?(Array) }
13
+ return if buckets.empty?
11
14
 
12
15
  explicit_spec, resolver = build_resolver(config)
13
16
  cache = {}
14
17
 
15
- entries.each_with_index do |entry, index|
16
- result = survived_results[index]
17
- next unless result
18
+ buckets.each do |key, results|
19
+ data[key].each_with_index do |entry, index|
20
+ result = results[index]
21
+ next unless result
18
22
 
19
- enrich_entry(entry, result.mutation, explicit_spec, resolver, cache)
23
+ enrich_entry(entry, result.mutation, explicit_spec, resolver, cache)
24
+ end
20
25
  end
21
26
  end
22
27
 
@@ -2,18 +2,18 @@
2
2
 
3
3
  require "json"
4
4
  require "mcp"
5
+ require_relative "../mcp"
5
6
  require_relative "../config"
6
7
  require_relative "../runner"
7
8
  require_relative "../reporter/json"
8
9
  require_relative "../spec_resolver"
9
-
10
- require_relative "../mcp"
10
+ require_relative "../ast/skip_sites/presets"
11
11
 
12
12
  class Evilution::MCP::MutateTool < MCP::Tool
13
13
  tool_name "evilution-mutate"
14
14
  description "Run mutation testing on Ruby source files and return structured JSON — not parsed CLI text. " \
15
15
  "Built for iterative TDD: " \
16
- "'incremental: true' caches killed/timeout results so rerunning on unchanged files is fast; " \
16
+ "'incremental: true' caches verdicts per method so a rerun only runs the mutations of edited methods; " \
17
17
  "'save_session: true' persists results for later diffing via evilution-session; " \
18
18
  "'suggest_tests: true' streams concrete RSpec/Minitest code for each survivor as progress " \
19
19
  "events so you can drop fixes straight into a test file. " \
@@ -43,9 +43,17 @@ class Evilution::MCP::MutateTool < MCP::Tool
43
43
  type: "string",
44
44
  description: "Only mutate the named method (e.g. Foo#bar)"
45
45
  },
46
+ since: {
47
+ type: "string",
48
+ description: "Only mutate the lines changed since this git ref (e.g. 'main', 'origin/main', a commit), " \
49
+ "diffed from its merge base with HEAD, uncommitted and untracked changes included. " \
50
+ "Without files: every changed .rb file under lib/ and app/; with files: only those of " \
51
+ "them that changed, line ranges narrowed to their changed lines. CLI: `--since REF`."
52
+ },
46
53
  timeout: {
47
54
  type: "integer",
48
- description: "Per-mutation timeout in seconds (default: 30)"
55
+ description: "Per-mutation timeout in seconds, the same for every mutation " \
56
+ "(default: derived from the baseline time of each mutation's spec files)"
49
57
  },
50
58
  jobs: {
51
59
  type: "integer",
@@ -55,6 +63,20 @@ class Evilution::MCP::MutateTool < MCP::Tool
55
63
  type: "integer",
56
64
  description: "Stop after N surviving mutants"
57
65
  },
66
+ stop_on_kill: {
67
+ type: "boolean",
68
+ description: "Stop each mutation's test run at the first failure that decides the verdict " \
69
+ "(default: true). Pass false to run every selected example."
70
+ },
71
+ skip_sites: {
72
+ type: "array",
73
+ items: { type: "string", enum: Evilution::AST::SkipSites::Presets.names.map(&:to_s) },
74
+ description: "Presets of low-value code to leave unmutated (default: none, or the config file's " \
75
+ "skip_sites): logging (log lines, deprecation warnings), debug_output (puts/print/warn/p/pp), " \
76
+ "error_messages (the message of a raised error, not the raise or its class), requires " \
77
+ "(load-time require/require_relative; no subject mutates these yet, so it skips nothing). " \
78
+ "Skips are counted per preset in summary.skipped_sites."
79
+ },
58
80
  spec: {
59
81
  type: "array",
60
82
  items: { type: "string" },
@@ -67,7 +89,8 @@ class Evilution::MCP::MutateTool < MCP::Tool
67
89
  },
68
90
  incremental: {
69
91
  type: "boolean",
70
- description: "Cache killed/timeout results and skip re-running them on unchanged files. " \
92
+ description: "Cache killed/survived/timeout verdicts and skip re-running them until the method, " \
93
+ "its spec files or the run's settings change. " \
71
94
  "Set true when iterating on the same files to speed up repeat runs."
72
95
  },
73
96
  integration: {
@@ -116,8 +139,9 @@ class Evilution::MCP::MutateTool < MCP::Tool
116
139
  enum: %w[full summary minimal],
117
140
  description: "Response verbosity: full (all entries, diffs stripped from killed/neutral/equivalent), " \
118
141
  "summary (omits killed/neutral/equivalent arrays; remaining timed_out/errors/unresolved " \
119
- "entries shed `diff` and `error_backtrace` to bound payload size; default), " \
120
- "minimal (summary + survived; also includes a trimmed sample of up to 3 errored " \
142
+ "entries shed `diff` and `error_backtrace`, and run and per-entry `timings` are dropped, " \
143
+ "to bound payload size; default), " \
144
+ "minimal (summary + survived + uncovered; also includes a trimmed sample of up to 3 errored " \
121
145
  "entries with error_message and a 5-line backtrace head when errors > 0)"
122
146
  }
123
147
  }
@@ -165,6 +189,7 @@ class Evilution::MCP::MutateTool < MCP::Tool
165
189
  report,
166
190
  verbosity: Evilution::MCP::MutateTool::OptionParser.normalize_verbosity(verbosity),
167
191
  survived_results: summary.survived_results,
192
+ uncovered_results: summary.uncovered_results,
168
193
  config: config,
169
194
  enricher: Evilution::MCP::MutateTool::SurvivedEnricher,
170
195
  summary: summary
@@ -2,11 +2,10 @@
2
2
 
3
3
  require "json"
4
4
  require "mcp"
5
+ require_relative "../mcp"
5
6
  require_relative "../session/store"
6
7
  require_relative "../session/diff"
7
8
 
8
- require_relative "../mcp"
9
-
10
9
  class Evilution::MCP::SessionTool < MCP::Tool
11
10
  tool_name "evilution-session"
12
11
  description "Inspect mutation testing history without re-running any tests. " \
data/lib/evilution/mcp.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # version.rb defines the Evilution module, so any MCP file can be the first
4
+ # one required.
5
+ require_relative "version"
6
+
3
7
  module Evilution::MCP
4
8
  # Public contract version for the evilution MCP tool surface (input schemas,
5
9
  # output payload shapes, error envelope, action enumerations). Bumped only
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "diff/lcs"
4
+ # Loaded by mutation.rb, once Evilution::Mutation is defined.
5
+
6
+ # The lines a mutation takes out of its file and puts in, as "- line" and
7
+ # "+ line", in the order Diff::LCS.diff lists them for the two whole files.
8
+ #
9
+ # A mutation changes a few lines of a file that can run to thousands, and
10
+ # splitting both into lines to diff them costs per mutation what the file
11
+ # is long. Diff::LCS first sets aside the longest run of equal lines at the
12
+ # top of the two sequences and then the longest at the bottom; what it
13
+ # reports comes from the lines between the two runs. So only those lines
14
+ # are split and handed to it, found from where the bytes of the two sources
15
+ # stop being equal, and with them the first equal line after them: the
16
+ # lines left unmatched before it are reported in the order a match puts
17
+ # them in, which differs from the order at the end of a sequence.
18
+ module Evilution::Mutation::LineDiff
19
+ NEWLINE = "\n"
20
+ private_constant :NEWLINE
21
+
22
+ Window = Data.define(:start, :original_end, :mutated_end)
23
+ private_constant :Window
24
+
25
+ def self.call(original, mutated)
26
+ return "" if original == mutated
27
+
28
+ window = window(original.b, mutated.b)
29
+ changes = ::Diff::LCS.diff(lines(original, window.start, window.original_end),
30
+ lines(mutated, window.start, window.mutated_end))
31
+ changes.flatten(1).map { |change| "#{change.action} #{change.element.chomp}" }.join(NEWLINE)
32
+ end
33
+
34
+ # The lines of the source between two byte offsets, in its encoding.
35
+ def self.lines(source, from, to)
36
+ source.byteslice(from, to - from).lines
37
+ end
38
+
39
+ # The bytes from the start of the first line that differs to the end of
40
+ # the first equal line after it, in each source. Both are binary.
41
+ def self.window(original, mutated)
42
+ start = line_start_before(original, common_prefix(original, mutated))
43
+ original_rest = original.byteslice(start, original.bytesize - start)
44
+ mutated_rest = mutated.byteslice(start, mutated.bytesize - start)
45
+ tail = first_equal_line(original_rest, mutated_rest)
46
+ growth = mutated_rest.bytesize - original_rest.bytesize
47
+ Window.new(start: start, original_end: start + tail, mutated_end: start + tail + growth)
48
+ end
49
+
50
+ # Where the first equal line after the change ends in the original, from
51
+ # the start of the first line that differs; the end of the source when
52
+ # the two differ down to their last line.
53
+ def self.first_equal_line(original, mutated)
54
+ suffix = common_suffix(original, mutated)
55
+ from = suffix_line_start(original, mutated, suffix)
56
+ return original.bytesize unless from
57
+
58
+ line_end = original.index(NEWLINE, from)
59
+ line_end ? line_end + 1 : original.bytesize
60
+ end
61
+
62
+ # The first offset in the original's equal tail that starts a line in
63
+ # both sources, or nil when none does. Past a line break inside the tail
64
+ # a line starts in both; where the tail itself starts, only when both
65
+ # break a line there.
66
+ def self.suffix_line_start(original, mutated, suffix)
67
+ from = original.bytesize - suffix
68
+ return from if line_start?(original, from) && line_start?(mutated, mutated.bytesize - suffix)
69
+
70
+ line_break = original.index(NEWLINE, from)
71
+ line_break && (line_break + 1)
72
+ end
73
+
74
+ def self.line_start?(source, offset)
75
+ offset.zero? || source.getbyte(offset - 1) == NEWLINE.ord
76
+ end
77
+
78
+ def self.line_start_before(source, offset)
79
+ return 0 if offset.zero?
80
+
81
+ line_break = source.rindex(NEWLINE, offset - 1)
82
+ line_break ? line_break + 1 : 0
83
+ end
84
+
85
+ # How many bytes the two start with alike, found by halving: each probe
86
+ # compares two shared slices in C rather than walking the bytes in Ruby.
87
+ def self.common_prefix(left, right)
88
+ longest_equal(left, right) { |source, length| source.byteslice(0, length) }
89
+ end
90
+
91
+ def self.common_suffix(left, right)
92
+ longest_equal(left, right) { |source, length| source.byteslice(source.bytesize - length, length) }
93
+ end
94
+
95
+ def self.longest_equal(left, right)
96
+ low = 0
97
+ high = [left.bytesize, right.bytesize].min
98
+ while low < high
99
+ probe = (low + high + 1) / 2
100
+ if yield(left, probe) == yield(right, probe)
101
+ low = probe
102
+ else
103
+ high = probe - 1
104
+ end
105
+ end
106
+ low
107
+ end
108
+
109
+ private_class_method :lines, :window, :first_equal_line, :suffix_line_start, :line_start?,
110
+ :line_start_before, :common_prefix, :common_suffix, :longest_equal
111
+ end
@@ -6,7 +6,15 @@ require_relative "version"
6
6
  class Evilution::Mutation
7
7
  Sources = Data.define(:original, :mutated)
8
8
  Slice = Data.define(:original, :mutated)
9
- Location = Data.define(:file_path, :line, :column)
9
+ # lines: the lines of the original file the mutation's bytes sit on. A
10
+ # mutation is reported at the line its node starts on, which need not be the
11
+ # first line it changes, and it can change several. Left out, it is taken to
12
+ # change only the line it is reported at.
13
+ Location = Data.define(:file_path, :line, :column, :lines) do
14
+ def initialize(file_path:, line:, column:, lines: line..line)
15
+ super
16
+ end
17
+ end
10
18
 
11
19
  # What a mutation holds once its sources are released (see strip_sources!),
12
20
  # and when it was built without a slice. Their fields read as nil, so the
@@ -17,7 +25,7 @@ class Evilution::Mutation
17
25
 
18
26
  # restore_source: the original file, evaluated after the mutation's tests
19
27
  # to put back what applying it changed (see
20
- # Mutator::Base#build_restore_source). nil when a mutation was built
28
+ # Mutator::LoadSources#restore_source). nil when a mutation was built
21
29
  # without one.
22
30
  attr_reader :subject, :operator_name, :parse_status, :location, :restore_source
23
31
 
@@ -72,6 +80,10 @@ class Evilution::Mutation
72
80
  @location.column
73
81
  end
74
82
 
83
+ def changed_lines
84
+ @location.lines
85
+ end
86
+
75
87
  def unparseable?
76
88
  @parse_status == :unparseable
77
89
  end
@@ -98,17 +110,7 @@ class Evilution::Mutation
98
110
  private
99
111
 
100
112
  def compute_diff
101
- diffs = ::Diff::LCS.diff(original_source.lines, mutated_source.lines)
102
- return "" if diffs.empty?
103
-
104
- diffs.flatten(1).filter_map { |change| format_diff_change(change) }.join("\n")
105
- end
106
-
107
- def format_diff_change(change)
108
- case change.action
109
- when "-" then "- #{change.element.chomp}"
110
- when "+" then "+ #{change.element.chomp}"
111
- end
113
+ LineDiff.call(original_source, mutated_source)
112
114
  end
113
115
 
114
116
  def compute_unified_diff
@@ -137,3 +139,5 @@ class Evilution::Mutation
137
139
  end
138
140
  end
139
141
  end
142
+
143
+ require_relative "mutation/line_diff"