Skip to content

Commit 49a55b5

Browse files
luisleo526claude
andcommitted
Merge main (a2bb907, the squash of #483) into the ruleset probe branch
No conflict. Main moved by #483 only (the promote-baseline workflow-level defaults/env pins in scripts/ci_preflight.py and its tests); the probe files are untouched by it, and the merged scripts/ci_preflight.py and scripts/test_ci_preflight.py auto-merged. Against main the diff is only the probe. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2 parents 32e4e5d + a2bb907 commit 49a55b5

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

‎docs/ci.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,9 @@ responses are selected by username. Mutation tests replace a script with
12031203
`exit 0`, remove repository/fork/identity checks or permission lookups, disable
12041204
`fail`, bypass failed lookups, add guard credentials or a checkout, or
12051205
disconnect the credential job. Missing, skipped or unsuccessful authorization
1206-
cannot admit promotion.
1206+
cannot admit promotion. The stage also rejects workflow-level `defaults` and
1207+
`env`, and guard-level `defaults`, so an inherited shell or environment
1208+
variable cannot bypass the guard pin.
12071209

12081210
The release pool is restricted to the existing pinned release and promotion
12091211
jobs; reusable call edges cannot admit PR events to them.

‎scripts/ci_preflight.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,13 @@ def ci_workflow_findings(ci: str, native: str, promote: str, cmake: str,
18371837
or '.["pineforge/parity"] == "success"' not in head_gate
18381838
or head_gate.count('echo "green=false" >> "$GITHUB_OUTPUT"; exit 0') != 2):
18391839
findings.append("baseline promotion must run main's copy and require the latest two head statuses")
1840+
# The job pin cannot see inherited workflow settings.
1841+
for key in ('defaults', 'env'):
1842+
if _job_values(promote, key):
1843+
findings.append(f'baseline promotion must not define workflow-level {key}')
18401844
promotion_jobs = _jobs(promote)
1845+
if _job_values(promotion_jobs.get('promote-guard', ''), 'defaults'):
1846+
findings.append('baseline promotion promote-guard must not define job-level defaults')
18411847
promotion_text = _jobs_text(promote) or ''
18421848
promotion_headers = list(_JOB_HEADER.finditer(promotion_text))
18431849
if ([header.group(1) for header in promotion_headers] != ['promote-guard', 'promote']

‎scripts/test_ci_preflight.py‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,45 @@ def test_promotion_guard_rejects_mutations_of_the_real_workflow(self):
10481048
self.assertIn("baseline promotion must run main's copy and require the latest two head statuses",
10491049
ci_workflow_findings(*changed))
10501050

1051+
def test_promotion_guard_rejects_workflow_defaults_and_env(self):
1052+
original = self.ci_sources()
1053+
self.assertEqual(ci_workflow_findings(*original), [])
1054+
self.assertEqual(original[2].count('\njobs:\n'), 1)
1055+
settings = (
1056+
('defaults', 'defaults:\n run:\n shell: bash -c "exit 0" -- {0}\n'),
1057+
('env', 'env:\n KEY: ${{ secrets.PINEFORGE_APP_PRIVATE_KEY }}\n'),
1058+
('defaults', 'defaults: {}\n'),
1059+
('env', 'env: {}\n'),
1060+
('defaults', "'defaults': {run: {shell: bash}}\n"),
1061+
('env', '"env": {PUBLIC_VALUE: harmless}\n'),
1062+
)
1063+
for key, setting in settings:
1064+
with self.subTest(setting=setting):
1065+
changed = original.copy()
1066+
changed[2] = changed[2].replace('\njobs:\n', '\n' + setting + 'jobs:\n', 1)
1067+
self.assertNotEqual(changed[2], original[2])
1068+
self.assertEqual(_jobs(changed[2]), _jobs(original[2]))
1069+
self.assertEqual(ci_workflow_findings(*changed), [
1070+
f'baseline promotion must not define workflow-level {key}',
1071+
])
1072+
1073+
def test_promotion_guard_rejects_job_defaults(self):
1074+
original = self.ci_sources()
1075+
self.assertEqual(ci_workflow_findings(*original), [])
1076+
for setting in (
1077+
' defaults:\n run:\n shell: bash -c "exit 0" -- {0}\n',
1078+
' defaults: {}\n',
1079+
' "defaults": {run: {shell: bash}}\n'):
1080+
with self.subTest(setting=setting):
1081+
changed = original.copy()
1082+
changed[2] = in_job(changed[2], 'promote-guard', ' steps:\n',
1083+
setting + ' steps:\n')
1084+
self.assertNotEqual(changed[2], original[2])
1085+
self.assertEqual(ci_workflow_findings(*changed), [
1086+
'baseline promotion promote-guard must not define job-level defaults',
1087+
'baseline promotion must start with the pinned read-only promote-guard',
1088+
])
1089+
10511090
def promotion_guard_result(self, *, workflow=None, **overrides):
10521091
"""Run the real workflow shell; only the external gh CLI is stubbed."""
10531092
bash = shutil.which('bash')

0 commit comments

Comments
 (0)