polyrun 3.0.1 → 3.2.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/CHANGELOG.md +21 -0
- data/README.md +16 -2
- data/docs/QUALITY.md +82 -0
- data/docs/QUALITY_CONFIGURATION.md +95 -0
- data/ext/polyrun_coverage_merge/coverage_merge.c +13 -26
- data/lib/polyrun/cli/ci_shard_run_command.rb +1 -1
- data/lib/polyrun/cli/graph_command.rb +68 -0
- data/lib/polyrun/cli/help.rb +5 -1
- data/lib/polyrun/cli/helpers.rb +3 -2
- data/lib/polyrun/cli/mutation_command.rb +67 -0
- data/lib/polyrun/cli/quality_commands.rb +65 -0
- data/lib/polyrun/cli/run_shards_parallel_wait.rb +48 -70
- data/lib/polyrun/cli/run_shards_plan_options.rb +1 -1
- data/lib/polyrun/cli/run_shards_worker_interrupt.rb +16 -0
- data/lib/polyrun/cli/tool_options.rb +48 -0
- data/lib/polyrun/cli.rb +17 -1
- data/lib/polyrun/config/effective.rb +9 -0
- data/lib/polyrun/config/resolver.rb +9 -0
- data/lib/polyrun/config/schema.rb +8 -3
- data/lib/polyrun/config/suite.rb +6 -1
- data/lib/polyrun/config/tool_defaults.rb +42 -0
- data/lib/polyrun/config/tool_validation.rb +79 -0
- data/lib/polyrun/config/tools.rb +120 -0
- data/lib/polyrun/config.rb +6 -4
- data/lib/polyrun/coverage/collector.rb +7 -1
- data/lib/polyrun/coverage/example_diff.rb +4 -8
- data/lib/polyrun/error.rb +3 -0
- data/lib/polyrun/graph/client.rb +64 -0
- data/lib/polyrun/graph/error.rb +13 -0
- data/lib/polyrun/graph/index.rb +75 -0
- data/lib/polyrun/graph/inspect.rb +58 -0
- data/lib/polyrun/graph/plan.rb +134 -0
- data/lib/polyrun/graph/planner.rb +117 -0
- data/lib/polyrun/graph/syntax.rb +114 -0
- data/lib/polyrun/graph/transaction.rb +81 -0
- data/lib/polyrun/graph/worker.rb +55 -0
- data/lib/polyrun/graph/workspace.rb +117 -0
- data/lib/polyrun/minitest_support.rb +1 -1
- data/lib/polyrun/mutation/candidates.rb +91 -0
- data/lib/polyrun/mutation/operators.rb +51 -0
- data/lib/polyrun/mutation/runner.rb +133 -0
- data/lib/polyrun/mutation/subjects.rb +88 -0
- data/lib/polyrun/process_stdio.rb +13 -8
- data/lib/polyrun/quality/command.rb +84 -0
- data/lib/polyrun/quality/measure.rb +38 -0
- data/lib/polyrun/quality/observe.rb +53 -0
- data/lib/polyrun/quality/observe_hook.rb +103 -0
- data/lib/polyrun/quality/sandbox.rb +70 -0
- data/lib/polyrun/rspec_support.rb +1 -1
- data/lib/polyrun/spec_quality/config.rb +8 -3
- data/lib/polyrun/spec_quality.rb +3 -4
- data/lib/polyrun/version.rb +1 -1
- data/lib/polyrun/worker_output.rb +25 -33
- data/lib/polyrun/worker_output_forwarders.rb +11 -7
- data/lib/polyrun.rb +1 -2
- data/polyrun.gemspec +6 -1
- data/sig/polyrun/config.rbs +2 -2
- metadata +44 -2
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require "io/wait"
|
|
2
|
+
|
|
3
|
+
module Polyrun
|
|
4
|
+
module Quality
|
|
5
|
+
module Command
|
|
6
|
+
DEFAULT_OUTPUT_LIMIT = 1_048_576
|
|
7
|
+
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
# rubocop:disable Metrics/AbcSize -- keep descriptor ownership and process cleanup in the same scope
|
|
11
|
+
def call(argv, root:, timeout:, env: {}, max_output: DEFAULT_OUTPUT_LIMIT)
|
|
12
|
+
timeout = Float(timeout)
|
|
13
|
+
validate!(argv, timeout, max_output)
|
|
14
|
+
|
|
15
|
+
started = monotonic
|
|
16
|
+
streams = []
|
|
17
|
+
2.times { streams << IO.pipe }
|
|
18
|
+
output = {"stdout" => +"".b, "stderr" => +"".b}
|
|
19
|
+
pid = Process.spawn(env, [argv.first, argv.first], *argv.drop(1), chdir: root, in: File::NULL, out: streams[0][1], err: streams[1][1], pgroup: true)
|
|
20
|
+
streams.each { |_, writer| writer.close }
|
|
21
|
+
code = collect(pid, streams.map(&:first), output, started + timeout, max_output)
|
|
22
|
+
output.each_value { |value| value.force_encoding(Encoding::UTF_8).scrub!("") }
|
|
23
|
+
output.merge("exitstatus" => code, "wall_s" => monotonic - started)
|
|
24
|
+
rescue Errno::ENOENT => e
|
|
25
|
+
{"stdout" => "", "stderr" => e.message, "exitstatus" => 127, "wall_s" => monotonic - started}
|
|
26
|
+
ensure
|
|
27
|
+
terminate(pid) if pid
|
|
28
|
+
streams&.flatten&.each { |stream| stream.close unless stream.closed? }
|
|
29
|
+
end
|
|
30
|
+
# rubocop:enable Metrics/AbcSize
|
|
31
|
+
|
|
32
|
+
def collect(pid, readers, output, deadline, limit)
|
|
33
|
+
active = readers.dup
|
|
34
|
+
status = nil
|
|
35
|
+
loop do
|
|
36
|
+
status ||= Process.waitpid2(pid, Process::WNOHANG)&.last
|
|
37
|
+
return status.exitstatus || 128 + status.termsig if status && active.empty?
|
|
38
|
+
return 124 if monotonic >= deadline
|
|
39
|
+
|
|
40
|
+
return 122 if drain(active, readers, output, deadline, limit)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def drain(active, readers, output, deadline, limit)
|
|
45
|
+
ready = IO.select(active, nil, nil, (deadline - monotonic).clamp(0.0001, 0.001))&.first || []
|
|
46
|
+
ready.each do |reader|
|
|
47
|
+
chunk = reader.read_nonblock(16_384, exception: false)
|
|
48
|
+
if chunk.nil?
|
|
49
|
+
active.delete(reader)
|
|
50
|
+
elsif chunk != :wait_readable
|
|
51
|
+
key = (reader == readers.first) ? "stdout" : "stderr"
|
|
52
|
+
remaining = limit - output.values.sum(&:bytesize)
|
|
53
|
+
output[key] << chunk.byteslice(0, remaining)
|
|
54
|
+
return true if chunk.bytesize > remaining
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
false
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def validate!(argv, timeout, max_output)
|
|
61
|
+
raise ArgumentError, "timeout must be finite and positive" unless timeout.finite? && timeout.positive?
|
|
62
|
+
raise ArgumentError, "command must not be empty" unless argv.is_a?(Array) && !argv.empty?
|
|
63
|
+
raise ArgumentError, "output limit must be positive" unless max_output.is_a?(Integer) && max_output.positive?
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def terminate(pid)
|
|
67
|
+
Process.kill("KILL", -pid)
|
|
68
|
+
rescue Errno::ESRCH
|
|
69
|
+
nil
|
|
70
|
+
ensure
|
|
71
|
+
begin
|
|
72
|
+
Process.waitpid(pid)
|
|
73
|
+
rescue Errno::ECHILD
|
|
74
|
+
nil
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def monotonic
|
|
79
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
80
|
+
end
|
|
81
|
+
private_class_method :collect, :drain, :validate!, :terminate, :monotonic
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require_relative "command"
|
|
2
|
+
require_relative "../benchmark/pressure/process_sample"
|
|
3
|
+
|
|
4
|
+
module Polyrun
|
|
5
|
+
module Quality
|
|
6
|
+
module Measure
|
|
7
|
+
module_function
|
|
8
|
+
|
|
9
|
+
def call(command, root:, timeout:, label:, ceilings: {}, max_output: Command::DEFAULT_OUTPUT_LIMIT)
|
|
10
|
+
validate_ceilings!(ceilings)
|
|
11
|
+
before = Process.times
|
|
12
|
+
result = Command.call(command, root: root, timeout: timeout, max_output: max_output)
|
|
13
|
+
metrics = process_metrics(before).merge("wall_s" => result["wall_s"])
|
|
14
|
+
failures = ceilings.keys.select { |key| !metrics[key].is_a?(Numeric) || metrics[key] > ceilings[key] }
|
|
15
|
+
result.merge("ok" => result["exitstatus"].zero? && failures.empty?, "label" => label, "metrics" => metrics,
|
|
16
|
+
"failures" => failures, "memory_probe_class" => "orchestrator_sample", "network" => "not_measured", "energy_proxy" => "cpu_seconds")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def process_metrics(before)
|
|
20
|
+
after = Process.times
|
|
21
|
+
rss = Benchmark::Pressure::ProcessSample.rss_bytes
|
|
22
|
+
{
|
|
23
|
+
"cpu_s" => after.utime + after.stime - before.utime - before.stime,
|
|
24
|
+
"child_cpu_s" => after.cutime + after.cstime - before.cutime - before.cstime,
|
|
25
|
+
"orchestrator_rss_bytes" => rss.positive? ? rss : nil
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def validate_ceilings!(ceilings)
|
|
30
|
+
raise ArgumentError, "ceilings must be an object" unless ceilings.is_a?(Hash)
|
|
31
|
+
unless ceilings.values.all? { |value| value.is_a?(Numeric) && value.finite? && value >= 0 }
|
|
32
|
+
raise ArgumentError, "ceilings must be finite nonnegative numbers"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
private_class_method :process_metrics, :validate_ceilings!
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "tmpdir"
|
|
3
|
+
require_relative "command"
|
|
4
|
+
|
|
5
|
+
module Polyrun
|
|
6
|
+
module Quality
|
|
7
|
+
module Observe
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def call(command, root:, output:, timeout: 300, limit: 10_000, max_output: Command::DEFAULT_OUTPUT_LIMIT, max_artifact_bytes: 16_777_216)
|
|
11
|
+
raise ArgumentError, "max entries must be positive" unless limit.is_a?(Integer) && limit.positive?
|
|
12
|
+
|
|
13
|
+
output = File.expand_path(output)
|
|
14
|
+
Dir.mktmpdir("polyrun-observe", File.dirname(output)) do |directory|
|
|
15
|
+
artifact = File.join(directory, "trace.json")
|
|
16
|
+
result = Command.call(command, root: root, timeout: timeout, max_output: max_output, env: environment(root, artifact, limit))
|
|
17
|
+
present = File.file?(artifact)
|
|
18
|
+
if present
|
|
19
|
+
validate_artifact!(artifact, max_artifact_bytes)
|
|
20
|
+
File.rename(artifact, output)
|
|
21
|
+
end
|
|
22
|
+
result["ok"] = result["exitstatus"].zero? && present
|
|
23
|
+
result["code"] = if !result["exitstatus"].zero?
|
|
24
|
+
"COMMAND_FAILED"
|
|
25
|
+
elsif present
|
|
26
|
+
"OBSERVED"
|
|
27
|
+
else
|
|
28
|
+
"TRACE_MISSING"
|
|
29
|
+
end
|
|
30
|
+
result
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def environment(root, artifact, limit)
|
|
35
|
+
library = File.expand_path("../..", __dir__)
|
|
36
|
+
{"POLYRUN_OBSERVE_ROOT" => File.realpath(root), "POLYRUN_OBSERVE_OUTPUT" => artifact,
|
|
37
|
+
"POLYRUN_OBSERVE_LIMIT" => limit.to_s, "POLYRUN_OBSERVE_RUBYOPT" => ENV["RUBYOPT"],
|
|
38
|
+
"RUBYLIB" => [library, ENV["RUBYLIB"]].compact.join(File::PATH_SEPARATOR),
|
|
39
|
+
"RUBYOPT" => "#{ENV["RUBYOPT"]} -rpolyrun/quality/observe_hook"}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def validate_artifact!(path, max_bytes)
|
|
43
|
+
raise ArgumentError, "observation artifact is too large" if File.size(path) > max_bytes
|
|
44
|
+
|
|
45
|
+
trace = JSON.parse(File.read(path))
|
|
46
|
+
unless trace.is_a?(Hash) && trace["calls"].is_a?(Array) && trace["provenance"] == "observed"
|
|
47
|
+
raise ArgumentError, "invalid observation artifact"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
private_class_method :environment, :validate_artifact!
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
module Polyrun
|
|
4
|
+
module Quality
|
|
5
|
+
module ObserveHook
|
|
6
|
+
class Recorder
|
|
7
|
+
def initialize(root, output, limit)
|
|
8
|
+
@root = File.realpath(root) + "/"
|
|
9
|
+
@output = output
|
|
10
|
+
@limit = limit
|
|
11
|
+
@calls = {}
|
|
12
|
+
@paths = {}
|
|
13
|
+
@owners = {}
|
|
14
|
+
@entries = 0
|
|
15
|
+
@truncated = false
|
|
16
|
+
@process = Process.pid
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def record(event)
|
|
20
|
+
path = relative_path(event.path)
|
|
21
|
+
return unless path
|
|
22
|
+
|
|
23
|
+
owner = event.defined_class
|
|
24
|
+
name = event.method_id
|
|
25
|
+
methods = @calls.dig(path, owner)
|
|
26
|
+
count = methods && methods[name]
|
|
27
|
+
if count
|
|
28
|
+
methods[name] = count + 1
|
|
29
|
+
elsif @entries < @limit
|
|
30
|
+
identity = owner_identity(event)
|
|
31
|
+
return unless identity
|
|
32
|
+
|
|
33
|
+
@owners[owner] = identity
|
|
34
|
+
methods ||= ((@calls[path] ||= {})[owner] ||= {})
|
|
35
|
+
methods[name] = 1
|
|
36
|
+
@entries += 1
|
|
37
|
+
else
|
|
38
|
+
@truncated = true
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def write
|
|
43
|
+
return unless Process.pid == @process
|
|
44
|
+
|
|
45
|
+
rows = @calls.flat_map do |path, owners|
|
|
46
|
+
owners.flat_map do |owner, methods|
|
|
47
|
+
name, separator = @owners.fetch(owner)
|
|
48
|
+
methods.map do |method, count|
|
|
49
|
+
{"path" => path, "owner" => name, "method" => method.to_s, "subject" => "#{name}#{separator}#{method}", "count" => count}
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
File.write(@output, JSON.generate("calls" => rows, "truncated" => @truncated, "provenance" => "observed"))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
def relative_path(source)
|
|
59
|
+
path = @paths[source]
|
|
60
|
+
if path.nil?
|
|
61
|
+
resolved = File.file?(source) ? File.realpath(source) : nil
|
|
62
|
+
path = resolved&.start_with?(@root) ? resolved.delete_prefix(@root) : false
|
|
63
|
+
@paths[source] = path if @paths.size < @limit
|
|
64
|
+
end
|
|
65
|
+
path
|
|
66
|
+
rescue Errno::ENOENT
|
|
67
|
+
false
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def owner_identity(event)
|
|
71
|
+
owner = event.defined_class
|
|
72
|
+
name = owner.name
|
|
73
|
+
separator = "#"
|
|
74
|
+
if owner.singleton_class? && event.self.is_a?(Module)
|
|
75
|
+
name = event.self.name
|
|
76
|
+
separator = "."
|
|
77
|
+
end
|
|
78
|
+
[name, separator] if name.is_a?(String) && !name.empty?
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
module_function
|
|
83
|
+
|
|
84
|
+
def install
|
|
85
|
+
root = ENV.delete("POLYRUN_OBSERVE_ROOT")
|
|
86
|
+
output = ENV.delete("POLYRUN_OBSERVE_OUTPUT")
|
|
87
|
+
limit = Integer(ENV.delete("POLYRUN_OBSERVE_LIMIT") || "10000")
|
|
88
|
+
ENV["RUBYOPT"] = ENV.delete("POLYRUN_OBSERVE_RUBYOPT")
|
|
89
|
+
return unless root && output
|
|
90
|
+
|
|
91
|
+
recorder = Recorder.new(root, output, limit)
|
|
92
|
+
trace = TracePoint.new(:call) { |event| recorder.record(event) }
|
|
93
|
+
at_exit do
|
|
94
|
+
trace.disable
|
|
95
|
+
recorder.write
|
|
96
|
+
end
|
|
97
|
+
trace.enable
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
Polyrun::Quality::ObserveHook.install
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require "digest"
|
|
2
|
+
require "fileutils"
|
|
3
|
+
require "find"
|
|
4
|
+
require_relative "../config/tools"
|
|
5
|
+
|
|
6
|
+
module Polyrun
|
|
7
|
+
module Quality
|
|
8
|
+
class Sandbox
|
|
9
|
+
attr_reader :bytes
|
|
10
|
+
|
|
11
|
+
def initialize(root, settings: {})
|
|
12
|
+
@settings = Config::Tools.merge(Config::ToolDefaults::STAGING, Config::Tools.stringify(settings))
|
|
13
|
+
errors = Config::ToolValidation.check(@settings, Config::ToolDefaults::STAGING, "staging")
|
|
14
|
+
raise ArgumentError, errors.join("; ") unless errors.empty?
|
|
15
|
+
|
|
16
|
+
@root = File.realpath(root)
|
|
17
|
+
@bytes = 0
|
|
18
|
+
@files = inventory
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def copy_to(destination)
|
|
22
|
+
@files.each do |relative, expected|
|
|
23
|
+
source = File.join(@root, relative)
|
|
24
|
+
raise ArgumentError, "project changed while staging" unless File.file?(source) && !File.symlink?(source) && Digest::SHA256.file(source).hexdigest == expected
|
|
25
|
+
|
|
26
|
+
target = File.join(destination, relative)
|
|
27
|
+
FileUtils.mkdir_p(File.dirname(target))
|
|
28
|
+
FileUtils.copy_file(source, target, true)
|
|
29
|
+
raise ArgumentError, "project changed while staging" unless Digest::SHA256.file(target).hexdigest == expected
|
|
30
|
+
end
|
|
31
|
+
destination
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.environment(destination)
|
|
35
|
+
{"BUNDLE_GEMFILE" => File.file?(File.join(destination, "Gemfile")) ? File.join(destination, "Gemfile") : nil,
|
|
36
|
+
"RUBYLIB" => [File.join(destination, "lib"), ENV["RUBYLIB"]].compact.join(File::PATH_SEPARATOR)}
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def inventory
|
|
42
|
+
files = {}
|
|
43
|
+
Find.find(@root) do |path|
|
|
44
|
+
next if path == @root
|
|
45
|
+
|
|
46
|
+
name = File.basename(path)
|
|
47
|
+
relative = path.delete_prefix("#{@root}/")
|
|
48
|
+
if excluded?(name) || @settings["exclude_paths"].any? { |pattern| File.fnmatch?(pattern, relative, File::FNM_PATHNAME) }
|
|
49
|
+
Find.prune if File.directory?(path)
|
|
50
|
+
next
|
|
51
|
+
end
|
|
52
|
+
raise ArgumentError, "symbolic links are not supported in staged projects" if File.symlink?(path)
|
|
53
|
+
next unless File.file?(path)
|
|
54
|
+
|
|
55
|
+
@bytes += File.size(path)
|
|
56
|
+
raise ArgumentError, "staged project exceeds configured file or byte limit" if @bytes > @settings["max_bytes"] || files.size >= @settings["max_files"]
|
|
57
|
+
|
|
58
|
+
files[path.delete_prefix("#{@root}/")] = Digest::SHA256.file(path).hexdigest
|
|
59
|
+
end
|
|
60
|
+
files
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def excluded?(name)
|
|
64
|
+
return true if name.start_with?(".") && !@settings["include_hidden"].include?(name)
|
|
65
|
+
|
|
66
|
+
@settings["exclude"].any? { |pattern| File.fnmatch?(pattern, name) } || name.end_with?(".key")
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -50,7 +50,7 @@ module Polyrun
|
|
|
50
50
|
# Writes {WorkerPing} after suite start, before/after each example (+location+ is file:line from metadata).
|
|
51
51
|
# Keeps +--worker-idle-timeout+ sensitive to example progress (not only a background thread).
|
|
52
52
|
def install_spec_quality!(only_if: nil, root: nil, output_path: nil)
|
|
53
|
-
pred = only_if || -> { Polyrun::SpecQuality.enabled? }
|
|
53
|
+
pred = only_if || -> { Polyrun::SpecQuality.enabled?(root: root || Dir.pwd) }
|
|
54
54
|
return unless pred.call
|
|
55
55
|
|
|
56
56
|
require_relative "spec_quality/rspec_hook"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "yaml"
|
|
2
|
+
require_relative "../config"
|
|
2
3
|
|
|
3
4
|
module Polyrun
|
|
4
5
|
module SpecQuality
|
|
@@ -25,10 +26,12 @@ module Polyrun
|
|
|
25
26
|
|
|
26
27
|
module_function
|
|
27
28
|
|
|
28
|
-
def enabled?(env = ENV)
|
|
29
|
+
def enabled?(env = ENV, root: Dir.pwd)
|
|
29
30
|
return false if disabled?(env)
|
|
30
31
|
|
|
31
|
-
truthy?(env["POLYRUN_SPEC_QUALITY"]) || truthy?(env["POLYRUN_SPEC_QUALITY_FRAGMENTS"])
|
|
32
|
+
return true if truthy?(env["POLYRUN_SPEC_QUALITY"]) || truthy?(env["POLYRUN_SPEC_QUALITY_FRAGMENTS"])
|
|
33
|
+
|
|
34
|
+
Polyrun::Config::Tools.spec_quality(root: root, env: env)["enabled"] == true
|
|
32
35
|
end
|
|
33
36
|
|
|
34
37
|
def disabled?(env = ENV)
|
|
@@ -38,7 +41,9 @@ module Polyrun
|
|
|
38
41
|
def load(root:, config_path: nil, env: ENV, **overrides)
|
|
39
42
|
root = File.expand_path(root)
|
|
40
43
|
file_cfg = load_yaml(root, config_path)
|
|
41
|
-
|
|
44
|
+
shared = Polyrun::Config::Tools.spec_quality(root: root, env: env).except("enabled")
|
|
45
|
+
merged = DEFAULTS.merge(stringify_keys(file_cfg)).merge(shared)
|
|
46
|
+
merged.merge!(stringify_keys(file_cfg)) if config_path
|
|
42
47
|
apply_env!(merged, env)
|
|
43
48
|
merged.merge!(stringify_keys(overrides).transform_keys(&:to_s))
|
|
44
49
|
merged["root"] = root
|
data/lib/polyrun/spec_quality.rb
CHANGED
|
@@ -37,8 +37,8 @@ module Polyrun
|
|
|
37
37
|
instance_variable_defined?(:@config) && @config
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
def enabled?
|
|
41
|
-
Config.enabled? && !Config.disabled?
|
|
40
|
+
def enabled?(root: Dir.pwd)
|
|
41
|
+
Config.enabled?(ENV, root: root) && !Config.disabled?
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
attr_reader :config
|
|
@@ -130,8 +130,7 @@ module Polyrun
|
|
|
130
130
|
|
|
131
131
|
def spec_quality_requested_for_quick?(root = Dir.pwd)
|
|
132
132
|
return false if Config.disabled?
|
|
133
|
-
return true if
|
|
134
|
-
return true if %w[1 true yes].include?(ENV["POLYRUN_SPEC_QUALITY_FRAGMENTS"]&.to_s&.downcase)
|
|
133
|
+
return true if Config.enabled?(ENV, root: root)
|
|
135
134
|
|
|
136
135
|
path = File.join(File.expand_path(root), Config::DEFAULT_CONFIG_RELATIVE)
|
|
137
136
|
return false unless File.file?(path)
|
data/lib/polyrun/version.rb
CHANGED
|
@@ -52,40 +52,16 @@ module Polyrun
|
|
|
52
52
|
|
|
53
53
|
def spawn_worker(child_env, cmd, paths, hook_cfg)
|
|
54
54
|
shard = child_env.fetch("POLYRUN_SHARD_INDEX", "?")
|
|
55
|
+
log_io = File.open(log_path_for(shard), "wb")
|
|
55
56
|
out_read, out_write = IO.pipe
|
|
56
57
|
err_read, err_write = IO.pipe
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
child_env,
|
|
63
|
-
"sh",
|
|
64
|
-
"-c",
|
|
65
|
-
hook_cfg.build_worker_shell_script(cmd, paths),
|
|
66
|
-
out: out_write,
|
|
67
|
-
err: err_write,
|
|
68
|
-
pgroup: true
|
|
69
|
-
)
|
|
70
|
-
else
|
|
71
|
-
# Array(cmd) so a String command is one argv element (not character-splatted).
|
|
72
|
-
Process.spawn(
|
|
73
|
-
child_env,
|
|
74
|
-
*Array(cmd),
|
|
75
|
-
*Array(paths),
|
|
76
|
-
out: out_write,
|
|
77
|
-
err: err_write,
|
|
78
|
-
pgroup: true
|
|
79
|
-
)
|
|
80
|
-
end
|
|
81
|
-
rescue
|
|
82
|
-
[out_read, out_write, err_read, err_write].each do |io|
|
|
83
|
-
io.close unless io.closed?
|
|
84
|
-
rescue IOError
|
|
85
|
-
nil
|
|
86
|
-
end
|
|
87
|
-
raise
|
|
59
|
+
argv = if hook_cfg.worker_hooks? && !Polyrun::Hooks.disabled?
|
|
60
|
+
["sh", "-c", hook_cfg.build_worker_shell_script(cmd, paths)]
|
|
61
|
+
else
|
|
62
|
+
Array(cmd) + Array(paths)
|
|
88
63
|
end
|
|
64
|
+
pid = Process.spawn(child_env, *argv, out: out_write, err: err_write, pgroup: true)
|
|
89
65
|
|
|
90
66
|
out_write.close
|
|
91
67
|
err_write.close
|
|
@@ -95,16 +71,32 @@ module Polyrun
|
|
|
95
71
|
shard: shard,
|
|
96
72
|
stdout_io: out_read,
|
|
97
73
|
stderr_io: err_read,
|
|
98
|
-
|
|
74
|
+
log_io: log_io
|
|
99
75
|
)
|
|
100
76
|
pid
|
|
77
|
+
rescue
|
|
78
|
+
[log_io, out_read, out_write, err_read, err_write].compact.each do |io|
|
|
79
|
+
io.close unless io.closed?
|
|
80
|
+
rescue IOError
|
|
81
|
+
nil
|
|
82
|
+
end
|
|
83
|
+
raise unless pid
|
|
84
|
+
|
|
85
|
+
begin
|
|
86
|
+
Process.kill("KILL", -pid)
|
|
87
|
+
rescue Errno::ESRCH
|
|
88
|
+
nil
|
|
89
|
+
ensure
|
|
90
|
+
Process.waitpid(pid)
|
|
91
|
+
end
|
|
92
|
+
raise
|
|
101
93
|
end
|
|
102
94
|
|
|
103
|
-
def start_forwarders(pid:, shard:, stdout_io:, stderr_io:,
|
|
95
|
+
def start_forwarders(pid:, shard:, stdout_io:, stderr_io:, log_io:)
|
|
104
96
|
forwarder = WorkerForwarder.new(
|
|
105
97
|
shard: shard,
|
|
106
98
|
pid: pid,
|
|
107
|
-
|
|
99
|
+
log_io: log_io,
|
|
108
100
|
prefix_live: prefix_live?
|
|
109
101
|
)
|
|
110
102
|
threads = [
|
|
@@ -18,14 +18,18 @@ module Polyrun
|
|
|
18
18
|
|
|
19
19
|
@mutex.synchronize do
|
|
20
20
|
if progress_chunk?(chunk)
|
|
21
|
-
write_tty(chunk)
|
|
21
|
+
write_tty(chunk) if @prefix_live
|
|
22
22
|
@log_io&.write(chunk)
|
|
23
23
|
return
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
offset = @buffer.length
|
|
26
27
|
@buffer << chunk
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
line_prefix = nil
|
|
29
|
+
while (newline_index = @buffer.index("\n", offset))
|
|
30
|
+
line_prefix ||= prefix
|
|
31
|
+
emit_line(@buffer.slice!(0, newline_index + 1), line_prefix)
|
|
32
|
+
offset = 0
|
|
29
33
|
end
|
|
30
34
|
end
|
|
31
35
|
end
|
|
@@ -45,8 +49,8 @@ module Polyrun
|
|
|
45
49
|
chunk.include?("\r") && !chunk.include?("\n")
|
|
46
50
|
end
|
|
47
51
|
|
|
48
|
-
def emit_line(line)
|
|
49
|
-
prefixed = "#{
|
|
52
|
+
def emit_line(line, line_prefix = prefix)
|
|
53
|
+
prefixed = "#{line_prefix}#{line}"
|
|
50
54
|
@log_io&.write(prefixed)
|
|
51
55
|
write_tty(prefixed) if @prefix_live
|
|
52
56
|
end
|
|
@@ -62,10 +66,10 @@ module Polyrun
|
|
|
62
66
|
end
|
|
63
67
|
|
|
64
68
|
class WorkerForwarder
|
|
65
|
-
def initialize(shard:, pid:,
|
|
69
|
+
def initialize(shard:, pid:, log_io:, prefix_live:)
|
|
66
70
|
@shard = shard
|
|
67
71
|
@pid = pid
|
|
68
|
-
@log_io =
|
|
72
|
+
@log_io = log_io
|
|
69
73
|
@stdout = LineForwarder.new(shard: shard, pid: pid, log_io: @log_io, prefix_live: prefix_live, tty_io: Polyrun::Log.stdout)
|
|
70
74
|
@stderr = LineForwarder.new(shard: shard, pid: pid, log_io: @log_io, prefix_live: prefix_live, tty_io: Polyrun::Log.stderr)
|
|
71
75
|
@write_mutex = Mutex.new
|
data/lib/polyrun.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require_relative "polyrun/version"
|
|
2
|
+
require_relative "polyrun/error"
|
|
2
3
|
require_relative "polyrun/log"
|
|
3
4
|
require_relative "polyrun/debug"
|
|
4
5
|
require_relative "polyrun/config"
|
|
@@ -39,8 +40,6 @@ if defined?(Rails::Railtie)
|
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
module Polyrun
|
|
42
|
-
class Error < StandardError; end
|
|
43
|
-
|
|
44
43
|
# Delegate to {Polyrun::Log} for swappable stderr/stdout (CLI and library messages).
|
|
45
44
|
def self.stderr=(io)
|
|
46
45
|
Log.stderr = io
|
data/polyrun.gemspec
CHANGED
|
@@ -6,23 +6,28 @@ Gem::Specification.new do |spec|
|
|
|
6
6
|
spec.authors = ["Andrei Makarov"]
|
|
7
7
|
spec.email = ["contact@kiskolabs.com"]
|
|
8
8
|
spec.summary = "Parallel tests, coverage (SimpleCov-compatible) formatters, fixtures/snapshots, assets & DB provisioning—zero runtime deps"
|
|
9
|
+
spec.description = "Polyrun runs parallel test shards, merges SimpleCov-compatible coverage, emits CI reports, and prepares fixtures, snapshots, assets, and databases. It ships with no runtime gem dependencies beyond the standard library and vendored or native code."
|
|
9
10
|
spec.homepage = "https://github.com/amkisko/polyrun.rb"
|
|
10
11
|
spec.license = "MIT"
|
|
11
12
|
spec.required_ruby_version = ">= 3.4"
|
|
12
13
|
|
|
13
14
|
spec.files = (
|
|
14
|
-
Dir["lib/**/*", "sig/**/*.rbs", "bin/polyrun", "README.md", "CHANGELOG.md", "docs/SETUP_PROFILE.md", "LICENSE", "CONTRIBUTING.md", "CODE_OF_CONDUCT.md", "SECURITY.md", "polyrun.gemspec"] +
|
|
15
|
+
Dir["lib/**/*", "sig/**/*.rbs", "bin/polyrun", "README.md", "CHANGELOG.md", "docs/SETUP_PROFILE.md", "docs/QUALITY.md", "docs/QUALITY_CONFIGURATION.md", "LICENSE", "CONTRIBUTING.md", "CODE_OF_CONDUCT.md", "SECURITY.md", "polyrun.gemspec"] +
|
|
15
16
|
Dir["ext/**/extconf.rb", "ext/**/*.c", "ext/**/*.h"]
|
|
16
17
|
).uniq.reject { |f| File.directory?(f) }
|
|
17
18
|
spec.bindir = "bin"
|
|
18
19
|
spec.executables = ["polyrun"]
|
|
19
20
|
spec.require_paths = ["lib"]
|
|
20
21
|
spec.extensions = ["ext/polyrun_coverage_merge/extconf.rb"]
|
|
22
|
+
spec.extra_rdoc_files = %w[README.md CHANGELOG.md LICENSE CONTRIBUTING.md CODE_OF_CONDUCT.md SECURITY.md]
|
|
21
23
|
|
|
22
24
|
spec.metadata = {
|
|
23
25
|
"homepage_uri" => spec.homepage,
|
|
26
|
+
"source_code_uri" => "#{spec.homepage}/tree/main",
|
|
27
|
+
"changelog_uri" => "#{spec.homepage}/blob/main/CHANGELOG.md",
|
|
24
28
|
"bug_tracker_uri" => "#{spec.homepage}/issues",
|
|
25
29
|
"documentation_uri" => "#{spec.homepage}#readme",
|
|
30
|
+
"allowed_push_host" => "https://rubygems.org",
|
|
26
31
|
"rubygems_mfa_required" => "true"
|
|
27
32
|
}
|
|
28
33
|
|
data/sig/polyrun/config.rbs
CHANGED
|
@@ -5,8 +5,8 @@ module Polyrun
|
|
|
5
5
|
attr_reader path: String?
|
|
6
6
|
attr_reader raw: untyped
|
|
7
7
|
|
|
8
|
-
def self.load: (?path: String?) -> Config
|
|
9
|
-
def self.resolve_path: (String? explicit) -> String?
|
|
8
|
+
def self.load: (?path: String?, ?suite: String?, ?root: String) -> Config
|
|
9
|
+
def self.resolve_path: (String? explicit, ?root: String) -> String?
|
|
10
10
|
|
|
11
11
|
def initialize: (path: String?, raw: untyped) -> void
|
|
12
12
|
|