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
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 8ee24d99a3ad44598daf5f40203fef05c638283795207e46f325e4f5113b7ae9
|
|
4
|
+
data.tar.gz: f7752e018b44b4eaaef0b416fe8854be09ab43f8dfdaac398249a1adb0ecf9bd
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e102c864435fe644bc133ffcb5faded3020bea16f52415553d63a289e5fdf2e5ca0db9ad389a43e0f78af263a4c7e4a6ad17bc40ba25ded0142601db2928dae6
|
|
7
|
+
data.tar.gz: 6869369072382c532daf5298ab70de27cec6149b1556ab496a5bc70f3b3837301495ef7fbc0291f6d90e72d615467d3c4b8df1f8cf2bd45914125f6c6836f949
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yudai Takada
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
<h1 align="center">ripr</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
Diff-driven mutation testing for Ruby that highlights untested code, missing test inputs, and gaps in assertions.
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://github.com/ydah/ripr/actions/workflows/main.yml"><img alt="Ruby CI" src="https://github.com/ydah/ripr/actions/workflows/main.yml/badge.svg?branch=main"></a>
|
|
9
|
+
<a href="#installation"><img alt="CRuby 3.3 and later" src="https://img.shields.io/badge/CRuby-3.3%2B-CC342D"></a>
|
|
10
|
+
<a href="LICENSE.txt"><img alt="MIT license" src="https://img.shields.io/badge/license-MIT-blue"></a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="#installation">Installation</a> ·
|
|
15
|
+
<a href="#quick-start">Quick start</a> ·
|
|
16
|
+
<a href="#reading-the-results">Results</a> ·
|
|
17
|
+
<a href="#configuration">Configuration</a> ·
|
|
18
|
+
<a href="#ci">CI</a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
ripr requires CRuby 3.3 or later on Linux or macOS and a Minitest or RSpec suite. Add ripr to your project's Gemfile.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
gem "ripr", git: "https://github.com/ydah/ripr.git", group: :test, require: false
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Once ripr is available on RubyGems, use `gem "ripr", "~> 0.1", group: :test, require: false`.
|
|
30
|
+
|
|
31
|
+
## Quick start
|
|
32
|
+
|
|
33
|
+
Run a full mutation test from your project's root.
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
bundle install
|
|
37
|
+
bundle exec ripr --full
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
For everyday changes, run against a Git reference.
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
bundle exec ripr --since origin/main
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`--since` selects mutations on lines changed since the merge base, including staged, unstaged, and untracked source changes. Use `--scope method` to include every mutation in a touched method. The score and quality gates apply to the selected mutations.
|
|
47
|
+
|
|
48
|
+
## Reading the results
|
|
49
|
+
|
|
50
|
+
ripr observes an unmodified test run, then runs relevant tests against each mutation. Each gap tells you what to investigate next.
|
|
51
|
+
|
|
52
|
+
| Result | What happened | What to try |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| `not_reached` | No test ran the expression. | Exercise the method and branch. |
|
|
55
|
+
| `not_infected` | Tests ran the expression, and the mutation left its value unchanged for the observed inputs. | Add a boundary case or another input. |
|
|
56
|
+
| `not_detected` | The mutation was exercised and tests still passed. | Check whether the changed value reaches an assertion. |
|
|
57
|
+
|
|
58
|
+
Ages 20 and 10 produce the same results for `age >= 18` and `age > 18`. The text report shows the inputs that reached the comparison.
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
not infected lib/sample.rb:5:5 "age >= 18" → "age > 18" id=9c572228cf
|
|
62
|
+
observed: [[20,18],[10,18]]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Add age 18 to exercise the boundary.
|
|
66
|
+
|
|
67
|
+
When ripr cannot safely compare values during the baseline, it keeps the affected tests in the mutation run. Use `--verify-not-infected` to run the relevant tests against mutations classified as `not_infected`.
|
|
68
|
+
|
|
69
|
+
### Reports
|
|
70
|
+
|
|
71
|
+
The default report is text. Write an HTML report and its `mutation.json` data to `.ripr/report/` with `bundle exec ripr --reporter html`. The interactive viewer requires network access, and the static table works offline.
|
|
72
|
+
|
|
73
|
+
For tools and coding agents, use `bundle exec ripr --since origin/main --reporter agent` to emit [JSON with a suggested action for each gap](schema/agent-v1.json). Keep `agent` as the only stdout reporter when piping JSON. Use `bundle exec ripr --only MUTANT_ID` to rerun a single mutation.
|
|
74
|
+
|
|
75
|
+
Install the [bundled agent skill](skills/mutation-test-loop/SKILL.md) with `bundle exec ripr init-skill`. The default destination is `.claude/skills/mutation-test-loop`. Use `--dir` to choose another directory.
|
|
76
|
+
|
|
77
|
+
### Equivalent mutations
|
|
78
|
+
|
|
79
|
+
Use `bundle exec ripr accept MUTANT_ID --reason "Why the documented behavior makes this equivalent"` to accept a mutation. Track `ripr.accepted.yml` in your project. A change to the method invalidates its acceptance.
|
|
80
|
+
|
|
81
|
+
For source-level exclusions, use `ripr:disable-line` or `ripr:disable-next-line` with an operator and a reason.
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
value >= limit # ripr:disable-line comparison -- The specification excludes the boundary
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Configuration
|
|
88
|
+
|
|
89
|
+
Run `bundle exec ripr init` to generate `.ripr.yml`. ripr looks for source under `lib/` by default and detects Minitest or RSpec. Set the framework and test glob explicitly when needed.
|
|
90
|
+
|
|
91
|
+
```yaml
|
|
92
|
+
include: [lib/**/*.rb]
|
|
93
|
+
exclude: [lib/**/version.rb]
|
|
94
|
+
framework: rspec
|
|
95
|
+
tests: "spec/**/*_spec.rb"
|
|
96
|
+
jobs: auto
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Use `bundle exec ripr --help` for CLI options and `bundle exec ripr list operators` for available mutations. CLI flags override file settings. Ignore `.ripr/` in Git. Use `--full` to bypass cached results, especially after changing external test data or environment variables.
|
|
100
|
+
|
|
101
|
+
## CI
|
|
102
|
+
|
|
103
|
+
For a pull request workflow on GitHub Actions, fetch history for the merge base and install your project's bundle.
|
|
104
|
+
|
|
105
|
+
```yaml
|
|
106
|
+
steps:
|
|
107
|
+
- uses: actions/checkout@v6
|
|
108
|
+
with:
|
|
109
|
+
fetch-depth: 0
|
|
110
|
+
- uses: ruby/setup-ruby@v1
|
|
111
|
+
with:
|
|
112
|
+
ruby-version: "3.3"
|
|
113
|
+
bundler-cache: true
|
|
114
|
+
- run: bundle exec ripr --since origin/main --reporter text --reporter github
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The `github` reporter adds annotations for surviving mutations. The [composite action](action.yml) also caches `.ripr/`. After establishing a baseline, add `--fail-on-survived` or `--threshold 80` to enforce a quality gate.
|
|
118
|
+
|
|
119
|
+
| Exit code | Meaning |
|
|
120
|
+
| --- | --- |
|
|
121
|
+
| 0 | Run completed and any requested quality gates passed. |
|
|
122
|
+
| 1 | Invalid arguments or configuration. |
|
|
123
|
+
| 2 | A quality gate failed. |
|
|
124
|
+
| 3 | Internal execution error. |
|
|
125
|
+
| 4 | Baseline tests failed. |
|
|
126
|
+
|
|
127
|
+
Timeouts count as detected mutations. Errors remain in the score denominator. Accepted, static, and invalid mutations are excluded.
|
|
128
|
+
|
|
129
|
+
## Scope and limitations
|
|
130
|
+
|
|
131
|
+
ripr targets pure Ruby libraries. Start it before loading the source under test. It uses `fork` and CRuby's instruction-sequence loader. Use `RIPR_LOADER=require` for the alternate loader, which rejects wrapped target `load` calls. Configure bootsnap before ripr installs its hook.
|
|
132
|
+
|
|
133
|
+
Mutation sites are inside ordinary method definitions. Class-body and top-level expressions, `define_method` blocks, singleton receivers other than `self`, and detached heredoc interpolation are excluded. Operands of `defined?` stay intact. ripr instruments source in memory.
|
|
134
|
+
|
|
135
|
+
Use deterministic, independent tests. Shared state, time, and thread ordering can invalidate cached observations. If a mutation site runs outside a tracked test, ripr conservatively selects all tests. Mutations cannot change effects already computed while loading. Ractor and complete Rails integration are outside the supported scope.
|
|
136
|
+
|
|
137
|
+
## Development
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
bundle install
|
|
141
|
+
bundle exec rake test
|
|
142
|
+
bundle exec rubocop --cache false
|
|
143
|
+
gem build ripr.gemspec
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Run `bundle exec ruby script/self_mutate.rb` to mutation-test ripr's Core. The project is licensed under the [MIT License](LICENSE.txt).
|
data/exe/ripr
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "tempfile"
|
|
5
|
+
require "time"
|
|
6
|
+
require "yaml"
|
|
7
|
+
require_relative "../ripr"
|
|
8
|
+
|
|
9
|
+
module Ripr
|
|
10
|
+
class AcceptLedger
|
|
11
|
+
def initialize(path = "ripr.accepted.yml")
|
|
12
|
+
@path = File.expand_path(path)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def read
|
|
16
|
+
return [] unless File.file?(@path)
|
|
17
|
+
|
|
18
|
+
data = YAML.safe_load_file(@path, permitted_classes: [], permitted_symbols: [], aliases: false)
|
|
19
|
+
valid = data.is_a?(Array) && data.all? do |entry|
|
|
20
|
+
entry.is_a?(Hash) && %w[full_id method_hash reason].all? { |key| entry[key].is_a?(String) && !entry[key].strip.empty? }
|
|
21
|
+
end
|
|
22
|
+
raise Error, "invalid acceptance ledger #{@path}: expected an array of acceptances" unless valid
|
|
23
|
+
|
|
24
|
+
data
|
|
25
|
+
rescue Psych::Exception => e
|
|
26
|
+
raise Error, "invalid acceptance ledger #{@path}: #{e.message}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def accept(mutant, reason:)
|
|
30
|
+
raise Error, "acceptance reason must not be empty" unless reason.is_a?(String) && !reason.strip.empty?
|
|
31
|
+
|
|
32
|
+
entries = read.reject { |entry| entry["full_id"] == mutant.fetch("full_id") }
|
|
33
|
+
entry = mutant.slice("id", "full_id", "operator", "original", "mutated", "method_hash")
|
|
34
|
+
.merge("reason" => reason, "recorded_at" => Time.now.utc.iso8601)
|
|
35
|
+
entries << entry
|
|
36
|
+
directory = File.dirname(@path)
|
|
37
|
+
FileUtils.mkdir_p(directory)
|
|
38
|
+
Tempfile.create(["accepted-", ".yml"], directory) do |file|
|
|
39
|
+
file.write(YAML.dump(entries))
|
|
40
|
+
file.flush
|
|
41
|
+
file.fsync
|
|
42
|
+
file.close
|
|
43
|
+
File.rename(file.path, @path)
|
|
44
|
+
end
|
|
45
|
+
entry
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def reason_for(mutant)
|
|
49
|
+
entry = read.find { |item| item["full_id"] == mutant["full_id"] && item["method_hash"] == mutant["method_hash"] }
|
|
50
|
+
entry && entry["reason"]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def stale?(mutant)
|
|
54
|
+
read.any? { |entry| entry["full_id"] == mutant["full_id"] && entry["method_hash"] != mutant["method_hash"] }
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
data/lib/ripr/cli.rb
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "optparse"
|
|
4
|
+
require_relative "../ripr"
|
|
5
|
+
require_relative "config"
|
|
6
|
+
require_relative "engine/runner"
|
|
7
|
+
require_relative "reporters"
|
|
8
|
+
require_relative "accept_ledger"
|
|
9
|
+
require_relative "snapshot"
|
|
10
|
+
|
|
11
|
+
module Ripr
|
|
12
|
+
class CLI
|
|
13
|
+
def self.start(arguments = ARGV, stdout: $stdout, stderr: $stderr)
|
|
14
|
+
new(arguments.dup, stdout, stderr).call
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def initialize(arguments, stdout, stderr)
|
|
18
|
+
@arguments = arguments
|
|
19
|
+
@stdout = stdout
|
|
20
|
+
@stderr = stderr
|
|
21
|
+
@overrides = {}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def call
|
|
25
|
+
command = %w[run list init accept init-skill].include?(@arguments.first) ? @arguments.shift : "run"
|
|
26
|
+
@list_kind = @arguments.shift if command == "list" && %w[mutants operators].include?(@arguments.first)
|
|
27
|
+
parser.parse!(@arguments)
|
|
28
|
+
return 0 if @help
|
|
29
|
+
|
|
30
|
+
directory = @arguments.length == 1 && File.directory?(@arguments.first) &&
|
|
31
|
+
(File.directory?(File.join(@arguments.first, "test")) || File.directory?(File.join(@arguments.first, "spec")))
|
|
32
|
+
if directory
|
|
33
|
+
root = @arguments.shift
|
|
34
|
+
return Dir.chdir(root) { execute(command) }
|
|
35
|
+
end
|
|
36
|
+
execute(command)
|
|
37
|
+
rescue OptionParser::ParseError, ArgumentError, Errno::ENOENT => e
|
|
38
|
+
@stderr.puts "ripr: #{e.message}"
|
|
39
|
+
1
|
|
40
|
+
rescue BaselineFailure => e
|
|
41
|
+
@stderr.puts "ripr: #{e.message}"
|
|
42
|
+
4
|
|
43
|
+
rescue StandardError, ScriptError => e
|
|
44
|
+
@stderr.puts "ripr: #{e.class}: #{e.message}"
|
|
45
|
+
@stderr.puts e.backtrace if ENV["RIPR_DEBUG"]
|
|
46
|
+
3
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def parser
|
|
52
|
+
OptionParser.new do |options|
|
|
53
|
+
options.banner = "Usage: ripr [run|list|init|accept|init-skill] [options] [PATHS...]"
|
|
54
|
+
options.on("--since REF") { |v| @overrides[:since] = v }
|
|
55
|
+
options.on("--scope SCOPE") { |v| @overrides[:scope] = v }
|
|
56
|
+
options.on("--framework FRAMEWORK") { |v| @overrides[:framework] = v }
|
|
57
|
+
options.on("--tests GLOB") { |v| (@overrides[:tests] ||= []) << v }
|
|
58
|
+
options.on("-j", "--jobs N", Integer) { |v| @overrides[:jobs] = v }
|
|
59
|
+
options.on("--operators LIST") { |v| @overrides[:operators] = v == "default" ? "default" : v.split(",") }
|
|
60
|
+
options.on("--reporter NAME") { |v| (@overrides[:reporters] ||= []) << v }
|
|
61
|
+
options.on("--report-dir DIR") { |v| @overrides[:report_dir] = v }
|
|
62
|
+
options.on("--only IDS") { |v| @overrides[:only] = v.split(",") }
|
|
63
|
+
options.on("--threshold N", Float) { |v| @overrides[:thresholds] = { "break" => v } }
|
|
64
|
+
options.on("--timeout-factor F", Float) { |v| (@overrides[:timeout] ||= {})["factor"] = v }
|
|
65
|
+
options.on("--timeout-base MS", Float) { |v| (@overrides[:timeout] ||= {})["base_ms"] = v }
|
|
66
|
+
options.on("--seed N", Integer) { |v| @overrides[:seed] = v }
|
|
67
|
+
options.on("--no-samples") { @overrides[:samples] = false }
|
|
68
|
+
%w[full dry-run fail-on-survived verify-not-infected].each do |name|
|
|
69
|
+
options.on("--#{name}") { @overrides[name.tr("-", "_").to_sym] = true }
|
|
70
|
+
end
|
|
71
|
+
options.on("--reason TEXT") { |v| @reason = v }
|
|
72
|
+
options.on("--dir DIR") { |v| @skill_dir = v }
|
|
73
|
+
options.on("--force") { @force = true }
|
|
74
|
+
options.on("--version") do
|
|
75
|
+
@stdout.puts VERSION
|
|
76
|
+
@help = true
|
|
77
|
+
end
|
|
78
|
+
options.on("-h", "--help") do
|
|
79
|
+
@stdout.puts options
|
|
80
|
+
@help = true
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def execute(command)
|
|
86
|
+
config = Config.load(command == "list" ? @overrides.merge(dry_run: true) : @overrides)
|
|
87
|
+
return init if command == "init"
|
|
88
|
+
return init_skill if command == "init-skill"
|
|
89
|
+
return accept(config) if command == "accept"
|
|
90
|
+
|
|
91
|
+
if command == "list" && @list_kind == "operators"
|
|
92
|
+
@stdout.puts Core::Operators::NAMES
|
|
93
|
+
return 0
|
|
94
|
+
end
|
|
95
|
+
raise ArgumentError, "#{command} is not available yet" unless %w[run list].include?(command)
|
|
96
|
+
|
|
97
|
+
runner = Engine::Runner.new(config, @arguments)
|
|
98
|
+
runner.plan
|
|
99
|
+
results = if command == "list"
|
|
100
|
+
runner.mutants.map { |m| m.merge("status" => "planned") }
|
|
101
|
+
else
|
|
102
|
+
runner.call do |done, total|
|
|
103
|
+
@stderr.print "\rripr: mutation workers #{done}/#{total}#{"\n" if done == total}" if @stderr.tty?
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
runner.warnings.each { |message| @stderr.puts "ripr: #{message}" }
|
|
107
|
+
summary = Reporters.write(results, runner, config, stdout: @stdout)
|
|
108
|
+
return 0 if config[:dry_run] || command == "list"
|
|
109
|
+
return 2 if config[:fail_on_survived] && summary.fetch("survived").positive?
|
|
110
|
+
return 2 if config[:thresholds]["break"] && summary.fetch("score") < config[:thresholds].fetch("break")
|
|
111
|
+
|
|
112
|
+
0
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def init
|
|
116
|
+
raise ArgumentError, ".ripr.yml already exists" if File.exist?(".ripr.yml")
|
|
117
|
+
|
|
118
|
+
File.write(".ripr.yml", { "include" => ["lib/**/*.rb"], "exclude" => ["lib/**/version.rb"],
|
|
119
|
+
"framework" => "auto", "scope" => "node", "jobs" => "auto", "operators" => "default",
|
|
120
|
+
"samples" => true }.to_yaml)
|
|
121
|
+
@stdout.puts "Created .ripr.yml"
|
|
122
|
+
0
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def init_skill
|
|
126
|
+
source = File.expand_path("../../skills/mutation-test-loop/SKILL.md", __dir__)
|
|
127
|
+
target = File.join(@skill_dir || ".claude/skills", "mutation-test-loop", "SKILL.md")
|
|
128
|
+
if File.exist?(target) && !@force && File.read(target) != File.read(source)
|
|
129
|
+
raise ArgumentError, "#{target} has changes; use --force to overwrite"
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
FileUtils.mkdir_p(File.dirname(target))
|
|
133
|
+
FileUtils.cp(source, target)
|
|
134
|
+
@stdout.puts "Installed #{target}"
|
|
135
|
+
0
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def accept(config)
|
|
139
|
+
unless @arguments.length == 1 && @reason && !@reason.strip.empty?
|
|
140
|
+
raise ArgumentError,
|
|
141
|
+
"accept requires one mutant ID and --reason TEXT"
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
records = Snapshot.new.read.fetch("mutants", {})
|
|
145
|
+
record = records.values.find { |entry| [entry["id"], entry["full_id"]].include?(@arguments.first) }
|
|
146
|
+
raise ArgumentError, "unknown mutant ID; run ripr first" unless record
|
|
147
|
+
|
|
148
|
+
runner = Engine::Runner.new(config)
|
|
149
|
+
runner.plan
|
|
150
|
+
mutant = runner.mutants.find { |entry| entry["full_id"] == record["full_id"] }
|
|
151
|
+
unless mutant && mutant["method_hash"] == record["method_hash"]
|
|
152
|
+
raise ArgumentError, "mutant source changed; rerun ripr before accepting"
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
AcceptLedger.new.accept(mutant, reason: @reason)
|
|
156
|
+
@stdout.puts "Accepted #{mutant.fetch('id')}"
|
|
157
|
+
0
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
data/lib/ripr/config.rb
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "yaml"
|
|
4
|
+
require "etc"
|
|
5
|
+
require_relative "core/operators"
|
|
6
|
+
|
|
7
|
+
module Ripr
|
|
8
|
+
class Config
|
|
9
|
+
YAML_KEYS = %w[include exclude framework tests scope jobs operators arid_callees thresholds timeout samples].freeze
|
|
10
|
+
DEFAULTS = {
|
|
11
|
+
include: ["lib/**/*.rb"], exclude: ["lib/**/version.rb"], framework: "auto", tests: nil,
|
|
12
|
+
scope: "node", jobs: Etc.nprocessors, operators: Core::Operators::NAMES,
|
|
13
|
+
arid_callees: %w[logger.* puts pp warn], thresholds: { "high" => 80, "low" => 60, "break" => nil },
|
|
14
|
+
timeout: { "factor" => 2.0, "base_ms" => 1000 }, samples: true,
|
|
15
|
+
reporters: ["text"], report_dir: ".ripr/report", since: nil, only: [], full: false,
|
|
16
|
+
dry_run: false, fail_on_survived: false, verify_not_infected: false, seed: 0
|
|
17
|
+
}.freeze
|
|
18
|
+
|
|
19
|
+
def self.load(overrides = {}, path: ".ripr.yml")
|
|
20
|
+
data = File.file?(path) ? YAML.safe_load_file(path, permitted_classes: [], aliases: false) : {}
|
|
21
|
+
data ||= {}
|
|
22
|
+
raise ArgumentError, "#{path} must contain a mapping" unless data.is_a?(Hash)
|
|
23
|
+
|
|
24
|
+
unknown = data.keys.map(&:to_s) - YAML_KEYS
|
|
25
|
+
raise ArgumentError, "unknown configuration keys: #{unknown.join(', ')}" unless unknown.empty?
|
|
26
|
+
|
|
27
|
+
file_values = data.transform_keys(&:to_sym)
|
|
28
|
+
values = DEFAULTS.merge(file_values).merge(overrides)
|
|
29
|
+
%i[timeout thresholds].each do |key|
|
|
30
|
+
next unless file_values.fetch(key, {}).is_a?(Hash) && overrides.fetch(key, {}).is_a?(Hash)
|
|
31
|
+
|
|
32
|
+
values[key] = DEFAULTS.fetch(key).merge(file_values.fetch(key, {})).merge(overrides.fetch(key, {}))
|
|
33
|
+
end
|
|
34
|
+
new(values)
|
|
35
|
+
rescue Psych::Exception => e
|
|
36
|
+
raise ArgumentError, "invalid configuration: #{e.message}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def initialize(values)
|
|
40
|
+
@values = values
|
|
41
|
+
@values[:jobs] = Etc.nprocessors if @values[:jobs] == "auto"
|
|
42
|
+
@values[:operators] = Core::Operators::NAMES if @values[:operators] == "default"
|
|
43
|
+
validate
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def [](key)
|
|
47
|
+
@values.fetch(key)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def to_h
|
|
51
|
+
@values.dup
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def validate
|
|
57
|
+
raise ArgumentError, "framework must be auto, minitest, or rspec" unless %w[auto minitest rspec].include?(self[:framework])
|
|
58
|
+
raise ArgumentError, "scope must be node or method" unless %w[node method].include?(self[:scope])
|
|
59
|
+
raise ArgumentError, "jobs must be a positive integer" unless self[:jobs].is_a?(Integer) && self[:jobs].positive?
|
|
60
|
+
raise ArgumentError, "seed must be an integer" unless self[:seed].is_a?(Integer)
|
|
61
|
+
|
|
62
|
+
%i[include exclude arid_callees operators reporters only].each do |key|
|
|
63
|
+
raise ArgumentError, "#{key} must be a list of strings" unless self[key].is_a?(Array) && self[key].all?(String)
|
|
64
|
+
end
|
|
65
|
+
unknown = self[:operators] - Core::Operators::NAMES
|
|
66
|
+
raise ArgumentError, "unknown operators: #{unknown.join(', ')}" unless unknown.empty?
|
|
67
|
+
|
|
68
|
+
unknown = self[:reporters] - %w[text agent json html github]
|
|
69
|
+
raise ArgumentError, "unknown reporters: #{unknown.join(', ')}" unless unknown.empty?
|
|
70
|
+
|
|
71
|
+
validate_mapping(:timeout, %w[factor base_ms])
|
|
72
|
+
validate_mapping(:thresholds, %w[high low break])
|
|
73
|
+
self[:timeout].each_value do |value|
|
|
74
|
+
raise ArgumentError, "timeout values must be finite and positive" unless finite?(value) && value.positive?
|
|
75
|
+
end
|
|
76
|
+
self[:thresholds].each_value do |value|
|
|
77
|
+
raise ArgumentError, "threshold must be between 0 and 100" unless value.nil? || (finite?(value) && value.between?(0, 100))
|
|
78
|
+
end
|
|
79
|
+
%w[high low].each do |key|
|
|
80
|
+
raise ArgumentError, "#{key} threshold must be an integer" unless self[:thresholds][key].is_a?(Integer)
|
|
81
|
+
end
|
|
82
|
+
raise ArgumentError, "tests must be a glob string or a list" unless self[:tests].nil? || self[:tests].is_a?(String) ||
|
|
83
|
+
(self[:tests].is_a?(Array) && self[:tests].all?(String))
|
|
84
|
+
|
|
85
|
+
%i[samples full dry_run fail_on_survived verify_not_infected].each do |key|
|
|
86
|
+
raise ArgumentError, "#{key} must be true or false" unless [true, false].include?(self[key])
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def finite?(value)
|
|
91
|
+
value.is_a?(Numeric) && value.finite?
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def validate_mapping(key, allowed)
|
|
95
|
+
value = self[key]
|
|
96
|
+
raise ArgumentError, "#{key} must be a mapping" unless value.is_a?(Hash)
|
|
97
|
+
raise ArgumentError, "unknown #{key} keys" unless (value.keys - allowed).empty?
|
|
98
|
+
|
|
99
|
+
@values[key] = DEFAULTS.fetch(key).merge(value)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|