saboteur 0.8.0 → 0.9.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 (128) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +215 -0
  3. data/README.md +44 -6
  4. data/exe/saboteur +6 -2
  5. data/lib/saboteur/attribute_finder.rb +116 -0
  6. data/lib/saboteur/baseline/run_evidence.rb +2 -1
  7. data/lib/saboteur/cli/agent_provenance.rb +59 -0
  8. data/lib/saboteur/cli/dirty_tree_notice.rb +28 -0
  9. data/lib/saboteur/cli/doctor_command.rb +41 -0
  10. data/lib/saboteur/cli/error_cause.rb +40 -0
  11. data/lib/saboteur/cli/execution_options.rb +46 -0
  12. data/lib/saboteur/cli/exit_status.rb +12 -14
  13. data/lib/saboteur/cli/explicit_file_options.rb +21 -0
  14. data/lib/saboteur/cli/explicit_sources.rb +46 -0
  15. data/lib/saboteur/cli/failure_output.rb +35 -0
  16. data/lib/saboteur/cli/help_command.rb +23 -0
  17. data/lib/saboteur/cli/matrix_option.rb +17 -0
  18. data/lib/saboteur/cli/output_options.rb +27 -0
  19. data/lib/saboteur/cli/presets.rb +41 -1
  20. data/lib/saboteur/cli/preview_command.rb +26 -0
  21. data/lib/saboteur/cli/run_budget_options.rb +6 -1
  22. data/lib/saboteur/cli/run_command.rb +33 -0
  23. data/lib/saboteur/cli/run_output.rb +38 -0
  24. data/lib/saboteur/cli/run_reporting.rb +6 -5
  25. data/lib/saboteur/cli/run_validation.rb +54 -0
  26. data/lib/saboteur/cli/source_set.rb +0 -18
  27. data/lib/saboteur/cli.rb +29 -305
  28. data/lib/saboteur/config.rb +76 -7
  29. data/lib/saboteur/config_file.rb +12 -8
  30. data/lib/saboteur/constant_subject_finder.rb +3 -0
  31. data/lib/saboteur/custom_map.rb +24 -5
  32. data/lib/saboteur/deep_source.rb +49 -0
  33. data/lib/saboteur/dirty_tree_warning.rb +6 -4
  34. data/lib/saboteur/doctor.rb +10 -0
  35. data/lib/saboteur/engine/baseline_guard.rb +118 -15
  36. data/lib/saboteur/engine/baseline_parts.rb +51 -0
  37. data/lib/saboteur/engine/boot.rb +11 -3
  38. data/lib/saboteur/engine/bytecode_equivalence.rb +17 -1
  39. data/lib/saboteur/engine/candidate_selection.rb +16 -5
  40. data/lib/saboteur/engine/candidates.rb +4 -1
  41. data/lib/saboteur/engine/coverage_inputs_snapshot.rb +146 -0
  42. data/lib/saboteur/engine/coverage_miss_note.rb +86 -0
  43. data/lib/saboteur/engine/coverage_partial.rb +48 -0
  44. data/lib/saboteur/engine/coverage_parts.rb +50 -0
  45. data/lib/saboteur/engine/coverage_shadow.rb +92 -0
  46. data/lib/saboteur/engine/coverage_store.rb +296 -21
  47. data/lib/saboteur/engine/diagnostics.rb +24 -7
  48. data/lib/saboteur/engine/distribution.rb +2 -2
  49. data/lib/saboteur/engine/gated_run.rb +4 -1
  50. data/lib/saboteur/engine/load_coverage.rb +72 -8
  51. data/lib/saboteur/engine/partial_invalidation.rb +115 -0
  52. data/lib/saboteur/engine/partial_merge.rb +40 -0
  53. data/lib/saboteur/engine/pipelines.rb +11 -3
  54. data/lib/saboteur/engine/reference_specs.rb +71 -0
  55. data/lib/saboteur/engine/result_cache.rb +68 -5
  56. data/lib/saboteur/engine/resume_manifest.rb +110 -0
  57. data/lib/saboteur/engine/run_budget.rb +10 -7
  58. data/lib/saboteur/engine/run_fingerprint.rb +2 -1
  59. data/lib/saboteur/engine/sandbox_policy.rb +26 -5
  60. data/lib/saboteur/engine/scheduler.rb +33 -25
  61. data/lib/saboteur/engine/selection_announcement.rb +9 -3
  62. data/lib/saboteur/engine/shadow_comparison.rb +121 -0
  63. data/lib/saboteur/engine/shadow_run.rb +38 -0
  64. data/lib/saboteur/engine/subject_selection.rb +144 -64
  65. data/lib/saboteur/engine/suite_partition.rb +22 -0
  66. data/lib/saboteur/engine/test_guess.rb +186 -32
  67. data/lib/saboteur/engine/unchanged_syntax.rb +10 -2
  68. data/lib/saboteur/engine.rb +44 -11
  69. data/lib/saboteur/environment_hints.rb +55 -0
  70. data/lib/saboteur/execution/bundle_gemfile_pin.rb +72 -0
  71. data/lib/saboteur/execution/external_runner.rb +123 -1
  72. data/lib/saboteur/execution/fiddle_loader.rb +34 -0
  73. data/lib/saboteur/execution/gemfile_path_sources.rb +166 -0
  74. data/lib/saboteur/execution/marker_sweep.rb +2 -1
  75. data/lib/saboteur/execution/process_table.rb +7 -3
  76. data/lib/saboteur/execution/reevaluator.rb +7 -0
  77. data/lib/saboteur/execution/sandbox.rb +39 -20
  78. data/lib/saboteur/execution/seatbelt.rb +10 -3
  79. data/lib/saboteur/execution/supervisor.rb +42 -8
  80. data/lib/saboteur/execution/supervisor_batch.rb +105 -0
  81. data/lib/saboteur/execution/test_command_shape.rb +149 -0
  82. data/lib/saboteur/execution/worker_pool.rb +48 -4
  83. data/lib/saboteur/frameworks/rails.rb +2 -5
  84. data/lib/saboteur/frameworks/sqlite_memory_database.rb +32 -2
  85. data/lib/saboteur/gates.rb +121 -28
  86. data/lib/saboteur/install.rb +6 -1
  87. data/lib/saboteur/integration/base.rb +19 -2
  88. data/lib/saboteur/integration/rspec.rb +145 -18
  89. data/lib/saboteur/line_hits.rb +81 -0
  90. data/lib/saboteur/method_calls.rb +91 -0
  91. data/lib/saboteur/mutation_source/argument_swap.rb +54 -0
  92. data/lib/saboteur/mutation_source/builtin.rb +33 -21
  93. data/lib/saboteur/mutation_source/condition_negation.rb +3 -12
  94. data/lib/saboteur/mutation_source/hazard_guard.rb +94 -13
  95. data/lib/saboteur/mutation_source/jump_value.rb +59 -0
  96. data/lib/saboteur/mutation_source/literal_replacement.rb +6 -23
  97. data/lib/saboteur/mutation_source/operator_examples.rb +6 -0
  98. data/lib/saboteur/mutation_source/operator_registry.rb +6 -0
  99. data/lib/saboteur/mutation_source/operator_visit.rb +7 -1
  100. data/lib/saboteur/mutation_source/rescue_removal.rb +69 -0
  101. data/lib/saboteur/mutation_source/unary_removal.rb +47 -0
  102. data/lib/saboteur/mutation_source/when_removal.rb +51 -0
  103. data/lib/saboteur/preview.rb +13 -0
  104. data/lib/saboteur/refinement_activations.rb +22 -10
  105. data/lib/saboteur/reporter/agent.rb +2 -2
  106. data/lib/saboteur/reporter/agent_incomplete.rb +31 -5
  107. data/lib/saboteur/reporter/agent_summary.rb +16 -10
  108. data/lib/saboteur/reporter/review_comments.rb +151 -0
  109. data/lib/saboteur/reporter/safe_out.rb +32 -0
  110. data/lib/saboteur/reporter/stryker.rb +8 -6
  111. data/lib/saboteur/reporter/survivor_classification.rb +41 -3
  112. data/lib/saboteur/reporter/survivor_hints.rb +5 -0
  113. data/lib/saboteur/reporter/terminal.rb +45 -5
  114. data/lib/saboteur/result.rb +14 -4
  115. data/lib/saboteur/selection/coverage_map.rb +150 -9
  116. data/lib/saboteur/selection/external_test_map.rb +4 -0
  117. data/lib/saboteur/selection/git_diff.rb +24 -2
  118. data/lib/saboteur/selection/layout_only_lines.rb +45 -1
  119. data/lib/saboteur/selection/recorder.rb +52 -22
  120. data/lib/saboteur/selection/trace_recorder.rb +83 -0
  121. data/lib/saboteur/selection/untracked_changes.rb +1 -2
  122. data/lib/saboteur/subject.rb +16 -0
  123. data/lib/saboteur/subject_finder.rb +91 -6
  124. data/lib/saboteur/text.rb +31 -0
  125. data/lib/saboteur/version.rb +1 -1
  126. data/lib/saboteur/working_tree.rb +7 -2
  127. data/lib/saboteur.rb +9 -0
  128. metadata +48 -16
