polyrun 2.2.8 → 3.0.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -8
  3. data/README.md +7 -6
  4. data/docs/SETUP_PROFILE.md +2 -1
  5. data/ext/polyrun_coverage_merge/coverage_merge.c +34 -15
  6. data/lib/polyrun/benchmark/pressure/cooker.rb +191 -0
  7. data/lib/polyrun/benchmark/pressure/process_sample.rb +127 -0
  8. data/lib/polyrun/benchmark/pressure.rb +144 -0
  9. data/lib/polyrun/cli/ci_shard_run_command.rb +31 -0
  10. data/lib/polyrun/cli/default_run.rb +10 -3
  11. data/lib/polyrun/cli/help.rb +5 -3
  12. data/lib/polyrun/cli/run_shards_command.rb +17 -0
  13. data/lib/polyrun/cli.rb +5 -2
  14. data/lib/polyrun/coverage/collector.rb +21 -49
  15. data/lib/polyrun/coverage/collector_blob.rb +53 -0
  16. data/lib/polyrun/coverage/merge.rb +33 -6
  17. data/lib/polyrun/coverage/merge_fragment_meta.rb +7 -1
  18. data/lib/polyrun/coverage/merge_merge_two.rb +2 -0
  19. data/lib/polyrun/coverage/merge_native.rb +2 -0
  20. data/lib/polyrun/data/parallel_provisioning.rb +2 -2
  21. data/lib/polyrun/hooks/dsl.rb +6 -6
  22. data/lib/polyrun/{minitest.rb → minitest_support.rb} +4 -4
  23. data/lib/polyrun/partition/paths.rb +95 -48
  24. data/lib/polyrun/partition/suite.rb +10 -6
  25. data/lib/polyrun/quick/config.rb +56 -0
  26. data/lib/polyrun/quick/example_group.rb +49 -4
  27. data/lib/polyrun/quick/example_runner.rb +30 -7
  28. data/lib/polyrun/quick/matchers.rb +6 -3
  29. data/lib/polyrun/quick/matchers_predicates.rb +122 -0
  30. data/lib/polyrun/quick/reporter.rb +40 -6
  31. data/lib/polyrun/quick/runner.rb +30 -16
  32. data/lib/polyrun/reporting/rspec_failure_fragment_formatter.rb +1 -1
  33. data/lib/polyrun/reporting/rspec_junit.rb +2 -2
  34. data/lib/polyrun/{rspec → rspec_support}/active_record_timeout_recovery.rb +1 -1
  35. data/lib/polyrun/{rspec → rspec_support}/example_debug.rb +1 -1
  36. data/lib/polyrun/{rspec → rspec_support}/example_debug_instrumentation.rb +1 -1
  37. data/lib/polyrun/{rspec → rspec_support}/sharded_formatter_compat.rb +1 -1
  38. data/lib/polyrun/{rspec.rb → rspec_support.rb} +12 -12
  39. data/lib/polyrun/sus_support.rb +55 -0
  40. data/lib/polyrun/templates/POLYRUN.md +1 -1
  41. data/lib/polyrun/timing/rspec_example_formatter.rb +2 -2
  42. data/lib/polyrun/version.rb +1 -1
  43. data/lib/polyrun/worker_ping.rb +9 -6
  44. data/sig/polyrun/{minitest.rbs → minitest_support.rbs} +1 -1
  45. data/sig/polyrun/{rspec.rbs → rspec_support.rbs} +1 -1
  46. data/sig/polyrun/sus_support.rbs +7 -0
  47. metadata +17 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f6a7a0e969581e53f92c3e1bd4dfbb046c8321fb25601d58be12d4cc8cb6a96
4
- data.tar.gz: 0c4625804e0ee0ce3f695570001658f9d907d9102c059258efa9c00fdf16d669
3
+ metadata.gz: a596cf2a374f9aa883e0f8e449a93a02c303cfc4378d9a0ef2e2b7d45f66d776
4
+ data.tar.gz: bf7047e62fc1f77a0105e1aac00ff1fca794dd74d47a3aef5838c7cb32aff348
5
5
  SHA512:
6
- metadata.gz: 663f89b311212915efcb030db4cf88feb7f3f78b981746d63ee8c5548fec1abd23e13df3b307f4173601e4b3b829dab9ac56664caecfd929ed48c585deec58c2
7
- data.tar.gz: be540c7af7282a2868408a6e8fa7837976ae2ffe443acbec7e65bb6e881d0bce419a344cf75573cadb2af0f562272032eabaf30564e2fab9a998f76029e37c07
6
+ metadata.gz: 39862a1442ecb1704ee9e4416841a70905b94a88fd6e191c4ddcfce8ad8ca02993c99802963e72c175e634e20e39595835e87b083379ebffb317117cddc5604b
7
+ data.tar.gz: 84a45dd40b1b48fcf9c71ba81103e958ab48c23832b069d3fc2f30be96e7897d37468e39677cb9089a8981390a63037165bd9cc1c8cadca2a0dbae841e84b2e6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.0.0 (2026-11-12)
4
+
5
+ - Rename `Polyrun::RSpec` to `Polyrun::RSpecSupport` and `Polyrun::Minitest` to `Polyrun::MinitestSupport` (requires `polyrun/rspec_support` / `polyrun/minitest_support`). Hard cut: old constants and require paths are removed (RFC-0007).
6
+ - Fix `Polyrun::Reporting::RspecJunit.install!` raising `NoMethodError` on `configure` when RSpec wiring was already required (`::RSpec` qualification).
7
+ - Add Sus as a first-class suite: `partition.suite: sus`, `test/**/*.rb` globs, auto-detect via `config/sus.rb`, `parallel-sus`, `ci-shard-sus`, and `Polyrun::SusSupport` (RFC-0008).
8
+ - Treat Covered-style `COVERAGE` (non-falsey) as coverage-wanted for `Coverage::Collector` / SusSupport `install_coverage!` (RFC-0008).
9
+ - Classify Sus-style `test/**/*.rb` paths as `:sus` instead of `:quick` during suite inference.
10
+ - Extend `Polyrun::Quick`: `config/polyrun_quick.rb` suite hooks and `add_load_path`, `around`, error-aware `after`, `with` / `subject`, `be` / `be_a` / `raise_exception`, slowest-example summary (RFC-0009).
11
+
12
+ ## 2.2.9 (2026-11-07)
13
+
14
+ - Add `Polyrun::Benchmark::Pressure` for load benches: wall/CPU/RSS/heap/GC plus optional storage and network byte deltas, with target ceilings for iterative pressure runs.
15
+ - Add `benchmarks/load.rb`, `benchmarks/cooker.rb`, and Make targets (`bench-load`, `bench-calibrate`, cooker propose/gate) for coverage-merge pressure matrices; JSON under `benchmarks/output/`.
16
+ - Speed coverage merge on the hot path: faster fragment read/parse, cheaper empty-meta merges, and native merge micro-optimizations (hash capacity, Fixnum line hits, empty-operand early return).
17
+
3
18
  ## 2.2.8 (2026-11-04)
