polyrun 3.0.0 → 3.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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/README.md +4 -2
  4. data/docs/QUALITY.md +80 -0
  5. data/docs/QUALITY_CONFIGURATION.md +95 -0
  6. data/lib/polyrun/cli/ci_shard_run_command.rb +1 -1
  7. data/lib/polyrun/cli/graph_command.rb +68 -0
  8. data/lib/polyrun/cli/help.rb +5 -1
  9. data/lib/polyrun/cli/helpers.rb +3 -2
  10. data/lib/polyrun/cli/mutation_command.rb +67 -0
  11. data/lib/polyrun/cli/quality_commands.rb +65 -0
  12. data/lib/polyrun/cli/run_shards_plan_options.rb +1 -1
  13. data/lib/polyrun/cli/tool_options.rb +48 -0
  14. data/lib/polyrun/cli.rb +17 -1
  15. data/lib/polyrun/config/effective.rb +9 -0
  16. data/lib/polyrun/config/resolver.rb +9 -0
  17. data/lib/polyrun/config/schema.rb +8 -3
  18. data/lib/polyrun/config/suite.rb +6 -1
  19. data/lib/polyrun/config/tool_defaults.rb +42 -0
  20. data/lib/polyrun/config/tool_validation.rb +79 -0
  21. data/lib/polyrun/config/tools.rb +120 -0
  22. data/lib/polyrun/config.rb +6 -4
  23. data/lib/polyrun/coverage/merge/formatters.rb +0 -3
  24. data/lib/polyrun/graph/client.rb +64 -0
  25. data/lib/polyrun/graph/error.rb +13 -0
  26. data/lib/polyrun/graph/index.rb +75 -0
  27. data/lib/polyrun/graph/inspect.rb +58 -0
  28. data/lib/polyrun/graph/plan.rb +134 -0
  29. data/lib/polyrun/graph/planner.rb +117 -0
  30. data/lib/polyrun/graph/syntax.rb +114 -0
  31. data/lib/polyrun/graph/transaction.rb +81 -0
  32. data/lib/polyrun/graph/worker.rb +55 -0
  33. data/lib/polyrun/graph/workspace.rb +117 -0
  34. data/lib/polyrun/minitest_support.rb +1 -1
  35. data/lib/polyrun/mutation/candidates.rb +91 -0
  36. data/lib/polyrun/mutation/operators.rb +51 -0
  37. data/lib/polyrun/mutation/runner.rb +131 -0
  38. data/lib/polyrun/mutation/subjects.rb +88 -0
  39. data/lib/polyrun/quality/command.rb +84 -0
  40. data/lib/polyrun/quality/measure.rb +38 -0
  41. data/lib/polyrun/quality/observe.rb +53 -0
  42. data/lib/polyrun/quality/observe_hook.rb +103 -0
  43. data/lib/polyrun/quality/sandbox.rb +70 -0
  44. data/lib/polyrun/rspec_support.rb +1 -1
  45. data/lib/polyrun/spec_quality/config.rb +8 -3
  46. data/lib/polyrun/spec_quality.rb +3 -4
  47. data/lib/polyrun/version.rb +1 -1
  48. data/polyrun.gemspec +1 -1
  49. data/sig/polyrun/config.rbs +2 -2
  50. metadata +29 -1
