deadgate 0.1.2__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {deadgate-0.1.2 → deadgate-0.1.3}/PKG-INFO +30 -2
  2. {deadgate-0.1.2 → deadgate-0.1.3}/README.md +29 -1
  3. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate/detectors.py +60 -5
  4. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate.egg-info/PKG-INFO +30 -2
  5. {deadgate-0.1.2 → deadgate-0.1.3}/pyproject.toml +1 -1
  6. {deadgate-0.1.2 → deadgate-0.1.3}/tests/test_corpus.py +18 -2
  7. {deadgate-0.1.2 → deadgate-0.1.3}/tests/test_wildcard_gates.py +154 -0
  8. {deadgate-0.1.2 → deadgate-0.1.3}/LICENSE +0 -0
  9. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate/__init__.py +0 -0
  10. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate/checknames.py +0 -0
  11. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate/cli.py +0 -0
  12. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate/predicates.py +0 -0
  13. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate/protection.py +0 -0
  14. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate/resolve.py +0 -0
  15. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate/sandbox.py +0 -0
  16. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate.egg-info/SOURCES.txt +0 -0
  17. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate.egg-info/dependency_links.txt +0 -0
  18. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate.egg-info/entry_points.txt +0 -0
  19. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate.egg-info/requires.txt +0 -0
  20. {deadgate-0.1.2 → deadgate-0.1.3}/deadgate.egg-info/top_level.txt +0 -0
  21. {deadgate-0.1.2 → deadgate-0.1.3}/setup.cfg +0 -0
  22. {deadgate-0.1.2 → deadgate-0.1.3}/tests/test_predicates.py +0 -0
  23. {deadgate-0.1.2 → deadgate-0.1.3}/tests/test_protection.py +0 -0
  24. {deadgate-0.1.2 → deadgate-0.1.3}/tests/test_sandbox.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deadgate
3
- Version: 0.1.2
3
+ Version: 0.1.3
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
@@ -161,6 +161,34 @@ is a separate and harder problem and is not in this release.
161
161
  ## Licence
162
162
  MIT
163
163
 
164
+ ## 0.1.3 closes a fifth class, and D4 stops claiming HIGH
165
+
166
+ **Upgrade from anything earlier.** Five times now this tool has reported correct CI as
167
+ broken, each time because it asked "does this job consult its upstreams?" and looked in too
168
+ few places.
169
+
170
+ | # | what was missed | found on |
171
+ |---|---|---|
172
+ | 1 | `needs.*.result`, the WILDCARD form, matched with `[A-Za-z0-9_-]+` which cannot match `*` | Arize-ai/openinference |
173
+ | 2 | D4 judged a job alone, ignoring the workflow's own gate | Arize-ai/openinference |
174
+ | 3 | `toJSON(needs)`, every upstream read with no `result` token anywhere | astral-sh/ruff |
175
+ | 4 | PLACEMENT: a reusable-workflow call has `uses:` and no `steps:`, passing the result through JOB-level `with:` | scikit-learn |
176
+ | 5 | a gate that NAMES each upstream, `needs.a.result`, `needs.b.result`, one per job | open-gsd, omi, inbox-zero |
177
+
178
+ 1 and 2 shipped in 0.1.0. 3 and 4 were found by pointing the fixed version at two more
179
+ repositories. 5 was found by hand-labelling 40 of its own surviving findings, which is the
180
+ only method here that found anything the previous method could not.
181
+
182
+ **D4 no longer produces a HIGH finding.** That sample scored D4 at **0 defensible out of
183
+ 18**, and the overall false-positive rate among survivors was 40% (Wilson 95% [26%, 55%]),
184
+ statistically indistinguishable from the 40% removed in 0.1.2. D4's HIGH came from whether
185
+ the job's NAME matched test/lint/check, while the finding asserted something about branch
186
+ protection that a workflow file cannot know. It is now MEDIUM when nothing in the workflow
187
+ gates at all, LOW when something does, and HIGH only when protection data confirms the job
188
+ is a required check.
189
+
190
+ Corpus HIGH across 275 repositories and 4543 files: **658 to 354**.
191
+
164
192
  ## 0.1.2 closes four false-positive classes, two of them shipped
165
193
 
166
194
  **Upgrade from 0.1.0 or 0.1.1.** Four times this tool reported correct CI as broken, each time
@@ -198,5 +226,5 @@ That gap is the lesson worth keeping. The tool was least accurate on the reposit
198
226
  BEST CI, which is the worst place for a linter to cry wolf, and no corpus average would have