@@ -3,6 +3,7 @@
3
3
 
4
4
  require "coverage"
5
5
  require_relative "coverage_map"
6
+ require_relative "../method_calls"
6
7
 
7
8
  module Saboteur
8
9
  module Selection
@@ -12,6 +13,8 @@ module Saboteur
12
13
  def initialize(files)
13
14
  @files = Set.new(files.map { |file| CoverageMap.canonical(file) })
14
15
  @canonical = Hash.new { |hash, path| hash[path] = CoverageMap.canonical(path) }
16
+ @calls = MethodCalls.new(@files, canonical: ->(path) { @canonical[path] })
17
+ @arm_spans = {}
15
18
  @lines = hit_table
16
19
  @methods = hit_table
17
20
  @branches = hit_table
@@ -21,17 +24,22 @@ module Saboteur
21
24
  @outside = per_file { Set.new }
22
25
  @outside_methods = per_file { Set.new }
23
26
  @durations = {}
27
+ @first_loaders = {}
28
+ @seen = Set.new
24
29
  end
25
30
 
26
31
  def start
27
32
  Coverage.resume if Coverage.state == :suspended
28
- CoverageReads.result(stop: false, clear: true)
33
+ snapshot = CoverageReads.result(stop: false, clear: true)
34
+ @calls.enable
35
+ snapshot
29
36
  end
