deadgate 0.2.0__tar.gz → 0.3.0__tar.gz

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 (27) hide show
  1. {deadgate-0.2.0 → deadgate-0.3.0}/PKG-INFO +53 -20
  2. {deadgate-0.2.0 → deadgate-0.3.0}/README.md +52 -19
  3. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate/cli.py +10 -11
  4. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate/detectors.py +20 -179
  5. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate.egg-info/PKG-INFO +53 -20
  6. {deadgate-0.2.0 → deadgate-0.3.0}/pyproject.toml +1 -1
  7. {deadgate-0.2.0 → deadgate-0.3.0}/tests/test_api_status_gates.py +29 -35
  8. {deadgate-0.2.0 → deadgate-0.3.0}/tests/test_corpus.py +1 -81
  9. {deadgate-0.2.0 → deadgate-0.3.0}/tests/test_d1_requires_protection.py +4 -4
  10. {deadgate-0.2.0 → deadgate-0.3.0}/tests/test_d3_narrowing.py +9 -20
  11. {deadgate-0.2.0 → deadgate-0.3.0}/LICENSE +0 -0
  12. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate/__init__.py +0 -0
  13. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate/checknames.py +0 -0
  14. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate/predicates.py +0 -0
  15. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate/protection.py +0 -0
  16. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate/resolve.py +0 -0
  17. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate/sandbox.py +0 -0
  18. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate.egg-info/SOURCES.txt +0 -0
  19. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate.egg-info/dependency_links.txt +0 -0
  20. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate.egg-info/entry_points.txt +0 -0
  21. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate.egg-info/requires.txt +0 -0
  22. {deadgate-0.2.0 → deadgate-0.3.0}/deadgate.egg-info/top_level.txt +0 -0
  23. {deadgate-0.2.0 → deadgate-0.3.0}/setup.cfg +0 -0
  24. {deadgate-0.2.0 → deadgate-0.3.0}/tests/test_predicates.py +0 -0
  25. {deadgate-0.2.0 → deadgate-0.3.0}/tests/test_protection.py +0 -0
  26. {deadgate-0.2.0 → deadgate-0.3.0}/tests/test_sandbox.py +0 -0
  27. {deadgate-0.2.0 → deadgate-0.3.0}/tests/test_wildcard_gates.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deadgate
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Find CI checks that cannot fail: gates satisfied by skipped jobs, exit statuses swallowed by pipes, fan-ins that never read whether their upstream passed.
5
5
  Author-email: Erik Hill <contact@erikhill.dev>
6
6
  License: MIT
@@ -54,33 +54,53 @@ be parsed**. A file it could not read is never counted as a file with no problem
54
54
  | D3 | a `run:` step ends a pipeline in a filter with no `pipefail` | the step's status is the filter's, so an upstream failure passes |
55
55
 
56
56
  **Two detectors have been removed rather than tuned**, each on hand-labelled evidence
57
- that it was never right: D4 on 0 true of 18 sampled (0.1.5), and D2 on 0 true of 27
57
+ that it was never right: D4 on 0 true of 18 sampled, of which 8 false and **10 left
58
+ unresolved** (0.1.5), and D2 on 0 true of 27
58
59
  censused (0.1.6). The shapes they fired on are described in those sections, including
59
60
  the one real hazard that is now undetected by design.
60
61
 
62
+ ### There is no severity any more
63
+
64
+ Every D3 stratum was censused, and the tiers did not rank anything:
65
+
66
+ | tier | n | false |
67
+ |---|---|---|
68
+ | HIGH | 94 | 30.9% `[22.4, 40.8]` |
69
+ | LOW | 415 | 31.6% `[27.3, 36.2]` |
70
+ | MEDIUM | 153 | **55.6%** `[47.6, 63.2]` |
71
+
72
+ HIGH's interval overlaps the merged non-HIGH tier (38.0% `[34.1, 42.1]`), so the loudest
73
+ tier was not reliably better than everything else. LOW was indistinguishable from HIGH.
74
+ The one real separation was MEDIUM being **worse**, and that came from `_d3_severity`
75
+ short-circuiting on whether the workflow runs on `pull_request` before it looked at the
76
+ finding at all: the axis measured the trigger, not correctness.
77
+
78
+ A severity that hid the better findings behind `--all` and shouted the worse ones is worse
79
+ than none, so it is gone. `--all` is accepted and ignored. **D3 is 37.0% false overall**,
80
+ 245 of 662, and that is the number.
81
+
61
82
  ### Measured precision, so the table above is not the only claim
62
83
 
63
84
  Every figure below is hand-labelled. None is an estimate of an estimate.
64
85
 
65
- | detector | tier | basis | false |
66
- |---|---|---|---|
67
- | D3 | HIGH (94) | complete census | **30.9%** |
68
- | D3 | MEDIUM (144) | **complete census** | **54.9%** |
69
- | D3 | LOW (426) | uncapped sample, n=15 | **47%** `[25, 70]` |
70
- | D1 | **not reported without `--repo`** | see below | n/a |
71
-
72
- **What you see by default is about 45% false.** The CLI hides LOW without `--all`, so the
73
- default output is HIGH plus MEDIUM, 238 D3 findings, of which about 108 are wrong.
86
+ | detector | basis | false |
87
+ |---|---|---|
88
+ | D3, all 662 | **complete census of all three former strata** | **37.0%** |
89
+ | D1 | not reported without `--repo` | see below |
74
90
 
75
- MEDIUM is worse than HIGH, and both are now censused so that is exact. Whether MEDIUM is
76
- worse than LOW is still **not** established: LOW rests on n=15 and its interval `[25, 70]`
77
- contains MEDIUM's exact 54.9%. Settling it needs LOW measured properly, which has not been
78
- done.
91
+ **Everything is reported now.** Nothing is hidden, so what you see is the whole 37.0%.
92
+ Collapsing the tiers raised the default output from 247 findings to 653 and *lowered* the
93
+ false rate a reader experiences from 46.2% to 37.0%, because the hidden tier was the
94
+ better one.
79
95
 
80
- An uncapped n=30 sample put MEDIUM at 70%; the census says 54.9%. Off by 14 points, inside
81
- its own interval but near the edge, which is the cost of n=30 even with the cap removed.
96
+ Two samples along the way were notably off, and both were caught only by censusing the
97
+ thing they estimated. An uncapped n=30 sample put MEDIUM at 70%; the census says 55.6%, 14
98
+ points out and near the edge of its own interval. A n=15 sample put LOW at 47% `[25, 70]`;
99
+ the census says 31.6%. Small samples were the cost even after the per-repository cap was
100
+ removed.
82
101
 
83
- MEDIUM is not one population. Classified by shape, it splits sharply:
102
+ The former MEDIUM was not one population. Classified by shape, it split sharply, and the
103
+ same shapes explain the whole detector:
84
104
 
85
105
  | shape | n | false |
86
106
  |---|---|---|
@@ -411,7 +431,8 @@ said the branch protection that job provides is decorative.
411
431
  That is not a precision problem a narrowing fixes. The detector's own gate test disagreed
412
432
  with its own finding text, every single time.
413
433
 
