specguard-ruby 0.3.3 → 0.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d91e0fec640df334c1ee281f06852adb53172514aa6bc357346d0ba76c725fe
4
- data.tar.gz: c2f3974d36260c4cdf33296e85f3a44879be617122ce3291a17538d2d7e4e68f
3
+ metadata.gz: 43e3d2ff78fc5e1750d77197ff2ef15c9815040147c4e52c51dd71855261b5c1
4
+ data.tar.gz: e55c3f9bdcaa0a21f60fb8654ee8848a55c06b6ceb282ac523390dfbec07f12d
5
5
  SHA512:
6
- metadata.gz: '019c9e92094afec846e8184c39ce185c47eb564b6cd4b6ec9ed2198e1876865b02efd8b198ac2d161629840a8b188991fc4fd347265bc47b5a67b513d4498a60'
7
- data.tar.gz: 411ea2d03fa8be62ec65f54a1341cd6ca8926dfdf481618b86d4551c111d84312efcc3d9dacfabe015bf9dee254a956e468137f6a4bef6468635302d673e4266
6
+ metadata.gz: e5603b3d5deaa9e5a8119c469a8a142f4bb9527b231866e4a3c57d7face3319fb70ece91d19c81f8cb9094d48363d887ab81175e2c9897148f730c8ac72ef4b5
7
+ data.tar.gz: e5a67e10d778c961e4cb8edf743db91861cbf350e15ff305370ad42d102e4d28aaf25c591617c47c73d090a77d18b3faf6cb529dd8570f18245e38402168e123
data/README.md CHANGED
@@ -43,8 +43,9 @@ bundle exec ruby -rminitest/specguard_plugin -e 'Minitest.extensions << "specgua
43
43
  ## The linter — `specguard-lint`
44
44
 
45
45
  Validates `# @intent:` annotations in changed (or all) `*_spec.rb` files against the OpenTestIntent
46
- JSON Schema. Exits `1` on a malformed annotation; **never** fails on a *missing* one (adoption is
47
- opt-in and gradual).
46
+ JSON Schema. Exits `1` on a malformed annotation or a well-formed but unreachable one (stacked
47
+ above another comment-form `@intent:` line, so the one-line lookback never claims it) — and
48
+ **never** fails on a *missing* one (adoption is opt-in and gradual).
48
49
 
49
50
  ```bash
50
51
  bundle exec specguard-lint --changed # CI mode: only files in the current diff
@@ -278,7 +279,9 @@ the `read` kind. The binary's own UTF-8 refusal prose (`input is not well-formed
278
279
 
279
280
  Every way the backend can fail — the binary is missing, will not execute, exits with something that
280
281
  is not a verdict, or emits output that is not a report — is **exit 2**, the linter's "could not do
281
- my job" code. It never becomes exit 1, which means "an annotation is malformed" and nothing else.
282
+ my job" code. It never becomes exit 1, which means "an annotation is malformed" or well-formed
283
+ but unreachable: stacked above another comment-form `@intent:` line, so the one-line lookback
284
+ never claims it — and nothing else.
282
285
 
283
286
  ## The formatter — `SpecGuard::RSpecFormatter`
284
287
 
@@ -9,7 +9,7 @@ module SpecGuard
9
9
  # == The contract, and the reason it needs defending
10
10
  #
11
11
  # 0 every annotation checked is valid (including "there were none")
12
- # 1 at least one annotation is malformed
12
+ # 1 at least one annotation is malformed or unreachable
13
13
  # 2 the linter could not do its job — misuse, or the tool itself broken
14
14
  #
15
15
  # Ruby does not give you this for free; it actively works against it.
@@ -102,9 +102,11 @@ module SpecGuard
102
102
  # Every annotation checked was valid — or there were none to check.
103
103
  # "Lint, don't require": a missing annotation is never an error.
104
104
  EXIT_OK = 0
105
- # One or more annotations are malformed. The only code produced by
106
- # inspecting content, and the only path that reaches it is a failed
107
- # {Linter::Result}.
105
+ # One or more annotations are malformed or well-formed but
106
+ # unreachable (SPGD-900: stacked above another comment-form `@intent:`
107
+ # line, so the one-line lookback never claims it, a dead contract that
108
+ # is still a failure). The only code produced by inspecting content,
109
+ # and the only path that reaches it is a failed {Linter::Result}.
108
110
  EXIT_MALFORMED = 1
109
111
  # The linter could not do its job: bad flags, `--changed` outside a git
110
112
  # repository, a validator that could not be resolved, or an unexpected
@@ -140,6 +142,14 @@ module SpecGuard
140
142
 
141
143
  results = backend.check(selection.files)
142
144
 