@@ -0,0 +1,70 @@
1
+ require "digest"
2
+ require "fileutils"
3
+ require "find"
4
+ require_relative "../config/tools"
5
+
6
+ module Polyrun
7
+ module Quality
8
+ class Sandbox
9
+ attr_reader :bytes
10
+
11
+ def initialize(root, settings: {})
12
+ @settings = Config::Tools.merge(Config::ToolDefaults::STAGING, Config::Tools.stringify(settings))
13
+ errors = Config::ToolValidation.check(@settings, Config::ToolDefaults::STAGING, "staging")
14
+ raise ArgumentError, errors.join("; ") unless errors.empty?
15
+
16
+ @root = File.realpath(root)
17
+ @bytes = 0
18
+ @files = inventory
19
+ end
20
+
21
+ def copy_to(destination)
22
+ @files.each do |relative, expected|
23
+ source = File.join(@root, relative)
24
+ raise ArgumentError, "project changed while staging" unless File.file?(source) && !File.symlink?(source) && Digest::SHA256.file(source).hexdigest == expected
25
+
26
+ target = File.join(destination, relative)
27
+ FileUtils.mkdir_p(File.dirname(target))
28
+ FileUtils.copy_file(source, target, true)
29
+ raise ArgumentError, "project changed while staging" unless Digest::SHA256.file(target).hexdigest == expected
30
+ end
31
+ destination
32
+ end
33
+
34
+ def self.environment(destination)
35
+ {"BUNDLE_GEMFILE" => File.file?(File.join(destination, "Gemfile")) ? File.join(destination, "Gemfile") : nil,
36
+ "RUBYLIB" => [File.join(destination, "lib"), ENV["RUBYLIB"]].compact.join(File::PATH_SEPARATOR)}
37
+ end
38
+
39
+ private
40
+
41
+ def inventory
42
+ files = {}
43
+ Find.find(@root) do |path|
44
+ next if path == @root
45
+
46
+ name = File.basename(path)
47
+ relative = path.delete_prefix("#{@root}/")
48
+ if excluded?(name) || @settings["exclude_paths"].any? { |pattern| File.fnmatch?(pattern, relative, File::FNM_PATHNAME) }
49
+ Find.prune if File.directory?(path)
50
+ next
51
+ end
52
+ raise ArgumentError, "symbolic links are not supported in staged projects" if File.symlink?(path)
53
+ next unless File.file?(path)
54
+
55
+ @bytes += File.size(path)
56
+ raise ArgumentError, "staged project exceeds configured file or byte limit" if @bytes > @settings["max_bytes"] || files.size >= @settings["max_files"]
57
+
58
+ files[path.delete_prefix("#{@root}/")] = Digest::SHA256.file(path).hexdigest
59
+ end
60
+ files
61
+ end
62
+
63
+ def excluded?(name)
64
+ return true if name.start_with?(".") && !@settings["include_hidden"].include?(name)
65
+
66
+ @settings["exclude"].any? { |pattern| File.fnmatch?(pattern, name) } || name.end_with?(".key")
67
+ end
68
+ end
69
+ end
70
+ end
@@ -50,7 +50,7 @@ module Polyrun
50
50
  # Writes {WorkerPing} after suite start, before/after each example (+location+ is file:line from metadata).
51
51
  # Keeps +--worker-idle-timeout+ sensitive to example progress (not only a background thread).
52
52
  def install_spec_quality!(only_if: nil, root: nil, output_path: nil)
53
- pred = only_if || -> { Polyrun::SpecQuality.enabled? }
53
+ pred = only_if || -> { Polyrun::SpecQuality.enabled?(root: root || Dir.pwd) }
54
54
  return unless pred.call
55
55
 
56
56
  require_relative "spec_quality/rspec_hook"
@@ -1,4 +1,5 @@
1
1
  require "yaml"
2
+ require_relative "../config"
2
3
 
3
4
  module Polyrun
4
5
  module SpecQuality
@@ -25,10 +26,12 @@ module Polyrun
25
26
 
26
27
  module_function
27
28
 
28
- def enabled?(env = ENV)
29
+ def enabled?(env = ENV, root: Dir.pwd)
29
30
  return false if disabled?(env)
30
31
 
31
- truthy?(env["POLYRUN_SPEC_QUALITY"]) || truthy?(env["POLYRUN_SPEC_QUALITY_FRAGMENTS"])
32
+ return true if truthy?(env["POLYRUN_SPEC_QUALITY"]) || truthy?(env["POLYRUN_SPEC_QUALITY_FRAGMENTS"])
33
+
34
+ Polyrun::Config::Tools.spec_quality(root: root, env: env)["enabled"] == true
32
35
  end
33
36
 
34
37
  def disabled?(env = ENV)
@@ -38,7 +41,9 @@ module Polyrun
38
41
  def load(root:, config_path: nil, env: ENV, **overrides)
39
42
  root = File.expand_path(root)
40
43
  file_cfg = load_yaml(root, config_path)
