swarf 0.2.0 → 0.2.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 +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +3 -1
- data/lib/swarf/complexity.rb +15 -2
- data/lib/swarf/coverage_map.rb +6 -1
- data/lib/swarf/probe.rb +9 -0
- data/lib/swarf/version.rb +1 -1
- data/skills/swarf/SKILL.md +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6521ee458e5e51406ae4ee081b2dd3d87ef53db4c8b63f13c3b6d4dd75433737
|
|
4
|
+
data.tar.gz: f5de7399798e889418f7f26425e2789c9e71ce24c8e84d26b0c2c77dbb9dc280
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 18c26000b8294be4bb424d7ccd8421f8d5952feeb5e8b408571ab9ab0a1cf0f703bf6eb4ac2b254a9cb8ed1fdd793a2ed57ea7609ade1ab76bb9140b6c87642f
|
|
7
|
+
data.tar.gz: 33c0819b15c6e2ffdc928c28cf9080d8e83d82e18dae1769eaa6418581fe3f272079d353509131d6db0f91eea69c299eb0239b315c223869ae47ed863ad75f1a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1 — 2026-11-09
|
|
4
|
+
|
|
5
|
+
- The probe no longer kills the boot of apps using bootsnap on Ruby 4.0.2+, where
|
|
6
|
+
dumping an instruction sequence under coverage raises. It sets
|
|
7
|
+
`DISABLE_BOOTSNAP_COMPILE_CACHE=1` so bootsnap skips the part that would.
|
|
8
|
+
- A method with `rescue` no longer scores 0% when tests ran it but never raised.
|
|
9
|
+
Ruby's `Coverage` records no branch for `rescue`, so a branch inside the
|
|
10
|
+
handler was the only one measured. Each rescue now adds its own outcomes: the
|
|
11
|
+
body ran, and each handler ran.
|
|
12
|
+
|
|
3
13
|
## 0.2.0 — 2026-09-06
|
|
4
14
|
|
|
5
15
|
- `swarf init` installs a Claude Code skill into `.claude/skills/swarf/` and adds
|
data/README.md
CHANGED
|
@@ -239,12 +239,14 @@ flowchart LR
|
|
|
239
239
|
Score --> Report["report, worst first"]
|
|
240
240
|
```
|
|
241
241
|
|
|
242
|
-
The probe is
|
|
242
|
+
The probe is `Coverage.start` plus an `at_exit` that dumps the result. The runner never loads your application — it parses text.
|
|
243
243
|
|
|
244
244
|
## Things worth knowing
|
|
245
245
|
|
|
246
246
|
**Any run counts, not just specs.** A rake task, booting the app or a script all record coverage; nothing static can tell you whether a line executed.
|
|
247
247
|
|
|
248
|
+
**Bootsnap loses its compile cache under the probe.** Ruby 4.0.2 and later refuse to dump an instruction sequence while coverage is being measured, and bootsnap dumps one as it loads — with the probe first, `bootsnap/setup` would kill the boot. On those Rubies the probe sets `DISABLE_BOOTSNAP_COMPILE_CACHE=1` before bootsnap loads. The load path cache stays on, so boot is only a little slower.
|
|
249
|
+
|
|
248
250
|
**swarf and SimpleCov cannot both run.** Ruby permits one `Coverage.start` per process. If SimpleCov gets there first, swarf warns and records nothing rather than killing your suite.
|
|
249
251
|
|
|
250
252
|
**Branch coverage is preferred, with a line fallback.** Ruby puts a decision on a line that runs whichever way the decision goes, so `return 0 if x.negative?` reads 100% by line even when the guard never fires — wrong exactly where risk collects. Methods with no branches fall back to lines, where "did it run" is the whole truth.
|
data/lib/swarf/complexity.rb
CHANGED
|
@@ -4,7 +4,7 @@ require "prism"
|
|
|
4
4
|
|
|
5
5
|
module Swarf
|
|
6
6
|
module Complexity
|
|
7
|
-
Method = Struct.new(:path, :name, :cc, :start_line, :body) do
|
|
7
|
+
Method = Struct.new(:path, :name, :cc, :start_line, :body, :rescues) do
|
|
8
8
|
def range = start_line..(body&.last || start_line)
|
|
9
9
|
end
|
|
10
10
|
|
|
@@ -43,7 +43,7 @@ module Swarf
|
|
|
43
43
|
|
|
44
44
|
def visit_def_node(node)
|
|
45
45
|
method = Method.new(path: @path, name: qualify(node), cc: 1,
|
|
46
|
-
start_line: node.location.start_line, body: body_range(node))
|
|
46
|
+
start_line: node.location.start_line, body: body_range(node), rescues: [])
|
|
47
47
|
@methods << method
|
|
48
48
|
@stack.push(method)
|
|
49
49
|
super
|
|
@@ -61,6 +61,19 @@ module Swarf
|
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
+
def visit_begin_node(node)
|
|
65
|
+
main = node.statements&.location&.start_line
|
|
66
|
+
handlers = []
|
|
67
|
+
clause = node.rescue_clause
|
|
68
|
+
while clause
|
|
69
|
+
handlers << clause.statements&.location&.start_line
|
|
70
|
+
clause = clause.subsequent
|
|
71
|
+
end
|
|
72
|
+
handlers.compact!
|
|
73
|
+
@stack.last.rescues.push(main, *handlers) if @stack.any? && main && handlers.any?
|
|
74
|
+
super
|
|
75
|
+
end
|
|
76
|
+
|
|
64
77
|
def visit_call_node(node)
|
|
65
78
|
decision if node.safe_navigation?
|
|
66
79
|
super
|
data/lib/swarf/coverage_map.rb
CHANGED
|
@@ -25,12 +25,17 @@ module Swarf
|
|
|
25
25
|
private
|
|
26
26
|
|
|
27
27
|
def branch_coverage(measurement, method)
|
|
28
|
-
outcomes = measurement.branches(method.range)
|
|
28
|
+
outcomes = measurement.branches(method.range) + rescue_outcomes(measurement, method)
|
|
29
29
|
return nil if outcomes.empty?
|
|
30
30
|
|
|
31
31
|
ratio(outcomes.count(&:positive?), outcomes.size, "br")
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
# Coverage records no branch for rescue, though Complexity counts one.
|
|
35
|
+
def rescue_outcomes(measurement, method)
|
|
36
|
+
method.rescues.flat_map { |line| measurement.lines(line..line) }
|
|
37
|
+
end
|
|
38
|
+
|
|
34
39
|
def line_coverage(measurement, method)
|
|
35
40
|
return nil unless method.body
|
|
36
41
|
|
data/lib/swarf/probe.rb
CHANGED
|
@@ -6,12 +6,21 @@ module Swarf
|
|
|
6
6
|
module Probe
|
|
7
7
|
def self.start
|
|
8
8
|
::Coverage.start(lines: true, branches: true, methods: true)
|
|
9
|
+
spare_bootsnap
|
|
9
10
|
at_exit { record(::Coverage.result) }
|
|
10
11
|
rescue RuntimeError => e
|
|
11
12
|
warn "swarf: coverage is already being measured (#{e.message}); not recording. " \
|
|
12
13
|
"Remove SimpleCov, or drop the swarf/probe require."
|
|
13
14
|
end
|
|
14
15
|
|
|
16
|
+
def self.spare_bootsnap
|
|
17
|
+
return unless defined?(::RubyVM::InstructionSequence)
|
|
18
|
+
|
|
19
|
+
::RubyVM::InstructionSequence.compile("").to_binary
|
|
20
|
+
rescue RuntimeError
|
|
21
|
+
ENV["DISABLE_BOOTSNAP_COMPILE_CACHE"] ||= "1"
|
|
22
|
+
end
|
|
23
|
+
|
|
15
24
|
def self.record(result)
|
|
16
25
|
require_relative "store"
|
|
17
26
|
Store.new.record(result)
|
data/lib/swarf/version.rb
CHANGED
data/skills/swarf/SKILL.md
CHANGED
|
@@ -60,6 +60,8 @@ The probe must load before the code under test, because `Coverage` only sees fil
|
|
|
60
60
|
|
|
61
61
|
Add `.swarf/` to `.gitignore`. Runs merge, so a single spec file adds to what earlier runs proved; nothing is erased until the file's bytes change.
|
|
62
62
|
|
|
63
|
+
On Ruby 4.0.2+ the probe sets `DISABLE_BOOTSNAP_COMPILE_CACHE=1`. If a boot still dies with `should not compile with coverage`, something started `Coverage` before `swarf/probe` did.
|
|
64
|
+
|
|
63
65
|
Do not run swarf's probe alongside SimpleCov. Ruby allows one `Coverage.start` per process; if SimpleCov started first, swarf warns and records nothing.
|
|
64
66
|
|
|
65
67
|
## Commands
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: swarf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ariel Rzezak
|
|
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
61
|
version: '0'
|
|
62
62
|
requirements: []
|
|
63
|
-
rubygems_version: 4.0.
|
|
63
|
+
rubygems_version: 4.0.24
|
|
64
64
|
specification_version: 4
|
|
65
65
|
summary: 'Scores Ruby methods by the CRAP metric: complexity against coverage.'
|
|
66
66
|
test_files: []
|