evilution 1.6.0 → 1.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a0b8191841143845ce57b7b44c407aaca2a60df082d956e589e8d5202508d69
4
- data.tar.gz: 47bba12a95be5ffe2610a369c98d91de1f4d1469a7a63bde15efcd51a3c21c88
3
+ metadata.gz: ae8097f318440eec5a0558ca7ed0cd46fa139163542b3212b9f3d49d8ad050dd
4
+ data.tar.gz: 903f2cef98029adc766ea58aef956c80edd769da782b87b422ca6111854bd72a
5
5
  SHA512:
6
- metadata.gz: ceb42ff4858277cc2b01e955e08e05bc16bf9b7e514a119075423fba3acb309669d2fef675a69a0897b3c4bf824e6344162f237ad3aec87454e096c664822f0d
7
- data.tar.gz: d80ef7071355f0b8bdd5848f33f18ca73e8bf3d89794046ff5a7baeeac5d960de5ef7a5269d84d603e867d22f828dcf478b4d3e8ca44931d04e99e75a8acafe9
6
+ metadata.gz: d641953f458a9b6fbd431c17f06ed91a54eb00c464e54e120bcca3ff92f21644632b48a5d219ec5a27bef4d96dd1ca45ed0dec20d78fadadd4f716fbf39c6b85
7
+ data.tar.gz: bdd502626373fb71ec4bf1655df58325aaae4a1380b2669f5d2adc06bf4ac04103d24ec9f11fd4ab3bf19fd80e63a8e2ca207ca1c058066687ed232f2551e32c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  Versioning policy: see [docs/versioning.md](docs/versioning.md).
4
4
 