30
37
 
31
38
  def test_started(id, test_file)
32
39
  @tests << id
33
40
  @tests_by_file[test_file] << id
34
41
  each_hit do |file, line, kind|
42
+ @seen << file
35
43
  { line: @outside, method: @outside_methods, branch: @outside_branches }.fetch(kind)[test_file] << [file, line]
36
44
  end
37
45
  @started_at = monotonic
@@ -40,6 +48,7 @@ module Saboteur
40
48
  def test_finished(id)
41
49
  @durations[id] = monotonic - @started_at if @started_at
42
50
  each_hit do |file, line, kind|
51
+ @first_loaders[file] = id if @seen.add?(file)
43
52
  { line: @lines, method: @methods, branch: @branches }.fetch(kind)[file][line] << id
44
53
  end
45
54
  end
@@ -52,7 +61,8 @@ module Saboteur
52
61
  methods = @methods.transform_values { |by_line| by_line.transform_values(&:uniq) }
53
62
  branches = @branches.transform_values { |arms| arms.transform_values(&:uniq) }
54
63
  CoverageMap.new(lines: lines, tests: @tests, build_seconds: build_seconds, durations: @durations,
55
- methods: methods, branches: branches, loaded_files: loaded_files)
64
+ methods: methods, branches: branches, loaded_files: loaded_files,
65
+ first_loaders: @first_loaders.dup)
56
66
  end
57
67
 
58
68
  private
@@ -64,24 +74,36 @@ module Saboteur
64
74
  end
65
75
  end
66
76
 
77
+ # The arm spans of a branch never change, so the filtering below runs
78
+ # once per branch. Every read walks every branch of every recorded
79
+ # file, and redoing the sibling check each time cost far more than
80
+ # the Coverage read itself (#655).
67
81
  def record_branches(file, data)
68
- data.fetch(:branches, {}).each do |(_kind, _id, *parent_span), arms|
69
- spans = arms.map { |(_arm_kind, _arm_id, *span), _count| span }
70
- arms.each do |(_arm_kind, _arm_id, *span), count|
71
- next if span == parent_span
72
- # Ruby spans a `when X` arm with a bare `nil` body from the
73
- # `when` to the case's end, containing the sibling arms.
74
- # Sibling arms are disjoint by definition, so a containing span
75
- # is bogus; recording it would let it intersect and narrow
76
- # selection for edits inside the siblings it swallows.
77
- next if spans.any? { |other| span != other && contains?(span, other) }
78
-
79
- @branches[file][span] # Keep zero-hit arms as evidence, not as covered code.
80
- yield span if count.positive?
82
+ data.fetch(:branches, {}).each do |key, arms|
83
+ (@arm_spans[[file, key]] ||= recordable_arms(file, arms, key)).each do |arm, span|
84
+ yield span if arms.fetch(arm).positive?
81
85
  end
82
86
  end
83
87
  end
84
88
 