4
19
 
5
20
  - Honor top-level `workers:` in `polyrun.yml` when `POLYRUN_WORKERS` is unset (`polyrun config workers`, `start`, `run-shards`, `run-queue`, `doctor`).
@@ -80,8 +95,8 @@
80
95
 
81
96
  - Add `Polyrun::WorkerOutput` for per-shard worker stdout/stderr routing (`POLYRUN_WORKER_OUTPUT_ROUTING=1` or `POLYRUN_WORKER_LOG_DIR`); optional prefixed TTY echo (`POLYRUN_WORKER_OUTPUT_PREFIX=0` for log-only).
82
97
  - Add `partition.paths_build.exclude_prefixes` to omit path prefixes from `build-paths` / `start` while keeping files runnable outside polyrun.
83
- - Add `Polyrun::RSpec.install_example_debug!`, `install_example_timeout!`, `install_example_rails_logging!`, `install_example_prosopite!` (`POLYRUN_EXAMPLE_DEBUG=1` and related env vars).
84
- - Add `Polyrun::RSpec.install_sharded_formatter_compat!` for progress formatters (e.g. Fuubar) under `POLYRUN_SHARD_*`.
98
+ - Add `Polyrun::RSpecSupport.install_example_debug!`, `install_example_timeout!`, `install_example_rails_logging!`, `install_example_prosopite!` (`POLYRUN_EXAMPLE_DEBUG=1` and related env vars).
99
+ - Add `Polyrun::RSpecSupport.install_sharded_formatter_compat!` for progress formatters (e.g. Fuubar) under `POLYRUN_SHARD_*`.
85
100
 
86
101
  ## 2.1.2 (2026-07-05)
87
102
 
@@ -94,7 +109,7 @@
94
109
  ## 2.1.0 (2026-07-03)
95
110
 
96
111
  - Add experimental per-example spec quality (`Polyrun::SpecQuality`): `POLYRUN_SPEC_QUALITY=1`, worker JSONL fragments, `merge-spec-quality`, `report-spec-quality`, and `run-shards --merge-spec-quality`.
97
- - Add `Polyrun::RSpec.install_spec_quality!`, `Polyrun::Minitest.install_spec_quality!`, and Quick example hooks; `polyrun init --profile spec-quality`.
112
+ - Add `Polyrun::RSpecSupport.install_spec_quality!`, `Polyrun::MinitestSupport.install_spec_quality!`, and Quick example hooks; `polyrun init --profile spec-quality`.
98
113
  - Add `Polyrun::Coverage::ExampleDiff` for per-example line hit deltas from `Coverage.peek_result`; record per-example factory counts via `Data::FactoryCounts`.
99
114
  - Report zero-hit examples, line churn, hot lines, shard attribution, optional partition hints (`report-spec-quality --plan`), optional CPU/GC/IO profiling (stdlib), and CI gate thresholds in `config/polyrun_spec_quality.yml`.
100
115
  - Document spec quality in `docs/SPEC_QUALITY.md`.
@@ -121,13 +136,13 @@
121
136
 
122
137
  - Add `run-shards --worker-timeout SEC` and `POLYRUN_WORKER_TIMEOUT_SEC` (wall time per worker since spawn); stop stuck workers; record exit 124 for that shard.
123
138
  - Add `run-shards --worker-idle-timeout SEC` and `POLYRUN_WORKER_IDLE_TIMEOUT_SEC`; parent reads monotonic timestamps from `POLYRUN_WORKER_PING_FILE`; record exit 125 when the last ping is stale. Idle applies only after a valid positive ping (use wall timeout until the first ping).
124
- - Add `Polyrun::WorkerPing` (`ping!`, `ensure_interval_ping_thread!` when `POLYRUN_WORKER_PING_THREAD`). Add `Polyrun::RSpec.install_worker_ping!` and `Polyrun::Minitest.install_worker_ping!`; Polyrun Quick calls `WorkerPing.ping!` around each example. Parent creates ping paths under `tmp/polyrun/` and unlinks files after workers exit.
139
+ - Add `Polyrun::WorkerPing` (`ping!`, `ensure_interval_ping_thread!` when `POLYRUN_WORKER_PING_THREAD`). Add `Polyrun::RSpecSupport.install_worker_ping!` and `Polyrun::MinitestSupport.install_worker_ping!`; Polyrun Quick calls `WorkerPing.ping!` around each example. Parent creates ping paths under `tmp/polyrun/` and unlinks files after workers exit.
125
140
  - Poll every live shard worker together when timeouts are enabled so idle and wall limits apply to all children, not only the first waiter.
126
141
  - Split parallel worker teardown into `RunShardsParallelWait` and `RunShardsWorkerInterrupt`; keep spawn logic in `RunShardsParallelChildren`.
127
142
  - Add `Polyrun::Log.orchestration_warn`; when `POLYRUN_ORCHESTRATION_STDERR=1`, copy one line to process `$stderr` if `Log.stderr` is not the same object (custom/null sinks).
