specguard-ruby 0.3.34 → 0.3.36
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 +4 -4
- data/README.md +15 -2
- data/lib/specguard/client/delivery_warning.rb +4 -2
- data/lib/specguard/client/file_selector.rb +3 -2
- data/lib/specguard/client/path_root.rb +100 -0
- data/lib/specguard/client/root_binding.rb +57 -0
- data/lib/specguard/client/sink_writer.rb +53 -0
- data/lib/specguard/minitest/reporter.rb +34 -31
- data/lib/specguard/rspec/formatter.rb +65 -62
- data/lib/specguard/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 991575484b52a572f28efefb1ec0c7410f050fd34e2b7b9cb651ba945897b926
|
|
4
|
+
data.tar.gz: ba8c38cc1541f1a32e15c546e4a264b4c03549c1ee147fb9e7468facb8fc10bd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 35bffa2fbd23ed02c04a4e3309d7139066dca7574e47965d5d099a5c714d9eb9747605a8f5c9048826c1021e6035d95b2cfbb89b122bf45d5ed66b83df98b976
|
|
7
|
+
data.tar.gz: 1f114f41b076bdc7fd3e9c28da71967964f6c26f7209d9ed8d5b091460554576cbf41fddb4825ef7e6f016eb8fe2846386165a3c63267d78dbe79a3b40b8db47
|
data/README.md
CHANGED
|
@@ -423,6 +423,19 @@ have named, not against a `spec/support/` helper.
|
|
|
423
423
|
`file_path` and `line_number` keep meaning the **definition** site — that is the line the `@intent:`
|
|
424
424
|
annotation is read from.
|
|
425
425
|
|
|
426
|
+
**Paths are relative to the git repository root.** Run from a gem or engine subdirectory of a
|
|
427
|
+
monorepo (`gems/a`, `gems/b`), the formatter and the Minitest reporter ship `gems/a/spec/util_spec.rb`
|
|
428
|
+
— not the working-directory-relative `spec/util_spec.rb` that every sibling package would share, which
|
|
429
|
+
made two packages' same-named specs collide on one run id and silently drop one package's rows. The
|
|
430
|
+
root is `git rev-parse --show-toplevel`, resolved once per run; outside a git repository (or when git
|
|
431
|
+
is missing) it is the working directory, and a run from the repository root ships exactly what it
|
|
432
|
+
always did. Annotations are still read from the working directory, so annotated specs in a
|
|
433
|
+
subdirectory run stay annotated. `specguard-lint` output stays working-directory-relative (display
|
|
434
|
+
only). **One-time discontinuity:** if you already run from a subdirectory of a repository, the
|
|
435
|
+
`file_path`, `spec_file_path` and `id` values change on the first run after upgrading
|
|
436
|
+
(`spec/util_spec.rb` → `gems/a/spec/util_spec.rb`), so per-file history for those specs restarts under
|
|
437
|
+
the new names.
|
|
438
|
+
|
|
426
439
|
An example counts as **annotated** when an `@intent:` sits on its `it` line, or on the comment line
|
|
427
440
|
immediately above it:
|
|
428
441
|
|
|
@@ -1180,8 +1193,8 @@ body is encoded on the wire, never what is in it.
|
|
|
1180
1193
|
|
|
1181
1194
|
| Field | What it holds | Where it comes from |
|
|
1182
1195
|
| --- | --- | --- |
|
|
1183
|
-
| `id` | RSpec's own example id, `./spec/orders_spec.rb[1:2]` — the re-run argument | `example.id` |
|
|
1184
|
-
| `spec_file_path` | the spec file that **ran** the example, relative to the
|
|
1196
|
+
| `id` | RSpec's own example id, `./spec/orders_spec.rb[1:2]` — the re-run argument. From a subdirectory of a git repository the path half is repo-relative (`gems/a/spec/orders_spec.rb[1:2]`) | `example.id` |
|
|
1197
|
+
| `spec_file_path` | the spec file that **ran** the example, relative to the git repository root (the working directory when not in a git repo) when it lives under it — an absolute path when it does not, because a spec outside that root has no relative name | `metadata[:rerun_file_path]` |
|
|
1185
1198
|
| `file_path` | the spec file the example is **defined** in, on the same terms | `metadata[:file_path]` |
|
|
1186
1199
|
| `line_number` | the line it is defined on | `metadata[:line_number]` |
|
|
1187
1200
|
| `name` | the composed `describe`/`context`/`it` string | `example.full_description` |
|
|
@@ -13,8 +13,10 @@ module SpecGuard
|
|
|
13
13
|
# wording change cannot reach one client and miss the other.
|
|
14
14
|
#
|
|
15
15
|
# What stays in each client: the prefix, the warning budget (`@warned`),
|
|
16
|
-
# and
|
|
17
|
-
#
|
|
16
|
+
# and what it does with the answer of the shared write ({SinkWriter}) —
|
|
17
|
+
# whether `error` is nil, and which sentence that earns. The write itself
|
|
18
|
+
# no longer differs between the clients; what each does with its answer
|
|
19
|
+
# does, by design. Only the clause text is shared here.
|
|
18
20
|
module DeliveryWarning
|
|
19
21
|
module_function
|
|
20
22
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "open3"
|
|
4
|
+
require_relative "path_root"
|
|
4
5
|
|
|
5
6
|
module SpecGuard
|
|
6
7
|
module Client
|
|
@@ -401,8 +402,8 @@ module SpecGuard
|
|
|
401
402
|
# Empty when git cannot say, in which case the caller falls back to `root`
|
|
402
403
|
# (the top level *is* root for the common case of running from there).
|
|
403
404
|
def toplevel(root)
|
|
404
|
-
|
|
405
|
-
|
|
405
|
+
# The one probe the reporters' path root shares (SPGD-2109).
|
|
406
|
+
PathRoot.toplevel(root) || ""
|
|
406
407
|
end
|
|
407
408
|
|
|
408
409
|
# The merge base of HEAD with the default branch.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "open3"
|
|
4
|
+
require "pathname"
|
|
5
|
+
|
|
6
|
+
module SpecGuard
|
|
7
|
+
module Client
|
|
8
|
+
# The directory a run's row paths are relative to: the git toplevel of the
|
|
9
|
+
# working directory, so a run started from a gem/engine subdirectory of a
|
|
10
|
+
# monorepo (`gems/a`, `gems/b`) ships `gems/a/spec/util_spec.rb`, not
|
|
11
|
+
# `spec/util_spec.rb`. Two packages each holding `spec/util_spec.rb` would
|
|
12
|
+
# otherwise ship identical `file_path`/`id` values, and the platform's
|
|
13
|
+
# per-run upsert keeps one writer's rows and drops the other's.
|
|
14
|
+
#
|
|
15
|
+
# This is the Ruby twin of specguard-ts's `resolveRunRoots()` (SPGD-2105).
|
|
16
|
+
# Like that, it is two values, not one: the clients keep reading spec
|
|
17
|
+
# SOURCE (annotation lookup) from the working directory — the cwd-relative
|
|
18
|
+
# spelling — and only SHIP paths relative to the path root. Collapsing the
|
|
19
|
+
# two would resolve a repo-relative spelling against the cwd and ship
|
|
20
|
+
# every annotated spec of a subdirectory run as `unannotated`.
|
|
21
|
+
#
|
|
22
|
+
# Falls back to the working directory itself when git is absent, the
|
|
23
|
+
# directory is not in a repository, or the reported toplevel does not
|
|
24
|
+
# contain it (compared by real path, so a symlinked tmpdir such as macOS
|
|
25
|
+
# `/var` vs `/private/var` does not read as "outside"). In that case —
|
|
26
|
+
# and when the cwd *is* the toplevel — the answer is the cwd string
|
|
27
|
+
# exactly as given, so output is byte-identical to a run with no path
|
|
28
|
+
# root at all.
|
|
29
|
+
module PathRoot
|
|
30
|
+
module_function
|
|
31
|
+
|
|
32
|
+
# The repository's top level, as a real path.
|
|
33
|
+
# @param dir [String] where to ask git from
|
|
34
|
+
# @return [String, nil] nil when git cannot say
|
|
35
|
+
def toplevel(dir)
|
|
36
|
+
out, _err, status = Open3.capture3("git", "rev-parse", "--show-toplevel", chdir: dir)
|
|
37
|
+
return nil unless status.success?
|
|
38
|
+
|
|
39
|
+
top = out.strip
|
|
40
|
+
top.empty? ? nil : real_path(top)
|
|
41
|
+
rescue SystemCallError
|
|
42
|
+
# git not installed / not executable / `dir` unreadable.
|
|
43
|
+
nil
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# The path root for a run started in `cwd`.
|
|
47
|
+
#
|
|
48
|
+
# Returned in the spelling of `cwd` (an ancestor of it, so absolute paths
|
|
49
|
+
# the test framework built through the same spelling still start with
|
|
50
|
+
# it) whenever that spelling can be recovered; the real toplevel
|
|
51
|
+
# otherwise.
|
|
52
|
+
# @param cwd [String]
|
|
53
|
+
# @return [String]
|
|
54
|
+
def resolve(cwd)
|
|
55
|
+
top = toplevel(cwd)
|
|
56
|
+
return cwd if top.nil?
|
|
57
|
+
|
|
58
|
+
real_cwd = real_path(cwd)
|
|
59
|
+
return cwd if real_cwd == top
|
|
60
|
+
return cwd unless real_cwd.start_with?(top.end_with?("/") ? top : "#{top}/")
|
|
61
|
+
|
|
62
|
+
suffix = real_cwd.delete_prefix(top)
|
|
63
|
+
cwd.end_with?(suffix) ? cwd.delete_suffix(suffix) : top
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# The working directory relative to the path root; empty when they are
|
|
67
|
+
# the same directory.
|
|
68
|
+
def prefix(cwd, root)
|
|
69
|
+
return "" if cwd == root
|
|
70
|
+
|
|
71
|
+
cwd.delete_prefix("#{root}/")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# A path as the test framework spells it relative to the working
|
|
75
|
+
# directory (or absolute, for a file outside it), re-expressed relative
|
|
76
|
+
# to the path root. With an empty `prefix` the two roots coincide and
|
|
77
|
+
# the path is returned untouched.
|
|
78
|
+
#
|
|
79
|
+
# An absolute path under the root loses the root; an absolute path
|
|
80
|
+
# outside it, or a relative one that climbs out of it, keeps today's
|
|
81
|
+
# spelling.
|
|
82
|
+
def rebase(path, root:, prefix:)
|
|
83
|
+
return path if prefix.empty?
|
|
84
|
+
|
|
85
|
+
if path.start_with?("/")
|
|
86
|
+
path.start_with?("#{root}/") ? path.delete_prefix("#{root}/") : path
|
|
87
|
+
else
|
|
88
|
+
joined = Pathname.new(File.join(prefix, path)).cleanpath.to_s
|
|
89
|
+
joined.start_with?("../") || joined == ".." ? path : joined
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def real_path(path)
|
|
94
|
+
File.realpath(path)
|
|
95
|
+
rescue SystemCallError
|
|
96
|
+
File.expand_path(path)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "path_root"
|
|
4
|
+
|
|
5
|
+
module SpecGuard
|
|
6
|
+
module Client
|
|
7
|
+
# The class-level root binding shared by the RSpec formatter and the
|
|
8
|
+
# Minitest reporter: `repo_root`, `path_root` and `path_prefix`.
|
|
9
|
+
#
|
|
10
|
+
# Both clients carried the same three methods, differing only in their
|
|
11
|
+
# comments, and every fix to the one-binding discipline had to land once
|
|
12
|
+
# per client (SPGD-1408/1421 for Minitest, SPGD-1429 for RSpec, SPGD-2109
|
|
13
|
+
# in both). One definition here means a binding fix cannot reach one
|
|
14
|
+
# client and miss the other.
|
|
15
|
+
#
|
|
16
|
+
# Use with `extend`, never `include`: the methods run with the CLASS as
|
|
17
|
+
# `self`, so the memos stay class-level ivars (`@repo_root`,
|
|
18
|
+
# `@path_root_binding`) on each client. Specs that save, clear and restore
|
|
19
|
+
# them on the client class depend on that.
|
|
20
|
+
module RootBinding
|
|
21
|
+
# `Dir.pwd` bound once — by the first client construction (whose
|
|
22
|
+
# `#initialize` reads it, SPGD-1421 / SPGD-1429) or the first direct
|
|
23
|
+
# read — never per row: a suite that changes the working directory after
|
|
24
|
+
# the client was built would otherwise relativize one run's rows against
|
|
25
|
+
# two different roots. The memo is what binds it — an unmemoized
|
|
26
|
+
# `Dir.pwd` here re-reads the cwd on every read and is exactly the
|
|
27
|
+
# two-root split the constructors' comments name, with both spellings
|
|
28
|
+
# individually well-formed so nothing downstream can detect the drift.
|
|
29
|
+
# The memo is also the ONE value the annotation lookup reads against:
|
|
30
|
+
# `#initialize` hands it over, so the relativization root and the
|
|
31
|
+
# lookup's read root cannot drift apart the way they did when each bound
|
|
32
|
+
# `Dir.pwd` at its own moment.
|
|
33
|
+
def repo_root
|
|
34
|
+
@repo_root ||= Dir.pwd
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The directory every shipped row path is relative to (SPGD-2109): the
|
|
38
|
+
# git toplevel of {#repo_root}, or {#repo_root} itself outside a
|
|
39
|
+
# repository. Derived from the ONE bound {#repo_root} and probed once
|
|
40
|
+
# per binding — the same one-binding discipline, so a run started from a
|
|
41
|
+
# monorepo package subdirectory ships `gems/a/spec/x_spec.rb` rather
|
|
42
|
+
# than a name every sibling package shares. {#repo_root} stays the READ
|
|
43
|
+
# root (the annotation lookup resolves spec source against it); the two
|
|
44
|
+
# are deliberately not one value.
|
|
45
|
+
def path_root
|
|
46
|
+
bound = repo_root
|
|
47
|
+
@path_root_binding = nil unless @path_root_binding&.first == bound
|
|
48
|
+
(@path_root_binding ||= [bound, SpecGuard::Client::PathRoot.resolve(bound)]).last
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# {#repo_root} relative to {#path_root}; empty when they coincide.
|
|
52
|
+
def path_prefix
|
|
53
|
+
SpecGuard::Client::PathRoot.prefix(repo_root, path_root)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
|
|
6
|
+
module SpecGuard
|
|
7
|
+
module Client
|
|
8
|
+
# The local JSON-line sink writer shared by the two framework clients'
|
|
9
|
+
# sinks: the RSpec formatter's replay queue and local development record,
|
|
10
|
+
# and the Minitest reporter's (see {Configuration#output_path} and
|
|
11
|
+
# {Configuration#local_output_path}). One definition here means the write
|
|
12
|
+
# — the guarded `mkdir_p`, the single append-mode write of the full line,
|
|
13
|
+
# the exception-as-value contract — cannot drift between the two clients,
|
|
14
|
+
# which hand-copied it until SPGD-2124 and had already been co-edited in
|
|
15
|
+
# separate commits (SPGD-1413).
|
|
16
|
+
#
|
|
17
|
+
# What stays in each client: which sink the run warrants (`#deliver`
|
|
18
|
+
# decides), and what each does with the write's answer — the formatter's
|
|
19
|
+
# fall-back folds it into the delivery line its budget is already spent
|
|
20
|
+
# on, the reporter's keyless branch names the configured path in its own
|
|
21
|
+
# line. The write itself is shared.
|
|
22
|
+
module SinkWriter
|
|
23
|
+
module_function
|
|
24
|
+
|
|
25
|
+
# Appends one line to `path`. Opened in append mode and written with a
|
|
26
|
+
# single call so that two suites sharing an output path (parallel CI
|
|
27
|
+
# shards, say) interleave whole runs rather than halves of one.
|
|
28
|
+
#
|
|
29
|
+
# `path` is passed in rather than read here, so the line a client's
|
|
30
|
+
# fall-back composes and the file it describes are provably the same
|
|
31
|
+
# string — a second read of a process-wide singleton could answer
|
|
32
|
+
# differently and name a path nothing was written to.
|
|
33
|
+
#
|
|
34
|
+
# Returns the exception the write died of, or `nil` when it landed,
|
|
35
|
+
# rather than warning itself or raising — the clients need the outcome
|
|
36
|
+
# *in* their own sentence, and a raise here could not be folded into
|
|
37
|
+
# one: it would fall through to a client's generic handler and spend
|
|
38
|
+
# the run's one warning budget on a sentence this module's answer was
|
|
39
|
+
# meant to replace (SPGD-1413). `Interrupt` stays deliberately outside
|
|
40
|
+
# the clause, as everywhere else in these files: Ctrl-C must stay
|
|
41
|
+
# Ctrl-C.
|
|
42
|
+
def append(data, path)
|
|
43
|
+
directory = File.dirname(path)
|
|
44
|
+
FileUtils.mkdir_p(directory) unless directory == "." || File.directory?(directory)
|
|
45
|
+
|
|
46
|
+
File.open(path, "a") { |file| file.write("#{JSON.generate(data)}\n") }
|
|
47
|
+
nil
|
|
48
|
+
rescue ScriptError, StandardError => e
|
|
49
|
+
e
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "json"
|
|
4
|
-
require "fileutils"
|
|
5
|
-
|
|
6
3
|
# Configuration and Transport are the framework-free halves of the client
|
|
7
4
|
# (env resolution, wire delivery, the never-raise contract), under
|
|
8
5
|
# `SpecGuard::Client`. Required here rather than assumed because nothing else
|
|
@@ -10,6 +7,7 @@ require "fileutils"
|
|
|
10
7
|
require_relative "../client"
|
|
11
8
|
require_relative "../client/configuration"
|
|
12
9
|
require_relative "../client/delivery_warning"
|
|
10
|
+
require_relative "../client/sink_writer"
|
|
13
11
|
|
|
14
12
|
# The annotation lookup is the third framework-free half: what counts as a
|
|
15
13
|
# test's annotation is a property of the source line, not of the framework
|
|
@@ -21,6 +19,8 @@ require_relative "../client/delivery_warning"
|
|
|
21
19
|
# `specguard/client` does not require `rspec/core`, so a minitest-only machine
|
|
22
20
|
# stays loadable.
|
|
23
21
|
require_relative "../client/annotation_lookup"
|
|
22
|
+
require_relative "../client/path_root"
|
|
23
|
+
require_relative "../client/root_binding"
|
|
24
24
|
|
|
25
25
|
# The Minitest half of `specguard-ruby`. Everything the RSpec formatter knows
|
|
26
26
|
# about the platform — the envelope's field names, the transport's
|
|
@@ -60,23 +60,7 @@ module SpecGuard
|
|
|
60
60
|
# whose file cannot be named fits no by-file aggregate on the platform
|
|
61
61
|
# and would surface as noise. The RSpec formatter's `capture` makes the
|
|
62
62
|
# equivalent call about a metadata-less example.
|
|
63
|
-
|
|
64
|
-
# `Dir.pwd` bound once — by the first `Reporter.new` (whose
|
|
65
|
-
# `#initialize` reads it, SPGD-1421) or the first direct read — never
|
|
66
|
-
# per row: a reporter constructed inside a test that changes the
|
|
67
|
-
# working directory would otherwise relativize one suite's rows
|
|
68
|
-
# against two different roots. The memo is what binds it — an
|
|
69
|
-
# unmemoized `Dir.pwd` here re-reads the cwd on every row and is
|
|
70
|
-
# exactly the two-root split this comment names, with both spellings
|
|
71
|
-
# individually well-formed so nothing downstream can detect the
|
|
72
|
-
# drift. The memo is also the ONE value the annotation lookup reads
|
|
73
|
-
# against: `#initialize` hands it over, so the relativization root
|
|
74
|
-
# and the lookup's read root cannot drift apart the way they did when
|
|
75
|
-
# each bound `Dir.pwd` at its own moment.
|
|
76
|
-
def repo_root
|
|
77
|
-
@repo_root ||= Dir.pwd
|
|
78
|
-
end
|
|
79
|
-
end
|
|
63
|
+
extend SpecGuard::Client::RootBinding
|
|
80
64
|
|
|
81
65
|
def initialize(configuration: SpecGuard.configuration,
|
|
82
66
|
transport: nil, output: $stderr,
|
|
@@ -108,6 +92,8 @@ module SpecGuard
|
|
|
108
92
|
# binds one root, hands it to the default lookup, and pins rspec-core's
|
|
109
93
|
# lazily memoized relativization regex to the same moment.)
|
|
110
94
|
root = self.class.repo_root
|
|
95
|
+
# Probed at the same moment, once, never mid-run (SPGD-2109).
|
|
96
|
+
self.class.path_root
|
|
111
97
|
@annotations = annotations || SpecGuard::Client::AnnotationLookup.new(root: root)
|
|
112
98
|
@clock = clock
|
|
113
99
|
@rows = []
|
|
@@ -264,10 +250,15 @@ module SpecGuard
|
|
|
264
250
|
# the RSpec formatter makes about a metadata-less example.
|
|
265
251
|
return nil if file.to_s.strip.empty? || line.to_i.zero?
|
|
266
252
|
|
|
253
|
+
# `read_file` is the cwd-relative spelling the annotation lookup
|
|
254
|
+
# resolves against the read root; `file` is what ships, relative to
|
|
255
|
+
# the path root (SPGD-2109). Equal unless the run started below the
|
|
256
|
+
# git toplevel.
|
|
257
|
+
read_file = read_relative_path(file)
|
|
267
258
|
file = relative_path(file)
|
|
268
259
|
name = "#{result.klass}##{result.name}"
|
|
269
260
|
line_number = line&.to_i
|
|
270
|
-
intent = annotation_for(
|
|
261
|
+
intent = annotation_for(read_file, line_number)
|
|
271
262
|
{
|
|
272
263
|
# Minitest has no RSpec-style rerun path or nested ids, so the
|
|
273
264
|
# definition site is the row's id — the run-local primary key for
|
|
@@ -328,7 +319,20 @@ module SpecGuard
|
|
|
328
319
|
"passed"
|
|
329
320
|
end
|
|
330
321
|
|
|
322
|
+
# Relative to the path root (the git toplevel; the working directory
|
|
323
|
+
# outside a repository) — the identity a platform aggregate groups by.
|
|
331
324
|
def relative_path(path)
|
|
325
|
+
root = self.class.path_root
|
|
326
|
+
prefix = self.class.path_prefix
|
|
327
|
+
return SpecGuard::Client::PathRoot.rebase(path, root: root, prefix: prefix) unless prefix.empty?
|
|
328
|
+
return path unless path.start_with?("#{root}/")
|
|
329
|
+
|
|
330
|
+
path.delete_prefix("#{root}/")
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
# The cwd-relative spelling: what the annotation lookup reads against
|
|
334
|
+
# the read root.
|
|
335
|
+
def read_relative_path(path)
|
|
332
336
|
root = self.class.repo_root
|
|
333
337
|
return path unless path.start_with?("#{root}/")
|
|
334
338
|
|
|
@@ -344,21 +348,20 @@ module SpecGuard
|
|
|
344
348
|
# One JSON run per line, to whichever file this delivery's outcome
|
|
345
349
|
# warrants (see `#deliver` for which and why).
|
|
346
350
|
#
|
|
347
|
-
#
|
|
348
|
-
#
|
|
349
|
-
#
|
|
351
|
+
# A one-line delegation to {SpecGuard::Client::SinkWriter.append}, the
|
|
352
|
+
# write both clients share (this reporter carried a hand-copy of it, and
|
|
353
|
+
# the RSpec formatter the second, until SPGD-2124). It returns the
|
|
354
|
+
# exception the write died of, or `nil` when it landed, rather than
|
|
355
|
+
# warning itself. Both call sites need the outcome *in* their own
|
|
356
|
+
# sentence — the keyless branch has no preceding line and says so
|
|
350
357
|
# directly, the fall-back folds it into the delivery line it is already
|
|
351
358
|
# spending the run's one warning on — and a warning here would reach
|
|
352
359
|
# `warn_once` first on the fall-back path and spend that budget on the
|
|
353
360
|
# generic write message, losing the HTTP status the operator needs
|
|
354
|
-
# (SPGD-1413). `Interrupt` stays outside the clause, as
|
|
355
|
-
# in this class.
|
|
361
|
+
# (SPGD-1413). `Interrupt` stays outside the writer's clause, as
|
|
362
|
+
# everywhere else in this class.
|
|
356
363
|
def append(data, path)
|
|
357
|
-
|
|
358
|
-
File.open(path, "a") { |f| f.puts(JSON.generate(data)) }
|
|
359
|
-
nil
|
|
360
|
-
rescue ScriptError, StandardError => e
|
|
361
|
-
e
|
|
364
|
+
SpecGuard::Client::SinkWriter.append(data, path)
|
|
362
365
|
end
|
|
363
366
|
|
|
364
367
|
# The keyless branch's write, and its own warning. Nothing preceded it on
|
|
@@ -37,8 +37,6 @@
|
|
|
37
37
|
# directions.
|
|
38
38
|
require "rspec/core"
|
|
39
39
|
require "rspec/core/formatters/base_formatter"
|
|
40
|
-
require "json"
|
|
41
|
-
require "fileutils"
|
|
42
40
|
|
|
43
41
|
# `specguard/rspec` is what defines `SpecGuard::RSpec` — the namespace whose
|
|
44
42
|
# existence is the shadowing hazard documented below, and the home of the
|
|
@@ -49,6 +47,9 @@ require_relative "../rspec"
|
|
|
49
47
|
require_relative "../client/configuration"
|
|
50
48
|
require_relative "../client/transport"
|
|
51
49
|
require_relative "../client/delivery_warning"
|
|
50
|
+
require_relative "../client/sink_writer"
|
|
51
|
+
require_relative "../client/path_root"
|
|
52
|
+
require_relative "../client/root_binding"
|
|
52
53
|
# Brings the linter's discovery chain with it (Scanner, Finding, Schema). That
|
|
53
54
|
# direction is safe — `specguard/rspec` does not require `rspec/core`, so the
|
|
54
55
|
# linter stays loadable without RSpec; it is only the reverse that would break
|
|
@@ -273,23 +274,7 @@ module SpecGuard
|
|
|
273
274
|
example_started example_passed example_failed example_pending dump_summary
|
|
274
275
|
].freeze
|
|
275
276
|
|
|
276
|
-
|
|
277
|
-
# `Dir.pwd` bound once — by the first formatter construction (whose
|
|
278
|
-
# `#initialize` reads it, SPGD-1429) or the first direct read — never
|
|
279
|
-
# per row: a suite that changes the working directory after the
|
|
280
|
-
# formatter was built would otherwise relativize one run's rows
|
|
281
|
-
# against two different roots. The memo is what binds it — an
|
|
282
|
-
# unmemoized `Dir.pwd` here re-reads the cwd on every read and is
|
|
283
|
-
# exactly the two-root split the constructor's comment names, with
|
|
284
|
-
# both spellings individually well-formed so nothing downstream can
|
|
285
|
-
# detect the drift. The memo is also the ONE value the default
|
|
286
|
-
# annotation lookup reads against: `#initialize` hands it over, so
|
|
287
|
-
# the relativization root and the lookup's read root cannot drift
|
|
288
|
-
# apart the way they did when each bound `Dir.pwd` at its own moment.
|
|
289
|
-
def repo_root
|
|
290
|
-
@repo_root ||= Dir.pwd
|
|
291
|
-
end
|
|
292
|
-
end
|
|
277
|
+
extend SpecGuard::Client::RootBinding
|
|
293
278
|
|
|
294
279
|
# @param output [IO] the stream RSpec hands every formatter. This class's
|
|
295
280
|
# product is a file, so nothing in the capture path writes here — but the
|
|
@@ -354,6 +339,9 @@ module SpecGuard
|
|
|
354
339
|
# is left alone: its memoization is correct for what it does, and
|
|
355
340
|
# overwriting a bound value would second-guess it.
|
|
356
341
|
root = self.class.repo_root
|
|
342
|
+
# Probed here too, at the same moment, so the git call happens once at
|
|
343
|
+
# construction and never mid-run (SPGD-2109).
|
|
344
|
+
self.class.path_root
|
|
357
345
|
::RSpec::Core::Metadata.relative_path_regex
|
|
358
346
|
@error_stream = error_stream
|
|
359
347
|
@annotations = annotations || SpecGuard::Client::AnnotationLookup.new(root: root)
|
|
@@ -753,12 +741,14 @@ module SpecGuard
|
|
|
753
741
|
# Called from inside {#never_fail_the_run}, so a raise below it cannot
|
|
754
742
|
# fail the run — but neither arm leaves its failure to that generic
|
|
755
743
|
# envelope, because each spends the run's one warning on a line that has
|
|
756
|
-
# to say what actually happened. {#append}
|
|
757
|
-
#
|
|
758
|
-
#
|
|
759
|
-
#
|
|
760
|
-
#
|
|
761
|
-
#
|
|
744
|
+
# to say what actually happened. {#append} hands the sink's outcome back
|
|
745
|
+
# as a value — the write and its rescue live in {Client::SinkWriter},
|
|
746
|
+
# shared with the Minitest reporter (SPGD-2124) — so the one line
|
|
747
|
+
# {#fall_back} is spending can report whether the queue took the run
|
|
748
|
+
# rather than promise it (SPGD-1413); the keyless {#append_local} does
|
|
749
|
+
# the same and names the configured sink path in the line it emits, the
|
|
750
|
+
# way the Minitest twin does (SPGD-1400). Nothing raises out of either
|
|
751
|
+
# way.
|
|
762
752
|
#
|
|
763
753
|
# == Why a failure writes the file rather than shrugging
|
|
764
754
|
#
|
|
@@ -877,7 +867,7 @@ module SpecGuard
|
|
|
877
867
|
# whose accessors are `commit_sha`, `branch`, `run_id`, `shard_id`,
|
|
878
868
|
# `output_path`, `endpoint`, `api_key` and `timeout`, and which has no
|
|
879
869
|
# `dry_run?`. Note that four methods here — {#payload}, {#deliver},
|
|
880
|
-
# {#
|
|
870
|
+
# {#fall_back} and {#append_local} — legitimately call
|
|
881
871
|
# `SpecGuard::RSpec.configuration` for this gem's own settings, so both
|
|
882
872
|
# spellings appear in this file and mean different things.
|
|
883
873
|
#
|
|
@@ -1112,6 +1102,11 @@ module SpecGuard
|
|
|
1112
1102
|
def capture(example)
|
|
1113
1103
|
metadata = example.metadata || {}
|
|
1114
1104
|
result = example.execution_result
|
|
1105
|
+
# `read_path` is rspec-core's cwd-relative spelling — what the
|
|
1106
|
+
# annotation lookup resolves against the read root. `file_path` is the
|
|
1107
|
+
# same file as shipped: relative to the path root (SPGD-2109). They are
|
|
1108
|
+
# equal unless the run started below the git toplevel.
|
|
1109
|
+
read_path = read_relative_path(metadata[:file_path])
|
|
1115
1110
|
file_path = relative_path(metadata[:file_path])
|
|
1116
1111
|
line_number = metadata[:line_number]
|
|
1117
1112
|
|
|
@@ -1121,7 +1116,7 @@ module SpecGuard
|
|
|
1121
1116
|
# the intent of the examples in it and not the examples themselves. It
|
|
1122
1117
|
# also routes through {#warn_once}, so the operator hears about it exactly
|
|
1123
1118
|
# once however many examples are affected.
|
|
1124
|
-
intent = never_fail_the_run { @annotations.intent_for(file:
|
|
1119
|
+
intent = never_fail_the_run { @annotations.intent_for(file: read_path, line: line_number) }
|
|
1125
1120
|
|
|
1126
1121
|
{
|
|
1127
1122
|
# Not wrapped in `never_fail_the_run`, unlike the annotation lookup
|
|
@@ -1129,7 +1124,7 @@ module SpecGuard
|
|
|
1129
1124
|
# memoized string interpolation over a Hash RSpec has already built, and
|
|
1130
1125
|
# a guard here could only ever add a way to emit an identity-less row
|
|
1131
1126
|
# silently. The outer guard at `#example_finished` still covers it.
|
|
1132
|
-
"id" => example
|
|
1127
|
+
"id" => shipped_id(example, metadata),
|
|
1133
1128
|
# `|| file_path` rather than a bare read: RSpec defaults
|
|
1134
1129
|
# `:rerun_file_path` for every example it builds, so the fallback is
|
|
1135
1130
|
# unreachable in a real run — but if a producer ever hands us metadata
|
|
@@ -1159,7 +1154,19 @@ module SpecGuard
|
|
|
1159
1154
|
# definition of "relative to the project root" rather than inventing a
|
|
1160
1155
|
# second one, then drop the `./` so the value matches what a linter, a
|
|
1161
1156
|
# `git diff --name-only` and the platform all use as a file's identity.
|
|
1157
|
+
#
|
|
1158
|
+
# When the run started below the git toplevel (a monorepo package),
|
|
1159
|
+
# "relative to the project root" means the toplevel, not the cwd: the cwd
|
|
1160
|
+
# spelling is re-expressed against it (SPGD-2109).
|
|
1162
1161
|
def relative_path(path)
|
|
1162
|
+
read = read_relative_path(path)
|
|
1163
|
+
return read if read.nil?
|
|
1164
|
+
|
|
1165
|
+
SpecGuard::Client::PathRoot.rebase(read, root: self.class.path_root, prefix: self.class.path_prefix)
|
|
1166
|
+
end
|
|
1167
|
+
|
|
1168
|
+
# rspec-core's own cwd-relative spelling, `./` dropped.
|
|
1169
|
+
def read_relative_path(path)
|
|
1163
1170
|
return nil if path.nil?
|
|
1164
1171
|
|
|
1165
1172
|
string = path.to_s
|
|
@@ -1168,26 +1175,29 @@ module SpecGuard
|
|
|
1168
1175
|
(::RSpec::Core::Metadata.relative_path(string) || string).sub(%r{\A\./}, "")
|
|
1169
1176
|
end
|
|
1170
1177
|
|
|
1171
|
-
#
|
|
1172
|
-
#
|
|
1173
|
-
#
|
|
1174
|
-
#
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
#
|
|
1178
|
+
# RSpec's example id is `"#{rerun_file_path}[#{scoped_id}]"`, with the
|
|
1179
|
+
# rerun path cwd-relative. Below the git toplevel the path half is rebased
|
|
1180
|
+
# onto the path root like every other shipped path; at the toplevel (or
|
|
1181
|
+
# outside a repository) the id is RSpec's own, untouched.
|
|
1182
|
+
def shipped_id(example, metadata)
|
|
1183
|
+
id = example.id
|
|
1184
|
+
return id if self.class.path_prefix.empty?
|
|
1185
|
+
|
|
1186
|
+
rerun = metadata[:rerun_file_path].to_s
|
|
1187
|
+
return id if rerun.empty? || !id.to_s.start_with?(rerun)
|
|
1188
|
+
|
|
1189
|
+
"#{relative_path(rerun)}#{id[rerun.length..]}"
|
|
1190
|
+
end
|
|
1191
|
+
|
|
1192
|
+
# Appends one line to the replay queue — a one-line delegation to
|
|
1193
|
+
# {Client::SinkWriter.append}, the write both clients share (the
|
|
1194
|
+
# formatter carried a hand-copy of it until SPGD-2124, and the Minitest
|
|
1195
|
+
# reporter carried the second one). The return contract — the exception
|
|
1196
|
+
# as a value, `nil` on success, `Interrupt` outside the clause — lives on
|
|
1197
|
+
# the module now; what stays here is what this client does with the
|
|
1198
|
+
# answer, folding it into the fall-back's one line (see {#fall_back}).
|
|
1186
1199
|
def append(data, path)
|
|
1187
|
-
|
|
1188
|
-
nil
|
|
1189
|
-
rescue ScriptError, StandardError => e
|
|
1190
|
-
e
|
|
1200
|
+
Client::SinkWriter.append(data, path)
|
|
1191
1201
|
end
|
|
1192
1202
|
|
|
1193
1203
|
# The keyless branch's sink: `local_output_path`, a local development
|
|
@@ -1196,14 +1206,14 @@ module SpecGuard
|
|
|
1196
1206
|
# failed deliveries. See {Configuration#local_output_path}.
|
|
1197
1207
|
#
|
|
1198
1208
|
# Its failure is its own line rather than {#never_fail_the_run}'s generic
|
|
1199
|
-
# substitute: the path is knowable here — read once into a local,
|
|
1200
|
-
#
|
|
1201
|
-
# same input (SPGD-1400), as does this file's delivery arm
|
|
1202
|
-
# {#sink_clause} (SPGD-1413). The write goes through {#append} so
|
|
1203
|
-
# exception comes back as a value to compose the line from; left to
|
|
1204
|
-
# it would fall through to {#never_fail_the_run} and spend the
|
|
1205
|
-
# warning on the one sentence this exists to replace.
|
|
1206
|
-
# outside, as everywhere else in this file.
|
|
1209
|
+
# substitute: the path is knowable here — read once into a local, so the
|
|
1210
|
+
# line names exactly the file the write attempted — and the Minitest twin
|
|
1211
|
+
# names it on the same input (SPGD-1400), as does this file's delivery arm
|
|
1212
|
+
# through {#sink_clause} (SPGD-1413). The write goes through {#append} so
|
|
1213
|
+
# the exception comes back as a value to compose the line from; left to
|
|
1214
|
+
# raise, it would fall through to {#never_fail_the_run} and spend the
|
|
1215
|
+
# run's one warning on the one sentence this exists to replace.
|
|
1216
|
+
# `Interrupt` stays outside, as everywhere else in this file.
|
|
1207
1217
|
def append_local(data)
|
|
1208
1218
|
path = SpecGuard::RSpec.configuration.local_output_path
|
|
1209
1219
|
error = append(data, path)
|
|
@@ -1213,13 +1223,6 @@ module SpecGuard
|
|
|
1213
1223
|
"(#{error.class}: #{error.message}). The test run is unaffected.")
|
|
1214
1224
|
end
|
|
1215
1225
|
|
|
1216
|
-
def append_to(data, path)
|
|
1217
|
-
directory = File.dirname(path)
|
|
1218
|
-
FileUtils.mkdir_p(directory) unless directory == "." || File.directory?(directory)
|
|
1219
|
-
|
|
1220
|
-
File.open(path, "a") { |file| file.write("#{JSON.generate(data)}\n") }
|
|
1221
|
-
end
|
|
1222
|
-
|
|
1223
1226
|
# `Errno::*` and `IOError` — the sink's failure modes — are both
|
|
1224
1227
|
# `StandardError` descendants, so they need no separate clause; they are
|
|
1225
1228
|
# named in the ticket because they are the *reason* this rescue is here, not
|
data/lib/specguard/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: specguard-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.36
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- specguard Agent
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|
|
@@ -59,9 +59,12 @@ files:
|
|
|
59
59
|
- lib/specguard/client/ingest_reporter.rb
|
|
60
60
|
- lib/specguard/client/json_reporter.rb
|
|
61
61
|
- lib/specguard/client/linter.rb
|
|
62
|
+
- lib/specguard/client/path_root.rb
|
|
62
63
|
- lib/specguard/client/payload_normalizer.rb
|
|
64
|
+
- lib/specguard/client/root_binding.rb
|
|
63
65
|
- lib/specguard/client/scanner.rb
|
|
64
66
|
- lib/specguard/client/schemas/open-test-intent.v1.json
|
|
67
|
+
- lib/specguard/client/sink_writer.rb
|
|
65
68
|
- lib/specguard/client/transport.rb
|
|
66
69
|
- lib/specguard/client/validator_backend.rb
|
|
67
70
|
- lib/specguard/minitest/reporter.rb
|