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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +234 -0
- data/CODE_OF_CONDUCT.md +26 -0
- data/CONTRIBUTING.md +23 -0
- data/LICENSE +21 -0
- data/README.md +251 -0
- data/SECURITY.md +25 -0
- data/bin/polyrun +6 -0
- data/docs/QUALITY.md +82 -0
- data/docs/QUALITY_CONFIGURATION.md +95 -0
- data/docs/SETUP_PROFILE.md +139 -0
- data/lib/polyrun/benchmark/pressure/cooker.rb +191 -0
- data/lib/polyrun/benchmark/pressure/process_sample.rb +127 -0
- data/lib/polyrun/benchmark/pressure.rb +144 -0
- data/lib/polyrun/benchmark/profile.rb +191 -0
- data/lib/polyrun/benchmark/report.rb +87 -0
- data/lib/polyrun/cli/benchmark_commands.rb +66 -0
- data/lib/polyrun/cli/ci_shard_hooks.rb +129 -0
- data/lib/polyrun/cli/ci_shard_run_command.rb +177 -0
- data/lib/polyrun/cli/ci_shard_run_parse.rb +68 -0
- data/lib/polyrun/cli/config_command.rb +42 -0
- data/lib/polyrun/cli/coverage_commands.rb +150 -0
- data/lib/polyrun/cli/coverage_merge_io.rb +150 -0
- data/lib/polyrun/cli/database_commands.rb +163 -0
- data/lib/polyrun/cli/default_run.rb +144 -0
- data/lib/polyrun/cli/doctor_command.rb +94 -0
- data/lib/polyrun/cli/env_commands.rb +43 -0
- data/lib/polyrun/cli/failure_commands.rb +99 -0
- data/lib/polyrun/cli/graph_command.rb +68 -0
- data/lib/polyrun/cli/help.rb +83 -0
- data/lib/polyrun/cli/helpers.rb +162 -0
- data/lib/polyrun/cli/hooks_command.rb +97 -0
- data/lib/polyrun/cli/init_command.rb +108 -0
- data/lib/polyrun/cli/mutation_command.rb +67 -0
- data/lib/polyrun/cli/partition_diagnostics.rb +22 -0
- data/lib/polyrun/cli/plan_command.rb +184 -0
- data/lib/polyrun/cli/prepare_command.rb +70 -0
- data/lib/polyrun/cli/prepare_recipe.rb +82 -0
- data/lib/polyrun/cli/quality_commands.rb +65 -0
- data/lib/polyrun/cli/queue_command.rb +161 -0
- data/lib/polyrun/cli/quick_command.rb +13 -0
- data/lib/polyrun/cli/report_commands.rb +108 -0
- data/lib/polyrun/cli/run_queue_command.rb +127 -0
- data/lib/polyrun/cli/run_shards_command.rb +164 -0
- data/lib/polyrun/cli/run_shards_parallel_children.rb +112 -0
- data/lib/polyrun/cli/run_shards_parallel_wait.rb +252 -0
- data/lib/polyrun/cli/run_shards_plan_boot_phases.rb +207 -0
- data/lib/polyrun/cli/run_shards_plan_options.rb +74 -0
- data/lib/polyrun/cli/run_shards_planning.rb +123 -0
- data/lib/polyrun/cli/run_shards_run.rb +171 -0
- data/lib/polyrun/cli/run_shards_worker_interrupt.rb +101 -0
- data/lib/polyrun/cli/skip_env.rb +34 -0
- data/lib/polyrun/cli/spec_quality_commands.rb +149 -0
- data/lib/polyrun/cli/start_bootstrap.rb +126 -0
- data/lib/polyrun/cli/timing_command.rb +31 -0
- data/lib/polyrun/cli/tool_options.rb +48 -0
- data/lib/polyrun/cli/validate_command.rb +26 -0
- data/lib/polyrun/cli.rb +272 -0
- data/lib/polyrun/config/dotted_path.rb +21 -0
- data/lib/polyrun/config/effective.rb +82 -0
- data/lib/polyrun/config/resolver.rb +114 -0
- data/lib/polyrun/config/schema.rb +39 -0
- data/lib/polyrun/config/suite.rb +109 -0
- data/lib/polyrun/config/tool_defaults.rb +42 -0
- data/lib/polyrun/config/tool_validation.rb +79 -0
- data/lib/polyrun/config/tools.rb +120 -0
- data/lib/polyrun/config.rb +97 -0
- data/lib/polyrun/coverage/cobertura_zero_lines.rb +32 -0
- data/lib/polyrun/coverage/collector.rb +169 -0
- data/lib/polyrun/coverage/collector_blob.rb +53 -0
- data/lib/polyrun/coverage/collector_finish.rb +98 -0
- data/lib/polyrun/coverage/collector_fragment_meta.rb +57 -0
- data/lib/polyrun/coverage/config_resolve.rb +131 -0
- data/lib/polyrun/coverage/example_diff.rb +184 -0
- data/lib/polyrun/coverage/example_diff_snapshot.rb +44 -0
- data/lib/polyrun/coverage/example_diff_track_filter.rb +51 -0
- data/lib/polyrun/coverage/file_stats_report.rb +36 -0
- data/lib/polyrun/coverage/filter.rb +22 -0
- data/lib/polyrun/coverage/formatter.rb +137 -0
- data/lib/polyrun/coverage/merge/formatters.rb +188 -0
- data/lib/polyrun/coverage/merge/formatters_html.rb +221 -0
- data/lib/polyrun/coverage/merge/html/_file_list.html.erb +21 -0
- data/lib/polyrun/coverage/merge/html/_file_section.html.erb +26 -0
- data/lib/polyrun/coverage/merge/html/_groups_table.html.erb +18 -0
- data/lib/polyrun/coverage/merge/html/_overview.html.erb +47 -0
- data/lib/polyrun/coverage/merge/html/report.css +147 -0
- data/lib/polyrun/coverage/merge/html/report.js +48 -0
- data/lib/polyrun/coverage/merge/html/template.html.erb +30 -0
- data/lib/polyrun/coverage/merge.rb +160 -0
- data/lib/polyrun/coverage/merge_fragment_meta.rb +58 -0
- data/lib/polyrun/coverage/merge_merge_two.rb +168 -0
- data/lib/polyrun/coverage/merge_native.rb +39 -0
- data/lib/polyrun/coverage/rails.rb +126 -0
- data/lib/polyrun/coverage/reporting.rb +41 -0
- data/lib/polyrun/coverage/result.rb +18 -0
- data/lib/polyrun/coverage/track_files.rb +150 -0
- data/lib/polyrun/data/cached_fixtures.rb +122 -0
- data/lib/polyrun/data/factory_counts.rb +48 -0
- data/lib/polyrun/data/factory_instrumentation.rb +50 -0
- data/lib/polyrun/data/fixtures.rb +68 -0
- data/lib/polyrun/data/parallel_provisioning.rb +93 -0
- data/lib/polyrun/data/snapshot.rb +84 -0
- data/lib/polyrun/database/clone_shards.rb +106 -0
- data/lib/polyrun/database/provision.rb +83 -0
- data/lib/polyrun/database/shard.rb +64 -0
- data/lib/polyrun/database/url_builder/connection/infer.rb +53 -0
- data/lib/polyrun/database/url_builder/connection/url_builders.rb +43 -0
- data/lib/polyrun/database/url_builder/connection.rb +191 -0
- data/lib/polyrun/database/url_builder/template_prepare.rb +21 -0
- data/lib/polyrun/database/url_builder.rb +188 -0
- data/lib/polyrun/debug.rb +81 -0
- data/lib/polyrun/env/ci.rb +65 -0
- data/lib/polyrun/error.rb +3 -0
- data/lib/polyrun/export/csv.rb +25 -0
- data/lib/polyrun/export/markdown.rb +47 -0
- data/lib/polyrun/graph/client.rb +64 -0
- data/lib/polyrun/graph/error.rb +13 -0
- data/lib/polyrun/graph/index.rb +75 -0
- data/lib/polyrun/graph/inspect.rb +58 -0
- data/lib/polyrun/graph/plan.rb +134 -0
- data/lib/polyrun/graph/planner.rb +117 -0
- data/lib/polyrun/graph/syntax.rb +114 -0
- data/lib/polyrun/graph/transaction.rb +81 -0
- data/lib/polyrun/graph/worker.rb +55 -0
- data/lib/polyrun/graph/workspace.rb +117 -0
- data/lib/polyrun/hooks/dsl.rb +128 -0
- data/lib/polyrun/hooks/shell_runner.rb +33 -0
- data/lib/polyrun/hooks/worker_runner.rb +27 -0
- data/lib/polyrun/hooks/worker_shell.rb +50 -0
- data/lib/polyrun/hooks.rb +190 -0
- data/lib/polyrun/log.rb +86 -0
- data/lib/polyrun/minitest_support.rb +60 -0
- data/lib/polyrun/mutation/candidates.rb +91 -0
- data/lib/polyrun/mutation/operators.rb +51 -0
- data/lib/polyrun/mutation/runner.rb +133 -0
- data/lib/polyrun/mutation/subjects.rb +88 -0
- data/lib/polyrun/partition/constraints.rb +80 -0
- data/lib/polyrun/partition/hrw.rb +70 -0
- data/lib/polyrun/partition/min_heap.rb +64 -0
- data/lib/polyrun/partition/paths.rb +175 -0
- data/lib/polyrun/partition/paths_build.rb +141 -0
- data/lib/polyrun/partition/plan.rb +250 -0
- data/lib/polyrun/partition/plan_lpt.rb +91 -0
- data/lib/polyrun/partition/plan_sharding.rb +56 -0
- data/lib/polyrun/partition/reports.rb +139 -0
- data/lib/polyrun/partition/stable_shuffle.rb +18 -0
- data/lib/polyrun/partition/suite.rb +120 -0
- data/lib/polyrun/partition/timing_diagnostics.rb +138 -0
- data/lib/polyrun/partition/timing_keys.rb +86 -0
- data/lib/polyrun/prepare/artifacts.rb +40 -0
- data/lib/polyrun/prepare/assets.rb +64 -0
- data/lib/polyrun/process_stdio.rb +96 -0
- data/lib/polyrun/quality/command.rb +84 -0
- data/lib/polyrun/quality/measure.rb +38 -0
- data/lib/polyrun/quality/observe.rb +53 -0
- data/lib/polyrun/quality/observe_hook.rb +103 -0
- data/lib/polyrun/quality/sandbox.rb +70 -0
- data/lib/polyrun/queue/duration.rb +30 -0
- data/lib/polyrun/queue/file_store.rb +413 -0
- data/lib/polyrun/queue/file_store_intent.rb +188 -0
- data/lib/polyrun/queue/file_store_pending.rb +48 -0
- data/lib/polyrun/queue/worker_loop.rb +73 -0
- data/lib/polyrun/quick/assertions.rb +32 -0
- data/lib/polyrun/quick/config.rb +56 -0
- data/lib/polyrun/quick/errors.rb +6 -0
- data/lib/polyrun/quick/example_group.rb +111 -0
- data/lib/polyrun/quick/example_runner.rb +129 -0
- data/lib/polyrun/quick/matchers.rb +159 -0
- data/lib/polyrun/quick/matchers_predicates.rb +122 -0
- data/lib/polyrun/quick/reporter.rb +76 -0
- data/lib/polyrun/quick/runner.rb +224 -0
- data/lib/polyrun/quick.rb +1 -0
- data/lib/polyrun/railtie.rb +7 -0
- data/lib/polyrun/reporting/failure_merge.rb +171 -0
- data/lib/polyrun/reporting/junit.rb +126 -0
- data/lib/polyrun/reporting/junit_emit.rb +58 -0
- data/lib/polyrun/reporting/junit_report.rb +87 -0
- data/lib/polyrun/reporting/rspec_failure_fragment_formatter.rb +95 -0
- data/lib/polyrun/reporting/rspec_junit.rb +39 -0
- data/lib/polyrun/rspec_support/active_record_timeout_recovery.rb +51 -0
- data/lib/polyrun/rspec_support/example_debug.rb +167 -0
- data/lib/polyrun/rspec_support/example_debug_instrumentation.rb +73 -0
- data/lib/polyrun/rspec_support/sharded_formatter_compat.rb +57 -0
- data/lib/polyrun/rspec_support.rb +110 -0
- data/lib/polyrun/spec_quality/config.rb +139 -0
- data/lib/polyrun/spec_quality/fragment.rb +39 -0
- data/lib/polyrun/spec_quality/merge.rb +78 -0
- data/lib/polyrun/spec_quality/minitest_hook.rb +42 -0
- data/lib/polyrun/spec_quality/plan_loader.rb +47 -0
- data/lib/polyrun/spec_quality/profile.rb +102 -0
- data/lib/polyrun/spec_quality/report.rb +363 -0
- data/lib/polyrun/spec_quality/rspec_hook.rb +55 -0
- data/lib/polyrun/spec_quality/sql_counter.rb +34 -0
- data/lib/polyrun/spec_quality.rb +212 -0
- data/lib/polyrun/sus_support.rb +55 -0
- data/lib/polyrun/templates/POLYRUN.md +51 -0
- data/lib/polyrun/templates/ci_matrix.polyrun.yml +22 -0
- data/lib/polyrun/templates/minimal_gem.polyrun.yml +13 -0
- data/lib/polyrun/templates/polyrun_hooks_spec_quality.rb +12 -0
- data/lib/polyrun/templates/polyrun_spec_quality.yml +20 -0
- data/lib/polyrun/templates/rails_prepare.polyrun.yml +51 -0
- data/lib/polyrun/templates/rails_prepare_task.rake +16 -0
- data/lib/polyrun/timing/merge.rb +36 -0
- data/lib/polyrun/timing/rspec_example_formatter.rb +60 -0
- data/lib/polyrun/timing/stats.rb +76 -0
- data/lib/polyrun/timing/summary.rb +78 -0
- data/lib/polyrun/timing/variance_report.rb +51 -0
- data/lib/polyrun/version.rb +3 -0
- data/lib/polyrun/worker_output.rb +181 -0
- data/lib/polyrun/worker_output_forwarders.rb +94 -0
- data/lib/polyrun/worker_ping.rb +77 -0
- data/lib/polyrun.rb +59 -0
- data/polyrun.gemspec +49 -0
- data/sig/polyrun/cli.rbs +6 -0
- data/sig/polyrun/config.rbs +20 -0
- data/sig/polyrun/debug.rbs +12 -0
- data/sig/polyrun/log.rbs +12 -0
- data/sig/polyrun/minitest_support.rbs +7 -0
- data/sig/polyrun/quick.rbs +19 -0
- data/sig/polyrun/rspec_support.rbs +21 -0
- data/sig/polyrun/sus_support.rbs +7 -0
- data/sig/polyrun/worker_output.rbs +11 -0
- data/sig/polyrun/worker_ping.rbs +10 -0
- data/sig/polyrun.rbs +11 -0
- metadata +463 -0
data/docs/QUALITY.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Graph edits and quality checks
|
|
2
|
+
|
|
3
|
+
Polyrun implements Ruby graph indexing, guarded source edits, mutation generation, execution, observation, and command measurements within the gem. These commands use Ruby standard libraries, including Prism. No additional graph or mutation package, executable, source checkout, or database is required. The consuming project's test command still needs its ordinary dependencies.
|
|
4
|
+
|
|
5
|
+
The commands are opt-in. See [Quality configuration](QUALITY_CONFIGURATION.md) for activation, shared defaults, per-feature settings, and every configurable limit.
|
|
6
|
+
|
|
7
|
+
## Graph workflow
|
|
8
|
+
|
|
9
|
+
polyrun graph --enable index --json
|
|
10
|
+
polyrun graph --enable inspect 'Account#save' --calls --callers --callees --json
|
|
11
|
+
polyrun graph --enable inspect --control-plane --json
|
|
12
|
+
polyrun graph --enable plan change.json --json
|
|
13
|
+
polyrun graph --enable check PLAN --json --prove -- bundle exec rspec
|
|
14
|
+
polyrun graph --enable apply PLAN --json
|
|
15
|
+
|
|
16
|
+
Every graph command accepts `--root PATH` and `--timeout SECONDS`. State is stored under `.polyrun/graph`. Indexing parses source without executing it. It scans `lib` and `app` when present; otherwise it scans the project excluding development artifacts. The JSON index reuses unchanged source snapshots. Method identifiers, call identifiers, byte ranges, source fingerprints, and provenance describe the indexed source. Statically resolved edges are labeled `static_guess`; dynamic dispatch remains `unknown`. Lifecycle and signal inspection is a naming heuristic, not proof of runtime control flow.
|
|
17
|
+
|
|
18
|
+
Selectors accept an exact subject such as `Account#save` or `Account.build`, a node identifier, or `path:lib/account.rb#save`. A bare method name must resolve uniquely. Ambiguous selectors fail rather than choosing a definition.
|
|
19
|
+
|
|
20
|
+
A change description is JSON or safe YAML:
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"snapshot": "snapshot-HASH",
|
|
25
|
+
"operations": [{
|
|
26
|
+
"op": "replace_call_name",
|
|
27
|
+
"node": "call-ID",
|
|
28
|
+
"expect": {"name": "old_name", "fingerprint": "HASH"},
|
|
29
|
+
"replacement": "new_name"
|
|
30
|
+
}]
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Take the snapshot and call fields from index and inspect output. Planning supports this operation only, with a default ceiling of 1,000 distinct call edits. It validates expected tokens, applies byte edits to an isolated project copy, checks Ruby syntax, and emits a bounded diff. It does not rename every definition or infer dispatch equivalence.
|
|
35
|
+
|
|
36
|
+
Check verifies that sources are unchanged, syntax is valid, and the intended staged hashes match. An optional prove command runs in the staged tree; its Gemfile and library path point there. Tests that explicitly load an outside checkout do not validate the staged edit. A successful check creates a receipt binding metadata and all staged files. A failed prove revokes previous approval. Apply rejects missing receipts, changed staged files, changed originals, added source files, symbolic links, and overlapping graph commands.
|
|
37
|
+
|
|
38
|
+
`--prove` accepts the selected command's exit status; it does not establish a mathematical proof. Test success covers the executions tested. The selected command must return failure when its required checks fail or remain incomplete. Receipts bind staged bytes; they do not certify external commands, loaded dependencies, or runtime method lookup.
|
|
39
|
+
|
|
40
|
+
Apply uses per-file atomic replacement with backups and a recovery journal. An ordinary write failure restores originals. If the process stops during apply, the next apply attempts recovery before verifying that sources are unchanged. Recovery refuses to overwrite an unrelated edit. This is a cooperative local editing protocol; it does not provide a whole-tree atomic filesystem commit, protection from concurrent non-cooperating writers, or certified power-loss durability.
|
|
41
|
+
|
|
42
|
+
Rebuild a deleted index from source with `graph index`. Recreate deleted plans from the change description and check them again; receipts cannot be reconstructed as approvals.
|
|
43
|
+
|
|
44
|
+
## Mutation testing
|
|
45
|
+
|
|
46
|
+
polyrun mutate --enable --subject 'Account#save' --workers 2 --timeout 120 -- bundle exec rspec
|
|
47
|
+
polyrun mutate --enable --subjects-file subjects.txt --shard 1 --total 3 -- ruby -Ilib test/probe.rb
|
|
48
|
+
polyrun mutate --enable --plan PLAN --max-mutations 1000 -- ruby -Ilib test/probe.rb
|
|
49
|
+
polyrun mutate --enable --observed tmp/observed.json -- ruby -Ilib test/probe.rb
|
|
50
|
+
|
|
51
|
+
Arguments after `--` are the actual test command. Polyrun generates syntax-valid mutations of literals, comparison and arithmetic operators, and method bodies using Prism. The Ruby API accepts operator objects implementing `call(node)` for extension. This initial operator set does not cover every Ruby construct or establish semantic equivalence.
|
|
52
|
+
|
|
53
|
+
Subjects are exact method subjects or wildcard patterns using `*`. Subjects are deduplicated and sorted before deterministic one-based sharding. Missing or ambiguous definitions fail. There is no implicit whole-program run. Empty CI shards succeed with zero results. Plan selection targets methods containing the planned calls; it does not apply the plan first. Observed selection requires a complete observation.
|
|
54
|
+
|
|
55
|
+
A successful baseline runs before mutations in a separate project copy. Each unique mutation then runs in a new isolated copy, with one source edit. Exit 0 means the suite did not detect the edit (report code `SURVIVED`); exit 1 means the suite detected it (report code `KILLED`). Timeouts, excessive output, unavailable commands, signals, and other exit statuses are incomplete results and never count as detections. Any undetected or incomplete result fails the invocation. The command's exit-status contract matters: a test runner that uses exit 1 for unrelated setup errors cannot distinguish those errors from test failures.
|
|
56
|
+
|
|
57
|
+
The default worker ceiling is 32. The default mutation ceiling is 1,000; both are configurable. Each command defaults to a 300-second timeout and 1 MiB combined output; retained diagnostics are limited to 16 MiB. Default project staging permits at most 10,000 regular files and 64 MiB, with at most 1 GiB cumulative copied bytes per mutation invocation. Hidden directories, dependency caches, build outputs, symbolic links, and key files are excluded. The project-root `coverage` report tree is excluded by path so nested library directories named `coverage` still stage. Projects depending on excluded inputs need an explicit self-contained test setup.
|
|
58
|
+
|
|
59
|
+
Polyrun runs these tools against its own checkout. `make graph` indexes `lib`. `make mutate`, `make observe`, and `make measure` run through `polyrun --suite self` with a shared focused quality-spec command. `make quality-self` runs all four. Graph stays enabled in the root config. Mutation, observe, and measure stay disabled at the root so nested quality CLI specs do not inherit the self workload; the `self` suite enables them. Mutation uses the operator family as the CI green gate. A full-operator assessment of the same subjects closed detectable suite gaps and accepted two behavioral equivalents; details are in the undetected-mutation assessment review. The quality CI job runs `make quality-self`.
|
|
60
|
+
|
|
61
|
+
The JSON report names the Polyrun engine, baseline, selected subjects, executed mutations, per-case result, and aggregate `killed` / `survived` counts (detected vs undetected). `--output PATH` also writes it to a file. Counts are unavailable when the run is incomplete.
|
|
62
|
+
|
|
63
|
+
## CI composition
|
|
64
|
+
|
|
65
|
+
Run the project's normal parallel suite and coverage merge before a narrower mutation selection:
|
|
66
|
+
|
|
67
|
+
bundle exec polyrun run-shards --workers 2 --merge-coverage -- bundle exec rspec
|
|
68
|
+
bundle exec polyrun mutate --enable --subjects-file subjects.txt --shard 1 --total 3 --workers 2 --output mutation-1.json -- bundle exec rspec
|
|
69
|
+
|
|
70
|
+
Repeat the mutation job for shard numbers 1 through 3 with the same subject file. Mutation shard numbers are one-based; the existing worker environment uses its own documented index convention. Keep each job's report as an artifact and use the command's status as its gate. Use `graph check PLAN --prove -- bundle exec rspec` to test a staged edit before apply. These commands stay independently useful; a graph plan is not required for mutation testing.
|
|
71
|
+
|
|
72
|
+
## Observation and measurement
|
|
73
|
+
|
|
74
|
+
polyrun observe --enable --output tmp/observed.json -- ruby -Ilib test/probe.rb
|
|
75
|
+
polyrun measure --enable --label tests --output tmp/measurement.json -- bundle exec rspec
|
|
76
|
+
polyrun measure --enable --ceilings ceilings.json -- ruby -Ilib test/probe.rb
|
|
77
|
+
|
|
78
|
+
Observe injects an opt-in Ruby TracePoint hook through RUBYOPT. It records bounded call counts, named subjects, and relative paths within the requested root. It skips anonymous owners, records no arguments or receiver values, and disables injection into descendants. Missing or truncated observations are not complete mutation selections. Observation proves calls in that run, not test coverage or static dispatch.
|
|
79
|
+
|
|
80
|
+
Measure reports wall time, orchestrator CPU, waited child CPU, an orchestrator resident-memory sample, and command status. Memory is not child peak RSS; CPU is only an energy proxy. Ceilings fail closed for invalid or unavailable metrics. Local pressure commands, isolated full-process RSS measurements, and their limits are documented in [the benchmark binding](../benchmarks/quality-binding.md).
|
|
81
|
+
|
|
82
|
+
All child commands use argument arrays, bounded output, a finite timeout, and process-group cancellation. Project tests and prove commands execute with the caller's authority. Copies isolate source edits, not filesystem or network access. Reports may contain project paths and command diagnostics; review them before sharing.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Quality tool configuration
|
|
2
|
+
|
|
3
|
+
Graph, mutation, observation, and measurement are disabled by default. Enable a feature in `polyrun.yml`, or pass `--enable` for one invocation. `--no-enable` disables it for that invocation even when configuration or the environment enables it. Shared defaults never enable features. Existing test workers do not run these tools automatically.
|
|
4
|
+
|
|
5
|
+
All graph and mutation implementation ships in the Polyrun gem. No other graph or mutation package, executable, database, or source checkout is needed. Test commands still use the consuming project's ordinary dependencies.
|
|
6
|
+
|
|
7
|
+
## Root defaults and feature settings
|
|
8
|
+
|
|
9
|
+
```yaml
|
|
10
|
+
workers: 2
|
|
11
|
+
timeout: 120
|
|
12
|
+
command: [bundle, exec, rspec]
|
|
13
|
+
max_output_bytes: 1048576
|
|
14
|
+
source_roots: [lib, app]
|
|
15
|
+
max_source_files: 100000
|
|
16
|
+
max_source_file_bytes: 10485760
|
|
17
|
+
max_source_bytes: 67108864
|
|
18
|
+
staging:
|
|
19
|
+
max_files: 10000
|
|
20
|
+
max_bytes: 67108864
|
|
21
|
+
exclude: [vendor, node_modules, tmp, log, pkg, benchmarks]
|
|
22
|
+
exclude_paths: [coverage]
|
|
23
|
+
include_hidden: [.rspec, .ruby-version]
|
|
24
|
+
graph:
|
|
25
|
+
enabled: true
|
|
26
|
+
state_dir: .polyrun/graph
|
|
27
|
+
timeout: 60
|
|
28
|
+
max_nodes: 250000
|
|
29
|
+
max_operations: 1000
|
|
30
|
+
max_diff_bytes: 524288
|
|
31
|
+
max_plan_bytes: 1048576
|
|
32
|
+
max_receipt_files: 100000
|
|
33
|
+
mutation:
|
|
34
|
+
enabled: true
|
|
35
|
+
subjects: ['Account#save']
|
|
36
|
+
operators: [literal, operator, body]
|
|
37
|
+
max_workers: 32
|
|
38
|
+
max_mutations: 1000
|
|
39
|
+
max_subjects: 10000
|
|
40
|
+
max_report_bytes: 16777216
|
|
41
|
+
max_copy_bytes: 1073741824
|
|
42
|
+
quality:
|
|
43
|
+
observe:
|
|
44
|
+
enabled: true
|
|
45
|
+
output: tmp/observed.json
|
|
46
|
+
max_entries: 10000
|
|
47
|
+
max_artifact_bytes: 16777216
|
|
48
|
+
command: [ruby, -Ilib, test/probe.rb]
|
|
49
|
+
measure:
|
|
50
|
+
enabled: true
|
|
51
|
+
label: tests
|
|
52
|
+
output: tmp/measurement.json
|
|
53
|
+
ceilings: {wall_s: 120}
|
|
54
|
+
spec_quality:
|
|
55
|
+
enabled: false
|
|
56
|
+
min_line_churn: 50
|
|
57
|
+
min_query_count: 20
|
|
58
|
+
sample: 1.0
|
|
59
|
+
strict: false
|
|
60
|
+
profile: [cpu, mem]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Create parent directories for configured outputs before running commands. Arrays of command arguments execute directly; no shell splitting or interpolation is applied. A command after `--` replaces the configured command. CLI subjects or observed files replace their configured lists; repeated CLI selections accumulate within that invocation. Other arrays replace inherited arrays; mappings merge recursively.
|
|
64
|
+
|
|
65
|
+
The precedence is CLI, environment, feature settings, shared root settings, defaults. Each shared setting has one root location. The `global` section is rejected, including inside selected suites. Selected `suites` overlays merge before resolution; `--config`, `POLYRUN_CONFIG`, and `--suite` work with all tool commands. `POLYRUN_WORKERS` overrides worker defaults for mutations and existing parallel workers. Root `timeout` also supplies existing worker timeouts; their specific `--worker-timeout` and `POLYRUN_WORKER_TIMEOUT_SEC` remain overrides. Root-level `root` and `command` defaults apply to the new tool commands; existing workers retain their working-directory and command conventions.
|
|
66
|
+
|
|
67
|
+
`POLYRUN_GRAPH`, `POLYRUN_MUTATION`, and `POLYRUN_QUALITY` enable their corresponding commands with `1`, `true`, `yes`, or `on`; `0`, `false`, `no`, or `off` disable them. `POLYRUN_TIMEOUT` and `POLYRUN_MAX_OUTPUT_BYTES` supply shared environment overrides. Invalid values fail instead of silently selecting another setting.
|
|
68
|
+
|
|
69
|
+
A command's `--root` selects automatic project configuration discovery. Relative root settings are resolved against that discovery directory or the invoking directory. Output and subject-file paths resolve against the effective root. Source roots and graph state directories must stay inside the project. Changing source scope can invalidate an existing plan; selecting another state directory selects another local index and plan collection.
|
|
70
|
+
|
|
71
|
+
## Complete settings and validation
|
|
72
|
+
|
|
73
|
+
Inspect every supported key and effective default without enabling the tool:
|
|
74
|
+
|
|
75
|
+
polyrun config graph
|
|
76
|
+
polyrun config mutation
|
|
77
|
+
polyrun config quality.observe
|
|
78
|
+
polyrun config quality.measure
|
|
79
|
+
polyrun config workers
|
|
80
|
+
polyrun validate
|
|
81
|
+
polyrun --suite review config mutation
|
|
82
|
+
|
|
83
|
+
Root shared settings include `root`, `workers`, `timeout`, `command`, `output`, `max_output_bytes`, `max_input_bytes`, `max_artifact_bytes`, `source_roots`, `source_fallback`, `source_exclude`, `max_nodes`, `max_source_files`, `max_source_file_bytes`, `max_source_bytes`, and `staging`. Activation stays in feature blocks; root defaults never enable a feature. A feature accepts only keys it uses: source and staging settings apply to graph and mutation; workers apply to mutation. `quality` shares execution defaults for observe and measure before their own overrides. Irrelevant feature keys are errors, while shared root defaults are applied only where relevant.
|
|
84
|
+
|
|
85
|
+
Graph writes `output` in the selected CLI format. Graph also accepts `json`, `calls`, `callers`, `callees`, `control_plane`, and `prove`, in addition to the limits shown above. Configure `prove: true` and a command to run behavioral checks without repeating the command after `--`. `--no-prove` runs syntax checks only. Graph JSON and inspection flags have corresponding `--no-` overrides.
|
|
86
|
+
|
|
87
|
+
Mutation also accepts `subjects_file`, `observed`, `plan`, `shard`, `total`, and `output`. Mutation limits and worker ceilings are positive configurable values; increasing them is an explicit resource-budget decision. Shard numbering remains one-based. Operators select the built-in rule families; Ruby callers may provide additional operator objects through the runner API.
|
|
88
|
+
|
|
89
|
+
Unknown keys, malformed types, escaping source/state paths, and nonpositive resource bounds fail validation before execution. Output truncation, process cleanup, unchanged-source checks, symlink rejection, receipt integrity, and key-file exclusions remain invariants. Limits do not turn copied test execution into an OS sandbox.
|
|
90
|
+
|
|
91
|
+
## Existing per-example quality collection
|
|
92
|
+
|
|
93
|
+
`quality.spec_quality` accepts the settings documented in [SPEC_QUALITY.md](SPEC_QUALITY.md), including collection filters, thresholds, profiling, sampling, and report gates. Root `source_roots` supplies its `track_under` fallback. The existing environment activation and disable switches still apply; `POLYRUN_SPEC_QUALITY_DISABLE` always prevents collection. `POLYRUN_QUALITY` controls the observe and measure commands, not per-example collection.
|
|
94
|
+
|
|
95
|
+
The default dedicated spec-quality file provides settings below the main file's `quality.spec_quality` block. An explicitly selected dedicated file overrides the main block, followed by environment and explicit Ruby API overrides. Enabling settings does not install test hooks: use the existing RSpec, Minitest, or Quick integration. Direct graph and mutation Ruby API calls are explicit opt-in; pass a resolved `Polyrun::Config::Tools.resolve` mapping as `settings:` to use the same defaults and validation.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Polyrun setup profile (agent / human checklist)
|
|
2
|
+
|
|
3
|
+
Use this as a fill-in worksheet before editing a host project. `polyrun.yml` is the contract; everything else is an adapter that must stay aligned with it.
|
|
4
|
+
|
|
5
|
+
## 1. Project shape
|
|
6
|
+
|
|
7
|
+
| Field | Options / notes |
|
|
8
|
+
|--------|------------------|
|
|
9
|
+
| Project type | Gem (library, no Rails app), Rails (full app), or multi-gemfile (Appraisal / multiple `gemfiles/*.gemfile`) |
|
|
10
|
+
| Gemfile path to polyrun | For example `gem "polyrun", path: "../polyrun.rb"` or `gem "polyrun"` from RubyGems—note the path relative to each gemfile |
|
|
11
|
+
| Appraisal / Docker | If Appraisal: polyrun must appear in `Appraisals` and each generated gemfile. If Docker: document working directory and whether prepare is one-shot or repeated with tests |
|
|
12
|
+
|
|
13
|
+
## 2. Parallelism target (pick one primary story)
|
|
14
|
+
|
|
15
|
+
| Target | Typical CLI / CI |
|
|
16
|
+
|--------|-------------------|
|
|
17
|
+
| Single CI job, N workers on one runner | One workflow job runs `polyrun parallel-rspec --workers N` (or `start`); merge coverage in the same job or a small follow-up step; upload artifacts |
|
|
18
|
+
| Matrix: one shard per CI job | Matrix sets `POLYRUN_SHARD_INDEX` / `POLYRUN_SHARD_TOTAL` (or CI vendor equivalents—see `Polyrun::Env::Ci` and the README); each job runs `plan` plus the test command for its shard; upload `coverage/polyrun-fragment-<i>.json`; a merge job runs `merge-coverage` |
|
|
19
|
+
|
|
20
|
+
Do not mix “fan out N workers inside one job” with “matrix shard index” in the same workflow without a clear story for which process writes which fragment and where merge runs.
|
|
21
|
+
|
|
22
|
+
## 3. Database
|
|
23
|
+
|
|
24
|
+
| Field | Options |
|
|
25
|
+
|--------|---------|
|
|
26
|
+
| Single test DB | Omitting `databases:` in `polyrun.yml` may be enough; ensure parallel workers do not share one DB if they mutate data |
|
|
27
|
+
| Multi-DB or shard suffixes | `databases:` in `polyrun.yml` (`shard_db_pattern`, `template_db`, optional `connections` and `env_key`). `database.yml` or `DATABASE_URL` may use `%{shard}` or `POLYRUN_SHARD_INDEX` suffixes—the same convention as `polyrun env` |
|
|
28
|
+
| Non-Postgres adapters (mysql2, trilogy, …) | `UrlBuilder` still emits URLs from `template_db` / `shard_db_pattern`. Auto provision on `polyrun start` and `db:clone-shards` / `db:setup-shard` are PostgreSQL-only (`CREATE DATABASE … TEMPLATE`). For MySQL/MariaDB, set `start.databases: false` (or rely on the skip warning) and provision shards in `prepare` |
|
|
29
|
+
| External provisioning | Sometimes `db:prepare` plus shell clone scripts (multi-DB apps)—document ordering: prepare databases before `run-shards` |
|
|
30
|
+
|
|
31
|
+
## 4. Prepare (run once before workers)
|
|
32
|
+
|
|
33
|
+
| Field | Options |
|
|
34
|
+
|--------|---------|
|
|
35
|
+
| None | Typical for gems without assets |
|
|
36
|
+
| Assets | `Polyrun::Prepare::Assets`, `prepare.recipe: assets` or `default`, digest markers |
|
|
37
|
+
| Playwright / browsers | Install once in prepare; workers skip reinstall (`SKIP_*` env flags in app code if needed) |
|
|
38
|
+
| Custom shell | `prepare.recipe: shell` with `prepare.command:`—must not repeat heavy work inside each worker |
|
|
39
|
+
|
|
40
|
+
Rule: anything expensive (compile, `yarn`, Playwright download) belongs in prepare or a CI cache step, not in `before(:suite)` per worker unless gated by `POLYRUN_SHARD_TOTAL` or similar env.
|
|
41
|
+
|
|
42
|
+
## 5. Spec list and ordering
|
|
43
|
+
|
|
44
|
+
| Field | Options |
|
|
45
|
+
|--------|---------|
|
|
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 |
|
|
48
|
+
| Ordered stages | `partition.paths_build.stages`: regex (e.g. slow integration first) or `sort_by_substring_order` for stable ordering |
|
|
49
|
+
| Exclude prefixes | `partition.paths_build.exclude_prefixes`: omit paths (e.g. `spec/benchmark/`) from `paths_file` while keeping them runnable outside polyrun |
|
|
50
|
+
|
|
51
|
+
`paths_build` controls **membership** in `partition.paths_file`, not shard assignment order. Default `round_robin` sorts paths alphabetically before mod assignment. Use `strategy: preserve_order_round_robin` to honor paths-file line order. Set `partition.timing_file` without `strategy` to auto-select `cost_binpack`; use `lazy_robin` for round-robin assignment with timing diagnostics.
|
|
52
|
+
|
|
53
|
+
Refresh list: `polyrun -c polyrun.yml build-paths` (also runs automatically before `plan` / `run-shards` when configured).
|
|
54
|
+
|
|
55
|
+
## 5b. Parallel worker logs (opt-in)
|
|
56
|
+
|
|
57
|
+
When `run-shards` fans out multiple workers, stdout/stderr interleave on the parent TTY by default.
|
|
58
|
+
|
|
59
|
+
| Env | Effect |
|
|
60
|
+
|--------|--------|
|
|
61
|
+
| `POLYRUN_WORKER_OUTPUT_ROUTING=1` | Route each worker through per-shard log files (default dir `tmp/polyrun/workers`) |
|
|
62
|
+
| `POLYRUN_WORKER_LOG_DIR` | Custom log directory (also enables routing when set) |
|
|
63
|
+
| `POLYRUN_WORKER_OUTPUT_ROUTING=0` | Force inherited stdio even when log dir is set |
|
|
64
|
+
| `POLYRUN_WORKER_OUTPUT_PREFIX=0` | Write logs only; no live prefixed TTY echo |
|
|
65
|
+
|
|
66
|
+
Carriage-return progress chunks (Fuubar-style) pass through unprefixed on the TTY and in logs.
|
|
67
|
+
|
|
68
|
+
## 5c. RSpec example debug (local investigation)
|
|
69
|
+
|
|
70
|
+
Orchestration tracing stays on `DEBUG=1` / `POLYRUN_DEBUG=1`. Per-example tooling is separate:
|
|
71
|
+
|
|
72
|
+
| Env | Effect |
|
|
73
|
+
|--------|--------|
|
|
74
|
+
| `POLYRUN_EXAMPLE_DEBUG=1` | Enable print helpers, Rails logging; disable per-example timeouts |
|
|
75
|
+
| `POLYRUN_DEBUG_SQL=1` or `DEBUG_SQL=1` | Log mutating SQL |
|
|
76
|
+
| `POLYRUN_DEBUG_TRACE=1` or `DEBUG_TRACE=1` | TracePoint under app root |
|
|
77
|
+
| `DEBUG_PROSOPITE=1` | Prosopite N+1 scan when gem is loaded |
|
|
78
|
+
| `DEBUG_LOG_LEVEL` | Rails / ActiveRecord logger severity: `debug`, `info`, `warn`, `error`, `fatal`, or Ruby Logger integers (`0` debug … `4` fatal); default `debug` |
|
|
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) |
|
|
80
|
+
|
|
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.
|
|
82
|
+
|
|
83
|
+
## 6. Coverage and CI reports
|
|
84
|
+
|
|
85
|
+
| Field | Options |
|
|
86
|
+
|--------|---------|
|
|
87
|
+
| Collector | `require "polyrun"` plus `Polyrun::Coverage::Collector.start!` in `spec_helper` (non-Rails gems) |
|
|
88
|
+
| Rails | `require "polyrun/coverage/rails"` (or documented Rails integration) in `spec_helper` / `test_helper` |
|
|
89
|
+
| Fragments | Per shard: `coverage/polyrun-fragment-<shard>.json` |
|
|
90
|
+
| Merge | `polyrun merge-coverage` on fragments → merged JSON; then `polyrun report-coverage` (formats: json, lcov, cobertura, console, html, …) |
|
|
91
|
+
| JUnit | `polyrun report-junit` from RSpec JSON if needed |
|
|
92
|
+
|
|
93
|
+
## 7. `polyrun.yml` as contract — adapters
|
|
94
|
+
|
|
95
|
+
After `polyrun.yml` is fixed, add or adjust adapters (same shard semantics):
|
|
96
|
+
|
|
97
|
+
| Adapter | Role |
|
|
98
|
+
|---------|------|
|
|
99
|
+
| `bin/rspec_parallel` / `bin/rspec_ci_shard` | Thin wrappers: prepare, start, or plan + rspec |
|
|
100
|
+
| `bin/polyrun-rspec` | Single shard (`env` + plan + rspec), e.g. one matrix cell or ad-hoc run |
|
|
101
|
+
| `config/database.yml` | ERB / suffixes matching `databases.shard_db_pattern` |
|
|
102
|
+
| Prepare script | Referenced from `prepare.command` |
|
|
103
|
+
| `POLYRUN.md` (or `spec/README`) | Canonical commands for this repo; CI model (below) |
|
|
104
|
+
|
|
105
|
+
Bot workflow: read and write `polyrun.yml` first, then generate or patch wrappers and docs to match.
|
|
106
|
+
|
|
107
|
+
## 8. CI models (document one in `POLYRUN.md`)
|
|
108
|
+
|
|
109
|
+
Model A — one job, N worker processes
|
|
110
|
+
|
|
111
|
+
- Command: `polyrun -c polyrun.yml parallel-rspec --workers N` (or `polyrun start`). Global `-c` / `-v` / `-h` must appear before the subcommand.
|
|
112
|
+
- Coverage fragments appear on the same runner; `merge-coverage` can run in the same job after workers finish.
|
|
113
|
+
|
|
114
|
+
Model B — matrix of jobs (one shard per job)
|
|
115
|
+
|
|
116
|
+
- Each job sets `POLYRUN_SHARD_INDEX` / `POLYRUN_SHARD_TOTAL` (and DB URLs per shard if needed).
|
|
117
|
+
- Run `polyrun ci-shard-run -- bundle exec rspec` (or `ci-shard-rspec`), or `ci-shard-run -- bundle exec polyrun quick` / other runners; or the same steps manually (`bin/rspec_ci_shard` wrappers).
|
|
118
|
+
- Upload `coverage/polyrun-fragment-*.json` (or named per shard).
|
|
119
|
+
- A final `merge-coverage` job downloads artifacts and merges.
|
|
120
|
+
|
|
121
|
+
GitHub Actions does not set `CI_NODE_INDEX` / `CI_NODE_TOTAL` by default—set `POLYRUN_*` explicitly in the matrix.
|
|
122
|
+
|
|
123
|
+
## 9. Chatbot / agent context blocks (high signal)
|
|
124
|
+
|
|
125
|
+
1. Upstream README sections: partition, prepare, databases, merge-coverage, `Env::Ci` (shard detection).
|
|
126
|
+
2. Project `polyrun.yml` (filled in) plus one of: `POLYRUN.md` or `spec/README.md` with the canonical test command and CI model (A or B).
|
|
127
|
+
3. Exact `Gemfile` / Appraisal lines for `polyrun` and any Docker or path notes.
|
|
128
|
+
|
|
129
|
+
## 10. Scaffold from this repo
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
polyrun init --list
|
|
133
|
+
polyrun init --profile gem -o polyrun.yml
|
|
134
|
+
polyrun init --profile rails -o polyrun.yml
|
|
135
|
+
polyrun init --profile ci-matrix -o polyrun.yml
|
|
136
|
+
polyrun init --profile doc -o POLYRUN.md # host-project doc template
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Templates live under `lib/polyrun/templates/` in the gem. See `examples/templates/README.md` for profile descriptions.
|
|
@@ -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
|