128
143
  - Wire `env_worker_timeout_sec` / `env_worker_idle_timeout_sec` into `ci-shard-run` plan context. Rescue `Interrupt` around `after_suite` in `run-shards` and `ci-shard` orchestration where suite hooks run.
129
144
  - In `Polyrun::Hooks#run_phase`, rescue `Interrupt` for Ruby DSL and shell hook phases (return 130).
130
- - Document worker timeout, idle ping, and `POLYRUN_ORCHESTRATION_STDERR` in `polyrun help`. Add `sig/polyrun/worker_ping.rbs` and extend `Polyrun::RSpec` / `Polyrun::Minitest` installer signatures.
145
+ - Document worker timeout, idle ping, and `POLYRUN_ORCHESTRATION_STDERR` in `polyrun help`. Add `sig/polyrun/worker_ping.rbs` and extend `Polyrun::RSpecSupport` / `Polyrun::MinitestSupport` installer signatures.
131
146
 
132
147
  ## 1.4.2 (2026-04-24)
133
148
 
@@ -139,7 +154,7 @@
139
154
  ## 1.4.1 (2026-04-16)
140
155
 
141
156
  - Add `polyrun merge-failures` and `run-shards --merge-failures` / `--merge-failures-output` / `--merge-failures-format`; merge per-worker JSONL under `tmp/polyrun_failures/polyrun-failure-fragment-*.jsonl` (or RSpec JSON via `-i`). Run merge after all workers exit, including when a shard failed (`--merge-coverage` still runs only after all shards succeed).
142
- - Add `Polyrun::Reporting::FailureMerge`, `Polyrun::RSpec.install_failure_fragments!`, and `Polyrun::Reporting::RspecFailureFragmentFormatter`; parent sets `POLYRUN_FAILURE_FRAGMENTS=1` on workers when merge-failures is enabled.
157
+ - Add `Polyrun::Reporting::FailureMerge`, `Polyrun::RSpecSupport.install_failure_fragments!`, and `Polyrun::Reporting::RspecFailureFragmentFormatter`; parent sets `POLYRUN_FAILURE_FRAGMENTS=1` on workers when merge-failures is enabled.
143
158
  - Add optional `reporting:` in `polyrun.yml` and `Polyrun::Config#reporting` for merge-failures toggles and paths; honor `POLYRUN_MERGE_FAILURES`, `POLYRUN_MERGED_FAILURES_OUT`, `POLYRUN_MERGED_FAILURES_FORMAT`; set `POLYRUN_MERGED_FAILURES_PATH` for `after_suite` when merge wrote a file.
144
159
  - On bad JSONL or non-RSpec JSON, raise `Polyrun::Error` with path and line where applicable; `merge-failures` exits 1 without a full stack trace; a failed merge after successful workers forces `run-shards` exit 1.
145
160
  - Fix `run_shards_plan_ready_log` to take `cfg` so debug logging for merge-failures does not raise `NameError`.
@@ -174,11 +189,11 @@
174
189
  ## 1.1.0 (2026-04-15)
175
190
 
176
191
  - Add `ci-shard-run` / `ci-shard-rspec` for matrix-style sharding (one job per `POLYRUN_SHARD_INDEX` / `POLYRUN_SHARD_TOTAL`): resolve paths via the same plan as `polyrun plan`, then `exec` the given command with this shard’s paths (unlike `run-shards`, which fans out multiple workers on one host).
177
- - Add experimental per-example partition timing: `partition.timing_granularity` / `--timing-granularity` (`file` default, `example` for `path:line` items), `POLYRUN_TIMING_GRANULARITY`, merged timing JSON with `absolute_path:line` keys, `TimingKeys.load_costs_json_file`, constraints matching pins/globs on the file part of locators, queue init support, and optional `Polyrun::Timing::RSpecExampleFormatter` plus `Polyrun::RSpec.install_example_timing!`.
192
+ - Add experimental per-example partition timing: `partition.timing_granularity` / `--timing-granularity` (`file` default, `example` for `path:line` items), `POLYRUN_TIMING_GRANULARITY`, merged timing JSON with `absolute_path:line` keys, `TimingKeys.load_costs_json_file`, constraints matching pins/globs on the file part of locators, queue init support, and optional `Polyrun::Timing::RSpecExampleFormatter` plus `Polyrun::RSpecSupport.install_example_timing!`.
178
193
  - Add `Polyrun::ProcessStdio.inherit_stdio_spawn_wait` and `spawn_wait` for subprocesses with inherited stdio (or temp-file capture when `silent: true`) to avoid Open3 pipe-thread noise on interrupt; used by prepare (shell / custom assets), `Prepare::Assets.precompile!`, and `Provision.prepare_template!` (`bin/rails db:prepare`). On failure, `db:prepare` / `assets:precompile` embed captured stdout/stderr in `Polyrun::Error` (truncated when huge).
179
194
  - Refactor `polyrun plan` around `plan_command_compute_manifest` and `plan_command_build_manifest`; `cmd_plan` output stays aligned with `plan_command_compute_manifest` (tests guard drift).
180
195
  - `TimingKeys.load_costs_json_file` accepts optional `root:` for key normalization; warns when two JSON keys normalize to the same entry with different seconds; `TimingKeys.canonical_file_path` / `normalize_locator` resolve directory symlinks so `/var/…` and `/private/var/…` (macOS) map to one key.
181
- - `Polyrun::RSpec.install_example_timing!(output_path:)` no longer sets `ENV` when an explicit path is passed; formatter uses `timing_output_path` (override or `ENV` / default filename).
196
+ - `Polyrun::RSpecSupport.install_example_timing!(output_path:)` no longer sets `ENV` when an explicit path is passed; formatter uses `timing_output_path` (override or `ENV` / default filename).
182
197
  - Fix noisy `IOError` / broken-pipe behavior when interrupting long-running prepare / Rails subprocesses that previously used `Open3.capture3`.
