polyrun 3.2.0-java

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 (225) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +234 -0
  3. data/CODE_OF_CONDUCT.md +26 -0
  4. data/CONTRIBUTING.md +23 -0
  5. data/LICENSE +21 -0
  6. data/README.md +251 -0
  7. data/SECURITY.md +25 -0
  8. data/bin/polyrun +6 -0
  9. data/docs/QUALITY.md +82 -0
  10. data/docs/QUALITY_CONFIGURATION.md +95 -0
  11. data/docs/SETUP_PROFILE.md +139 -0
  12. data/lib/polyrun/benchmark/pressure/cooker.rb +191 -0
  13. data/lib/polyrun/benchmark/pressure/process_sample.rb +127 -0
  14. data/lib/polyrun/benchmark/pressure.rb +144 -0
  15. data/lib/polyrun/benchmark/profile.rb +191 -0
  16. data/lib/polyrun/benchmark/report.rb +87 -0
  17. data/lib/polyrun/cli/benchmark_commands.rb +66 -0
  18. data/lib/polyrun/cli/ci_shard_hooks.rb +129 -0
  19. data/lib/polyrun/cli/ci_shard_run_command.rb +177 -0
  20. data/lib/polyrun/cli/ci_shard_run_parse.rb +68 -0
  21. data/lib/polyrun/cli/config_command.rb +42 -0
  22. data/lib/polyrun/cli/coverage_commands.rb +150 -0
  23. data/lib/polyrun/cli/coverage_merge_io.rb +150 -0
  24. data/lib/polyrun/cli/database_commands.rb +163 -0
  25. data/lib/polyrun/cli/default_run.rb +144 -0
  26. data/lib/polyrun/cli/doctor_command.rb +94 -0
  27. data/lib/polyrun/cli/env_commands.rb +43 -0
  28. data/lib/polyrun/cli/failure_commands.rb +99 -0
  29. data/lib/polyrun/cli/graph_command.rb +68 -0
  30. data/lib/polyrun/cli/help.rb +83 -0
  31. data/lib/polyrun/cli/helpers.rb +162 -0
  32. data/lib/polyrun/cli/hooks_command.rb +97 -0
  33. data/lib/polyrun/cli/init_command.rb +108 -0
  34. data/lib/polyrun/cli/mutation_command.rb +67 -0
  35. data/lib/polyrun/cli/partition_diagnostics.rb +22 -0
  36. data/lib/polyrun/cli/plan_command.rb +184 -0
  37. data/lib/polyrun/cli/prepare_command.rb +70 -0
  38. data/lib/polyrun/cli/prepare_recipe.rb +82 -0
  39. data/lib/polyrun/cli/quality_commands.rb +65 -0
  40. data/lib/polyrun/cli/queue_command.rb +161 -0
  41. data/lib/polyrun/cli/quick_command.rb +13 -0
  42. data/lib/polyrun/cli/report_commands.rb +108 -0
  43. data/lib/polyrun/cli/run_queue_command.rb +127 -0
  44. data/lib/polyrun/cli/run_shards_command.rb +164 -0
  45. data/lib/polyrun/cli/run_shards_parallel_children.rb +112 -0
  46. data/lib/polyrun/cli/run_shards_parallel_wait.rb +252 -0
  47. data/lib/polyrun/cli/run_shards_plan_boot_phases.rb +207 -0
  48. data/lib/polyrun/cli/run_shards_plan_options.rb +74 -0
  49. data/lib/polyrun/cli/run_shards_planning.rb +123 -0
  50. data/lib/polyrun/cli/run_shards_run.rb +171 -0
  51. data/lib/polyrun/cli/run_shards_worker_interrupt.rb +101 -0
  52. data/lib/polyrun/cli/skip_env.rb +34 -0
  53. data/lib/polyrun/cli/spec_quality_commands.rb +149 -0
  54. data/lib/polyrun/cli/start_bootstrap.rb +126 -0
  55. data/lib/polyrun/cli/timing_command.rb +31 -0
  56. data/lib/polyrun/cli/tool_options.rb +48 -0
  57. data/lib/polyrun/cli/validate_command.rb +26 -0
  58. data/lib/polyrun/cli.rb +272 -0
  59. data/lib/polyrun/config/dotted_path.rb +21 -0
  60. data/lib/polyrun/config/effective.rb +82 -0
  61. data/lib/polyrun/config/resolver.rb +114 -0
  62. data/lib/polyrun/config/schema.rb +39 -0
  63. data/lib/polyrun/config/suite.rb +109 -0
  64. data/lib/polyrun/config/tool_defaults.rb +42 -0
  65. data/lib/polyrun/config/tool_validation.rb +79 -0
  66. data/lib/polyrun/config/tools.rb +120 -0
  67. data/lib/polyrun/config.rb +97 -0
  68. data/lib/polyrun/coverage/cobertura_zero_lines.rb +32 -0
  69. data/lib/polyrun/coverage/collector.rb +169 -0
  70. data/lib/polyrun/coverage/collector_blob.rb +53 -0
  71. data/lib/polyrun/coverage/collector_finish.rb +98 -0
  72. data/lib/polyrun/coverage/collector_fragment_meta.rb +57 -0
  73. data/lib/polyrun/coverage/config_resolve.rb +131 -0
  74. data/lib/polyrun/coverage/example_diff.rb +184 -0
  75. data/lib/polyrun/coverage/example_diff_snapshot.rb +44 -0
  76. data/lib/polyrun/coverage/example_diff_track_filter.rb +51 -0
  77. data/lib/polyrun/coverage/file_stats_report.rb +36 -0
  78. data/lib/polyrun/coverage/filter.rb +22 -0
  79. data/lib/polyrun/coverage/formatter.rb +137 -0
  80. data/lib/polyrun/coverage/merge/formatters.rb +188 -0
  81. data/lib/polyrun/coverage/merge/formatters_html.rb +221 -0
  82. data/lib/polyrun/coverage/merge/html/_file_list.html.erb +21 -0
  83. data/lib/polyrun/coverage/merge/html/_file_section.html.erb +26 -0
  84. data/lib/polyrun/coverage/merge/html/_groups_table.html.erb +18 -0
  85. data/lib/polyrun/coverage/merge/html/_overview.html.erb +47 -0
  86. data/lib/polyrun/coverage/merge/html/report.css +147 -0
  87. data/lib/polyrun/coverage/merge/html/report.js +48 -0
  88. data/lib/polyrun/coverage/merge/html/template.html.erb +30 -0
  89. data/lib/polyrun/coverage/merge.rb +160 -0
  90. data/lib/polyrun/coverage/merge_fragment_meta.rb +58 -0
  91. data/lib/polyrun/coverage/merge_merge_two.rb +168 -0
  92. data/lib/polyrun/coverage/merge_native.rb +39 -0
  93. data/lib/polyrun/coverage/rails.rb +126 -0
  94. data/lib/polyrun/coverage/reporting.rb +41 -0
  95. data/lib/polyrun/coverage/result.rb +18 -0
  96. data/lib/polyrun/coverage/track_files.rb +150 -0
  97. data/lib/polyrun/data/cached_fixtures.rb +122 -0
  98. data/lib/polyrun/data/factory_counts.rb +48 -0
  99. data/lib/polyrun/data/factory_instrumentation.rb +50 -0
  100. data/lib/polyrun/data/fixtures.rb +68 -0
  101. data/lib/polyrun/data/parallel_provisioning.rb +93 -0
  102. data/lib/polyrun/data/snapshot.rb +84 -0
  103. data/lib/polyrun/database/clone_shards.rb +106 -0
  104. data/lib/polyrun/database/provision.rb +83 -0
  105. data/lib/polyrun/database/shard.rb +64 -0
  106. data/lib/polyrun/database/url_builder/connection/infer.rb +53 -0
  107. data/lib/polyrun/database/url_builder/connection/url_builders.rb +43 -0
  108. data/lib/polyrun/database/url_builder/connection.rb +191 -0
  109. data/lib/polyrun/database/url_builder/template_prepare.rb +21 -0
  110. data/lib/polyrun/database/url_builder.rb +188 -0
  111. data/lib/polyrun/debug.rb +81 -0
  112. data/lib/polyrun/env/ci.rb +65 -0
  113. data/lib/polyrun/error.rb +3 -0
  114. data/lib/polyrun/export/csv.rb +25 -0
  115. data/lib/polyrun/export/markdown.rb +47 -0
  116. data/lib/polyrun/graph/client.rb +64 -0
  117. data/lib/polyrun/graph/error.rb +13 -0
  118. data/lib/polyrun/graph/index.rb +75 -0
  119. data/lib/polyrun/graph/inspect.rb +58 -0
  120. data/lib/polyrun/graph/plan.rb +134 -0
  121. data/lib/polyrun/graph/planner.rb +117 -0
  122. data/lib/polyrun/graph/syntax.rb +114 -0
  123. data/lib/polyrun/graph/transaction.rb +81 -0
  124. data/lib/polyrun/graph/worker.rb +55 -0
  125. data/lib/polyrun/graph/workspace.rb +117 -0
  126. data/lib/polyrun/hooks/dsl.rb +128 -0
  127. data/lib/polyrun/hooks/shell_runner.rb +33 -0
  128. data/lib/polyrun/hooks/worker_runner.rb +27 -0
  129. data/lib/polyrun/hooks/worker_shell.rb +50 -0
  130. data/lib/polyrun/hooks.rb +190 -0
  131. data/lib/polyrun/log.rb +86 -0
  132. data/lib/polyrun/minitest_support.rb +60 -0
  133. data/lib/polyrun/mutation/candidates.rb +91 -0
  134. data/lib/polyrun/mutation/operators.rb +51 -0
  135. data/lib/polyrun/mutation/runner.rb +133 -0
  136. data/lib/polyrun/mutation/subjects.rb +88 -0
  137. data/lib/polyrun/partition/constraints.rb +80 -0
  138. data/lib/polyrun/partition/hrw.rb +70 -0
  139. data/lib/polyrun/partition/min_heap.rb +64 -0
  140. data/lib/polyrun/partition/paths.rb +175 -0
  141. data/lib/polyrun/partition/paths_build.rb +141 -0
  142. data/lib/polyrun/partition/plan.rb +250 -0
  143. data/lib/polyrun/partition/plan_lpt.rb +91 -0
  144. data/lib/polyrun/partition/plan_sharding.rb +56 -0
  145. data/lib/polyrun/partition/reports.rb +139 -0
  146. data/lib/polyrun/partition/stable_shuffle.rb +18 -0
  147. data/lib/polyrun/partition/suite.rb +120 -0
  148. data/lib/polyrun/partition/timing_diagnostics.rb +138 -0
  149. data/lib/polyrun/partition/timing_keys.rb +86 -0
  150. data/lib/polyrun/prepare/artifacts.rb +40 -0
  151. data/lib/polyrun/prepare/assets.rb +64 -0
  152. data/lib/polyrun/process_stdio.rb +96 -0
  153. data/lib/polyrun/quality/command.rb +84 -0
  154. data/lib/polyrun/quality/measure.rb +38 -0
  155. data/lib/polyrun/quality/observe.rb +53 -0
  156. data/lib/polyrun/quality/observe_hook.rb +103 -0
  157. data/lib/polyrun/quality/sandbox.rb +70 -0
  158. data/lib/polyrun/queue/duration.rb +30 -0
  159. data/lib/polyrun/queue/file_store.rb +413 -0
  160. data/lib/polyrun/queue/file_store_intent.rb +188 -0
  161. data/lib/polyrun/queue/file_store_pending.rb +48 -0
  162. data/lib/polyrun/queue/worker_loop.rb +73 -0
  163. data/lib/polyrun/quick/assertions.rb +32 -0
  164. data/lib/polyrun/quick/config.rb +56 -0
  165. data/lib/polyrun/quick/errors.rb +6 -0
  166. data/lib/polyrun/quick/example_group.rb +111 -0
  167. data/lib/polyrun/quick/example_runner.rb +129 -0
  168. data/lib/polyrun/quick/matchers.rb +159 -0
  169. data/lib/polyrun/quick/matchers_predicates.rb +122 -0
  170. data/lib/polyrun/quick/reporter.rb +76 -0
  171. data/lib/polyrun/quick/runner.rb +224 -0
  172. data/lib/polyrun/quick.rb +1 -0
  173. data/lib/polyrun/railtie.rb +7 -0
  174. data/lib/polyrun/reporting/failure_merge.rb +171 -0
  175. data/lib/polyrun/reporting/junit.rb +126 -0
  176. data/lib/polyrun/reporting/junit_emit.rb +58 -0
  177. data/lib/polyrun/reporting/junit_report.rb +87 -0
  178. data/lib/polyrun/reporting/rspec_failure_fragment_formatter.rb +95 -0
  179. data/lib/polyrun/reporting/rspec_junit.rb +39 -0
  180. data/lib/polyrun/rspec_support/active_record_timeout_recovery.rb +51 -0
  181. data/lib/polyrun/rspec_support/example_debug.rb +167 -0
  182. data/lib/polyrun/rspec_support/example_debug_instrumentation.rb +73 -0
  183. data/lib/polyrun/rspec_support/sharded_formatter_compat.rb +57 -0
  184. data/lib/polyrun/rspec_support.rb +110 -0
  185. data/lib/polyrun/spec_quality/config.rb +139 -0
  186. data/lib/polyrun/spec_quality/fragment.rb +39 -0
  187. data/lib/polyrun/spec_quality/merge.rb +78 -0
  188. data/lib/polyrun/spec_quality/minitest_hook.rb +42 -0
  189. data/lib/polyrun/spec_quality/plan_loader.rb +47 -0
  190. data/lib/polyrun/spec_quality/profile.rb +102 -0
  191. data/lib/polyrun/spec_quality/report.rb +363 -0
  192. data/lib/polyrun/spec_quality/rspec_hook.rb +55 -0
  193. data/lib/polyrun/spec_quality/sql_counter.rb +34 -0
  194. data/lib/polyrun/spec_quality.rb +212 -0
  195. data/lib/polyrun/sus_support.rb +55 -0
  196. data/lib/polyrun/templates/POLYRUN.md +51 -0
  197. data/lib/polyrun/templates/ci_matrix.polyrun.yml +22 -0
  198. data/lib/polyrun/templates/minimal_gem.polyrun.yml +13 -0
  199. data/lib/polyrun/templates/polyrun_hooks_spec_quality.rb +12 -0
  200. data/lib/polyrun/templates/polyrun_spec_quality.yml +20 -0
  201. data/lib/polyrun/templates/rails_prepare.polyrun.yml +51 -0
  202. data/lib/polyrun/templates/rails_prepare_task.rake +16 -0
  203. data/lib/polyrun/timing/merge.rb +36 -0
  204. data/lib/polyrun/timing/rspec_example_formatter.rb +60 -0
  205. data/lib/polyrun/timing/stats.rb +76 -0
  206. data/lib/polyrun/timing/summary.rb +78 -0
  207. data/lib/polyrun/timing/variance_report.rb +51 -0
  208. data/lib/polyrun/version.rb +3 -0
  209. data/lib/polyrun/worker_output.rb +181 -0
  210. data/lib/polyrun/worker_output_forwarders.rb +94 -0
  211. data/lib/polyrun/worker_ping.rb +77 -0
  212. data/lib/polyrun.rb +59 -0
  213. data/polyrun.gemspec +49 -0
  214. data/sig/polyrun/cli.rbs +6 -0
  215. data/sig/polyrun/config.rbs +20 -0
  216. data/sig/polyrun/debug.rbs +12 -0
  217. data/sig/polyrun/log.rbs +12 -0
  218. data/sig/polyrun/minitest_support.rbs +7 -0
  219. data/sig/polyrun/quick.rbs +19 -0
  220. data/sig/polyrun/rspec_support.rbs +21 -0
  221. data/sig/polyrun/sus_support.rbs +7 -0
  222. data/sig/polyrun/worker_output.rbs +11 -0
  223. data/sig/polyrun/worker_ping.rbs +10 -0
  224. data/sig/polyrun.rbs +11 -0
  225. metadata +463 -0
