Skip to content

Commit ef94b5d

Browse files
wei-haiclaude
andauthored
perf(cursor-approve): drop the full-history clone from the checkout axes (#463)
* perf(cursor-approve): drop the full-history clone from the checkout axes Both PR-head checkouts in cursor-axis-base.yml (the Cursor `axis` job and `axis-direct`) cloned every branch and tag with fetch-depth: 0, which took 1.5-10 minutes per axis on a large monorepo caller, often longer than the review itself. Only the merge base needs history. - Check out commit_sha at depth 1, then run the shared scripts/check-pr-size/fetch-history.sh (already used by cursor-review's diff-size job and pr-size.yml) to fetch BASE_SHA and commit_sha back to a merge base it can vouch for, failing the job with an ::error:: otherwise. - Render prompt resolves merge-base(BASE_SHA, commit_sha) with no fallback, instead of merge-base(origin/<base_ref>, commit_sha) falling back to BASE_SHA. origin/<base_ref> no longer exists in a narrowed checkout; the result is the same commit unless the base branch has since absorbed the PR's own commits, and it now matches the compare API the no-checkout axes use. - New test_axis_checkout.py pins depth 1, the fetch step's order and inputs, and the no-fallback merge base. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(check-pr-size): drop a tracker reference from the fetch-history header Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(cursor-approve): warn the axes that blame stops at a shallow boundary Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e3bc077 commit ef94b5d

5 files changed

Lines changed: 108 additions & 12 deletions

File tree

‎.github/cursor-approve/prompt-common.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ the merge base.
3030
work, you are looking at that artifact, not at the PR.
3131

3232
2. **Read; do not run.** Read the changed code, the code around it, and its
33-
history (`git log`, `git blame`, `git show`). Do not build the project, run
34-
its tests, or execute anything it contains. CI runs elsewhere, and its result
35-
is not your question.
33+
history (`git log`, `git blame`, `git show`). The checkout's history ends a
34+
little past the merge base: a line `git blame` credits to a `^`-prefixed
35+
boundary commit was written earlier, not there, so do not rest a verdict on
36+
who added it or when. Do not build the project, run its tests, or execute
37+
anything it contains. CI runs elsewhere, and its result is not your question.
3638

3739
3. **Pick a verdict by what the evidence supports.**
3840
- `red` — you found evidence of a blocker on your axis. Name it.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""The checkout axes clone narrowly and fail closed on the merge base.
2+
3+
Both PR-head checkouts in cursor-axis-base.yml (the Cursor `axis` job and
4+
`axis-direct`) are depth 1, followed by the shared fetch-history.sh, which
5+
fetches back to the merge base of BASE_SHA and commit_sha or fails the job.
6+
A full-history clone took minutes per axis on a large monorepo.
7+
8+
Run: python3 -m unittest discover -s .github/cursor-approve/tests -p 'test_*.py'
9+
"""
10+
11+
import os
12+
import re
13+
import unittest
14+
15+
HERE = os.path.dirname(os.path.abspath(__file__))
16+
ROOT = os.path.normpath(os.path.join(HERE, "..", "..", ".."))
17+
with open(os.path.join(ROOT, ".github", "workflows", "cursor-axis-base.yml"), encoding="utf-8") as f:
18+
BASE = f.read()
19+
20+
CHECKOUT = "Check out the PR head (read-only)"
21+
FETCH = "Fetch the merge-base history"
22+
RENDER = "Render prompt"
23+
SCRIPT = ('run: bash "$GITHUB_WORKSPACE/_cursor_approve_assets/'
24+
'scripts/check-pr-size/fetch-history.sh"')
25+
26+
27+
def job(name):
28+
start = BASE.index(f"\n {name}:\n")
29+
nxt = re.search(r"\n [A-Za-z0-9_-]+:\n", BASE[start + 1:])
30+
return BASE[start:start + 1 + nxt.start()] if nxt else BASE[start:]
31+
32+
33+
def steps(text):
34+
"""[(name, text)] in order."""
35+
parts = re.split(r"\n - name: ", text)
36+
return [(p.split("\n", 1)[0].strip(), p) for p in parts[1:]]
37+
38+
39+
class NarrowCheckout(unittest.TestCase):
40+
def test_no_full_history_clone(self):
41+
self.assertNotRegex(BASE, r"fetch-depth:\s*0\b")
42+
43+
def test_each_checkout_job_fetches_the_merge_base_before_rendering(self):
44+
for name, gate in (("axis", "if: inputs.checkout"), ("axis-direct", None)):
45+
with self.subTest(job=name):
46+
st = steps(job(name))
47+
names = [n for n, _ in st]
48+
self.assertLess(names.index(CHECKOUT), names.index(FETCH))
49+
self.assertLess(names.index(FETCH), names.index(RENDER))
50+
checkout, fetch = dict(st)[CHECKOUT], dict(st)[FETCH]
51+
self.assertIn("fetch-depth: 1\n", checkout)
52+
self.assertIn("ref: ${{ inputs.commit_sha }}", checkout)
53+
self.assertIn(SCRIPT, fetch)
54+
self.assertIn("working-directory: pr\n", fetch)
55+
self.assertIn("HEAD_SHA: ${{ inputs.commit_sha }}", fetch)
56+
self.assertIn("BASE_SHA: ${{ github.event.pull_request.base.sha }}", fetch)
57+
self.assertIn("FETCH_TOKEN: ${{ github.token }}", fetch)
58+
if gate:
59+
self.assertIn(gate + "\n", fetch)
60+
61+
def test_render_reads_the_vouched_merge_base_with_no_fallback(self):
62+
# A silent fallback to BASE_SHA would show every base-branch commit
63+
# since the fork point as reverted by the PR.
64+
for name in ("axis", "axis-direct"):
65+
with self.subTest(job=name):
66+
render = dict(steps(job(name)))[RENDER]
67+
self.assertIn('merge_base="$(git -C pr merge-base "$BASE_SHA" "$COMMIT_SHA")"', render)
68+
self.assertNotIn("origin/$BASE_REF", render)
69+
70+
71+
if __name__ == "__main__":
72+
unittest.main()

‎.github/workflows/cursor-axis-base.yml‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,22 @@ jobs:
467467
with:
468468
ref: ${{ inputs.commit_sha }}
469469
path: pr
470-
fetch-depth: 0
470+
# Depth 1 plus the next step instead of a full clone: only the merge
471+
# base needs history, and a full clone takes minutes on a monorepo.
472+
fetch-depth: 1
471473
persist-credentials: false
472474

475+
- name: Fetch the merge-base history
476+
# The shared script cursor-review.yml's diff-size job uses. Fails the
477+
# axis when no trustworthy merge base of BASE_SHA and commit_sha exists.
478+
if: inputs.checkout
479+
working-directory: pr
480+
env:
481+
FETCH_TOKEN: ${{ github.token }}
482+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
483+
HEAD_SHA: ${{ inputs.commit_sha }}
484+
run: bash "$GITHUB_WORKSPACE/_cursor_approve_assets/scripts/check-pr-size/fetch-history.sh"
485+
473486
- name: Fetch the change (no checkout)
474487
if: ${{ !inputs.checkout && (inputs.axis == 'business' || inputs.axis == 'design') }}
475488
env:
@@ -542,7 +555,7 @@ jobs:
542555
{ printf '# %s\n\n' "$PR_TITLE"; printf '%s\n' "$PR_BODY"; } > "$ctx"
543556
merge_base="$BASE_SHA"
544557
if [ "$CHECKOUT" = "true" ]; then
545-
merge_base="$(git -C pr merge-base "origin/$BASE_REF" "$COMMIT_SHA" 2>/dev/null || printf '%s' "$BASE_SHA")"
558+
merge_base="$(git -C pr merge-base "$BASE_SHA" "$COMMIT_SHA")"
546559
fi
547560
{
548561
python3 "$CURSOR_APPROVE_ASSETS/aggregate.py" render \
@@ -858,9 +871,18 @@ jobs:
858871
with:
859872
ref: ${{ inputs.commit_sha }}
860873
path: pr
861-
fetch-depth: 0
874+
fetch-depth: 1
862875
persist-credentials: false
863876

877+
- name: Fetch the merge-base history
878+
# As the Cursor job.
879+
working-directory: pr
880+
env:
881+
FETCH_TOKEN: ${{ github.token }}
882+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
883+
HEAD_SHA: ${{ inputs.commit_sha }}
884+
run: bash "$GITHUB_WORKSPACE/_cursor_approve_assets/scripts/check-pr-size/fetch-history.sh"
885+
864886
- name: Download the prior verdicts
865887
if: inputs.prior_rounds > 0
866888
continue-on-error: true
@@ -890,7 +912,7 @@ jobs:
890912
ctx_dir="pr/.git"
891913
ctx="$ctx_dir/cursor-approve-context.md"
892914
{ printf '# %s\n\n' "$PR_TITLE"; printf '%s\n' "$PR_BODY"; } > "$ctx"
893-
merge_base="$(git -C pr merge-base "origin/$BASE_REF" "$COMMIT_SHA" 2>/dev/null || printf '%s' "$BASE_SHA")"
915+
merge_base="$(git -C pr merge-base "$BASE_SHA" "$COMMIT_SHA")"
894916
# Rule 1's exact diff. `--text --no-textconv --no-ext-diff`: the
895917
# checkout's own .gitattributes (`-diff`, `binary`, a textconv
896918
# driver) must not shrink a file's change to "Binary files differ"

‎docs/callers/cursor-approve.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ diff the workflow fetches from the GitHub API.)
687687

688688
| Input | Default | Meaning |
689689
|---|---|---|
690-
| `commit_sha` | — (required) | The PR head to judge; checked out read-only with full history. |
690+
| `commit_sha` | — (required) | The PR head to judge; checked out read-only with the history back to its merge base. |
691691
| `model` | `claude-opus-5-5-xhigh` | Cursor model id (cursor-review's judge model). |
692692
| `runs_on` | `"ubuntu-latest"` | JSON-encoded `runs-on`, as in cursor-review. |
693693
| `prior_rounds` | `0` | 0–3, passed to the base: the same value as `cursor-approve.yml`'s. See [Prior rounds](#prior-rounds). |

‎scripts/check-pr-size/fetch-history.sh‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# Fetch the base commit, the head commit and their merge-base history into a
33
# `fetch-depth: 1`, `persist-credentials: false` PR checkout — instead of the
44
# `fetch-depth: 0` clone of every branch and tag that used to sit in front of
5-
# check-pr-size. Shared by pr-size.yml and cursor-review.yml's `diff-size` job,
6-
# so the two workflows that run the tool cannot drift on how its history is
7-
# narrowed. (BE-8940 for pr-size; cursor-review adopted it to take the clone off
8-
# its review round's critical path.)
5+
# check-pr-size. Shared by pr-size.yml, cursor-review.yml's `diff-size` job and
6+
# cursor-axis-base.yml's checkout axes, so they cannot drift on how history is
7+
# narrowed. (cursor-review adopted it to take the clone off its review round's
8+
# critical path.)
99
#
1010
# Run from the root of the PR checkout. Inputs:
1111
# env FETCH_TOKEN the job's read-only token (`permissions: contents: read`)

0 commit comments

Comments
 (0)