slopbouncer 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ca84305189f394bc4bb5fdf378975319cffcb60a12c8f7daa24bd502e6b8a0e
4
- data.tar.gz: 871c5423d4062d56b649a2deed05f8ad74d5104d680c78e35b9d602bafb4fd1d
3
+ metadata.gz: 75fbc0d28692eb3df2fcd5cde3e0d0b2f3c55cab7f531b274d58fc90da63c8f4
4
+ data.tar.gz: 4364064bac7d9c3f5b92e7f1df5c215b2c4a4da9fc8ef8ce69fdf24dfab60d8d
5
5
  SHA512:
6
- metadata.gz: 720017c454cf95a4e4a5816e422adfa969cf73192bd76ccfea41564ab1bedeb790f66adf08020ea6dd4668af363d1c13c38ab19e9e4c782b77b9fd7f0e589044
7
- data.tar.gz: aebfec5161e5b55e0a2f5b6d2bddc6cc374bb6454233b7f777fc6cd4917e24dbcb527fccd7bd137c8cfab92f938a807a79c6f1f0e9caf2d5a7953d9ea306b579
6
+ metadata.gz: 2028a31966406e8b1e9eaa5057ee69fde76e25da026eabbb125153dc92bbe6117384b6866dea6e3d337861296c5791c439c965f4aa3cf8963cb1f74794d1a90f
7
+ data.tar.gz: 37d95d69e84d3410ecef7a5123f56f4340308f0531c8732ccd40fd734cee4ed41964d3adb71d9b292289a117d01928b9f51e026e2a417a55933e0fb976ad439c
data/README.md CHANGED
@@ -37,7 +37,25 @@ Then run it from the root of the repository you want checked:
37
37
  slopbouncer main..HEAD
38
38
  ```
39
39
 
40
- The argument is a range of commits. Give one commit instead, such as `HEAD` or `origin/main`, and it checks everything since then, committed or not. It prints one line for each finding:
40
+ The argument is a range of commits. Give one commit instead, such as `HEAD` or `origin/main`, and it checks everything since then, committed or not. At a terminal it lays the findings out by file, with each rule in colour:
41
+
42
+ ```
43
+ test/basket_test.rb
44
+ Basket applies a voucher
45
+ skip_added marked to be skipped
46
+
47
+ test/checkout_test.rb
48
+ Checkout lets a guest pay
49
+ assertion_removed assert_equal "paid", order.status
50
+
51
+ test/refund_test.rb
52
+ Refund refunds part of an order
53
+ expected_value_changed 100 → 90
54
+
55
+ 3 tests got weaker in 3 files
56
+ ```
57
+
58
+ When its output goes to a file or another program, it prints one plain line for each finding:
41
59
 
42
60
  ```
43
61
  test/basket_test.rb: Basket applies a voucher: skip_added: marked to be skipped
@@ -49,9 +67,10 @@ test/refund_test.rb: Refund refunds part of an order: expected_value_changed: 10
49
67
  |---|---|
50
68
  | `--json` | Prints the findings as JSON |
51
69
  | `--strict` | Exits with 1 when anything is flagged |
70
+ | `--color` | Uses the terminal layout, in colour, wherever the output goes. For a script whose own output a person reads |
52
71
  | `--agent=NAME` | Runs as that coding agent's hook (see below) |
53
72
 
54
- Without `--strict` it exits with 0 whatever it finds: it flags for review and does not block. It exits with 2 when it is given nothing to compare.
73
+ Setting `NO_COLOR` keeps the terminal layout and leaves the colour out. Without `--strict` it exits with 0 whatever it finds: it flags for review and does not block. It exits with 2 when it is given nothing to compare.
55
74
 
56
75
  ## Feeding it back to a coding agent
57
76
 
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slopbouncer
4
+ # The findings laid out for a person at a terminal: each file once, the
5
+ # tests flagged in it underneath, each rule with its detail under its test,
6
+ # and a count at the end. Colour is optional; the layout is the same without.
7
+ module TerminalReport
8
+ BOLD = 1
9
+ RED = 31
10
+ GREEN = 32
11
+ YELLOW = 33
12
+ # Red for a check that has gone, yellow for one that was changed or switched off.
13
+ COLOURS = { 'test_deleted' => RED, 'assertion_removed' => RED, 'no_assertions' => RED,
14
+ 'expected_value_changed' => YELLOW, 'skip_added' => YELLOW }.freeze
15
+
16
+ def self.call(findings, colour:)
17
+ paint = ->(text, code) { colour ? "\e[#{code}m#{text}\e[0m" : text }
18
+ return paint.call('No tests got weaker.', GREEN) if findings.empty?
19
+
20
+ files = findings.group_by(&:file)
21
+ tests = files.sum { |_file, found| found.map(&:test).uniq.size }
22
+ [*files.map { |file, found| file(file, found, paint) }, count(tests, files.size)].join("\n\n")
23
+ end
24
+
25
+ def self.file(file, found, paint)
26
+ tests = found.group_by(&:test).flat_map do |test, about|
27
+ [" #{test}", *about.map { |finding| " #{paint.call(finding.rule, COLOURS.fetch(finding.rule, YELLOW))} #{detail(finding)}" }]
28
+ end
29
+ [paint.call(file, BOLD), *tests].join("\n")
30
+ end
31
+
32
+ def self.detail(finding)
33
+ finding.before ? "#{finding.before} → #{finding.after}" : finding.detail
34
+ end
35
+
36
+ def self.count(tests, files)
37
+ "#{tests} #{tests == 1 ? 'test' : 'tests'} got weaker in #{files} #{files == 1 ? 'file' : 'files'}"
38
+ end
39
+ private_class_method :file, :detail, :count
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Slopbouncer
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/slopbouncer.rb CHANGED
@@ -8,6 +8,7 @@ require_relative 'slopbouncer/ruby_tests'
8
8
  require_relative 'slopbouncer/compare'
9
9
  require_relative 'slopbouncer/agents'
10
10
  require_relative 'slopbouncer/install'
11
+ require_relative 'slopbouncer/terminal_report'
11
12
 
12
13
  # A static check that flags tests which got weaker in a change, so a person
13
14
  # can decide whether that was intended.
@@ -63,13 +64,25 @@ module Slopbouncer
63
64
  return stop_hook(target.to_s, input, agent.split('=', 2)[1] || Agents::DEFAULT) if agent
64
65
 
65
66
  findings = check(target.to_s)
66
- puts arguments.include?('--json') ? JSON.pretty_generate(findings.map { |finding| finding.to_h.compact }) : report(findings)
67
+ puts printed(findings, arguments)
67
68
  arguments.include?('--strict') && findings.any? ? 1 : 0
68
69
  rescue Error => e
69
70
  warn e.message
70
71
  2
71
72
  end
72
73
 
74
+ # JSON when asked for it. Otherwise laid out for a person when the output is
75
+ # a terminal or colour is asked for, and one plain line for each finding
76
+ # when it goes to another program.
77
+ def self.printed(findings, arguments)
78
+ return JSON.pretty_generate(findings.map { |finding| finding.to_h.compact }) if arguments.include?('--json')
79
+
80
+ asked = arguments.intersect?(%w[--color --colour])
81
+ return report(findings) unless asked || $stdout.tty?
82
+
83
+ TerminalReport.call(findings, colour: asked || ENV['NO_COLOR'].to_s.empty?)
84
+ end
85
+
73
86
  # Sets a coding agent up in the current directory: slopbouncer install claude-code
74
87
  def self.install(words, arguments)
75
88
  raise Error, "Say which agent to set up: #{Agents::ALL.keys.join(', ')}" if words.empty?
@@ -136,5 +149,5 @@ module Slopbouncer
136
149
  "#{finding.file}: #{finding.test}: #{finding.rule}: #{what}"
137
150
  }.join("\n")
138
151
  end
139
- private_class_method :deleted, :settings, :install, :stop_hook, :working_directory, :hook_input, :to_the_agent
152
+ private_class_method :deleted, :settings, :printed, :install, :stop_hook, :working_directory, :hook_input, :to_the_agent
140
153
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slopbouncer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kipple Pty Ltd
@@ -46,6 +46,7 @@ files:
46
46
  - lib/slopbouncer/git.rb
47
47
  - lib/slopbouncer/install.rb
48
48
  - lib/slopbouncer/ruby_tests.rb
49
+ - lib/slopbouncer/terminal_report.rb
49
50
  - lib/slopbouncer/version.rb
50
51
  homepage: https://github.com/mainline-dev/slopbouncer
51
52
  licenses: