Skip to content

Commit 349418e

Browse files
committed
Accept grouped parity-only promotion predicates
Normalize enclosing parentheses around the exact parity-success expression. Reject compound and malformed predicates, and cover parity-only, verify-only, combined-status and missing-status cases plus expression wrapping controls.
1 parent a46b586 commit 349418e

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

‎scripts/ci_preflight.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4534,6 +4534,15 @@ def ci_workflow_findings(ci: str, native: str, promote: str, cmake: str,
45344534
or any(_step_values(step, 'if') != ["steps.ci.outputs.green == 'true'"]
45354535
for step in promote_steps[4:])):
45364536
findings.append('baseline promotion must guard resolution, tree and gate checks before credentials')
4537+
head_predicates = re.findall(r'^[ \t]*\|[ \t]*(.*?)\s*\' <<< "\$statuses"',
4538+
head_gate, re.MULTILINE | re.DOTALL)
4539+
for index, predicate in enumerate(head_predicates):
4540+
predicate = predicate.strip()
4541+
# Only whole-expression wrappers may surround the exact parity atom.
4542+
# Unbalanced wrappers and compound expressions cannot reduce to it.
4543+
while predicate.startswith('(') and predicate.endswith(')'):
4544+
predicate = predicate[1:-1].strip()
4545+
head_predicates[index] = predicate
45374546
if (_events(promote) != {'push', 'workflow_dispatch'}
45384547
or re.search(r'^ pull_request(?:_target)?:', promote, re.MULTILINE)
45394548
or ' statuses: read' not in promote
@@ -4546,9 +4555,7 @@ def ci_workflow_findings(ci: str, native: str, promote: str, cmake: str,
45464555
or 'gh api --paginate' not in head_gate
45474556
or 'reduce (.[][]) as $s' not in head_gate
45484557
or 'if has($s.context) then . else .[$s.context] = $s.state end' not in head_gate
4549-
or re.findall(r'^[ \t]*\|[ \t]*(.*?)\s*\' <<< "\$statuses"',
4550-
head_gate, re.MULTILINE | re.DOTALL)
4551-
!= ['.["pineforge/parity"] == "success"']
4558+
or head_predicates != ['.["pineforge/parity"] == "success"']
45524559
or head_gate.count('echo "green=false" >> "$GITHUB_OUTPUT"; exit 0') != 2):
45534560
findings.append("baseline promotion must run main's copy and require "
45544561
"the latest head parity status only (verify is advisory)")

‎scripts/test_ci_preflight.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5738,6 +5738,10 @@ def test_baseline_promotion_rejects_head_status_policy_mutations(self):
57385738
"the latest head parity status only (verify is advisory)")
57395739
for predicate in (verify + ' and ' + parity, parity + ' and ' + verify,
57405740
parity + '\n and ' + verify,
5741+
'(' + parity, parity + ')', '((' + parity + ')',
5742+
'(' + parity + '))', '(' + parity + ') or true',
5743+
'(' + parity + ') and true', 'not (' + parity + ')',
5744+
'(' + parity + ') | true',
57415745
verify, 'true', '.["pineforge/parity"] == "failure"'):
57425746
with self.subTest(predicate=predicate):
57435747
changed = original.copy()
@@ -5746,6 +5750,37 @@ def test_baseline_promotion_rejects_head_status_policy_mutations(self):
57465750
self.assertNotEqual(changed[2], original[2])
57475751
self.assertIn(finding, ci_workflow_findings(*changed))
57485752

5753+
def test_baseline_promotion_head_predicate_four_rows_and_wrapping(self):
5754+
original = self.ci_sources()
5755+
self.assertEqual(ci_workflow_findings(*original), [])
5756+
parity = '.["pineforge/parity"] == "success"'
5757+
finding = ("baseline promotion must run main's copy and require "
5758+
"the latest head parity status only (verify is advisory)")
5759+
cases = (
5760+
('parenthesized-parity-only',
5761+
'(.["pineforge/parity"] == "success")', []),
5762+
('neither-required', 'true', [finding]),
5763+
('parenthesized-verify-and-parity',
5764+
'(.["pineforge/verify"] == "success" and .["pineforge/parity"] == "success")',
5765+
[finding]),
5766+
('verify-only', '.["pineforge/verify"] == "success"', [finding]),
5767+
)
5768+
for name, predicate, expected in cases:
5769+
with self.subTest(policy=name):
5770+
changed = original.copy()
5771+
changed[2] = in_step(changed[2], 'promote', 'Confirm the gate on the PR head',
5772+
parity, predicate)
5773+
self.assertNotEqual(changed[2], original[2])
5774+
self.assertEqual(ci_workflow_findings(*changed), expected)
5775+
for predicate in (' ' + parity + ' ', '( ( ' + parity + ' ) )',
5776+
'(\n ( ' + parity + ' )\n )'):
5777+
with self.subTest(wrapping=predicate):
5778+
changed = original.copy()
5779+
changed[2] = in_step(changed[2], 'promote', 'Confirm the gate on the PR head',
5780+
parity, predicate)
5781+
self.assertNotEqual(changed[2], original[2])
5782+
self.assertEqual(ci_workflow_findings(*changed), [])
5783+
57495784
def test_promotion_guard_rejects_added_contents_read_permission(self):
57505785
finding = 'baseline promotion must start with the pinned read-only promote-guard'
57515786
findings = self.mutated_file_findings(

0 commit comments

Comments
 (0)