414
- D4 was removed on 0 true of 18 **sampled**. D2 goes on 0 true of 27 **censused**.
434
+ D4 was removed on a sample of 18 that scored 0 true, 8 false and **10 arguable**. D2
435
+ goes on 0 true of 27 **censused**, with no arguable bucket at all.
415
436
 
416
437
  Total output across the corpus: **1054 to 1027.** HIGH is unchanged at 125, all D3.
417
438
 
@@ -424,6 +445,18 @@ Both comments now name the function that actually does the work.
424
445
 
425
446
  ## 0.1.5 removes D4
426
447
 
448
+ > **Correction.** This section originally read "0 defensible findings out of 18", and
449
+ > that overstates it. The sample was **0 defensible, 8 false and 10 ARGUABLE**: ten of the
450
+ > eighteen were never resolved. A later census of D3's HIGH stratum established that an
451
+ > arguable bucket is not a random sample of its population, running 66% false against 34%
452
+ > overall, enough to flip a verdict. The ten were probably mostly false; probably is not a
453
+ > measurement. The sample was also drawn from D4's HIGH stratum, and severity has since
454
+ > been measured to carry no quality signal, so that stratification means nothing either.
455
+ >
456
+ > **The removal still stands, on evidence that depends on neither:** 80% of D4's 932
457
+ > findings describe a mechanism redundant with GitHub's needs-skip rule, which is
458
+ > measured below and is severity-independent.
459
+
427
460
  **D4 is gone, not demoted.** It scored **0 defensible findings out of 18** in a
428
461
  pre-registered hand-labelled sample, and it was the largest detector by volume: **932
429
462
  findings over 93 repositories, 47% of everything this tool emitted.**
@@ -613,5 +646,5 @@ That gap is the lesson worth keeping. The tool was least accurate on the reposit
613
646
  BEST CI, which is the worst place for a linter to cry wolf, and no corpus average would have
614
647
  surfaced it. The suite passed unchanged through every one of the four, 149 of it through the
615
648
  first two fixes and 161 through the second two, so not one of them was covered by anything.
616
- There are 228 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
649
+ There are 212 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
617
650
  suite ever drift apart again.
@@ -26,33 +26,53 @@ be parsed**. A file it could not read is never counted as a file with no problem
26
26
  | D3 | a `run:` step ends a pipeline in a filter with no `pipefail` | the step's status is the filter's, so an upstream failure passes |
27
27
 
28
28
  **Two detectors have been removed rather than tuned**, each on hand-labelled evidence
29
- that it was never right: D4 on 0 true of 18 sampled (0.1.5), and D2 on 0 true of 27
29
+ that it was never right: D4 on 0 true of 18 sampled, of which 8 false and **10 left
30
+ unresolved** (0.1.5), and D2 on 0 true of 27
30
31
  censused (0.1.6). The shapes they fired on are described in those sections, including
31
32
  the one real hazard that is now undetected by design.
32
33
 
34
+ ### There is no severity any more
35
+
36
+ Every D3 stratum was censused, and the tiers did not rank anything:
37
+
38
+ | tier | n | false |
39
+ |---|---|---|
40
+ | HIGH | 94 | 30.9% `[22.4, 40.8]` |
41
+ | LOW | 415 | 31.6% `[27.3, 36.2]` |
42
+ | MEDIUM | 153 | **55.6%** `[47.6, 63.2]` |
43
+
44
+ HIGH's interval overlaps the merged non-HIGH tier (38.0% `[34.1, 42.1]`), so the loudest
45
+ tier was not reliably better than everything else. LOW was indistinguishable from HIGH.
46
+ The one real separation was MEDIUM being **worse**, and that came from `_d3_severity`
47
+ short-circuiting on whether the workflow runs on `pull_request` before it looked at the
48
+ finding at all: the axis measured the trigger, not correctness.
49
+
50
+ A severity that hid the better findings behind `--all` and shouted the worse ones is worse
51
+ than none, so it is gone. `--all` is accepted and ignored. **D3 is 37.0% false overall**,
52
+ 245 of 662, and that is the number.
53
+
33
54
  ### Measured precision, so the table above is not the only claim
34
55
 
35
56
  Every figure below is hand-labelled. None is an estimate of an estimate.
36
57
 
37
- | detector | tier | basis | false |
38
- |---|---|---|---|
39
- | D3 | HIGH (94) | complete census | **30.9%** |
40
- | D3 | MEDIUM (144) | **complete census** | **54.9%** |
41
- | D3 | LOW (426) | uncapped sample, n=15 | **47%** `[25, 70]` |
42
- | D1 | **not reported without `--repo`** | see below | n/a |
43
-
44
- **What you see by default is about 45% false.** The CLI hides LOW without `--all`, so the
45
- default output is HIGH plus MEDIUM, 238 D3 findings, of which about 108 are wrong.
58
+ | detector | basis | false |
59
+ |---|---|---|
60
+ | D3, all 662 | **complete census of all three former strata** | **37.0%** |
61
+ | D1 | not reported without `--repo` | see below |
46
62
 
47
- MEDIUM is worse than HIGH, and both are now censused so that is exact. Whether MEDIUM is
48
- worse than LOW is still **not** established: LOW rests on n=15 and its interval `[25, 70]`
49
- contains MEDIUM's exact 54.9%. Settling it needs LOW measured properly, which has not been
50
- done.
63
+ **Everything is reported now.** Nothing is hidden, so what you see is the whole 37.0%.
64
+ Collapsing the tiers raised the default output from 247 findings to 653 and *lowered* the
65
+ false rate a reader experiences from 46.2% to 37.0%, because the hidden tier was the
66
+ better one.
51
67
 
52
- An uncapped n=30 sample put MEDIUM at 70%; the census says 54.9%. Off by 14 points, inside
53
- its own interval but near the edge, which is the cost of n=30 even with the cap removed.
68
+ Two samples along the way were notably off, and both were caught only by censusing the
69
+ thing they estimated. An uncapped n=30 sample put MEDIUM at 70%; the census says 55.6%, 14
70
+ points out and near the edge of its own interval. A n=15 sample put LOW at 47% `[25, 70]`;
71
+ the census says 31.6%. Small samples were the cost even after the per-repository cap was
72
+ removed.
54
73
 
55
- MEDIUM is not one population. Classified by shape, it splits sharply:
74
+ The former MEDIUM was not one population. Classified by shape, it split sharply, and the
75
+ same shapes explain the whole detector:
56
76
 
57
77
  | shape | n | false |
58
78
  |---|---|---|
@@ -383,7 +403,8 @@ said the branch protection that job provides is decorative.
383
403
  That is not a precision problem a narrowing fixes. The detector's own gate test disagreed
384
404
  with its own finding text, every single time.
385
405
 
386
- D4 was removed on 0 true of 18 **sampled**. D2 goes on 0 true of 27 **censused**.
406
+ D4 was removed on a sample of 18 that scored 0 true, 8 false and **10 arguable**. D2
407
+ goes on 0 true of 27 **censused**, with no arguable bucket at all.
387
408
 
388
409
  Total output across the corpus: **1054 to 1027.** HIGH is unchanged at 125, all D3.
389
410
 
@@ -396,6 +417,18 @@ Both comments now name the function that actually does the work.
396
417
 
