deadgate 0.1.9__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.9 → deadgate-0.2.0}/PKG-INFO +75 -7
- {deadgate-0.1.9 → deadgate-0.2.0}/README.md +74 -6
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate/cli.py +30 -1
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate/detectors.py +70 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate.egg-info/PKG-INFO +75 -7
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate.egg-info/SOURCES.txt +1 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/pyproject.toml +1 -1
- deadgate-0.2.0/tests/test_d1_requires_protection.py +116 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/tests/test_d3_narrowing.py +44 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/LICENSE +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate/__init__.py +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate/checknames.py +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate/predicates.py +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate/protection.py +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate/resolve.py +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate/sandbox.py +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate.egg-info/dependency_links.txt +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate.egg-info/entry_points.txt +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate.egg-info/requires.txt +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/deadgate.egg-info/top_level.txt +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/setup.cfg +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/tests/test_api_status_gates.py +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/tests/test_corpus.py +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/tests/test_predicates.py +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/tests/test_protection.py +0 -0
- {deadgate-0.1.9 → deadgate-0.2.0}/tests/test_sandbox.py +0 -0
- {deadgate-0.1.9 → 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.
|
|
@@ -444,6 +508,10 @@ the 54 findings hand-labelled, 29 distinct jobs. **76% false per finding, 59% pe
|
|
|
444
508
|
exact, no interval. Even after all three fixes above it is 65% false, with eleven of the
|
|
445
509
|
survivors a single reporting job.
|
|
446
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
|
+
|
|
447
515
|
"A required check is satisfied by a skipped job" needs a protection configuration no
|
|
448
516
|
workflow file carries. So D1 follows D2: MEDIUM when nothing in the workflow
|
|
449
517
|
consults upstream results at all, LOW when something does, and HIGH only when
|
|
@@ -545,5 +613,5 @@ That gap is the lesson worth keeping. The tool was least accurate on the reposit
|
|
|
545
613
|
BEST CI, which is the worst place for a linter to cry wolf, and no corpus average would have
|
|
546
614
|
surfaced it. The suite passed unchanged through every one of the four, 149 of it through the
|
|
547
615
|
first two fixes and 161 through the second two, so not one of them was covered by anything.
|
|
548
|
-
There are
|
|
616
|
+
There are 228 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
|
|
549
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.
|
|
@@ -416,6 +480,10 @@ the 54 findings hand-labelled, 29 distinct jobs. **76% false per finding, 59% pe
|
|
|
416
480
|
exact, no interval. Even after all three fixes above it is 65% false, with eleven of the
|
|
417
481
|
survivors a single reporting job.
|
|
418
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
|
+
|
|
419
487
|
"A required check is satisfied by a skipped job" needs a protection configuration no
|
|
420
488
|
workflow file carries. So D1 follows D2: MEDIUM when nothing in the workflow
|
|
421
489
|
consults upstream results at all, LOW when something does, and HIGH only when
|
|
@@ -517,5 +585,5 @@ That gap is the lesson worth keeping. The tool was least accurate on the reposit
|
|
|
517
585
|
BEST CI, which is the worst place for a linter to cry wolf, and no corpus average would have
|
|
518
586
|
surfaced it. The suite passed unchanged through every one of the four, 149 of it through the
|
|
519
587
|
first two fixes and 161 through the second two, so not one of them was covered by anything.
|
|
520
|
-
There are
|
|
588
|
+
There are 228 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
|
|
521
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))
|
|
@@ -566,6 +611,29 @@ def _every_use_is_safe(var: str, body: str, assign_line: str) -> bool:
|
|
|
566
611
|
return True
|
|
567
612
|
|
|
568
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
|
+
|
|
569
637
|
def _masked_status_can_matter(line: str, body: str) -> bool:
|
|
570
638
|
"""Could this masked exit status change any outcome?"""
|
|
571
639
|
if not _LINE_CONSUMES.search(line):
|
|
@@ -674,6 +742,8 @@ def d3_pipe_masked_exit(jobs: dict, doc: dict | None = None) -> list[Finding]:
|
|
|
674
742
|
for segment, filt in _pipeline_candidates(line):
|
|
675
743
|
if filt not in FILTERS or not _segment_head_can_fail(segment):
|
|
676
744
|
continue
|
|
745
|
+
if _tail_is_a_content_assertion(segment):
|
|
746
|
+
continue
|
|
677
747
|
assigned = (re.match(r"([A-Za-z_][A-Za-z0-9_]*)=", line) or [None, ""])[1]
|
|
678
748
|
if _result_is_emptiness_checked(assigned, body):
|
|
679
749
|
continue
|
|
@@ -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.
|
|
@@ -444,6 +508,10 @@ the 54 findings hand-labelled, 29 distinct jobs. **76% false per finding, 59% pe
|
|
|
444
508
|
exact, no interval. Even after all three fixes above it is 65% false, with eleven of the
|
|
445
509
|
survivors a single reporting job.
|
|
446
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
|
+
|
|
447
515
|
"A required check is satisfied by a skipped job" needs a protection configuration no
|
|
448
516
|
workflow file carries. So D1 follows D2: MEDIUM when nothing in the workflow
|
|
449
517
|
consults upstream results at all, LOW when something does, and HIGH only when
|
|
@@ -545,5 +613,5 @@ That gap is the lesson worth keeping. The tool was least accurate on the reposit
|
|
|
545
613
|
BEST CI, which is the worst place for a linter to cry wolf, and no corpus average would have
|
|
546
614
|
surfaced it. The suite passed unchanged through every one of the four, 149 of it through the
|
|
547
615
|
first two fixes and 161 through the second two, so not one of them was covered by anything.
|
|
548
|
-
There are
|
|
616
|
+
There are 228 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
|
|
549
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
|
|
@@ -291,3 +291,47 @@ def test_a_process_substitution_is_not_reported_as_a_command_substitution():
|
|
|
291
291
|
"""Only `$( )` bodies are returned; `<( )` is matched for paren balance only."""
|
|
292
292
|
bodies = _substitution_bodies("diff <(sort a | uniq) <(sort b)")
|
|
293
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
|