@@ -0,0 +1,83 @@
1
+ module Polyrun
2
+ class CLI
3
+ module Help
4
+ def print_help
5
+ Polyrun::Log.puts <<~HELP
6
+ usage: polyrun [global options] [<command> | <paths...>]
7
+
8
+ With no command, runs parallel tests for the resolved suite: partition.suite when set; else suite inferred from partition.paths_file; else filesystem auto-detect (RSpec under spec/, then Sus when config/sus.rb + test/**/*.rb, then Minitest *_test.rb, then Polyrun Quick). If the first argument is a known subcommand name, it is dispatched. Otherwise, path-like tokens (optionally with run-shards flags such as --workers) shard those files in parallel; see commands below.
9
+
10
+ global options:
11
+ -c, --config PATH polyrun.yml path (or POLYRUN_CONFIG)
12
+ --suite NAME apply suites.NAME overlay from polyrun.yml (or POLYRUN_SUITE)
13
+ -v, --verbose
14
+ -h, --help
15
+
16
+ Trace timing (stderr): DEBUG=1 or POLYRUN_DEBUG=1
17
+ Coverage: POLYRUN_COVERAGE=1 or Covered-style COVERAGE=<report>; (or config/polyrun_coverage.yml + POLYRUN_QUICK_COVERAGE=1); POLYRUN_COVERAGE_DISABLE=1 skips; POLYRUN_COVERAGE_BRANCHES=1 for branch data in fragments; POLYRUN_COVERAGE_VERBOSE=1 for per-worker and merged console summaries
18
+ Benchmark profiles: POLYRUN_BENCH=1 (stdout); JSON sidecar in tmp/benchmarks/; POLYRUN_BENCH_FORMATS=csv,markdown for extra exports; report-benchmark / bench
19
+ Hooks shell output: POLYRUN_HOOKS_VERBOSE=1 or -v / POLYRUN_VERBOSE=1 (or DEBUG); failures always print
20
+ Merge profiling (stderr): POLYRUN_PROFILE_MERGE=1 (or verbose / DEBUG)
21
+ Post-merge formats (run-shards): POLYRUN_MERGE_FORMATS (default: json,lcov,cobertura,console,html,csv,markdown)
22
+ Start skips: POLYRUN_SKIP_PREPARE=1, POLYRUN_SKIP_DATABASES=1 (legacy aliases: POLYRUN_START_SKIP_PREPARE, POLYRUN_START_SKIP_DATABASES); POLYRUN_SKIP_BUILD_SPEC_PATHS=1
23
+ Paths build skip: POLYRUN_SKIP_PATHS_BUILD=1
24
+ Named suite: --suite NAME or POLYRUN_SUITE (see suites: in polyrun.yml)
25
+ Slow merge warning (seconds, default 10; 0 disables): POLYRUN_MERGE_SLOW_WARN_SECONDS
26
+ Failure merge: run-shards --merge-failures (enable failure fragments in test setup); POLYRUN_MERGE_FAILURES=1, POLYRUN_FAILURE_FRAGMENT_DIR, POLYRUN_MERGED_FAILURES_OUT
27
+ Parallel workers: POLYRUN_WORKERS, else top-level workers: in polyrun.yml, else default 5, max 10 (run-shards / parallel-rspec / start). CI local processes per job: POLYRUN_SHARD_PROCESSES or ci-shard --shard-processes (not POLYRUN_WORKERS)
28
+ Coverage config: config/polyrun_coverage.yml overlays inline coverage: in polyrun.yml (formats -> report_formats; directory output_path -> report_output_dir)
29
+ Per-worker wall timeout: --worker-timeout SEC or POLYRUN_WORKER_TIMEOUT_SEC. Exit 124; parent stops remaining workers.
30
+ Per-worker idle timeout: --worker-idle-timeout SEC or POLYRUN_WORKER_IDLE_TIMEOUT_SEC after a progress ping (POLYRUN_WORKER_PING_FILE). Enable pings in test setup. Exit 125. Optional periodic pings: POLYRUN_WORKER_PING_THREAD=1 (POLYRUN_WORKER_PING_INTERVAL_SEC).
31
+ Worker output routing (opt-in): POLYRUN_WORKER_OUTPUT_ROUTING=1 or POLYRUN_WORKER_LOG_DIR; per-shard logs under tmp/polyrun/workers (POLYRUN_WORKER_OUTPUT_PREFIX=0 for log-only)
32
+ Example debug (RSpec, opt-in): POLYRUN_EXAMPLE_DEBUG=1 (print/Rails logging/timeouts); POLYRUN_DEBUG_SQL / DEBUG_SQL; POLYRUN_DEBUG_TRACE / DEBUG_TRACE; DEBUG_PROSOPITE=1
33
+ Sharded formatter compat: silences per-worker seed, summary, and pending lines under POLYRUN_SHARD_* (see docs/SETUP_PROFILE.md)
34
+ Orchestration warnings on process stderr: POLYRUN_ORCHESTRATION_STDERR=1
35
+ Spec quality (opt-in): POLYRUN_SPEC_QUALITY=1; run-shards --merge-spec-quality; merge-spec-quality / report-spec-quality
36
+ Partition timing granularity (default file): POLYRUN_TIMING_GRANULARITY=file|example (experimental; see partition.timing_granularity)
37
+ Partition strategies: round_robin (default, sorted), preserve_order_round_robin (paths-file order), lazy_robin (sorted RR + timing diagnostics), cost_binpack (LPT), hrw. partition.timing_file without strategy implies cost_binpack.
38
+
39
+ commands:
40
+ version print version
41
+ graph opt-in Ruby graph edits (--enable or graph.enabled); index, inspect, plan, check, apply
42
+ mutate opt-in mutation testing (--enable or mutation.enabled); configurable subjects, workers, and CI shards
43
+ measure opt-in command measurements (--enable or quality settings), optional JSON ceilings
44
+ observe opt-in Ruby call observation (--enable or quality settings); --output PATH required
45
+ plan emit partition manifest JSON
46
+ prepare run prepare recipe: default | assets (optional prepare.command overrides bin/rails assets:precompile) | shell (prepare.command required)
47
+ merge-coverage merge SimpleCov JSON fragments (json/lcov/cobertura/console/html/csv/markdown)
48
+ merge-failures merge per-shard failure JSONL fragments or RSpec JSON files (jsonl/json/csv/markdown)
49
+ run-shards fan out N parallel OS processes (POLYRUN_SHARD_*; not Ruby threads); optional --merge-coverage / --merge-failures / --merge-spec-quality
50
+ parallel-rspec run-shards + merge-coverage (defaults to: bundle exec rspec after --); no start prepare/DB bootstrap
51
+ parallel-minitest run-shards + merge-coverage (defaults to: bundle exec rails test or ruby -I test after --); no start prepare/DB bootstrap
52
+ parallel-sus run-shards + merge-coverage (defaults to: bundle exec sus after --); no start prepare/DB bootstrap
53
+ parallel-quick run-shards + merge-coverage (defaults to: bundle exec polyrun quick after --); no start prepare/DB bootstrap
54
+ start parallel-rspec; auto-runs prepare (shell/assets) and db:setup-* when polyrun.yml configures them; legacy script/build_spec_paths.rb if paths_build absent
55
+ ci-shard-run CI matrix: build-paths + plan for POLYRUN_SHARD_INDEX / POLYRUN_SHARD_TOTAL (or config), then run your command with that shard's paths after --; optional --shard-processes M or --workers M (POLYRUN_SHARD_PROCESSES; not POLYRUN_WORKERS) for N×M jobs × processes on this host
56
+ ci-shard-rspec same as ci-shard-run -- bundle exec rspec; optional --shard-processes / --workers / -- [rspec-only flags]
57
+ ci-shard-sus same as ci-shard-run -- bundle exec sus; optional --shard-processes / --workers / -- [sus-only flags]
58
+ build-paths write partition.paths_file from partition.paths_build (same as auto step before plan/run-shards)
59
+ init write a starter polyrun.yml or POLYRUN.md from built-in templates (see docs/SETUP_PROFILE.md)
60
+ queue file-backed batch queue: init (optional --shard/--total etc. as plan, then claim/ack/reclaim/status --json)
61
+ run-queue init queue and run N workers that claim batches until drained
62
+ quick quick test runner (describe/with/it, before/after/around, let/subject, expect…to, assert_*; config/polyrun_quick.rb; optional capybara!)
63
+ hook run <phase> run one shell hook from polyrun.yml hooks: (e.g. before_suite); optional --shard/--total
64
+ report-coverage write all coverage formats from one JSON file
65
+ report-junit RSpec JSON or Polyrun testcase JSON → JUnit XML, CSV, or Markdown
66
+ report-timing slow-file summary from merged timing JSON (text/csv/markdown)
67
+ report-benchmark benchmark profile export from tmp/benchmarks/profile_*.json
68
+ bench run performance benchmark specs (same as rake bench_performance)
69
+ merge-timing merge polyrun_timing_*.json shards
70
+ merge-spec-quality merge polyrun-spec-quality-fragment-*.jsonl shards
71
+ report-spec-quality spec quality report from merged JSON (text/json/csv/markdown)
72
+ config print effective config by dotted path (loaded YAML plus merged prepare.env, resolved partition shard fields, workers)
73
+ validate check polyrun.yml top-level keys (unknown keys exit 1)
74
+ doctor print effective config summary (file, suite, start gates, DBs, coverage)
75
+ env print shard + database env (see polyrun.yml databases)
76
+ db:setup-template migrate template DB (PostgreSQL)
77
+ db:setup-shard CREATE DATABASE shard FROM template (one POLYRUN_SHARD_INDEX)
78
+ db:clone-shards migrate templates + DROP/CREATE all shard DBs (replaces clone_shard shell scripts)
79
+ HELP
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,162 @@
1
+ require "yaml"
2
+
3
+ require_relative "../partition/timing_keys"
4
+
5
+ module Polyrun
6
+ class CLI
7
+ module Helpers
8
+ private
9
+
10
+ def env_int(name, fallback)
11
+ Polyrun::Config::Resolver.env_int(name, fallback)
12
+ end
13
+
14
+ # Shared timing → costs/strategy resolution for +plan+ and +run-shards+.
15
+ # @return [Array] +[costs, strategy, error_code]+ where +error_code+ is nil on success
16
+ def partition_resolve_costs_and_strategy(
17
+ timing_path,
18
+ strategy,
19
+ timing_granularity,
20
+ strategy_explicit: false,
21
+ log_prefix: "polyrun"
22
+ )
23
+ strategy = strategy.to_s
24
+ if timing_path
25
+ if strategy_explicit && strategy == "round_robin"
26
+ return [nil, strategy, nil]
27
+ end
28
+
29
+ costs = Polyrun::Partition::Plan.load_timing_costs(
30
+ File.expand_path(timing_path.to_s, Dir.pwd),
31
+ granularity: timing_granularity
32
+ )
33
+ if costs.empty?
34
+ Polyrun::Log.warn "#{log_prefix}: timing file missing or empty: #{timing_path}"
35
+ return [nil, nil, 2]
36
+ end
37
+ if Polyrun::Partition::Plan.timing_load_strategy?(strategy)
38
+ return [costs, strategy, nil]
39
+ end
40
+ unless strategy_explicit
41
+ Polyrun::Log.warn "#{log_prefix}: using cost_binpack (timing data present)" if @verbose
42
+ return [costs, "cost_binpack", nil]
43
+ end
44
+
45
+ [nil, strategy, nil]
46
+ elsif Polyrun::Partition::Plan.cost_strategy?(strategy) || Polyrun::Partition::Plan.lazy_robin_strategy?(strategy)
47
+ Polyrun::Log.warn "#{log_prefix}: --timing or partition.timing_file required for strategy #{strategy}"
48
+ [nil, nil, 2]
49
+ else
50
+ [nil, strategy, nil]
51
+ end
52
+ end
53
+
54
+ # Per-worker wall clock (from spawn) for run-shards / ci-shard fan-out; unset or invalid means no limit.
55
+ def env_worker_timeout_sec(cfg = nil)
56
+ shared = cfg ? Polyrun::Config::Tools.stringify(cfg.raw) : {}
57
+ s = (ENV["POLYRUN_WORKER_TIMEOUT_SEC"] || ENV["POLYRUN_TIMEOUT"] || shared["timeout"]).to_s.strip
58
+ return nil if s.empty?
59
+
60
+ f = Float(s, exception: false)
61
+ return nil if f.nil? || f <= 0
62
+
63
+ f
64
+ end
65
+
66
+ # Max seconds without a new monotonic timestamp ping in the worker (see +polyrun/worker_ping+).
67
+ def env_worker_idle_timeout_sec
68
+ s = ENV["POLYRUN_WORKER_IDLE_TIMEOUT_SEC"].to_s.strip
69
+ return nil if s.empty?
70
+
71
+ f = Float(s, exception: false)
72
+ return nil if f.nil? || f <= 0
73
+
74
+ f
75
+ end
76
+
77
+ def resolve_shard_index(pc)
78
+ Polyrun::Config::Resolver.resolve_shard_index(pc)
79
+ end
80
+
81
+ def resolve_shard_total(pc)
82
+ Polyrun::Config::Resolver.resolve_shard_total(pc)
83
+ end
84
+
85
+ def expand_merge_input_pattern(path)
86
+ p = path.to_s
87
+ abs = File.expand_path(p, Dir.pwd)
88
+ return Dir.glob(abs).sort if p.include?("*") || p.include?("?")
89
+
90
+ [abs]
91
+ end
92
+
93
+ # Same rounding/strict semantics as {Polyrun::Coverage::Collector}; see {Coverage::ConfigResolve}.
94
+ def coverage_minimum_line_gate_from_polyrun_coverage_yml(config_path: nil)
95
+ require_relative "../coverage/config_resolve"
96
+ Polyrun::Coverage::ConfigResolve.minimum_line_gate(root: Dir.pwd, polyrun_config_path: config_path)
97
+ end
98
+
99
+ def load_partition_constraints(pc, constraints_path)
100
+ if constraints_path
101
+ path = File.expand_path(constraints_path.to_s, Dir.pwd)
102
+ unless File.file?(path)
103
+ Polyrun::Log.warn "polyrun: constraints file not found: #{path}"
104
+ return nil
105
+ end
106
+ h = YAML.safe_load_file(path, permitted_classes: [Symbol], aliases: true)
107
+ return Polyrun::Partition::Constraints.from_hash(h, root: Dir.pwd)
108
+ end
109
+ if pc["constraints"].is_a?(Hash)
110
+ return Polyrun::Partition::Constraints.from_hash(pc["constraints"], root: Dir.pwd)
111
+ end
112
+ cf = pc["constraints_file"] || pc[:constraints_file]
113
+ if cf
114
+ path = File.expand_path(cf.to_s, Dir.pwd)
115
+ return nil unless File.file?(path)
116
+
117
+ h = YAML.safe_load_file(path, permitted_classes: [Symbol], aliases: true)
118
+ return Polyrun::Partition::Constraints.from_hash(h, root: Dir.pwd)
119
+ end
120
+ nil
121
+ end
122
+
123
+ # +default_weight+ should be precomputed when sorting many paths (e.g. +queue init+), matching
124
+ # {Partition::Plan#default_weight} semantics: mean of known timing costs for missing paths.
125
+ def queue_weight_for(path, costs, default_weight = nil, granularity: :file)
126
+ g = Polyrun::Partition::TimingKeys.normalize_granularity(granularity)
127
+ key = Polyrun::Partition::TimingKeys.normalize_locator(path.to_s, Dir.pwd, g)
128
+ return costs[key] if costs.key?(key)
129
+
130
+ unless default_weight.nil?
131
+ return default_weight
132
+ end
133
+
134
+ vals = costs.values
135
+ return 1.0 if vals.empty?
136
+
137
+ vals.sum / vals.size.to_f
138
+ end
139
+
140
+ # CLI + polyrun.yml + POLYRUN_TIMING_GRANULARITY; default +:file+.
141
+ def resolve_partition_timing_granularity(pc, cli_val)
142
+ Polyrun::Config::Resolver.resolve_partition_timing_granularity(pc, cli_val)
143
+ end
144
+
145
+ def load_stable_assignment(pc)
146
+ path = pc["stable_assignment_file"] || pc[:stable_assignment_file]
147
+ return nil unless path
148
+
149
+ abs = File.expand_path(path.to_s, Dir.pwd)
150
+ return nil unless File.file?(abs)
151
+
152
+ data = JSON.parse(File.read(abs))
153
+ return data if data.is_a?(Hash)
154
+
155
+ nil
156
+ rescue JSON::ParserError
157
+ Polyrun::Log.warn "polyrun: invalid stable_assignment_file JSON: #{abs}"
158
+ nil
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,97 @@
1
+ module Polyrun
2
+ class CLI
3
+ # +polyrun hook run <phase>+ — run one lifecycle phase from +polyrun.yml+ +hooks:+ (manual debugging / CI).
4
+ module HooksCommand
5
+ private
6
+
7
+ def cmd_hook(argv, config_path)
8
+ sub = argv.shift
9
+ case sub
10
+ when "run"
11
+ cmd_hook_run(argv, config_path)
12
+ when nil, "help", "-h", "--help"
13
+ print_hook_help
14
+ 0
15
+ else
16
+ Polyrun::Log.warn "polyrun hook: unknown subcommand #{sub.inspect} (try: polyrun hook run <phase>)"
17
+ print_hook_help
18
+ 2
19
+ end
20
+ end
21
+
22
+ def cmd_hook_run(argv, config_path)
23
+ phase = argv.shift
24
+ if phase.nil? || phase == "-h" || phase == "--help"
25
+ print_hook_help
26
+ return 2
27
+ end
28
+
29
+ shard, total = hook_run_parse_shard_flags!(argv)
30
+
31
+ unless argv.empty?
32
+ Polyrun::Log.warn "polyrun hook run: unexpected arguments: #{argv.inspect}"
33
+ return 2
34
+ end
35
+
36
+ phase_sym = Polyrun::Hooks.parse_phase(phase)
37
+ unless phase_sym && Polyrun::Hooks::PHASES.include?(phase_sym)
38
+ Polyrun::Log.warn "polyrun hook run: unknown phase #{phase.inspect} (expected: #{Polyrun::Hooks::PHASES.join(", ")})"
39
+ return 2
40
+ end
41
+
42
+ cfg = Polyrun::Config.load(path: config_path || ENV["POLYRUN_CONFIG"])
43
+ hook_cfg = Polyrun::Hooks.from_config(cfg)
44
+ env = hook_run_env(shard, total)
45
+
46
+ hook_cfg.run_phase(phase_sym, env)
47
+ rescue ArgumentError => e
48
+ Polyrun::Log.warn "polyrun hook run: #{e.message}"
49
+ 2
50
+ end
51
+
52
+ def hook_run_parse_shard_flags!(argv)
53
+ shard = nil
54
+ total = nil
55
+ while (a = argv.first)
56
+ case a
57
+ when "--shard"
58
+ argv.shift
59
+ shard = Integer(argv.shift || (raise ArgumentError, "--shard needs a value"))
60
+ when "--total"
61
+ argv.shift
62
+ total = Integer(argv.shift || (raise ArgumentError, "--total needs a value"))
63
+ else
64
+ break
65
+ end
66
+ end
67
+ [shard, total]
68
+ end
69
+
70
+ def hook_run_env(shard, total)
71
+ env = ENV.to_h.merge(
72
+ "POLYRUN_HOOK_ORCHESTRATOR" => "1",
73
+ "POLYRUN_HOOK_CLI" => "1"
74
+ )
75
+ env["POLYRUN_SHARD_INDEX"] = shard.to_s unless shard.nil?
76
+ env["POLYRUN_SHARD_TOTAL"] = total.to_s unless total.nil?
77
+ env
78
+ end
79
+
80
+ def print_hook_help
81
+ Polyrun::Log.puts <<~HELP
82
+ usage: polyrun hook run <phase> [--shard N] [--total M]
83
+
84
+ Runs hook(s) from polyrun.yml: Ruby DSL (+hooks.ruby+) then shell strings for <phase> (same names as RSpec lifecycle:
85
+ before_suite / after_suite as before(:suite) / after(:suite); before_shard / after_shard as
86
+ before(:all) / after(:all); before_worker / after_worker as before(:each) / after(:each)).
87
+
88
+ Phases: #{Polyrun::Hooks::PHASES.join(", ")}
89
+
90
+ Optional --shard / --total set POLYRUN_SHARD_INDEX / POLYRUN_SHARD_TOTAL for the hook process.
91
+ POLYRUN_HOOKS_DISABLE=1 skips hooks during run-shards / ci-shard only; polyrun hook run still executes.
92
+ For CI matrix (POLYRUN_SHARD_TOTAL > 1), ci-shard-run skips before_suite / after_suite unless POLYRUN_HOOKS_SUITE_PER_MATRIX_JOB=1; run those phases here or in a dedicated CI job.
93
+ HELP
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,108 @@
1
+ require "optparse"
2
+ require "fileutils"
3
+
4
+ module Polyrun
5
+ class CLI
6
+ module InitCommand
7
+ INIT_PROFILES = {
8
+ "gem" => "minimal_gem.polyrun.yml",
9
+ "rails" => "rails_prepare.polyrun.yml",
10
+ "rails-prepare-task" => "rails_prepare_task.rake",
11
+ "ci-matrix" => "ci_matrix.polyrun.yml",
12
+ "spec-quality" => "polyrun_spec_quality.yml",
13
+ "doc" => "POLYRUN.md"
14
+ }.freeze
15
+
16
+ private
17
+
18
+ def templates_dir
19
+ File.expand_path("../templates", __dir__)
20
+ end
21
+
22
+ def cmd_init(argv, _config_path)
23
+ profile, output, dry_run, force, list = init_parse_options!(argv)
24
+ return init_list_profiles if list
25
+ return init_missing_profile if profile.nil?
26
+
27
+ filename = INIT_PROFILES[profile]
28
+ return init_unknown_profile(profile) unless filename
29
+
30
+ src = File.join(templates_dir, filename)
31
+ return init_missing_template(src) unless File.file?(src)
32
+
33
+ body = File.read(src, encoding: Encoding::UTF_8)
34
+ dest = output || default_init_output(profile)
35
+ return init_dry_run_print(body) if dry_run
36
+
37
+ path = File.expand_path(dest)
38
+ return init_refuses_overwrite(path) if File.file?(path) && !force
39
+
40
+ FileUtils.mkdir_p(File.dirname(path))
41
+ File.write(path, body)
42
+ Polyrun::Log.warn "polyrun init: wrote #{path}"
43
+ 0
44
+ end
45
+
46
+ def init_parse_options!(argv)
47
+ profile = nil
48
+ output = nil
49
+ dry_run = false
50
+ force = false
51
+ list = false
52
+
53
+ OptionParser.new do |opts|
54
+ opts.banner = "usage: polyrun init [--profile NAME] [--output PATH] [--dry-run] [--force]\n polyrun init --list"
55
+ opts.on("--profile NAME", INIT_PROFILES.keys.join(", ")) { |p| profile = p }
56
+ opts.on("-o", "--output PATH", "destination file (default: polyrun.yml or POLYRUN.md for --profile doc)") { |p| output = p }
57
+ opts.on("--dry-run", "print template to stdout; do not write") { dry_run = true }
58
+ opts.on("--force", "overwrite existing output file") { force = true }
59
+ opts.on("--list", "print available profiles") { list = true }
60
+ end.parse!(argv)
61
+
62
+ [profile, output, dry_run, force, list]
63
+ end
64
+
65
+ def init_list_profiles
66
+ Polyrun::Log.puts "polyrun init profiles:"
67
+ INIT_PROFILES.each do |name, file|
68
+ Polyrun::Log.puts " #{name.ljust(12)} #{file}"
69
+ end
70
+ 0
71
+ end
72
+
73
+ def init_missing_profile
74
+ Polyrun::Log.warn "polyrun init: specify --profile (#{INIT_PROFILES.keys.join(", ")}) or --list"
75
+ 2
76
+ end
77
+
78
+ def init_unknown_profile(profile)
79
+ Polyrun::Log.warn "polyrun init: unknown profile #{profile.inspect}"
80
+ 2
81
+ end
82
+
83
+ def init_missing_template(src)
84
+ Polyrun::Log.warn "polyrun init: template missing: #{src}"
85
+ 1
86
+ end
87
+
88
+ def init_dry_run_print(body)
89
+ Polyrun::Log.print body
90
+ 0
91
+ end
92
+
93
+ def init_refuses_overwrite(path)
94
+ Polyrun::Log.warn "polyrun init: #{path} exists (use --force to overwrite)"
95
+ 1
96
+ end
97
+
98
+ def default_init_output(profile)
99
+ case profile
100
+ when "doc" then "POLYRUN.md"
101
+ when "spec-quality" then "config/polyrun_spec_quality.yml"
102
+ when "rails-prepare-task" then "lib/tasks/polyrun_prepare.rake"
103
+ else "polyrun.yml"
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,67 @@
1
+ require "json"
2
+ require_relative "../graph/error"
3
+
4
+ module Polyrun
5
+ class CLI
6
+ module MutationCommand
7
+ private
8
+
9
+ def cmd_mutate(argv)
10
+ options = {}
11
+ command = extract_tool_command!(argv)
12
+ parse_mutation_options!(argv, options)
13
+ settings = configured_tool("mutation", options)
14
+ require_relative "../mutation/runner"
15
+ subjects = mutation_subjects(settings)
16
+ report = Mutation::Runner.new(root: settings["root"], settings: settings,
17
+ arguments: command || settings["command"]).call(subjects, shard: settings["shard"], total: settings["total"])
18
+ payload = JSON.generate(report)
19
+ File.write(settings["output"], payload + "\n") if settings["output"]
20
+ Polyrun::Log.puts payload
21
+ report["ok"] ? 0 : 1
22
+ rescue OptionParser::ParseError, ArgumentError, KeyError, JSON::ParserError, SystemCallError, Graph::Error, Psych::Exception => e
23
+ Polyrun::Log.warn "mutate: #{e.message}"
24
+ 2
25
+ end
26
+
27
+ def parse_mutation_options!(argv, options)
28
+ parser = OptionParser.new do |opts|
29
+ common_tool_options(opts, options)
30
+ %w[max-mutations workers shard total].each do |key|
31
+ opts.on("--#{key} N", Integer) { |value| options[key.tr("-", "_").to_sym] = value }
32
+ end
33
+ %w[subjects-file plan output].each do |key|
34
+ opts.on("--#{key} PATH") { |value| options[key.tr("-", "_").to_sym] = value }
35
+ end
36
+ opts.on("--subject EXPRESSION") { |value| (options[:subjects] ||= []) << value }
37
+ opts.on("--observed PATH") { |value| (options[:observed] ||= []) << value }
38
+ end
39
+ raise ArgumentError, "unexpected mutation arguments" unless parser.parse(argv).empty?
40
+ end
41
+
42
+ def mutation_file_subjects(settings)
43
+ path = File.expand_path(settings["subjects_file"], settings["root"])
44
+ raise ArgumentError, "subjects file is too large" if File.size(path) > settings["max_input_bytes"]
45
+
46
+ File.readlines(path, chomp: true).reject(&:empty?)
47
+ end
48
+
49
+ def mutation_graph_settings(root)
50
+ cfg = Config.load(path: ENV["POLYRUN_CONFIG"], root: root)
51
+ Config::Tools.resolve(cfg, "graph", root: root)
52
+ end
53
+
54
+ def mutation_subjects(settings)
55
+ subjects = settings["subjects"].dup
56
+ subjects.concat(mutation_file_subjects(settings)) if settings["subjects_file"]
57
+ if settings["plan"] || !settings["observed"].empty?
58
+ require_relative "../mutation/subjects"
59
+ graph = mutation_graph_settings(settings["root"])
60
+ subjects.concat(Mutation::Subjects.from_plan(settings["root"], settings["plan"], settings: graph)) if settings["plan"]
61
+ settings["observed"].each { |path| subjects.concat(Mutation::Subjects.from_observation(File.expand_path(path, settings["root"]), max_bytes: settings["max_artifact_bytes"])) }
62
+ end
63
+ subjects
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,22 @@
1
+ module Polyrun
2
+ class CLI
3
+ # Shared stderr diagnostics after {Partition::Plan} is built.
4
+ module PartitionDiagnostics
5
+ private
6
+
7
+ def partition_emit_diagnostics!(plan:, items:, costs:, timing_path:, granularity: :file)
8
+ return unless timing_path && costs && !costs.empty?
9
+
10
+ analysis = Polyrun::Partition::TimingDiagnostics.analyze(
11
+ items: items,
12
+ costs: costs,
13
+ timing_path: timing_path,
14
+ root: plan.root,
15
+ granularity: granularity
16
+ )
17
+ Polyrun::Partition::TimingDiagnostics.emit_warnings!(analysis)
18
+ Polyrun::Partition::Reports.emit_all!(plan)
19
+ end
20
+ end
21
+ end
22
+ end