41
- merged = DEFAULTS.merge(stringify_keys(file_cfg))
44
+ shared = Polyrun::Config::Tools.spec_quality(root: root, env: env).except("enabled")
45
+ merged = DEFAULTS.merge(stringify_keys(file_cfg)).merge(shared)
46
+ merged.merge!(stringify_keys(file_cfg)) if config_path
42
47
  apply_env!(merged, env)
43
48
  merged.merge!(stringify_keys(overrides).transform_keys(&:to_s))
44
49
  merged["root"] = root
@@ -37,8 +37,8 @@ module Polyrun
37
37
  instance_variable_defined?(:@config) && @config
38
38
  end
39
39
 
40
- def enabled?
41
- Config.enabled? && !Config.disabled?
40
+ def enabled?(root: Dir.pwd)
41
+ Config.enabled?(ENV, root: root) && !Config.disabled?
42
42
  end
43
43
 
44
44
  attr_reader :config
@@ -130,8 +130,7 @@ module Polyrun
130
130
 
131
131
  def spec_quality_requested_for_quick?(root = Dir.pwd)
132
132
  return false if Config.disabled?
133
- return true if %w[1 true yes].include?(ENV["POLYRUN_SPEC_QUALITY"]&.to_s&.downcase)
134
- return true if %w[1 true yes].include?(ENV["POLYRUN_SPEC_QUALITY_FRAGMENTS"]&.to_s&.downcase)
133
+ return true if Config.enabled?(ENV, root: root)
135
134
 
136
135
  path = File.join(File.expand_path(root), Config::DEFAULT_CONFIG_RELATIVE)
137
136
  return false unless File.file?(path)
@@ -1,3 +1,3 @@
1
1
  module Polyrun
2
- VERSION = "3.0.0"
2
+ VERSION = "3.1.0"
3
3
  end
data/polyrun.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.required_ruby_version = ">= 3.4"
12
12
 
13
13
  spec.files = (
14
- Dir["lib/**/*", "sig/**/*.rbs", "bin/polyrun", "README.md", "CHANGELOG.md", "docs/SETUP_PROFILE.md", "LICENSE", "CONTRIBUTING.md", "CODE_OF_CONDUCT.md", "SECURITY.md", "polyrun.gemspec"] +
14
+ Dir["lib/**/*", "sig/**/*.rbs", "bin/polyrun", "README.md", "CHANGELOG.md", "docs/SETUP_PROFILE.md", "docs/QUALITY.md", "docs/QUALITY_CONFIGURATION.md", "LICENSE", "CONTRIBUTING.md", "CODE_OF_CONDUCT.md", "SECURITY.md", "polyrun.gemspec"] +
15
15
  Dir["ext/**/extconf.rb", "ext/**/*.c", "ext/**/*.h"]
16
16
  ).uniq.reject { |f| File.directory?(f) }
17
17
  spec.bindir = "bin"
@@ -5,8 +5,8 @@ module Polyrun
5
5
  attr_reader path: String?
6
6
  attr_reader raw: untyped
7
7
 
8
- def self.load: (?path: String?) -> Config
9
- def self.resolve_path: (String? explicit) -> String?
8
+ def self.load: (?path: String?, ?suite: String?, ?root: String) -> Config
9
+ def self.resolve_path: (String? explicit, ?root: String) -> String?
10
10
 
11
11
  def initialize: (path: String?, raw: untyped) -> void
12
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyrun
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov
@@ -206,6 +206,8 @@ files:
206
206
  - README.md
207
207
  - SECURITY.md
208
208
  - bin/polyrun
209
+ - docs/QUALITY.md
210
+ - docs/QUALITY_CONFIGURATION.md
209
211
  - docs/SETUP_PROFILE.md
210
212
  - ext/polyrun_coverage_merge/coverage_merge.c
211
213
  - ext/polyrun_coverage_merge/extconf.rb
@@ -228,14 +230,17 @@ files:
228
230
  - lib/polyrun/cli/doctor_command.rb
229
231
  - lib/polyrun/cli/env_commands.rb
230
232
  - lib/polyrun/cli/failure_commands.rb
233
+ - lib/polyrun/cli/graph_command.rb
231
234
  - lib/polyrun/cli/help.rb
