polyrun-legacy 0.1.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 +7 -0
- data/CHANGELOG.md +8 -0
- data/CODE_OF_CONDUCT.md +26 -0
- data/CONTRIBUTING.md +23 -0
- data/LICENSE +21 -0
- data/README.md +115 -0
- data/SECURITY.md +25 -0
- data/bin/polyrun +5 -0
- data/lib/polyrun/legacy/cli.rb +102 -0
- data/lib/polyrun/legacy/compat.rb +53 -0
- data/lib/polyrun/legacy/config_commands.rb +52 -0
- data/lib/polyrun/legacy/configuration.rb +115 -0
- data/lib/polyrun/legacy/coverage_formats.rb +95 -0
- data/lib/polyrun/legacy/coverage_reports.rb +74 -0
- data/lib/polyrun/legacy/failure_reports.rb +100 -0
- data/lib/polyrun/legacy/junit_reports.rb +115 -0
- data/lib/polyrun/legacy/lifecycle.rb +95 -0
- data/lib/polyrun/legacy/merge.rb +139 -0
- data/lib/polyrun/legacy/options.rb +48 -0
- data/lib/polyrun/legacy/partition.rb +22 -0
- data/lib/polyrun/legacy/partition_plan.rb +105 -0
- data/lib/polyrun/legacy/paths.rb +59 -0
- data/lib/polyrun/legacy/planning_commands.rb +104 -0
- data/lib/polyrun/legacy/process_launch.rb +78 -0
- data/lib/polyrun/legacy/report_commands.rb +61 -0
- data/lib/polyrun/legacy/run_shards.rb +59 -0
- data/lib/polyrun/legacy/shard_commands.rb +132 -0
- data/lib/polyrun/legacy/shard_env.rb +34 -0
- data/lib/polyrun/legacy/shard_heap.rb +35 -0
- data/lib/polyrun/legacy/table.rb +54 -0
- data/lib/polyrun/legacy/timings.rb +103 -0
- data/lib/polyrun/legacy/version.rb +5 -0
- data/lib/polyrun/legacy/worker_wait.rb +80 -0
- data/lib/polyrun/legacy/yaml_data.rb +116 -0
- data/lib/polyrun/legacy.rb +7 -0
- data/polyrun-legacy.gemspec +44 -0
- metadata +91 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: cb19fd082e88b0015e476d9d7d1d459f4aefe7fe378f6a1e3760979e28f52f42
|
|
4
|
+
data.tar.gz: dde31b31d8984272a695e940662153e62682bc04fdc0fa6ce2db685d6eb62dd1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2016944512c96197e4f3334dcaeed0755a3a1a88f42ed72c368b1426c421ebd660a688190ffda6f5cbbe7012d022308d2d92b4ded9d437792ad13d3ec3a4c381
|
|
7
|
+
data.tar.gz: 42590112d33d250cafb4215c4321ca8f5b5682aba6d2a145645762fb5a0375abe289a7175c3333d253afe150b8c6b26ab40ef8d5488dab50398f300dd35a2f83
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (2026-12-01)
|
|
4
|
+
|
|
5
|
+
- Plan and run local or CI shards with round-robin, timing-based, and rendezvous assignments.
|
|
6
|
+
- Run RSpec, Minitest, and Sus suites, with worker timeouts and per-shard logs.
|
|
7
|
+
- Load suite configuration, prepare the environment, and run explicit shell hooks.
|
|
8
|
+
- Merge SimpleCov coverage, timing data, and worker failures. Export coverage reports and JUnit results.
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Pledge
|
|
4
|
+
|
|
5
|
+
Participation is a harassment-free experience. Treat each other with respect. Keep private context private.
|
|
6
|
+
|
|
7
|
+
## Expected behavior
|
|
8
|
+
|
|
9
|
+
- Engage with genuine curiosity. Admit uncertainty.
|
|
10
|
+
- Own every line you submit, including generated code.
|
|
11
|
+
- Correct errors politely.
|
|
12
|
+
- Use language that welcomes people and respects identity and privacy.
|
|
13
|
+
|
|
14
|
+
## Unacceptable behavior
|
|
15
|
+
|
|
16
|
+
- Harassment, trolling, or insulting comments, public or private.
|
|
17
|
+
- Using jargon or volume, including automated spam, to silence others.
|
|
18
|
+
- Sharing others' data or personal context without permission.
|
|
19
|
+
|
|
20
|
+
## Automation
|
|
21
|
+
|
|
22
|
+
You remain responsible for bugs, security holes, and bias in generated artifacts you submit.
|
|
23
|
+
|
|
24
|
+
## Enforcement
|
|
25
|
+
|
|
26
|
+
Report abusive or harassing behavior to contact@kiskolabs.com. Reports are reviewed and investigated.
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Contributing Guidelines
|
|
2
|
+
|
|
3
|
+
## Automation authorship
|
|
4
|
+
|
|
5
|
+
You may use AI and automation tools. You remain the author of every line you submit: review, debug, and understand the change.
|
|
6
|
+
|
|
7
|
+
Keep pull requests small enough to review. Annotate non-obvious logic.
|
|
8
|
+
|
|
9
|
+
Never send project secrets or private context to public models.
|
|
10
|
+
|
|
11
|
+
## How to contribute
|
|
12
|
+
|
|
13
|
+
### Reporting issues
|
|
14
|
+
|
|
15
|
+
Verify the facts before filing. Use issue templates for goals, constraints, and reproduction steps.
|
|
16
|
+
|
|
17
|
+
### Pull requests
|
|
18
|
+
|
|
19
|
+
Keep one pull request to one goal. Explain why the change is needed. Run smoke tests and regression checks locally before opening the request.
|
|
20
|
+
|
|
21
|
+
### Review
|
|
22
|
+
|
|
23
|
+
Reviewers will ask about approach and trade-offs. Treat suggested changes as part of the work.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrei Makarov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Polyrun Legacy
|
|
2
|
+
|
|
3
|
+
`polyrun-legacy` provides local and CI test sharding, suite preparation, and test reports on MRI Ruby 1.8.7 and newer on POSIX. Support is experimental. The smoke check also runs on JRuby and TruffleRuby Native. See [RFC 0011](../rfcs/0011-polyrun-legacy.md) for the contract.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Install the gem from RubyGems once released, or [build it from this checkout](#build-and-publish).
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
gem install polyrun-legacy
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Both Polyrun gems install the `polyrun` executable. Give each gem a separate gem path. In Ruby code, load the legacy gem with `require "polyrun/legacy"`.
|
|
14
|
+
|
|
15
|
+
Planning and report commands use the Ruby installation's JSON library when available. On a Ruby 1.8.7 installation without JSON, install the pure Ruby implementation.
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
gem install json_pure -v 1.8.6
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
If the old RubyGems client cannot reach RubyGems, download the packages with a current client and use `gem install --local FILE.gem` under the old Ruby.
|
|
22
|
+
|
|
23
|
+
## Run shards
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
polyrun run-shards --workers 2 -- rspec spec/alpha_spec.rb spec/beta_spec.rb
|
|
27
|
+
polyrun run-shards --workers 2 -- bundle exec rspec -- spec/alpha_spec.rb spec/beta_spec.rb
|
|
28
|
+
polyrun run-shards --workers 2 --paths-file spec/spec_paths.txt -- bundle exec rspec
|
|
29
|
+
polyrun parallel-minitest --workers 2
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Place paths before the command delimiter, pass them via `--paths-file` or `--paths-glob`, or separate them from command arguments with a second `--`. A single executable can take paths directly. With an explicit empty path list after the second `--`, a generic command can select its own work using the shard environment.
|
|
33
|
+
|
|
34
|
+
The `parallel-rspec`, `parallel-minitest`, and `parallel-sus` commands discover paths for that suite and use an installed runner when applicable. Append `-- COMMAND ARG ...` to substitute a runner, such as an older RSpec executable. The wrappers merge available coverage after a successful run. Use `--merge-coverage` with `run-shards` to opt in and `--merge-failures` to collect failure fragments even if a worker fails.
|
|
35
|
+
|
|
36
|
+
Each child gets zero-based `POLYRUN_SHARD_INDEX` and the requested `POLYRUN_SHARD_TOTAL`. With multiple workers, `TEST_ENV_NUMBER` is the one-based shard number. The runner skips empty partitions when distributing paths and returns the first failing worker's status in shard order. `--worker-log-dir DIR` writes stdout and stderr together to one log per shard. `--worker-timeout SEC` stops workers on timeout and returns 124. Ruby 1.8.7 measures this timeout with the system clock.
|
|
37
|
+
|
|
38
|
+
## Plan and run a CI shard
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
polyrun build-paths --glob 'spec/**/*_spec.rb'
|
|
42
|
+
polyrun plan --paths-file spec/spec_paths.txt --shard 0 --total 2
|
|
43
|
+
polyrun plan --paths-file spec/spec_paths.txt --timing polyrun_timing.json --total 2
|
|
44
|
+
polyrun ci-shard-run --paths-file spec/spec_paths.txt --shard-processes 2 -- bundle exec rspec
|
|
45
|
+
polyrun env --shard 1 --total 2 --database 'store_test_%{shard}'
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`plan` emits the selected paths as JSON. Strategies include sorted `round_robin`, `preserve_order_round_robin`, timing-aware `lazy_robin` and `cost_binpack`, and `hrw` rendezvous hashing. A timing file implies `cost_binpack` unless a strategy is given.
|
|
49
|
+
|
|
50
|
+
`ci-shard-run`, `ci-shard-rspec`, and `ci-shard-sus` run the selected global shard. Set `POLYRUN_SHARD_INDEX` and `POLYRUN_SHARD_TOTAL` in the CI job or pass `--shard` and `--total`. With multiple local workers, `POLYRUN_SHARD_MATRIX_INDEX` and `POLYRUN_SHARD_MATRIX_TOTAL` identify the global shard.
|
|
51
|
+
|
|
52
|
+
## Configure and prepare
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
polyrun -c polyrun.yml --suite smoke config workers
|
|
56
|
+
polyrun validate
|
|
57
|
+
polyrun doctor
|
|
58
|
+
polyrun prepare --dry-run
|
|
59
|
+
polyrun hook run before_shard --shard 0 --total 2
|
|
60
|
+
polyrun start
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The CLI checks `polyrun.yml` and `config/polyrun.yml`. Use `-c` or `POLYRUN_CONFIG` for another YAML or JSON file. Named suites overlay the base settings. The supported settings cover worker count and timeout, partition strategy and paths, coverage formats, preparation, and explicit shell hooks. YAML configuration accepts data mappings, sequences, and scalars. YAML aliases and custom tags are rejected.
|
|
64
|
+
|
|
65
|
+
`build-paths` uses `partition.paths_build.all_glob` and writes `partition.paths_file` when configured. `prepare` supports the `default`, `shell`, and `assets` recipes. `start` prepares once before running the selected suite. Set `POLYRUN_SKIP_PREPARE=1` to skip this step. `hook run` executes a configured shell phase explicitly. Shard commands pass `POLYRUN_HOOKS_DISABLE=1` to workers.
|
|
66
|
+
|
|
67
|
+
## Merge coverage
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
polyrun merge-coverage
|
|
71
|
+
polyrun merge-coverage -i 'reports/shard-*.json' -o reports/merged.json --format json,lcov,console
|
|
72
|
+
polyrun report-coverage -i reports/merged.json -o reports/formats
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
By default, the merge reads `coverage/polyrun-fragment-*.json`, writes `coverage/polyrun-merged.json`, and prints a line coverage summary. Repeat `-i` to combine files and quoted globs. Supported formats are JSON, LCOV, Cobertura, console, HTML, CSV, and Markdown.
|
|
76
|
+
|
|
77
|
+
Supply SimpleCov-shaped fragments with a top-level `coverage` object or a `coverage` object per suite. The merge adds line hits, preserves `null` for non-executable lines and retains `"ignored"` lines. Branch data is merged on a best-effort basis. Supply fragments from a coverage tool that runs on your Ruby version or try the fixtures in this checkout's `legacy/examples/`.
|
|
78
|
+
|
|
79
|
+
## Timing and test results
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
polyrun merge-timing -i 'reports/timing-*.json' -o polyrun_timing.json
|
|
83
|
+
polyrun report-timing -i polyrun_timing.json --top 15 --format csv
|
|
84
|
+
polyrun merge-failures -i 'reports/failure-*.jsonl' --format json
|
|
85
|
+
polyrun report-junit -i 'reports/rspec-*.json'
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Timing input can contain elapsed seconds or aggregate statistics per path. Failure merging accepts worker JSONL or RSpec JSON. JUnit accepts RSpec JSON or Polyrun testcase JSON and exports XML, CSV, or Markdown.
|
|
89
|
+
|
|
90
|
+
## Support limits
|
|
91
|
+
|
|
92
|
+
The main gem includes database provisioning, the file-backed queue, the Quick runner, the Ruby hook DSL and automatic hook lifecycle, and the graph, mutation, and quality tools. Coverage collection stays with a test tool that supports your Ruby interpreter. Legacy's Cobertura export reports line coverage. Legacy's HTML export is a static summary by file.
|
|
93
|
+
|
|
94
|
+
## Validate
|
|
95
|
+
|
|
96
|
+
From the checkout root, run the focused specs on the project's current Ruby and the smoke check.
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
bundle exec rspec --options /dev/null legacy/spec
|
|
100
|
+
make smoke-legacy
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Smoke defaults to `rbenv which ruby` (the active rbenv version, including `.ruby-version`). Override with `POLYRUN_LEGACY_RUBY` for another MRI, JRuby, or TruffleRuby Native executable. The focused specs use the same variable for their CLI subprocesses and otherwise use the current Ruby. RSpec itself runs on the project's Ruby.
|
|
104
|
+
|
|
105
|
+
Both checks run without Rails. The focused specs use a fixture executable to check delegation to `bin/rails`. See the release matrix in [RFC 0011](../rfcs/0011-polyrun-legacy.md#compatibility-checks).
|
|
106
|
+
|
|
107
|
+
## Build and publish
|
|
108
|
+
|
|
109
|
+
From the checkout root, run the following in a current Ruby environment with RubyGems publishing access. The release smoke uses the active rbenv Ruby unless `POLYRUN_LEGACY_RUBY` is set. Release versions are set in `lib/polyrun/legacy/version.rb` relative to this directory.
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
make release-legacy
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The release runs the focused Legacy specs, the Legacy smoke check, builds `polyrun-legacy`, pushes to RubyGems, and creates the `polyrun-legacy-<version>` git tag and GitHub release. Use `ruby usr/bin/release_legacy.rb --build-only` for a local artifact, or `--artifacts DIR` to finish a partial publish.
|
data/SECURITY.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# SECURITY
|
|
2
|
+
|
|
3
|
+
## Reporting a Vulnerability
|
|
4
|
+
|
|
5
|
+
Email security details to: security@kiskolabs.com
|
|
6
|
+
|
|
7
|
+
Send the report only to that address. Include description, steps to reproduce, potential impact, and a suggested fix when you have one.
|
|
8
|
+
|
|
9
|
+
### Response Timeline
|
|
10
|
+
|
|
11
|
+
- We will acknowledge receipt of your report.
|
|
12
|
+
- We will provide an initial assessment.
|
|
13
|
+
- We will keep you informed of our progress and resolution timeline.
|
|
14
|
+
|
|
15
|
+
### Disclosure Policy
|
|
16
|
+
|
|
17
|
+
- We will work with you to understand and resolve the issue.
|
|
18
|
+
- We will credit you for the discovery unless you prefer to remain anonymous.
|
|
19
|
+
- We will publish a security advisory after the vulnerability is patched.
|
|
20
|
+
- We will coordinate public disclosure with you.
|
|
21
|
+
|
|
22
|
+
## Automation Security
|
|
23
|
+
|
|
24
|
+
- Keep production credentials, API keys, and personal data out of prompts sent to third-party models or automation services.
|
|
25
|
+
- Verify automated dependencies.
|
data/bin/polyrun
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
module Polyrun
|
|
2
|
+
module Legacy
|
|
3
|
+
module CLI
|
|
4
|
+
CONFIG_COMMANDS = %w[
|
|
5
|
+
run-shards parallel-rspec parallel-minitest parallel-sus start plan
|
|
6
|
+
ci-shard-run ci-shard-rspec ci-shard-sus build-paths env config validate doctor prepare hook
|
|
7
|
+
].freeze
|
|
8
|
+
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
def run(arguments)
|
|
12
|
+
argv = arguments.dup
|
|
13
|
+
options = global_options(argv)
|
|
14
|
+
command = argv.shift
|
|
15
|
+
if CONFIG_COMMANDS.include?(command)
|
|
16
|
+
config = Configuration.new(options[:path], options[:suite])
|
|
17
|
+
return configured(command, argv, config)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
unconfigured(command, argv)
|
|
21
|
+
rescue OptionParser::ParseError, ArgumentError, SystemCallError, NotImplementedError, LoadError => error
|
|
22
|
+
warn "polyrun: #{error.message}"
|
|
23
|
+
(command == "validate") ? 1 : 2
|
|
24
|
+
rescue Interrupt
|
|
25
|
+
130
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def global_options(argv)
|
|
29
|
+
options = {}
|
|
30
|
+
options[:path] = Options.env_value("POLYRUN_CONFIG", nil)
|
|
31
|
+
options[:suite] = Options.env_value("POLYRUN_SUITE", nil)
|
|
32
|
+
if argv.first && !%w[-h --help --version].include?(argv.first)
|
|
33
|
+
OptionParser.new do |flags|
|
|
34
|
+
flags.on("-c", "--config PATH") { |value| options[:path] = value }
|
|
35
|
+
flags.on("--suite NAME") { |value| options[:suite] = value }
|
|
36
|
+
end.order!(argv)
|
|
37
|
+
end
|
|
38
|
+
options
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def configured(command, argv, config)
|
|
42
|
+
case command
|
|
43
|
+
when "run-shards" then ShardCommands.run(command, argv, nil, config)
|
|
44
|
+
when "parallel-rspec", "parallel-minitest", "parallel-sus"
|
|
45
|
+
ShardCommands.run(command, argv, command.sub("parallel-", ""), config)
|
|
46
|
+
when "start" then ShardCommands.run(command, argv, Paths.default_suite(config.partition), config)
|
|
47
|
+
when "plan" then PlanningCommands.plan(argv, config)
|
|
48
|
+
when "ci-shard-run" then PlanningCommands.ci_run(command, argv, nil, config)
|
|
49
|
+
when "ci-shard-rspec", "ci-shard-sus"
|
|
50
|
+
PlanningCommands.ci_run(command, argv, command.sub("ci-shard-", ""), config)
|
|
51
|
+
when "build-paths" then ShardCommands.build_paths(argv, config)
|
|
52
|
+
when "env" then PlanningCommands.env(argv, config)
|
|
53
|
+
when "config" then ConfigCommands.show(argv, config)
|
|
54
|
+
when "validate" then ConfigCommands.validate(argv, config)
|
|
55
|
+
when "doctor" then ConfigCommands.doctor(argv, config)
|
|
56
|
+
when "prepare" then Lifecycle.prepare(argv, config)
|
|
57
|
+
when "hook" then Lifecycle.hook(argv, config)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def unconfigured(command, argv)
|
|
62
|
+
case command
|
|
63
|
+
when "merge-coverage" then CoverageReports.merge(argv)
|
|
64
|
+
when "report-coverage" then CoverageReports.report(argv)
|
|
65
|
+
when "merge-timing" then ReportCommands.merge_timing(argv)
|
|
66
|
+
when "report-timing" then ReportCommands.report_timing(argv)
|
|
67
|
+
when "merge-failures" then FailureReports.command(argv)
|
|
68
|
+
when "report-junit" then JunitReports.command(argv)
|
|
69
|
+
when "version", "--version"
|
|
70
|
+
puts VERSION
|
|
71
|
+
0
|
|
72
|
+
when nil, "help", "--help", "-h" then help
|
|
73
|
+
else
|
|
74
|
+
raise ArgumentError, "unknown command #{command.inspect}"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def help
|
|
79
|
+
# rubocop:disable Layout/HeredocIndentation -- Ruby 1.8 compatibility
|
|
80
|
+
puts <<HELP
|
|
81
|
+
Usage: polyrun [-c PATH] [--suite NAME] COMMAND [options]
|
|
82
|
+
|
|
83
|
+
Run tests
|
|
84
|
+
start, run-shards, parallel-rspec, parallel-minitest, parallel-sus
|
|
85
|
+
ci-shard-run, ci-shard-rspec, ci-shard-sus
|
|
86
|
+
|
|
87
|
+
Prepare and inspect a run
|
|
88
|
+
prepare, hook run, config, validate, doctor
|
|
89
|
+
build-paths, plan, env
|
|
90
|
+
|
|
91
|
+
Combine and export reports
|
|
92
|
+
merge-coverage, report-coverage, merge-timing, report-timing
|
|
93
|
+
merge-failures, report-junit
|
|
94
|
+
|
|
95
|
+
Use polyrun COMMAND --help for command options.
|
|
96
|
+
HELP
|
|
97
|
+
# rubocop:enable Layout/HeredocIndentation
|
|
98
|
+
0
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require "fileutils"
|
|
2
|
+
require "tempfile"
|
|
3
|
+
|
|
4
|
+
module Polyrun
|
|
5
|
+
module Legacy
|
|
6
|
+
module Compat
|
|
7
|
+
module_function
|
|
8
|
+
|
|
9
|
+
def load_json
|
|
10
|
+
require "json"
|
|
11
|
+
rescue LoadError
|
|
12
|
+
begin
|
|
13
|
+
require "rubygems" unless defined?(Gem)
|
|
14
|
+
require "json/pure"
|
|
15
|
+
rescue LoadError
|
|
16
|
+
raise ArgumentError, "JSON support is missing. On Ruby 1.8.7, install json_pure 1.8.6."
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def parse_json(source)
|
|
21
|
+
if JSON::VERSION.split(".").first == "1"
|
|
22
|
+
JSON.parse(source, :create_additions => false) # rubocop:disable Style/HashSyntax
|
|
23
|
+
else
|
|
24
|
+
JSON.parse(source)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def write_report(path, contents)
|
|
29
|
+
directory = File.dirname(File.expand_path(path))
|
|
30
|
+
FileUtils.mkdir_p(directory)
|
|
31
|
+
temporary = Tempfile.new(".polyrun-report", directory)
|
|
32
|
+
begin
|
|
33
|
+
temporary.binmode
|
|
34
|
+
temporary.write(contents)
|
|
35
|
+
temporary.close
|
|
36
|
+
File.rename(temporary.path, path)
|
|
37
|
+
ensure
|
|
38
|
+
temporary.close!
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def read_json(path)
|
|
43
|
+
load_json
|
|
44
|
+
contents = File.open(path, "rb") { |input| input.read } # rubocop:disable Style/FileRead
|
|
45
|
+
begin
|
|
46
|
+
parse_json(contents)
|
|
47
|
+
rescue JSON::ParserError
|
|
48
|
+
raise ArgumentError, "#{path}: invalid JSON"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Polyrun
|
|
2
|
+
module Legacy
|
|
3
|
+
module ConfigCommands
|
|
4
|
+
module_function
|
|
5
|
+
|
|
6
|
+
def show(argv, config)
|
|
7
|
+
raise ArgumentError, "provide one dotted configuration path" unless argv.length == 1
|
|
8
|
+
|
|
9
|
+
value = config.value(argv.first)
|
|
10
|
+
if value.nil?
|
|
11
|
+
warn "polyrun config: no value for #{argv.first}"
|
|
12
|
+
return 1
|
|
13
|
+
end
|
|
14
|
+
if value.is_a?(Hash) || value.is_a?(Array)
|
|
15
|
+
Compat.load_json
|
|
16
|
+
value = JSON.generate(value)
|
|
17
|
+
end
|
|
18
|
+
puts value
|
|
19
|
+
0
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def validate(argv, config)
|
|
23
|
+
raise ArgumentError, "validate takes no arguments" unless argv.empty?
|
|
24
|
+
|
|
25
|
+
keys = config.unsupported_keys
|
|
26
|
+
unless keys.empty?
|
|
27
|
+
warn "polyrun validate: unsupported keys: #{keys.join(", ")}"
|
|
28
|
+
return 1
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
Options.integer(config.workers, "workers", 1)
|
|
32
|
+
puts "polyrun validate: ok (#{config.path || "no file"})"
|
|
33
|
+
0
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def doctor(argv, config)
|
|
37
|
+
raise ArgumentError, "doctor takes no arguments" unless argv.empty?
|
|
38
|
+
|
|
39
|
+
shard, total = ShardEnv.defaults(config.partition)
|
|
40
|
+
puts "polyrun doctor"
|
|
41
|
+
puts " config: #{config.path || "(none)"}"
|
|
42
|
+
puts " suite: #{config.suite || "(none)"}"
|
|
43
|
+
puts " workers: #{config.workers}"
|
|
44
|
+
puts " shard: #{shard}/#{total}"
|
|
45
|
+
puts " strategy: #{config.partition["strategy"] || "round_robin"}"
|
|
46
|
+
keys = config.unsupported_keys
|
|
47
|
+
puts " unsupported configuration keys: #{keys.join(", ")}" unless keys.empty?
|
|
48
|
+
0
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
module Polyrun
|
|
2
|
+
module Legacy
|
|
3
|
+
class Configuration
|
|
4
|
+
FILES = %w[polyrun.yml config/polyrun.yml].freeze
|
|
5
|
+
SECTIONS = %w[partition coverage prepare hooks suites].freeze
|
|
6
|
+
TOP_LEVEL = (%w[version workers timeout] + SECTIONS).freeze
|
|
7
|
+
|
|
8
|
+
attr_reader :path, :suite
|
|
9
|
+
|
|
10
|
+
def initialize(path, suite)
|
|
11
|
+
@path = path || FILES.find { |name| File.file?(name) }
|
|
12
|
+
@suite = suite
|
|
13
|
+
@data = @path ? load_data(@path) : {}
|
|
14
|
+
apply_suite if @suite
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def partition
|
|
18
|
+
section("partition")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def section(name)
|
|
22
|
+
@data.fetch(name, {})
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def workers
|
|
26
|
+
Options.env_value("POLYRUN_WORKERS", @data.fetch("workers", 1))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def shard_settings
|
|
30
|
+
settings = {}
|
|
31
|
+
settings[:paths_file] = string_option(partition, "paths_file")
|
|
32
|
+
settings[:globs] = paths_globs
|
|
33
|
+
settings[:strategy] = string_option(partition, "strategy")
|
|
34
|
+
settings[:seed] = partition["seed"]
|
|
35
|
+
settings[:timing] = string_option(partition, "timing_file")
|
|
36
|
+
settings[:worker_timeout] = Options.env_value("POLYRUN_WORKER_TIMEOUT_SEC", @data["timeout"])
|
|
37
|
+
settings
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def paths_globs
|
|
41
|
+
build = partition["paths_build"]
|
|
42
|
+
return [] unless build
|
|
43
|
+
raise ArgumentError, "partition.paths_build must be a mapping" unless build.is_a?(Hash)
|
|
44
|
+
|
|
45
|
+
globs = Array(build["all_glob"])
|
|
46
|
+
raise ArgumentError, "all_glob must contain path patterns" unless globs.all? { |glob| glob.is_a?(String) }
|
|
47
|
+
|
|
48
|
+
globs
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def value(dotted)
|
|
52
|
+
case dotted
|
|
53
|
+
when "workers" then workers
|
|
54
|
+
when "partition.shard_index" then ShardEnv.defaults(partition).first.to_i
|
|
55
|
+
when "partition.shard_total" then ShardEnv.defaults(partition).last.to_i
|
|
56
|
+
else
|
|
57
|
+
dotted.split(".").inject(@data) { |value, key| value.is_a?(Hash) ? value[key] : nil }
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def unsupported_keys
|
|
62
|
+
@data.keys.sort - TOP_LEVEL
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
def load_data(path)
|
|
68
|
+
data = (File.extname(path) == ".json") ? Compat.read_json(path) : (YamlData.read(path) || {})
|
|
69
|
+
raise ArgumentError, "expected a configuration object" unless data.is_a?(Hash)
|
|
70
|
+
|
|
71
|
+
validate_sections(data)
|
|
72
|
+
data
|
|
73
|
+
rescue ArgumentError => error
|
|
74
|
+
raise ArgumentError, "#{path}: #{error.message}" unless error.message.index("#{path}:") == 0
|
|
75
|
+
|
|
76
|
+
raise
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def apply_suite
|
|
80
|
+
overlay = section("suites")[@suite]
|
|
81
|
+
raise ArgumentError, "unknown suite #{@suite.inspect}" unless overlay.is_a?(Hash)
|
|
82
|
+
|
|
83
|
+
@data = overlay_hash(@data, overlay)
|
|
84
|
+
validate_sections(@data)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def overlay_hash(base, overlay)
|
|
88
|
+
combined = base.dup
|
|
89
|
+
overlay.each do |key, value|
|
|
90
|
+
combined[key] = if value.is_a?(Hash) && base[key].is_a?(Hash)
|
|
91
|
+
overlay_hash(base[key], value)
|
|
92
|
+
else
|
|
93
|
+
value
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
combined
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def validate_sections(data)
|
|
100
|
+
SECTIONS.each do |name|
|
|
101
|
+
if data.key?(name) && !data[name].is_a?(Hash)
|
|
102
|
+
raise ArgumentError, "#{name} must be a mapping"
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def string_option(section, key)
|
|
108
|
+
value = section[key]
|
|
109
|
+
raise ArgumentError, "partition.#{key} must be a string" if value && !value.is_a?(String)
|
|
110
|
+
|
|
111
|
+
value
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
module Polyrun
|
|
2
|
+
module Legacy
|
|
3
|
+
module CoverageFormats
|
|
4
|
+
EXTENSIONS = {
|
|
5
|
+
"json" => ".json", "lcov" => ".lcov", "cobertura" => ".xml", "console" => "-summary.txt",
|
|
6
|
+
"html" => ".html", "csv" => ".csv", "markdown" => ".md"
|
|
7
|
+
}.freeze
|
|
8
|
+
NAMES = %w[json lcov cobertura console html csv markdown].freeze
|
|
9
|
+
HEADERS = %w[path covered relevant line_percent].freeze
|
|
10
|
+
DISPLAY_HEADERS = ["File", "Covered lines", "Counted lines", "Coverage (%)"].freeze
|
|
11
|
+
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
def names(list)
|
|
15
|
+
formats = list.split(",").map { |name| name.strip }.uniq
|
|
16
|
+
if formats.empty? || !(formats - NAMES).empty?
|
|
17
|
+
raise ArgumentError, "choose report formats from #{NAMES.join(", ")}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
formats
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def render(coverage, format_name)
|
|
24
|
+
case format_name
|
|
25
|
+
when "json" then JSON.generate({"coverage" => coverage}) + "\n"
|
|
26
|
+
when "console" then Merge.console_summary(coverage) + "\n"
|
|
27
|
+
when "lcov" then lcov(coverage)
|
|
28
|
+
when "cobertura" then cobertura(coverage)
|
|
29
|
+
when "csv" then Table.csv(HEADERS, file_rows(coverage))
|
|
30
|
+
when "markdown" then Table.markdown("Polyrun coverage report", DISPLAY_HEADERS, file_rows(coverage))
|
|
31
|
+
when "html" then Table.html("Polyrun coverage report", DISPLAY_HEADERS, file_rows(coverage))
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def lcov(coverage)
|
|
36
|
+
output = ""
|
|
37
|
+
coverage.keys.sort.each do |path|
|
|
38
|
+
raise ArgumentError, "LCOV cannot represent paths containing newlines" if path.index(/[\r\n]/)
|
|
39
|
+
|
|
40
|
+
output << "TN:polyrun\nSF:#{path}\n"
|
|
41
|
+
line_hits(coverage[path]).each { |number, count| output << "DA:#{number},#{count}\n" }
|
|
42
|
+
output << "end_of_record\n"
|
|
43
|
+
end
|
|
44
|
+
output
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def cobertura(coverage)
|
|
48
|
+
covered = total = 0
|
|
49
|
+
classes = coverage.keys.sort.map do |path|
|
|
50
|
+
hits = line_hits(coverage[path])
|
|
51
|
+
count = covered_count(hits)
|
|
52
|
+
covered += count
|
|
53
|
+
total += hits.length
|
|
54
|
+
cobertura_class(path, hits, count)
|
|
55
|
+
end
|
|
56
|
+
rate = coverage_rate(covered, total)
|
|
57
|
+
header = %(<?xml version="1.0" encoding="UTF-8"?>\n)
|
|
58
|
+
header << %(<coverage line-rate="#{rate}" branch-rate="0" lines-covered="#{covered}" lines-valid="#{total}" )
|
|
59
|
+
header << %(branches-covered="0" branches-valid="0" complexity="0" timestamp="#{Time.now.to_i}" version="1">\n)
|
|
60
|
+
header << %(<packages><package name="app" line-rate="#{rate}" branch-rate="0" complexity="0"><classes>\n)
|
|
61
|
+
header + classes.join + "</classes></package></packages></coverage>\n"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def cobertura_class(path, hits, count)
|
|
65
|
+
name = Table.xml(path)
|
|
66
|
+
rate = coverage_rate(count, hits.length)
|
|
67
|
+
lines = hits.map { |number, hits_at_line| %(<line number="#{number}" hits="#{hits_at_line}"/>\n) }
|
|
68
|
+
%(<class name="#{name}" filename="#{name}" line-rate="#{rate}" branch-rate="0" complexity="0"><methods/><lines>\n) +
|
|
69
|
+
lines.join + "</lines></class>\n"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def file_rows(coverage)
|
|
73
|
+
coverage.keys.sort.map do |path|
|
|
74
|
+
hits = line_hits(coverage[path])
|
|
75
|
+
covered = covered_count(hits)
|
|
76
|
+
[path, covered, hits.length, format("%.2f", coverage_rate(covered, hits.length) * 100)]
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def line_hits(entry)
|
|
81
|
+
hits = []
|
|
82
|
+
entry["lines"].each_with_index { |count, index| hits << [index + 1, count] if Merge.hit_count?(count) }
|
|
83
|
+
hits
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def covered_count(hits)
|
|
87
|
+
hits.count { |_, count| count > 0 }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def coverage_rate(covered, total)
|
|
91
|
+
(total == 0) ? 0.0 : covered.to_f / total
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|