89
+ def recordable_arms(file, arms, key)
90
+ _kind, _id, *parent_span = key
91
+ spans = arms.keys.map { |(_arm_kind, _arm_id, *span)| span }
92
+ arms.keys.filter_map do |arm|
93
+ _arm_kind, _arm_id, *span = arm
94
+ next if span == parent_span
95
+ # Ruby spans a `when X` arm with a bare `nil` body from the
96
+ # `when` to the case's end, containing the sibling arms.
97
+ # Sibling arms are disjoint by definition, so a containing span
98
+ # is bogus; recording it would let it intersect and narrow
99
+ # selection for edits inside the siblings it swallows.
100
+ next if spans.any? { |other| span != other && contains?(span, other) }
101
+
102
+ @branches[file][span] # Keep zero-hit arms as evidence, not as covered code.
103
+ [arm, span]
104
+ end
105
+ end
106
+
85
107
  # [line, column] pairs compare lexically, like CoverageMap#position.
86
108
  # Both endpoints come from one slice per side: a separate slice per
87
109
  # comparand would make its size irrelevant on the right-hand side of
@@ -108,6 +130,7 @@ module Saboteur
108
130
  # own work (and anything it calls) is never attributed to a test.
109
131
  def each_hit
110
132
  snapshot = CoverageReads.result(stop: false, clear: true)
133
+ calls = @calls.pause.drain
111
134
  suspended = Coverage.running?
112
135
  Coverage.suspend if suspended
113
136
  snapshot.each do |path, data|
@@ -115,17 +138,24 @@ module Saboteur
115
138
  next unless @files.include?(file)
116
139
 
117
140
  # Lines mode (set up by the executable); nil marks a line with no
118
- # code. Methods mode keys are [owner, name, start_line, ...]; an
119
- # endless def's body never counts a line hit, but its calls count
120
- # here (issue #107).
141
+ # code. An endless def's body never counts a line hit, but its
142
+ # calls count through the method tracer (issue #107).
121
143
  data[:lines].each_with_index { |count, index| yield file, index + 1, :line if count&.positive? }
122
144
  record_branches(file, data) { |span| yield file, span, :branch }
123
- data[:methods]&.each do |(_owner, _name, start_line, *), count|
124
- yield file, start_line, :method if count.positive?
125
- end
145
+ end
146
+ calls.each do |path, hits|
147
+ # A file loaded before Coverage started has no line evidence; its
148
+ # calls must not make it look recorded (the preloaded refusal).
149
+ next unless snapshot.key?(path)
150
+
151
+ file = @canonical[path]
152
+ hits.to_set(&:first).each { |line| yield file, line, :method }
126
153
  end
127
154
  ensure
128
- Coverage.resume if suspended
155
+ @calls.resume
156
+ # A test may leave Coverage suspended (an in-process Engine#call
157
+ # does); the next test must still be measured.
158
+ Coverage.resume if Coverage.state == :suspended
129
159
  end
130
160
  end
131
161
  end