232
235
  - lib/polyrun/cli/helpers.rb
233
236
  - lib/polyrun/cli/hooks_command.rb
234
237
  - lib/polyrun/cli/init_command.rb
238
+ - lib/polyrun/cli/mutation_command.rb
235
239
  - lib/polyrun/cli/partition_diagnostics.rb
236
240
  - lib/polyrun/cli/plan_command.rb
237
241
  - lib/polyrun/cli/prepare_command.rb
238
242
  - lib/polyrun/cli/prepare_recipe.rb
243
+ - lib/polyrun/cli/quality_commands.rb
239
244
  - lib/polyrun/cli/queue_command.rb
240
245
  - lib/polyrun/cli/quick_command.rb
241
246
  - lib/polyrun/cli/report_commands.rb
@@ -252,6 +257,7 @@ files:
252
257
  - lib/polyrun/cli/spec_quality_commands.rb
253
258
  - lib/polyrun/cli/start_bootstrap.rb
254
259
  - lib/polyrun/cli/timing_command.rb
260
+ - lib/polyrun/cli/tool_options.rb
255
261
  - lib/polyrun/cli/validate_command.rb
256
262
  - lib/polyrun/config.rb
257
263
  - lib/polyrun/config/dotted_path.rb
@@ -259,6 +265,9 @@ files:
259
265
  - lib/polyrun/config/resolver.rb
260
266
  - lib/polyrun/config/schema.rb
261
267
  - lib/polyrun/config/suite.rb
268
+ - lib/polyrun/config/tool_defaults.rb
269
+ - lib/polyrun/config/tool_validation.rb
270
+ - lib/polyrun/config/tools.rb
262
271
  - lib/polyrun/coverage/cobertura_zero_lines.rb
263
272
  - lib/polyrun/coverage/collector.rb
264
273
  - lib/polyrun/coverage/collector_blob.rb
@@ -306,6 +315,16 @@ files:
306
315
  - lib/polyrun/env/ci.rb
307
316
  - lib/polyrun/export/csv.rb
308
317
  - lib/polyrun/export/markdown.rb
318
+ - lib/polyrun/graph/client.rb
319
+ - lib/polyrun/graph/error.rb
320
+ - lib/polyrun/graph/index.rb
321
+ - lib/polyrun/graph/inspect.rb
322
+ - lib/polyrun/graph/plan.rb
323
+ - lib/polyrun/graph/planner.rb
324
+ - lib/polyrun/graph/syntax.rb
325
+ - lib/polyrun/graph/transaction.rb
326
+ - lib/polyrun/graph/worker.rb
327
+ - lib/polyrun/graph/workspace.rb
309
328
  - lib/polyrun/hooks.rb
310
329
  - lib/polyrun/hooks/dsl.rb
311
330
  - lib/polyrun/hooks/shell_runner.rb
@@ -313,6 +332,10 @@ files:
313
332
  - lib/polyrun/hooks/worker_shell.rb
314
333
  - lib/polyrun/log.rb
315
334
  - lib/polyrun/minitest_support.rb
335
+ - lib/polyrun/mutation/candidates.rb
336
+ - lib/polyrun/mutation/operators.rb
337
+ - lib/polyrun/mutation/runner.rb
338
+ - lib/polyrun/mutation/subjects.rb
316
339
  - lib/polyrun/partition/constraints.rb
317
340
  - lib/polyrun/partition/hrw.rb
318
341
  - lib/polyrun/partition/min_heap.rb
@@ -329,6 +352,11 @@ files:
329
352
  - lib/polyrun/prepare/artifacts.rb
330
353
  - lib/polyrun/prepare/assets.rb
331
354
  - lib/polyrun/process_stdio.rb
355
+ - lib/polyrun/quality/command.rb
356
+ - lib/polyrun/quality/measure.rb
357
+ - lib/polyrun/quality/observe.rb
358
+ - lib/polyrun/quality/observe_hook.rb
359
+ - lib/polyrun/quality/sandbox.rb
332
360
  - lib/polyrun/queue/duration.rb
333
361
  - lib/polyrun/queue/file_store.rb
334
362
  - lib/polyrun/queue/file_store_intent.rb