Skip to content

Commit db58170

Browse files
luisleo526ci-cxclaude
authored
ci: fully qualify the two remote-tracking refs the promote-baseline ancestry check and the doc-reverts default base read (ORG-ACTIONPINS-CARD) [replaces #494] (#507)
* ci: fully qualify the two remote-tracking refs the promote-baseline ancestry check and the doc-reverts default base read (ORG-ACTIONPINS-CARD, LB-464 P3) promote-baseline.yml tested `git merge-base --is-ancestor "$MERGE_SHA" "origin/$BASE_REF"`, and check_doc_reverts.py default_base() resolved the bare names `origin/main` then `main`. A short name resolves through git's ref-lookup order, so a tag called `origin/main` (or `main`) would win over the remote-tracking branch or the local branch. Both now use the fully qualified names (`refs/remotes/origin/$BASE_REF`; `refs/remotes/origin/main`, then `refs/heads/main`, same order and same fallback to the merged-pull-request walk). The exact-text pin in scripts/ci_preflight.py is updated to the new command and stays as strict; the old short form is now a finding. Red-first tests: the pin refuses the short command and accepts the qualified one; a repository where a TAG named `origin/main` points at an unrelated commit and the real remote-tracking ref points elsewhere, and the same for a tag named `main` with no remote-tracking ref, each returns the merge base of the real ref and not the tag's. Five controls keep the order, the environment override, the local fallback, the merged-pull-request fallback and the no-base result. The first-parent walk is untouched (the lab-host defect is a separate card). The default_base docstring in scripts/check_doc_reverts.py is re-wrapped around the two renamed refs; the sentences it carries come from 1e360bd and d093560 and keep their wording, only the ref names change. Lane: ci-fu-shortrefs (Codex gpt-6.1-sol). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * ci: release ruleset probe lists every branch ruleset (measurement only, gate unchanged) [replaces #489] (#505) * ci(release): the ruleset probe lists every branch ruleset as visible or hidden, even when the gate verdict is a refusal (CR-245 F1 measurement) The one dispatch of release-ruleset-probe.yml from main (run 40083495967) refused on the first branch ruleset of the inventory, the organization ruleset `default` (13094758): "returned missing or invalid bypass_actors (token cannot see this ruleset's bypass_actors)". The verdict reader stops at the first failure, so the run did not say whether the release App token can see bypass_actors on the repository ruleset that is the real barrier (21476386), nor on any other. The probe now first prints one line per branch ruleset of the includes_parents inventory (id, name, source_type, source, enforcement, updated_at, bypass_actors visible with the actor count or hidden, applies to main, has a pull_request rule), then runs the unchanged verdict: success prints the existing success lines; a refusal prints the same ::error:: text on stderr and exits 1, but stdout now carries the listing. A detail read that fails is reported on its own row and the listing continues. The listing is a measurement: `gate`, `_release_bump` and `_require_release_rulesets` are untouched, every gate test and the existing source mutants are kept, and the probe's verdict replay over every existing ruleset fixture still compares verdict and refusal text byte for byte. The workflow release-ruleset-probe.yml is not changed. The listing reads each branch ruleset detail independently of the verdict read (two reads per detail in the probe), which docs/ci.md now says. Red-first rows: the real situation (org ruleset hidden, repository ruleset visible: both listed, the org one hidden, refusal unchanged), both hidden, one detail read failing, all visible with a valid barrier, the read-only call list, and a source mutant that drops the listing. Rewrites named for the doc-reverts check, all introduced by 9c18d41 (#488, "ci(release): read-only ruleset probe for the release gate (CR-245 F1)"): docs/ci.md "Success prints the barrier id/name and one compact inventory line with enforcement, source and bypass visibility."; docs/ci.md "Refusal exits 1 with empty stdout and the reader's `::error::` diagnostic; API/response failures name the endpoint."; docs/ci.md "Two hidden rulesets need two dispatches: the first refusal names only the first hidden ruleset; make its `bypass_actors` visible before dispatching again to identify the second." (replaced: all hidden rulesets are listed in one dispatch); the probe docstring "Read exactly the bump's ruleset evidence, with the same refusal policy."; two test comments ("The reader report's complete [] inventory fails on main without an endpoint." and "The runtime assertions already hold there; the prose does not."). The module docstring sentence "Each endpoint/page is read at most once; failures refuse without retry or sleep." (ad1ebac, #479) is scoped to the gate's reads. Lane: ci-fu-cr488m (Codex gpt-6.1-sol). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * ci(release): the probe listing bounds its inventory=ERROR row to 240 characters like the detail-error rows (CR-245 F1 measurement, sol P2) The new stdout listing printed the whole exception text on an `inventory=ERROR` row, while the per-ruleset `detail=ERROR` rows truncate it to 240 characters; a `gh` transport error with 300 characters of stderr was echoed in full. The row now applies the same bound ([:240], still !r-escaped). Four rows assert the exact bounded line (an inventory transport error, a repository transport error, a default-branch rejection with a long repository argument, an invalid summary with a long field) together with the unchanged stderr, exit code 1 and API call list of the verdict; each has a mutation control that removes only the bound and must fail. The verdict functions are untouched and the verdict's own stderr is not bounded. No documentation sentence is changed (none described a length limit). Lane: ci-fu-cr488n (Codex gpt-6.1-sol). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: ci-cx <ci-cx@invalid> Co-authored-by: Claude Sonnet 5.5 <[email protected]>
1 parent 19350a8 commit db58170

5 files changed

Lines changed: 104 additions & 14 deletions

File tree

‎.github/workflows/promote-baseline.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ jobs:
340340
set -euo pipefail
341341
# The PR head's objects, to read its tree: fetched, never checked out or run.
342342
git fetch --quiet origin "$BASE_REF" "+refs/pull/$PR_NUMBER/head:refs/remotes/origin/pr-head"
343-
if ! git merge-base --is-ancestor "$MERGE_SHA" "origin/$BASE_REF"; then
344-
echo "::notice::merge commit $MERGE_SHA is not on origin/$BASE_REF; skipping"
343+
if ! git merge-base --is-ancestor "$MERGE_SHA" "refs/remotes/origin/$BASE_REF"; then
344+
echo "::notice::merge commit $MERGE_SHA is not on refs/remotes/origin/$BASE_REF; skipping"
345345
echo "ok=false" >> "$GITHUB_OUTPUT"; exit 0
346346
fi
347347
merge_tree=$(git rev-parse "$MERGE_SHA^{tree}")

‎scripts/check_doc_reverts.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@
5252
Without ``--head`` the gate walks the non-merge commits of ``base..HEAD`` one
5353
by one, each against its parent and with its own message. ``base`` is
5454
``--base``, else ``$PINEFORGE_DOC_REVERT_BASE``, else the merge base with
55-
``origin/main`` or ``main``, else -- in a checkout with no branch refs, as the
56-
lab's remote hosts have -- the newest first-parent ancestor of ``HEAD`` whose
57-
subject ends in a pull request number, `` (#N)``: the squash or merge commit
58-
GitHub wrote on ``main``, which is the merge base CI would find (its branch's
59-
commits were judged one by one, with their own messages, before it merged; a
60-
squash commit's message is the pull request's title and cannot name them
61-
again). Where none resolves, the walk starts at ``HEAD`` and stops at the first
62-
commit that predates this gate. A commit whose own tree
63-
has no ``scripts/check_doc_reverts.py`` is never judged: the rule binds from
64-
the commit that introduced it on. At most ``MAX_COMMITS`` commits are walked.
55+
``refs/remotes/origin/main`` or ``refs/heads/main``, else -- in a checkout with
56+
no branch refs, as the lab's remote hosts have -- the newest first-parent
57+
ancestor of ``HEAD`` whose subject ends in a pull request number, `` (#N)``:
58+
the squash or merge commit GitHub wrote on ``main``, which is the merge base
59+
CI would find (its branch's commits were judged one by one, with their own
60+
messages, before it merged; a squash commit's message is the pull request's
61+
title and cannot name them again). Where none resolves, the walk starts at
62+
``HEAD`` and stops at the first commit that predates this gate. A commit whose
63+
own tree has no ``scripts/check_doc_reverts.py`` is never judged: the rule binds
64+
from the commit that introduced it on. At most ``MAX_COMMITS`` commits are walked.
6565
6666
Exit 0 when every revert and deletion is named, 1 when one is not, 2 when git
6767
or a named ref cannot be read.
@@ -352,7 +352,7 @@ def default_base(root: Path) -> str | None:
352352
env = os.environ.get('PINEFORGE_DOC_REVERT_BASE')
353353
if env:
354354
return resolve(env, root)
355-
for ref in ('origin/main', 'main'):
355+
for ref in ('refs/remotes/origin/main', 'refs/heads/main'):
356356
tip = git('rev-parse', '--verify', '--quiet', ref + '^{commit}', root=root,
357357
check=False).strip()
358358
if tip:

‎scripts/ci_preflight.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ def ci_workflow_findings(ci: str, native: str, promote: str, cmake: str,
18841884
or 'BASE_REF: main' not in exacttree
18851885
or 'git fetch --quiet origin "$BASE_REF" "+refs/pull/$PR_NUMBER/head:refs/remotes/origin/pr-head"'
18861886
not in exacttree
1887-
or 'git merge-base --is-ancestor "$MERGE_SHA" "origin/$BASE_REF"' not in exacttree
1887+
or 'git merge-base --is-ancestor "$MERGE_SHA" "refs/remotes/origin/$BASE_REF"' not in exacttree
18881888
or '--is-ancestor "$HEAD_SHA"' in promote
18891889
or 'merge_tree=$(git rev-parse "$MERGE_SHA^{tree}")' not in exacttree
18901890
or 'head_tree=$(git rev-parse "$HEAD_SHA^{tree}")' not in exacttree

‎scripts/test_check_doc_reverts.py‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
import contextlib
2020
import io
21+
import os
2122
from pathlib import Path
2223
import shutil
2324
import subprocess
2425
import tempfile
2526
import unittest
27+
from unittest import mock
2628

2729
import check_doc_reverts as guard
2830

@@ -91,6 +93,73 @@ def with_keep_handle(page: str = BASE_PAGE) -> str:
9193
return page + '\n' + KEEP_HANDLE + '\n'
9294

9395

96+
class DefaultBase(unittest.TestCase):
97+
def setUp(self) -> None:
98+
env = mock.patch.dict(os.environ, {'PINEFORGE_DOC_REVERT_BASE': ''})
99+
env.start()
100+
self.addCleanup(env.stop)
101+
102+
def test_tags_cannot_shadow_branch_refs(self) -> None:
103+
for ref, tag in (('refs/remotes/origin/main', 'origin/main'),
104+
('refs/heads/main', 'main')):
105+
with self.subTest(ref=ref), repo() as r:
106+
common = r.commit(BASE_PAGE, 'docs: common ancestor')
107+
r.git('checkout', '-q', '-b', 'tag-history')
108+
tag_tip = r.commit(with_keep_handle(), 'docs: unrelated tag history')
109+
r.git('tag', tag, tag_tip)
110+
r.git('checkout', '-q', 'lane')
111+
base = r.commit(BASE_PAGE + '\nThe main branch adds its own sentence.\n',
112+
'docs: main branch')
113+
r.git('update-ref', ref, base)
114+
r.commit(with_keep_handle(), 'docs: lane after main')
115+
self.assertEqual(r.git('merge-base', 'HEAD', f'refs/tags/{tag}'), common)
116+
self.assertEqual(r.git('merge-base', 'HEAD', ref), base)
117+
self.assertNotEqual(common, base)
118+
self.assertEqual(guard.default_base(r.root), base)
119+
120+
def test_remote_tracking_main_precedes_local_main(self) -> None:
121+
with repo() as r:
122+
remote = r.commit(BASE_PAGE, 'docs: remote main')
123+
r.git('update-ref', 'refs/remotes/origin/main', remote)
124+
local = r.commit(with_keep_handle(), 'docs: local main')
125+
r.git('update-ref', 'refs/heads/main', local)
126+
r.commit(BASE_PAGE + '\nThe lane adds a new sentence after local main.\n',
127+
'docs: lane')
128+
self.assertEqual(guard.default_base(r.root), remote)
129+
130+
def test_local_main_is_used_without_remote_tracking_main(self) -> None:
131+
with repo() as r:
132+
base = r.commit(BASE_PAGE, 'docs: local main')
133+
r.git('update-ref', 'refs/heads/main', base)
134+
r.commit(with_keep_handle(), 'docs: lane')
135+
self.assertEqual(guard.default_base(r.root), base)
136+
137+
def test_environment_base_precedes_branch_refs(self) -> None:
138+
with repo() as r:
139+
override = r.commit(BASE_PAGE, 'docs: explicit base')
140+
remote = r.commit(with_keep_handle(), 'docs: remote main')
141+
r.git('update-ref', 'refs/remotes/origin/main', remote)
142+
local = r.commit(BASE_PAGE + '\nLocal main adds another sentence.\n',
143+
'docs: local main')
144+
r.git('update-ref', 'refs/heads/main', local)
145+
r.commit(with_keep_handle(), 'docs: lane')
146+
with mock.patch.dict(os.environ, {'PINEFORGE_DOC_REVERT_BASE': override}):
147+
self.assertEqual(guard.default_base(r.root), override)
148+
149+
def test_merged_pull_request_is_used_without_branch_refs(self) -> None:
150+
with repo() as r:
151+
r.commit(BASE_PAGE, 'docs: initial guide')
152+
base = r.commit(with_keep_handle(), 'docs: merged guide (#12)')
153+
r.commit(BASE_PAGE + '\nThe lane adds a new sentence after the merge.\n',
154+
'docs: lane')
155+
self.assertEqual(guard.default_base(r.root), base)
156+
157+
def test_no_branch_ref_or_merged_pull_request_has_no_base(self) -> None:
158+
with repo() as r:
159+
r.commit(BASE_PAGE, 'docs: initial guide')
160+
self.assertIsNone(guard.default_base(r.root))
161+
162+
94163
class MustFail(unittest.TestCase):
95164
def setup_history(self, r: Repo) -> tuple[str, str]:
96165
base = r.commit(BASE_PAGE, 'docs: the guide')

‎scripts/test_ci_preflight.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,27 @@ def test_ci_contract_pins_parallel_pr_light_and_full_events(self):
868868
self.assertNotEqual(changed[index], original[index])
869869
self.assertNotEqual(ci_workflow_findings(*changed), [])
870870

871+
def test_baseline_promotion_accepts_qualified_base_ref(self):
872+
sources = self.ci_sources()
873+
short = 'git merge-base --is-ancestor "$MERGE_SHA" "origin/$BASE_REF"'
874+
qualified = ('git merge-base --is-ancestor "$MERGE_SHA" '
875+
'"refs/remotes/origin/$BASE_REF"')
876+
# Supply the same qualified input before and after the workflow fix.
877+
sources[2] = sources[2].replace(short, qualified)
878+
self.assertEqual(sources[2].count(qualified), 1)
879+
self.assertEqual(ci_workflow_findings(*sources, others=self.other_sources()), [])
880+
881+
def test_baseline_promotion_rejects_short_base_ref(self):
882+
sources = self.ci_sources()
883+
short = 'git merge-base --is-ancestor "$MERGE_SHA" "origin/$BASE_REF"'
884+
qualified = ('git merge-base --is-ancestor "$MERGE_SHA" '
885+
'"refs/remotes/origin/$BASE_REF"')
886+
# Supply the old command even when the workflow already uses the fix.
887+
sources[2] = sources[2].replace(qualified, short)
888+
self.assertEqual(sources[2].count(short), 1)
889+
self.assertIn('baseline promotion must admit a squash merge by tree equality only',
890+
ci_workflow_findings(*sources, others=self.other_sources()))
891+
871892
def test_baseline_promotion_rejects_later_pr_head_checkout(self):
872893
finding = ("baseline promotion must run main's copy and require "
873894
"the latest two head statuses")

0 commit comments

Comments
 (0)