145
+ # The structural pass (SPGD-900): annotations that are valid in
146
+ # isolation but can never be extracted — stacked consecutive
147
+ # comment-form `@intent:` lines, where the one-line lookback
148
+ # (SPGD-12 §2) claims only the line just above the example. These are
149
+ # Linter::Results like any other, so both renderers and the exit code
150
+ # pick them up with no second path to keep in step.
151
+ results += unreachable_results(selection.files)
152
+
143
153
  # Computed once, here, and handed to whichever renderer runs. `--json`
144
154
  # is a second renderer over this list, not a second code path: the exit
145
155
  # code below is the same expression it always was, and the document's
@@ -162,6 +172,19 @@ module SpecGuard
162
172
 
163
173
  private
164
174
 
175
+ # {Scanner}'s structural findings are annotations, not file problems:
176
+ # each carries a real `file:line`, so they become failing line-scoped
177
+ # {Linter::Result}s exactly like a malformed payload would. A file the
178
+ # backend could not read contributes nothing here — the backend's own
179
+ # KIND_READ result already reports it, and this pass cannot be positional
180
+ # about a file it never saw.
181
+ def unreachable_results(paths)
182
+ Scanner.unreachable_findings(paths).map do |finding|
183
+ Linter::Result.new(file: finding.file, line: finding.line,
184
+ kind: finding.kind, problem: finding.problem)
185
+ end
186
+ end
187
+
165
188
  # One line per run naming the implementation that produced the verdicts.
166
189
  # Since the SPGD-867 cutover there is exactly one implementation — the
167
190
  # resolved `validate-intent` binary — and the line says which one,
@@ -48,6 +48,17 @@ module SpecGuard
48
48
  # of ways an annotation can fail is written down in one place.
49
49
  KIND_SCHEMA = :schema
50
50
 
51
+ # The annotation is well-formed in isolation but can never be EXTRACTED:
52
+ # it is a comment-form `@intent:` on a line whose next line is also a
53
+ # comment-form `@intent:`, so the one-line lookback (SPGD-12 §2 —
54
+ # {AnnotationLookup} claims only the comment on the line immediately
55
+ # above an example) always skips it in favour of the lower line. The
56
+ # contract is dead metadata: counted by the linter, discarded by
57
+ # extraction. Produced by {Scanner}'s structural pass, not by
58
+ # {AnnotationScanner} — each annotation is scanned in isolation there,
59
+ # which is exactly why this defect is invisible to it.
60
+ KIND_UNREACHABLE = :unreachable
61
+
51
62
  def initialize(file:, line:, intent: nil, problem: nil, kind: nil)
52
63
  super
53
64
  end
@@ -19,7 +19,8 @@ module SpecGuard
19
19
  #
20
20
  # == What counts as a failure
21
21
  #
22
- # Three things reach the same verdict from different directions:
22
+ # Three things make an annotation malformed, reaching the same verdict
23
+ # from different directions:
23
24
  #
24
25
  # * the payload could not be captured off the line at all
25
26
  # (`Finding::KIND_EXTRACTION`) — a typo'd annotation;
@@ -35,6 +36,14 @@ module SpecGuard
35
36
  # valid UTF-8 — is also reported as a failure, and therefore also exits 1.
36
37
  # That matches `validate-intent`, which classifies it separately (its own
37
38
  # `read` kind) and still reports it as `FAIL` with exit 1.
39
+ #
40
+ # `Finding::KIND_UNREACHABLE` — an annotation that is well-formed in
41
+ # isolation but stacked above another comment-form `@intent:` line, so
42
+ # the one-line lookback (SPGD-12 §2) never claims it — is also reported
43
+ # as a failure, and therefore also exits 1. Nothing about it is
44
+ # malformed; the contract is dead metadata, counted by the linter and
45
+ # discarded by extraction, and the structural pass that flags it
46
+ # (SPGD-900) reports it loudly rather than letting it pass as clean.
38
47
  module Linter
39
48
  # One annotation's verdict. `problem` is set when discovery could not
40
49
  # produce an intent at all; `reasons` when the schema rejected one.
@@ -230,6 +230,107 @@ module SpecGuard
230
230
  Finding.new(file: file, line: line, kind: Finding::KIND_PARSE,
231
231
  problem: "could not parse annotation: #{e.message}")
232
232
  end