@@ -0,0 +1,83 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "recorder"
5
+ require_relative "../line_hits"
6
+
7
+ module Saboteur
8
+ module Selection
9
+ # The Recorder, with line hits from a TracePoint instead of a
10
+ # Coverage.result read around every test (#725). Methods come from the
11
+ # same call tracer. It records no branches, so a map from it has none:
12
+ # not a drop-in for the Coverage recorder until that is designed.
13
+ class TraceRecorder < Recorder
14
+ def initialize(files)
15
+ super
16
+ @line_hits = LineHits.new(@files, canonical: ->(path) { @canonical[path] })
17
+ end
18
+
19
+ def start
20
+ Coverage.resume if Coverage.state == :suspended
21
+ snapshot = CoverageReads.result(stop: false, clear: true)
22
+ @line_hits.enable
23
+ @calls.enable
24
+ snapshot
25
+ end
26
+
27
+ # Lines and methods are exact per test. Branches have no TracePoint
28
+ # event, so Coverage is read once per spec file instead of once per
29
+ # test: the delta read when the next file's first test starts goes to
30
+ # every test of the file that just ran and to every test of the file
31
+ # starting. A branch can therefore be credited to a few more tests than
32
+ # ran it, never fewer, so selection only widens.
33
+ def test_started(id, test_file)
34
+ flush_branches(test_file) unless test_file == @branch_file
35
+ @branch_file = test_file
36
+ super
37
+ end
38
+
39
+ def result(**)
40
+ flush_branches(nil)
41
+ super
42
+ end
43
+
44
+ private
45
+
46
+ def flush_branches(next_file)
47
+ hits = read_branches
48
+ [@branch_file, next_file].compact.each do |test_file|
49
+ hits.each { |file, span| @outside_branches[test_file] << [file, span] }
50
+ end
51
+ end
52
+
53
+ def read_branches
54
+ @line_hits.pause
55
+ @calls.pause
56
+ snapshot = CoverageReads.result(stop: false, clear: true)
57
+ Coverage.suspend if Coverage.running?
58
+ hits = []
59
+ snapshot.each do |path, data|
60
+ file = @canonical[path]
61
+ record_branches(file, data) { |span| hits << [file, span] } if @files.include?(file)
62
+ end
63
+ hits
64
+ ensure
65
+ Coverage.resume if Coverage.state == :suspended
66
+ @line_hits.resume
67
+ @calls.resume
68
+ end
69
+
70
+ # Both tracers are paused while the delta is processed, so the
71
+ # recorder's own work is never attributed to a test.
72
+ def each_hit
73
+ lines = @line_hits.pause.drain
74
+ calls = @calls.pause.drain
75
+ lines.each_pair { |file, numbers| numbers.each { |line| yield @canonical[file], line, :line } }
76
+ calls.each_pair { |path, hits| hits.to_set(&:first).each { |line| yield @canonical[path], line, :method } }
77
+ ensure
78
+ @line_hits.resume
79
+ @calls.resume
80
+ end
81
+ end
82
+ end
83
+ end
@@ -84,8 +84,7 @@ module Saboteur
84
84
  def warn_unreadable(names, diagnostics)
85
85
  return if names.empty? || diagnostics.nil?
86
86
 
87
- shown = names.sort.first(5).join(", ")
88
- shown += ", ..." if names.size > 5
87
+ shown = Text.name_list(names.sort)
89
88
  diagnostics.warn("--since: #{names.size} included untracked file(s) could not be read (vanished, " \
90
89
  "unreadable or replaced), so their subjects are not covered: #{shown}")
91
90
  end
@@ -72,6 +72,22 @@ module Saboteur
72
72
  "#{owner}#{singleton ? '.' : '#'}#{name}"
73
73
  end
74
74
 
75
+ # "path:line" for warnings, relative to the run root (or the full path
76
+ # without one), so a skipped subject can be told apart from a real
77
+ # subject sharing its id (#627).
78
+ def location(root)
79
+ file = root ? @file.delete_prefix("#{root}/") : @file
80
+ "#{file}:#{start_line}"
81
+ end
82
+
83
+ # The gate sentence a scoped run prints when every subject was skipped
84
+ # (#574); the location disambiguates a skipped subject from a real one
85
+ # sharing its id (#627).
86
+ def skipped_gate_sentence(reason, root)
87
+ "saboteur: #{Text.display_safe(id)} (#{Text.display_safe(location(root))}) was skipped (#{reason}), " \
88
+ "so the change under test was not verified"
89
+ end
90
+
75
91
  # The node whose children are the method's statements: the block body
76
92
  # for `define_method(:m) { ... }` (#194), the def body otherwise.
77
93
  def body_node
@@ -3,20 +3,27 @@
3
3
 
4
4
  require "prism"
5
5
  require_relative "subject"
6
+ require_relative "deep_source"
6
7
 
7
8
  module Saboteur
8
9
  # Finds `def` methods in a Ruby file with Prism.
9
10
  #
10
11
  # Included: instance methods and `def self.x` inside a class or module,
11
12
  # defs inside `class << self`, and defs passed to a receiverless call such
12
- # as `private def x`. Skipped: top-level defs, defs nested in defs, and
13
- # `def obj.x` for obj != self. Defs in blocks (`included do`, builders)
13
+ # as `private def x`. Skipped: top-level defs and defs nested in defs.
14
+ # `def Const.m` is found but marked skipped (a constant receiver names an
15
+ # owner saboteur cannot re-evaluate through, #627); `def obj.x` for any
16
+ # other obj is dropped, as before. Defs in blocks (`included do`, builders)
14
17
  # are found but marked skipped ("defined inside a block"), so the report
15
18
  # names them instead of leaving them out - except the four core class
16
19
  # factories: `X = Data.define`, `Struct.new`, `Class.new` or `Module.new`
17
20
  # with a block names X as the owner, and its defs are ordinary subjects