199
227
  surfaced it. The suite passed unchanged through every one of the four, 149 of it through the
200
228
  first two fixes and 161 through the second two, so not one of them was covered by anything.
201
- There are 165 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
229
+ There are 173 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
202
230
  suite ever drift apart again.
@@ -133,6 +133,34 @@ is a separate and harder problem and is not in this release.
133
133
  ## Licence
134
134
  MIT
135
135
 
136
+ ## 0.1.3 closes a fifth class, and D4 stops claiming HIGH
137
+
138
+ **Upgrade from anything earlier.** Five times now this tool has reported correct CI as
139
+ broken, each time because it asked "does this job consult its upstreams?" and looked in too
140
+ few places.
141
+
142
+ | # | what was missed | found on |
143
+ |---|---|---|
144
+ | 1 | `needs.*.result`, the WILDCARD form, matched with `[A-Za-z0-9_-]+` which cannot match `*` | Arize-ai/openinference |
145
+ | 2 | D4 judged a job alone, ignoring the workflow's own gate | Arize-ai/openinference |
146
+ | 3 | `toJSON(needs)`, every upstream read with no `result` token anywhere | astral-sh/ruff |
147
+ | 4 | PLACEMENT: a reusable-workflow call has `uses:` and no `steps:`, passing the result through JOB-level `with:` | scikit-learn |
148
+ | 5 | a gate that NAMES each upstream, `needs.a.result`, `needs.b.result`, one per job | open-gsd, omi, inbox-zero |
149
+
150
+ 1 and 2 shipped in 0.1.0. 3 and 4 were found by pointing the fixed version at two more
151
+ repositories. 5 was found by hand-labelling 40 of its own surviving findings, which is the
152
+ only method here that found anything the previous method could not.
153
+
154
+ **D4 no longer produces a HIGH finding.** That sample scored D4 at **0 defensible out of
155
+ 18**, and the overall false-positive rate among survivors was 40% (Wilson 95% [26%, 55%]),
156
+ statistically indistinguishable from the 40% removed in 0.1.2. D4's HIGH came from whether
157
+ the job's NAME matched test/lint/check, while the finding asserted something about branch
158
+ protection that a workflow file cannot know. It is now MEDIUM when nothing in the workflow
159
+ gates at all, LOW when something does, and HIGH only when protection data confirms the job
160
+ is a required check.
161
+
162
+ Corpus HIGH across 275 repositories and 4543 files: **658 to 354**.
163
+
136
164
  ## 0.1.2 closes four false-positive classes, two of them shipped
137
165
 
138
166
  **Upgrade from 0.1.0 or 0.1.1.** Four times this tool reported correct CI as broken, each time
@@ -170,5 +198,5 @@ That gap is the lesson worth keeping. The tool was least accurate on the reposit
170
198
  BEST CI, which is the worst place for a linter to cry wolf, and no corpus average would have
171
199
  surfaced it. The suite passed unchanged through every one of the four, 149 of it through the
172
200
  first two fixes and 161 through the second two, so not one of them was covered by anything.
173
- There are 165 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
201
+ There are 173 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
174
202
  suite ever drift apart again.
@@ -101,6 +101,8 @@ _NEEDS_READ = re.compile(r"needs\.(?:\*|[A-Za-z0-9_\-]+)\.(?:result|outputs)")
101
101
  # Fixing the wildcard form in 0.1.1 and stopping there was the error; the lesson is that a
102
102
  # gate can consult its upstreams without naming any of them.
103
103
  _NEEDS_WHOLE_CONTEXT = re.compile(r"to_?json\s*\(\s*needs\s*\)", re.I)
104
+ # Which upstreams does a gate name explicitly? `needs.<job>.result`, one per job.
105
+ _NAMED_RESULT = re.compile(r"needs\.([A-Za-z0-9_\-]+)\.result")
104
106
  _NEEDS_WILDCARD_RESULT = re.compile(r"needs\.\*\.result")
105
107
 
106
108
 
@@ -410,12 +412,63 @@ def _jobs_covered_by_a_wildcard_gate(jobs: dict) -> set[str]:
410
412
  for name, job in jobs.items():
411
413
  if not isinstance(job, dict) or not _runs_like_a_gate(job.get("if")):
412
414
  continue