183
198
 
184
199
  ## 1.0.0 (2026-04-14)
data/README.md CHANGED
@@ -10,11 +10,11 @@ Running tests in parallel across processes still requires a single merged covera
10
10
 
11
11
  Polyrun provides:
12
12
 
13
- - Orchestration: `plan`, `run-shards`, and `parallel-rspec` / `parallel-minitest` / `parallel-quick` (run-shards plus merge-coverage), with an optional on-disk queue and constraints for file lists and load balancing. Bare `polyrun` (no subcommand) picks the suite from `partition.suite`, else `partition.paths_file`, else filesystem auto-detect. For **GitHub Actions-style matrix sharding** (one job per global shard), use `ci-shard-run -- …` (any test runner) or `ci-shard-rspec`—not `run-shards` / `parallel-*`, which fan out N workers on one machine.
13
+ - Orchestration: `plan`, `run-shards`, and `parallel-rspec` / `parallel-minitest` / `parallel-sus` / `parallel-quick` (run-shards plus merge-coverage), with an optional on-disk queue and constraints for file lists and load balancing. Bare `polyrun` (no subcommand) picks the suite from `partition.suite`, else `partition.paths_file`, else filesystem auto-detect (Sus when `config/sus.rb` and `test/**/*.rb` exist). For **GitHub Actions-style matrix sharding** (one job per global shard), use `ci-shard-run -- …` (any test runner), `ci-shard-rspec`, or `ci-shard-sus`—not `run-shards` / `parallel-*`, which fan out N workers on one machine.
14
14
  - Coverage: merge SimpleCov-compatible JSON fragments; emit JSON, LCOV, Cobertura, or console summaries (you can drop separate SimpleCov merge plugins for this path).
15
15
  - CI reporting: JUnit XML from RSpec JSON; slow-file reports from merged timing JSON.
16
16
  - Parallel hygiene: asset digest markers, SQL snapshots, YAML fixture batches, and DB URL or shard helpers aligned with `POLYRUN_SHARD_*`.
17
- - Optional **`polyrun quick`**: `Polyrun::Quick` — nested `describe`, `it` / `test`, `before` / `after`, `let` / `let!`, `expect(x).to …` matchers, `assert_*` (Minitest-like), and optional **`Polyrun::Quick.capybara!`** (extends `Capybara::DSL` when the **capybara** gem is loaded). Stdlib-only in Polyrun itself. Coverage uses the same `Polyrun::Coverage::Collector` path as RSpec when `POLYRUN_COVERAGE=1` or `config/polyrun_coverage.yml` is present (not when `POLYRUN_COVERAGE_DISABLE=1`).
17
+ - Optional **`polyrun quick`**: `Polyrun::Quick` — nested `describe` / `with`, `it` / `test`, `before` / `after` / `around`, `let` / `let!` / `subject`, `expect(x).to …` / `expect { }.to raise_exception`, `assert_*`, optional `config/polyrun_quick.rb` (`before_suite` / `after_suite` / `add_load_path`), and optional **`Polyrun::Quick.capybara!`**. Stdlib-only in Polyrun itself. Coverage when `POLYRUN_COVERAGE=1`, Covered-style `COVERAGE`, or `config/polyrun_coverage.yml` + `POLYRUN_QUICK_COVERAGE=1` (not when `POLYRUN_COVERAGE_DISABLE=1`).
18
18
  - No runtime gems in the gemspec: stdlib and vendored pieces only.
19
19
 
20
20
  Capybara and Playwright stay in your application; Polyrun does not replace browser drivers.
@@ -93,6 +93,7 @@ bin/polyrun ci-shard-run -- bundle exec rspec # CI matrix: shard plan + append
93
93
  bin/polyrun ci-shard-rspec # same as ci-shard-run -- bundle exec rspec
94
94
  bin/polyrun parallel-rspec --workers 5 # run-shards + merge-coverage (default: bundle exec rspec)
95
95
  bin/polyrun parallel-minitest --workers 5 # same; default rails test or ruby -I test
96
+ bin/polyrun parallel-sus --workers 5 # same; default bundle exec sus (OS processes; use with config/sus.rb)
96
97
  bin/polyrun parallel-quick --workers 5 # same; default bundle exec polyrun quick
97
98
  bin/polyrun run-shards --workers 5 --merge-coverage -- bundle exec rspec
98
99
  bin/polyrun merge-coverage -i cov1.json -i cov2.json -o merged.json --format json,lcov,cobertura,console
@@ -122,8 +123,8 @@ Runnable Rails demos (multi-DB, Vite, Capybara, Docker, Postgres sketches) live
122
123
 
123
124
  That single require loads the CLI and core library **without** loading RSpec or Minitest. Optional integrations (use only what your app needs):
124
125
 
125
- - `require "polyrun/rspec"` — `Polyrun::RSpec` registers `ParallelProvisioning` in `before(:suite)` (your app must use RSpec).
126
- - `require "polyrun/minitest"` — `Polyrun::Minitest` is a thin alias for `ParallelProvisioning.run_suite_hooks!` (does not `require "minitest"`).
126
+ - `require "polyrun/rspec_support"` — `Polyrun::RSpecSupport` registers `ParallelProvisioning` in `before(:suite)` (your app must use RSpec).
127
+ - `require "polyrun/minitest_support"` — `Polyrun::MinitestSupport` is a thin alias for `ParallelProvisioning.run_suite_hooks!` (does not `require "minitest"`).
127
128
  - `require "polyrun/reporting/rspec_junit"` — `Polyrun::Reporting::RspecJunit` adds RSpec’s JSON formatter and writes JUnit on exit; RSpec is loaded only inside `RspecJunit.install!`.
128
129
 
129
130
  | API | Purpose |
@@ -141,8 +142,8 @@ That single require loads the CLI and core library **without** loading RSpec or
141
142
  | `Polyrun::Data::FactoryInstrumentation` | Opt-in FactoryBot patch → `FactoryCounts` (after `require "factory_bot"`). |