5
+ ## [1.6.1] - 2026-11-28
6
+
7
+ ### Fixed
8
+
9
+ - **JSON output is written whatever the encoding of the text in it** — a diff, error message or backtrace that reached the report tagged binary (`ASCII-8BIT`), or tagged UTF-8 but holding invalid bytes, made `JSON.generate` raise (binary text holding valid UTF-8 only warned before json 3.1), so no JSON report was written. Such strings are now read as UTF-8, with invalid bytes replaced by U+FFFD. Strings that are already valid UTF-8, or tagged with another encoding, are left as they are. This covers the `--format json` report, `--save-session` files, and the MCP `evilution-mutate` response and its progress messages; the MCP progress stream used to stop at the first such string, with a warning on stderr only (PR #1993, GH #1991)
10
+ - **The memory budget specs no longer fail at random late in the suite** — on Ruby 4.0.7 CI, the mutation-generation budget read 15–25 MB of growth with nothing retained: a full GC can leave the heap room to grow before it collects again, so the next round's garbage landed on new heap pages. The probe now subtracts heap page growth from RSS growth and adds live-object growth, and new specs check that deliberate leaks, inside and outside the GC heap, are still caught. The 10 MB budget is unchanged (test-only) (PR #1994, GH #1895)
11
+
12
+ ### Changed
13
+
14
+ - **Dependency bumps** — `mcp` 1.10.0 -> 1.12.0 (PR #1987 and the release update), `rubocop` 1.92.2 -> 1.93.0 (PR #1990 and the release update), `rubocop-ast` 1.51.0 -> 1.54.0 and `parser` 3.3.13.0 -> 3.3.14.0 (PR #1990), `json` 3.1.0 -> 3.2.0 (PR #1990 and the release update), `regexp_parser` 2.13.1 -> 2.13.4 (PR #1987 and the release update), `connection_pool` 3.0.2 -> 3.0.3 and `test-unit` 3.7.8 -> 3.7.9 (release update), `ruby/setup-ruby` 1.338.0 -> 1.343.0 (PR #1986), `rubygems/release-gem` 1.4.1 -> 1.4.2 (PR #1988)
15
+
16
+ ### Documentation
17
+
18
+ - **Adaptive timeout: slow kills and what to tune** — a mutant that sends the code into deep recursion can take more than ten times its spec files' baseline to end in `SystemStackError` and is killed only by the 30 s re-run; the README now says so, and suggests raising `timeout_factor` or `timeout_floor`, or setting `timeout`, when many mutations show `adaptive_timeout` in their `timings`
19
+ - **Prism requirement** — the README now says `prism >= 1.5, < 3`, as the gemspec has allowed since 1.6.0
20
+
5
21
  ## [1.6.0] - 2026-11-17
6
22
 
7
23
  This release is about wall time. A run now does less work per mutant: each kill check stops at the first failing example, the per-mutation timeout follows how long the mutation's specs took in the baseline, parallel workers stay up for the whole run instead of being started and stopped per batch, and each file is parsed once. Stopping at the first failure alone cut wall time by about a fifth on the benchmark corpus, with no kill lost. New opt-in switches go further: mutants on lines no test executes are reported `uncovered` without running, examples that killed nearby mutants run first, and log calls, error messages and `require` lines can be left unmutated. `--since REF` mutates only what changed since a git ref.
data/README.md CHANGED
@@ -31,7 +31,7 @@ Or standalone:
31
31
  gem install evilution
32
32
  ```
33
33
 
34
- Requires `prism >= 1.5, < 2`. Older Rails apps (e.g. Rails 7.1 pins `prism 0.19`) must upgrade prism — the gemspec constraint forces bundler to resolve a compatible 1.x version. If your app pins `prism 2.x`, bundler will reject the install until evilution widens its upper bound.
34
+ Requires `prism >= 1.5, < 3`. Older Rails apps (e.g. Rails 7.1 pins `prism 0.19`) must upgrade prism — the gemspec constraint forces bundler to resolve a compatible 1.x or 2.x version.
35
35
 
36
36
  ### Installing on Rails 7.1 + Ruby 3.3
37
37
 
@@ -436,6 +436,8 @@ A skipped mutation is not run and not scored. It is counted in `summary.skipped`
436
436
 
437
437
  Use `--format json` for machine-readable output. The same shape is used for both stdout reports (`--format json`) and saved session files (`--save-session` → `.evilution/results/*.json`); session files add a small set of extra top-level fields described under [Session JSON files](#session-json-files) below.
438
438
 
439
+ Every string in the report is valid UTF-8. Text that arrives tagged binary, such as a diff or a child process's error output, is read as UTF-8, and bytes that are not valid UTF-8 are replaced with U+FFFD. The same applies to session files and to the successful MCP `evilution-mutate` response and its progress messages. Error payloads (from `run --format json` and from `evilution-mutate`) and `util mutation --format json` are written as they are.
440
+
439
441
  Schema:
440
442
 
441
443
  ```json
@@ -619,7 +621,7 @@ limit = clamp(timeout_factor × baseline seconds of the mutation's spec files, t
619
621
 
620
622
  With the defaults (factor 10, floor 10s, ceiling 60s) a mutant on a spec file that passes in 0.3s is first given 10s instead of 30s, and one whose spec files take 4s gets 40s. The baseline runs each spec file in a forked process of its own, so its time holds the fork and loading the file; the factor leaves room for the re-run of a survivor against its whole spec files ([Survivor Confirmation](#survivor-confirmation)) and for workers competing for the CPU under `--jobs`, and the floor covers spec files so fast that scheduling noise outweighs them.
621
623
 
622
- A mutant that slows the code down can still fail its test well after its baseline suggests, and a timeout reported there would hide a kill. So a mutation that uses up a limit shorter than the fixed 30s is run again under 30s, and the verdict of that second run is the one reported: a mutation is only reported as a timeout where the fixed limit would have reported one too. The first run is part of what the mutation cost: it is in its `duration` and in the JSON report's `timings` as `adaptive_timeout`. A mutant that loops therefore costs the shorter limit plus 30s; the time saved is on kills and survivors, and on spec files slow enough to get a longer limit. Raise `timeout_floor` if many mutations are run twice.
624
+ A mutant that slows the code down can still fail its test well after its baseline suggests, and a timeout reported there would hide a kill. So a mutation that uses up a limit shorter than the fixed 30s is run again under 30s, and the verdict of that second run is the one reported: a mutation is only reported as a timeout where the fixed limit would have reported one too. The first run is part of what the mutation cost: it is in its `duration` and in the JSON report's `timings` as `adaptive_timeout`. A mutant that loops therefore costs the shorter limit plus 30s; the time saved is on kills and survivors, and on spec files slow enough to get a longer limit. A mutant that fails its tests slowly costs the same: one that sends the code into deep recursion can take more than ten times its spec files' baseline to end in `SystemStackError`, and is killed only by the second run. If many mutations are run twice (their `timings` show `adaptive_timeout`), raise `timeout_factor` or `timeout_floor`, or set `timeout` for a fixed limit.
623
625
 
624
626
  A mutation keeps the fixed 30s limit when the baseline cannot vouch for its spec files: no baseline ran (`--no-baseline`), no spec file resolves for its source (it falls back to the whole suite, or is reported unresolved), one of its spec files failed in the baseline, or `related_specs_heuristic` adds spec files the baseline never ran. Every mutation keeps it when a `worker_process_start`, `mutation_insert_pre` or `mutation_insert_post` hook is configured: those run inside the time a mutation is allowed, and the baseline runs none of them.
625
627
 
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "version"
4
+
5
+ # A copy of a payload that JSON.generate can write. Strings tagged BINARY
6
+ # (subprocess output, files read in binary mode) are retagged UTF-8, and
7
+ # strings tagged UTF-8 that hold invalid bytes (git output forced to UTF-8, a
8
+ # child's error message) are copied; in both, bytes that are not valid UTF-8
9
+ # become U+FFFD. Valid UTF-8 strings, strings in any other encoding (the json
10
+ # gem transcodes those itself) and everything that is not a string pass through
11
+ # as the same object. The input is never changed.
12
+ #
13
+ # The payload must be built from plain Hash, Array and scalar values: any
14
+ # other object (a Struct, a Data, a custom class) passes through as it is, and
15
+ # the strings inside it are not normalized.
16
+ #
17
+ # Known limitation: two hash keys that differ only in encoding, such as a
18
+ # BINARY "あ".b and a UTF-8 "あ", normalize to the same key and the later entry
19
+ # wins. Report keys are Symbols and file paths, so a report never holds both.
20
+ class Evilution::EncodingNormalizer
21
+ def call(payload)
22
+ case payload
23
+ when Hash then payload.to_h { |key, value| [call(key), call(value)] }
24
+ when Array then payload.map { |element| call(element) }
25
+ when String then normalize_string(payload)
26
+ else payload
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ # scrub's default replacement in a Unicode encoding is U+FFFD.
33
+ def normalize_string(string)
34
+ case string.encoding
35
+ when Encoding::BINARY then string.dup.force_encoding(Encoding::UTF_8).scrub
36
+ when Encoding::UTF_8 then string.valid_encoding? ? string : string.scrub
37
+ else string
38
+ end
39
+ end
40
+ end
@@ -4,8 +4,12 @@ require "json"
4
4
  require_relative "../mutate_tool"
5
5
  require_relative "../../reporter/suggestion"
6
6
  require_relative "../../diagnostic"
7
+ require_relative "../../encoding_normalizer"
7
8
 
8
9
  module Evilution::MCP::MutateTool::ProgressStreamer
10
+ # Retags BINARY strings and scrubs invalid UTF-8 so JSON generation cannot fail on them.
11
+ ENCODING_NORMALIZER = Evilution::EncodingNormalizer.new
12
+
9
13
  def self.build(server_context:, suggest_tests:, integration:)
10
14
  return nil unless suggest_tests && server_context.respond_to?(:report_progress)
11
15
 
@@ -20,7 +24,7 @@ module Evilution::MCP::MutateTool::ProgressStreamer
20
24
  begin
21
25
  survivor_index += 1
22
26
  detail = build_suggestion_detail(result.mutation, suggestion)
23
- server_context.report_progress(survivor_index, message: ::JSON.generate(detail))
27
+ server_context.report_progress(survivor_index, message: ::JSON.generate(ENCODING_NORMALIZER.call(detail)))
24
28
  rescue StandardError => e
25
29
  Evilution::Diagnostic.warn("[evilution] progress stream disabled after error: #{e.class}: #{e.message}")
26
30
  disabled = true
@@ -6,6 +6,7 @@ require_relative "../../feedback"
6
6
  require_relative "../../feedback/detector"
7
7
  require_relative "../../feedback/messages"
8
8
  require_relative "../../feedback/setup_warning"
9
+ require_relative "../../encoding_normalizer"
9
10
 
10
11
  module Evilution::MCP::MutateTool::ReportTrimmer
11
12
  # An uncovered mutation is a survivor no test executes, as actionable as one
@@ -30,6 +31,9 @@ module Evilution::MCP::MutateTool::ReportTrimmer
30
31
  ERROR_BACKTRACE_HEAD_LINES = 5
31
32
  ERROR_SAMPLE_KEYS = %w[operator file line error_message error_class].freeze
32
33
 
34
+ # Retags BINARY strings and scrubs invalid UTF-8 so JSON generation cannot fail on them.
35
+ ENCODING_NORMALIZER = Evilution::EncodingNormalizer.new
36
+
33
37
  def self.call(json_string, verbosity:, survived_results:, config:, enricher:, summary: nil, uncovered_results: [])
34
38
  data = ::JSON.parse(json_string)
35
39
  case verbosity
@@ -45,7 +49,7 @@ module Evilution::MCP::MutateTool::ReportTrimmer
45
49
  enricher.call(data, survived_results, config, uncovered_results: uncovered_results)
46
50
  embed_feedback(data, summary) unless verbosity == "minimal"
47
51
  embed_setup_warning(data, summary)
48
- ::JSON.generate(data)
52
+ ::JSON.generate(ENCODING_NORMALIZER.call(data))
49
53
  end
50
54
 
51
55
  def self.apply_minimal(data)
@@ -6,18 +6,21 @@ require_relative "suggestion"
6
6
 
7
7
  require_relative "../reporter"
8
8
  require_relative "../session/schema"
9
+ require_relative "../encoding_normalizer"
9
10
 
10
11
  class Evilution::Reporter::JSON
11
- def initialize(suggest_tests: false, integration: :rspec, subjects: Subjects.new, baseline: Baseline.new, timings: Timings.new)
12
+ def initialize(suggest_tests: false, integration: :rspec, subjects: Subjects.new, baseline: Baseline.new, timings: Timings.new,
13
+ encoding_normalizer: Evilution::EncodingNormalizer.new)
12
14
  suggestion = Evilution::Reporter::Suggestion.new(suggest_tests: suggest_tests, integration: integration)
13
15
  @mutation_detail = MutationDetail.new(suggestion: suggestion, timings: timings)
14
16
  @subjects = subjects
15
17
  @baseline = baseline
16
18
  @timings = timings
19
+ @encoding_normalizer = encoding_normalizer
17
20
  end
18
21
 
19
22
  def call(summary)
20
- ::JSON.generate(build_report(summary))
23
+ ::JSON.generate(@encoding_normalizer.call(build_report(summary)))
21
24
  end
22
25
 
23
26
  private
@@ -6,10 +6,13 @@ require "time"
6
6
  require "fileutils"
7
7
 
8
8
  require_relative "../session"
9
+ require_relative "../encoding_normalizer"
9
10
  require_relative "schema"
10
11
 
11
12
  class Evilution::Session::Store
12
13
  DEFAULT_DIR = ".evilution/results"
14
+ # Retags BINARY strings and scrubs invalid UTF-8 so JSON generation cannot fail on them.
15
+ ENCODING_NORMALIZER = Evilution::EncodingNormalizer.new
13
16
 
14
17
  def initialize(results_dir: DEFAULT_DIR)
15
18
  @results_dir = results_dir
@@ -19,7 +22,7 @@ class Evilution::Session::Store
19
22
  FileUtils.mkdir_p(@results_dir)
20
23
 
21
24
  now = Time.now
22
- data = build_session_data(summary, now)
25
+ data = ENCODING_NORMALIZER.call(build_session_data(summary, now))
23
26
  filename = "#{format_timestamp(now)}-#{SecureRandom.hex(4)}.json"
24
27
  path = File.join(@results_dir, filename)
25
28
  atomic_write(path, JSON.pretty_generate(data))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Evilution
4
- VERSION = "1.6.0"
4
+ VERSION = "1.6.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evilution
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Kiselev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-17 00:00:00.000000000 Z
11
+ date: 2026-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diff-lcs
@@ -277,6 +277,7 @@ files:
277
277
  - lib/evilution/coverage_example_filter.rb
278
278
  - lib/evilution/diagnostic.rb
279
279
  - lib/evilution/disable_comment.rb
280
+ - lib/evilution/encoding_normalizer.rb
280
281
  - lib/evilution/equivalent.rb
281
282
  - lib/evilution/equivalent/detector.rb
282
283
  - lib/evilution/equivalent/heuristic.rb