413
- if not _reads_all_upstream_state(_job_blob(job)):
415
+ blob = _job_blob(job)
416
+ direct = set(_needs_of(job))
417
+ if _reads_all_upstream_state(blob):
418
+ # wildcard or whole-context: asks about every direct need at once
419
+ covered |= direct
414
420
  continue
415
- covered |= set(_needs_of(job))
421
+ # A gate can also enumerate its needs BY NAME, one expression each. That is
422
+ # the same coverage spelled out longhand, and it was the fifth false-positive
423
+ # class: scikit-learn, open-gsd, BasedHardware/omi and elie222/inbox-zero all
424
+ # write gates this way, and 6 of the 16 false positives in a 40-finding
425
+ # hand-labelled sample came from failing to read it.
426
+ #
427
+ # Deliberately NOT all-or-nothing: a gate that names eight of its nine needs
428
+ # covers those eight and not the ninth. Treating it as total would re-create
429
+ # the bug in the other direction, suppressing a finding about the one upstream
430
+ # nobody checks.
431
+ named = set(_NAMED_RESULT.findall(blob)) & direct
432
+ covered |= named
416
433
  return covered
417
434
 
418
435
 
436
+ def _workflow_has_any_gate(jobs: dict) -> bool:
437
+ """Does ANY job here consult upstream results at all?"""
438
+ return any(isinstance(j, dict) and _runs_like_a_gate(j.get("if"))
439
+ and _reads_any_upstream_state(_job_blob(j)) for j in jobs.values())
440
+
441
+
442
+ def _d4_severity(name: str, job: dict, doc: dict, has_gate: bool) -> str:
443
+ """D4 severity, capped at MEDIUM because the HIGH claim is not checkable from here.
444
+
445
+ D4 used to inherit `_gate_severity`, which returns HIGH when the job's NAME matches
446
+ test/lint/check/verify/ci and the workflow runs on pull_request. That is a guess from a
447
+ word, and the finding it labels asserts something stronger: "any branch protection
448
+ requiring it passes with nothing tested". Whether the job is a required check is exactly
449
+ what a workflow file cannot say.
450
+
451
+ Measured before changing it: in a pre-registered hand-labelled sample of 40 of this
452
+ tool's own surviving HIGH findings, D4 scored 0 defensible out of 18. Every arguable case
453
+ failed on the same point, that a failed gating job is itself red on the pull request, so
454
+ the stated impact needs a protection configuration the detector cannot see.
455
+
456
+ So HIGH is reserved for the escalation path, where `protection.py` has attributed the job
457
+ to a confirmed required check. Without that:
458
+
459
+ MEDIUM no job in the workflow consults upstream results at all, so nothing anywhere
460
+ would notice. 126 of the 196 D4 HIGH on the corpus were this.
461
+ LOW the workflow DOES gate, just not over this upstream. Weaker on purpose: 55% of
462
+ real gates delegate the decision to a script the detector cannot read, so a
463
+ claim that an existing gate misses one upstream is the claim most likely to be
464
+ wrong.
465
+ """
466
+ base = _gate_severity(name, job, doc)
467
+ if base == "LOW":
468
+ return "LOW"
469
+ return "MEDIUM" if not has_gate else "LOW"
470
+
471
+
419
472
  def d4_outputs_gate_without_result_check(jobs: dict, doc: dict | None = None) -> list[Finding]:
