2121 DOCS_ONLY_SKIP , GITHUB_ONLY_SKIP , HEAVY_SKIP , HOSTED_MATRIX_RUNNER , JOB_COMMANDS ,
2222 PR_RUNNER , POST_RUNNER , MATRIX_LINUX_RUNNER , MATRIX_RUNNER ,
2323 NATIVE_EXCLUSION , NATIVE_CACHE_SAVE , CURL_CACHE_SAVE ,
24- PROOF_JOBS , PR_PROOF_JOBS , RELEASE_RUNNER , _jobs , check_commands ,
24+ PREFLIGHT_IF , PROOF_JOBS , PR_PROOF_JOBS , RELEASE_RUNNER , _jobs , check_commands ,
2525 ci_workflow_findings , gated_workflow_findings ,
2626 native_workflow_findings , run_checks )
2727
@@ -89,6 +89,13 @@ def in_job(workflow, job, before, after):
8989 return workflow [:at ] + after + workflow [at + len (before ):]
9090
9191
92+ def ready_pr (condition ):
93+ """Keep the draft guard when mutating another PR job condition."""
94+ if not condition .startswith ('${{ ' ) or not condition .endswith (' }}' ):
95+ raise AssertionError (f'not a workflow condition: { condition !r} ' )
96+ return '${{ !github.event.pull_request.draft && (' + condition [4 :- 3 ] + ') }}'
97+
98+
9299def in_step (workflow , job , name , before , after ):
93100 """Mutate the named real step, even when another step shares a line."""
94101 step = ci_preflight ._step_named (ci_preflight ._steps (_jobs (workflow )[job ]),
@@ -631,8 +638,9 @@ def test_all_status_functions_require_refusal_and_repository_guards_from_mutated
631638 guard = f' if: { ci_preflight .AUTHZ_SUCCESS } \n '
632639 unnamed_run = ' - run: python3 scripts/ci_preflight.py --output-dir build-ci-preflight\n '
633640 for function in ('always()' , 'cancelled()' , 'failure()' , 'success()' ):
634- conditioned = in_job (body , None , f' if: { AUTHZ_ALWAYS } \n ' ,
635- ' if: ${{ ' + function + " && needs.authz.result == 'success' }}\n " )
641+ condition = '${{ ' + function + " && needs.authz.result == 'success' }}"
642+ conditioned = in_job (body , None , f' if: { PREFLIGHT_IF } \n ' ,
643+ f' if: { ready_pr (condition )} \n ' )
636644 mutations = (
637645 (in_job (conditioned , None , AUTHZ_REFUSE_STEP , '' ),
638646 'ci.yml job preflight with a status function must refuse authz first' ),
@@ -1338,6 +1346,41 @@ def test_ci_split_requires_every_home_trigger_without_path_filters(self):
13381346 + ('unfiltered PR' if index == 0 else 'main push, nightly and manual' ) + ' triggers' ,
13391347 findings )
13401348
1349+ def test_ci_split_requires_ready_for_review (self ):
1350+ self .assertEqual (ci_workflow_findings (* self .ci_sources (), others = self .other_sources ()), [])
1351+ findings = self .mutated_file_findings (0 , None ,
1352+ ' types: [opened, synchronize, reopened, ready_for_review, converted_to_draft]\n ' ,
1353+ ' types: [opened, synchronize, reopened, converted_to_draft]\n ' )
1354+ self .assertIn ('ci.yml must keep its exact unfiltered PR triggers' , findings )
1355+ self .assertIn ('ci.yml must run on every pull_request without event filters' , findings )
1356+
1357+ def test_ci_split_requires_converted_to_draft (self ):
1358+ self .assertEqual (ci_workflow_findings (* self .ci_sources (), others = self .other_sources ()), [])
1359+ findings = self .mutated_file_findings (0 , None ,
1360+ ' types: [opened, synchronize, reopened, ready_for_review, converted_to_draft]\n ' ,
1361+ ' types: [opened, synchronize, reopened, ready_for_review]\n ' )
1362+ self .assertIn ('ci.yml must keep its exact unfiltered PR triggers' , findings )
1363+ self .assertIn ('ci.yml must run on every pull_request without event filters' , findings )
1364+
1365+ def test_ci_split_requires_separate_draft_and_ready_concurrency_groups (self ):
1366+ self .assertEqual (ci_workflow_findings (* self .ci_sources (), others = self .other_sources ()), [])
1367+ findings = self .mutated_file_findings (0 , None ,
1368+ ' group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}'
1369+ "-${{ github.event.pull_request.draft && 'draft' || 'ready' }}\n " ,
1370+ ' group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}\n ' )
1371+ self .assertIn ('ci.yml must keep its exact draft and ready concurrency groups' , findings )
1372+
1373+ def test_ci_split_requires_draft_guards_on_every_pr_suite_job (self ):
1374+ self .assertEqual (ci_workflow_findings (* self .ci_sources (), others = self .other_sources ()), [])
1375+ for job in ('preflight' , * PR_PROOF_JOBS ):
1376+ with self .subTest (job = job ):
1377+ findings = self .mutated_file_findings (0 , job , '!github.event.pull_request.draft && ' , '' )
1378+ finding = ('preflight must follow authz and changes and run even if classification fails'
1379+ if job == 'preflight' else
1380+ f'{ job } must start alongside preflight, after authz and changes, '
1381+ 'and skip only its classified path policy' )
1382+ self .assertIn (finding , findings )
1383+
13411384 def test_ci_split_refuses_deleting_or_renaming_every_job (self ):
13421385 ci = self .ci_sources ()[0 ]
13431386 self .assertEqual (set (_jobs (ci )), set (CI_JOB_IDS ))
@@ -2173,13 +2216,19 @@ def test_legacy_metadata_cannot_replace_runner_pins(self):
21732216 self .assertIn (f'ci.yml job preflight must run on { PR_RUNNER } ' , findings )
21742217
21752218 def test_ci_contract_pins_the_docs_only_skip (self ):
2176- """Each proof job waits for authz and changes and skips only its docs-only
2177- answer; preflight also waits for the class decision and always runs."""
2219+ """Keep each pipeline's path policy and dependencies; PR suite jobs
2220+ also require a ready PR, and post-merge preflight always runs."""
21782221 original , others = self .ci_sources (), self .other_sources ()
21792222 self .assertEqual (ci_workflow_findings (* original , others = others ), [])
2180- docs_skip = f' if: { DOCS_ONLY_SKIP } \n '
2223+ docs_skip = f' if: { ready_pr ( DOCS_ONLY_SKIP ) } \n '
21812224 mutations = []
21822225 for index , proofs , policy in ((0 , PR_PROOF_JOBS , GITHUB_ONLY_SKIP ), (6 , PROOF_JOBS , DOCS_ONLY_SKIP )):
2226+ wrong_skips = [f' if: { ready_pr (condition ) if index == 0 else condition } \n '
2227+ for condition in (
2228+ "${{ needs.changes.outputs.docs_only != 'true' }}" ,
2229+ "${{ !cancelled() && needs.changes.outputs.docs_only == 'false' }}" ,
2230+ "${{ !cancelled() && needs.changes.outputs.docs_only != 'true' }}" ,
2231+ )]
21832232 for job in proofs :
21842233 skip = f' if: { policy } \n '
21852234 refused = f'{ job } must start alongside preflight, after authz and changes'
@@ -2188,21 +2237,19 @@ def test_ci_contract_pins_the_docs_only_skip(self):
21882237 (index , job , ' needs: [authz, changes]\n ' , ' needs: [changes, preflight]\n ' , refused ),
21892238 (index , job , ' needs: [authz, changes]\n ' , ' needs: preflight\n ' , refused ),
21902239 (index , job , skip , '' , refused ),
2191- (index , job , skip , " if: ${{ needs.changes.outputs.docs_only != 'true' }}\n " , refused ),
2192- (index , job , skip , " if: ${{ !cancelled() && needs.changes.outputs.docs_only == 'false' }}\n " ,
2193- refused ),
2240+ (index , job , skip , wrong_skips [0 ], refused ),
2241+ (index , job , skip , wrong_skips [1 ], refused ),
21942242 (index , job , skip , skip .replace ("!= 'true'" , "!= 'true' && github.event_name != 'push'" ),
21952243 refused ),
2196- (index , job , skip , " if: ${{ !cancelled() && needs.changes.outputs.docs_only != 'true' }}\n " ,
2197- refused )]
2244+ (index , job , skip , wrong_skips [2 ], refused )]
21982245 mutations += [
21992246 (0 , 'preflight' , ' needs: [authz, changes]\n ' , '' ,
22002247 'preflight must follow authz and changes' ),
22012248 (0 , 'preflight' , ' needs: [authz, changes]\n ' , ' needs: build\n ' ,
22022249 'preflight must follow authz and changes' ),
2203- (0 , 'preflight' , f' if: { AUTHZ_ALWAYS } \n ' , docs_skip ,
2250+ (0 , 'preflight' , f' if: { PREFLIGHT_IF } \n ' , docs_skip ,
22042251 'preflight must follow authz and changes' ),
2205- (0 , 'preflight' , f' if: { AUTHZ_ALWAYS } \n ' , '' ,
2252+ (0 , 'preflight' , f' if: { PREFLIGHT_IF } \n ' , '' ,
22062253 'preflight must follow authz and changes' ),
22072254 (0 , 'changes' , ' steps:\n ' , ' needs: preflight\n steps:\n ' ,
22082255 'changes must start after authz' ),
@@ -2592,8 +2639,8 @@ def test_github_only_contract_refuses_previous_job_trust_and_reader_bypasses(sel
25922639 ('build-gate' , 'github_only = False' , 'github_only = True' ),
25932640 ('build-gate' , 'bool(paths) and all(' , 'True or all(' ),
25942641 ('build-gate' , 'snapshot() != count' , 'False' ),
2595- ('build' , GITHUB_ONLY_SKIP , DOCS_ONLY_SKIP ),
2596- ('corpus-parity-subset' , GITHUB_ONLY_SKIP , DOCS_ONLY_SKIP ),
2642+ ('build' , GITHUB_ONLY_SKIP , ready_pr ( DOCS_ONLY_SKIP ) ),
2643+ ('corpus-parity-subset' , GITHUB_ONLY_SKIP , ready_pr ( DOCS_ONLY_SKIP ) ),
25972644 ('preflight' , ci_preflight .PREFLIGHT_TIER , "'github-only'" ),
25982645 ('changes' , 'pull-requests: read' , 'pull-requests: write' ),
25992646 ('build-gate' , 'pull-requests: read' , 'pull-requests: write' )):
0 commit comments