ripr 0.1.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +146 -0
- data/exe/ripr +6 -0
- data/lib/ripr/accept_ledger.rb +57 -0
- data/lib/ripr/cli.rb +160 -0
- data/lib/ripr/config.rb +102 -0
- data/lib/ripr/core/analyzer.rb +179 -0
- data/lib/ripr/core/classifier.rb +18 -0
- data/lib/ripr/core/instrumenter.rb +110 -0
- data/lib/ripr/core/operators.rb +41 -0
- data/lib/ripr/core/reuse_planner.rb +20 -0
- data/lib/ripr/engine/baseline_cache.rb +95 -0
- data/lib/ripr/engine/child.rb +103 -0
- data/lib/ripr/engine/result_cache.rb +83 -0
- data/lib/ripr/engine/runner.rb +224 -0
- data/lib/ripr/engine/scheduler.rb +81 -0
- data/lib/ripr/git.rb +58 -0
- data/lib/ripr/integration/minitest.rb +72 -0
- data/lib/ripr/integration/rspec.rb +88 -0
- data/lib/ripr/loader.rb +165 -0
- data/lib/ripr/reporters.rb +139 -0
- data/lib/ripr/runtime.rb +205 -0
- data/lib/ripr/snapshot.rb +41 -0
- data/lib/ripr/version.rb +5 -0
- data/lib/ripr.rb +8 -0
- data/schema/agent-v1.json +74 -0
- data/skills/mutation-test-loop/SKILL.md +28 -0
- metadata +94 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "cgi"
|
|
5
|
+
require "fileutils"
|
|
6
|
+
require "pathname"
|
|
7
|
+
require_relative "core/classifier"
|
|
8
|
+
|
|
9
|
+
module Ripr
|
|
10
|
+
module Reporters
|
|
11
|
+
ACTIONS = { "not_reached" => "add_test", "not_infected" => "add_input", "not_detected" => "strengthen_assertion" }.freeze
|
|
12
|
+
HINTS = {
|
|
13
|
+
"not_reached" => "Add a test that executes this method and branch.",
|
|
14
|
+
"not_infected" => "Add boundary inputs that change the mutated expression's value.",
|
|
15
|
+
"not_detected" => "Assert the changed return value or side effect. Accept only if the mutation is equivalent."
|
|
16
|
+
}.freeze
|
|
17
|
+
LOAD_NOTE = "Reached outside a tracked test, possibly during loading or in a background thread. " \
|
|
18
|
+
"Switching cannot change effects already computed before test execution."
|
|
19
|
+
MTE_STATUSES = { "killed" => "Killed", "timeout" => "Timeout", "error" => "RuntimeError", "not_reached" => "NoCoverage",
|
|
20
|
+
"not_infected" => "Survived", "not_detected" => "Survived", "accepted" => "Ignored",
|
|
21
|
+
"static" => "Ignored", "invalid" => "CompileError", "planned" => "Pending" }.freeze
|
|
22
|
+
|
|
23
|
+
def self.agent(results, run, summary = Core::Classifier.summary(results))
|
|
24
|
+
gaps = results.filter_map do |mutant|
|
|
25
|
+
status = mutant.fetch("status")
|
|
26
|
+
next unless ACTIONS.key?(status)
|
|
27
|
+
|
|
28
|
+
id = mutant.fetch("id")
|
|
29
|
+
hint = HINTS.fetch(status)
|
|
30
|
+
observed = mutant.fetch("observed", [])
|
|
31
|
+
hint += " Observed operands: #{JSON.generate(observed)}." if status == "not_infected" && !observed.empty?
|
|
32
|
+
hint += " #{LOAD_NOTE}" if mutant["load_reached"]
|
|
33
|
+
mutant.slice("id", "full_id", "location", "subject", "operator", "original", "mutated", "observed", "covering_tests",
|
|
34
|
+
"load_reached")
|
|
35
|
+
.merge("kind" => status, "action" => ACTIONS.fetch(status), "hint" => hint,
|
|
36
|
+
"rerun" => "ripr --only #{id}", "accept" => "ripr accept #{id} --reason \"...\"")
|
|
37
|
+
end
|
|
38
|
+
{ "schema" => "ripr.agent/v1", "run" => run, "summary" => summary, "gaps" => gaps }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.mte(results, sources, thresholds)
|
|
42
|
+
files = sources.to_h do |path, source|
|
|
43
|
+
mutants = results.select { |m| m.fetch("location").fetch("file") == path }.map do |mutant|
|
|
44
|
+
location = mutant.fetch("location")
|
|
45
|
+
reason = mutant["accepted"] || mutant.fetch("status")
|
|
46
|
+
reason += ". #{LOAD_NOTE}" if mutant["load_reached"]
|
|
47
|
+
{ "id" => mutant.fetch("id"), "mutatorName" => mutant.fetch("operator"), "replacement" => mutant.fetch("mutated"),
|
|
48
|
+
"status" => MTE_STATUSES.fetch(mutant.fetch("status")), "statusReason" => reason,
|
|
49
|
+
"location" => { "start" => { "line" => location.fetch("line"), "column" => location.fetch("column") },
|
|
50
|
+
"end" => { "line" => location.fetch("end_line"), "column" => location.fetch("end_column") } } }
|
|
51
|
+
end
|
|
52
|
+
[path, { "language" => "ruby", "source" => source, "mutants" => mutants }]
|
|
53
|
+
end
|
|
54
|
+
{ "schemaVersion" => "2", "thresholds" => thresholds.slice("high", "low"), "files" => files }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.write(results, runner, config, stdout: $stdout)
|
|
58
|
+
summary = Core::Classifier.summary(results)
|
|
59
|
+
summary["static"] += runner.static
|
|
60
|
+
run = { "since" => config[:since], "scope" => config[:scope], "framework" => runner.framework, "metrics" => runner.metrics }
|
|
61
|
+
config[:reporters].each do |name|
|
|
62
|
+
case name
|
|
63
|
+
when "text"
|
|
64
|
+
stdout.puts "Killed #{summary['killed']} · Survived #{summary['survived']} " \
|
|
65
|
+
"(#{summary['not_infected']} not infected) · Score #{summary['score']}%"
|
|
66
|
+
stdout.puts "Reused #{runner.metrics['reused']} · Baseline #{runner.metrics['baseline_tests_run']} tests · " \
|
|
67
|
+
"#{summary['static']} static variants excluded"
|
|
68
|
+
results.each do |mutant|
|
|
69
|
+
next unless ACTIONS.key?(mutant["status"]) || config[:dry_run]
|
|
70
|
+
|
|
71
|
+
location = mutant.fetch("location")
|
|
72
|
+
stdout.puts "#{mutant['status'].tr('_', ' ')} #{location['file']}:#{location['line']}:#{location['column']} " \
|
|
73
|
+
"#{mutant['original'].inspect} → #{mutant['mutated'].inspect} id=#{mutant['id']}"
|
|
74
|
+
stdout.puts " observed: #{JSON.generate(mutant['observed'])}" unless mutant.fetch("observed", []).empty?
|
|
75
|
+
stdout.puts " #{LOAD_NOTE}" if mutant["load_reached"]
|
|
76
|
+
end
|
|
77
|
+
when "agent"
|
|
78
|
+
stdout.puts JSON.generate(agent(results, run, summary))
|
|
79
|
+
when "github"
|
|
80
|
+
results.each do |mutant|
|
|
81
|
+
next unless ACTIONS.key?(mutant["status"])
|
|
82
|
+
|
|
83
|
+
location = mutant.fetch("location")
|
|
84
|
+
path = location.fetch("file")
|
|
85
|
+
if ENV["GITHUB_WORKSPACE"]
|
|
86
|
+
path = Pathname.new(File.expand_path(path)).relative_path_from(Pathname.new(ENV.fetch("GITHUB_WORKSPACE"))).to_s
|
|
87
|
+
end
|
|
88
|
+
file = annotation(path, property: true)
|
|
89
|
+
message = "#{mutant['original']} → #{mutant['mutated']}"
|
|
90
|
+
message += ". #{LOAD_NOTE}" if mutant["load_reached"]
|
|
91
|
+
message = annotation(message)
|
|
92
|
+
stdout.puts "::warning file=#{file},line=#{location['line']},col=#{location['column']}," \
|
|
93
|
+
"title=ripr #{mutant['status']}::#{message}"
|
|
94
|
+
end
|
|
95
|
+
when "json", "html"
|
|
96
|
+
FileUtils.mkdir_p(config[:report_dir])
|
|
97
|
+
report = mte(results, runner.sources, config[:thresholds])
|
|
98
|
+
File.write(File.join(config[:report_dir], "mutation.json"), "#{JSON.pretty_generate(report)}\n")
|
|
99
|
+
File.write(File.join(config[:report_dir], "index.html"), html(report)) if name == "html"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
summary
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def self.annotation(value, property: false)
|
|
106
|
+
escaped = value.gsub("%", "%25").gsub("\r", "%0D").gsub("\n", "%0A")
|
|
107
|
+
property ? escaped.gsub(":", "%3A").gsub(",", "%2C") : escaped
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def self.html(report)
|
|
111
|
+
data = JSON.generate(report).gsub("<") { "\\u003c" }
|
|
112
|
+
rows = report.fetch("files").flat_map do |path, file|
|
|
113
|
+
file.fetch("mutants").map do |mutant|
|
|
114
|
+
values = [path, mutant.fetch("location").fetch("start").fetch("line"), mutant["mutatorName"],
|
|
115
|
+
mutant["statusReason"], mutant["replacement"]]
|
|
116
|
+
"<tr>#{values.map { |v| "<td>#{CGI.escapeHTML(v.to_s)}</td>" }.join}</tr>"
|
|
117
|
+
end
|
|
118
|
+
end.join
|
|
119
|
+
<<~HTML
|
|
120
|
+
<!doctype html>
|
|
121
|
+
<html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width">
|
|
122
|
+
<title>ripr mutation report</title>
|
|
123
|
+
<style>body{font:16px system-ui;margin:2rem;color:#20252b}table{border-collapse:collapse;width:100%}th,td{padding:.6rem;text-align:left;border-bottom:1px solid #ccc}td:last-child{white-space:pre-wrap;font-family:monospace}caption{font-size:1.5rem;text-align:left;margin-bottom:1rem}</style>
|
|
124
|
+
<mutation-test-report-app id="interactive-report" hidden></mutation-test-report-app>
|
|
125
|
+
<table id="fallback-report"><caption>ripr mutation report</caption><thead><tr><th>File</th><th>Line</th><th>Operator</th><th>Status</th><th>Replacement</th></tr></thead><tbody>#{rows}</tbody></table>
|
|
126
|
+
<script type="application/json" id="mutation-report">#{data}</script>
|
|
127
|
+
<script src="https://cdn.jsdelivr.net/npm/mutation-testing-elements@3.9.0/dist/mutation-test-elements.js" integrity="sha384-/dXYuoYRvO6rJ0FNtdKR+Hmq5iGrkkSDpc/TGgbSoReog26ZqhLhpSt4l+0Wwew2" crossorigin="anonymous" async></script>
|
|
128
|
+
<script>
|
|
129
|
+
customElements.whenDefined('mutation-test-report-app').then(() => {
|
|
130
|
+
const app = document.getElementById('interactive-report');
|
|
131
|
+
app.report = JSON.parse(document.getElementById('mutation-report').textContent);
|
|
132
|
+
app.hidden = false;
|
|
133
|
+
document.getElementById('fallback-report').hidden = true;
|
|
134
|
+
});
|
|
135
|
+
</script></html>
|
|
136
|
+
HTML
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
data/lib/ripr/runtime.rb
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ripr
|
|
4
|
+
module Value
|
|
5
|
+
TYPES = [Integer, Float, Rational, String, Symbol, NilClass, TrueClass, FalseClass].freeze
|
|
6
|
+
PROBE_METHODS = %i[>= > <= < <=> == != + - * / % coerce method_missing ! encoding [] encode to_s].freeze
|
|
7
|
+
CLASS_OF = Object.instance_method(:class)
|
|
8
|
+
SINGLETON_METHODS = Object.instance_method(:singleton_methods)
|
|
9
|
+
PRIVATE_METHODS = Object.instance_method(:private_methods)
|
|
10
|
+
|
|
11
|
+
module_function
|
|
12
|
+
|
|
13
|
+
def pure?(value)
|
|
14
|
+
klass = CLASS_OF.bind_call(value)
|
|
15
|
+
TYPES.include?(klass) && SINGLETON_METHODS.bind_call(value).empty? &&
|
|
16
|
+
!PRIVATE_METHODS.bind_call(value, false).intersect?(PROBE_METHODS) && core_ops_intact?(klass)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def core_ops_intact?(klass)
|
|
20
|
+
PROBE_METHODS.all? do |name|
|
|
21
|
+
next true unless klass.method_defined?(name) || klass.private_method_defined?(name)
|
|
22
|
+
|
|
23
|
+
method = klass.instance_method(name)
|
|
24
|
+
method.source_location.nil? && method.original_name == name
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def same?(left, right)
|
|
29
|
+
klass = CLASS_OF.bind_call(left)
|
|
30
|
+
return false unless klass == CLASS_OF.bind_call(right) && pure?(left) && pure?(right)
|
|
31
|
+
return [left].pack("G") == [right].pack("G") if klass == Float
|
|
32
|
+
return left.encoding == right.encoding && left == right if klass == String
|
|
33
|
+
|
|
34
|
+
left == right
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def sample(value)
|
|
38
|
+
case CLASS_OF.bind_call(value).name
|
|
39
|
+
when "String" then value[0, 32].encode(Encoding::UTF_8, invalid: :replace, undef: :replace)
|
|
40
|
+
when "Symbol", "Rational" then value.to_s
|
|
41
|
+
when "Float" then value < Float::INFINITY && value > -Float::INFINITY ? value : value.to_s
|
|
42
|
+
else value
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class Probe
|
|
48
|
+
def initialize(site_table, samples: true)
|
|
49
|
+
@site_table = site_table
|
|
50
|
+
@record_samples = samples
|
|
51
|
+
@reach = {}
|
|
52
|
+
@infect = {}
|
|
53
|
+
@samples = {}
|
|
54
|
+
@load_reached = []
|
|
55
|
+
@mutex = Mutex.new
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def reach(site)
|
|
59
|
+
test = R.current_test
|
|
60
|
+
return if test && !@site_table.key?(site)
|
|
61
|
+
|
|
62
|
+
@mutex.synchronize do
|
|
63
|
+
record_reach(site, test)
|
|
64
|
+
record_infection(site, test) if test
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def observe_bin(site, left, right, original, pure = true) # rubocop:disable Style/OptionalBooleanParameter
|
|
69
|
+
variants = @site_table[site]
|
|
70
|
+
test = R.current_test
|
|
71
|
+
return if test && !variants
|
|
72
|
+
|
|
73
|
+
@mutex.synchronize do
|
|
74
|
+
record_reach(site, test)
|
|
75
|
+
safe_operands = nil
|
|
76
|
+
if variants && @record_samples && (@samples[site]&.size || 0) < 3
|
|
77
|
+
safe_operands = Value.pure?(left) && Value.pure?(right)
|
|
78
|
+
sample_operands(site, left, right) if safe_operands
|
|
79
|
+
end
|
|
80
|
+
return unless test
|
|
81
|
+
|
|
82
|
+
variants.each.with_index(1) do |id, variant|
|
|
83
|
+
next if @infect[id]&.include?(test)
|
|
84
|
+
|
|
85
|
+
safe_operands = Value.pure?(left) && Value.pure?(right) if pure && safe_operands.nil?
|
|
86
|
+
same = pure && safe_operands && begin
|
|
87
|
+
Value.same?(original, yield(variant))
|
|
88
|
+
rescue StandardError
|
|
89
|
+
false
|
|
90
|
+
end
|
|
91
|
+
record(@infect, id, test) unless same
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def observe_ret(site, value)
|
|
97
|
+
test = R.current_test
|
|
98
|
+
return if test && !@site_table.key?(site)
|
|
99
|
+
|
|
100
|
+
@mutex.synchronize do
|
|
101
|
+
record_reach(site, test)
|
|
102
|
+
record_infection(site, test) if test && Value::CLASS_OF.bind_call(value) != NilClass
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def snapshot
|
|
107
|
+
@mutex.synchronize do
|
|
108
|
+
{ "reach" => @reach.transform_values(&:dup), "infect" => @infect.transform_values(&:dup),
|
|
109
|
+
"samples" => @samples.transform_values { |pairs| pairs.map(&:dup) }, "load_reached" => @load_reached.dup }
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
private
|
|
114
|
+
|
|
115
|
+
def record_reach(site, test)
|
|
116
|
+
if test
|
|
117
|
+
record(@reach, site, test)
|
|
118
|
+
else
|
|
119
|
+
@load_reached << site unless @load_reached.include?(site)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def record_infection(site, test)
|
|
124
|
+
@site_table.fetch(site).each { |id| record(@infect, id, test) }
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def record(table, key, test)
|
|
128
|
+
entries = (table[key] ||= [])
|
|
129
|
+
entries << test unless entries.include?(test)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def sample_operands(site, left, right)
|
|
133
|
+
pairs = (@samples[site] ||= [])
|
|
134
|
+
pair = [Value.sample(left), Value.sample(right)]
|
|
135
|
+
pairs << pair unless pairs.include?(pair)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
module R
|
|
140
|
+
class << self
|
|
141
|
+
attr_accessor :probe
|
|
142
|
+
|
|
143
|
+
def configure(site_table, samples: true)
|
|
144
|
+
reset
|
|
145
|
+
@site_table = site_table
|
|
146
|
+
@samples = samples
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def reset
|
|
150
|
+
@active_site = nil
|
|
151
|
+
@active_variant = 0
|
|
152
|
+
@probe = nil
|
|
153
|
+
self.current_test = nil
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def current_test
|
|
157
|
+
Thread.current.thread_variable_get(:ripr_current_test)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def current_test=(test)
|
|
161
|
+
Thread.current.thread_variable_set(:ripr_current_test, test)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def activate(site, variant)
|
|
165
|
+
@active_site = site
|
|
166
|
+
@active_variant = variant
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def bin(site, left, right, pure = true) # rubocop:disable Style/OptionalBooleanParameter
|
|
170
|
+
if (probe = @probe)
|
|
171
|
+
original = begin
|
|
172
|
+
yield(left, right, 0)
|
|
173
|
+
rescue Exception # rubocop:disable Lint/RescueException -- Record caught test exceptions without changing their propagation.
|
|
174
|
+
probe.reach(site)
|
|
175
|
+
raise
|
|
176
|
+
end
|
|
177
|
+
probe.observe_bin(site, left, right, original, pure) { |variant| yield(left, right, variant) }
|
|
178
|
+
original
|
|
179
|
+
else
|
|
180
|
+
yield(left, right, site == @active_site ? @active_variant : 0)
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def lit(site, *values)
|
|
185
|
+
@probe&.reach(site)
|
|
186
|
+
values[site == @active_site ? @active_variant : 0]
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def cond(site, value)
|
|
190
|
+
@probe&.reach(site)
|
|
191
|
+
site == @active_site ? !value : value
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def ret(site, value)
|
|
195
|
+
@probe&.observe_ret(site, value)
|
|
196
|
+
site == @active_site ? nil : value
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def on?(site)
|
|
200
|
+
@probe&.reach(site)
|
|
201
|
+
site == @active_site
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "json"
|
|
5
|
+
require "tempfile"
|
|
6
|
+
|
|
7
|
+
module Ripr
|
|
8
|
+
class Snapshot
|
|
9
|
+
VERSION = 2
|
|
10
|
+
|
|
11
|
+
def initialize(path = ".ripr/snapshot.json")
|
|
12
|
+
@path = File.expand_path(path)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def read
|
|
16
|
+
return {} unless File.file?(@path)
|
|
17
|
+
|
|
18
|
+
data = JSON.parse(File.read(@path))
|
|
19
|
+
unless data.is_a?(Hash) && data["version"] == VERSION && data["mutants"].is_a?(Hash) && data["mutants"].values.all?(Hash)
|
|
20
|
+
warn "ripr: ignoring unsupported snapshot #{@path}"
|
|
21
|
+
return {}
|
|
22
|
+
end
|
|
23
|
+
data
|
|
24
|
+
rescue JSON::ParserError
|
|
25
|
+
warn "ripr: ignoring corrupt snapshot #{@path}"
|
|
26
|
+
{}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def write(data)
|
|
30
|
+
directory = File.dirname(@path)
|
|
31
|
+
FileUtils.mkdir_p(directory)
|
|
32
|
+
Tempfile.create(["snapshot-", ".json"], directory) do |file|
|
|
33
|
+
file.write(JSON.generate(data))
|
|
34
|
+
file.flush
|
|
35
|
+
file.fsync
|
|
36
|
+
file.close
|
|
37
|
+
File.rename(file.path, @path)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/ripr/version.rb
ADDED
data/lib/ripr.rb
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "ripr.agent/v1",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"required": ["schema", "run", "summary", "gaps"],
|
|
6
|
+
"properties": {
|
|
7
|
+
"schema": {"const": "ripr.agent/v1"},
|
|
8
|
+
"run": {
|
|
9
|
+
"type": "object",
|
|
10
|
+
"required": ["since", "scope", "framework"],
|
|
11
|
+
"properties": {
|
|
12
|
+
"since": {"type": ["string", "null"]},
|
|
13
|
+
"scope": {"enum": ["node", "method"]},
|
|
14
|
+
"framework": {"enum": ["minitest", "rspec", null]}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"summary": {
|
|
18
|
+
"type": "object",
|
|
19
|
+
"required": ["killed", "timeout", "error", "not_reached", "not_infected", "not_detected", "accepted", "score"],
|
|
20
|
+
"properties": {
|
|
21
|
+
"score": {"type": "number", "minimum": 0, "maximum": 100}
|
|
22
|
+
},
|
|
23
|
+
"additionalProperties": {"type": "number", "minimum": 0}
|
|
24
|
+
},
|
|
25
|
+
"gaps": {
|
|
26
|
+
"type": "array",
|
|
27
|
+
"items": {
|
|
28
|
+
"type": "object",
|
|
29
|
+
"required": ["id", "full_id", "kind", "action", "hint", "location", "subject", "operator", "original", "mutated", "observed", "covering_tests", "rerun", "accept"],
|
|
30
|
+
"properties": {
|
|
31
|
+
"id": {"type": "string", "pattern": "^[a-f0-9]{10}$"},
|
|
32
|
+
"full_id": {"type": "string"},
|
|
33
|
+
"kind": {"enum": ["not_reached", "not_infected", "not_detected"]},
|
|
34
|
+
"action": {"enum": ["add_test", "add_input", "strengthen_assertion"]},
|
|
35
|
+
"hint": {"type": "string"},
|
|
36
|
+
"load_reached": {"type": "boolean"},
|
|
37
|
+
"location": {
|
|
38
|
+
"type": "object",
|
|
39
|
+
"required": ["file", "line", "column"],
|
|
40
|
+
"properties": {
|
|
41
|
+
"file": {"type": "string"},
|
|
42
|
+
"line": {"type": "integer", "minimum": 1},
|
|
43
|
+
"column": {"type": "integer", "minimum": 1}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"subject": {"type": "string"},
|
|
47
|
+
"operator": {"type": "string"},
|
|
48
|
+
"original": {"type": "string"},
|
|
49
|
+
"mutated": {"type": "string"},
|
|
50
|
+
"observed": {"type": "array", "maxItems": 3, "items": {"type": "array"}},
|
|
51
|
+
"covering_tests": {
|
|
52
|
+
"type": "array",
|
|
53
|
+
"items": {
|
|
54
|
+
"type": "object",
|
|
55
|
+
"required": ["id", "file", "line"],
|
|
56
|
+
"properties": {
|
|
57
|
+
"id": {"type": "string"},
|
|
58
|
+
"file": {"type": "string"},
|
|
59
|
+
"line": {"type": "integer", "minimum": 1}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"rerun": {"type": "string"},
|
|
64
|
+
"accept": {"type": "string"}
|
|
65
|
+
},
|
|
66
|
+
"allOf": [
|
|
67
|
+
{"if": {"properties": {"kind": {"const": "not_reached"}}}, "then": {"properties": {"action": {"const": "add_test"}}}},
|
|
68
|
+
{"if": {"properties": {"kind": {"const": "not_infected"}}}, "then": {"properties": {"action": {"const": "add_input"}}}},
|
|
69
|
+
{"if": {"properties": {"kind": {"const": "not_detected"}}}, "then": {"properties": {"action": {"const": "strengthen_assertion"}}}}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mutation-test-loop
|
|
3
|
+
description: Improve Ruby tests using ripr mutation diagnostics, or triage ripr not_reached, not_infected, and not_detected results.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Improve tests with ripr
|
|
7
|
+
|
|
8
|
+
Run `bundle exec ripr --since origin/main --reporter agent` from the project root.
|
|
9
|
+
Use `--full` for a complete audit or when no suitable Git reference exists.
|
|
10
|
+
A baseline failure must be fixed before interpreting mutation results.
|
|
11
|
+
|
|
12
|
+
For each entry in `gaps`, read the implementation and the listed tests, then follow its `action`:
|
|
13
|
+
|
|
14
|
+
- `add_test`: exercise the method and branch at `location`.
|
|
15
|
+
- `add_input`: use `original`, `mutated`, and `observed` to find an input that changes the expression. For `age >= 18` becoming `age > 18`, test age 18 when only 20 and 10 were observed.
|
|
16
|
+
- `strengthen_assertion`: assert a return value or side effect that belongs to the intended behavior. Infection can also fail to propagate, so inspect the surrounding code before adding an assertion.
|
|
17
|
+
|
|
18
|
+
After a focused test change, run `bundle exec ripr --only ID --reporter agent` using the gap's ID.
|
|
19
|
+
Confirm that the mutant is killed, and run the project's normal tests.
|
|
20
|
+
Keep implementation changes for separately demonstrated bugs; strengthen tests against the existing intended behavior.
|
|
21
|
+
|
|
22
|
+
If the mutation is equivalent under the documented specification, explain why and use
|
|
23
|
+
`bundle exec ripr accept ID --reason "specific specification-based reason"`.
|
|
24
|
+
Commit the resulting `ripr.accepted.yml` with the explanation.
|
|
25
|
+
Recheck stale acceptances after a method changes.
|
|
26
|
+
|
|
27
|
+
Finish when each targeted gap is killed or has a justified acceptance, and normal tests pass.
|
|
28
|
+
Report remaining gaps and failures explicitly. Assertions must check behavior; a higher score alone is insufficient justification for a test.
|
metadata
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ripr
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Yudai Takada
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: prism
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.0'
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '3'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '1.0'
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '3'
|
|
32
|
+
description: Find missing inputs and assertions with mutation switching and per-test
|
|
33
|
+
infection probes.
|
|
34
|
+
email:
|
|
35
|
+
- t.yudai92@gmail.com
|
|
36
|
+
executables:
|
|
37
|
+
- ripr
|
|
38
|
+
extensions: []
|
|
39
|
+
extra_rdoc_files: []
|
|
40
|
+
files:
|
|
41
|
+
- CHANGELOG.md
|
|
42
|
+
- LICENSE.txt
|
|
43
|
+
- README.md
|
|
44
|
+
- exe/ripr
|
|
45
|
+
- lib/ripr.rb
|
|
46
|
+
- lib/ripr/accept_ledger.rb
|
|
47
|
+
- lib/ripr/cli.rb
|
|
48
|
+
- lib/ripr/config.rb
|
|
49
|
+
- lib/ripr/core/analyzer.rb
|
|
50
|
+
- lib/ripr/core/classifier.rb
|
|
51
|
+
- lib/ripr/core/instrumenter.rb
|
|
52
|
+
- lib/ripr/core/operators.rb
|
|
53
|
+
- lib/ripr/core/reuse_planner.rb
|
|
54
|
+
- lib/ripr/engine/baseline_cache.rb
|
|
55
|
+
- lib/ripr/engine/child.rb
|
|
56
|
+
- lib/ripr/engine/result_cache.rb
|
|
57
|
+
- lib/ripr/engine/runner.rb
|
|
58
|
+
- lib/ripr/engine/scheduler.rb
|
|
59
|
+
- lib/ripr/git.rb
|
|
60
|
+
- lib/ripr/integration/minitest.rb
|
|
61
|
+
- lib/ripr/integration/rspec.rb
|
|
62
|
+
- lib/ripr/loader.rb
|
|
63
|
+
- lib/ripr/reporters.rb
|
|
64
|
+
- lib/ripr/runtime.rb
|
|
65
|
+
- lib/ripr/snapshot.rb
|
|
66
|
+
- lib/ripr/version.rb
|
|
67
|
+
- schema/agent-v1.json
|
|
68
|
+
- skills/mutation-test-loop/SKILL.md
|
|
69
|
+
homepage: https://github.com/ydah/ripr
|
|
70
|
+
licenses:
|
|
71
|
+
- MIT
|
|
72
|
+
metadata:
|
|
73
|
+
allowed_push_host: https://rubygems.org
|
|
74
|
+
homepage_uri: https://github.com/ydah/ripr
|
|
75
|
+
source_code_uri: https://github.com/ydah/ripr/tree/main
|
|
76
|
+
rubygems_mfa_required: 'true'
|
|
77
|
+
rdoc_options: []
|
|
78
|
+
require_paths:
|
|
79
|
+
- lib
|
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '3.3'
|
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
requirements: []
|
|
91
|
+
rubygems_version: 4.0.20
|
|
92
|
+
specification_version: 4
|
|
93
|
+
summary: Mutation testing with reach and infection diagnostics for Ruby
|
|
94
|
+
test_files: []
|