420
473
  """A job gated on an upstream's OUTPUTS, with nothing checking that upstream SUCCEEDED.
421
474
 
@@ -444,7 +497,7 @@ def d4_outputs_gate_without_result_check(jobs: dict, doc: dict | None = None) ->
444
497
  # `needs.*.result` asks about EVERY upstream, so it checks all of them at once.
445
498
  # Expanding it is the difference between a correct gate and a reported one.
446
499
  checked |= ups
447
- sev = _gate_severity(name, job, doc or {})
500
+ sev = _d4_severity(name, job, doc or {}, _workflow_has_any_gate(jobs))
448
501
  for up in sorted(ups - checked - _jobs_covered_by_a_wildcard_gate(jobs)):
449
502
  found.append(Finding(
450
503
  detector="D4",
@@ -454,8 +507,10 @@ def d4_outputs_gate_without_result_check(jobs: dict, doc: dict | None = None) ->
454
507
  detail=(f"job '{name}' runs only when '{up}' outputs say so, and nothing checks "
455
508
  f"needs.{up}.result. If '{up}' FAILS, its outputs are unset, the "
456
509
  f"condition is false, '{name}' skips, and a skipped job reports Success."),
457
- repro=(f"Make '{up}' exit 1. '{name}' does not run, reports Success, and any "
458
- f"branch protection requiring it passes with nothing tested."),
510
+ repro=(f"Make '{up}' exit 1. '{name}' does not run and reports Success. "
511
+ f"Whether that lets a merge through depends on which checks are "
512
+ f"REQUIRED, which this file cannot say: if '{up}' is itself required, "
513
+ f"its own failure blocks the merge and this is noise."),
459
514
  ))
460
515
  return found
461
516
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deadgate
3
- Version: 0.1.2
3
+ Version: 0.1.3
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
@@ -161,6 +161,34 @@ is a separate and harder problem and is not in this release.
161
161
  ## Licence
162
162
  MIT
163
163
 
164
+ ## 0.1.3 closes a fifth class, and D4 stops claiming HIGH
165
+
166
+ **Upgrade from anything earlier.** Five times now this tool has reported correct CI as
167
+ broken, each time because it asked "does this job consult its upstreams?" and looked in too
168
+ few places.
169
+
170
+ | # | what was missed | found on |
171
+ |---|---|---|
172
+ | 1 | `needs.*.result`, the WILDCARD form, matched with `[A-Za-z0-9_-]+` which cannot match `*` | Arize-ai/openinference |
173
+ | 2 | D4 judged a job alone, ignoring the workflow's own gate | Arize-ai/openinference |
174
+ | 3 | `toJSON(needs)`, every upstream read with no `result` token anywhere | astral-sh/ruff |
175
+ | 4 | PLACEMENT: a reusable-workflow call has `uses:` and no `steps:`, passing the result through JOB-level `with:` | scikit-learn |
176
+ | 5 | a gate that NAMES each upstream, `needs.a.result`, `needs.b.result`, one per job | open-gsd, omi, inbox-zero |
177
+
178
+ 1 and 2 shipped in 0.1.0. 3 and 4 were found by pointing the fixed version at two more
179
+ repositories. 5 was found by hand-labelling 40 of its own surviving findings, which is the
180
+ only method here that found anything the previous method could not.
181
+
182
+ **D4 no longer produces a HIGH finding.** That sample scored D4 at **0 defensible out of
183
+ 18**, and the overall false-positive rate among survivors was 40% (Wilson 95% [26%, 55%]),
184
+ statistically indistinguishable from the 40% removed in 0.1.2. D4's HIGH came from whether
185
+ the job's NAME matched test/lint/check, while the finding asserted something about branch
186
+ protection that a workflow file cannot know. It is now MEDIUM when nothing in the workflow
187
+ gates at all, LOW when something does, and HIGH only when protection data confirms the job
188
+ is a required check.
189
+
190
+ Corpus HIGH across 275 repositories and 4543 files: **658 to 354**.
191
+
164
192
  ## 0.1.2 closes four false-positive classes, two of them shipped
165
193
 
166
194
  **Upgrade from 0.1.0 or 0.1.1.** Four times this tool reported correct CI as broken, each time
@@ -198,5 +226,5 @@ That gap is the lesson worth keeping. The tool was least accurate on the reposit
198
226
  BEST CI, which is the worst place for a linter to cry wolf, and no corpus average would have
199
227
  surfaced it. The suite passed unchanged through every one of the four, 149 of it through the
200
228
  first two fixes and 161 through the second two, so not one of them was covered by anything.
201
- There are 165 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
229
+ There are 173 tests now, and `scripts/check_readme_test_count.py` fails if that number and the
202
230
  suite ever drift apart again.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "deadgate"
3
- version = "0.1.2"
3
+ version = "0.1.3"
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"
@@ -107,9 +107,25 @@ jobs:
107
107
  """
108
108
 
109
109
 
110
- def test_d4_pr_verification_job_is_high():
110
+ def test_d4_pr_verification_job_caps_at_medium_without_protection_data():
111
+ """D4 no longer reaches HIGH from the job's NAME.
112
+
113
+ This test asserted HIGH, inherited from `_gate_severity`, which returns HIGH when the
114
+ name matches test/lint/check and the workflow runs on pull_request. The finding it
115
+ labelled claims "any branch protection requiring it passes with nothing tested", and
116
+ whether the job is required is the one thing a workflow file cannot say.
117
+
118
+ Changed on evidence, not taste: in a pre-registered hand-labelled sample of 40 of this
119
+ tool's own surviving HIGH findings, D4 scored 0 defensible out of 18, and every arguable
120
+ case failed on exactly that point. HIGH is now reserved for the escalation path, where
121
+ branch protection has attributed the job to a confirmed required check.
122
+
123
+ MEDIUM here because this fixture's workflow has no fan-in gate at all, so nothing
124
+ anywhere would notice the skip.
125
+ """
111
126
  f = [x for x in _scan(_yaml.safe_load(_PR_TEST)) if x.detector == "D4"]