397
418
  ## 0.1.5 removes D4
398
419
 
420
+ > **Correction.** This section originally read "0 defensible findings out of 18", and
421
+ > that overstates it. The sample was **0 defensible, 8 false and 10 ARGUABLE**: ten of the
422
+ > eighteen were never resolved. A later census of D3's HIGH stratum established that an
423
+ > arguable bucket is not a random sample of its population, running 66% false against 34%
424
+ > overall, enough to flip a verdict. The ten were probably mostly false; probably is not a
425
+ > measurement. The sample was also drawn from D4's HIGH stratum, and severity has since
426
+ > been measured to carry no quality signal, so that stratification means nothing either.
427
+ >
428
+ > **The removal still stands, on evidence that depends on neither:** 80% of D4's 932
429
+ > findings describe a mechanism redundant with GitHub's needs-skip rule, which is
430
+ > measured below and is severity-independent.
431
+
399
432
  **D4 is gone, not demoted.** It scored **0 defensible findings out of 18** in a
400
433
  pre-registered hand-labelled sample, and it was the largest detector by volume: **932
401
434
  findings over 93 repositories, 47% of everything this tool emitted.**
@@ -585,5 +618,5 @@ That gap is the lesson worth keeping. The tool was least accurate on the reposit
585
618
  BEST CI, which is the worst place for a linter to cry wolf, and no corpus average would have
586
619
  surfaced it. The suite passed unchanged through every one of the four, 149 of it through the
587
620
  first two fixes and 161 through the second two, so not one of them was covered by anything.
588
- There are 228 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
621
+ There are 212 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
589
622
  suite ever drift apart again.
@@ -28,9 +28,11 @@ def main(argv: list[str] | None = None) -> int:
28
28
  "administer the required set is incomplete, so findings can only be "
29
29
  "escalated, never cleared.")
30
30
  ap.add_argument("--branch", help="branch to read protection from (default: the repo's default)")
31
- ap.add_argument("--all", action="store_true",
32
- help="include LOW findings (release and deploy pipelines, where a skip "
33
- "is usually the intent). Hidden by default so the output stays actionable.")
31
+ # `--all` used to hide the LOW tier. It is gone with the tiers: a census of all three
32
+ # strata found LOW at 31.6% false against MEDIUM at 55.6%, so the flag was hiding the
33
+ # BETTER findings and showing the worse ones. It is accepted and ignored so existing
34
+ # invocations do not break.
35
+ ap.add_argument("--all", action="store_true", help=argparse.SUPPRESS)
34
36
  args = ap.parse_args(argv)
35
37
 
36
38
  root = pathlib.Path(args.path)
@@ -105,30 +107,27 @@ def main(argv: list[str] | None = None) -> int:
105
107
  continue
106
108
  if prot is not None:
107
109
  job = ((doc or {}).get("jobs") or {}).get(x.job)
110
+ # resolve() still runs, but only to ATTRIBUTE the job to a required
111
+ # check. It no longer moves a severity, because there is no longer a
112
+ # severity to move.
108
113
  r = resolve(x.severity, x.job, job if isinstance(job, dict) else {}, prot,
109
114
  str(f) in callable_files)
110
115
  why = f"{r.verdict}: {r.why}"
111
- if r.moved:
112
- why = f"{r.structural} -> {r.severity} {why}"
113
- x = replace(x, severity=r.severity)
114
116
  if x.detector == "D1" and r.verdict != REQUIRED:
115
117
  suppressed += 1
116
118
  continue
117
- if x.severity == "LOW" and not args.all:
118
- suppressed += 1
119
- continue
120
119
  findings.append((f, x, why))
121
120
 
122
121
  if not args.quiet:
123
122
  for f, x, why in findings:
124
123
  rel = f.relative_to(root) if f.is_relative_to(root) else f
125
- print(f"[{x.detector}/{x.severity}] {rel}::{x.job} {x.title}")
124
+ print(f"[{x.detector}] {rel}::{x.job} {x.title}")
126
125
  print(f" {x.detail}")
127
126
  if why:
128
127
  print(f" branch: {why}")
129
128
  print(f" repro: {x.repro}\n")
130
129
 
131
- tail = f", {suppressed} LOW hidden (use --all)" if suppressed else ""
130
+ tail = f", {suppressed} D1 finding(s) not attributable to a required check" if suppressed else ""
132
131
  print(f"{len(files)} workflow file(s), {len(findings)} finding(s){tail}")
133
132
 
134
133
  if prot is not None and prot.required:
@@ -34,7 +34,20 @@ class Finding:
34
34
  title: str
35
35
  detail: str
36
36
  repro: str
37
- severity: str = "HIGH"
37
+ # There is no severity any more, and this field is kept only so existing callers do
38
+ # not break. Every D3 stratum was censused and the tiers did not rank anything:
39
+ #
40
+ # HIGH n= 94 30.9% false [22.4, 40.8]
41
+ # LOW n=415 31.6% false [27.3, 36.2] indistinguishable from HIGH
42
+ # MEDIUM n=153 55.6% false [47.6, 63.2] the only tier that separated, worst
43
+ #
44
+ # HIGH's interval overlaps the merged non-HIGH tier, so the loudest tier was not
45
+ # reliably better than everything else. The one real separation was MEDIUM being
46
+ # WORSE, which came from `_d3_severity` short-circuiting on `_on_pull_request` before
47
+ # it looked at the finding at all: the axis measured the workflow's trigger, not
48
+ # correctness. A severity that hides the better findings behind --all and shouts the
49
+ # worse ones is worse than none.
50
+ severity: str = "FINDING"
38
51
 
39
52
 
40
53
  def _truthy_always(cond) -> bool:
@@ -123,24 +136,6 @@ _NEEDS_NAMED = re.compile(r"needs\.([A-Za-z0-9_\-]+)\.(?:result|outputs)")
123
136
  _NEEDS_WILDCARD = re.compile(r"needs\.\*\.(?:result|outputs)")
124
137
 
125
138
 
126
- def _referenced_needs(text: str, needs: list[str]) -> set[str]:
127
- """Which of this job's `needs` does the text actually consult?
128
-
129
- Suggested by Arhan Canli in the dev.to thread on the write-up, and it is a better
130
- shape than what it replaces. `needs.X.result`, `needs.*` and `toJSON(needs)` are one
131
- rule, not three patterns to be discovered one outage at a time: compare the set of
132
- need ids a job references against its `needs:` list and report only the unreferenced
133
- ones. The spelling stops mattering.
134
-
135
- It is also strictly more precise than the boolean it replaces. `_reads_any_upstream_state`
136
- was all-or-nothing, so a gate naming eight of its nine needs suppressed the finding
137
- about the ninth, which is the one nobody checks.
138
- """
139
- if _NEEDS_WILDCARD.search(text) or _NEEDS_WHOLE_CONTEXT.search(text):
140
- return set(needs) # both forms consult every upstream at once
141
- return set(_NEEDS_NAMED.findall(text)) & set(needs)
142
-
143
-
144
139
  def _reads_any_upstream_state(text: str) -> bool:
145
140
  """True when the text consults any upstream's result or outputs, by name, by wildcard, or
146
141
  by serialising the whole `needs` context."""
@@ -192,20 +187,6 @@ _API_STATUS_READ = re.compile(
192
187
  re.I)
193
188
 
194
189
 
195
- _ONE_STEP_DOWN = {"HIGH": "MEDIUM", "MEDIUM": "LOW", "LOW": "LOW"}
196
-
197
-
198
- def _demote(sev: str) -> str:
199
- """One tier down, from wherever the finding actually sits.
200
-
201
- The class-7 guard first wrote `"MEDIUM" if sev == "HIGH" else sev`, which became a
202
- silent no-op the moment D1 stopped producing a structural HIGH: the guard still ran,
203
- still appended its note, and changed nothing. Two tests caught it by asserting the
204
- demoted severity was strictly below the baseline rather than equal to a literal.
205
- """
206
- return _ONE_STEP_DOWN.get(sev, sev)
207
-
208
-
209
190
  def _token_in_scope(job: dict, step: dict) -> bool:
210
191
  """Is a GitHub token available to this step?
211
192
 
@@ -302,8 +283,8 @@ def d1_skippable_upstream(jobs: dict, doc: dict | None = None,
302
283
  if not skippable:
303
284
  continue
304
285
  text = _job_blob(job)
305
- # All-or-nothing on purpose, and `_referenced_needs` above is the per-name model
306
- # that is deliberately NOT used here.
286
+ # All-or-nothing on purpose. A per-name model was built and measured here and is
287
+ # now deleted rather than left sitting unused.
307
288
  #
308
289
  # Arhan Canli's point in the dev.to thread is right in principle: needs.X.result,
309
290
  # needs.* and toJSON(needs) are one rule, so comparing the referenced set against
@@ -327,24 +308,24 @@ def d1_skippable_upstream(jobs: dict, doc: dict | None = None,
327
308
  # to jobs that are plausibly gates.
328
309
  if _reads_any_upstream_state(text):
329
310
  continue
330
- sev = _d1_severity(name, job, doc or {}, _workflow_has_any_gate(jobs))
331
311
  # Class 7: the job may consult the API instead of `needs`, in a script this
332
312
  # tool cannot parse. Only considered when the job announces itself as a gate,
333
313
  # so an ordinary job running ./build.sh is untouched.
314
+ # Class 7 still SUPPRESSES when the script provably reads run status. What it
315
+ # used to do on top of that, demote an unverifiable claim a tier, has nowhere to
316
+ # go now that there are no tiers, so it only annotates.
334
317
  unverified = ""
335
318
  if _GATE_NAME.search(name):
336
319
  verdict = _script_reads_status(_delegated_status_scripts(job), base)
337
320
  if verdict is True:
338
321
  continue
339
322
  if verdict is None and _delegated_status_scripts(job):
340
- sev = _demote(sev)
341
323
  unverified = (" NOTE: this job shells out to a script with a token in"
342
324
  " scope, so whether it checks upstream status could not be"
343
325
  " verified from the workflow alone.")
344
326
  for up in skippable:
345
327
  found.append(Finding(
346
328
  detector="D1",
347
- severity=sev,
348
329
  job=name,
349
330
  title="gate satisfied by a skipped job",
350
331
  detail=(f"job '{name}' depends on '{up}', which is conditional. A skipped job "
@@ -564,62 +545,9 @@ def _result_is_emptiness_checked(var: str, body: str) -> bool:
564
545
  # one missed `export V=$(...)` and `for f in $(...)` as consumption.
565
546
 
566
547
  # The output of this line is captured, redirected, or exported, so a wrong value escapes.
567
- _LINE_CONSUMES = re.compile(
568
- r">>?\s*\S" # any redirect
569
- r"|\$\{?GITHUB_(OUTPUT|ENV)\b" # crosses the step boundary
570
- r"|\btee\b" # tee writes a file
571
- r"|\$\(" # captured by a substitution
572
- r"|^\s*(?:export|local|declare|readonly)?\s*[A-Za-z_][A-Za-z0-9_]*=")
573
-
574
- _PRINT_ONLY = re.compile(r"^\s*(echo|printf)\b")
575
- _BARE_TEST = re.compile(r"^\s*(test\s|\[\s|\[\[\s)")
576
- _IS_CONDITION = re.compile(r"^\s*(if|elif|while|until)\b|\bif\s+\[|&&|\|\|")
577
-
578
-
579
- def _every_use_is_safe(var: str, body: str, assign_line: str) -> bool:
580
- """True when every use of `var` either fails loudly on empty or cannot matter.
581
-
582
- Deliberately conservative: anything not provably safe keeps the finding. A bare
583
- command argument is NOT safe, because the corpus has it both ways. `helm push "$PKG"`
584
- fails loudly on an empty argument; `ninja -C "$DIR" $TARGETS` silently builds the
585
- default target and succeeds. The workflow cannot tell those apart, so both are kept.
586
-
587
- The three safe shapes, each confirmed by running bash rather than by reasoning:
588
- * never dereferenced at all
589
- * only printed, with no redirect (a redirect is export, not print)
590
- * a BARE `test x = y` or `[ x = y ]` statement, whose non-zero status is the step's.
591
- Note `if [ "$X" -gt 1 ]` is NOT this: `set -e` is suspended in an if-condition, so
592
- an empty X makes `[` error, the else branch is taken, and the check passes
593
- silently. That distinction was wrong in the first census pass and cost two labels.
594
- """
595
- rest = body.replace(assign_line, "", 1)
596
- uses = [ln.strip() for ln in rest.splitlines()
597
- if re.search(rf"\$\{{?{re.escape(var)}\b", ln)]
598
- if not uses:
599
- return True
600
- for use in uses:
601
- if re.search(rf"\$\{{{re.escape(var)}:[-=]", use):
602
- continue # ${var:-default} applied
603
- redirects = re.search(r">>?\s*\S|\$\{?GITHUB_(OUTPUT|ENV)\b", use)
604
- if _PRINT_ONLY.match(use) and not redirects:
605
- continue
606
- if "GITHUB_STEP_SUMMARY" in use and not re.search(r"\$\{?GITHUB_(OUTPUT|ENV)\b", use):
607
- continue # a markdown summary is cosmetic
608
- if _BARE_TEST.match(use) and not _IS_CONDITION.match(use):
609
- continue
610
- return False
611
- return True
612
548
 
613
549
 
614
- # `cmd | grep -q PATTERN` does not mask anything, and that is demonstrable rather than
615
- # likely. When the head fails it produces no output, grep finds no match and exits 1, so
616
- # the pipeline fails exactly when the head does:
617
- #
618
- # $ nosuchcommand 2>/dev/null | grep -q arm64 ; echo $?
619
- # 1
620
- #
621
- # grep -q is also asking about CONTENT, not status: it is the idiom for "does this output
622
- # contain X", and it short-circuits on the first match, which can SIGPIPE the head anyway.
550
+
623
551
  # All 6 such findings in D3's MEDIUM census were false, as were the ones in the HIGH
624
552
  # census, and no labelled true finding has this shape.
625
553
  #
@@ -634,44 +562,6 @@ def _tail_is_a_content_assertion(segment: str) -> bool:
634
562
  return bool(_TAIL_IS_ASSERTION.match(tail))
635
563
 
636
564
 
637
- def _masked_status_can_matter(line: str, body: str) -> bool:
638
- """Could this masked exit status change any outcome?"""
639
- if not _LINE_CONSUMES.search(line):
640
- return False
641
- # The assignment must CAPTURE the pipeline, so the RHS has to open a command
642
- # substitution. `WINEDEBUG=-all timeout 300 make check | tee x.log` is an inline
643
- # ENV PREFIX, not a capture: reading it as one made the variable look unused and
644
- # suppressed two real findings where a test command's failure is masked by tee.
645
- # The simulation missed this because it only applied the assignment check to lines
646
- # already classified as captures; the real detector applies it to every line.
647
- assigned = re.match(
648
- r"\s*(?:export|local|declare|readonly)?\s*([A-Za-z_][A-Za-z0-9_]*)=[\"']?\$\(", line)
649
- if assigned and _every_use_is_safe(assigned.group(1), body, line):
650
- return False
651
- return True
652
-
653
-
654
- def _d3_severity(step: dict, job_name: str, job: dict, doc: dict, line: str) -> str:
655
- """Does the masked exit status actually decide anything?
656
-
657
- A pipeline whose result is exported, or which sits in a step that can fail the build,
658
- masks a decision. A pipeline in a cleanup or logging step masks nothing anybody reads.
659
- Tracing twenty D3 findings by hand, the ones that mattered all had a consumer and the
660
- ones that did not were fire-and-forget.
661
- """
662
- body = str(step.get("run") or "")
663
- if not _on_pull_request(doc):
664
- return "LOW"
665
- exported = "GITHUB_OUTPUT" in body or "GITHUB_ENV" in body
666
- decides = bool(re.search(r"\bexit\s+[1-9]|::error::", body))
667
- assigned = re.match(r"\s*([A-Za-z_][A-Za-z0-9_]*)=", line)
668
- consumed = bool(assigned and re.search(rf"\$\{{?{re.escape(assigned.group(1))}\b",
669
- body.replace(line, "", 1)))
670
- if (decides or exported or consumed) and _masked_status_can_matter(line, body):
671
- return "HIGH"
672
- return "MEDIUM"
673
-
674
-
675
565
  def _logical_lines(body: str):
676
566
  """Shell lines, joined where a pipeline continues onto the next one.