233
+
234
+ # == The structural pass: annotations the extraction can never claim
235
+ #
236
+ # Everything above validates each annotation IN ISOLATION — one payload,
237
+ # one verdict. But the formatter's extraction contract
238
+ # ({AnnotationLookup}, SPGD-12 §2) is positional: only the comment-form
239
+ # annotation on the line IMMEDIATELY ABOVE an example is inheritable.
240
+ # So when two consecutive comment-form `@intent:` lines sit above one
241
+ # `it`, the UPPER line is unreachable — silently discarded by the
242
+ # one-line lookback — while this pipeline counts it as a valid
243
+ # annotation and the run exits 0. Measured (SPGD-897 audit): 16 such
244
+ # stacked pairs shipped through `specguard-lint` exit 0, every upper
245
+ # contract dead. Reported loudly, not skipped — the same stance
246
+ # {AnnotationScanner} takes for NO_PAYLOAD.
247
+ #
248
+ # A comment-form annotation line is a comment-only line
249
+ # ({AnnotationLookup::COMMENT_LINE}) carrying the `@intent:` token. The
250
+ # trailing same-line form never matches COMMENT_LINE, so it is never
251
+ # flagged and never makes a neighbour unreachable — its annotation
252
+ # belongs to its own example's line and the lookback is not involved.
253
+ #
254
+ # @param paths [Enumerable<String>]
255
+ # @return [Array<Finding>] one per unreachable comment-form annotation,
256
+ # in file-then-line order. A file that cannot be read contributes
257
+ # nothing here — {ValidatorBackend} already reports read failures, and
258
+ # this pass has nothing positional to say about a file it never saw.
259
+ def unreachable_findings(paths)
260
+ paths.flat_map { |path| unreachable_findings_in_file(path) }
261
+ end
262
+
263
+ # @param path [String]
264
+ # @return [Array<Finding>]
265
+ def unreachable_findings_in_file(path)
266
+ begin
267
+ text = File.read(path, encoding: "UTF-8")
268
+ rescue SystemCallError, IOError
269
+ return []
270
+ end
271
+
272
+ unreachable_findings_in_text(text, file: path)
273
+ end
274
+
275
+ UNREACHABLE_ANNOTATION =
276
+ "unreachable annotation: the previous line is also a comment-form @intent:, " \
277
+ "so the one-line lookback claims only the line just above the example " \
278
+ "and this annotation is silently discarded at extraction (SPGD-12 §2)"
279
+
280
+ # A comment-only line carrying an `@intent:` token — the only form an
281
+ # example on the NEXT line may claim ({AnnotationLookup::COMMENT_LINE}).
282
+ COMMENT_INTENT_LINE = /\A\s*#.*@intent:/
283
+
284
+ # The line an annotation run may be claimed from: the first example
285
+ # keyword. The lookback rule is `example.metadata[:line_number] - 1`, so
286
+ # only the comment form on the line immediately above an example is
287
+ # inheritable — which makes an EXAMPLE the anchor of the whole rule.
288
+ #
289
+ # Anchoring on the example is what keeps this pass off annotation
290
+ # corpora with no examples at all (the recorded-binary fixtures in
291
+ # spec/fixtures/): there is no lookback there to silently discard
292
+ # anything, so there is nothing to report. The defect this pass exists
293
+ # for (SPGD-897) is stacked lines above a real example — an annotation
294
+ # the author believed was attached to the `it` under it.
295
+ EXAMPLE_LINE = /\A\s*(?:it|specify)\b/
296
+
297
+ # @param text [String] source of one file
298
+ # @param file [String] path to record on each Finding
299
+ # @return [Array<Finding>] one per comment-form `@intent:` line in a
300
+ # stacked run — a maximal run of consecutive comment-form `@intent:`
301
+ # lines immediately above an example — except the run's LAST line,
302
+ # which is the one the one-line lookback claims. For the canonical
303
+ # two-line stack above one `it`, that is the UPPER line.
304
+ def unreachable_findings_in_text(text, file:)
305
+ # A file that is not valid UTF-8 is reported once, loudly, by the
306
+ # backend as a read failure; nothing positional can be said about it,
307
+ # and `lines` below would raise on the invalid bytes.
308
+ return [] unless text.valid_encoding?
309
+
310
+ lines = text.lines
311
+ i = 0
312
+ findings = []
313
+
314
+ while i < lines.length
315
+ unless COMMENT_INTENT_LINE.match?(lines[i])
316
+ i += 1
317
+ next
318
+ end
319
+
320
+ run_start = i
321
+ i += 1 while i < lines.length && COMMENT_INTENT_LINE.match?(lines[i])
322
+ run_end = i # exclusive; lines[run_end] is the line after the run
323
+
324
+ if run_end < lines.length && EXAMPLE_LINE.match?(lines[run_end]) && run_start < run_end - 1
325
+ (run_start...(run_end - 1)).each do |j|
326
+ findings << Finding.new(file: file, line: j + 1, problem: UNREACHABLE_ANNOTATION,
327
+ kind: Finding::KIND_UNREACHABLE)
328
+ end
329
+ end
330
+ end
331
+
332
+ findings
333
+ end
233
334
  end
234
335
  end
235
336
  end
@@ -7,5 +7,5 @@
7
7
  # framework-scoped version constant a lie, so the number moved here and the
8
8
  # rspec module now points at it for back-compat.
9
9
  module SpecGuard
10
- VERSION = "0.3.3"
10
+ VERSION = "0.3.4"
11
11
  end
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.3
4
+ version: 0.3.4
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-08-29 00:00:00.000000000 Z
11
+ date: 2026-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json