112
- assert f and f[0].severity == "HIGH", f
127
+ assert f and f[0].severity == "MEDIUM", f
128
+ assert "cannot say" in f[0].repro, "the repro must state the condition, not assert it"
113
129
 
114
130
 
115
131
  def test_d4_release_publish_job_is_low():
@@ -355,3 +355,157 @@ def test_a_gate_that_forwards_the_whole_context_to_a_reusable_workflow_covers_it
355
355
  assert d4_outputs_gate_without_result_check(jobs_of(src)) == []
356
356
  nogate = src.replace("results: ${{ toJSON(needs) }}", "results: none")
357
357
  assert [f.detector for f in d4_outputs_gate_without_result_check(jobs_of(nogate))] == ["D4"]
358
+
359
+
360
+ # ---------------------------------------------------------------------------
361
+ # the fifth class: a gate that spells its needs out longhand
362
+ # ---------------------------------------------------------------------------
363
+ #
364
+ # A gate can ask about every upstream without the wildcard and without toJSON, by naming
365
+ # each one: needs.a.result, needs.b.result, one expression per job. That is the same
366
+ # coverage written longhand, and it was invisible. Found by hand-labelling a 40-finding
367
+ # sample of 0.1.2's survivors: 6 of the 16 false positives were this, across scikit-learn,
368
+ # open-gsd, BasedHardware/omi and elie222/inbox-zero.
369
+
370
+ ENUMERATING_GATE = textwrap.dedent("""
371
+ jobs:
372
+ changes:
373
+ runs-on: ubuntu-latest
374
+ steps: [{run: "true"}]
375
+ preflight:
376
+ runs-on: ubuntu-latest
377
+ steps: [{run: "true"}]
378
+ test:
379
+ needs: [changes, preflight]
380
+ if: ${{ needs.changes.outputs.code == 'true' }}
381
+ runs-on: ubuntu-latest
382
+ steps: [{run: "pytest"}]
383
+ required-tests:
384
+ needs: [changes, preflight, test]
385
+ if: ${{ always() }}
386
+ runs-on: ubuntu-latest
387
+ steps:
388
+ - run: |
389
+ test "${{ needs.changes.result }}" = success
390
+ test "${{ needs.preflight.result }}" = success
391
+ test "${{ needs.test.result }}" = success
392
+ """)
393
+
394
+
395
+ def test_a_gate_that_enumerates_its_needs_by_name_covers_them():
396
+ src = ENUMERATING_GATE
397
+ assert "needs.*.result" not in src and "toJSON" not in src, "fixture must use the longhand form"
398
+ assert d4_outputs_gate_without_result_check(jobs_of(src)) == []
399
+
400
+
401
+ def test_the_coverage_is_per_name_and_not_all_or_nothing():
402
+ # The precision that stops this fix from becoming the same bug pointing the other way.
403
+ # Drop ONE name from the gate and the job gated on that upstream comes back, while the
404
+ # others stay suppressed. A gate naming eight of nine needs covers eight.
405
+ src = "\n".join(l for l in ENUMERATING_GATE.splitlines()
406
+ if "needs.changes.result" not in l)
407
+ assert "needs.changes.result" not in src
408
+ found = d4_outputs_gate_without_result_check(jobs_of(src))
409
+ ups = sorted(f.detail.split("'")[3] for f in found)
410
+ assert ups == ["changes"], f"only the unnamed upstream should return, got {ups}"
411
+
412
+
413
+ def test_naming_a_job_the_gate_does_not_need_covers_nothing():
414
+ # A result read for a job outside the gate's own needs says nothing about that job,
415
+ # because the gate does not wait for it. The intersection with `needs` is load-bearing.
416
+ src = ENUMERATING_GATE.replace("needs.changes.result", "needs.unrelated.result")
417
+ found = d4_outputs_gate_without_result_check(jobs_of(src))
418
+ assert [f.detail.split("'")[3] for f in found] == ["changes"]
419
+
420
+
421
+ def test_a_gate_naming_a_job_outside_its_needs_does_not_cover_that_job():
422
+ # The `& direct` intersection, isolated. The gate names needs.changes.result but does
423
+ # NOT need `changes`, so it does not wait for it and cannot report on it. Without the
424
+ # intersection the mention alone would suppress the finding about `build`.
425
+ src = textwrap.dedent("""
426
+ jobs:
427
+ changes:
428
+ runs-on: ubuntu-latest
429
+ steps: [{run: "true"}]
430
+ other:
431
+ runs-on: ubuntu-latest
432
+ steps: [{run: "true"}]
433
+ build:
434
+ needs: [changes]
435
+ if: ${{ needs.changes.outputs.code == 'true' }}
436
+ runs-on: ubuntu-latest
437
+ steps: [{run: "make"}]
438
+ gate:
439
+ needs: [other]
440
+ if: ${{ always() }}
441
+ runs-on: ubuntu-latest
442
+ steps:
443
+ - run: echo "${{ needs.changes.result }}"
444
+ """)
445
+ found = d4_outputs_gate_without_result_check(jobs_of(src))
446
+ assert [f.detail.split("'")[3] for f in found] == ["changes"], (
447
+ "a gate that does not need `changes` cannot cover it, however it is mentioned")
448
+
449
+
450
+ def test_reading_an_upstreams_outputs_is_not_reading_its_result():
451
+ # The `.result` anchor, isolated. A gate that reads needs.changes.outputs.* consults a
452
+ # VALUE the job produced, which tells it nothing about whether the job failed: a failed
453
+ # job produces no outputs and the read is empty, which is the whole defect D4 describes.
454
+ src = ENUMERATING_GATE.replace("needs.changes.result", "needs.changes.outputs.code")
455
+ found = d4_outputs_gate_without_result_check(jobs_of(src))
456
+ assert [f.detail.split("'")[3] for f in found] == ["changes"]
457
+
458
+
459
+ # ---------------------------------------------------------------------------
460
+ # D4 severity: MEDIUM when nothing gates, LOW when something does
461
+ # ---------------------------------------------------------------------------
462
+
463
+ def _d4(src):
464
+ import deadgate.detectors as D
465
+ d = yaml.safe_load(src)
466
+ return [f for f in D.scan_workflow(d) if f.detector == "D4"]
467
+
468
+
469
+ D4_NO_GATE = textwrap.dedent("""
470
+ on: [pull_request]
471
+ jobs:
472
+ changes:
473
+ runs-on: ubuntu-latest
474
+ steps: [{run: "true"}]
475
+ test:
476
+ needs: [changes]
477
+ if: ${{ needs.changes.outputs.code == 'true' }}
478
+ runs-on: ubuntu-latest
479
+ steps: [{run: "pytest"}]
480
+ """)
481
+
482
+
483
+ def test_d4_is_medium_when_no_job_in_the_workflow_gates_at_all():
484
+ # The strongest D4 case: nothing anywhere consults an upstream result, so the skip is
485
+ # genuinely unobserved. 126 of the 196 D4 HIGH on the corpus were this shape.
486
+ f = _d4(D4_NO_GATE)
487
+ assert [x.severity for x in f] == ["MEDIUM"], f
488
+
489
+
490
+ def test_d4_drops_to_low_when_the_workflow_gates_but_not_over_this_upstream():
491
+ # Weaker on purpose. 55% of real gates hand the decision to a script this tool cannot
492
+ # read, so "a gate exists but misses this one upstream" is the claim most likely wrong.
493
+ src = D4_NO_GATE + (
494
+ " gate:\n"
495
+ " needs: [test]\n"
496
+ " if: ${{ always() }}\n"
497
+ " runs-on: ubuntu-latest\n"
498
+ " steps:\n"
499
+ ' - run: test "${{ needs.test.result }}" = success\n')
500
+ assert "gate:" in yaml.safe_load(src)["jobs"] or "gate" in yaml.safe_load(src)["jobs"], \
501
+ "the gate must actually be nested under jobs:"
502
+ f = _d4(src)
503
+ assert [x.severity for x in f] == ["LOW"], f
504
+
505
+
506
+ def test_d4_never_claims_branch_protection_as_fact():
507
+ # The repro used to assert "any branch protection requiring it passes with nothing
508
+ # tested". That is conditional on which checks are required, which a workflow cannot say.
509
+ for x in _d4(D4_NO_GATE):
510
+ assert "cannot say" in x.repro
511
+ assert "passes with nothing tested" not in x.repro
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes