specbandit 0.12.0 → 0.13.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 +4 -4
- data/lib/specbandit/cli.rb +21 -3
- data/lib/specbandit/configuration.rb +7 -1
- data/lib/specbandit/version.rb +1 -1
- data/lib/specbandit/worker.rb +94 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 95622117125136b9368557368697eb0b9663983289dc7a5c53692a230ac4d7ef
|
|
4
|
+
data.tar.gz: 5d74e976511d86b4c8da066cc782fc358af1c69e89ae02edcc3935b077ad473e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 19a2cff1aab50ad0412e515a2081b85dcd8f94addf96232bfb2be3694b02980410df1a8788d3451907a985b26fc6cfecb1dd7d45750ba108b63f84975ea36996
|
|
7
|
+
data.tar.gz: 9af9ad631d684be5485a43620b76dcda02e7e223e50b6ecab47def52ee24fa4ab296dff43e5eea11c03acaea5146178da9cced4740ebb1036b41edef38ba0852
|
data/lib/specbandit/cli.rb
CHANGED
|
@@ -123,10 +123,22 @@ module Specbandit
|
|
|
123
123
|
Specbandit.configuration.key_rerun_ttl = v
|
|
124
124
|
end
|
|
125
125
|
|
|
126
|
+
opts.on('--key-failed KEY', 'Redis key to record failed test files for later review') do |v|
|
|
127
|
+
Specbandit.configuration.key_failed = v
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
opts.on('--key-failed-ttl SECONDS', Integer, 'TTL for failed key in seconds (default: 604800 / 1 week)') do |v|
|
|
131
|
+
Specbandit.configuration.key_failed_ttl = v
|
|
132
|
+
end
|
|
133
|
+
|
|
126
134
|
opts.on('--rerun', 'Signal this is a re-run (fail hard if rerun key is empty)') do
|
|
127
135
|
Specbandit.configuration.rerun = true
|
|
128
136
|
end
|
|
129
137
|
|
|
138
|
+
opts.on('--report FILE', 'Write JSON report with run statistics to FILE') do |v|
|
|
139
|
+
Specbandit.configuration.report = v
|
|
140
|
+
end
|
|
141
|
+
|
|
130
142
|
opts.on('--verbose', 'Show per-batch file list and full command output (default: quiet)') do
|
|
131
143
|
Specbandit.configuration.verbose = true
|
|
132
144
|
end
|
|
@@ -207,9 +219,12 @@ module Specbandit
|
|
|
207
219
|
--rspec-opts OPTS Extra options forwarded to RSpec (for rspec adapter)
|
|
208
220
|
--batch-size N Files per batch (default: 5, or set SPECBANDIT_BATCH_SIZE)
|
|
209
221
|
--redis-url URL Redis URL (default: redis://localhost:6379)
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
222
|
+
--key-rerun KEY Per-runner rerun key for re-run support
|
|
223
|
+
--key-rerun-ttl N TTL for rerun key (default: 604800 / 1 week)
|
|
224
|
+
--key-failed KEY Redis key to record failed test files
|
|
225
|
+
--key-failed-ttl N TTL for failed key (default: 604800 / 1 week)
|
|
226
|
+
--rerun Signal this is a re-run (fail hard if rerun key is empty)
|
|
227
|
+
--report FILE Write JSON report to FILE after run
|
|
213
228
|
--verbose Show per-batch file list and full command output
|
|
214
229
|
|
|
215
230
|
Arguments after -- are forwarded to the adapter (rspec opts, command opts, etc.).
|
|
@@ -226,8 +241,11 @@ module Specbandit
|
|
|
226
241
|
SPECBANDIT_RSPEC_OPTS RSpec options (rspec adapter)
|
|
227
242
|
SPECBANDIT_KEY_RERUN Per-runner rerun key
|
|
228
243
|
SPECBANDIT_KEY_RERUN_TTL Rerun key TTL in seconds (default: 604800)
|
|
244
|
+
SPECBANDIT_KEY_FAILED Redis key for failed test files
|
|
245
|
+
SPECBANDIT_KEY_FAILED_TTL Failed key TTL in seconds (default: 604800)
|
|
229
246
|
SPECBANDIT_RERUN Signal re-run mode (1/true/yes)
|
|
230
247
|
SPECBANDIT_VERBOSE Enable verbose output (1/true/yes)
|
|
248
|
+
SPECBANDIT_REPORT Path to write JSON report file
|
|
231
249
|
|
|
232
250
|
File input priority for push:
|
|
233
251
|
1. stdin (piped) echo "spec/a_spec.rb" | specbandit push --key KEY
|
|
@@ -4,12 +4,14 @@ module Specbandit
|
|
|
4
4
|
class Configuration
|
|
5
5
|
attr_accessor :redis_url, :batch_size, :key, :rspec_opts, :key_ttl,
|
|
6
6
|
:key_rerun, :key_rerun_ttl, :rerun, :verbose,
|
|
7
|
-
:adapter, :command, :command_opts
|
|
7
|
+
:adapter, :command, :command_opts,
|
|
8
|
+
:key_failed, :key_failed_ttl, :report
|
|
8
9
|
|
|
9
10
|
DEFAULT_REDIS_URL = 'redis://localhost:6379'
|
|
10
11
|
DEFAULT_BATCH_SIZE = 5
|
|
11
12
|
DEFAULT_KEY_TTL = 21_600 # 6 hours in seconds
|
|
12
13
|
DEFAULT_KEY_RERUN_TTL = 604_800 # 1 week in seconds
|
|
14
|
+
DEFAULT_KEY_FAILED_TTL = 604_800 # 1 week in seconds
|
|
13
15
|
DEFAULT_ADAPTER = 'cli'
|
|
14
16
|
|
|
15
17
|
def initialize
|
|
@@ -25,6 +27,9 @@ module Specbandit
|
|
|
25
27
|
@adapter = ENV.fetch('SPECBANDIT_ADAPTER', DEFAULT_ADAPTER)
|
|
26
28
|
@command = ENV.fetch('SPECBANDIT_COMMAND', nil)
|
|
27
29
|
@command_opts = parse_space_separated(ENV.fetch('SPECBANDIT_COMMAND_OPTS', nil))
|
|
30
|
+
@key_failed = ENV.fetch('SPECBANDIT_KEY_FAILED', nil)
|
|
31
|
+
@key_failed_ttl = Integer(ENV.fetch('SPECBANDIT_KEY_FAILED_TTL', DEFAULT_KEY_FAILED_TTL))
|
|
32
|
+
@report = ENV.fetch('SPECBANDIT_REPORT', nil)
|
|
28
33
|
end
|
|
29
34
|
|
|
30
35
|
def validate!
|
|
@@ -32,6 +37,7 @@ module Specbandit
|
|
|
32
37
|
raise Error, 'batch_size must be a positive integer' unless batch_size.positive?
|
|
33
38
|
raise Error, 'key_ttl must be a positive integer' unless key_ttl.positive?
|
|
34
39
|
raise Error, 'key_rerun_ttl must be a positive integer' unless key_rerun_ttl.positive?
|
|
40
|
+
raise Error, 'key_failed_ttl must be a positive integer' unless key_failed_ttl.positive?
|
|
35
41
|
raise Error, '--rerun requires --key-rerun to be set' if rerun && (key_rerun.nil? || key_rerun.empty?)
|
|
36
42
|
end
|
|
37
43
|
|
data/lib/specbandit/version.rb
CHANGED
data/lib/specbandit/worker.rb
CHANGED
|
@@ -4,7 +4,8 @@ require 'json'
|
|
|
4
4
|
|
|
5
5
|
module Specbandit
|
|
6
6
|
class Worker
|
|
7
|
-
attr_reader :queue, :key, :batch_size, :adapter, :key_rerun, :key_rerun_ttl, :
|
|
7
|
+
attr_reader :queue, :key, :batch_size, :adapter, :key_rerun, :key_rerun_ttl, :key_failed, :key_failed_ttl, :rerun,
|
|
8
|
+
:output, :verbose, :report
|
|
8
9
|
|
|
9
10
|
def initialize(
|
|
10
11
|
key: Specbandit.configuration.key,
|
|
@@ -12,8 +13,11 @@ module Specbandit
|
|
|
12
13
|
adapter: nil,
|
|
13
14
|
key_rerun: Specbandit.configuration.key_rerun,
|
|
14
15
|
key_rerun_ttl: Specbandit.configuration.key_rerun_ttl,
|
|
16
|
+
key_failed: Specbandit.configuration.key_failed,
|
|
17
|
+
key_failed_ttl: Specbandit.configuration.key_failed_ttl,
|
|
15
18
|
rerun: Specbandit.configuration.rerun,
|
|
16
19
|
verbose: Specbandit.configuration.verbose,
|
|
20
|
+
report: Specbandit.configuration.report,
|
|
17
21
|
queue: nil,
|
|
18
22
|
output: $stdout,
|
|
19
23
|
# Legacy parameter for backward compatibility.
|
|
@@ -24,12 +28,16 @@ module Specbandit
|
|
|
24
28
|
@batch_size = batch_size
|
|
25
29
|
@key_rerun = key_rerun
|
|
26
30
|
@key_rerun_ttl = key_rerun_ttl
|
|
31
|
+
@key_failed = key_failed
|
|
32
|
+
@key_failed_ttl = key_failed_ttl
|
|
27
33
|
@rerun = rerun
|
|
28
34
|
@verbose = verbose
|
|
35
|
+
@report = report
|
|
29
36
|
@queue = queue || RedisQueue.new
|
|
30
37
|
@output = output
|
|
31
38
|
@batch_results = []
|
|
32
39
|
@accumulated_examples = []
|
|
40
|
+
@accumulated_failed_files = []
|
|
33
41
|
@accumulated_summary = { duration: 0.0, example_count: 0, failure_count: 0, pending_count: 0,
|
|
34
42
|
errors_outside_of_examples_count: 0 }
|
|
35
43
|
|
|
@@ -46,6 +54,7 @@ module Specbandit
|
|
|
46
54
|
#
|
|
47
55
|
# Returns 0 if all batches passed (or nothing to do), 1 if any batch failed.
|
|
48
56
|
def run
|
|
57
|
+
@run_start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
49
58
|
adapter.setup
|
|
50
59
|
|
|
51
60
|
exit_code = if key_rerun
|
|
@@ -66,6 +75,7 @@ module Specbandit
|
|
|
66
75
|
|
|
67
76
|
print_summary if @batch_results.any?
|
|
68
77
|
merge_json_results
|
|
78
|
+
write_report
|
|
69
79
|
exit_code
|
|
70
80
|
ensure
|
|
71
81
|
adapter.teardown
|
|
@@ -89,6 +99,7 @@ module Specbandit
|
|
|
89
99
|
batch.each { |f| output.puts " #{f}" } if verbose
|
|
90
100
|
|
|
91
101
|
result = adapter.run_batch(batch, batch_num)
|
|
102
|
+
record_failed_files(batch, result)
|
|
92
103
|
process_batch_result(result)
|
|
93
104
|
|
|
94
105
|
if result.exit_code != 0
|
|
@@ -132,6 +143,7 @@ module Specbandit
|
|
|
132
143
|
files.each { |f| output.puts " #{f}" } if verbose
|
|
133
144
|
|
|
134
145
|
result = adapter.run_batch(files, batch_num)
|
|
146
|
+
record_failed_files(files, result)
|
|
135
147
|
process_batch_result(result)
|
|
136
148
|
|
|
137
149
|
if result.exit_code != 0
|
|
@@ -151,11 +163,50 @@ module Specbandit
|
|
|
151
163
|
failed ? 1 : 0
|
|
152
164
|
end
|
|
153
165
|
|
|
166
|
+
# Record failed files to the failed key in Redis for later review.
|
|
167
|
+
# Called after each batch; only pushes when key_failed is configured
|
|
168
|
+
# and the batch had a non-zero exit code.
|
|
169
|
+
#
|
|
170
|
+
# For RSpec batches with JSON output, only the individual failed file
|
|
171
|
+
# paths are recorded (not the entire batch). For CLI adapter batches
|
|
172
|
+
# (no per-file granularity), the whole batch is recorded as fallback.
|
|
173
|
+
def record_failed_files(files, result)
|
|
174
|
+
return unless key_failed
|
|
175
|
+
return if result.exit_code.zero?
|
|
176
|
+
|
|
177
|
+
failed_files = extract_failed_files(result) || files
|
|
178
|
+
return if failed_files.empty?
|
|
179
|
+
|
|
180
|
+
queue.push(key_failed, failed_files, ttl: key_failed_ttl)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Extract individual failed file paths from an RspecBatchResult's JSON output.
|
|
184
|
+
# Returns nil when per-file data is not available (CLI adapter).
|
|
185
|
+
def extract_failed_files(result)
|
|
186
|
+
return nil unless result.is_a?(RspecBatchResult) && result.json_path && File.exist?(result.json_path)
|
|
187
|
+
|
|
188
|
+
data = JSON.parse(File.read(result.json_path))
|
|
189
|
+
failed = data.fetch('examples', [])
|
|
190
|
+
.select { |e| e['status'] == 'failed' }
|
|
191
|
+
.filter_map { |e| e['file_path'] }
|
|
192
|
+
.uniq
|
|
193
|
+
|
|
194
|
+
failed.empty? ? nil : failed
|
|
195
|
+
rescue JSON::ParserError
|
|
196
|
+
nil
|
|
197
|
+
end
|
|
198
|
+
|
|
154
199
|
# Process a BatchResult: store it, and for RSpec batches,
|
|
155
200
|
# read the JSON output for rich reporting.
|
|
156
201
|
def process_batch_result(result)
|
|
157
202
|
@batch_results << result
|
|
158
203
|
|
|
204
|
+
# Accumulate failed files for the report while JSON data is still available.
|
|
205
|
+
if result.exit_code != 0
|
|
206
|
+
per_file = extract_failed_files(result)
|
|
207
|
+
@accumulated_failed_files.concat(per_file || result.files)
|
|
208
|
+
end
|
|
209
|
+
|
|
159
210
|
# If the adapter returned an RspecBatchResult with a json_path,
|
|
160
211
|
# accumulate the structured results for rich reporting.
|
|
161
212
|
return unless result.is_a?(RspecBatchResult) && result.json_path
|
|
@@ -242,6 +293,48 @@ module Specbandit
|
|
|
242
293
|
File.write(path, JSON.pretty_generate(merged))
|
|
243
294
|
end
|
|
244
295
|
|
|
296
|
+
# Write a JSON report file with run statistics when --report is set.
|
|
297
|
+
def write_report
|
|
298
|
+
return unless report
|
|
299
|
+
return if @batch_results.empty?
|
|
300
|
+
|
|
301
|
+
wall_time = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - @run_start_time).round(2)
|
|
302
|
+
durations = batch_durations
|
|
303
|
+
failed_batches_count = @batch_results.count { |r| r.exit_code != 0 }
|
|
304
|
+
passed_batches_count = @batch_results.count { |r| r.exit_code == 0 }
|
|
305
|
+
|
|
306
|
+
data = {
|
|
307
|
+
specbandit_version: Specbandit::VERSION,
|
|
308
|
+
summary: {
|
|
309
|
+
total_files: @batch_results.sum { |r| r.files.size },
|
|
310
|
+
total_batches: @batch_results.size,
|
|
311
|
+
passed_batches: passed_batches_count,
|
|
312
|
+
failed_batches: failed_batches_count,
|
|
313
|
+
passed: failed_batches_count == 0
|
|
314
|
+
},
|
|
315
|
+
failed_files: @accumulated_failed_files.uniq,
|
|
316
|
+
total_wall_time: wall_time,
|
|
317
|
+
batch_timings: {
|
|
318
|
+
count: durations.size,
|
|
319
|
+
min: format('%.2f', durations.min || 0),
|
|
320
|
+
avg: format('%.2f', durations.empty? ? 0 : durations.sum / durations.size),
|
|
321
|
+
max: format('%.2f', durations.max || 0),
|
|
322
|
+
all: durations.map { |d| d.round(2) }
|
|
323
|
+
},
|
|
324
|
+
batches: @batch_results.map do |r|
|
|
325
|
+
{
|
|
326
|
+
batch_num: r.batch_num,
|
|
327
|
+
files: r.files,
|
|
328
|
+
exit_code: r.exit_code,
|
|
329
|
+
duration: r.duration.round(2),
|
|
330
|
+
passed: r.exit_code == 0
|
|
331
|
+
}
|
|
332
|
+
end
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
File.write(report, JSON.pretty_generate(data))
|
|
336
|
+
end
|
|
337
|
+
|
|
245
338
|
# Print a unified summary to the output stream after all batches.
|
|
246
339
|
def print_summary
|
|
247
340
|
output.puts ''
|