142
143
  | `Polyrun::Data::SqlSnapshot` | PostgreSQL `pg_dump` / `psql` snapshots under `spec/fixtures/sql_snapshots/`. |
143
144
  | `Polyrun::Data::FactoryCounts` | Factory/build counters + summary text. |
144
- | `Polyrun::RSpec` (`require "polyrun/rspec"`) | `install_parallel_provisioning!` → `before(:suite)` hooks. |
145
- | `Polyrun::Minitest` (`require "polyrun/minitest"`) | `install_parallel_provisioning!` → same as `ParallelProvisioning.run_suite_hooks!` (no Minitest gem dependency). |
145
+ | `Polyrun::RSpecSupport` (`require "polyrun/rspec_support"`) | `install_parallel_provisioning!` → `before(:suite)` hooks. |
146
+ | `Polyrun::MinitestSupport` (`require "polyrun/minitest_support"`) | `install_parallel_provisioning!` → same as `ParallelProvisioning.run_suite_hooks!` (no Minitest gem dependency). |
146
147
  | `Polyrun::Reporting::RspecJunit` (`require "polyrun/reporting/rspec_junit"`) | CI: RSpec JSON formatter + JUnit from `install!` (RSpec loaded only there). |
147
148
  | `Polyrun::Prepare::Assets` | Digest trees, marker file, `assets:precompile`. |
148
149
  | `Polyrun::Database::Shard` | Shard env map, `%{shard}` DB names, URL path suffix for `postgres://`, `mysql2://`, `mongodb://`, etc. |
@@ -44,6 +44,7 @@ Rule: anything expensive (compile, `yarn`, Playwright download) belongs in prepa
44
44
  | Field | Options |
45
45
  |--------|---------|
46
46
  | Plain glob | `partition.paths_build.all_glob: spec/**/*_spec.rb` and empty or minimal `stages` |
47
+ | Sus suite | `partition.suite: sus` (or auto via `config/sus.rb`); default glob `test/**/*.rb`; CLI `parallel-sus` / `ci-shard-sus`; wire `polyrun/sus_support` in `config/sus.rb`. Prefer Polyrun collector fragments for shard merge; do not enable Covered::Sus in the same process |
47
48
  | Ordered stages | `partition.paths_build.stages`: regex (e.g. slow integration first) or `sort_by_substring_order` for stable ordering |
48
49
  | Exclude prefixes | `partition.paths_build.exclude_prefixes`: omit paths (e.g. `spec/benchmark/`) from `paths_file` while keeping them runnable outside polyrun |
49
50
 
@@ -77,7 +78,7 @@ Orchestration tracing stays on `DEBUG=1` / `POLYRUN_DEBUG=1`. Per-example toolin
77
78
  | `DEBUG_LOG_LEVEL` | Rails / ActiveRecord logger severity: `debug`, `info`, `warn`, `error`, `fatal`, or Ruby Logger integers (`0` debug … `4` fatal); default `debug` |
78
79
  | `RSPEC_EXAMPLE_TIMEOUT_SEC` | Per-example timeout (disabled while example debug is on); on timeout, ActiveRecord connection pools are disconnected so the next example gets fresh connections (any adapter) |
79
80
 
80
- In `spec_helper` / `spec/support`: `require "polyrun/rspec"` then `Polyrun::RSpec.install_sharded_formatter_compat!` (silences per-worker seed/summary/pending under `POLYRUN_SHARD_*`), `install_example_debug!`, `install_example_rails_logging!`, `install_example_prosopite!`, `install_example_timeout!`. Pair with `install_worker_ping!` for idle timeouts.
81
+ In `spec_helper` / `spec/support`: `require "polyrun/rspec_support"` then `Polyrun::RSpecSupport.install_sharded_formatter_compat!` (silences per-worker seed/summary/pending under `POLYRUN_SHARD_*`), `install_example_debug!`, `install_example_rails_logging!`, `install_example_prosopite!`, `install_example_timeout!`. Pair with `install_worker_ping!` for idle timeouts.
81
82
 
82
83
  ## 6. Coverage and CI reports
83
84
 
@@ -16,12 +16,12 @@ static ID id_coverage;
16
16
  static ID id_relevant;
17
17
  static ID id_covered;
18
18
  static ID id_sort_branches_for_native;
19
+ static ID id_keys;
20
+ static ID id_plus;
21
+ static ID id_gt;
19
22
 
20
- static VALUE
21
- ignored_string(void)
22
- {
23
- return rb_str_new_cstr("ignored");
24
- }
23
+ static VALUE str_ignored;
24
+ static VALUE ary_empty_lines;
25
25
 
26
26
  static int
27
27
  ignored_hit_p(VALUE value)
@@ -67,7 +67,7 @@ line_hit_positive_p(VALUE value)
67
67
  return 0;
68
68
  }
69
69
 
70
- VALUE comparison = rb_funcall(as_int, rb_intern(">"), 1, LONG2FIX(0));
70
+ VALUE comparison = rb_funcall(as_int, id_gt, 1, LONG2FIX(0));
71
71
  return RTEST(comparison);
72
72
  }
73
73
 
@@ -75,7 +75,7 @@ static VALUE
75
75
  coerce_line_array(VALUE value)
76
76
  {
77
77
  if (NIL_P(value)) {
78
- return rb_ary_new();
78
+ return ary_empty_lines;
79
79
  }
80
80
  if (!RB_TYPE_P(value, T_ARRAY)) {
81
81
  rb_raise(rb_eTypeError, "lines must be an Array");
@@ -88,7 +88,7 @@ static VALUE
88
88
  line_array_for_count(VALUE value)
89
89
  {
90
90
  if (NIL_P(value) || !RB_TYPE_P(value, T_ARRAY)) {
91
- return rb_ary_new();
91
+ return ary_empty_lines;
92
92
  }
93
93
 
94
94
  return value;
@@ -104,14 +104,17 @@ merge_line_hits(VALUE left, VALUE right)
104
104
  return left;
105
105
  }
106
106
  if (ignored_hit_p(left) || ignored_hit_p(right)) {
107
- return ignored_string();
107
+ return str_ignored;
108
108
  }
109
109
 
110
110
  VALUE left_i = line_hit_to_i(left);
111
111
  VALUE right_i = line_hit_to_i(right);
112
112
 
113
113
  if (!NIL_P(left_i) && !NIL_P(right_i)) {
114
- return rb_funcall(left_i, rb_intern("+"), 1, right_i);
114
+ if (RB_FIXNUM_P(left_i) && RB_FIXNUM_P(right_i)) {
115
+ return LONG2FIX(FIX2LONG(left_i) + FIX2LONG(right_i));
116
+ }
117
+ return rb_funcall(left_i, id_plus, 1, right_i);
115
118
  }
116
119
  if (NIL_P(left_i) && !NIL_P(right_i)) {
117
120
  return right_i;
@@ -134,9 +137,12 @@ merge_line_arrays(VALUE left, VALUE right)
134
137
  long max_len = left_len > right_len ? left_len : right_len;
135
138
  VALUE out = rb_ary_new2(max_len);
136
139
 
140
+ const VALUE *left_ptr = RARRAY_CONST_PTR(left);
141
+ const VALUE *right_ptr = RARRAY_CONST_PTR(right);
142
+
137
143
  for (long index = 0; index < max_len; index++) {
138
- VALUE left_hit = index < left_len ? rb_ary_entry(left, index) : Qnil;
139
- VALUE right_hit = index < right_len ? rb_ary_entry(right, index) : Qnil;
144
+ VALUE left_hit = index < left_len ? left_ptr[index] : Qnil;
145
+ VALUE right_hit = index < right_len ? right_ptr[index] : Qnil;
140
146
  rb_ary_store(out, index, merge_line_hits(left_hit, right_hit));
141
147
  }
142
148
 
@@ -185,7 +191,7 @@ static VALUE
185
191
  merge_branch_entries(VALUE left, VALUE right)
186
192
  {
187
193
  VALUE out = rb_hash_dup(left);
188
- VALUE sum = rb_funcall(coverage_count(left), rb_intern("+"), 1, coverage_count(right));
194
+ VALUE sum = rb_funcall(coverage_count(left), id_plus, 1, coverage_count(right));
189
195
  rb_hash_aset(out, str_coverage, sum);
190
196
 
191
197
  return out;
@@ -202,7 +208,7 @@ merge_module_value(void)
202
208
  static VALUE
203
209
  hash_keys(VALUE hash)
204
210
  {
205
- return rb_funcall(hash, rb_intern("keys"), 0);
211
+ return rb_funcall(hash, id_keys, 0);
206
212
  }
207
213
 
208
214
  static VALUE
@@ -395,7 +401,12 @@ merge_two(VALUE module, VALUE left, VALUE right)
395
401
  secondary = left;
396
402
  }
397
403
 
398
- VALUE out = rb_hash_new();
404
+ if (RHASH_SIZE(secondary) == 0) {
405
+ return rb_hash_dup(primary);
406
+ }
407
+
408
+ long capa = (long)RHASH_SIZE(primary);
409
+ VALUE out = rb_hash_new_capa(capa > 0 ? capa : 0);
399
410
  VALUE primary_keys = hash_keys(primary);
400
411
  long primary_length = RARRAY_LEN(primary_keys);
401
412
 
@@ -472,18 +483,26 @@ Init_polyrun_coverage_merge(void)
472
483
  id_relevant = rb_intern("relevant");
473
484
  id_covered = rb_intern("covered");
474
485
  id_sort_branches_for_native = rb_intern("sort_branches_for_native");
486
+ id_keys = rb_intern("keys");
487
+ id_plus = rb_intern("+");
488
+ id_gt = rb_intern(">");
475
489
  str_lines = rb_obj_freeze(rb_str_new_cstr("lines"));
476
490
  str_branches = rb_obj_freeze(rb_str_new_cstr("branches"));
477
491
  str_type = rb_obj_freeze(rb_str_new_cstr("type"));
478
492
  str_start_line = rb_obj_freeze(rb_str_new_cstr("start_line"));
479
493
  str_end_line = rb_obj_freeze(rb_str_new_cstr("end_line"));
480
494
  str_coverage = rb_obj_freeze(rb_str_new_cstr("coverage"));
495
+ str_ignored = rb_obj_freeze(rb_str_new_cstr("ignored"));
496
+ ary_empty_lines = rb_ary_new();
497
+ rb_obj_freeze(ary_empty_lines);
481
498
  rb_global_variable(&str_lines);
482
499
  rb_global_variable(&str_branches);
483
500
  rb_global_variable(&str_type);
484
501
  rb_global_variable(&str_start_line);
485
502
  rb_global_variable(&str_end_line);
486
503
  rb_global_variable(&str_coverage);
504
+ rb_global_variable(&str_ignored);
505
+ rb_global_variable(&ary_empty_lines);
487
506
 
488
507
  VALUE module = rb_define_module("PolyrunCoverageMerge");
489
508
  rb_define_singleton_method(module, "merge_line_arrays", merge_line_arrays_method, 2);
@@ -0,0 +1,191 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "json"
5
+ require "time"
6
+
7
+ module Polyrun
8
+ module Benchmark
9
+ module Pressure
10
+ # Episode helpers for amkisko/pressure-benchmarking prayer: multi-sample measure,
11
+ # propose ceilings, calibrate stage separation, and cooker iteration logs.
12
+ module Cooker
13
+ DEFAULT_SAMPLES = 3
14
+ DEFAULT_HEADROOM = 1.15
15
+ DEFAULT_COOKER_N = 10
16
+ SERIES_KEYS = %w[
17
+ wall_s cpu_s rss_delta_bytes heap_delta_bytes storage_delta_bytes
18
+ network_in_bytes network_out_bytes allocated_objects
19
+ ].freeze
20
+
21
+ module_function
22
+
23
+ def measure_samples(n:, label:, ops: nil, gc_start: true, extras: {}, &block)
24
+ raise ArgumentError, "samples-per-load must be >= 1" if n < 1
25
+
26
+ samples = Array.new(n) do |i|
27
+ Pressure.measure(
28
+ label: "#{label}_s#{i + 1}",
29
+ ops: ops,
30
+ gc_start: gc_start,
31
+ extras: extras,
32
+ &block
33
+ )
34
+ end
35
+ aggregate(samples, label: label, basis: extras.fetch("basis", "median"))
36
+ end
37
+
38
+ def aggregate(samples, label:, basis: "median")
39
+ metrics_list = samples.map { |s| flatten_metrics(s["metrics"]) }
40
+ keys = SERIES_KEYS
41
+ summary = {}
42
+ keys.each do |key|
43
+ values = metrics_list.filter_map { |m| m[key] }
44
+ next if values.empty?
45
+
46
+ summary[key] = {
47
+ "samples" => values,
48
+ "median" => percentile(values, 0.5),
49
+ "max" => values.max,
50
+ "min" => values.min,
51
+ "basis_value" => (basis.to_s == "max") ? values.max : percentile(values, 0.5)
52
+ }
53
+ end
54
+ wall = summary.dig("wall_s", "basis_value")
55
+ ops = samples.first && samples.first["ops"]
56
+ {
57
+ "label" => label.to_s,
58
+ "ops" => ops,
59
+ "ops_per_s" => (ops && wall&.positive?) ? ops / wall : nil,
60
+ "basis" => basis.to_s,
61
+ "n" => samples.length,
62
+ "samples" => samples,
63
+ "series" => summary,
64
+ "metrics" => summary.transform_values { |h| h["basis_value"] },
65
+ "gateable" => samples.length >= DEFAULT_SAMPLES
66
+ }
67
+ end
68
+
69
+ def flatten_metrics(metrics)
70
+ flat = metrics.dup
71
+ flat["allocated_objects"] = metrics.dig("gc", "allocated_objects")
72
+ flat
73
+ end
74
+
75
+ def propose_ceilings(series_summary, headroom: DEFAULT_HEADROOM, keys: nil)
76
+ keys ||= SERIES_KEYS
77
+ keys.each_with_object({}) do |key, out|
78
+ entry = series_summary[key] || series_summary.dig("series", key)
79
+ next unless entry
80
+
81
+ value = entry.is_a?(Hash) ? entry["basis_value"] : entry
82
+ next if value.nil?
83
+
84
+ out[key] = value.to_f * headroom
85
+ end
86
+ end
87
+
88
+ def gate(series_or_metrics, ceilings)
89
+ metrics = series_or_metrics["metrics"] || series_or_metrics
90
+ failures = []
91
+ ceilings.each do |key, limit|
92
+ next if limit.nil?
93
+ next unless metrics.key?(key)
94
+
95
+ failures << key if metrics[key].to_f > limit.to_f
96
+ end
97
+ {"pass" => failures.empty?, "failures" => failures, "metrics" => metrics, "ceilings" => ceilings}
98
+ end
99
+
100
+ def calibrate!(stages)
101
+ # stages: ordered Array of [name, known_rank, callable]
102
+ # known_rank must be strictly increasing with expected wall cost.
103
+ measured = stages.map do |name, known_rank, callable|
104
+ result = Pressure.measure(label: "calibrate_#{name}", ops: 1, gc_start: true) { callable.call }
105
+ {
106
+ "stage" => name.to_s,
107
+ "known_rank" => known_rank,
108
+ "wall_s" => result["metrics"]["wall_s"],
109
+ "cpu_s" => result["metrics"]["cpu_s"]
110
+ }
111
+ end
112
+ by_wall = measured.sort_by { |row| row["wall_s"] }
113
+ by_known = measured.sort_by { |row| row["known_rank"] }
114
+ order_ok = by_wall.map { |r| r["stage"] } == by_known.map { |r| r["stage"] }
115
+ distinct = measured.map { |r| r["wall_s"] }.uniq.length == measured.length
116
+ {
117
+ "pass" => order_ok && distinct,
118
+ "order_ok" => order_ok,
119
+ "distinct_wall" => distinct,
120
+ "stages" => measured,
121
+ "report" => format_calibrate(measured, order_ok, distinct)
122
+ }
123
+ end
124
+
125
+ def format_calibrate(measured, order_ok, distinct)
126
+ lines = measured.map { |r| format("%s rank=%s wall=%.6fs cpu=%.6fs", r["stage"], r["known_rank"], r["wall_s"], r["cpu_s"]) }
127
+ status = (order_ok && distinct) ? "PASS" : "FAIL"
128
+ ([status, "order_ok=#{order_ok}", "distinct_wall=#{distinct}"] + lines).join(" | ")
129
+ end
130
+
131
+ def load_ceilings(path)
132
+ return {} unless File.file?(path)
133
+
134
+ JSON.parse(File.read(path))
135
+ end
136
+
137
+ def write_ceilings!(path, ceilings, meta: {})
138
+ FileUtils.mkdir_p(File.dirname(path))
139
+ payload = {
140
+ "meta" => meta.merge("recorded_at" => Time.now.utc.iso8601),
141
+ "ceilings" => ceilings
142
+ }
143
+ File.write(path, JSON.pretty_generate(payload))
144
+ path
145
+ end
146
+
147
+ def new_episode(repository_root:, binding:)
148
+ {
149
+ "started_at" => Time.now.utc.iso8601,
150
+ "finished_at" => nil,
151
+ "repository_root" => repository_root,
152
+ "binding" => binding,
153
+ "calibrate" => nil,
154
+ "load_steps" => [],
155
+ "ceilings_before" => nil,
156
+ "ceilings_after" => nil,
157
+ "iterations" => [],
158
+ "accepted" => false,
159
+ "stop_reason" => nil
160
+ }
161
+ end
162
+
163
+ def append_iteration!(episode, iteration:, primary:, hypothesis:, change:, prove:)
164
+ episode["iterations"] << {
165
+ "n" => iteration,
166
+ "primary_series" => primary,
167
+ "hypothesis" => hypothesis,
168
+ "change" => change,
169
+ "prove" => prove
170
+ }
171
+ episode
172
+ end
173
+
174
+ def write_episode!(episode, path:)
175
+ episode["finished_at"] = Time.now.utc.iso8601
176
+ FileUtils.mkdir_p(File.dirname(path))
177
+ File.write(path, JSON.pretty_generate(episode))
178
+ path
179
+ end
180
+
181
+ def percentile(values, fraction)
182
+ sorted = values.map(&:to_f).sort
183
+ return sorted.first if sorted.length == 1
184
+
185
+ idx = ((sorted.length - 1) * fraction).round
186
+ sorted[idx]
187
+ end
188
+ end
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "objspace"
4
+ require "open3"
5
+
6
+ module Polyrun
7
+ module Benchmark
8
+ module Pressure
9
+ # Wall/CPU/RSS/heap/GC sampling and diffs for {Pressure.measure}.
10
+ module ProcessSample
11
+ module_function
12
+
13
+ def sample
14
+ times = Process.times
15
+ {
16
+ "wall_s" => monotonic_s,
17
+ "cpu_user_s" => times.utime,
18
+ "cpu_system_s" => times.stime,
19
+ "rss_bytes" => rss_bytes,
20
+ "heap_bytes" => heap_bytes,
21
+ "gc" => gc_sample,
22
+ "storage_bytes" => 0,
23
+ "network_in_bytes" => 0,
24
+ "network_out_bytes" => 0
25
+ }
26
+ end
27
+
28
+ def diff(before, after_sample, extras: {})
29
+ wall_s = after_sample["wall_s"] - before["wall_s"]
30
+ cpu = cpu_diff(before, after_sample)
31
+ memory = memory_diff(before, after_sample)
32
+ io = io_diff(before, after_sample, extras)
33
+ {
34
+ "wall_s" => wall_s,
35
+ "cpu_user_s" => cpu[:user],
36
+ "cpu_system_s" => cpu[:system],
37
+ "cpu_s" => cpu[:total],
38
+ "cpu_pct" => wall_s.positive? ? (cpu[:total] / wall_s) * 100.0 : 0.0,
39
+ "rss_bytes" => memory[:rss],
40
+ "rss_delta_bytes" => memory[:rss_delta],
41
+ "heap_bytes" => memory[:heap],
42
+ "heap_delta_bytes" => memory[:heap_delta],
43
+ "gc" => gc_diff(before["gc"], after_sample["gc"]),
44
+ "storage_delta_bytes" => io[:storage],
45
+ "network_in_bytes" => io[:network_in],
46
+ "network_out_bytes" => io[:network_out]
47
+ }
48
+ end
49
+
50
+ def monotonic_s
51
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
52
+ end
53
+
54
+ def rss_bytes
55
+ if File.readable?("/proc/self/status")
56
+ status = File.read("/proc/self/status")
57
+ if (match = status.match(/^VmRSS:\s+(\d+)\s+kB/))
58
+ return match[1].to_i * 1024
59
+ end
60
+ end
61
+
62
+ stdout, status = Open3.capture2("ps", "-o", "rss=", "-p", Process.pid.to_s)
63
+ return 0 unless status.success?
64
+
65
+ stdout.strip.to_i * 1024
66
+ rescue
67
+ 0
68
+ end
69
+
70
+ def heap_bytes
71
+ ObjectSpace.memsize_of_all
72
+ rescue
73
+ 0
74
+ end
75
+
76
+ def gc_sample
77
+ stat = GC.stat
78
+ {
79
+ "count" => stat[:count],
80
+ "allocated_objects" => stat[:total_allocated_objects],
81
+ "heap_live_slots" => stat[:heap_live_slots],
82
+ "heap_free_slots" => stat[:heap_free_slots],
83
+ "major_gc_count" => stat[:major_gc_count],
84
+ "minor_gc_count" => stat[:minor_gc_count]
85
+ }
86
+ end
87
+
88
+ def gc_diff(before, after_sample)
89
+ {
90
+ "count" => after_sample["count"] - before["count"],
91
+ "allocated_objects" => after_sample["allocated_objects"] - before["allocated_objects"],
92
+ "heap_live_slots" => after_sample["heap_live_slots"],
93
+ "heap_live_delta" => after_sample["heap_live_slots"] - before["heap_live_slots"],
94
+ "major_gc_count" => after_sample["major_gc_count"] - before["major_gc_count"],
95
+ "minor_gc_count" => after_sample["minor_gc_count"] - before["minor_gc_count"]
96
+ }
97
+ end
98
+
99
+ def cpu_diff(before, after_sample)
100
+ user = after_sample["cpu_user_s"] - before["cpu_user_s"]
101
+ system = after_sample["cpu_system_s"] - before["cpu_system_s"]
102
+ {user: user, system: system, total: user + system}
103
+ end
104
+
105
+ def memory_diff(before, after_sample)
106
+ {
107
+ rss: after_sample["rss_bytes"],
108
+ rss_delta: after_sample["rss_bytes"] - before["rss_bytes"],
109
+ heap: after_sample["heap_bytes"],
110
+ heap_delta: after_sample["heap_bytes"] - before["heap_bytes"]
111
+ }
112
+ end
113
+
114
+ def io_diff(before, after_sample, extras)
115
+ {
116
+ storage: (after_sample["storage_bytes"] - before["storage_bytes"]) +
117
+ extras.fetch("storage_delta_bytes", 0),
118
+ network_in: (after_sample["network_in_bytes"] - before["network_in_bytes"]) +
119
+ extras.fetch("network_in_bytes", 0),
120
+ network_out: (after_sample["network_out_bytes"] - before["network_out_bytes"]) +
121
+ extras.fetch("network_out_bytes", 0)
122
+ }
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end