Module: Polyrun::Partition::Paths
- Defined in:
- lib/polyrun/partition/paths.rb
Overview
Shared spec path listing for run-shards, queue init, and plan helpers.
Class Method Summary collapse
-
.detect_auto_suite(cwd = Dir.pwd) ⇒ Object
Prefer
spec/RSpec files, thentest/Minitest, then Polyrun Quick files (same globs as polyrun quick). -
.infer_suite_from_paths(paths) ⇒ Object
Infer parallel suite from explicit paths (
_spec.rbvs_test.rbvs Polyrun quick-style.rb). - .quick_parallel_default_paths(base) ⇒ Object
- .read_lines(path) ⇒ Object
-
.resolve_run_shard_items(paths_file: nil, cwd: Dir.pwd, partition: {}) ⇒ Object
When
paths_fileis set but missing, returns { error: “…” }. - .resolve_run_shard_items_glob(cwd:, partition: {}) ⇒ Object
Class Method Details
.detect_auto_suite(cwd = Dir.pwd) ⇒ Object
Prefer spec/ RSpec files, then test/ Minitest, then Polyrun Quick files (same globs as polyrun quick). Order avoids running the broader Quick glob when RSpec or Minitest files already exist.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/polyrun/partition/paths.rb', line 13 def detect_auto_suite(cwd = Dir.pwd) base = File.(cwd) return :rspec if Dir.glob(File.join(base, "spec/**/*_spec.rb")).any? return :minitest if Dir.glob(File.join(base, "test/**/*_test.rb")).any? quick = quick_parallel_default_paths(base) return :quick if quick.any? nil end |
.infer_suite_from_paths(paths) ⇒ Object
Infer parallel suite from explicit paths (_spec.rb vs _test.rb vs Polyrun quick-style .rb). Returns :rspec, :minitest, :quick, :invalid (mixed spec and test), or nil (empty).
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/polyrun/partition/paths.rb', line 27 def infer_suite_from_paths(paths) paths = paths.map { |p| File.(p) } return nil if paths.empty? specs = paths.count { |p| File.basename(p).end_with?("_spec.rb") } tests = paths.count { |p| File.basename(p).end_with?("_test.rb") } return :invalid if specs.positive? && tests.positive? return :rspec if specs.positive? return :minitest if tests.positive? others = paths.size - specs - tests return :quick if others.positive? nil end |
.quick_parallel_default_paths(base) ⇒ Object
103 104 105 106 |
# File 'lib/polyrun/partition/paths.rb', line 103 def quick_parallel_default_paths(base) require_relative "../quick/runner" Polyrun::Quick::Runner.parallel_default_paths(base) end |
.read_lines(path) ⇒ Object
7 8 9 |
# File 'lib/polyrun/partition/paths.rb', line 7 def read_lines(path) File.read(File.(path.to_s, Dir.pwd)).split("\n").map(&:strip).reject(&:empty?) end |
.resolve_run_shard_items(paths_file: nil, cwd: Dir.pwd, partition: {}) ⇒ Object
When paths_file is set but missing, returns { error: “…” }. Otherwise returns { items:, source: } (human-readable source label).
partition.suite (optional): auto (default), rspec, minitest, quick — used only when resolving from globs (no explicit paths_file and no spec/spec_paths.txt).
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/polyrun/partition/paths.rb', line 49 def resolve_run_shard_items(paths_file: nil, cwd: Dir.pwd, partition: {}) if paths_file abs = File.(paths_file.to_s, cwd) unless File.file?(abs) return {error: "paths file not found: #{abs}"} end {items: read_lines(abs), source: paths_file.to_s} elsif File.file?(File.join(cwd, "spec", "spec_paths.txt")) {items: read_lines(File.join(cwd, "spec", "spec_paths.txt")), source: "spec/spec_paths.txt"} else resolve_run_shard_items_glob(cwd: cwd, partition: partition) end end |
.resolve_run_shard_items_glob(cwd:, partition: {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/polyrun/partition/paths.rb', line 63 def resolve_run_shard_items_glob(cwd:, partition: {}) suite = (partition["suite"] || partition[:suite] || "auto").to_s.downcase suite = "auto" if suite.empty? base = File.(cwd) spec = Dir.glob(File.join(base, "spec/**/*_spec.rb")).sort test = Dir.glob(File.join(base, "test/**/*_test.rb")).sort quick = quick_parallel_default_paths(base) case suite when "rspec" return {error: "partition.suite is rspec but no spec/**/*_spec.rb files"} if spec.empty? {items: spec, source: "spec/**/*_spec.rb glob"} when "minitest" return {error: "partition.suite is minitest but no test/**/*_test.rb files"} if test.empty? {items: test, source: "test/**/*_test.rb glob"} when "quick" return {error: "partition.suite is quick but no Polyrun quick files under spec/ or test/"} if quick.empty? {items: quick, source: "Polyrun quick glob"} when "auto" if spec.any? {items: spec, source: "spec/**/*_spec.rb glob"} elsif test.any? {items: test, source: "test/**/*_test.rb glob"} elsif quick.any? {items: quick, source: "Polyrun quick glob"} else { error: "no spec paths (spec/spec_paths.txt, partition.paths_file, or spec/**/*_spec.rb); " \ "no test/**/*_test.rb; no Polyrun quick files" } end else {error: "unknown partition.suite: #{suite.inspect} (expected auto, rspec, minitest, quick)"} end end |