deadgate 0.1.8__tar.gz → 0.2.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.
- {deadgate-0.1.8 → deadgate-0.2.0}/PKG-INFO +112 -7
- {deadgate-0.1.8 → deadgate-0.2.0}/README.md +111 -6
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate/cli.py +30 -1
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate/detectors.py +159 -23
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate.egg-info/PKG-INFO +112 -7
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate.egg-info/SOURCES.txt +1 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/pyproject.toml +1 -1
- deadgate-0.2.0/tests/test_d1_requires_protection.py +116 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/tests/test_d3_narrowing.py +145 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/LICENSE +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate/__init__.py +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate/checknames.py +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate/predicates.py +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate/protection.py +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate/resolve.py +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate/sandbox.py +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate.egg-info/dependency_links.txt +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate.egg-info/entry_points.txt +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate.egg-info/requires.txt +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/deadgate.egg-info/top_level.txt +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/setup.cfg +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/tests/test_api_status_gates.py +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/tests/test_corpus.py +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/tests/test_predicates.py +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/tests/test_protection.py +0 -0
- {deadgate-0.1.8 → deadgate-0.2.0}/tests/test_sandbox.py +0 -0
- {deadgate-0.1.8 → deadgate-0.2.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.
|
|
3
|
+
Version: 0.2.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
|
|
@@ -50,7 +50,7 @@ be parsed**. A file it could not read is never counted as a file with no problem
|
|
|
50
50
|
|
|
51
51
|
| id | defect | why it matters |
|
|
52
52
|
|----|--------|----------------|
|
|
53
|
-
| D1 | a job depends on a skip-prone job and never reads `needs.*.result` |
|
|
53
|
+
| D1 | a job depends on a skip-prone job and never reads `needs.*.result` | **only reported with `--repo`**, when branch protection confirms the job is a required check |
|
|
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
|
|
@@ -58,10 +58,74 @@ that it was never right: D4 on 0 true of 18 sampled (0.1.5), and D2 on 0 true of
|
|
|
58
58
|
censused (0.1.6). The shapes they fired on are described in those sections, including
|
|
59
59
|
the one real hazard that is now undetected by design.
|
|
60
60
|
|
|
61
|
-
Measured precision, so the table above is not the only claim
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
### Measured precision, so the table above is not the only claim
|
|
62
|
+
|
|
63
|
+
Every figure below is hand-labelled. None is an estimate of an estimate.
|
|
64
|
+
|
|
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.
|
|
74
|
+
|
|
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.
|
|
79
|
+
|
|
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.
|
|
82
|
+
|
|
83
|
+
MEDIUM is not one population. Classified by shape, it splits sharply:
|
|
84
|
+
|
|
85
|
+
| shape | n | false |
|
|
86
|
+
|---|---|---|
|
|
87
|
+
| a test, audit or publish piped to `tee` or a file | 59 | **22%** |
|
|
88
|
+
| a captured value | 5 | 0% |
|
|
89
|
+
| other | 30 | 77% |
|
|
90
|
+
| a diagnostic head (`ls`, `df`, `--version`) | 23 | **96%** |
|
|
91
|
+
| `grep -q` assertion | 6 | **100%**, now suppressed |
|
|
92
|
+
|
|
93
|
+
The MEDIUM and LOW samples were drawn **uncapped**, which reverses the design of every
|
|
94
|
+
earlier sample here. A per-repository cap makes the estimator unbiased for the per-job
|
|
95
|
+
rate and about 16 points low for the per-finding rate, which is the defect described in
|
|
96
|
+
the 0.1.4 notes below.
|
|
97
|
+
|
|
98
|
+
### D1 says nothing unless branch protection confirms the check
|
|
99
|
+
|
|
100
|
+
D1's finding text says "a skipped job reports Success, and X never reads needs.Y.result",
|
|
101
|
+
which describes X running without its dependency. [GitHub documents that it does
|
|
102
|
+
not](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idneeds):
|
|
103
|
+
"If a job fails or is skipped, all jobs that need it are skipped unless the jobs use a
|
|
104
|
+
conditional expression that causes the job to continue."
|
|
105
|
+
|
|
106
|
+
Measured over 373 D1 findings on the corpus:
|
|
107
|
+
|
|
108
|
+
| | |
|
|
109
|
+
|---|---|
|
|
110
|
+
| 255 (68%) | the dependent would be **skipped too**, so what remains is "a skipped required check counts as success", which needs protection data |
|
|
111
|
+
| 101 (27%) | the dependent does run, but it is `release_lease`, `postSlackMessageOnFailure`, `ci-timing`, `merge-reports`: the reporting family the D2 census measured at **0 true of 27** |
|
|
112
|
+
| 10 (3%) | gutenberg status checks, known class-7 false positives |
|
|
113
|
+
| **~7** | candidates, precision never established |
|
|
114
|
+
|
|
115
|
+
An uncapped 40-finding sample of the current population labelled about **92% false**.
|
|
116
|
+
|
|
117
|
+
**The figure here used to read "65% false", and it was stale.** It came from a census of 54
|
|
118
|
+
findings taken at 0.1.4; that census covers 46 of today's 373 (12%), and among those the
|
|
119
|
+
rate is 76.7%. Quoting it against the whole population was the claim-rot pattern this
|
|
120
|
+
project keeps finding in other people's repositories.
|
|
121
|
+
|
|
122
|
+
D4 was **removed** for making an unverifiable branch-protection claim. D1 makes the same
|
|
123
|
+
claim, but unlike D4 the tool can check it: `--repo` reads the required contexts and
|
|
124
|
+
`resolve()` attributes a job to one. So the claim is gated on its evidence rather than the
|
|
125
|
+
detector deleted. **Without `--repo`, deadgate is a one-detector tool**, and the table
|
|
126
|
+
above should be read that way.
|
|
127
|
+
|
|
128
|
+
D3 is the only detector that produces HIGH.
|
|
65
129
|
|
|
66
130
|
Every finding carries a reproduction. A finding without one is an opinion, and this tool
|
|
67
131
|
does not emit opinions.
|
|
@@ -170,6 +234,43 @@ is a separate and harder problem and is not in this release.
|
|
|
170
234
|
## Licence
|
|
171
235
|
MIT
|
|
172
236
|
|
|
237
|
+
## 0.1.9 fixes a substitution scanner that was blind to shell quoting
|
|
238
|
+
|
|
239
|
+
Found by reading the segments 0.1.8 began reporting, not by a test. Several were mangled,
|
|
240
|
+
and a mangled segment means the reported filter and the head-can-fail judgement were both
|
|
241
|
+
computed on corrupted text. Three defects in one scanner, all from counting parens without
|
|
242
|
+
parsing:
|
|
243
|
+
|
|
244
|
+
| | shape | what it produced |
|
|
245
|
+
|---|---|---|
|
|
246
|
+
| quotes | `$(grep -o 'X\(A\|B\)' f \| cut ...)` | filter reported as `PATCH\` |
|
|
247
|
+
| fresh context | `"$(sed 's#^(a)#\1#p' f \| sort)"` | span closed at `+)` |
|
|
248
|
+
| process substitution | `$(comm <(a) <(b \| jq))` | everything after the first `<(...)` lost |
|
|
249
|
+
|
|
250
|
+
Inside `$( ... )` the body is parsed as new shell code, so a single quote quotes again even
|
|
251
|
+
when the substitution sits inside double quotes. The scanner now tracks single quotes,
|
|
252
|
+
double quotes, backslash escapes and `<( )`, and saves and restores the quote state across
|
|
253
|
+
a substitution boundary.
|
|
254
|
+
|
|
255
|
+
### D3's HIGH stratum is fully hand-labelled again
|
|
256
|
+
|
|
257
|
+
**94 findings, 65 true, 29 false, 30.9% false**, with no unlabelled residue. Across the
|
|
258
|
+
sequence: 51.2% before any narrowing, 35.1% after 0.1.7 against partial labels, 30.9% now
|
|
259
|
+
against complete ones.
|
|
260
|
+
|
|
261
|
+
Of the 17 that needed new labels because the reported segment moved, 11 are true. They are
|
|
262
|
+
the same defects named more precisely: `sha256sum f | cut -d' ' -f1` rather than the
|
|
263
|
+
`echo ... >> "$GITHUB_OUTPUT"` wrapped around it, and four `for x in $(find ... | sort)`
|
|
264
|
+
loops whose empty list means a check runs over nothing and passes.
|
|
265
|
+
|
|
266
|
+
### One thing deliberately left alone
|
|
267
|
+
|
|
268
|
+
Severity is judged on the **line** while the finding names the **segment**. That looks like
|
|
269
|
+
an inconsistency and is not: the segment is where the status is masked, the enclosing line
|
|
270
|
+
is how the bad value escapes. Judging severity on the segment alone was tried, and HIGH
|
|
271
|
+
fell from 94 to 30 with six tests red, because `sha256sum f | cut -d' ' -f1` on its own
|
|
272
|
+
shows no assignment and no export.
|
|
273
|
+
|
|
173
274
|
## 0.1.8 fixes two bugs the census found in D3 itself
|
|
174
275
|
|
|
175
276
|
Both were found by hand-labelling D3's HIGH findings, not by a test.
|
|
@@ -407,6 +508,10 @@ the 54 findings hand-labelled, 29 distinct jobs. **76% false per finding, 59% pe
|
|
|
407
508
|
exact, no interval. Even after all three fixes above it is 65% false, with eleven of the
|
|
408
509
|
survivors a single reporting job.
|
|
409
510
|
|
|
511
|
+
> That 65% describes the population as it stood at 0.1.4. It covers 46 of today's 373
|
|
512
|
+
> D1 findings, 12%, where the rate is 76.7%. D1 is no longer reported at all without
|
|
513
|
+
> `--repo`; see the precision section near the top.
|
|
514
|
+
|
|
410
515
|
"A required check is satisfied by a skipped job" needs a protection configuration no
|
|
411
516
|
workflow file carries. So D1 follows D2: MEDIUM when nothing in the workflow
|
|
412
517
|
consults upstream results at all, LOW when something does, and HIGH only when
|
|
@@ -508,5 +613,5 @@ That gap is the lesson worth keeping. The tool was least accurate on the reposit
|
|
|
508
613
|
BEST CI, which is the worst place for a linter to cry wolf, and no corpus average would have
|
|
509
614
|
surfaced it. The suite passed unchanged through every one of the four, 149 of it through the
|
|
510
615
|
first two fixes and 161 through the second two, so not one of them was covered by anything.
|
|
511
|
-
There are
|
|
616
|
+
There are 228 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
|
|
512
617
|
suite ever drift apart again.
|
|
@@ -22,7 +22,7 @@ be parsed**. A file it could not read is never counted as a file with no problem
|
|
|
22
22
|
|
|
23
23
|
| id | defect | why it matters |
|
|
24
24
|
|----|--------|----------------|
|
|
25
|
-
| D1 | a job depends on a skip-prone job and never reads `needs.*.result` |
|
|
25
|
+
| D1 | a job depends on a skip-prone job and never reads `needs.*.result` | **only reported with `--repo`**, when branch protection confirms the job is a required check |
|
|
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
|
|
@@ -30,10 +30,74 @@ that it was never right: D4 on 0 true of 18 sampled (0.1.5), and D2 on 0 true of
|
|
|
30
30
|
censused (0.1.6). The shapes they fired on are described in those sections, including
|
|
31
31
|
the one real hazard that is now undetected by design.
|
|
32
32
|
|
|
33
|
-
Measured precision, so the table above is not the only claim
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
### Measured precision, so the table above is not the only claim
|
|
34
|
+
|
|
35
|
+
Every figure below is hand-labelled. None is an estimate of an estimate.
|
|
36
|
+
|
|
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.
|
|
46
|
+
|
|
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.
|
|
51
|
+
|
|
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.
|
|
54
|
+
|
|
55
|
+
MEDIUM is not one population. Classified by shape, it splits sharply:
|
|
56
|
+
|
|
57
|
+
| shape | n | false |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| a test, audit or publish piped to `tee` or a file | 59 | **22%** |
|
|
60
|
+
| a captured value | 5 | 0% |
|
|
61
|
+
| other | 30 | 77% |
|
|
62
|
+
| a diagnostic head (`ls`, `df`, `--version`) | 23 | **96%** |
|
|
63
|
+
| `grep -q` assertion | 6 | **100%**, now suppressed |
|
|
64
|
+
|
|
65
|
+
The MEDIUM and LOW samples were drawn **uncapped**, which reverses the design of every
|
|
66
|
+
earlier sample here. A per-repository cap makes the estimator unbiased for the per-job
|
|
67
|
+
rate and about 16 points low for the per-finding rate, which is the defect described in
|
|
68
|
+
the 0.1.4 notes below.
|
|
69
|
+
|
|
70
|
+
### D1 says nothing unless branch protection confirms the check
|
|
71
|
+
|
|
72
|
+
D1's finding text says "a skipped job reports Success, and X never reads needs.Y.result",
|
|
73
|
+
which describes X running without its dependency. [GitHub documents that it does
|
|
74
|
+
not](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idneeds):
|
|
75
|
+
"If a job fails or is skipped, all jobs that need it are skipped unless the jobs use a
|
|
76
|
+
conditional expression that causes the job to continue."
|
|
77
|
+
|
|
78
|
+
Measured over 373 D1 findings on the corpus:
|
|
79
|
+
|
|
80
|
+
| | |
|
|
81
|
+
|---|---|
|
|
82
|
+
| 255 (68%) | the dependent would be **skipped too**, so what remains is "a skipped required check counts as success", which needs protection data |
|
|
83
|
+
| 101 (27%) | the dependent does run, but it is `release_lease`, `postSlackMessageOnFailure`, `ci-timing`, `merge-reports`: the reporting family the D2 census measured at **0 true of 27** |
|
|
84
|
+
| 10 (3%) | gutenberg status checks, known class-7 false positives |
|
|
85
|
+
| **~7** | candidates, precision never established |
|
|
86
|
+
|
|
87
|
+
An uncapped 40-finding sample of the current population labelled about **92% false**.
|
|
88
|
+
|
|
89
|
+
**The figure here used to read "65% false", and it was stale.** It came from a census of 54
|
|
90
|
+
findings taken at 0.1.4; that census covers 46 of today's 373 (12%), and among those the
|
|
91
|
+
rate is 76.7%. Quoting it against the whole population was the claim-rot pattern this
|
|
92
|
+
project keeps finding in other people's repositories.
|
|
93
|
+
|
|
94
|
+
D4 was **removed** for making an unverifiable branch-protection claim. D1 makes the same
|
|
95
|
+
claim, but unlike D4 the tool can check it: `--repo` reads the required contexts and
|
|
96
|
+
`resolve()` attributes a job to one. So the claim is gated on its evidence rather than the
|
|
97
|
+
detector deleted. **Without `--repo`, deadgate is a one-detector tool**, and the table
|
|
98
|
+
above should be read that way.
|
|
99
|
+
|
|
100
|
+
D3 is the only detector that produces HIGH.
|
|
37
101
|
|
|
38
102
|
Every finding carries a reproduction. A finding without one is an opinion, and this tool
|
|
39
103
|
does not emit opinions.
|
|
@@ -142,6 +206,43 @@ is a separate and harder problem and is not in this release.
|
|
|
142
206
|
## Licence
|
|
143
207
|
MIT
|
|
144
208
|
|
|
209
|
+
## 0.1.9 fixes a substitution scanner that was blind to shell quoting
|
|
210
|
+
|
|
211
|
+
Found by reading the segments 0.1.8 began reporting, not by a test. Several were mangled,
|
|
212
|
+
and a mangled segment means the reported filter and the head-can-fail judgement were both
|
|
213
|
+
computed on corrupted text. Three defects in one scanner, all from counting parens without
|
|
214
|
+
parsing:
|
|
215
|
+
|
|
216
|
+
| | shape | what it produced |
|
|
217
|
+
|---|---|---|
|
|
218
|
+
| quotes | `$(grep -o 'X\(A\|B\)' f \| cut ...)` | filter reported as `PATCH\` |
|
|
219
|
+
| fresh context | `"$(sed 's#^(a)#\1#p' f \| sort)"` | span closed at `+)` |
|
|
220
|
+
| process substitution | `$(comm <(a) <(b \| jq))` | everything after the first `<(...)` lost |
|
|
221
|
+
|
|
222
|
+
Inside `$( ... )` the body is parsed as new shell code, so a single quote quotes again even
|
|
223
|
+
when the substitution sits inside double quotes. The scanner now tracks single quotes,
|
|
224
|
+
double quotes, backslash escapes and `<( )`, and saves and restores the quote state across
|
|
225
|
+
a substitution boundary.
|
|
226
|
+
|
|
227
|
+
### D3's HIGH stratum is fully hand-labelled again
|
|
228
|
+
|
|
229
|
+
**94 findings, 65 true, 29 false, 30.9% false**, with no unlabelled residue. Across the
|
|
230
|
+
sequence: 51.2% before any narrowing, 35.1% after 0.1.7 against partial labels, 30.9% now
|
|
231
|
+
against complete ones.
|
|
232
|
+
|
|
233
|
+
Of the 17 that needed new labels because the reported segment moved, 11 are true. They are
|
|
234
|
+
the same defects named more precisely: `sha256sum f | cut -d' ' -f1` rather than the
|
|
235
|
+
`echo ... >> "$GITHUB_OUTPUT"` wrapped around it, and four `for x in $(find ... | sort)`
|
|
236
|
+
loops whose empty list means a check runs over nothing and passes.
|
|
237
|
+
|
|
238
|
+
### One thing deliberately left alone
|
|
239
|
+
|
|
240
|
+
Severity is judged on the **line** while the finding names the **segment**. That looks like
|
|
241
|
+
an inconsistency and is not: the segment is where the status is masked, the enclosing line
|
|
242
|
+
is how the bad value escapes. Judging severity on the segment alone was tried, and HIGH
|
|
243
|
+
fell from 94 to 30 with six tests red, because `sha256sum f | cut -d' ' -f1` on its own
|
|
244
|
+
shows no assignment and no export.
|
|
245
|
+
|
|
145
246
|
## 0.1.8 fixes two bugs the census found in D3 itself
|
|
146
247
|
|
|
147
248
|
Both were found by hand-labelling D3's HIGH findings, not by a test.
|
|
@@ -379,6 +480,10 @@ the 54 findings hand-labelled, 29 distinct jobs. **76% false per finding, 59% pe
|
|
|
379
480
|
exact, no interval. Even after all three fixes above it is 65% false, with eleven of the
|
|
380
481
|
survivors a single reporting job.
|
|
381
482
|
|
|
483
|
+
> That 65% describes the population as it stood at 0.1.4. It covers 46 of today's 373
|
|
484
|
+
> D1 findings, 12%, where the rate is 76.7%. D1 is no longer reported at all without
|
|
485
|
+
> `--repo`; see the precision section near the top.
|
|
486
|
+
|
|
382
487
|
"A required check is satisfied by a skipped job" needs a protection configuration no
|
|
383
488
|
workflow file carries. So D1 follows D2: MEDIUM when nothing in the workflow
|
|
384
489
|
consults upstream results at all, LOW when something does, and HIGH only when
|
|
@@ -480,5 +585,5 @@ That gap is the lesson worth keeping. The tool was least accurate on the reposit
|
|
|
480
585
|
BEST CI, which is the worst place for a linter to cry wolf, and no corpus average would have
|
|
481
586
|
surfaced it. The suite passed unchanged through every one of the four, 149 of it through the
|
|
482
587
|
first two fixes and 161 through the second two, so not one of them was covered by anything.
|
|
483
|
-
There are
|
|
588
|
+
There are 228 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
|
|
484
589
|
suite ever drift apart again.
|
|
@@ -10,7 +10,7 @@ import yaml
|
|
|
10
10
|
|
|
11
11
|
from .detectors import scan_workflow
|
|
12
12
|
from .protection import fetch, gh_api, repo_meta, selftest
|
|
13
|
-
from .resolve import attribute, resolve, workflow_is_callable
|
|
13
|
+
from .resolve import attribute, resolve, workflow_is_callable, REQUIRED
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
def workflows(root: pathlib.Path):
|
|
@@ -77,6 +77,32 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
77
77
|
callable_files.add(str(f))
|
|
78
78
|
for x in scan_workflow(doc, base=root):
|
|
79
79
|
why = ""
|
|
80
|
+
# D1 is reported ONLY when branch protection confirms the job is a required
|
|
81
|
+
# check. Without that confirmation its claim is not checkable, and measurement
|
|
82
|
+
# says the claim is almost always wrong:
|
|
83
|
+
#
|
|
84
|
+
# 373 findings on a 275-repo corpus
|
|
85
|
+
# -255 the dependent would be SKIPPED along with its need. GitHub documents
|
|
86
|
+
# this: "if a job fails or is skipped, all jobs that need it are
|
|
87
|
+
# skipped unless the jobs use a conditional expression that causes the
|
|
88
|
+
# job to continue". So the finding's text, "a skipped job reports
|
|
89
|
+
# Success and X never reads the result", describes a job running
|
|
90
|
+
# without its dependency. It does not run. What is left is "a skipped
|
|
91
|
+
# required check counts as success", which needs protection data.
|
|
92
|
+
# -101 the dependent does run, but it is release_lease, postSlackMessage*,
|
|
93
|
+
# ci-timing, merge-reports, consolidate-metrics. The reporting and
|
|
94
|
+
# notifier family, which the D2 census measured at 0 true of 27.
|
|
95
|
+
# -10 WordPress/gutenberg status checks, known class-7 false positives.
|
|
96
|
+
# ----
|
|
97
|
+
# ~7 candidates, and their precision was never established.
|
|
98
|
+
#
|
|
99
|
+
# An uncapped 40-finding sample of the current population labelled ~92% false.
|
|
100
|
+
# D4 was removed for making an unverifiable branch-protection claim; D1 makes
|
|
101
|
+
# the same claim but, unlike D4, the tool can actually check it with --repo.
|
|
102
|
+
# So the claim is gated on its evidence rather than the detector deleted.
|
|
103
|
+
if x.detector == "D1" and prot is None:
|
|
104
|
+
suppressed += 1
|
|
105
|
+
continue
|
|
80
106
|
if prot is not None:
|
|
81
107
|
job = ((doc or {}).get("jobs") or {}).get(x.job)
|
|
82
108
|
r = resolve(x.severity, x.job, job if isinstance(job, dict) else {}, prot,
|
|
@@ -85,6 +111,9 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
85
111
|
if r.moved:
|
|
86
112
|
why = f"{r.structural} -> {r.severity} {why}"
|
|
87
113
|
x = replace(x, severity=r.severity)
|
|
114
|
+
if x.detector == "D1" and r.verdict != REQUIRED:
|
|
115
|
+
suppressed += 1
|
|
116
|
+
continue
|
|
88
117
|
if x.severity == "LOW" and not args.all:
|
|
89
118
|
suppressed += 1
|
|
90
119
|
continue
|
|
@@ -119,6 +119,28 @@ def _job_blob(job) -> str:
|
|
|
119
119
|
return str(job)
|
|
120
120
|
|
|
121
121
|
|
|
122
|
+
_NEEDS_NAMED = re.compile(r"needs\.([A-Za-z0-9_\-]+)\.(?:result|outputs)")
|
|
123
|
+
_NEEDS_WILDCARD = re.compile(r"needs\.\*\.(?:result|outputs)")
|
|
124
|
+
|
|
125
|
+
|
|
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
|
+
|
|
122
144
|
def _reads_any_upstream_state(text: str) -> bool:
|
|
123
145
|
"""True when the text consults any upstream's result or outputs, by name, by wildcard, or
|
|
124
146
|
by serialising the whole `needs` context."""
|
|
@@ -280,6 +302,29 @@ def d1_skippable_upstream(jobs: dict, doc: dict | None = None,
|
|
|
280
302
|
if not skippable:
|
|
281
303
|
continue
|
|
282
304
|
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.
|
|
307
|
+
#
|
|
308
|
+
# Arhan Canli's point in the dev.to thread is right in principle: needs.X.result,
|
|
309
|
+
# needs.* and toJSON(needs) are one rule, so comparing the referenced set against
|
|
310
|
+
# the `needs:` list and reporting only unreferenced upstreams would stop the
|
|
311
|
+
# spelling from mattering, and would stop a gate naming eight of nine needs from
|
|
312
|
+
# suppressing the finding about the ninth.
|
|
313
|
+
#
|
|
314
|
+
# It was implemented and measured against this corpus before being rejected. It
|
|
315
|
+
# surfaces 396 additional findings, D1 going 373 to 769, and classified by job
|
|
316
|
+
# kind they are:
|
|
317
|
+
#
|
|
318
|
+
# 139 35% ship/publish
|
|
319
|
+
# 96 24% other
|
|
320
|
+
# 91 23% reporting/cleanup
|
|
321
|
+
# 66 17% check/test
|
|
322
|
+
# 4 1% gate-named
|
|
323
|
+
#
|
|
324
|
+
# 58% are the two families the D2 census measured at 0 true of 27, and 1% are
|
|
325
|
+
# jobs that name themselves a gate. The rule is sound; the population it reaches
|
|
326
|
+
# in D1 is the one already proven false. Revisit if D1's trigger is ever narrowed
|
|
327
|
+
# to jobs that are plausibly gates.
|
|
283
328
|
if _reads_any_upstream_state(text):
|
|
284
329
|
continue
|
|
285
330
|
sev = _d1_severity(name, job, doc or {}, _workflow_has_any_gate(jobs))
|
|
@@ -333,33 +378,92 @@ _ONLY_PRINTED = re.compile(r"^\s*echo\b(?!.*(>>|>|\$GITHUB_OUTPUT|\$GITHUB_ENV))
|
|
|
333
378
|
|
|
334
379
|
|
|
335
380
|
def _substitution_bodies(line: str) -> list[str]:
|
|
336
|
-
"""Bodies of $( ... ), innermost first, so a pipe inside one is analysed on its own.
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
381
|
+
"""Bodies of $( ... ), innermost first, so a pipe inside one is analysed on its own.
|
|
382
|
+
|
|
383
|
+
Delegates to `_substitution_spans`, which respects shell quoting. The hand-rolled
|
|
384
|
+
scanner this replaced counted parens blind to quotes and escapes, so an escaped paren
|
|
385
|
+
inside a quoted regex closed the substitution early and returned a truncated body.
|
|
386
|
+
It also had an off-by-one before that: `while i < len(line) - 1` never examined the
|
|
387
|
+
final character, so a substitution closing at end of line was never closed at all.
|
|
388
|
+
"""
|
|
389
|
+
return [line[a:b] for a, b in _substitution_spans(line)]
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def _substitution_spans(text: str) -> list[tuple[int, int]]:
|
|
393
|
+
r"""(start, end) of every `$( ... )` body, innermost first, respecting shell quoting.
|
|
394
|
+
|
|
395
|
+
Three things this has to get right, each found by reading a mangled segment in a real
|
|
396
|
+
finding rather than by a test:
|
|
397
|
+
|
|
398
|
+
1. Quotes. Counting `$(` and `)` blind made an escaped paren in a quoted regex close
|
|
399
|
+
the substitution early:
|
|
400
|
+
|
|
401
|
+
version=$(grep -o 'LLVM_VERSION_\(MAJOR\|MINOR\|PATCH\) [0-9]\+' f | cut -d ' ' -f 2)
|
|
402
|
+
|
|
403
|
+
reported its filter as `PATCH\`.
|
|
404
|
+
|
|
405
|
+
2. A substitution body is parsed FRESH. Inside double quotes a single quote is
|
|
406
|
+
literal, but inside `$( ... )` nested in double quotes it quotes again, so
|
|
407
|
+
|
|
408
|
+
touched="$(sed -nE 's#^(packages/[^/]+)/.*##p' f | sort -u)"
|
|
409
|
+
|
|
410
|
+
has its `)` protected by the inner single quotes. Treating the body as still
|
|
411
|
+
double-quoted closed the span at `+)` and produced `touched="/.*##p' f | sort -u)"`.
|
|
412
|
+
|
|
413
|
+
3. Process substitution. `<( ... )` and `>( ... )` take a paren too, and ignoring them
|
|
414
|
+
let their closing paren close the enclosing `$(`:
|
|
415
|
+
|
|
416
|
+
count_new_js=$(comm -1 -2 <(git diff ...) <(gh pr view ... | jq ...))
|
|
417
|
+
|
|
418
|
+
lost everything after the first `<(...)`.
|
|
419
|
+
"""
|
|
420
|
+
spans, stack = [], []
|
|
421
|
+
i, n = 0, len(text)
|
|
422
|
+
in_single = in_double = False
|
|
423
|
+
while i < n:
|
|
424
|
+
c = text[i]
|
|
425
|
+
if in_single:
|
|
426
|
+
if c == "'":
|
|
427
|
+
in_single = False
|
|
428
|
+
i += 1
|
|
429
|
+
continue
|
|
430
|
+
if c == "\\":
|
|
431
|
+
i += 2 # escaped character, whatever it is
|
|
432
|
+
continue
|
|
433
|
+
if c == "'" and not in_double:
|
|
434
|
+
in_single = True; i += 1; continue
|
|
435
|
+
if c == '"':
|
|
436
|
+
in_double = not in_double; i += 1; continue
|
|
437
|
+
# `$(`, `<(` and `>(` all open a paren that must be matched. A command
|
|
438
|
+
# substitution body is parsed fresh, so the quote state is saved and reset.
|
|
439
|
+
if c in "$<>" and i + 1 < n and text[i + 1] == "(":
|
|
440
|
+
stack.append((i + 2, in_double, c))
|
|
441
|
+
in_double = False
|
|
442
|
+
i += 2
|
|
443
|
+
continue
|
|
444
|
+
if c == ")" and stack:
|
|
445
|
+
start, saved_double, kind = stack.pop()
|
|
446
|
+
in_double = saved_double
|
|
447
|
+
if kind == "$":
|
|
448
|
+
spans.append((start, i))
|
|
348
449
|
i += 1
|
|
349
|
-
return
|
|
450
|
+
return spans
|
|
350
451
|
|
|
351
452
|
|
|
352
453
|
def _strip_substitutions(text: str) -> str:
|
|
353
|
-
"""The text with every `$( ... )` removed, so the OUTER command
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
454
|
+
"""The text with every top-level `$( ... )` removed, so the OUTER command stands alone."""
|
|
455
|
+
spans = _substitution_spans(text)
|
|
456
|
+
if not spans:
|
|
457
|
+
return text
|
|
458
|
+
top = []
|
|
459
|
+
for a, b in sorted(spans):
|
|
460
|
+
if not top or a > top[-1][1]:
|
|
461
|
+
top.append((a, b))
|
|
462
|
+
out, prev = [], 0
|
|
463
|
+
for a, b in top:
|
|
464
|
+
out.append(text[prev:a - 2]) # drop the "$(" too
|
|
465
|
+
prev = b + 1 # and the ")"
|
|
466
|
+
out.append(text[prev:])
|
|
363
467
|
return "".join(out)
|
|
364
468
|
|
|
365
469
|
|
|
@@ -507,6 +611,29 @@ def _every_use_is_safe(var: str, body: str, assign_line: str) -> bool:
|
|
|
507
611
|
return True
|
|
508
612
|
|
|
509
613
|
|
|
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.
|
|
623
|
+
# All 6 such findings in D3's MEDIUM census were false, as were the ones in the HIGH
|
|
624
|
+
# census, and no labelled true finding has this shape.
|
|
625
|
+
#
|
|
626
|
+
# The residual case is a head that prints a matching line and THEN fails. That is real but
|
|
627
|
+
# narrow, and reporting every assertion to catch it is the trade this corpus says no to.
|
|
628
|
+
_TAIL_IS_ASSERTION = re.compile(r"^grep\b.*(?:\s-\w*q|\s--quiet|\s--silent)")
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
def _tail_is_a_content_assertion(segment: str) -> bool:
|
|
632
|
+
"""True when the final filter is a `grep -q`, which fails when its input is empty."""
|
|
633
|
+
tail = segment.rsplit("|", 1)[1].strip() if "|" in segment else ""
|
|
634
|
+
return bool(_TAIL_IS_ASSERTION.match(tail))
|
|
635
|
+
|
|
636
|
+
|
|
510
637
|
def _masked_status_can_matter(line: str, body: str) -> bool:
|
|
511
638
|
"""Could this masked exit status change any outcome?"""
|
|
512
639
|
if not _LINE_CONSUMES.search(line):
|
|
@@ -615,6 +742,8 @@ def d3_pipe_masked_exit(jobs: dict, doc: dict | None = None) -> list[Finding]:
|
|
|
615
742
|
for segment, filt in _pipeline_candidates(line):
|
|
616
743
|
if filt not in FILTERS or not _segment_head_can_fail(segment):
|
|
617
744
|
continue
|
|
745
|
+
if _tail_is_a_content_assertion(segment):
|
|
746
|
+
continue
|
|
618
747
|
assigned = (re.match(r"([A-Za-z_][A-Za-z0-9_]*)=", line) or [None, ""])[1]
|
|
619
748
|
if _result_is_emptiness_checked(assigned, body):
|
|
620
749
|
continue
|
|
@@ -625,6 +754,13 @@ def d3_pipe_masked_exit(jobs: dict, doc: dict | None = None) -> list[Finding]:
|
|
|
625
754
|
label = step.get("name") or line[:40]
|
|
626
755
|
found.append(Finding(
|
|
627
756
|
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.
|
|
628
764
|
severity=_d3_severity(step, name, job, doc or {}, line),
|
|
629
765
|
job=name,
|
|
630
766
|
title="exit status masked by a pipe",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: deadgate
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.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
|
|
@@ -50,7 +50,7 @@ be parsed**. A file it could not read is never counted as a file with no problem
|
|
|
50
50
|
|
|
51
51
|
| id | defect | why it matters |
|
|
52
52
|
|----|--------|----------------|
|
|
53
|
-
| D1 | a job depends on a skip-prone job and never reads `needs.*.result` |
|
|
53
|
+
| D1 | a job depends on a skip-prone job and never reads `needs.*.result` | **only reported with `--repo`**, when branch protection confirms the job is a required check |
|
|
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
|
|
@@ -58,10 +58,74 @@ that it was never right: D4 on 0 true of 18 sampled (0.1.5), and D2 on 0 true of
|
|
|
58
58
|
censused (0.1.6). The shapes they fired on are described in those sections, including
|
|
59
59
|
the one real hazard that is now undetected by design.
|
|
60
60
|
|
|
61
|
-
Measured precision, so the table above is not the only claim
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
### Measured precision, so the table above is not the only claim
|
|
62
|
+
|
|
63
|
+
Every figure below is hand-labelled. None is an estimate of an estimate.
|
|
64
|
+
|
|
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.
|
|
74
|
+
|
|
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.
|
|
79
|
+
|
|
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.
|
|
82
|
+
|
|
83
|
+
MEDIUM is not one population. Classified by shape, it splits sharply:
|
|
84
|
+
|
|
85
|
+
| shape | n | false |
|
|
86
|
+
|---|---|---|
|
|
87
|
+
| a test, audit or publish piped to `tee` or a file | 59 | **22%** |
|
|
88
|
+
| a captured value | 5 | 0% |
|
|
89
|
+
| other | 30 | 77% |
|
|
90
|
+
| a diagnostic head (`ls`, `df`, `--version`) | 23 | **96%** |
|
|
91
|
+
| `grep -q` assertion | 6 | **100%**, now suppressed |
|
|
92
|
+
|
|
93
|
+
The MEDIUM and LOW samples were drawn **uncapped**, which reverses the design of every
|
|
94
|
+
earlier sample here. A per-repository cap makes the estimator unbiased for the per-job
|
|
95
|
+
rate and about 16 points low for the per-finding rate, which is the defect described in
|
|
96
|
+
the 0.1.4 notes below.
|
|
97
|
+
|
|
98
|
+
### D1 says nothing unless branch protection confirms the check
|
|
99
|
+
|
|
100
|
+
D1's finding text says "a skipped job reports Success, and X never reads needs.Y.result",
|
|
101
|
+
which describes X running without its dependency. [GitHub documents that it does
|
|
102
|
+
not](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idneeds):
|
|
103
|
+
"If a job fails or is skipped, all jobs that need it are skipped unless the jobs use a
|
|
104
|
+
conditional expression that causes the job to continue."
|
|
105
|
+
|
|
106
|
+
Measured over 373 D1 findings on the corpus:
|
|
107
|
+
|
|
108
|
+
| | |
|
|
109
|
+
|---|---|
|
|
110
|
+
| 255 (68%) | the dependent would be **skipped too**, so what remains is "a skipped required check counts as success", which needs protection data |
|
|
111
|
+
| 101 (27%) | the dependent does run, but it is `release_lease`, `postSlackMessageOnFailure`, `ci-timing`, `merge-reports`: the reporting family the D2 census measured at **0 true of 27** |
|
|
112
|
+
| 10 (3%) | gutenberg status checks, known class-7 false positives |
|
|
113
|
+
| **~7** | candidates, precision never established |
|
|
114
|
+
|
|
115
|
+
An uncapped 40-finding sample of the current population labelled about **92% false**.
|
|
116
|
+
|
|
117
|
+
**The figure here used to read "65% false", and it was stale.** It came from a census of 54
|
|
118
|
+
findings taken at 0.1.4; that census covers 46 of today's 373 (12%), and among those the
|
|
119
|
+
rate is 76.7%. Quoting it against the whole population was the claim-rot pattern this
|
|
120
|
+
project keeps finding in other people's repositories.
|
|
121
|
+
|
|
122
|
+
D4 was **removed** for making an unverifiable branch-protection claim. D1 makes the same
|
|
123
|
+
claim, but unlike D4 the tool can check it: `--repo` reads the required contexts and
|
|
124
|
+
`resolve()` attributes a job to one. So the claim is gated on its evidence rather than the
|
|
125
|
+
detector deleted. **Without `--repo`, deadgate is a one-detector tool**, and the table
|
|
126
|
+
above should be read that way.
|
|
127
|
+
|
|
128
|
+
D3 is the only detector that produces HIGH.
|
|
65
129
|
|
|
66
130
|
Every finding carries a reproduction. A finding without one is an opinion, and this tool
|
|
67
131
|
does not emit opinions.
|
|
@@ -170,6 +234,43 @@ is a separate and harder problem and is not in this release.
|
|
|
170
234
|
## Licence
|
|
171
235
|
MIT
|
|
172
236
|
|
|
237
|
+
## 0.1.9 fixes a substitution scanner that was blind to shell quoting
|
|
238
|
+
|
|
239
|
+
Found by reading the segments 0.1.8 began reporting, not by a test. Several were mangled,
|
|
240
|
+
and a mangled segment means the reported filter and the head-can-fail judgement were both
|
|
241
|
+
computed on corrupted text. Three defects in one scanner, all from counting parens without
|
|
242
|
+
parsing:
|
|
243
|
+
|
|
244
|
+
| | shape | what it produced |
|
|
245
|
+
|---|---|---|
|
|
246
|
+
| quotes | `$(grep -o 'X\(A\|B\)' f \| cut ...)` | filter reported as `PATCH\` |
|
|
247
|
+
| fresh context | `"$(sed 's#^(a)#\1#p' f \| sort)"` | span closed at `+)` |
|
|
248
|
+
| process substitution | `$(comm <(a) <(b \| jq))` | everything after the first `<(...)` lost |
|
|
249
|
+
|
|
250
|
+
Inside `$( ... )` the body is parsed as new shell code, so a single quote quotes again even
|
|
251
|
+
when the substitution sits inside double quotes. The scanner now tracks single quotes,
|
|
252
|
+
double quotes, backslash escapes and `<( )`, and saves and restores the quote state across
|
|
253
|
+
a substitution boundary.
|
|
254
|
+
|
|
255
|
+
### D3's HIGH stratum is fully hand-labelled again
|
|
256
|
+
|
|
257
|
+
**94 findings, 65 true, 29 false, 30.9% false**, with no unlabelled residue. Across the
|
|
258
|
+
sequence: 51.2% before any narrowing, 35.1% after 0.1.7 against partial labels, 30.9% now
|
|
259
|
+
against complete ones.
|
|
260
|
+
|
|
261
|
+
Of the 17 that needed new labels because the reported segment moved, 11 are true. They are
|
|
262
|
+
the same defects named more precisely: `sha256sum f | cut -d' ' -f1` rather than the
|
|
263
|
+
`echo ... >> "$GITHUB_OUTPUT"` wrapped around it, and four `for x in $(find ... | sort)`
|
|
264
|
+
loops whose empty list means a check runs over nothing and passes.
|
|
265
|
+
|
|
266
|
+
### One thing deliberately left alone
|
|
267
|
+
|
|
268
|
+
Severity is judged on the **line** while the finding names the **segment**. That looks like
|
|
269
|
+
an inconsistency and is not: the segment is where the status is masked, the enclosing line
|
|
270
|
+
is how the bad value escapes. Judging severity on the segment alone was tried, and HIGH
|
|
271
|
+
fell from 94 to 30 with six tests red, because `sha256sum f | cut -d' ' -f1` on its own
|
|
272
|
+
shows no assignment and no export.
|
|
273
|
+
|
|
173
274
|
## 0.1.8 fixes two bugs the census found in D3 itself
|
|
174
275
|
|
|
175
276
|
Both were found by hand-labelling D3's HIGH findings, not by a test.
|
|
@@ -407,6 +508,10 @@ the 54 findings hand-labelled, 29 distinct jobs. **76% false per finding, 59% pe
|
|
|
407
508
|
exact, no interval. Even after all three fixes above it is 65% false, with eleven of the
|
|
408
509
|
survivors a single reporting job.
|
|
409
510
|
|
|
511
|
+
> That 65% describes the population as it stood at 0.1.4. It covers 46 of today's 373
|
|
512
|
+
> D1 findings, 12%, where the rate is 76.7%. D1 is no longer reported at all without
|
|
513
|
+
> `--repo`; see the precision section near the top.
|
|
514
|
+
|
|
410
515
|
"A required check is satisfied by a skipped job" needs a protection configuration no
|
|
411
516
|
workflow file carries. So D1 follows D2: MEDIUM when nothing in the workflow
|
|
412
517
|
consults upstream results at all, LOW when something does, and HIGH only when
|
|
@@ -508,5 +613,5 @@ That gap is the lesson worth keeping. The tool was least accurate on the reposit
|
|
|
508
613
|
BEST CI, which is the worst place for a linter to cry wolf, and no corpus average would have
|
|
509
614
|
surfaced it. The suite passed unchanged through every one of the four, 149 of it through the
|
|
510
615
|
first two fixes and 161 through the second two, so not one of them was covered by anything.
|
|
511
|
-
There are
|
|
616
|
+
There are 228 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
|
|
512
617
|
suite ever drift apart again.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "deadgate"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.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"
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""D1 is reported ONLY when branch protection confirms the job is a required check.
|
|
2
|
+
|
|
3
|
+
D1's finding text says "a skipped job reports Success, and X never reads
|
|
4
|
+
needs.Y.result", which describes X running without its dependency. GitHub documents that
|
|
5
|
+
it does not run:
|
|
6
|
+
|
|
7
|
+
"If a job fails or is skipped, all jobs that need it are skipped unless the jobs use
|
|
8
|
+
a conditional expression that causes the job to continue."
|
|
9
|
+
-- docs.github.com, jobs.<job_id>.needs
|
|
10
|
+
|
|
11
|
+
Measured on the 275-repo corpus, 373 D1 findings:
|
|
12
|
+
|
|
13
|
+
255 68% the dependent would be SKIPPED too, so the text is wrong and what remains
|
|
14
|
+
is "a skipped required check counts as success", which needs protection data
|
|
15
|
+
101 27% the dependent does run, but it is release_lease, postSlackMessageOnFailure,
|
|
16
|
+
ci-timing, merge-reports, consolidate-metrics: the reporting and notifier
|
|
17
|
+
family the D2 census measured at 0 true of 27
|
|
18
|
+
10 3% WordPress/gutenberg status checks, known class-7 false positives
|
|
19
|
+
---
|
|
20
|
+
~7 candidates, precision never established
|
|
21
|
+
|
|
22
|
+
An uncapped 40-finding sample of the current population labelled about 92% false.
|
|
23
|
+
|
|
24
|
+
D4 was REMOVED for making an unverifiable branch-protection claim. D1 makes the same
|
|
25
|
+
claim, but unlike D4 the tool can check it: `--repo` reads the required contexts and
|
|
26
|
+
`resolve()` attributes a job to one. So the claim is gated on its evidence rather than
|
|
27
|
+
the detector deleted. Without `--repo`, D1 says nothing.
|
|
28
|
+
"""
|
|
29
|
+
import textwrap
|
|
30
|
+
|
|
31
|
+
import pytest
|
|
32
|
+
|
|
33
|
+
from deadgate.cli import main
|
|
34
|
+
from deadgate.protection import Protection, PROTECTED
|
|
35
|
+
|
|
36
|
+
WORKFLOW = textwrap.dedent("""
|
|
37
|
+
on: [pull_request]
|
|
38
|
+
jobs:
|
|
39
|
+
build:
|
|
40
|
+
if: ${{ github.event_name == 'push' }}
|
|
41
|
+
runs-on: ubuntu-latest
|
|
42
|
+
steps: [{run: make}]
|
|
43
|
+
verify-tests:
|
|
44
|
+
needs: [build]
|
|
45
|
+
if: ${{ always() }}
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
steps: [{run: pytest}]
|
|
48
|
+
""")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@pytest.fixture
|
|
52
|
+
def tree(tmp_path):
|
|
53
|
+
wf = tmp_path / ".github" / "workflows"
|
|
54
|
+
wf.mkdir(parents=True)
|
|
55
|
+
(wf / "ci.yml").write_text(WORKFLOW)
|
|
56
|
+
return tmp_path
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _run(tree, capsys, argv_extra=()):
|
|
60
|
+
rc = main([str(tree), "--all", *argv_extra])
|
|
61
|
+
return rc, capsys.readouterr().out
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_d1_says_nothing_without_protection_data(tree, capsys):
|
|
65
|
+
_, out = _run(tree, capsys)
|
|
66
|
+
assert "[D1/" not in out, out
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_the_workflow_really_does_trigger_d1(tree):
|
|
70
|
+
"""Without this the test above passes because the fixture produces no finding."""
|
|
71
|
+
import yaml
|
|
72
|
+
from deadgate.detectors import d1_skippable_upstream
|
|
73
|
+
jobs = yaml.safe_load(WORKFLOW)["jobs"]
|
|
74
|
+
assert [f.detector for f in d1_skippable_upstream(jobs, yaml.safe_load(WORKFLOW))] == ["D1"]
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_d1_is_reported_when_protection_confirms_the_check(tree, capsys, monkeypatch):
|
|
78
|
+
"""With --repo and a required context that matches, the claim is checkable and made."""
|
|
79
|
+
import deadgate.cli as cli
|
|
80
|
+
monkeypatch.setattr(cli, "gh_api", lambda: object())
|
|
81
|
+
monkeypatch.setattr(cli, "selftest", lambda api: (True, ""))
|
|
82
|
+
monkeypatch.setattr(cli, "repo_meta", lambda repo, api: ("main", True))
|
|
83
|
+
monkeypatch.setattr(cli, "fetch", lambda *a, **k: Protection(
|
|
84
|
+
state=PROTECTED, required=frozenset({"verify-tests"}), complete=True))
|
|
85
|
+
_, out = _run(tree, capsys, ("--repo", "o/r"))
|
|
86
|
+
assert "[D1/" in out, out
|
|
87
|
+
assert "REQUIRED" in out
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_d1_stays_silent_when_protection_says_the_job_is_not_required(tree, capsys, monkeypatch):
|
|
91
|
+
"""The other direction. Protection data that does NOT attribute the job is not a
|
|
92
|
+
licence to report it; it is evidence the claim is wrong."""
|
|
93
|
+
import deadgate.cli as cli
|
|
94
|
+
monkeypatch.setattr(cli, "gh_api", lambda: object())
|
|
95
|
+
monkeypatch.setattr(cli, "selftest", lambda api: (True, ""))
|
|
96
|
+
monkeypatch.setattr(cli, "repo_meta", lambda repo, api: ("main", True))
|
|
97
|
+
monkeypatch.setattr(cli, "fetch", lambda *a, **k: Protection(
|
|
98
|
+
state=PROTECTED, required=frozenset({"something-else"}), complete=True))
|
|
99
|
+
_, out = _run(tree, capsys, ("--repo", "o/r"))
|
|
100
|
+
assert "[D1/" not in out, out
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_d3_is_unaffected_by_the_d1_gate(tmp_path, capsys):
|
|
104
|
+
wf = tmp_path / ".github" / "workflows"
|
|
105
|
+
wf.mkdir(parents=True)
|
|
106
|
+
wf.joinpath("ci.yml").write_text(textwrap.dedent("""
|
|
107
|
+
on: [pull_request]
|
|
108
|
+
jobs:
|
|
109
|
+
build:
|
|
110
|
+
runs-on: ubuntu-latest
|
|
111
|
+
steps:
|
|
112
|
+
- run: |
|
|
113
|
+
echo "d=$(sha256sum f | cut -d ' ' -f 1)" >> "$GITHUB_OUTPUT"
|
|
114
|
+
"""))
|
|
115
|
+
main([str(tmp_path), "--all"])
|
|
116
|
+
assert "[D3/" in capsys.readouterr().out
|
|
@@ -190,3 +190,148 @@ def test_a_step_still_reports_only_one_finding():
|
|
|
190
190
|
"""The break stays. Two masked pipelines in one step report once, not twice."""
|
|
191
191
|
run = 'a=$(curl -s u1 | jq -r .x)\nb=$(curl -s u2 | jq -r .y)\necho "$a$b" >> "$GITHUB_OUTPUT"'
|
|
192
192
|
assert len(_high(run)) == 1
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
# ---------------------------------------------------------------------------
|
|
196
|
+
# Shell quoting in the substitution scanner.
|
|
197
|
+
#
|
|
198
|
+
# The scanner counted `$(` and `)` with no idea of quotes or escapes. An escaped paren
|
|
199
|
+
# inside a quoted regex closed the substitution early:
|
|
200
|
+
#
|
|
201
|
+
# version=$(grep -o 'LLVM_VERSION_\(MAJOR\|MINOR\|PATCH\) [0-9]\+' f | cut -d ' ' -f 2)
|
|
202
|
+
#
|
|
203
|
+
# gave a body of `grep -o 'LLVM_VERSION_\(MAJOR\|MINOR\|PATCH\` and an outer remainder of
|
|
204
|
+
# `version= [0-9]\+' f | cut -d ' ' -f 2)`, so the reported FILTER was `PATCH\`. That was
|
|
205
|
+
# survivable while the scan only produced a benign/not-benign hint, and stopped being
|
|
206
|
+
# survivable in 0.1.8, which began reporting the segment itself.
|
|
207
|
+
#
|
|
208
|
+
# Found by reading the reported segments of real findings, not by a test.
|
|
209
|
+
|
|
210
|
+
from deadgate.detectors import _substitution_bodies, _substitution_spans
|
|
211
|
+
|
|
212
|
+
LLVM = r"""version=$(grep -o 'LLVM_VERSION_\(MAJOR\|MINOR\|PATCH\) [0-9]\+' f | cut -d ' ' -f 2)"""
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def test_an_escaped_paren_in_a_quoted_regex_does_not_close_the_substitution():
|
|
216
|
+
bodies = _substitution_bodies(LLVM)
|
|
217
|
+
assert len(bodies) == 1, bodies
|
|
218
|
+
assert bodies[0].startswith("grep -o") and bodies[0].endswith("-f 2"), bodies[0]
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def test_the_outer_text_is_what_is_left_after_the_whole_substitution():
|
|
222
|
+
assert _strip_substitutions(LLVM).strip() == "version="
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def test_the_reported_filter_is_the_real_one_not_regex_debris():
|
|
226
|
+
filters = [f for _, f in _pipeline_candidates(LLVM)]
|
|
227
|
+
assert filters == ["cut"], filters
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def test_single_quotes_make_everything_literal():
|
|
231
|
+
"""No escape processing inside single quotes, so a lone backslash is just a character."""
|
|
232
|
+
assert _substitution_bodies(r"""echo '$(not a substitution)'""") == []
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def test_a_substitution_inside_double_quotes_is_still_found():
|
|
236
|
+
assert _substitution_bodies('echo "$(date | cut -c1-3)"') == ["date | cut -c1-3"]
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def test_nested_substitutions_come_innermost_first():
|
|
240
|
+
bodies = _substitution_bodies('a=$(echo "$(uname -s)" | tr a-z A-Z)')
|
|
241
|
+
assert bodies[0] == "uname -s", bodies
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def test_a_single_quote_inside_double_quotes_is_not_a_quote_opener():
|
|
245
|
+
"""An apostrophe in ordinary prose must not swallow the rest of the line.
|
|
246
|
+
|
|
247
|
+
Without double-quote tracking the `'` in "it's" starts single-quote mode and the
|
|
248
|
+
substitution after it is never seen.
|
|
249
|
+
"""
|
|
250
|
+
assert _substitution_bodies("""echo "it's $(date | cut -c1-3)" """) == ["date | cut -c1-3"]
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def test_strip_removes_whole_substitutions_not_nested_pieces():
|
|
254
|
+
"""Only TOP-LEVEL spans are removed. Removing nested ones separately would delete
|
|
255
|
+
the same characters twice and leave fragments of the outer command behind."""
|
|
256
|
+
assert _strip_substitutions('a=$(echo "$(uname -s)" | tr a-z A-Z) | tee f').strip() == "a= | tee f"
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def test_an_escaped_dollar_does_not_open_a_substitution():
|
|
260
|
+
r"""`\$(` is a literal dollar followed by a paren, not a command substitution.
|
|
261
|
+
|
|
262
|
+
This is what the backslash branch of the scanner is for. The escaped-quote case does
|
|
263
|
+
NOT discriminate, because `$(` is recognised inside double quotes anyway, so dropping
|
|
264
|
+
escape handling changes nothing there: a mutation removing the branch survived against
|
|
265
|
+
that test and only died against this one.
|
|
266
|
+
"""
|
|
267
|
+
assert _substitution_bodies(r"""echo \$(ls | head -1)""") == []
|
|
268
|
+
# and the unescaped form still is one
|
|
269
|
+
assert _substitution_bodies("""echo $(ls | head -1)""") == ["ls | head -1"]
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def test_a_substitution_body_is_parsed_fresh():
|
|
273
|
+
r"""Inside double quotes a single quote is literal, but inside `$( ... )` nested in
|
|
274
|
+
double quotes it quotes again, because the body is parsed as new shell code.
|
|
275
|
+
|
|
276
|
+
Treating the body as still double-quoted let the `)` in a quoted sed expression close
|
|
277
|
+
the span early, reporting `touched="/.*#\1#p' f | sort -u)"` as the segment.
|
|
278
|
+
"""
|
|
279
|
+
line = """touched="$(sed -nE 's#^(packages/[^/]+)/.*#\\1#p' f | sort -u)" """
|
|
280
|
+
assert _strip_substitutions(line).strip() == 'touched=""'
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def test_process_substitution_parens_are_matched_too():
|
|
284
|
+
r"""`<( ... )` takes a paren. Ignoring it let its closing paren close the enclosing
|
|
285
|
+
`$(`, losing everything after the first one."""
|
|
286
|
+
line = """count_new_js=$(comm -1 -2 <(git diff --name-only a b) <(gh pr view 1 --json files | jq -r '.f'))"""
|
|
287
|
+
assert _strip_substitutions(line).strip() == "count_new_js="
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def test_a_process_substitution_is_not_reported_as_a_command_substitution():
|
|
291
|
+
"""Only `$( )` bodies are returned; `<( )` is matched for paren balance only."""
|
|
292
|
+
bodies = _substitution_bodies("diff <(sort a | uniq) <(sort b)")
|
|
293
|
+
assert bodies == [], bodies
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
# ---------------------------------------------------------------------------
|
|
297
|
+
# `cmd | grep -q PATTERN` is a content assertion, not a masked status.
|
|
298
|
+
#
|
|
299
|
+
# Demonstrable rather than likely. When the head fails it emits nothing, grep matches
|
|
300
|
+
# nothing and exits 1, so the pipeline fails exactly when the head does:
|
|
301
|
+
#
|
|
302
|
+
# $ nosuchcommand 2>/dev/null | grep -q arm64 ; echo $?
|
|
303
|
+
# 1
|
|
304
|
+
#
|
|
305
|
+
# All 6 findings of this shape in D3's 153-finding MEDIUM census were false, as were the
|
|
306
|
+
# ones in the HIGH census, and no labelled true finding has it.
|
|
307
|
+
#
|
|
308
|
+
# This also corrected the corpus. b3_pipe_masked_exit, the canonical D3 broken fixture,
|
|
309
|
+
# was `curl -s https://example.test/health | grep -q ok`, which is NOT a D3 defect: the
|
|
310
|
+
# finding's own text says "a failure upstream of the pipe passes" and that is false here.
|
|
311
|
+
# The real hazard in that line is `curl -s` without `-f`, which does not fail on HTTP 500.
|
|
312
|
+
# The fixture now carries a genuine masking and the grep -q form moved to corpus/good/.
|
|
313
|
+
|
|
314
|
+
from deadgate.detectors import _tail_is_a_content_assertion
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def test_a_grep_q_tail_is_an_assertion():
|
|
318
|
+
for seg in ("file ./build/cli | grep -q arm64",
|
|
319
|
+
"nm retroarch | grep -q -- '-lpulse'",
|
|
320
|
+
"cmd | grep -sq pattern",
|
|
321
|
+
"cmd | grep --quiet pattern"):
|
|
322
|
+
assert _tail_is_a_content_assertion(seg), seg
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def test_a_plain_grep_tail_is_not_an_assertion():
|
|
326
|
+
"""Without -q the output is the point, so the masked status still matters."""
|
|
327
|
+
for seg in ("cmd | grep pattern", "cmd | grep -E 'a|b'", "cmd | grep -v skip"):
|
|
328
|
+
assert not _tail_is_a_content_assertion(seg), seg
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def test_a_grep_q_pipeline_is_not_reported():
|
|
332
|
+
assert not _high("file ./build/cli | grep -q arm64\nexit 1")
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def test_the_same_pipeline_without_q_is_still_reported():
|
|
336
|
+
"""The counter-case, so this cannot become a blanket mute on grep."""
|
|
337
|
+
assert _high('v=$(file ./build/cli | grep arm64)\necho "v=$v" >> "$GITHUB_OUTPUT"\nexit 1')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|