18
- # that re-evaluate through X.class_eval (#290). Any other block, and a
19
- # `A::X = ...` target, keeps the enclosing owner or the placeholder.
21
+ # that re-evaluate through X.class_eval (#290). Known registry DSLs work
22
+ # the same way: `Ohai.plugin(:Network) do` and
23
+ # `Puppet::Type.type(:t).provide :p do` class_eval a class registered
24
+ # under a predictable constant, so their defs re-evaluate through it
25
+ # (#700). Any other block, and a `A::X = ...` target, keeps the
26
+ # enclosing owner or the placeholder.
20
27
  class SubjectFinder
21
28
  Parsed = Data.define(:subjects, :errors)
22
29
  ANONYMOUS_OWNER = "(anonymous block)"
@@ -29,6 +36,8 @@ module Saboteur
29
36
  result = Prism.parse(source, filepath: file)
30
37
  return Parsed.new(subjects: [], errors: result.errors.map(&:message)) if result.failure?
31
38
 
39
+ DeepSource.check!(result.value, file)
40
+
32
41
  frozen = frozen_literals?(result)
33
42
  subjects = []
34
43
  walk(result.value, [], subjects, file: file, source: source, frozen: frozen)
@@ -80,6 +89,10 @@ module Saboteur
80
89
  # through its children.
81
90
  def walk_call(node, nesting, out, **ctx)
82
91
  return walk_heredoc_eval(node, nesting, out, **ctx) if heredoc_eval?(node)
92
+
93
+ dsl_owner = registry_dsl_owner(node)
94
+ return walk_registry_dsl(node, dsl_owner, nesting, out, **ctx) if dsl_owner
95
+
83
96
  return walk_children(node, nesting, out, **ctx) unless call_defined_method?(node)
84
97
 
85
98
  in_sclass = nesting.last&.sclass? || false
@@ -205,6 +218,55 @@ module Saboteur
205
218
  walk(call.block.body, lexical_nesting(nesting) + [Scope.new(kind: :factory, path: node.name.to_s)], out, **ctx)
206
219
  end
207
220
 
221
+ # Registry DSLs whose block class_evals a fresh class registered under a
222
+ # predictable constant (#700): `Ohai.plugin(:Network)` registers
223
+ # Ohai::NamedPlugin::Network, and `Puppet::Type.type(:package).provide
224
+ # :pacman` registers Puppet::Type::Package::ProviderPacman. Like the core
225
+ # class factories (#290) the block's defs re-evaluate through that
226
+ # constant, so they are ordinary subjects. The registry names its class
227
+ # at the top level, so the path restarts at `::` whatever the enclosing
228
+ # scope. A call the registry does not know, or one with a non-literal
229
+ # name, keeps the ordinary "defined inside a block" skip; extend the
230
+ # list here as more frameworks need it.
231
+ def registry_dsl_owner(node)
232
+ return unless node.block.is_a?(Prism::BlockNode)
233
+
234
+ if node.name == :plugin && node.receiver.is_a?(Prism::ConstantReadNode) && node.receiver.name == :Ohai
235
+ name = symbol_argument(node.arguments)
236
+ "::Ohai::NamedPlugin::#{camelize(name)}" if name
237
+ elsif node.name == :provide && (type = puppet_type_call(node.receiver))
238
+ name = symbol_argument(node.arguments)
239
+ "::Puppet::Type::#{camelize(type)}::Provider#{camelize(name)}" if name
240
+ end
241
+ end
242
+
243
+ # `Puppet::Type.type(:package)`: the type name the provider attaches to.
244
+ def puppet_type_call(receiver)
245
+ return unless receiver.is_a?(Prism::CallNode) && receiver.name == :type && receiver.block.nil?
246
+ return unless receiver.receiver.is_a?(Prism::ConstantPathNode) && receiver.receiver.slice == "Puppet::Type"
247
+
248
+ symbol_argument(receiver.arguments)
249
+ end
250
+
251
+ def symbol_argument(arguments)
252
+ first = arguments&.arguments&.first
253
+ first.unescaped if first.is_a?(Prism::SymbolNode)
254
+ end
255
+
256
+ def camelize(name)
257
+ name.split("_").map!(&:capitalize).join
258
+ end
259
+
260
+ # The receiver and arguments stay in the enclosing scope; only the DSL's
261
+ # own block belongs to the registered class. Walked like a factory block
262
+ # (#290): a block nested deeper still marks its defs skipped, and a DSL
263
+ # call that itself sits in a block names the registry class but keeps
264
+ # the skip, since the registration may never run.
265
+ def walk_registry_dsl(node, owner, nesting, out, **ctx)
266
+ (node.compact_child_nodes - [node.block]).each { |child| walk(child, nesting, out, **ctx) }
267
+ walk(node.block.body, lexical_nesting(nesting) + [Scope.new(kind: :factory, path: owner)], out, **ctx)
268
+ end
269
+
208
270
  # Constant-introducing declarations (class/module keywords and factory
209
271
  # assignments) bind on the enclosing lexical scope: factory blocks open
210
272
  # none, so their scopes never join a new constant's path (#339) - unless
@@ -233,8 +295,11 @@ module Saboteur
233
295
 
234
296
  def add_subject(node, nesting, out, file:, source:, frozen:, previous: nil, in_block: false)
235
297
  in_sclass = nesting.last&.sclass? || false
236
- # `def self.x` inside `class << self`, and `def obj.x`, are not subjects.
237
- return unless node.receiver.nil? || (node.receiver.is_a?(Prism::SelfNode) && !in_sclass)
298
+ # `def self.x` inside `class << self` is not a subject. A def with
299
+ # any other explicit receiver goes through the report-it door (#627).
300
+ if node.receiver && !(node.receiver.is_a?(Prism::SelfNode) && !in_sclass)
301
+ return report_receiver_def(node, out, file: file, source: source, frozen: frozen)
302
+ end
238
303
 
239
304
  singleton = in_sclass || !node.receiver.nil?
240
305
  owner = owner_path(nesting)
@@ -248,6 +313,26 @@ module Saboteur
248
313
  out << subject
249
314
  end
250
315
 
316
+ # `def Const.m` defines a singleton on the named constant; re-evaluating
317
+ # it through the enclosing owner would not redefine it. Emit it as a
318
+ # skipped subject so the report names it (#627) instead of the run
319
+ # reading as "nothing to mutate". A receiver saboteur cannot name (a
320
+ # local, a call result) stays out, as before.
321
+ def report_receiver_def(node, out, file:, source:, frozen:)
322
+ # Ruby only allows a bare constant here (`def A::B.m` is a syntax
323
+ # error), so the receiver is a ConstantReadNode or nothing we name.
324
+ receiver = node.receiver
325
+ return unless receiver.is_a?(Prism::ConstantReadNode)
326
+
327
+ owner = receiver.name.to_s
328
+
329
+ subject = Subject.new(name: node.name, owner: owner, singleton: true, sclass: false,
330
+ file: file, node: node, file_source: source, nesting: [],
331
+ frozen_literals: frozen, sig_span: nil)
332
+ subject.skip_reason = "constant-receiver def"
333
+ out << subject
334
+ end
335
+
251
336
  # The byte span of a `sig { ... }` or `T.sig { ... }` call on the lines
252
337
  # right before the def, when there is one.
253
338
  def sig_span(previous)
data/lib/saboteur/text.rb CHANGED
@@ -11,6 +11,37 @@ module Saboteur
11
11
  module Text
12
12
  module_function
13
13
 
14
+ # A list for a warning or note: the first five items, then "and N more".
15
+ # One rule for every message that names files, subjects or specs (#332).
16
+ # Items are repo-controlled text, so each is display_safe (#834).
17
+ def name_list(items, limit: 5)
18
+ shown = items.first(limit).map { |item| display_safe(item.to_s) }.join(", ")
19
+ rest = items.size - limit
20
+ rest.positive? ? "#{shown} and #{rest} more" : shown
21
+ end
22
+
23
+ # Display-safe single line for text a repository controls (file names,
24
+ # config patterns, subject ids) before it joins a warning CI prints
25
+ # (#834): control characters become \xNN escapes so an injected newline
26
+ # cannot start a fresh line, a "##[" anywhere (Azure DevOps) loses its
27
+ # bracket, and a "::" starting the text (a GitHub workflow command -
28
+ # the runner trims leading whitespace first) loses its first colon.
29
+ # Other colons and brackets, as in "Saboteur::Error", stay as they are.
30
+ # Invalid UTF-8 is scrubbed first, as everywhere Text renders outside bytes.
31
+ def display_safe(text)
32
+ escaped = utf8(text).gsub(/[\x00-\x1f\x7f\u0080-\u009f]/) { |char| format("\\x%02x", char.ord) }
33
+ escaped.gsub("##[", "##\\x5b").sub(/\A[[:space:]]*\K:(?=:)/) { "\\x3a" }
34
+ end
35
+
36
+ # display_safe for a message that is meant to span lines (an action line,
37
+ # then indented detail lines). Each line is made safe on its own, so a
38
+ # line of repository text that starts "::error::" after an injected
39
+ # newline loses its colon, while the message's own line breaks stay.
40
+ # Idempotent: escaping an already escaped message changes nothing.
41
+ def display_safe_lines(text)
42
+ utf8(text).lines.map { |line| display_safe(line.delete_suffix("\n")) + (line.end_with?("\n") ? "\n" : "") }.join
43
+ end
44
+
14
45
  # Lossy: bytes that are not valid UTF-8 become the replacement
15
46
  # character. For log and message display only - never feed the result
16
47
  # back into filesystem, cache or protocol identity: scrubbing rewrites
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Saboteur
5
- VERSION = "0.8.0"
5
+ VERSION = "0.9.0"
6
6
  end
@@ -70,9 +70,14 @@ module Saboteur
70
70
  end
71
71
 
72
72
  # -z implies --porcelain=v1, and status takes no revisions, so the
73
- # pathspecs need no "--" in front.
73
+ # pathspecs need no "--" in front. Files are excluded literally: a
74
+ # plain :(exclude) pathspec is a glob, and a bracketed tool file name
75
+ # like "g/[ab].gemfile" would otherwise hide real untracked files
76
+ # (#638). Directory entries keep the plain dir form.
74
77
  def status_command
75
- excluded = @ignored.map { |path| ":(exclude)#{path}" }
78
+ excluded = @ignored.map do |path|
79
+ path.end_with?("/") ? ":(exclude)#{path}" : ":(exclude,literal)#{path}"
80
+ end
76
81
  ["git", "status", "-z", "--untracked-files=all", ".", *excluded]
77
82
  end
78
83
  end
data/lib/saboteur.rb CHANGED
@@ -44,13 +44,17 @@ module Saboteur
44
44
  end
45
45
 
46
46
  require_relative "saboteur/coverage_reads"
47
+ require_relative "saboteur/method_calls"
48
+ require_relative "saboteur/line_hits"
47
49
  require_relative "saboteur/hooks"
48
50
  require_relative "saboteur/mutation_source/base"
49
51
  require_relative "saboteur/mutation_source/builtin"
50
52
  require_relative "saboteur/integration/base"
51
53
  require_relative "saboteur/subject"
54
+ require_relative "saboteur/deep_source"
52
55
  require_relative "saboteur/refinement_activations"
53
56
  require_relative "saboteur/subject_finder"
57
+ require_relative "saboteur/attribute_finder"
54
58
  require_relative "saboteur/constant_subject"
55
59
  require_relative "saboteur/constant_subject_finder"
56
60
  require_relative "saboteur/constant_reads"
@@ -63,6 +67,8 @@ require_relative "saboteur/execution/supervisor"
63
67
  require_relative "saboteur/execution/reevaluator"
64
68
  require_relative "saboteur/execution/wrapper"
65
69
  require_relative "saboteur/execution/runner"
70
+ require_relative "saboteur/execution/bundle_gemfile_pin"
71
+ require_relative "saboteur/execution/gemfile_path_sources"
66
72
  require_relative "saboteur/execution/external_runner"
67
73
  require_relative "saboteur/execution/worker_pool"
68
74
  require_relative "saboteur/execution/fork_readiness"
@@ -71,6 +77,7 @@ require_relative "saboteur/execution/seatbelt"
71
77
  require_relative "saboteur/selection/coverage_map"
72
78
  require_relative "saboteur/selection/external_test_map"
73
79
  require_relative "saboteur/selection/recorder"
80
+ require_relative "saboteur/selection/trace_recorder"
74
81
  require_relative "saboteur/selection/git_diff"
75
82
  require_relative "saboteur/selection/source_scope"
76
83
  require_relative "saboteur/result"
@@ -81,6 +88,7 @@ require_relative "saboteur/ignore_list"
81
88
  require_relative "saboteur/frameworks/rails"
82
89
  require_relative "saboteur/reporter/diff"
83
90
  require_relative "saboteur/reporter/findings"
91
+ require_relative "saboteur/reporter/review_comments"
84
92
  require_relative "saboteur/reporter/agent"
85
93
  require_relative "saboteur/working_tree"
86
94
  require_relative "saboteur/dirty_tree_warning"
@@ -89,4 +97,5 @@ require_relative "saboteur/reporter/terminal"
89
97
  require_relative "saboteur/reporter/stryker"
90
98
  require_relative "saboteur/reporter/survivor_classification"
91
99
  require_relative "saboteur/reporter/html"
100
+ require_relative "saboteur/environment_hints"
92
101
  require_relative "saboteur/engine"