polyrun 3.1.0 → 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 +9 -0
- data/README.md +12 -0
- data/docs/QUALITY.md +4 -2
- data/ext/polyrun_coverage_merge/coverage_merge.c +13 -26
- data/lib/polyrun/cli/run_shards_parallel_wait.rb +48 -70
- data/lib/polyrun/cli/run_shards_worker_interrupt.rb +16 -0
- 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/mutation/runner.rb +3 -1
- data/lib/polyrun/process_stdio.rb +13 -8
- 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 +5 -0
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 481c332f389796e80cab9f642f3b5b4c55320cfcf7c2fb1557a50503dccb9fcd
|
|
4
|
+
data.tar.gz: 603f44f8a26fc7df0f9305ac7813c2724bbe314d0a4d8046fea8fb2bcaeed9db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 69818cd763ba3c92414d11c4e09ddb7aa721daeb009e2fbd8416dd34f0a71e483a7f7264340a09bac3087a581eea53c52d2bc5ffaa7bc9d5f8015f3438638fec
|
|
7
|
+
data.tar.gz: 2b0b83322cd207d95f05021eff360ad8e42a8ff58e0e5b6c673074f029cef13cf2e04429c3501e17690f7b90e18c8f8bf54597166e50f3b469958ad770ab2f16
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 3.2.0 (2026-12-01)
|
|
4
|
+
|
|
5
|
+
- Add the experimental `polyrun-legacy` gem for local and CI sharding, suite configuration, preparation, and test reports on MRI Ruby 1.8.7 and newer on POSIX. The Legacy smoke check also runs on JRuby and TruffleRuby Native.
|
|
6
|
+
- Give the mutation baseline at least five seconds and use the configured timeout for each mutation.
|
|
7
|
+
- Build an extension-free `java` gem for JRuby and exercise installed sharding and artifact reporting on JRuby and TruffleRuby Native (RFC 0012).
|
|
8
|
+
- Handle `SIGINT` and `SIGTERM` while waiting for shard workers on JRuby and TruffleRuby so worker groups stop before Polyrun exits.
|
|
9
|
+
- Accept TruffleRuby's line coverage format for per-example deltas and report unavailable branch coverage before starting collection.
|
|
10
|
+
- Add a maintainer smoke run for a Spinel-compiled shard worker using the Polyrun legacy partition library.
|
|
11
|
+
|
|
3
12
|
## 3.1.0 (2026-11-14)
|
|
4
13
|
|
|
5
14
|
- Run graph indexing, curated mutation, observe, and measure against this repository (`make quality-self`, quality CI).
|
data/README.md
CHANGED
|
@@ -6,6 +6,18 @@ Use `polyrun graph` for guarded Ruby graph edits, `polyrun mutate` for mutation
|
|
|
6
6
|
|
|
7
7
|
Design changes go through `rfcs/` (RFC 0001).
|
|
8
8
|
|
|
9
|
+
## Ruby support
|
|
10
|
+
|
|
11
|
+
- `polyrun` requires Ruby 3.4 or newer. The main test suite runs on MRI 3.4 and 4.0.
|
|
12
|
+
- Experimental JRuby and TruffleRuby checks cover installation, local and CI sharding, and coverage, timing, failure, and JUnit reports from existing artifacts. JRuby 10.0.8.0 with JDK 21 uses the `java` gem and the Ruby coverage merger. TruffleRuby Native 40.1.0 uses the standard source gem and builds its C extension. The [compatibility workflow](.github/workflows/alternative-rubies.yml) exercises both on Linux x86-64.
|
|
13
|
+
- [`polyrun-legacy`](legacy/README.md) is a separate, experimental gem for MRI Ruby 1.8.7 and newer on POSIX. It provides local and CI sharding, suite configuration, preparation, and coverage, timing, and failure reports. The Legacy smoke check also runs on JRuby and TruffleRuby Native.
|
|
14
|
+
|
|
15
|
+
To check the main gem on another Ruby implementation, set `POLYRUN_ENGINE_RUBY` to the target executable and run `make smoke-engine`. The target builds the Ruby and Java variants of `polyrun` and checks the installed CLI and Bundler's package selection using those local artifacts.
|
|
16
|
+
|
|
17
|
+
JRuby 10.0.8.0 and TruffleRuby Native 40.1.0 collect line coverage. Leave `POLYRUN_COVERAGE_BRANCHES` unset for collection on these releases. You can merge existing branch coverage fragments on either engine.
|
|
18
|
+
|
|
19
|
+
Polyrun can run a Spinel-compiled executable as a shard worker. Set `POLYRUN_SPINEL` to the compiler executable and run `make smoke-spinel` to compile and run a worker that uses the legacy partition library. For full CLI compatibility, see the [Spinel probe](docs/issues/20261201172900_alternative-ruby-implementations.md).
|
|
20
|
+
|
|
9
21
|
## Why?
|
|
10
22
|
|
|
11
23
|
Running tests in parallel across processes still requires a single merged coverage report, stable shard assignment, isolated databases per worker so rows are not shared, and reliable timing data for cost-based splits—without wiring together many small tools and shell scripts.
|
data/docs/QUALITY.md
CHANGED
|
@@ -33,7 +33,9 @@ A change description is JSON or safe YAML:
|
|
|
33
33
|
|
|
34
34
|
Take the snapshot and call fields from index and inspect output. Planning supports this operation only, with a default ceiling of 1,000 distinct call edits. It validates expected tokens, applies byte edits to an isolated project copy, checks Ruby syntax, and emits a bounded diff. It does not rename every definition or infer dispatch equivalence.
|
|
35
35
|
|
|
36
|
-
Check verifies that sources are unchanged, syntax is valid, and the intended staged hashes match. An optional prove command runs in the staged tree; its Gemfile and library path point there. Tests that explicitly load an outside checkout
|
|
36
|
+
Check verifies that sources are unchanged, syntax is valid, and the intended staged hashes match. An optional prove command runs in the staged tree; its Gemfile and library path point there. Tests that explicitly load an outside checkout do not validate the staged edit. A successful check creates a receipt binding metadata and all staged files. A failed prove revokes previous approval. Apply rejects missing receipts, changed staged files, changed originals, added source files, symbolic links, and overlapping graph commands.
|
|
37
|
+
|
|
38
|
+
`--prove` accepts the selected command's exit status; it does not establish a mathematical proof. Test success covers the executions tested. The selected command must return failure when its required checks fail or remain incomplete. Receipts bind staged bytes; they do not certify external commands, loaded dependencies, or runtime method lookup.
|
|
37
39
|
|
|
38
40
|
Apply uses per-file atomic replacement with backups and a recovery journal. An ordinary write failure restores originals. If the process stops during apply, the next apply attempts recovery before verifying that sources are unchanged. Recovery refuses to overwrite an unrelated edit. This is a cooperative local editing protocol; it does not provide a whole-tree atomic filesystem commit, protection from concurrent non-cooperating writers, or certified power-loss durability.
|
|
39
41
|
|
|
@@ -65,7 +67,7 @@ Run the project's normal parallel suite and coverage merge before a narrower mut
|
|
|
65
67
|
bundle exec polyrun run-shards --workers 2 --merge-coverage -- bundle exec rspec
|
|
66
68
|
bundle exec polyrun mutate --enable --subjects-file subjects.txt --shard 1 --total 3 --workers 2 --output mutation-1.json -- bundle exec rspec
|
|
67
69
|
|
|
68
|
-
Repeat the mutation job for shard numbers 1 through 3 with the same subject file. Mutation shard numbers are one-based; the existing worker environment uses its own documented index convention. Keep each job's report as an artifact and use the command's status as its gate. Use `graph check PLAN --prove -- bundle exec rspec` to
|
|
70
|
+
Repeat the mutation job for shard numbers 1 through 3 with the same subject file. Mutation shard numbers are one-based; the existing worker environment uses its own documented index convention. Keep each job's report as an artifact and use the command's status as its gate. Use `graph check PLAN --prove -- bundle exec rspec` to test a staged edit before apply. These commands stay independently useful; a graph plan is not required for mutation testing.
|
|
69
71
|
|
|
70
72
|
## Observation and measurement
|
|
71
73
|
|
|
@@ -19,6 +19,10 @@ static ID id_sort_branches_for_native;
|
|
|
19
19
|
static ID id_keys;
|
|
20
20
|
static ID id_plus;
|
|
21
21
|
static ID id_gt;
|
|
22
|
+
static ID id_line_hit_to_i;
|
|
23
|
+
static ID id_to_i;
|
|
24
|
+
|
|
25
|
+
static VALUE merge_module_value(void);
|
|
22
26
|
|
|
23
27
|
static VALUE str_ignored;
|
|
24
28
|
static VALUE ary_empty_lines;
|
|
@@ -42,21 +46,7 @@ line_hit_to_i(VALUE value)
|
|
|
42
46
|
if (RB_TYPE_P(value, T_FIXNUM) || RB_TYPE_P(value, T_BIGNUM)) {
|
|
43
47
|
return value;
|
|
44
48
|
}
|
|
45
|
-
|
|
46
|
-
const char *text = StringValueCStr(value);
|
|
47
|
-
char *end = NULL;
|
|
48
|
-
long number = strtol(text, &end, 10);
|
|
49
|
-
if (end != text && *end == '\0') {
|
|
50
|
-
return LONG2FIX(number);
|
|
51
|
-
}
|
|
52
|
-
return Qnil;
|
|
53
|
-
}
|
|
54
|
-
if (RB_TYPE_P(value, T_SYMBOL)) {
|
|
55
|
-
VALUE as_string = rb_sym2str(value);
|
|
56
|
-
return line_hit_to_i(as_string);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return Qnil;
|
|
49
|
+
return rb_funcall(merge_module_value(), id_line_hit_to_i, 1, value);
|
|
60
50
|
}
|
|
61
51
|
|
|
62
52
|
static int
|
|
@@ -112,7 +102,7 @@ merge_line_hits(VALUE left, VALUE right)
|
|
|
112
102
|
|
|
113
103
|
if (!NIL_P(left_i) && !NIL_P(right_i)) {
|
|
114
104
|
if (RB_FIXNUM_P(left_i) && RB_FIXNUM_P(right_i)) {
|
|
115
|
-
return
|
|
105
|
+
return LONG2NUM(FIX2LONG(left_i) + FIX2LONG(right_i));
|
|
116
106
|
}
|
|
117
107
|
return rb_funcall(left_i, id_plus, 1, right_i);
|
|
118
108
|
}
|
|
@@ -137,12 +127,9 @@ merge_line_arrays(VALUE left, VALUE right)
|
|
|
137
127
|
long max_len = left_len > right_len ? left_len : right_len;
|
|
138
128
|
VALUE out = rb_ary_new2(max_len);
|
|
139
129
|
|
|
140
|
-
const VALUE *left_ptr = RARRAY_CONST_PTR(left);
|
|
141
|
-
const VALUE *right_ptr = RARRAY_CONST_PTR(right);
|
|
142
|
-
|
|
143
130
|
for (long index = 0; index < max_len; index++) {
|
|
144
|
-
VALUE left_hit =
|
|
145
|
-
VALUE right_hit =
|
|
131
|
+
VALUE left_hit = rb_ary_entry(left, index);
|
|
132
|
+
VALUE right_hit = rb_ary_entry(right, index);
|
|
146
133
|
rb_ary_store(out, index, merge_line_hits(left_hit, right_hit));
|
|
147
134
|
}
|
|
148
135
|
|
|
@@ -179,12 +166,10 @@ static VALUE
|
|
|
179
166
|
coverage_count(VALUE branch)
|
|
180
167
|
{
|
|
181
168
|
VALUE coverage = hash_field(branch, str_coverage, id_coverage);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return LONG2FIX(0);
|
|
169
|
+
if (RB_INTEGER_TYPE_P(coverage)) {
|
|
170
|
+
return coverage;
|
|
185
171
|
}
|
|
186
|
-
|
|
187
|
-
return as_int;
|
|
172
|
+
return rb_funcall(coverage, id_to_i, 0);
|
|
188
173
|
}
|
|
189
174
|
|
|
190
175
|
static VALUE
|
|
@@ -486,6 +471,8 @@ Init_polyrun_coverage_merge(void)
|
|
|
486
471
|
id_keys = rb_intern("keys");
|
|
487
472
|
id_plus = rb_intern("+");
|
|
488
473
|
id_gt = rb_intern(">");
|
|
474
|
+
id_line_hit_to_i = rb_intern("line_hit_to_i");
|
|
475
|
+
id_to_i = rb_intern("to_i");
|
|
489
476
|
str_lines = rb_obj_freeze(rb_str_new_cstr("lines"));
|
|
490
477
|
str_branches = rb_obj_freeze(rb_str_new_cstr("branches"));
|
|
491
478
|
str_type = rb_obj_freeze(rb_str_new_cstr("type"));
|
|
@@ -23,13 +23,15 @@ module Polyrun
|
|
|
23
23
|
idle_sec = ctx[:worker_idle_timeout_sec]
|
|
24
24
|
idle_sec = nil if idle_sec.is_a?(Numeric) && idle_sec <= 0
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
run_shards_with_interrupt_handlers do
|
|
27
|
+
Polyrun::Debug.time("Process.wait (#{pids.size} worker process(es))") do
|
|
28
|
+
if timeout_sec || idle_sec
|
|
29
|
+
run_shards_wait_all_children_multiplex(
|
|
30
|
+
pids, hook_cfg, ctx, workers, timeout_sec, idle_sec, shard_results, after_hook_err
|
|
31
|
+
)
|
|
32
|
+
else
|
|
33
|
+
run_shards_wait_all_children_sequential(pids, hook_cfg, workers, shard_results, after_hook_err)
|
|
34
|
+
end
|
|
33
35
|
end
|
|
34
36
|
rescue Interrupt
|
|
35
37
|
run_shards_shutdown_on_signal!(pids, 130)
|
|
@@ -67,41 +69,38 @@ module Polyrun
|
|
|
67
69
|
return [shard_results, after_hook_err] if pending.empty?
|
|
68
70
|
|
|
69
71
|
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
70
|
-
violation = run_shards_timeout_violation(
|
|
72
|
+
violation = run_shards_timeout_violation(pending, ctx, now, timeout_sec, idle_sec)
|
|
71
73
|
if violation
|
|
72
74
|
reason, timed_h = violation
|
|
73
|
-
|
|
74
|
-
case reason
|
|
75
|
+
code = case reason
|
|
75
76
|
when :wall_timeout
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
)
|
|
77
|
+
run_shards_warn_worker_timeout!(timed_h, ctx, timeout_sec)
|
|
78
|
+
WORKER_TIMEOUT_EXIT_STATUS
|
|
79
79
|
when :idle_timeout
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
)
|
|
80
|
+
run_shards_warn_worker_idle!(timed_h, ctx, idle_sec)
|
|
81
|
+
WORKER_IDLE_TIMEOUT_EXIT_STATUS
|
|
83
82
|
end
|
|
83
|
+
return run_shards_wait_flush_after_timeout!(
|
|
84
|
+
timed_h, pending, hook_cfg, code, workers, shard_results, after_hook_err
|
|
85
|
+
)
|
|
84
86
|
end
|
|
85
87
|
|
|
86
|
-
|
|
88
|
+
delay = timeout_sec ? run_shards_wall_deadline(pending.first, ctx, timeout_sec) - now : 0.2
|
|
89
|
+
sleep([0.2, delay].min)
|
|
87
90
|
end
|
|
88
91
|
end
|
|
89
92
|
|
|
90
93
|
# @return [(Symbol, Hash), nil] e.g. +[:wall_timeout, h]+ when a limit is exceeded
|
|
91
|
-
def run_shards_timeout_violation(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
spawned_at = h[:spawned_at] || ctx[:run_t0]
|
|
97
|
-
return [:wall_timeout, h] if now >= spawned_at + timeout_sec
|
|
98
|
-
end
|
|
94
|
+
def run_shards_timeout_violation(pending, ctx, now, timeout_sec, idle_sec)
|
|
95
|
+
# Polling removes completed workers in place, preserving spawn order.
|
|
96
|
+
first = pending.first
|
|
97
|
+
if timeout_sec && now >= run_shards_wall_deadline(first, ctx, timeout_sec)
|
|
98
|
+
return [:wall_timeout, first]
|
|
99
99
|
end
|
|
100
|
+
return unless idle_sec
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
next unless
|
|
103
|
-
|
|
104
|
-
next unless idle_sec && idle_sec > 0 && h[:ping_path]
|
|
102
|
+
pending.each do |h|
|
|
103
|
+
next unless h[:ping_path]
|
|
105
104
|
|
|
106
105
|
t, = run_shards_read_worker_ping_payload(h[:ping_path])
|
|
107
106
|
return [:idle_timeout, h] if t && (now - t) > idle_sec
|
|
@@ -110,16 +109,22 @@ module Polyrun
|
|
|
110
109
|
nil
|
|
111
110
|
end
|
|
112
111
|
|
|
112
|
+
def run_shards_wall_deadline(worker, ctx, timeout_sec)
|
|
113
|
+
(worker[:spawned_at] || ctx[:run_t0]) + timeout_sec
|
|
114
|
+
end
|
|
115
|
+
|
|
113
116
|
def run_shards_finalize_reaped_worker!(h, hook_cfg, workers, st, shard_results, after_hook_err)
|
|
117
|
+
exitstatus = st.exitstatus || (128 + st.termsig)
|
|
118
|
+
Polyrun::Debug.log("[parent pid=#{$$}] run-shards: Process.wait child_pid=#{h[:pid]} shard=#{h[:shard]} exit=#{exitstatus} success=#{st.success?}")
|
|
119
|
+
run_shards_finalize_worker!(h, hook_cfg, workers, exitstatus, shard_results, after_hook_err)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def run_shards_finalize_worker!(h, hook_cfg, workers, exitstatus, shard_results, after_hook_err)
|
|
114
123
|
Polyrun::WorkerOutput.finish_worker(h[:pid])
|
|
115
|
-
exitstatus = st.exitstatus
|
|
116
|
-
ok = st.success?
|
|
117
|
-
Polyrun::Debug.log("[parent pid=#{$$}] run-shards: Process.wait child_pid=#{h[:pid]} shard=#{h[:shard]} exit=#{exitstatus} success=#{ok}")
|
|
118
|
-
rc = run_shards_invoke_after_shard!(hook_cfg, h[:shard], workers, exitstatus)
|
|
119
|
-
after_hook_err = rc if rc != 0 && after_hook_err == 0
|
|
120
|
-
shard_results << {shard: h[:shard], exitstatus: exitstatus, success: ok}
|
|
121
124
|
run_shards_unlink_ping_path(h[:ping_path])
|
|
122
|
-
|
|
125
|
+
rc = run_shards_invoke_after_shard!(hook_cfg, h[:shard], workers, exitstatus)
|
|
126
|
+
shard_results << {shard: h[:shard], exitstatus: exitstatus, success: exitstatus == 0}
|
|
127
|
+
after_hook_err.zero? ? rc : after_hook_err
|
|
123
128
|
end
|
|
124
129
|
|
|
125
130
|
def run_shards_unlink_ping_path(path)
|
|
@@ -155,42 +160,15 @@ module Polyrun
|
|
|
155
160
|
[nil, nil]
|
|
156
161
|
end
|
|
157
162
|
|
|
158
|
-
def
|
|
159
|
-
run_shards_warn_worker_idle!(timed_h, ctx, idle_sec)
|
|
163
|
+
def run_shards_wait_flush_after_timeout!(timed_h, pending, hook_cfg, code, workers, shard_results, after_hook_err)
|
|
160
164
|
run_shards_force_stop_pid_status(timed_h[:pid])
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
shard_results << {shard: timed_h[:shard], exitstatus: WORKER_IDLE_TIMEOUT_EXIT_STATUS, success: false}
|
|
165
|
-
others.each do |h2|
|
|
166
|
-
st2 = run_shards_wait_or_force_stop_status(h2[:pid])
|
|
167
|
-
exit2 = st2&.exitstatus
|
|
168
|
-
ok2 = st2 ? st2.success? : false
|
|
169
|
-
exit2 = WORKER_IDLE_TIMEOUT_EXIT_STATUS if exit2.nil?
|
|
170
|
-
run_shards_unlink_ping_path(h2[:ping_path])
|
|
171
|
-
rc2 = run_shards_invoke_after_shard!(hook_cfg, h2[:shard], workers, exit2)
|
|
172
|
-
after_hook_err = rc2 if rc2 != 0 && after_hook_err == 0
|
|
173
|
-
shard_results << {shard: h2[:shard], exitstatus: exit2, success: ok2}
|
|
165
|
+
pending.delete(timed_h)
|
|
166
|
+
statuses = pending.map do |worker|
|
|
167
|
+
run_shards_wait_or_force_stop_status(worker[:pid])&.exitstatus || code
|
|
174
168
|
end
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
def run_shards_wait_flush_after_worker_timeout!(timed_h, others, hook_cfg, ctx, timeout_sec, workers, shard_results, after_hook_err)
|
|
179
|
-
run_shards_warn_worker_timeout!(timed_h, ctx, timeout_sec)
|
|
180
|
-
run_shards_force_stop_pid_status(timed_h[:pid])
|
|
181
|
-
run_shards_unlink_ping_path(timed_h[:ping_path])
|
|
182
|
-
rc = run_shards_invoke_after_shard!(hook_cfg, timed_h[:shard], workers, WORKER_TIMEOUT_EXIT_STATUS)
|
|
183
|
-
after_hook_err = rc if rc != 0 && after_hook_err == 0
|
|
184
|
-
shard_results << {shard: timed_h[:shard], exitstatus: WORKER_TIMEOUT_EXIT_STATUS, success: false}
|
|
185
|
-
others.each do |h2|
|
|
186
|
-
st2 = run_shards_wait_or_force_stop_status(h2[:pid])
|
|
187
|
-
exit2 = st2&.exitstatus
|
|
188
|
-
ok2 = st2 ? st2.success? : false
|
|
189
|
-
exit2 = WORKER_TIMEOUT_EXIT_STATUS if exit2.nil?
|
|
190
|
-
run_shards_unlink_ping_path(h2[:ping_path])
|
|
191
|
-
rc2 = run_shards_invoke_after_shard!(hook_cfg, h2[:shard], workers, exit2)
|
|
192
|
-
after_hook_err = rc2 if rc2 != 0 && after_hook_err == 0
|
|
193
|
-
shard_results << {shard: h2[:shard], exitstatus: exit2, success: ok2}
|
|
169
|
+
after_hook_err = run_shards_finalize_worker!(timed_h, hook_cfg, workers, code, shard_results, after_hook_err)
|
|
170
|
+
pending.zip(statuses).each do |worker, exitstatus|
|
|
171
|
+
after_hook_err = run_shards_finalize_worker!(worker, hook_cfg, workers, exitstatus, shard_results, after_hook_err)
|
|
194
172
|
end
|
|
195
173
|
[shard_results, after_hook_err]
|
|
196
174
|
end
|
|
@@ -6,6 +6,22 @@ module Polyrun
|
|
|
6
6
|
module RunShardsWorkerInterrupt
|
|
7
7
|
private
|
|
8
8
|
|
|
9
|
+
def run_shards_with_interrupt_handlers
|
|
10
|
+
previous = {}
|
|
11
|
+
handlers = {"INT" => ->(_) { raise Interrupt }, "TERM" => ->(_) { raise SignalException, "SIGTERM" }}
|
|
12
|
+
handlers.each do |signal, handler|
|
|
13
|
+
original = Signal.trap(signal, handler)
|
|
14
|
+
if original == "DEFAULT"
|
|
15
|
+
previous[signal] = original
|
|
16
|
+
else
|
|
17
|
+
Signal.trap(signal, original)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
yield
|
|
21
|
+
ensure
|
|
22
|
+
previous.each { |signal, handler| Signal.trap(signal, handler) }
|
|
23
|
+
end
|
|
24
|
+
|
|
9
25
|
def run_shards_log_interrupt_workers(pids, _ctx)
|
|
10
26
|
parts = pids.map { |h| "shard=#{h[:shard]} pid=#{h[:pid]}" }
|
|
11
27
|
Polyrun::Log.orchestration_warn "polyrun run-shards: SIGINT/SIGTERM while waiting on workers — stopping: #{parts.join(", ")}"
|
|
@@ -3,6 +3,7 @@ require "fileutils"
|
|
|
3
3
|
require "json"
|
|
4
4
|
|
|
5
5
|
require_relative "../version"
|
|
6
|
+
require_relative "../error"
|
|
6
7
|
require_relative "cobertura_zero_lines"
|
|
7
8
|
require_relative "filter"
|
|
8
9
|
require_relative "formatter"
|
|
@@ -44,6 +45,11 @@ module Polyrun
|
|
|
44
45
|
def start!(root:, reject_patterns: [], track_under: ["lib"], track_files: nil, groups: nil, output_path: nil, minimum_line_percent: nil, strict: nil, meta: {}, formatter: nil, report_output_dir: nil, report_basename: "polyrun-coverage")
|
|
45
46
|
return if disabled?
|
|
46
47
|
|
|
48
|
+
branches = branch_coverage_enabled?
|
|
49
|
+
if branches && !::Coverage.supported?(:branches)
|
|
50
|
+
raise Polyrun::Error, "#{RUBY_ENGINE} does not support branch coverage"
|
|
51
|
+
end
|
|
52
|
+
|
|
47
53
|
root = File.expand_path(root)
|
|
48
54
|
basename = fragment_default_basename_from_env
|
|
49
55
|
output_path ||= File.join(root, "coverage", "polyrun-fragment-#{basename}.json")
|
|
@@ -73,7 +79,7 @@ module Polyrun
|
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
unless ::Coverage.running?
|
|
76
|
-
::Coverage.start(lines: true, branches:
|
|
82
|
+
::Coverage.start(lines: true, branches: branches)
|
|
77
83
|
end
|
|
78
84
|
unless instance_variable_defined?(:@collector_finish_at_exit_registered)
|
|
79
85
|
@collector_finish_at_exit_registered = true
|
|
@@ -26,11 +26,10 @@ module Polyrun
|
|
|
26
26
|
filter = track_filter_for(root: root, track_under: track_under, ignore_paths: ignore_paths)
|
|
27
27
|
out = {}
|
|
28
28
|
raw.each do |path, coverage_entry|
|
|
29
|
-
next unless coverage_entry.is_a?(Hash)
|
|
30
29
|
next if filter && !filter.include_path?(path.to_s)
|
|
31
30
|
|
|
32
|
-
lines = coverage_entry
|
|
33
|
-
next
|
|
31
|
+
lines = line_array(coverage_entry)
|
|
32
|
+
next if lines.empty?
|
|
34
33
|
|
|
35
34
|
out[path.to_s] = Snapshot.sparse_snapshot_lines(lines)
|
|
36
35
|
end
|
|
@@ -84,6 +83,7 @@ module Polyrun
|
|
|
84
83
|
end
|
|
85
84
|
|
|
86
85
|
def line_array(entry)
|
|
86
|
+
return entry if entry.is_a?(Array)
|
|
87
87
|
return [] unless entry.is_a?(Hash)
|
|
88
88
|
return [] if entry["sparse"]
|
|
89
89
|
|
|
@@ -158,11 +158,7 @@ module Polyrun
|
|
|
158
158
|
end
|
|
159
159
|
|
|
160
160
|
def lines_from_peek_entry(path, after_raw)
|
|
161
|
-
|
|
162
|
-
return [] unless entry.is_a?(Hash)
|
|
163
|
-
|
|
164
|
-
arr = entry[:lines] || entry["lines"]
|
|
165
|
-
arr.is_a?(Array) ? arr : []
|
|
161
|
+
line_array(after_raw[path])
|
|
166
162
|
end
|
|
167
163
|
|
|
168
164
|
def track_filter_for(root:, track_under:, ignore_paths:)
|
|
@@ -73,7 +73,9 @@ module Polyrun
|
|
|
73
73
|
project.copy_to(directory)
|
|
74
74
|
apply_mutation(directory, mutation) if mutation
|
|
75
75
|
command = @arguments.map { |argument| argument.start_with?("#{@root}/") ? File.join(directory, argument.delete_prefix("#{@root}/")) : argument }
|
|
76
|
-
|
|
76
|
+
# Baseline keeps a floor so short per-mutation timeouts do not fail the clean run under load.
|
|
77
|
+
timeout = mutation ? @timeout : [@timeout, 5.0].max
|
|
78
|
+
result = Quality::Command.call(command, root: directory, timeout: timeout, max_output: @settings["max_output_bytes"], env: Quality::Sandbox.environment(directory))
|
|
77
79
|
result.merge!(mutation) if mutation
|
|
78
80
|
result["code"] = {0 => mutation ? "SURVIVED" : "BASELINE_OK", 1 => mutation ? "KILLED" : "BASELINE_FAILED",
|
|
79
81
|
122 => "OUTPUT_LIMIT", 124 => "TIMEOUT", 127 => "COMMAND_UNAVAILABLE"}.fetch(result["exitstatus"], "COMMAND_FAILED")
|
|
@@ -24,6 +24,11 @@ module Polyrun
|
|
|
24
24
|
#
|
|
25
25
|
# @return [Array(Process::Status, String, String)] status, stdout capture, stderr capture
|
|
26
26
|
def spawn_wait(env, *argv, chdir: nil, silent: false)
|
|
27
|
+
if chdir && RUBY_ENGINE == "jruby"
|
|
28
|
+
# JRuby's shell launch can continue after its chdir fails.
|
|
29
|
+
argv = ["/bin/sh", "-c", 'cd -- "$1" && shift && exec "$@"', "polyrun", chdir, *argv]
|
|
30
|
+
chdir = nil
|
|
31
|
+
end
|
|
27
32
|
args = spawn_argv(env, *argv)
|
|
28
33
|
return spawn_wait_inherit(args, chdir) unless silent
|
|
29
34
|
|
|
@@ -71,20 +76,20 @@ module Polyrun
|
|
|
71
76
|
if st.success?
|
|
72
77
|
[st, "", ""]
|
|
73
78
|
else
|
|
74
|
-
|
|
75
|
-
err = File.binread(err_path)
|
|
76
|
-
[st, truncate_failure_capture(out), truncate_failure_capture(err)]
|
|
79
|
+
[st, read_failure_capture(out_path), read_failure_capture(err_path)]
|
|
77
80
|
end
|
|
78
81
|
end
|
|
79
82
|
end
|
|
80
83
|
end
|
|
81
84
|
|
|
82
|
-
def
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
def read_failure_capture(path)
|
|
86
|
+
File.open(path, "rb") do |capture|
|
|
87
|
+
size = capture.size
|
|
88
|
+
return capture.read(MAX_FAILURE_CAPTURE_BYTES).to_s if size <= MAX_FAILURE_CAPTURE_BYTES
|
|
85
89
|
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
capture.seek(size - MAX_FAILURE_CAPTURE_BYTES)
|
|
91
|
+
"... (#{size} bytes total; showing last #{MAX_FAILURE_CAPTURE_BYTES} bytes)\n" + capture.read(MAX_FAILURE_CAPTURE_BYTES).to_s
|
|
92
|
+
end
|
|
88
93
|
end
|
|
89
94
|
end
|
|
90
95
|
end
|
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,6 +6,7 @@ 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"
|
|
@@ -18,11 +19,15 @@ Gem::Specification.new do |spec|
|
|
|
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
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: polyrun
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrei Makarov
|
|
@@ -191,13 +191,23 @@ dependencies:
|
|
|
191
191
|
- - ">="
|
|
192
192
|
- !ruby/object:Gem::Version
|
|
193
193
|
version: '3.5'
|
|
194
|
+
description: Polyrun runs parallel test shards, merges SimpleCov-compatible coverage,
|
|
195
|
+
emits CI reports, and prepares fixtures, snapshots, assets, and databases. It ships
|
|
196
|
+
with no runtime gem dependencies beyond the standard library and vendored or native
|
|
197
|
+
code.
|
|
194
198
|
email:
|
|
195
199
|
- contact@kiskolabs.com
|
|
196
200
|
executables:
|
|
197
201
|
- polyrun
|
|
198
202
|
extensions:
|
|
199
203
|
- ext/polyrun_coverage_merge/extconf.rb
|
|
200
|
-
extra_rdoc_files:
|
|
204
|
+
extra_rdoc_files:
|
|
205
|
+
- CHANGELOG.md
|
|
206
|
+
- CODE_OF_CONDUCT.md
|
|
207
|
+
- CONTRIBUTING.md
|
|
208
|
+
- LICENSE
|
|
209
|
+
- README.md
|
|
210
|
+
- SECURITY.md
|
|
201
211
|
files:
|
|
202
212
|
- CHANGELOG.md
|
|
203
213
|
- CODE_OF_CONDUCT.md
|
|
@@ -313,6 +323,7 @@ files:
|
|
|
313
323
|
- lib/polyrun/database/url_builder/template_prepare.rb
|
|
314
324
|
- lib/polyrun/debug.rb
|
|
315
325
|
- lib/polyrun/env/ci.rb
|
|
326
|
+
- lib/polyrun/error.rb
|
|
316
327
|
- lib/polyrun/export/csv.rb
|
|
317
328
|
- lib/polyrun/export/markdown.rb
|
|
318
329
|
- lib/polyrun/graph/client.rb
|
|
@@ -428,8 +439,11 @@ licenses:
|
|
|
428
439
|
- MIT
|
|
429
440
|
metadata:
|
|
430
441
|
homepage_uri: https://github.com/amkisko/polyrun.rb
|
|
442
|
+
source_code_uri: https://github.com/amkisko/polyrun.rb/tree/main
|
|
443
|
+
changelog_uri: https://github.com/amkisko/polyrun.rb/blob/main/CHANGELOG.md
|
|
431
444
|
bug_tracker_uri: https://github.com/amkisko/polyrun.rb/issues
|
|
432
445
|
documentation_uri: https://github.com/amkisko/polyrun.rb#readme
|
|
446
|
+
allowed_push_host: https://rubygems.org
|
|
433
447
|
rubygems_mfa_required: 'true'
|
|
434
448
|
rdoc_options: []
|
|
435
449
|
require_paths:
|