677
567
 
@@ -754,14 +644,6 @@ def d3_pipe_masked_exit(jobs: dict, doc: dict | None = None) -> list[Finding]:
754
644
  label = step.get("name") or line[:40]
755
645
  found.append(Finding(
756
646
  detector="D3",
757
- # Severity is judged on the LINE, while the finding names the
758
- # SEGMENT, and that split is deliberate. The segment is WHERE
759
- # the status is masked; the enclosing line is HOW the bad value
760
- # escapes, via an assignment or a redirect into $GITHUB_OUTPUT.
761
- # Judging severity on the segment alone was tried: it sees no
762
- # assignment and no export in `sha256sum f | cut -d' ' -f1`, so
763
- # HIGH fell from 94 to 30 and six tests went red.
764
- severity=_d3_severity(step, name, job, doc or {}, line),
765
647
  job=name,
766
648
  title="exit status masked by a pipe",
767
649
  detail=(f"step '{label}' in job '{name}' ends a pipeline with "
@@ -814,17 +696,6 @@ def _on_pull_request(doc: dict) -> bool:
814
696
  return False
815
697
 
816
698
 
817
- def _gate_severity(job_name: str, job: dict, doc: dict) -> str:
818
- name = f"{job_name} {job.get('name') or ''}"
819
- if _SHIP_JOB.search(name) and not _CHECK_JOB.search(name):
820
- return "LOW" # a release step, where skipping is usually the intent
821
- if not _on_pull_request(doc):
822
- return "LOW" # never runs on a PR, so it is not a merge gate
823
- if _CHECK_JOB.search(name):
824
- return "HIGH" # a PR verification job that can silently not run
825
- return "MEDIUM"
826
-
827
-
828
699
  def _needs_of(job) -> list[str]:
829
700
  n = job.get("needs") if isinstance(job, dict) else None
830
701
  if not n:
@@ -906,36 +777,6 @@ def _jobs_whose_whole_chain_a_gate_watches(jobs: dict) -> set[str]:
906
777
  return covered
907
778
 
908
779
 
909
- def _workflow_has_any_gate(jobs: dict) -> bool:
910
- """Does ANY job here consult upstream results at all?"""
911
- return any(isinstance(j, dict) and _runs_like_a_gate(j.get("if"))
912
- and _reads_any_upstream_state(_job_blob(j)) for j in jobs.values())
913
-
914
-
915
- def _d1_severity(name: str, job: dict, doc: dict, has_gate: bool) -> str:
916
- """D1 severity, capped at MEDIUM for the same reason D4 is.
917
-
918
- D1's finding asserts that a required check is satisfied by a skipped job. Whether the
919
- job is a required check is precisely what a workflow file cannot say, so a structural
920
- HIGH was a guess from a word in the job's name.
921
-
922
- Measured before changing it, by hand-labelling the ENTIRE D1 stratum rather than
923
- sampling it (54 findings, 29 jobs, so a census was cheaper than an argument about two
924
- disagreeing samples): 65% false per finding even after the API-gate and never-runs
925
- fixes. Eleven of the survivors are a single reporting job. That is not a tier that can
926
- keep claiming HIGH on its own authority.
927
-
928
- HIGH is therefore reserved for the escalation path in `protection.py`, where the job has
929
- been attributed to a confirmed required check. Without that, MEDIUM when nothing in the
930
- workflow consults upstream results at all, and LOW when the workflow does gate but not
931
- over this upstream.
932
- """
933
- base = _gate_severity(name, job, doc)
934
- if base == "LOW":
935
- return "LOW"
936
- return "MEDIUM" if not has_gate else "LOW"
937
-
938
-
939
780
  # D4 was REMOVED in 0.1.5, not demoted.
940
781
  #
941
782
  # It scored 0 defensible findings out of 18 in a pre-registered hand-labelled
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deadgate
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Find CI checks that cannot fail: gates satisfied by skipped jobs, exit statuses swallowed by pipes, fan-ins that never read whether their upstream passed.
5
5
  Author-email: Erik Hill <contact@erikhill.dev>
6
6
  License: MIT
@@ -54,33 +54,53 @@ be parsed**. A file it could not read is never counted as a file with no problem
54
54
  | D3 | a `run:` step ends a pipeline in a filter with no `pipefail` | the step's status is the filter's, so an upstream failure passes |
55
55
 
56
56
  **Two detectors have been removed rather than tuned**, each on hand-labelled evidence
57
- that it was never right: D4 on 0 true of 18 sampled (0.1.5), and D2 on 0 true of 27
57
+ that it was never right: D4 on 0 true of 18 sampled, of which 8 false and **10 left
58
+ unresolved** (0.1.5), and D2 on 0 true of 27
58
59
  censused (0.1.6). The shapes they fired on are described in those sections, including
59
60
  the one real hazard that is now undetected by design.
60
61
 
62
+ ### There is no severity any more
63
+
64
+ Every D3 stratum was censused, and the tiers did not rank anything:
65
+
66
+ | tier | n | false |
67
+ |---|---|---|
68
+ | HIGH | 94 | 30.9% `[22.4, 40.8]` |
69
+ | LOW | 415 | 31.6% `[27.3, 36.2]` |
70
+ | MEDIUM | 153 | **55.6%** `[47.6, 63.2]` |
71
+
72
+ HIGH's interval overlaps the merged non-HIGH tier (38.0% `[34.1, 42.1]`), so the loudest
73
+ tier was not reliably better than everything else. LOW was indistinguishable from HIGH.
74
+ The one real separation was MEDIUM being **worse**, and that came from `_d3_severity`
75
+ short-circuiting on whether the workflow runs on `pull_request` before it looked at the
76
+ finding at all: the axis measured the trigger, not correctness.
77
+
78
+ A severity that hid the better findings behind `--all` and shouted the worse ones is worse
79
+ than none, so it is gone. `--all` is accepted and ignored. **D3 is 37.0% false overall**,
80
+ 245 of 662, and that is the number.
81
+
61
82
  ### Measured precision, so the table above is not the only claim
62
83
 
63
84
  Every figure below is hand-labelled. None is an estimate of an estimate.
64
85
 
65
- | detector | tier | basis | false |
66
- |---|---|---|---|
67
- | D3 | HIGH (94) | complete census | **30.9%** |
68
- | D3 | MEDIUM (144) | **complete census** | **54.9%** |
69
- | D3 | LOW (426) | uncapped sample, n=15 | **47%** `[25, 70]` |
70
- | D1 | **not reported without `--repo`** | see below | n/a |
71
-
72
- **What you see by default is about 45% false.** The CLI hides LOW without `--all`, so the
73
- default output is HIGH plus MEDIUM, 238 D3 findings, of which about 108 are wrong.
86
+ | detector | basis | false |
87
+ |---|---|---|
88
+ | D3, all 662 | **complete census of all three former strata** | **37.0%** |
89
+ | D1 | not reported without `--repo` | see below |
74
90
 
75
- MEDIUM is worse than HIGH, and both are now censused so that is exact. Whether MEDIUM is
76
- worse than LOW is still **not** established: LOW rests on n=15 and its interval `[25, 70]`
77
- contains MEDIUM's exact 54.9%. Settling it needs LOW measured properly, which has not been
78
- done.
91
+ **Everything is reported now.** Nothing is hidden, so what you see is the whole 37.0%.
92
+ Collapsing the tiers raised the default output from 247 findings to 653 and *lowered* the
93
+ false rate a reader experiences from 46.2% to 37.0%, because the hidden tier was the
94
+ better one.
79
95
 
80
- An uncapped n=30 sample put MEDIUM at 70%; the census says 54.9%. Off by 14 points, inside
81
- its own interval but near the edge, which is the cost of n=30 even with the cap removed.
96
+ Two samples along the way were notably off, and both were caught only by censusing the
97
+ thing they estimated. An uncapped n=30 sample put MEDIUM at 70%; the census says 55.6%, 14
98
+ points out and near the edge of its own interval. A n=15 sample put LOW at 47% `[25, 70]`;
99
+ the census says 31.6%. Small samples were the cost even after the per-repository cap was
100
+ removed.
82
101
 
83
- MEDIUM is not one population. Classified by shape, it splits sharply:
102
+ The former MEDIUM was not one population. Classified by shape, it split sharply, and the
103
+ same shapes explain the whole detector:
84
104
 
85
105
  | shape | n | false |
86
106
  |---|---|---|
@@ -411,7 +431,8 @@ said the branch protection that job provides is decorative.
411
431
  That is not a precision problem a narrowing fixes. The detector's own gate test disagreed
412
432
  with its own finding text, every single time.
413
433
 
414
- D4 was removed on 0 true of 18 **sampled**. D2 goes on 0 true of 27 **censused**.
434
+ D4 was removed on a sample of 18 that scored 0 true, 8 false and **10 arguable**. D2
435
+ goes on 0 true of 27 **censused**, with no arguable bucket at all.
415
436
 
416
437
  Total output across the corpus: **1054 to 1027.** HIGH is unchanged at 125, all D3.
417
438
 
@@ -424,6 +445,18 @@ Both comments now name the function that actually does the work.
424
445
 
425
446
  ## 0.1.5 removes D4
426
447
 
448
+ > **Correction.** This section originally read "0 defensible findings out of 18", and
449
+ > that overstates it. The sample was **0 defensible, 8 false and 10 ARGUABLE**: ten of the
450
+ > eighteen were never resolved. A later census of D3's HIGH stratum established that an
451
+ > arguable bucket is not a random sample of its population, running 66% false against 34%
452
+ > overall, enough to flip a verdict. The ten were probably mostly false; probably is not a
453
+ > measurement. The sample was also drawn from D4's HIGH stratum, and severity has since
454
+ > been measured to carry no quality signal, so that stratification means nothing either.
455
+ >
456
+ > **The removal still stands, on evidence that depends on neither:** 80% of D4's 932
457
+ > findings describe a mechanism redundant with GitHub's needs-skip rule, which is
458
+ > measured below and is severity-independent.
459
+
427
460
  **D4 is gone, not demoted.** It scored **0 defensible findings out of 18** in a
428
461
  pre-registered hand-labelled sample, and it was the largest detector by volume: **932
429
462
  findings over 93 repositories, 47% of everything this tool emitted.**
@@ -613,5 +646,5 @@ That gap is the lesson worth keeping. The tool was least accurate on the reposit
613
646
  BEST CI, which is the worst place for a linter to cry wolf, and no corpus average would have
614
647
  surfaced it. The suite passed unchanged through every one of the four, 149 of it through the
615
648
  first two fixes and 161 through the second two, so not one of them was covered by anything.
616
- There are 228 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
649
+ There are 212 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
617
650
  suite ever drift apart again.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "deadgate"
3
- version = "0.2.0"
3
+ version = "0.3.0"
4
4
  description = "Find CI checks that cannot fail: gates satisfied by skipped jobs, exit statuses swallowed by pipes, fan-ins that never read whether their upstream passed."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -106,53 +106,18 @@ def test_the_regex_matches_the_real_artifact_not_a_tidier_one():
106
106
  assert _API_STATUS_READ.search("actions/runs/${id}/jobs")
107
107
 
108
108
 
109
- def test_the_baseline_gate_is_reported_at_all(tmp_path):
110
- """Without this the suppression tests below could pass on an empty list."""
111
- assert _baseline() in RANK
112
109
 
113
110
 
114
111
  def test_a_readable_script_that_reads_the_api_suppresses_the_finding(tmp_path):
115
112
  assert _run(tmp_path, script_body=f"// gutenberg\n{REAL_URL}\n") == []
116
113
 
117
114
 
118
- def test_a_readable_script_that_does_not_check_status_keeps_the_baseline(tmp_path):
119
- """The other direction. Delegation alone must not be an excuse."""
120
- out = _run(tmp_path, script_body="console.log('I only print things');\n")
121
- assert len(out) == 1
122
- assert out[0].severity == _baseline()
123
- assert "could not be verified" not in out[0].detail
124
115
 
125
116
 
126
- def test_an_unreadable_script_is_demoted_and_says_so(tmp_path):
127
- """Script absent: the claim is unverifiable, so it is demoted, not asserted."""
128
- out = _run(tmp_path, script_body=None)
129
- assert len(out) == 1
130
- assert RANK[out[0].severity] < RANK[_baseline()], (out[0].severity, _baseline())
131
- assert "could not be verified" in out[0].detail
132
117
 
133
118
 
134
- def test_no_tree_at_all_is_demoted_too(tmp_path):
135
- """Called as a library with no base, the claim is equally unverifiable."""
136
- out = _run(tmp_path, tree=False)
137
- assert len(out) == 1
138
- assert RANK[out[0].severity] < RANK[_baseline()]
139
- assert "could not be verified" in out[0].detail
140
119
 
141
120
 
142
- def test_a_script_without_a_token_is_not_excused(tmp_path):
143
- """The narrowing condition. Without credentials a script cannot read run status, so
144
- an ordinary build script must not buy an exemption."""
145
- doc = yaml.safe_load(WORKFLOW)
146
- # Deleted structurally, not by string replace: dedent had already changed the
147
- # indentation my first replace() targeted, so it silently matched nothing and the
148
- # test exercised the WITH-token case. The assert below is what caught that.
149
- del doc["jobs"]["unit-status-check"]["steps"][0]["env"]
150
- assert "GITHUB_TOKEN" not in yaml.dump(doc), "the fixture must actually drop the token"
151
- base = _tree(tmp_path, None)
152
- out = d1_skippable_upstream(doc["jobs"], doc, base)
153
- assert len(out) == 1
154
- assert out[0].severity == _baseline()
155
- assert "could not be verified" not in out[0].detail
156
121
 
157
122
 
158
123
  def test_a_job_that_is_not_a_named_gate_is_untouched(tmp_path):
@@ -335,3 +300,32 @@ def test_a_gate_that_reads_no_results_does_not_cover():
335
300
  jobs = yaml.safe_load(CHAIN % ("[detect, gate-upstream, e2e]", "always()"))["jobs"]
336
301
  jobs["finish"]["steps"] = [{"run": "echo done"}]
337
302
  assert [f for f in d1_skippable_upstream(jobs, {}, None) if f.job == "e2e"]
303
+
304
+
305
+ def test_an_unverifiable_delegation_is_annotated(tmp_path):
306
+ """There is no tier to demote to any more, so the guard only annotates.
307
+
308
+ It used to drop the finding one severity and say the claim was unverified. With the
309
+ tiers collapsed the demotion has nowhere to go; the NOTE is the whole remedy, and it
310
+ is the part that was always carrying the information.
311
+ """
312
+ out = _run(tmp_path, script_body=None)
313
+ assert len(out) == 1
314
+ assert "could not be verified" in out[0].detail
315
+
316
+
317
+ def test_a_readable_script_that_does_not_check_status_is_not_annotated(tmp_path):
318
+ """The other direction. Delegation alone must not attract the note."""
319
+ out = _run(tmp_path, script_body="console.log('I only print things');\n")
320
+ assert len(out) == 1
321
+ assert "could not be verified" not in out[0].detail
322
+
323
+
324
+ def test_a_script_without_a_token_is_not_excused(tmp_path):
325
+ """The narrowing condition. Without credentials a script cannot read run status."""
326
+ doc = yaml.safe_load(WORKFLOW)
327
+ del doc["jobs"]["unit-status-check"]["steps"][0]["env"]
328
+ assert "GITHUB_TOKEN" not in yaml.dump(doc), "the fixture must actually drop the token"
329
+ out = d1_skippable_upstream(doc["jobs"], doc, _tree(tmp_path, None))
330
+ assert len(out) == 1
331
+ assert "could not be verified" not in out[0].detail
@@ -170,36 +170,12 @@ def _of(doc_text, det):
170
170
  return [x for x in _scan(_yaml.safe_load(doc_text)) if x.detector == det]
171
171
 
172
172
 
173
- def test_d1_pr_verification_is_medium_not_high():
174
- """D1's structural ceiling is MEDIUM as of the census, not HIGH.
175
-
176
- This asserted HIGH until the whole D1 stratium was hand-labelled: 65% false per
177
- finding even after the API-gate and never-runs fixes, with 11 of the survivors a
178
- single reporting job. "A required check is satisfied by a skipped job" needs a
179
- protection configuration no workflow file carries, so HIGH now belongs only to the
180
- escalation path in protection.py. Still MEDIUM rather than LOW, so the ship-job
181
- branch below stays distinguishable and neither can be deleted silently.
182
- """
183
- f = _of(_D1_PR_TEST, "D1")
184
- assert f and f[0].severity == "MEDIUM", f
185
- assert f[0].severity != "HIGH"
186
173
 
187
174
 
188
- def test_d1_release_pipeline_is_low():
189
- f = _of(_D1_RELEASE, "D1")
190
- assert f and f[0].severity == "LOW", f
191
175
 
192
176
 
193
- def test_d3_exported_result_is_high():
194
- """The masked value leaves the step, so something downstream consumes it."""
195
- f = _of(_D3_EXPORTED, "D3")
196
- assert f and f[0].severity == "HIGH", f
197
177
 
198
178
 
199
- def test_d3_fire_and_forget_is_not_high():
200
- """A logging pipeline masks nothing anybody reads."""
201
- f = _of(_D3_CLEANUP, "D3")
202
- assert f and f[0].severity == "MEDIUM", f
203
179
 
204
180
 
205
181
  # ------------------------------------------------------------- what the corpus did NOT specify
@@ -236,66 +212,10 @@ def test_every_finding_carries_a_reproduction():
236
212
  assert f.detail.strip(), f"{path.name}: {f.detector} on {f.job} has no detail"
237
213
 
238
214
 
239
- def test_a_ship_job_on_a_pull_request_is_still_LOW():
240
- """The ship-job guard was unreachable from the test written for it: that fixture is
241
- tag-triggered, so `not _on_pull_request` already returned LOW one line later and deleting
242
- the guard changed nothing. This reaches the guard itself."""
243
- doc = yaml.safe_load("""
244
- on: [pull_request]
245
- jobs:
246
- prepare:
247
- if: github.ref == 'refs/heads/main'
248
- runs-on: ubuntu-latest
249
- steps:
250
- - run: echo prep
251
- publish:
252
- needs: [prepare]
253
- runs-on: ubuntu-latest
254
- steps:
255
- - run: twine upload dist/*
256
- """)
257
- hits = [f for f in _findings(doc) if f.detector == "D1" and f.job == "publish"]
258
- assert hits, "expected a D1 finding on the publish job"
259
- assert all(f.severity == "LOW" for f in hits), (
260
- f"a release job is not a merge gate even on a PR: got {[f.severity for f in hits]}")
261
215
 
262
216
 
263
- def test_a_check_job_on_a_pull_request_is_MEDIUM():
264
- """The other side of the same guard, so neither branch can be deleted silently.
265
217
 
266
- Was HIGH; capped at MEDIUM when the D1 census measured 65% false. A ship job stays
267
- LOW, so the two branches remain distinct and the guard is still load-bearing.
268
- """
269
- doc = yaml.safe_load("""
270
- on: [pull_request]
271
- jobs:
272
- prepare:
273
- if: github.ref == 'refs/heads/main'
274
- runs-on: ubuntu-latest
275
- steps:
276
- - run: echo prep
277
- verify-tests:
278
- needs: [prepare]
279
- runs-on: ubuntu-latest
280
- steps:
281
- - run: pytest
282
- """)
283
- hits = [f for f in _findings(doc) if f.detector == "D1" and f.job == "verify-tests"]
284
- assert hits and all(f.severity == "MEDIUM" for f in hits), (
285
- "a PR verification job that can silently not run is MEDIUM, capped by the census: "
286
- f"got {[f.severity for f in hits]}")
287
-
288
-
289
- def test_d3_outside_a_pull_request_is_LOW():
290
- """b4 is `on: [push]` and does fire D3, but the corpus asserted only the detector id, so
291
- D3's first severity line was dead in the suite. cli.py hides LOW without --all, so this
292
- guard decides whether the finding is printed at all."""
293
- b4 = next(p for p in BROKEN if p.name.startswith("b4_"))
294
- doc = yaml.safe_load(b4.read_text())
295
- d3 = [f for f in _findings(doc) if f.detector == "D3"]
296
- assert d3, "b4 should still fire D3"
297
- assert all(f.severity == "LOW" for f in d3), (
298
- f"a push-only workflow is not a merge gate: got {[f.severity for f in d3]}")
218
+
299
219
 
300
220
 
301
221
  @pytest.mark.parametrize("cond", [
@@ -63,7 +63,7 @@ def _run(tree, capsys, argv_extra=()):
63
63
 
64
64
  def test_d1_says_nothing_without_protection_data(tree, capsys):
65
65
  _, out = _run(tree, capsys)
66
- assert "[D1/" not in out, out
66
+ assert "[D1]" not in out, out
67
67
 
68
68
 
69
69
  def test_the_workflow_really_does_trigger_d1(tree):
@@ -83,7 +83,7 @@ def test_d1_is_reported_when_protection_confirms_the_check(tree, capsys, monkeyp
83
83
  monkeypatch.setattr(cli, "fetch", lambda *a, **k: Protection(
84
84
  state=PROTECTED, required=frozenset({"verify-tests"}), complete=True))
85
85
  _, out = _run(tree, capsys, ("--repo", "o/r"))
86
- assert "[D1/" in out, out
86
+ assert "[D1]" in out, out
87
87
  assert "REQUIRED" in out
88
88
 
89
89
 
@@ -97,7 +97,7 @@ def test_d1_stays_silent_when_protection_says_the_job_is_not_required(tree, caps
97
97
  monkeypatch.setattr(cli, "fetch", lambda *a, **k: Protection(
98
98
  state=PROTECTED, required=frozenset({"something-else"}), complete=True))
99
99
  _, out = _run(tree, capsys, ("--repo", "o/r"))
100
- assert "[D1/" not in out, out
100
+ assert "[D1]" not in out, out
101
101
 
102
102
 
103
103
  def test_d3_is_unaffected_by_the_d1_gate(tmp_path, capsys):
@@ -113,4 +113,4 @@ def test_d3_is_unaffected_by_the_d1_gate(tmp_path, capsys):
113
113
  echo "d=$(sha256sum f | cut -d ' ' -f 1)" >> "$GITHUB_OUTPUT"
114
114
  """))
115
115
  main([str(tmp_path), "--all"])
116
- assert "[D3/" in capsys.readouterr().out
116
+ assert "[D3]" in capsys.readouterr().out
@@ -23,10 +23,17 @@ import textwrap
23
23
 
24
24
  import yaml
25
25
 
26
- from deadgate.detectors import _masked_status_can_matter, scan_workflow
26
+ from deadgate.detectors import scan_workflow
27
27
 
28
28
 
29
29
  def _high(run: str) -> list:
30
+ """Historically "is this HIGH". With the tiers collapsed it is "is this reported".
31
+
32
+ The severity model was removed after all three D3 strata were censused: HIGH 30.9%
33
+ false, LOW 31.6%, MEDIUM 55.6%. HIGH's interval overlapped the merged non-HIGH tier,
34
+ LOW was indistinguishable from HIGH, and the one real separation was MEDIUM being
35
+ WORSE, an artefact of severity short-circuiting on the workflow's trigger. So these
36
+ tests now assert presence, not tier."""
30
37
  doc = yaml.safe_load(textwrap.dedent(f"""
31
38
  on: [pull_request]
32
39
  jobs:
@@ -37,7 +44,7 @@ def _high(run: str) -> list:
37
44
  run: |
38
45
  {textwrap.indent(run.strip(), " " * 18)}
39
46
  """))
40
- return [f for f in scan_workflow(doc) if f.detector == "D3" and f.severity == "HIGH"]
47
+ return [f for f in scan_workflow(doc) if f.detector == "D3"]
41
48
 
42
49
 
43
50
  # --- the shapes that must STAY high -----------------------------------------
@@ -90,38 +97,20 @@ def test_an_if_with_a_numeric_test_stays_high():
90
97
 
91
98
  # --- the shapes that must NOT be high ---------------------------------------
92
99
 
93
- def test_a_pipeline_whose_output_goes_nowhere_is_not_high():
94
- """`_d3_severity` reads `exit 1` from ANYWHERE in the step, so one exit at the bottom
95
- used to promote every log-extraction pipeline above it."""
96
- assert not _high('grep -E "warn" logs/install.log | tail -60\nexit 1')
97
100
 
98
101
 
99
- def test_a_captured_value_never_used_again_is_not_high():
100
- assert not _high('DMG="$(ls dl/*.dmg | head -1)"\nexit 1')
101
102
 
102
103
 
103
- def test_a_captured_value_that_is_only_printed_is_not_high():
104
- assert not _high('SCORE=$(cat r.json | jq -r .score)\necho "score: $SCORE"\nexit 1')
105
104
 
106
105
 
107
- def test_a_bare_test_statement_fails_loudly_so_is_not_high():
108
- """Verified by running bash: a bare `test x = y` that fails exits the step under -e,
109
- so an empty captured value surfaces rather than passing silently."""
110
- assert not _high('actual="$(sha256sum f | cut -d\' \' -f1)"\ntest "$actual" = "$expected"')
111
106
 
112
107
 
113
- def test_a_default_applied_at_the_use_site_is_not_high():
114
- assert not _high('words="$(wc -w < f | tr -d \' \')"\nif [ "${words:-0}" -gt 300 ]; then exit 1; fi')
115
108
 
116
109
 
117
110
  # --- the predicate itself ---------------------------------------------------
118
111
 
119
- def test_predicate_rejects_a_line_that_consumes_nothing():
120
- assert not _masked_status_can_matter("ls -la /tmp | head -10", "ls -la /tmp | head -10")
121
112
 
122
113
 
123
- def test_predicate_accepts_a_redirect():
124
- assert _masked_status_can_matter("cmd | jq . > out.json", "cmd | jq . > out.json")
125
114
 
126
115
 
127
116
  # ---------------------------------------------------------------------------
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes